schro: Add RGB support
authorDavid Schleef <ds@schleef.org>
Mon, 23 Jan 2012 17:02:37 +0000 (09:02 -0800)
committerDavid Schleef <ds@schleef.org>
Fri, 17 Feb 2012 23:15:34 +0000 (15:15 -0800)
This uses the automatic YCoCg conversion inside Schroedinger to
encode/decode RGB.  Only works in intra-only mode, similar to 10-
and 16-bit, since RGB is technically a >8-bit format for Dirac
purposes.  This depends on schroedinger-1.0.12, which is unreleased.

ext/schroedinger/gstschrodec.c
ext/schroedinger/gstschroenc.c
ext/schroedinger/gstschroutils.c

index 782788a..c8a6315 100644 (file)
@@ -99,10 +99,11 @@ GST_STATIC_PAD_TEMPLATE ("sink",
     );
 
 static GstStaticPadTemplate gst_schro_dec_src_template =
-GST_STATIC_PAD_TEMPLATE ("src",
+    GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV (GST_SCHRO_YUV_LIST))
+    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV (GST_SCHRO_YUV_LIST) ";"
+        GST_VIDEO_CAPS_ARGB)
     );
 
 GST_BOILERPLATE (GstSchroDec, gst_schro_dec, GstBaseVideoDecoder,
@@ -313,13 +314,15 @@ parse_sequence_header (GstSchroDec * schro_dec, guint8 * data, int size)
   ret = schro_parse_decode_sequence_header (data + 13, size - 13,
       &video_format);
   if (ret) {
-#if SCHRO_CHECK_VERSION(1,0,11)
     int bit_depth;
 
+#if SCHRO_CHECK_VERSION(1,0,11)
     bit_depth = schro_video_format_get_bit_depth (&video_format);
+#else
+    bit_depth = 8;
+#endif
 
     if (bit_depth == 8) {
-#endif
       if (video_format.chroma_format == SCHRO_CHROMA_444) {
         state->format = GST_VIDEO_FORMAT_AYUV;
       } else if (video_format.chroma_format == SCHRO_CHROMA_422) {
@@ -329,14 +332,18 @@ parse_sequence_header (GstSchroDec * schro_dec, guint8 * data, int size)
       }
 #if SCHRO_CHECK_VERSION(1,0,11)
     } else if (bit_depth <= 10) {
-      state->format = GST_VIDEO_FORMAT_v210;
+      if (video_format.colour_matrix == SCHRO_COLOUR_MATRIX_REVERSIBLE) {
+        state->format = GST_VIDEO_FORMAT_ARGB;
+      } else {
+        state->format = GST_VIDEO_FORMAT_v210;
+      }
     } else if (bit_depth <= 16) {
       state->format = GST_VIDEO_FORMAT_AYUV64;
     } else {
       GST_ERROR ("bit depth too large (%d > 16)", bit_depth);
       state->format = GST_VIDEO_FORMAT_AYUV64;
-    }
 #endif
+    }
     state->fps_n = video_format.frame_rate_numerator;
     state->fps_d = video_format.frame_rate_denominator;
     GST_DEBUG_OBJECT (schro_dec, "Frame rate is %d/%d", state->fps_n,
index 9c00177..cd70602 100644 (file)
@@ -103,11 +103,16 @@ static GstFlowReturn gst_schro_enc_shape_output (GstBaseVideoEncoder *
     base_video_encoder, GstVideoFrame * frame);
 static void gst_schro_enc_finalize (GObject * object);
 
+#if SCHRO_CHECK_VERSION(1,0,12)
+#define ARGB_CAPS ";" GST_VIDEO_CAPS_ARGB
+#else
+#define ARGB_CAPS
+#endif
 static GstStaticPadTemplate gst_schro_enc_sink_template =
 GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV (GST_SCHRO_YUV_LIST))
+    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV (GST_SCHRO_YUV_LIST) ARGB_CAPS)
     );
 
 static GstStaticPadTemplate gst_schro_enc_src_template =
@@ -285,15 +290,15 @@ gst_schro_enc_set_format (GstBaseVideoEncoder * base_video_encoder,
       schro_enc->video_format->chroma_format = SCHRO_CHROMA_422;
       break;
     case GST_VIDEO_FORMAT_AYUV:
+#if SCHRO_CHECK_VERSION(1,0,12)
+    case GST_VIDEO_FORMAT_ARGB:
+#endif
 #if SCHRO_CHECK_VERSION(1,0,11)
     case GST_VIDEO_FORMAT_Y444:
     case GST_VIDEO_FORMAT_AYUV64:
 #endif
       schro_enc->video_format->chroma_format = SCHRO_CHROMA_444;
       break;
-    case GST_VIDEO_FORMAT_ARGB:
-      schro_enc->video_format->chroma_format = SCHRO_CHROMA_420;
-      break;
     default:
       g_assert_not_reached ();
   }
@@ -311,14 +316,12 @@ gst_schro_enc_set_format (GstBaseVideoEncoder * base_video_encoder,
   schro_enc->video_format->aspect_ratio_numerator = state->par_n;
   schro_enc->video_format->aspect_ratio_denominator = state->par_d;
 
-#if SCHRO_CHECK_VERSION(1,0,11)
   switch (state->format) {
     default:
-#endif
       schro_video_format_set_std_signal_range (schro_enc->video_format,
           SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
-#if SCHRO_CHECK_VERSION(1,0,11)
       break;
+#if SCHRO_CHECK_VERSION(1,0,11)
     case GST_VIDEO_FORMAT_v210:
       schro_video_format_set_std_signal_range (schro_enc->video_format,
           SCHRO_SIGNAL_RANGE_10BIT_VIDEO);
@@ -330,8 +333,16 @@ gst_schro_enc_set_format (GstBaseVideoEncoder * base_video_encoder,
       schro_enc->video_format->chroma_offset = 128 << 8;
       schro_enc->video_format->chroma_excursion = 224 << 8;
       break;
-  }
 #endif
+#if SCHRO_CHECK_VERSION(1,0,12)
+    case GST_VIDEO_FORMAT_ARGB:
+      schro_enc->video_format->luma_offset = 256;
+      schro_enc->video_format->luma_excursion = 511;
+      schro_enc->video_format->chroma_offset = 256;
+      schro_enc->video_format->chroma_excursion = 511;
+      break;
+#endif
+  }
 
   schro_video_format_set_std_colour_spec (schro_enc->video_format,
       SCHRO_COLOUR_SPEC_HDTV);
@@ -505,6 +516,7 @@ gst_schro_enc_handle_frame (GstBaseVideoEncoder * base_video_encoder,
     GST_DEBUG ("granule offset %" G_GINT64_FORMAT, schro_enc->granule_offset);
   }
 
+  GST_ERROR ("sink buffer %p", frame->sink_buffer);
   schro_frame = gst_schro_buffer_wrap (gst_buffer_ref (frame->sink_buffer),
       state->format, state->width, state->height);
 
index 5ee2317..f23abf7 100644 (file)
@@ -72,6 +72,12 @@ gst_schro_buffer_wrap (GstBuffer * buf, GstVideoFormat format, int width,
       frame =
           schro_frame_new_from_data_AYUV (GST_BUFFER_DATA (buf), width, height);
       break;
+#if SCHRO_CHECK_VERSION(1,0,12)
+    case GST_VIDEO_FORMAT_ARGB:
+      frame =
+          schro_frame_new_from_data_ARGB (GST_BUFFER_DATA (buf), width, height);
+      break;
+#endif
 #if SCHRO_CHECK_VERSION(1,0,11)
     case GST_VIDEO_FORMAT_Y42B:
       frame =
@@ -94,27 +100,6 @@ gst_schro_buffer_wrap (GstBuffer * buf, GstVideoFormat format, int width,
           schro_frame_new_from_data_AY64 (GST_BUFFER_DATA (buf), width, height);
       break;
 #endif
-#if 0
-    case GST_VIDEO_FORMAT_ARGB:
-    {
-      SchroFrame *rgbframe =
-          schro_frame_new_from_data_AYUV (GST_BUFFER_DATA (buf), width, height);
-      SchroFrame *vframe1;
-      SchroFrame *vframe2;
-      SchroFrame *vframe3;
-
-      vframe1 = schro_virt_frame_new_unpack (rgbframe);
-      vframe2 = schro_virt_frame_new_color_matrix (vframe1);
-      vframe3 =
-          schro_virt_frame_new_subsample (vframe2, SCHRO_FRAME_FORMAT_U8_420);
-
-      frame = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
-          width, height);
-      schro_virt_frame_render (vframe3, frame);
-      schro_frame_unref (vframe3);
-    }
-      break;
-#endif
     default:
       g_assert_not_reached ();
       return NULL;