[Swfdec] 5 commits - libswfdec/swfdec_codec_ffmpeg.c libswfdec/swfdec_codec_video.c libswfdec/swfdec_player.c libswfdec/swfdec_video.c

Benjamin Otte company at kemper.freedesktop.org
Wed Sep 5 04:36:51 PDT 2007


 libswfdec/swfdec_codec_ffmpeg.c |   29 ++++++++++++++++++++++++++---
 libswfdec/swfdec_codec_video.c  |   13 +++++++------
 libswfdec/swfdec_player.c       |   16 +++++++++-------
 libswfdec/swfdec_video.c        |    2 ++
 4 files changed, 44 insertions(+), 16 deletions(-)

New commits:
diff-tree 97b081a94b818aedc4c7f9f9aea6d6326ca181d9 (from parents)
Merge: c5a17d5d70c47aa3cdddf31e038126a320e41d1c d16a6e3da03121a68bebcddb33473fda33bdf3db
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Sep 5 13:36:42 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec/swfdec

diff-tree c5a17d5d70c47aa3cdddf31e038126a320e41d1c (from 8ca087c8c351a8aeb09d508b074170f18fb24572)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Sep 5 13:36:04 2007 +0200

    various fixes:
    
    - align and pad input data correctly (FFmpeg is fast, because you do the
      memcpy in your own code!)
    - reallocate the scaling context when the size changes

diff --git a/libswfdec/swfdec_codec_ffmpeg.c b/libswfdec/swfdec_codec_ffmpeg.c
index 9fae7cf..1ed3054 100644
--- a/libswfdec/swfdec_codec_ffmpeg.c
+++ b/libswfdec/swfdec_codec_ffmpeg.c
@@ -208,26 +208,47 @@ typedef struct {
   AVCodecContext *	ctx;		/* out context (d'oh) */
   AVFrame *		frame;		/* the frame we use for decoding */
   struct SwsContext *	sws;		/* the format conversion */
+  int			sws_width;	/* width used in resampler */
+  int			sws_height;	/* height used in resampler */
 } SwfdecVideoDecoderFFMpeg;
 
+#define ALIGNMENT 31
 static SwfdecBuffer *
 swfdec_video_decoder_ffmpeg_decode (SwfdecVideoDecoder *dec, SwfdecBuffer *buffer,
     guint *width, guint *height, guint *rowstride)
 {
   SwfdecVideoDecoderFFMpeg *codec = (SwfdecVideoDecoderFFMpeg *) dec;
-  int got_image;
+  int got_image = 0;
   SwfdecBuffer *ret;
   AVPicture picture;
+  guchar *tmp, *aligned;
 
+  /* fullfill alignment and padding requirements */
+  tmp = g_try_malloc (buffer->length + ALIGNMENT + FF_INPUT_BUFFER_PADDING_SIZE);
+  if (tmp == NULL) {
+    SWFDEC_WARNING ("Could not allocate temporary memory");
+    return NULL;
+  }
+  aligned = (guchar *) (((uintptr_t) tmp + ALIGNMENT) & ~ALIGNMENT);
+  memcpy (aligned, buffer->data, buffer->length);
+  memset (aligned + buffer->length, 0, FF_INPUT_BUFFER_PADDING_SIZE);
   if (avcodec_decode_video (codec->ctx, codec->frame, &got_image, 
-	buffer->data, buffer->length) < 0) {
+	aligned, buffer->length) < 0) {
+    g_free (tmp);
     SWFDEC_WARNING ("error decoding frame");
     return NULL;
   }
+  g_free (tmp);
   if (got_image == 0) {
-    SWFDEC_WARNING ("error: did not get an image from decoding");
+    SWFDEC_WARNING ("did not get an image from decoding");
     return NULL;
   }
+  if (codec->sws &&
+      (codec->sws_width != codec->ctx->width ||
+       codec->sws_height != codec->ctx->height)) {
+    sws_freeContext (codec->sws);
+    codec->sws = NULL;
+  }
   if (codec->sws == NULL) {
     codec->sws = sws_getContext (codec->ctx->width, codec->ctx->height, codec->ctx->pix_fmt,
 	codec->ctx->width, codec->ctx->height, PIX_FMT_RGB32, 0, NULL, NULL, NULL);
@@ -235,6 +256,8 @@ swfdec_video_decoder_ffmpeg_decode (Swfd
       SWFDEC_ERROR ("Could not get conversion context");
       return NULL;
     }
+    codec->sws_width = codec->ctx->width;
+    codec->sws_height = codec->ctx->height;
   }
   ret = swfdec_buffer_new_and_alloc (codec->ctx->width * codec->ctx->height * 4);
   avpicture_fill (&picture, ret->data, PIX_FMT_RGB32, codec->ctx->width,
diff-tree 8ca087c8c351a8aeb09d508b074170f18fb24572 (from ef42d5ca51f0a0a12ba3a87b79240f2348b2d8d2)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Sep 5 12:50:08 2007 +0200

    only do size changes when decoding was successful

diff --git a/libswfdec/swfdec_codec_video.c b/libswfdec/swfdec_codec_video.c
index 51f3b10..842a13d 100644
--- a/libswfdec/swfdec_codec_video.c
+++ b/libswfdec/swfdec_codec_video.c
@@ -101,14 +101,15 @@ swfdec_video_decoder_decode (SwfdecVideo
     tmp = swfdec_buffer_new_subbuffer (buffer, 1, buffer->length - 1);
     buffer = decoder->decode (decoder, tmp, &width, &height, &rowstride);
     swfdec_buffer_unref (tmp);
-    if (wsub >= width || hsub >= height) {
-      SWFDEC_ERROR ("size subtraction too big");
-      if (buffer)
+    if (buffer) {
+      if (wsub >= width || hsub >= height) {
+	SWFDEC_ERROR ("size subtraction too big");
 	swfdec_buffer_unref (buffer);
-      return NULL;
+	return NULL;
+      }
+      width -= wsub;
+      height -= hsub;
     }
-    width -= wsub;
-    height -= hsub;
   } else {
     buffer = decoder->decode (decoder, buffer, &width, &height, &rowstride);
   }
diff-tree ef42d5ca51f0a0a12ba3a87b79240f2348b2d8d2 (from 7cc76a92b7d071df6adb6b4de61d7f1fe47d5472)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Sep 5 12:49:48 2007 +0200

    only iterate audio if there is audio to iterate

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index ff8fc1e..45bbbb3 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1134,13 +1134,15 @@ swfdec_player_do_advance (SwfdecPlayer *
   SWFDEC_DEBUG ("advancing %lu msecs (%u audio frames)", msecs, audio_samples);
 
   player->audio_skip = audio_samples;
-  /* iterate all playing sounds */
-  walk = player->audio;
-  while (walk) {
-    audio = walk->data;
-    walk = walk->next;
-    if (swfdec_audio_iterate (audio, audio_samples) == 0)
-      swfdec_audio_remove (audio);
+  if (audio_samples) {
+    /* iterate all playing sounds */
+    walk = player->audio;
+    while (walk) {
+      audio = walk->data;
+      walk = walk->next;
+      if (swfdec_audio_iterate (audio, audio_samples) == 0)
+	swfdec_audio_remove (audio);
+    }
   }
 
   for (timeout = player->timeouts ? player->timeouts->data : NULL;
diff-tree 7cc76a92b7d071df6adb6b4de61d7f1fe47d5472 (from a84130c80ddc1efbce631010e77e2b1239d967b0)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Sep 5 10:01:35 2007 +0200

    only provide a new image if decoding succeeded

diff --git a/libswfdec/swfdec_video.c b/libswfdec/swfdec_video.c
index 7caaeca..f825e3c 100644
--- a/libswfdec/swfdec_video.c
+++ b/libswfdec/swfdec_video.c
@@ -80,6 +80,8 @@ swfdec_video_input_iterate (SwfdecVideoM
     return;
 
   surface = swfdec_video_decoder_decode (input->decoder, buffer);
+  if (surface == NULL)
+    return;
   swfdec_video_movie_new_image (input->movie, surface);
   cairo_surface_destroy (surface);
 }


More information about the Swfdec mailing list