[Cogl] [PATCH 02/13] cogl-gst: video-sink: fix YV12/I420 support
Lionel Landwerlin
llandwerlin at gmail.com
Mon Dec 9 03:17:49 PST 2013
---
cogl-gst/cogl-gst-video-sink.c | 55 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 5 deletions(-)
diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c
index bcbef35..a42841a 100644
--- a/cogl-gst/cogl-gst-video-sink.c
+++ b/cogl-gst/cogl-gst-video-sink.c
@@ -616,7 +616,52 @@ cogl_gst_yv12_upload (CoglGstVideoSink *sink,
{
CoglGstVideoSinkPrivate *priv = sink->priv;
GstVideoFrame frame;
- CoglPixelFormat format = COGL_PIXEL_FORMAT_A_8;
+ CoglPixelFormat format = COGL_PIXEL_FORMAT_G_8;
+
+ if (!gst_video_frame_map (&frame, &priv->info, buffer, GST_MAP_READ))
+ goto map_fail;
+
+ clear_frame_textures (sink);
+
+ priv->frame[0] =
+ video_texture_new_from_data (priv->ctx,
+ GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0),
+ GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0),
+ format, format,
+ priv->info.stride[0], frame.data[0], NULL);
+
+ priv->frame[2] =
+ video_texture_new_from_data (priv->ctx,
+ GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1),
+ GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1),
+ format, format,
+ priv->info.stride[1], frame.data[1], NULL);
+
+ priv->frame[1] =
+ video_texture_new_from_data (priv->ctx,
+ GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2),
+ GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2),
+ format, format,
+ priv->info.stride[2], frame.data[2], NULL);
+
+ gst_video_frame_unmap (&frame);
+
+ return TRUE;
+
+map_fail:
+ {
+ GST_ERROR_OBJECT (sink, "Could not map incoming video frame");
+ return FALSE;
+ }
+}
+
+static CoglBool
+cogl_gst_i420_upload (CoglGstVideoSink *sink,
+ GstBuffer *buffer)
+{
+ CoglGstVideoSinkPrivate *priv = sink->priv;
+ GstVideoFrame frame;
+ CoglPixelFormat format = COGL_PIXEL_FORMAT_G_8;
if (!gst_video_frame_map (&frame, &priv->info, buffer, GST_MAP_READ))
goto map_fail;
@@ -674,9 +719,9 @@ cogl_gst_yv12_glsl_setup_pipeline (CoglGstVideoSink *sink,
"cogl_gst_sample_video%i (vec2 UV)\n"
"{\n"
" float y = 1.1640625 * "
- "(texture2D (cogl_sampler%i, UV).a - 0.0625);\n"
- " float u = texture2D (cogl_sampler%i, UV).a - 0.5;\n"
- " float v = texture2D (cogl_sampler%i, UV).a - 0.5;\n"
+ "(texture2D (cogl_sampler%i, UV).g - 0.0625);\n"
+ " float u = texture2D (cogl_sampler%i, UV).g - 0.5;\n"
+ " float v = texture2D (cogl_sampler%i, UV).g - 0.5;\n"
" vec4 color;\n"
" color.r = y + 1.59765625 * v;\n"
" color.g = y - 0.390625 * u - 0.8125 * v;\n"
@@ -715,7 +760,7 @@ static CoglGstRenderer i420_glsl_renderer =
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES("memory:SystemMemory", "I420")),
3, /* n_layers */
cogl_gst_yv12_glsl_setup_pipeline,
- cogl_gst_yv12_upload,
+ cogl_gst_i420_upload,
};
static void
--
1.8.5
More information about the Cogl
mailing list