bilboed gst-ffmpeg: gst-ffmpeg/ gst-ffmpeg/ext/ffmpeg/

[email protected] Wed, 17 Dec 2008 04:05:27 -0800 (PST)
Newsgroups gmane.comp.video.gstreamer.cvs
Message-ID <[email protected]>
CVS Root:       /cvs/gstreamer
Module:         gst-ffmpeg
Changes by:     bilboed
Date:           Wed Dec 17 2008  12:05:27 UTC

Log message:
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ff_aud_caps_new),
(gst_ffmpeg_codecid_to_caps), (gst_ffmpeg_smpfmt_to_caps),
(gst_ffmpeg_codectype_to_caps), (gst_ffmpeg_caps_to_smpfmt),
(gst_ffmpeg_caps_to_codecid), (av_smp_format_depth):
* ext/ffmpeg/gstffmpegcodecmap.h:
Add mapping for EAC3 and QCELP audio codecs.
Add conversion functions for all available audo SampleFormat.
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_open),
(gst_ffmpegdec_setcaps), (gst_ffmpegdec_negotiate),
(clip_audio_buffer), (gst_ffmpegdec_audio_frame):
Remove assumptions that we can only handle stereo 16bit signed integer
audio, and store the depth locally.

Modified files:
    .               : ChangeLog
    ext/ffmpeg      : gstffmpegcodecmap.c gstffmpegcodecmap.h
                      gstffmpegdec.c

Links:
http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ChangeLog.diff?r1=1.537&r2=1.538
http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.c.diff?r1=1.174&r2=1.175
http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.h.diff?r1=1.26&r2=1.27
http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegdec.c.diff?r1=1.216&r2=1.217

====Begin Diffs====
Index: ChangeLog
===================================================================
RCS file: /cvs/gstreamer/gst-ffmpeg/ChangeLog,v
retrieving revision 1.537
retrieving revision 1.538
diff -u -d -r1.537 -r1.538
--- ChangeLog	16 Dec 2008 16:21:27 -0000	1.537
+++ ChangeLog	17 Dec 2008 12:05:11 -0000	1.538
@@ -1,3 +1,18 @@
+2008-12-17  Edward Hervey  <[email protected]>
+
+	* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ff_aud_caps_new),
+	(gst_ffmpeg_codecid_to_caps), (gst_ffmpeg_smpfmt_to_caps),
+	(gst_ffmpeg_codectype_to_caps), (gst_ffmpeg_caps_to_smpfmt),
+	(gst_ffmpeg_caps_to_codecid), (av_smp_format_depth):
+	* ext/ffmpeg/gstffmpegcodecmap.h:
+	Add mapping for EAC3 and QCELP audio codecs.
+	Add conversion functions for all available audo SampleFormat.
+	* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_open),
+	(gst_ffmpegdec_setcaps), (gst_ffmpegdec_negotiate),
+	(clip_audio_buffer), (gst_ffmpegdec_audio_frame):
+	Remove assumptions that we can only handle stereo 16bit signed integer
+	audio, and store the depth locally.
 2008-12-16  Stefan Kost  <[email protected]>
 
 	* configure.ac:
Index: gstffmpegcodecmap.c
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -d -r1.174 -r1.175
--- gstffmpegcodecmap.c	13 Dec 2008 08:01:45 -0000	1.174
+++ gstffmpegcodecmap.c	17 Dec 2008 12:05:12 -0000	1.175
@@ -322,6 +322,7 @@
           rates = l_rates;
           break;
         }
+        case CODEC_ID_EAC3:
         case CODEC_ID_AC3:
         {
           const static gint l_rates[] = { 48000, 44100, 32000 };
@@ -361,6 +362,7 @@
      * they support, we whitelist them here. */
     switch (codec_id) {
       case CODEC_ID_AC3:
+      case CODEC_ID_EAC3:
       case CODEC_ID_AAC:
       case CODEC_ID_DTS:
         maxchannels = 6;
@@ -560,6 +562,11 @@
       caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-ac3", NULL);
       break;
+    case CODEC_ID_EAC3:
+      /* FIXME: bitrate */
+      caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-eac3", NULL);
+      break;
     case CODEC_ID_ATRAC3:
       caps = gst_ff_aud_caps_new (context, codec_id, "audio/atrac3", NULL);
@@ -986,6 +993,10 @@
           gst_ff_aud_caps_new (context, codec_id, "audio/x-truespeech", NULL);
+    case CODEC_ID_QCELP:
+      caps = gst_ff_aud_caps_new (context, codec_id, "audio/qcelp", NULL);
     case CODEC_ID_WS_VQA:
     case CODEC_ID_IDCIN:
     case CODEC_ID_8BPS:
@@ -1529,6 +1540,7 @@
   GstCaps *caps = NULL;
   int bpp = 0;
+  gboolean integer = TRUE;
   gboolean signedness = FALSE;
   switch (sample_fmt) {
@@ -1537,16 +1549,36 @@
       bpp = 16;
+    case SAMPLE_FMT_S32:
+      signedness = TRUE;
+      bpp = 32;
+    case SAMPLE_FMT_FLT:
+      integer = FALSE;
+    case SAMPLE_FMT_DBL:
+      bpp = 64;
     default:
       /* .. */
   }
   if (bpp) {
-    caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
-        "signed", G_TYPE_BOOLEAN, signedness,
-        "endianness", G_TYPE_INT, G_BYTE_ORDER,
-        "width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
+    if (integer) {
+      caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
+          "signed", G_TYPE_BOOLEAN, signedness,
+          "endianness", G_TYPE_INT, G_BYTE_ORDER,
+          "width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
+    } else {
+      caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-float",
+          "width", G_TYPE_INT, bpp, NULL);
+    }
   if (caps != NULL) {
@@ -1603,7 +1635,7 @@
         ctx.channels = -1;
         caps = gst_caps_new_empty ();
-        for (i = 0; i <= SAMPLE_FMT_S16; i++) {
+        for (i = 0; i <= SAMPLE_FMT_DBL; i++) {
           temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
           if (temp != NULL) {
             gst_caps_append (caps, temp);
@@ -1646,13 +1678,29 @@
   if (!raw)
     return;
-  if (gst_structure_get_int (structure, "width", &width) &&
-      gst_structure_get_int (structure, "depth", &depth) &&
-      gst_structure_get_boolean (structure, "signed", &signedness) &&
-      gst_structure_get_int (structure, "endianness", &endianness)) {
-    if (width == 16 && depth == 16 &&
-        endianness == G_BYTE_ORDER && signedness == TRUE) {
-      context->sample_fmt = SAMPLE_FMT_S16;
+  if (!strcmp (gst_structure_get_name (structure), "audio/x-raw-float")) {
+    /* FLOAT */
+    if (gst_structure_get_int (structure, "width", &width) &&
+	gst_structure_get_int (structure, "endianness", &endianness)) {
+      if (endianness == G_BYTE_ORDER) {
+	if (width == 32)
+	  context->sample_fmt = SAMPLE_FMT_FLT;
+	else if (width == 64)
+	  context->sample_fmt = SAMPLE_FMT_DBL;
+      }
+  } else {
+    /* INT */
+	gst_structure_get_int (structure, "depth", &depth) &&
+	gst_structure_get_boolean (structure, "signed", &signedness) &&
+	gst_structure_get_int (structure, "endianness", &endianness)) { 
+      if ((endianness == G_BYTE_ORDER) && (signedness == TRUE)) {
+	if ((width == 16) && (depth == 16))
+	  context->sample_fmt = SAMPLE_FMT_S16;
+	else if ((width == 32) && (depth == 32))
+	  context->sample_fmt = SAMPLE_FMT_S32;
     }
 }
@@ -2550,6 +2598,9 @@
   } else if (!strcmp (mimetype, "audio/x-ac3")) {
     id = CODEC_ID_AC3;
     audio = TRUE;
+  } else if (!strcmp (mimetype, "audio/x-eac3")) {
+    id = CODEC_ID_EAC3;
+    audio = TRUE;
   } else if (!strcmp (mimetype, "audio/atrac3")) {
     id = CODEC_ID_ATRAC3;
@@ -2821,6 +2872,9 @@
   } else if (!strcmp (mimetype, "audio/AMR-WB")) {
     id = CODEC_ID_AMR_WB;
+  } else if (!strcmp (mimetype, "audio/qcelp")) {
+    id = CODEC_ID_QCELP;
   } else if (!strcmp (mimetype, "video/x-h264")) {
     id = CODEC_ID_H264;
     video = TRUE;
@@ -3236,3 +3290,28 @@
   return 0;
+gint
+av_smp_format_depth (enum SampleFormat smp_fmt)
+{
+  gint depth = -1;
+  switch (smp_fmt) {
+    case SAMPLE_FMT_U8:
+      depth = 1;
+    case SAMPLE_FMT_S16:
+      depth = 2;
+      depth = 4;
+      depth = 8;
+    default:
+      GST_ERROR ("UNHANDLED SAMPLE FORMAT !");
+  }
+  return depth;
+}
Index: gstffmpegcodecmap.h
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- gstffmpegcodecmap.h	13 Dec 2008 07:55:40 -0000	1.26
+++ gstffmpegcodecmap.h	17 Dec 2008 12:05:12 -0000	1.27
@@ -163,4 +163,7 @@
 void 
 gst_ffmpeg_init_pix_fmt_info();
+av_smp_format_depth(enum SampleFormat smp_fmt);
 #endif /* __GST_FFMPEG_CODECMAP_H__ */
Index: gstffmpegdec.c
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegdec.c,v
retrieving revision 1.216
retrieving revision 1.217
diff -u -d -r1.216 -r1.217
--- gstffmpegdec.c	3 Dec 2008 17:43:45 -0000	1.216
+++ gstffmpegdec.c	17 Dec 2008 12:05:12 -0000	1.217
@@ -67,6 +67,7 @@
     {
       gint channels;
       gint samplerate;
+      gint depth;
     } audio;
   } format;
   gboolean waiting_for_key;
@@ -587,6 +588,7 @@
     case CODEC_TYPE_AUDIO:
       ffmpegdec->format.audio.samplerate = 0;
       ffmpegdec->format.audio.channels = 0;
+      ffmpegdec->format.audio.depth = 0;
@@ -707,8 +709,7 @@
         GST_DEBUG_OBJECT (ffmpegdec, "enabled direct rendering");
         ffmpegdec->current_dr = TRUE;
       }
-    }
-    else {
       GST_DEBUG_OBJECT (ffmpegdec, "direct rendering not supported");
@@ -1075,16 +1076,22 @@
       ffmpegdec->format.video.pix_fmt = ffmpegdec->context->pix_fmt;
+    {
+      gint depth = av_smp_format_depth (ffmpegdec->context->sample_fmt);
       if (ffmpegdec->format.audio.samplerate ==
           ffmpegdec->context->sample_rate &&
-          ffmpegdec->format.audio.channels == ffmpegdec->context->channels)
+          ffmpegdec->format.audio.channels == ffmpegdec->context->channels &&
+          ffmpegdec->format.audio.depth == depth)
         return TRUE;
       GST_DEBUG_OBJECT (ffmpegdec,
-          "Renegotiating audio from %dHz@%dchannels to %dHz@%dchannels",
+          "Renegotiating audio from %dHz@%dchannels (%d) to %dHz@%dchannels (%d)",
           ffmpegdec->format.audio.samplerate, ffmpegdec->format.audio.channels,
-          ffmpegdec->context->sample_rate, ffmpegdec->context->channels);
+          ffmpegdec->format.audio.depth,
+          ffmpegdec->context->sample_rate, ffmpegdec->context->channels, depth);
       ffmpegdec->format.audio.samplerate = ffmpegdec->context->sample_rate;
       ffmpegdec->format.audio.channels = ffmpegdec->context->channels;
+      ffmpegdec->format.audio.depth = depth;
@@ -1738,7 +1745,7 @@
     /* bring clipped time to bytes */
     diff =
         gst_util_uint64_scale_int (diff, dec->format.audio.samplerate,
-        GST_SECOND) * (2 * dec->format.audio.channels);
+        GST_SECOND) * (dec->format.audio.depth * dec->format.audio.channels);
     GST_DEBUG_OBJECT (dec, "clipping start to %" GST_TIME_FORMAT " %"
         G_GINT64_FORMAT " bytes", GST_TIME_ARGS (ctime), diff);
@@ -1750,7 +1757,7 @@
     GST_DEBUG_OBJECT (dec, "clipping stop to %" GST_TIME_FORMAT " %"
         G_GINT64_FORMAT " bytes", GST_TIME_ARGS (cstop), diff);
@@ -1824,7 +1831,8 @@
      *  1) calculate based on number of samples
      */
     in_duration = gst_util_uint64_scale_int (have_data, GST_SECOND,
-        2 * ffmpegdec->context->channels * ffmpegdec->context->sample_rate);
+        ffmpegdec->format.audio.depth * ffmpegdec->format.audio.channels *
+        ffmpegdec->format.audio.samplerate);
     GST_DEBUG_OBJECT (ffmpegdec,
         "Buffer created. Size:%d , timestamp:%" GST_TIME_FORMAT " , duration:%"

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/