diff options
author | Edward Hervey <edward@collabora.com> | 2012-08-28 14:56:27 -0700 |
---|---|---|
committer | Edward Hervey <edward.hervey@collabora.co.uk> | 2012-09-17 11:23:36 +0200 |
commit | 647ee5eb4a6c6a3062e2c966057c75193ab5c2ca (patch) | |
tree | 631c4b5c7227c903306b0e800d4c2be49dececeb | |
parent | dca592ad5a37ab9206986289450d5d725b53fd89 (diff) |
video-sink: Add NV12 shader supportnv12
-rw-r--r-- | clutter-gst/clutter-gst-video-sink.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/clutter-gst/clutter-gst-video-sink.c b/clutter-gst/clutter-gst-video-sink.c index f8d3954..cbc93fc 100644 --- a/clutter-gst/clutter-gst-video-sink.c +++ b/clutter-gst/clutter-gst-video-sink.c @@ -91,6 +91,22 @@ static gchar *ayuv_to_rgba_shader = " color.b = y + 2.015625 * u;" " gl_FragColor = color;" FRAGMENT_SHADER_END "}"; +static gchar *nv12_to_rgba_shader = + FRAGMENT_SHADER_VARS + "uniform sampler2D ytex;\n" + "uniform sampler2D utex;\n" + "void main () {\n" + " vec2 coord = vec2(" TEX_COORD ");\n" + " int chroma;\n" + " float y = 1.1640625 * (texture2D (ytex, coord).x - 0.0625);\n" + " float u = texture2D (utex, coord).r - 0.5;\n" + " float v = texture2D (utex, coord).a - 0.5;\n" + " vec4 color;\n" + " color.r = y + 1.59765625 * v;\n" + " color.g = y - 0.390625 * u - 0.8125 * v;\n" + " color.b = y + 2.015625 * u;\n" + " color.a = 1.0;\n" " gl_FragColor = color;\n" FRAGMENT_SHADER_END "}\n"; + static gchar *yv12_to_rgba_shader = FRAGMENT_SHADER_VARS "uniform sampler2D ytex;" @@ -107,8 +123,10 @@ static gchar *yv12_to_rgba_shader = " color.b = y + 2.015625 * u;" " color.a = 1.0;" " gl_FragColor = color;" FRAGMENT_SHADER_END "}"; + #define BASE_SINK_CAPS "{ AYUV," \ "YV12," \ + "NV12," \ "I420," \ "RGBA," \ "BGRA," \ @@ -141,6 +159,7 @@ typedef enum CLUTTER_GST_RGB24, CLUTTER_GST_AYUV, CLUTTER_GST_YV12, + CLUTTER_GST_NV12, CLUTTER_GST_I420, CLUTTER_GST_SURFACE } ClutterGstVideoFormat; @@ -358,6 +377,9 @@ clutter_gst_parse_caps (GstCaps * caps, case GST_VIDEO_FORMAT_YV12: format = CLUTTER_GST_YV12; break; + case GST_VIDEO_FORMAT_NV12: + format = CLUTTER_GST_NV12; + break; case GST_VIDEO_FORMAT_I420: format = CLUTTER_GST_I420; break; @@ -914,6 +936,56 @@ static ClutterGstRenderer yv12_glsl_renderer = { }; /* + * NV12 + * + * 8 bit Y plane followed by interleaved U/V plane containing 8 bit 2x2 subsampled UV + */ + +static void +clutter_gst_nv12_upload (ClutterGstVideoSink * sink, GstBuffer * buffer) +{ + ClutterGstVideoSinkPrivate *priv = sink->priv; + gint y_row_stride = GST_ROUND_UP_4 (priv->width); + CoglHandle y_tex, u_tex; + GstMapInfo info; + + gst_buffer_map (buffer, &info, GST_MAP_READ); + + y_tex = cogl_texture_new_from_data (priv->width, + priv->height, + CLUTTER_GST_TEXTURE_FLAGS, + COGL_PIXEL_FORMAT_G_8, COGL_PIXEL_FORMAT_G_8, y_row_stride, info.data); + + u_tex = cogl_texture_new_from_data (priv->width / 2, + priv->height / 2, + CLUTTER_GST_TEXTURE_FLAGS, + COGL_PIXEL_FORMAT_U_V, + COGL_PIXEL_FORMAT_U_V, + y_row_stride, info.data + (y_row_stride * priv->height)); + + gst_buffer_unmap (buffer, &info); + + _create_paint_material (sink, y_tex, u_tex, COGL_INVALID_HANDLE); +} + +static void +clutter_gst_nv12_glsl_init (ClutterGstVideoSink * sink) +{ + _create_template_material (sink, nv12_to_rgba_shader, TRUE, 2); +} + + +static ClutterGstRenderer nv12_glsl_renderer = { + "NV12 glsl", + CLUTTER_GST_NV12, + CLUTTER_GST_GLSL | CLUTTER_GST_MULTI_TEXTURE, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("NV12")), + clutter_gst_nv12_glsl_init, + clutter_gst_dummy_deinit, + clutter_gst_nv12_upload, +}; + +/* * YV12 (fragment program version) * * 8 bit Y plane followed by 8 bit 2x2 subsampled V and U planes. @@ -1113,7 +1185,8 @@ static ClutterGstRenderer hw_renderer = { "HW surface", CLUTTER_GST_SURFACE, 0, - GST_STATIC_CAPS ("x-video/surface, opengl=true"), + /* FIXME : add more caps later on */ + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, NV12 }")), clutter_gst_hw_init, clutter_gst_hw_deinit, clutter_gst_hw_upload, @@ -1134,6 +1207,7 @@ clutter_gst_build_renderers_list (void) &rgb24_renderer, &rgb32_renderer, &yv12_glsl_renderer, + &nv12_glsl_renderer, &i420_glsl_renderer, #ifdef CLUTTER_COGL_HAS_GL &yv12_fp_renderer, |