[Swfdec] 4 commits - libswfdec/swfdec_codec_audio.c libswfdec/swfdec_codec_gst.c libswfdec/swfdec_codec_video.c libswfdec/swfdec_sound.c

Benjamin Otte company at kemper.freedesktop.org
Sun Oct 14 13:02:39 PDT 2007


 libswfdec/swfdec_codec_audio.c |   72 ++++++++++++++++++++++++++++++++---------
 libswfdec/swfdec_codec_gst.c   |   11 +++---
 libswfdec/swfdec_codec_video.c |   64 ++++++++++++++++++++++++++++++------
 libswfdec/swfdec_sound.c       |    1 
 4 files changed, 117 insertions(+), 31 deletions(-)

New commits:
commit f31f005192c5b59e3fa793fef78cc8f06a30ba1b
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 14 21:59:12 2007 +0200

    fix plane computation to be correct
    
    Code is copied from gst-plugins-good/jpeg/gstjpegdec.c

diff --git a/libswfdec/swfdec_codec_gst.c b/libswfdec/swfdec_codec_gst.c
index a125598..08cf154 100644
--- a/libswfdec/swfdec_codec_gst.c
+++ b/libswfdec/swfdec_codec_gst.c
@@ -351,6 +351,7 @@ swfdec_video_decoder_gst_decode (SwfdecVideoDecoder *dec, SwfdecBuffer *buffer,
     SwfdecVideoImage *image)
 {
   SwfdecGstVideo *player = (SwfdecGstVideo *) dec;
+#define ALIGN(x, n) (((x) + (n) - 1) & (~((n) - 1)))
 
   while (player->in != NULL && !player->error) {
     swfdec_cond_wait (player->cond, player->mutex);
@@ -376,12 +377,12 @@ swfdec_video_decoder_gst_decode (SwfdecVideoDecoder *dec, SwfdecBuffer *buffer,
       break;
     case SWFDEC_VIDEO_FORMAT_I420:
       image->plane[0] = player->out->data;
-      image->rowstride[0] = player->width;
-      image->plane[1] = image->plane[0] + player->width * player->height;
-      image->rowstride[1] = (player->width + 1) / 2;
-      image->plane[2] = image->plane[1] + image->rowstride[1] * ((player->height + 1) / 2);
+      image->rowstride[0] = ALIGN (player->width, 4);
+      image->plane[1] = image->plane[0] + image->rowstride[0] * ALIGN (player->height, 2);
+      image->rowstride[1] = ALIGN (player->width, 8) / 2;
+      image->plane[2] = image->plane[1] + image->rowstride[1] * ALIGN (player->height, 2) / 2;
       image->rowstride[2] = image->rowstride[1];
-      g_assert (image->plane[2] + (image->rowstride[2] * ((player->height + 1) / 2)) == image->plane[0] + player->out->size);
+      g_assert (image->plane[2] + image->rowstride[2] * ALIGN (player->height, 2) / 2 == image->plane[0] + player->out->size);
       break;
   }
   return TRUE;
commit cba64ff0c2275420c7f251fc6d90467be3d3353b
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 14 21:26:49 2007 +0200

    free the reserved cache space on error

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index e4e9086..f086849 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -203,6 +203,7 @@ 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;
   }
   tmp = swfdec_buffer_queue_pull (queue, depth);
commit b083f36d612e43ae936073772857075c959079ad
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 14 21:21:46 2007 +0200

    allow env vars SWFDEC_CODEC_VIDEO or SWFDEC_CODEC for limiting codec options
    
    the env vars should be set to a colon-seperated list of codecs to try. The
    first one available is taken. Possible values are "builtin", "mad", "ffmpeg"
    and "gst". Other values are ignored.

diff --git a/libswfdec/swfdec_codec_audio.c b/libswfdec/swfdec_codec_audio.c
index a42dba8..bdf33f3 100644
--- a/libswfdec/swfdec_codec_audio.c
+++ b/libswfdec/swfdec_codec_audio.c
@@ -109,6 +109,35 @@ swfdec_audio_decoder_uncompressed_new (SwfdecAudioCodec type, SwfdecAudioFormat
 
 /*** PUBLIC API ***/
 
+static SwfdecAudioDecoder *
+swfdec_audio_decoder_builtin_new (SwfdecAudioCodec codec, SwfdecAudioFormat format)
+{
+  SwfdecAudioDecoder *ret;
+
+  ret = swfdec_audio_decoder_uncompressed_new (codec, format);
+  if (ret == NULL)
+    ret = swfdec_audio_decoder_adpcm_new (codec, format);
+
+  return ret;
+}
+
+struct {
+  const char *		name;
+  SwfdecAudioDecoder *	(* func) (SwfdecAudioCodec, SwfdecAudioFormat);
+} audio_codecs[] = {
+  { "builtin",	swfdec_audio_decoder_builtin_new },
+#ifdef HAVE_MAD
+  { "mad",	swfdec_audio_decoder_mad_new },
+#endif
+#ifdef HAVE_GST
+  { "gst",	swfdec_audio_decoder_gst_new },
+#endif
+#ifdef HAVE_FFMPEG
+  { "ffmpeg",	swfdec_audio_decoder_ffmpeg_new },
+#endif
+  { NULL, }
+};
+
 /**
  * swfdec_audio_decoder_new:
  * @format: #SwfdecAudioCodec to decode
@@ -122,24 +151,37 @@ SwfdecAudioDecoder *
 swfdec_audio_decoder_new (SwfdecAudioCodec codec, SwfdecAudioFormat format)
 {
   SwfdecAudioDecoder *ret;
+  const char *list;
 
   g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (format), NULL);
 
-  ret = swfdec_audio_decoder_uncompressed_new (codec, format);
-  if (ret == NULL)
-    ret = swfdec_audio_decoder_adpcm_new (codec, format);
-#ifdef HAVE_MAD
-  if (ret == NULL)
-    ret = swfdec_audio_decoder_mad_new (codec, format);
-#endif
-#ifdef HAVE_FFMPEG
-  if (ret == NULL)
-    ret = swfdec_audio_decoder_ffmpeg_new (codec, format);
-#endif
-#ifdef HAVE_GST
-  if (ret == NULL)
-    ret = swfdec_audio_decoder_gst_new (codec, format);
-#endif
+  list = g_getenv ("SWFDEC_CODEC_AUDIO");
+  if (list == NULL)
+    list = g_getenv ("SWFDEC_CODEC");
+  if (list == NULL) {
+    guint i;
+    for (i = 0; audio_codecs[i].name != NULL; i++) {
+      ret = audio_codecs[i].func (codec, format);
+      if (ret)
+	break;
+    }
+  } else {
+    char **split = g_strsplit (list, ":", -1);
+    guint i, j;
+    ret = NULL;
+    SWFDEC_LOG ("codecs limited to \"%s\"", list);
+    for (i = 0; split[i] != NULL && ret == NULL; i++) {
+      for (j = 0; audio_codecs[j].name != NULL; j++) {
+	if (g_ascii_strcasecmp (audio_codecs[j].name, split[i]) != 0)
+	  continue;
+	ret = audio_codecs[j].func (codec, format);
+	if (ret)
+	  break;
+      }
+    }
+    g_strfreev (split);
+  }
+
   if (ret) {
     ret->codec = codec;
     g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (ret->format), NULL);
commit 3ca6fc618facfd4ad5699070806d374b0714d901
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 14 21:12:01 2007 +0200

    allow env vars SWFDEC_CODEC_VIDEO or SWFDEC_CODEC for limiting codec options
    
    the env vars should be set to a colon-seperated list of codecs to try. The
    first one available is taken. Possible values are "builtin", "ffmpeg" and "gst".
    Other values are ignored.

diff --git a/libswfdec/swfdec_codec_video.c b/libswfdec/swfdec_codec_video.c
index e088d00..bdcce56 100644
--- a/libswfdec/swfdec_codec_video.c
+++ b/libswfdec/swfdec_codec_video.c
@@ -27,6 +27,32 @@
 #include "swfdec_debug.h"
 #include "swfdec_internal.h"
 
+static SwfdecVideoDecoder *
+swfdec_video_decoder_builtin_new (SwfdecVideoCodec codec)
+{
+  SwfdecVideoDecoder *ret;
+
+  ret = swfdec_video_decoder_screen_new (codec);
+  if (ret == NULL)
+    ret = swfdec_video_decoder_vp6_alpha_new (codec);
+
+  return ret;
+}
+
+struct {
+  const char *		name;
+  SwfdecVideoDecoder *	(* func) (SwfdecVideoCodec);
+} video_codecs[] = {
+  { "builtin",	swfdec_video_decoder_builtin_new },
+#ifdef HAVE_FFMPEG
+  { "ffmpeg",	swfdec_video_decoder_ffmpeg_new },
+#endif
+#ifdef HAVE_GST
+  { "gst",	swfdec_video_decoder_gst_new },
+#endif
+  { NULL, }
+};
+
 /**
  * swfdec_video_decoder_new:
  * @codec: #SwfdecVideoCodec to create the #SwfdecVideoDecoder for
@@ -40,18 +66,34 @@ SwfdecVideoDecoder *
 swfdec_video_decoder_new (SwfdecVideoCodec codec)
 {
   SwfdecVideoDecoder *ret;
+  const char *list;
 
-  ret = swfdec_video_decoder_screen_new (codec);
-  if (ret == NULL)
-    ret = swfdec_video_decoder_vp6_alpha_new (codec);
-#ifdef HAVE_FFMPEG
-  if (ret == NULL)
-    ret = swfdec_video_decoder_ffmpeg_new (codec);
-#endif
-#ifdef HAVE_GST
-  if (ret == NULL)
-    ret = swfdec_video_decoder_gst_new (codec);
-#endif
+  list = g_getenv ("SWFDEC_CODEC_VIDEO");
+  if (list == NULL)
+    list = g_getenv ("SWFDEC_CODEC");
+  if (list == NULL) {
+    guint i;
+    for (i = 0; video_codecs[i].name != NULL; i++) {
+      ret = video_codecs[i].func (codec);
+      if (ret)
+	break;
+    }
+  } else {
+    char **split = g_strsplit (list, ":", -1);
+    guint i, j;
+    ret = NULL;
+    SWFDEC_LOG ("codecs limited to \"%s\"", list);
+    for (i = 0; split[i] != NULL && ret == NULL; i++) {
+      for (j = 0; video_codecs[j].name != NULL; j++) {
+	if (g_ascii_strcasecmp (video_codecs[j].name, split[i]) != 0)
+	  continue;
+	ret = video_codecs[j].func (codec);
+	if (ret)
+	  break;
+      }
+    }
+    g_strfreev (split);
+  }
 
   if (ret != NULL) {
     ret->codec = codec;


More information about the Swfdec mailing list