[Swfdec] 9 commits - configure.ac libswfdec/swfdec_as_context.c libswfdec/swfdec_audio_internal.h libswfdec/swfdec_codec_audio.c libswfdec/swfdec_codec_gst.c libswfdec/swfdec_sound.c

Benjamin Otte company at kemper.freedesktop.org
Sun Oct 28 14:50:13 PDT 2007


 configure.ac                      |    8 ++---
 libswfdec/swfdec_as_context.c     |   14 ++++-----
 libswfdec/swfdec_audio_internal.h |    1 
 libswfdec/swfdec_codec_audio.c    |   12 +++++++-
 libswfdec/swfdec_codec_gst.c      |   54 +++++++++++++++++++++++++++++++-------
 libswfdec/swfdec_sound.c          |   11 +++----
 6 files changed, 72 insertions(+), 28 deletions(-)

New commits:
commit 35fdb57f33b63f078b0fa7062d0b970c7c739c7e
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:49:46 2007 +0100

    disable ffmpeg and mad backends in default configure

diff --git a/configure.ac b/configure.ac
index 296b09b..4f164b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,9 +188,9 @@ fi
 
 AC_ARG_ENABLE(mad,
 	AS_HELP_STRING([--enable-mad],
-			[enable mad audio (default=yes)])],
+			[enable mad audio (default=no)])],
 	enable_mad=$enableval,
-	enable_mad="yes")
+	enable_mad="no")
 
 if test "$enable_mad" = "yes"; then
 	AC_CHECK_LIB(mad, mad_decoder_finish, HAVE_MAD="yes" MAD_LIBS="-lmad", HAVE_MAD="no")
@@ -211,9 +211,9 @@ dnl  So you'll have to update your ffmpeg checkout if compilation fails.
 dnl  Or you submit a patch that detects ffmpeg reliably on the distros.
 AC_ARG_ENABLE(ffmpeg,
 	AS_HELP_STRING([--enable-ffmpeg],
-			[enable ffmpeg support (default=yes)])],
+			[enable ffmpeg support (default=no)])],
 	enable_ffmpeg=$enableval,
-	enable_ffmpeg="yes")
+	enable_ffmpeg="no")
 
 if test "$enable_ffmpeg" = "yes"; then
 	PKG_CHECK_MODULES(FFMPEG, libavcodec libswscale, HAVE_FFMPEG=yes, HAVE_FFMPEG=no)
commit 2aa0918b46d71707d1ca6f1ec22fd47de09bf23b
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:49:26 2007 +0100

    only pop blocks when there's not been an error with the pc before

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 54a1ac8..ca1af3d 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -863,13 +863,6 @@ start:
       pc = frame->pc;
       continue;
     }
-    if (check_block && (pc < frame->block_start || pc >= frame->block_end)) {
-      SWFDEC_LOG ("code exited block");
-      swfdec_as_frame_pop_block (frame);
-      pc = frame->pc;
-      if (frame != context->frame)
-	goto start;
-    }
     if (pc == exitpc) {
       swfdec_as_frame_return (frame, NULL);
       goto start;
@@ -878,6 +871,13 @@ start:
       SWFDEC_ERROR ("pc %p not in valid range [%p, %p) anymore", pc, startpc, endpc);
       goto error;
     }
+    if (check_block && (pc < frame->block_start || pc >= frame->block_end)) {
+      SWFDEC_LOG ("code exited block");
+      swfdec_as_frame_pop_block (frame);
+      pc = frame->pc;
+      if (frame != context->frame)
+	goto start;
+    }
 
     /* decode next action */
     action = *pc;
commit 397be351d19a0f66a2b0b4836416a67b0098d233
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:49:01 2007 +0100

    rewrite to allow any output format
    
    This gets rid of long lags when audioresample takes its time

diff --git a/libswfdec/swfdec_codec_gst.c b/libswfdec/swfdec_codec_gst.c
index b449533..35f00e5 100644
--- a/libswfdec/swfdec_codec_gst.c
+++ b/libswfdec/swfdec_codec_gst.c
@@ -148,14 +148,16 @@ swfdec_gst_get_element (GstCaps *caps)
 static GstPad *
 swfdec_gst_connect_srcpad (GstElement *element, GstCaps *caps)
 {
+  GstPadTemplate *tmpl;
   GstPad *srcpad, *sinkpad;
 
   sinkpad = gst_element_get_pad (element, "sink");
   if (sinkpad == NULL)
     return NULL;
-  srcpad = gst_pad_new ("src", GST_PAD_SRC);
-  if (!gst_pad_set_caps (srcpad, caps))
-    goto error;
+  gst_caps_ref (caps);
+  tmpl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
+  srcpad = gst_pad_new_from_template (tmpl, "src");
+  g_object_unref (tmpl);
   if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
     goto error;
   
@@ -173,14 +175,16 @@ error:
 static GstPad *
 swfdec_gst_connect_sinkpad (GstElement *element, GstCaps *caps)
 {
+  GstPadTemplate *tmpl;
   GstPad *srcpad, *sinkpad;
 
   srcpad = gst_element_get_pad (element, "src");
   if (srcpad == NULL)
     return NULL;
-  sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
-  if (!gst_pad_set_caps (sinkpad, caps))
-    goto error;
+  gst_caps_ref (caps);
+  tmpl = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
+  sinkpad = gst_pad_new_from_template (tmpl, "sink");
+  g_object_unref (tmpl);
   if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
     goto error;
   
@@ -279,6 +283,12 @@ swfdec_gst_decoder_push (SwfdecGstDecoder *dec, GstBuffer *buffer)
   if (caps) {
     gst_caps_unref (caps);
   } else {
+    caps = GST_PAD_CAPS (dec->src);
+    if (caps == NULL) {
+      caps = (GstCaps *) gst_pad_get_pad_template_caps (dec->src);
+      g_assert (gst_caps_is_fixed (caps));
+      gst_pad_set_caps (dec->src, caps);
+    }
     gst_buffer_set_caps (buffer, GST_PAD_CAPS (dec->src));
   }
 
@@ -370,6 +380,30 @@ swfdec_audio_decoder_gst_pull (SwfdecAudioDecoder *dec)
   return swfdec_buffer_new_from_gst (buf);
 }
 
+static gboolean
+swfdec_audio_decoder_set_caps (GstPad *pad, GstCaps *caps)
+{
+  SwfdecGstAudio *player = g_object_get_data (G_OBJECT (pad), "swfdec-player");
+  GstStructure *structure = gst_caps_get_structure (caps, 0);
+  int depth, channels, rate;
+
+  if (SWFDEC_IS_AUDIO_FORMAT (player->decoder.format)) {
+    SWFDEC_ERROR ("resetting format not allowed");
+    player->error = TRUE;
+    return FALSE;
+  }
+  if (!gst_structure_get_int (structure, "depth", &depth) ||
+      !gst_structure_get_int (structure, "rate", &rate) ||
+      !gst_structure_get_int (structure, "channels", &channels)) {
+    SWFDEC_ERROR ("invalid caps");
+    player->error = TRUE;
+    return FALSE;
+  }
+
+  player->decoder.format = swfdec_audio_format_new (rate, channels, depth == 16 ? TRUE : FALSE);
+  return TRUE;
+}
+
 SwfdecAudioDecoder *
 swfdec_audio_decoder_gst_new (SwfdecAudioCodec type, SwfdecAudioFormat format)
 {
@@ -389,7 +423,7 @@ swfdec_audio_decoder_gst_new (SwfdecAudioCodec type, SwfdecAudioFormat format)
   g_assert (srccaps);
 
   player = g_slice_new0 (SwfdecGstAudio);
-  player->decoder.format = swfdec_audio_format_new (44100, 2, TRUE);
+  player->decoder.format = SWFDEC_AUDIO_FORMAT_INVALID;
   player->decoder.pull = swfdec_audio_decoder_gst_pull;
   player->decoder.push = swfdec_audio_decoder_gst_push;
   player->decoder.free = swfdec_audio_decoder_gst_free;
@@ -402,17 +436,19 @@ swfdec_audio_decoder_gst_new (SwfdecAudioCodec type, SwfdecAudioFormat format)
   /* create audioconvert */
   gst_caps_unref (srccaps);
   srccaps = sinkcaps;
-  sinkcaps = gst_caps_from_string ("audio/x-raw-int, endianness=byte_order, signed=(boolean)true, width=16, depth=16, channels=2");
+  sinkcaps = gst_caps_from_string ("audio/x-raw-int, endianness=byte_order, signed=(boolean)true, width=16, depth=16, channels={2,1}");
   g_assert (sinkcaps);
   if (!swfdec_gst_decoder_init (&player->convert, "audioconvert", srccaps, sinkcaps))
     goto error;
   /* create audiorate */
   gst_caps_unref (srccaps);
   srccaps = sinkcaps;
-  sinkcaps = gst_caps_from_string ("audio/x-raw-int, endianness=byte_order, signed=(boolean)true, width=16, depth=16, rate=44100, channels=2");
+  sinkcaps = gst_caps_from_string ("audio/x-raw-int, endianness=byte_order, signed=(boolean)true, width=16, depth=16, rate={44100, 22050, 11025, 5512}, channels={2,1}");
   g_assert (sinkcaps);
   if (!swfdec_gst_decoder_init (&player->resample, "audioresample", srccaps, sinkcaps))
     goto error;
+  g_object_set_data (G_OBJECT (player->resample.sink), "swfdec-player", player);
+  gst_pad_set_setcaps_function (player->resample.sink, swfdec_audio_decoder_set_caps);
 
   gst_caps_unref (srccaps);
   gst_caps_unref (sinkcaps);
commit 6acb15e98eba17213203e44bcd15f2b327ebf02f
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:47:53 2007 +0100

    only require a sane format if a buffer was returned

diff --git a/libswfdec/swfdec_codec_audio.c b/libswfdec/swfdec_codec_audio.c
index 770027c..5e8b9aa 100644
--- a/libswfdec/swfdec_codec_audio.c
+++ b/libswfdec/swfdec_codec_audio.c
@@ -276,6 +276,8 @@ swfdec_audio_decoder_pull (SwfdecAudioDecoder *decoder)
   g_return_val_if_fail (decoder != NULL, NULL);
 
   ret = decoder->pull (decoder);
+  if (ret == NULL)
+    return NULL;
   g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (decoder->format), ret);
   return ret;
 }
commit c99e09aea38c969959691d2198c102ed17871857
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:39:09 2007 +0100

    check the audio format is valid after pulling

diff --git a/libswfdec/swfdec_codec_audio.c b/libswfdec/swfdec_codec_audio.c
index 0c5ba5c..770027c 100644
--- a/libswfdec/swfdec_codec_audio.c
+++ b/libswfdec/swfdec_codec_audio.c
@@ -185,7 +185,6 @@ swfdec_audio_decoder_new (SwfdecAudioCodec codec, SwfdecAudioFormat format)
 
   if (ret) {
     ret->codec = codec;
-    g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (ret->format), NULL);
     g_return_val_if_fail (ret->push, NULL);
     g_return_val_if_fail (ret->pull, NULL);
     g_return_val_if_fail (ret->free, NULL);
@@ -272,8 +271,12 @@ swfdec_audio_decoder_push (SwfdecAudioDecoder *decoder, SwfdecBuffer *buffer)
 SwfdecBuffer *
 swfdec_audio_decoder_pull (SwfdecAudioDecoder *decoder)
 {
+  SwfdecBuffer *ret;
+
   g_return_val_if_fail (decoder != NULL, NULL);
 
-  return decoder->pull (decoder);
+  ret = decoder->pull (decoder);
+  g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (decoder->format), ret);
+  return ret;
 }
 
commit 82bd44abf501719be638d4c97ed834c6899eb670
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 22:38:48 2007 +0100

    query the format before destroying the decoder (oops)

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 352d6ae..64e22a3 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -194,6 +194,7 @@ swfdec_sound_get_decoded (SwfdecSound *sound, SwfdecAudioFormat *format)
   while ((tmp = swfdec_audio_decoder_pull (decoder))) {
     swfdec_buffer_queue_push (queue, tmp);
   }
+  sound->decoded_format = swfdec_audio_decoder_get_format (decoder);
   swfdec_audio_decoder_free (decoder);
   depth = swfdec_buffer_queue_get_depth (queue);
   if (depth == 0) {
@@ -204,7 +205,6 @@ swfdec_sound_get_decoded (SwfdecSound *sound, SwfdecAudioFormat *format)
   tmp = swfdec_buffer_queue_pull (queue, depth);
   swfdec_buffer_queue_unref (queue);
 
-  sound->decoded_format = swfdec_audio_decoder_get_format (decoder);
   sample_bytes = swfdec_audio_format_get_bytes_per_sample (sound->decoded_format);
   n_samples = sound->n_samples / swfdec_audio_format_get_granularity (sound->decoded_format);
 
commit 43c2c77acd07323c9fe8d395ec58b782222f2a70
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 21:58:33 2007 +0100

    make sure the sound format only gets requested after decoding

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 8bf57e5..352d6ae 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -187,11 +187,6 @@ swfdec_sound_get_decoded (SwfdecSound *sound, SwfdecAudioFormat *format)
   decoder = swfdec_audio_decoder_new (sound->codec, sound->format);
   if (decoder == NULL)
     return NULL;
-  sound->decoded_format = swfdec_audio_decoder_get_format (decoder);
-  sample_bytes = swfdec_audio_format_get_bytes_per_sample (sound->decoded_format);
-  n_samples = sound->n_samples / swfdec_audio_format_get_granularity (sound->decoded_format);
-  /* FIXME: The size is only a guess */
-  swfdec_cached_load (SWFDEC_CACHED (sound), n_samples * sample_bytes);
 
   swfdec_audio_decoder_push (decoder, sound->encoded);
   swfdec_audio_decoder_push (decoder, NULL);
@@ -203,12 +198,16 @@ swfdec_sound_get_decoded (SwfdecSound *sound, SwfdecAudioFormat *format)
   depth = swfdec_buffer_queue_get_depth (queue);
   if (depth == 0) {
     SWFDEC_ERROR ("decoding didn't produce any data, bailing");
-    swfdec_cached_unload (SWFDEC_CACHED (sound));
     return NULL;
   }
+  swfdec_cached_load (SWFDEC_CACHED (sound), depth);
   tmp = swfdec_buffer_queue_pull (queue, depth);
   swfdec_buffer_queue_unref (queue);
 
+  sound->decoded_format = swfdec_audio_decoder_get_format (decoder);
+  sample_bytes = swfdec_audio_format_get_bytes_per_sample (sound->decoded_format);
+  n_samples = sound->n_samples / swfdec_audio_format_get_granularity (sound->decoded_format);
+
   SWFDEC_LOG ("after decoding, got %u samples, should get %u and skip %u", 
       tmp->length / sample_bytes, n_samples, sound->skip);
   if (sound->skip) {
commit cfb80250d2299f934879187d8e50b514b122ae75
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 21:57:55 2007 +0100

    check the audio format is valid before returning it

diff --git a/libswfdec/swfdec_codec_audio.c b/libswfdec/swfdec_codec_audio.c
index a46b315..0c5ba5c 100644
--- a/libswfdec/swfdec_codec_audio.c
+++ b/libswfdec/swfdec_codec_audio.c
@@ -217,6 +217,8 @@ swfdec_audio_decoder_free (SwfdecAudioDecoder *decoder)
  * @decoder: a #SwfdecAudioDecoder
  *
  * Queries the format that is used by the decoder for its produced output.
+ * The format will only be valid after swfdec_audio_decoder_pull () has been
+ * called at least once.
  *
  * Returns: the format of the decoded data
  **/
@@ -224,6 +226,7 @@ SwfdecAudioFormat
 swfdec_audio_decoder_get_format	(SwfdecAudioDecoder *decoder)
 {
   g_return_val_if_fail (decoder != NULL, 0);
+  g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (decoder->format), 0);
 
   return decoder->format;
 }
commit 61ad3e00c7b966edefbcd6984eff563d0834da9f
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 28 21:52:39 2007 +0100

    add a macro to invalid a value as invalid

diff --git a/libswfdec/swfdec_audio_internal.h b/libswfdec/swfdec_audio_internal.h
index d6b3915..512f6e7 100644
--- a/libswfdec/swfdec_audio_internal.h
+++ b/libswfdec/swfdec_audio_internal.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 typedef guint SwfdecAudioFormat;
 #define SWFDEC_IS_AUDIO_FORMAT(format) ((format) <= 0xF)
+#define SWFDEC_AUDIO_FORMAT_INVALID ((SwfdecAudioFormat) -1)
 
 
 struct _SwfdecAudio {


More information about the Swfdec mailing list