1 From 5be6ed00aad028d9cbb4e0c63af0be69d335c71e Mon Sep 17 00:00:00 2001
2 From: Song Bing <b06498@freescale.com>
3 Date: Fri, 11 Dec 2015 21:42:00 +0800
4 Subject: [PATCH] convertframe: Support video crop when convert frame
6 Get thumbnail will user convertframe to convert video frame to
7 desired video format and size. But haven't process crop meta on
8 the video buffer. Add support video crop.
10 https://bugzilla.gnome.org/show_bug.cgi?id=759329
12 Upstream-Status: Backport [1.7.1]
15 gst-libs/gst/video/convertframe.c | 65 +++++++++++++++++++++++++++++++++------
16 1 file changed, 56 insertions(+), 9 deletions(-)
18 diff --git a/gst-libs/gst/video/convertframe.c b/gst-libs/gst/video/convertframe.c
19 index aa9c3d3..942a51e 100644
20 --- a/gst-libs/gst/video/convertframe.c
21 +++ b/gst-libs/gst/video/convertframe.c
22 @@ -110,12 +110,23 @@ fail:
24 build_convert_frame_pipeline (GstElement ** src_element,
25 GstElement ** sink_element, const GstCaps * from_caps,
26 - const GstCaps * to_caps, GError ** err)
27 + GstVideoCropMeta * cmeta, const GstCaps * to_caps, GError ** err)
29 - GstElement *src = NULL, *csp = NULL, *vscale = NULL;
30 - GstElement *sink = NULL, *encoder = NULL, *pipeline;
31 + GstElement *vcrop = NULL, *csp = NULL, *csp2 = NULL, *vscale = NULL;
32 + GstElement *src = NULL, *sink = NULL, *encoder = NULL, *pipeline;
37 + if (!create_element ("videocrop", &vcrop, &error)) {
39 + ("build_convert_frame_pipeline: Buffer has crop metadata but videocrop element is not found. Cropping will be disabled");
41 + if (!create_element ("videoconvert", &csp2, &error))
46 /* videoscale is here to correct for the pixel-aspect-ratio for us */
47 GST_DEBUG ("creating elements");
48 if (!create_element ("appsrc", &src, &error) ||
49 @@ -133,15 +144,42 @@ build_convert_frame_pipeline (GstElement ** src_element,
51 GST_DEBUG ("adding elements");
52 gst_bin_add_many (GST_BIN (pipeline), src, csp, vscale, sink, NULL);
54 + gst_bin_add_many (GST_BIN (pipeline), vcrop, csp2, NULL);
57 g_object_set (src, "caps", from_caps, NULL);
59 + gst_video_info_from_caps (&info, from_caps);
60 + g_object_set (vcrop, "left", cmeta->x, NULL);
61 + g_object_set (vcrop, "top", cmeta->y, NULL);
62 + g_object_set (vcrop, "right", GST_VIDEO_INFO_WIDTH (&info) - cmeta->width,
64 + g_object_set (vcrop, "bottom",
65 + GST_VIDEO_INFO_HEIGHT (&info) - cmeta->height, NULL);
66 + GST_DEBUG ("crop meta [x,y,width,height]: %d %d %d %d", cmeta->x, cmeta->y,
67 + cmeta->width, cmeta->height);
69 g_object_set (sink, "caps", to_caps, NULL);
71 /* FIXME: linking is still way too expensive, profile this properly */
72 - GST_DEBUG ("linking src->csp");
73 - if (!gst_element_link_pads (src, "src", csp, "sink"))
76 + GST_DEBUG ("linking src->csp2");
77 + if (!gst_element_link_pads (src, "src", csp2, "sink"))
80 + GST_DEBUG ("linking csp2->vcrop");
81 + if (!gst_element_link_pads (csp2, "src", vcrop, "sink"))
84 + GST_DEBUG ("linking vcrop->csp");
85 + if (!gst_element_link_pads (vcrop, "src", csp, "sink"))
88 + GST_DEBUG ("linking src->csp");
89 + if (!gst_element_link_pads (src, "src", csp, "sink"))
93 GST_DEBUG ("linking csp->vscale");
94 if (!gst_element_link_pads_full (csp, "src", vscale, "sink",
95 @@ -193,8 +231,12 @@ no_elements:
98 gst_object_unref (src);
100 + gst_object_unref (vcrop);
102 gst_object_unref (csp);
104 + gst_object_unref (csp2);
106 gst_object_unref (vscale);
108 @@ -209,7 +251,11 @@ no_elements:
111 gst_object_unref (src);
113 + gst_object_unref (vcrop);
114 gst_object_unref (csp);
116 + gst_object_unref (csp2);
117 gst_object_unref (vscale);
118 gst_object_unref (sink);
120 @@ -282,7 +328,8 @@ gst_video_convert_sample (GstSample * sample, const GstCaps * to_caps,
124 - build_convert_frame_pipeline (&src, &sink, from_caps, to_caps_copy, &err);
125 + build_convert_frame_pipeline (&src, &sink, from_caps,
126 + gst_buffer_get_video_crop_meta (buf), to_caps_copy, &err);
130 @@ -646,8 +693,8 @@ gst_video_convert_sample_async (GstSample * sample,
134 - build_convert_frame_pipeline (&src, &sink, from_caps, to_caps_copy,
136 + build_convert_frame_pipeline (&src, &sink, from_caps,
137 + gst_buffer_get_video_crop_meta (buf), to_caps_copy, &error);