]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
096a6f4cba7732ef52f595f5b169358713413bbd
[thirdparty/openembedded/openembedded-core-contrib.git] /
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
5
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.
9
10 https://bugzilla.gnome.org/show_bug.cgi?id=759329
11
12 Upstream-Status: Backport [1.7.1]
13
14 ---
15 gst-libs/gst/video/convertframe.c | 65 +++++++++++++++++++++++++++++++++------
16 1 file changed, 56 insertions(+), 9 deletions(-)
17
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:
23 static GstElement *
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)
28 {
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;
33 + GstVideoInfo info;
34 GError *error = NULL;
35
36 + if (cmeta) {
37 + if (!create_element ("videocrop", &vcrop, &error)) {
38 + g_warning
39 + ("build_convert_frame_pipeline: Buffer has crop metadata but videocrop element is not found. Cropping will be disabled");
40 + } else {
41 + if (!create_element ("videoconvert", &csp2, &error))
42 + goto no_elements;
43 + }
44 + }
45 +
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,
50
51 GST_DEBUG ("adding elements");
52 gst_bin_add_many (GST_BIN (pipeline), src, csp, vscale, sink, NULL);
53 + if (vcrop)
54 + gst_bin_add_many (GST_BIN (pipeline), vcrop, csp2, NULL);
55
56 /* set caps */
57 g_object_set (src, "caps", from_caps, NULL);
58 + if (vcrop) {
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,
63 + NULL);
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);
68 + }
69 g_object_set (sink, "caps", to_caps, NULL);
70
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"))
74 - goto link_failed;
75 + if (vcrop) {
76 + GST_DEBUG ("linking src->csp2");
77 + if (!gst_element_link_pads (src, "src", csp2, "sink"))
78 + goto link_failed;
79 +
80 + GST_DEBUG ("linking csp2->vcrop");
81 + if (!gst_element_link_pads (csp2, "src", vcrop, "sink"))
82 + goto link_failed;
83 +
84 + GST_DEBUG ("linking vcrop->csp");
85 + if (!gst_element_link_pads (vcrop, "src", csp, "sink"))
86 + goto link_failed;
87 + } else {
88 + GST_DEBUG ("linking src->csp");
89 + if (!gst_element_link_pads (src, "src", csp, "sink"))
90 + goto link_failed;
91 + }
92
93 GST_DEBUG ("linking csp->vscale");
94 if (!gst_element_link_pads_full (csp, "src", vscale, "sink",
95 @@ -193,8 +231,12 @@ no_elements:
96 {
97 if (src)
98 gst_object_unref (src);
99 + if (vcrop)
100 + gst_object_unref (vcrop);
101 if (csp)
102 gst_object_unref (csp);
103 + if (csp2)
104 + gst_object_unref (csp2);
105 if (vscale)
106 gst_object_unref (vscale);
107 if (sink)
108 @@ -209,7 +251,11 @@ no_elements:
109 no_pipeline:
110 {
111 gst_object_unref (src);
112 + if (vcrop)
113 + gst_object_unref (vcrop);
114 gst_object_unref (csp);
115 + if (csp2)
116 + gst_object_unref (csp2);
117 gst_object_unref (vscale);
118 gst_object_unref (sink);
119
120 @@ -282,7 +328,8 @@ gst_video_convert_sample (GstSample * sample, const GstCaps * to_caps,
121 }
122
123 pipeline =
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);
127 if (!pipeline)
128 goto no_pipeline;
129
130 @@ -646,8 +693,8 @@ gst_video_convert_sample_async (GstSample * sample,
131 }
132
133 pipeline =
134 - build_convert_frame_pipeline (&src, &sink, from_caps, to_caps_copy,
135 - &error);
136 + build_convert_frame_pipeline (&src, &sink, from_caps,
137 + gst_buffer_get_video_crop_meta (buf), to_caps_copy, &error);
138 if (!pipeline)
139 goto no_pipeline;
140
141 --
142 2.5.0
143