[Swfdec] 5 commits - libswfdec/swfdec_as_object.c libswfdec/swfdec_audio.c libswfdec/swfdec_sound.c libswfdec/swfdec_xml.c

Pekka Lampila medar at kemper.freedesktop.org
Wed Oct 31 03:13:37 PDT 2007


 libswfdec/swfdec_as_object.c |   20 +++++++++++++-------
 libswfdec/swfdec_audio.c     |    2 +-
 libswfdec/swfdec_sound.c     |   20 +++++++-------------
 libswfdec/swfdec_xml.c       |    2 +-
 4 files changed, 22 insertions(+), 22 deletions(-)

New commits:
commit cd8a1b3eb4192c51b5787f53071e17270b5d2cca
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 31 12:08:50 2007 +0200

    Fix a mistake in swfdec_xml_unescape leading to invalid UTF-8 on version 5

diff --git a/libswfdec/swfdec_xml.c b/libswfdec/swfdec_xml.c
index f447e46..37174bc 100644
--- a/libswfdec/swfdec_xml.c
+++ b/libswfdec/swfdec_xml.c
@@ -133,7 +133,7 @@ swfdec_xml_unescape_len (SwfdecAsContext *cx, const char *orginal,
       if (!g_ascii_strncasecmp (p, xml_entities[i].escaped,
 	    strlen (xml_entities[i].escaped))) {
 	// FIXME: Do this cleaner
-	if (cx->version > 5 && xml_entities[i].character == '\xa0')
+	if (xml_entities[i].character == '\xa0')
 	  string = g_string_append_c (string, '\xc2');
 	string = g_string_append_c (string, xml_entities[i].character);
 	p += strlen (xml_entities[i].escaped);
commit 813bf7cc84c4d188074a72ad49ad6f79305f7f4e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 31 11:22:00 2007 +0200

    Fix asserts in swfdec_as_object_decode

diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 682cb2b..d0709ac 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -1557,7 +1557,7 @@ swfdec_as_object_decode (SwfdecAsObject *object, const char *str)
 {
   SwfdecAsContext *cx = object->context;
   SwfdecAsValue val;
-  char **varlist, *p;
+  char **varlist, *p, *unescaped;
   guint i;
 
   varlist = g_strsplit (str, "&", -1);
@@ -1571,15 +1571,21 @@ swfdec_as_object_decode (SwfdecAsObject *object, const char *str)
     }
 
     if (p != NULL) {
-      SWFDEC_AS_VALUE_SET_STRING (&val,
-	  swfdec_as_context_give_string (object->context, 
-	    swfdec_as_string_unescape (cx, p)));
+      unescaped = swfdec_as_string_unescape (cx, p);
+      if (unescaped != NULL) {
+	SWFDEC_AS_VALUE_SET_STRING (&val,
+	    swfdec_as_context_give_string (cx, unescaped));
+      } else {
+	SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_EMPTY);
+      }
     } else {
       SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_EMPTY);
     }
-    swfdec_as_object_set_variable (object,
-	swfdec_as_context_give_string (object->context, 
-	  swfdec_as_string_unescape (cx, varlist[i])), &val);
+    unescaped = swfdec_as_string_unescape (cx, varlist[i]);
+    if (unescaped != NULL) {
+      swfdec_as_object_set_variable (object,
+	  swfdec_as_context_give_string (cx, unescaped), &val);
+    }
   }
   g_strfreev (varlist);
 }
commit 28aa42cf849bfb39112e0e2c366b08ece2372845
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Tue Oct 30 19:28:22 2007 +0200

    Previous way of reading sound envelopes was still somewhat off, fixed

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 0e7f831..3e9da94 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -303,8 +303,7 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id)
   int has_loops;
   int has_out_point;
   int has_in_point;
-  guint i, j, n_envelopes;
-  GArray *envelopes;
+  guint i, j;
   SwfdecSound *sound;
   SwfdecSoundChunk *chunk;
 
@@ -352,47 +351,29 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id)
     chunk->loop_count = 1;
   }
   if (has_envelope) {
-    n_envelopes = swfdec_bits_get_u8 (b);
-    if (n_envelopes > 0) {
-      envelopes = g_array_sized_new (FALSE, FALSE,
-	  sizeof (SwfdecSoundEnvelope), n_envelopes);
-    }
+    chunk->n_envelopes = swfdec_bits_get_u8 (b);
+    chunk->envelope = g_new0 (SwfdecSoundEnvelope, chunk->n_envelopes);
     SWFDEC_LOG ("  n_envelopes = %u", chunk->n_envelopes);
-  } else {
-    n_envelopes = 0;
   }
 
-  for (i = 0; i < n_envelopes; i++) {
-    SwfdecSoundEnvelope envelope;
+  for (i = 0; i < chunk->n_envelopes; i++) {
+    chunk->envelope[i].offset = swfdec_bits_get_u32 (b);
+    if (i > 0 && chunk->envelope[i-1].offset > chunk->envelope[i].offset) {
+      SWFDEC_ERROR ("unordered sound envelopes");
+      chunk->envelope[i].offset = chunk->envelope[i-1].offset;
+    }
 
-    envelope.offset = swfdec_bits_get_u32 (b);
     for (j = 0; j < 2; j++) {
-      envelope.volume[j] = swfdec_bits_get_u16 (b);
-      if (envelope.volume[j] > 32768) {
+      chunk->envelope[i].volume[j] = swfdec_bits_get_u16 (b);
+      if (chunk->envelope[i].volume[j] > 32768) {
 	SWFDEC_ERROR ("envelope volume too big: %u > 32768",
-	    envelope.volume[j]);
-	envelope.volume[j] = 32768;
+	    chunk->envelope[i].volume[j]);
+	chunk->envelope[i].volume[j] = 32768;
       }
     }
 
-    if (envelopes->len > 0 && envelope.offset <= g_array_index (envelopes,
-	  SwfdecSoundEnvelope, envelopes->len - 1).offset) {
-      /* FIXME: what to do if == */
-      SWFDEC_ERROR ("sound envelope offset not sorted, ignoring");
-      continue;
-    }
-
-    envelopes = g_array_append_val (envelopes, envelope);
-
     SWFDEC_LOG ("    envelope = %u { %u, %u }", chunk->envelope[i].offset,
 	(guint) chunk->envelope[i].volume[0], (guint) chunk->envelope[i].volume[1]);
-    /* FIXME: check that mono sound gets averaged and then do this here? */
-  }
-
-  if (n_envelopes > 0) {
-    SWFDEC_FIXME ("Support for sound envelopes missing");
-    chunk->n_envelopes = envelopes->len;
-    chunk->envelope = (SwfdecSoundEnvelope *)g_array_free (envelopes, FALSE);
   }
 
   return chunk;
commit de501b9c73e5ee6de3ea742a4f43e7d37935eec5
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Tue Oct 30 19:10:13 2007 +0200

    Fix g_return_val_if_fail with a wrong return value

diff --git a/libswfdec/swfdec_audio.c b/libswfdec/swfdec_audio.c
index 79af900..f94ea53 100644
--- a/libswfdec/swfdec_audio.c
+++ b/libswfdec/swfdec_audio.c
@@ -290,7 +290,7 @@ swfdec_audio_format_get_rate (SwfdecAudioFormat	format)
 guint
 swfdec_audio_format_get_granularity (SwfdecAudioFormat format)
 {
-  g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (format), 44100);
+  g_return_val_if_fail (SWFDEC_IS_AUDIO_FORMAT (format), 1);
 
   return 1 << (3 - (format >> 2));
 }
commit 56407f55976fc53dad38b4ec6191fd360efcecc1
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Tue Oct 30 10:44:27 2007 +0200

    Fixes to sound envelope parsing

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 2f3dec0..0e7f831 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -303,7 +303,8 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id)
   int has_loops;
   int has_out_point;
   int has_in_point;
-  guint i, j;
+  guint i, j, n_envelopes;
+  GArray *envelopes;
   SwfdecSound *sound;
   SwfdecSoundChunk *chunk;
 
@@ -351,37 +352,49 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id)
     chunk->loop_count = 1;
   }
   if (has_envelope) {
-    SWFDEC_FIXME ("support for sound envelopes not implemented");
-    chunk->n_envelopes = swfdec_bits_get_u8 (b);
-    chunk->envelope = g_new (SwfdecSoundEnvelope, chunk->n_envelopes);
+    n_envelopes = swfdec_bits_get_u8 (b);
+    if (n_envelopes > 0) {
+      envelopes = g_array_sized_new (FALSE, FALSE,
+	  sizeof (SwfdecSoundEnvelope), n_envelopes);
+    }
     SWFDEC_LOG ("  n_envelopes = %u", chunk->n_envelopes);
+  } else {
+    n_envelopes = 0;
   }
 
-  for (i = 0; i < chunk->n_envelopes; i++) {
-    chunk->envelope[i].offset = swfdec_bits_get_u32 (b);
-    if (chunk->envelope[i].offset < chunk->start_sample) {
-      SWFDEC_WARNING ("envelope entry offset too small (%d vs %d)",
-	  chunk->envelope[i].offset, chunk->start_sample);
-      chunk->envelope[i].offset = chunk->start_sample;
-    }
-    if (i > 0 && chunk->envelope[i].offset <=
-	chunk->envelope[i-1].offset) {
-      /* FIXME: figure out how to handle this */
-      SWFDEC_FIXME ("sound envelope offsets not sorted");
-    }
+  for (i = 0; i < n_envelopes; i++) {
+    SwfdecSoundEnvelope envelope;
+
+    envelope.offset = swfdec_bits_get_u32 (b);
     for (j = 0; j < 2; j++) {
-      chunk->envelope[i].volume[j] = swfdec_bits_get_u16 (b);
-      if (chunk->envelope[i].volume[j] > 32768) {
-	SWFDEC_ERROR ("envelope volume too big: %u > 32768", 
-	    chunk->envelope[i].volume[j]);
-	chunk->envelope[i].volume[j] = 32768;
+      envelope.volume[j] = swfdec_bits_get_u16 (b);
+      if (envelope.volume[j] > 32768) {
+	SWFDEC_ERROR ("envelope volume too big: %u > 32768",
+	    envelope.volume[j]);
+	envelope.volume[j] = 32768;
       }
     }
+
+    if (envelopes->len > 0 && envelope.offset <= g_array_index (envelopes,
+	  SwfdecSoundEnvelope, envelopes->len - 1).offset) {
+      /* FIXME: what to do if == */
+      SWFDEC_ERROR ("sound envelope offset not sorted, ignoring");
+      continue;
+    }
+
+    envelopes = g_array_append_val (envelopes, envelope);
+
     SWFDEC_LOG ("    envelope = %u { %u, %u }", chunk->envelope[i].offset,
 	(guint) chunk->envelope[i].volume[0], (guint) chunk->envelope[i].volume[1]);
     /* FIXME: check that mono sound gets averaged and then do this here? */
   }
 
+  if (n_envelopes > 0) {
+    SWFDEC_FIXME ("Support for sound envelopes missing");
+    chunk->n_envelopes = envelopes->len;
+    chunk->envelope = (SwfdecSoundEnvelope *)g_array_free (envelopes, FALSE);
+  }
+
   return chunk;
 }
 


More information about the Swfdec mailing list