flacdec: Improve debugging and add some FIXMEs
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 26 Mar 2010 13:55:53 +0000 (14:55 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 26 Mar 2010 13:55:53 +0000 (14:55 +0100)
ext/flac/gstflacdec.c

index 309854a..e20c3f2 100644 (file)
@@ -436,6 +436,10 @@ gst_flac_dec_scan_got_frame (GstFlacDec * flacdec, guint8 * data, guint size,
   else if (sr == 0x0D || sr == 0x0E)
     sr_from_end = 16;
 
+  /* FIXME: This is can be 36 bit if variable block size is used,
+   * fortunately not encoder supports this yet and we check for that
+   * above.
+   */
   val = (guint32) g_utf8_get_char_validated ((gchar *) data + 4, -1);
 
   if (val == (guint32) - 1 || val == (guint32) - 2) {
@@ -446,16 +450,22 @@ gst_flac_dec_scan_got_frame (GstFlacDec * flacdec, guint8 * data, guint size,
   headerlen = 4 + g_unichar_to_utf8 ((gunichar) val, NULL) +
       (bs_from_end / 8) + (sr_from_end / 8);
 
-  if (gst_flac_calculate_crc8 (data, headerlen) != data[headerlen])
+  if (gst_flac_calculate_crc8 (data, headerlen) != data[headerlen]) {
+    GST_LOG_OBJECT (flacdec, "invalid checksum");
     return FALSE;
+  }
 
   if (flacdec->min_blocksize == flacdec->max_blocksize) {
     *last_sample_num = (val + 1) * flacdec->min_blocksize;
   } else {
-    *last_sample_num = val;     /* FIXME: + length of last block in samples */
+    *last_sample_num = 0;       /* FIXME: + length of last block in samples */
   }
 
-  if (flacdec->sample_rate > 0) {
+  /* FIXME: only valid for fixed block size streams */
+  GST_DEBUG_OBJECT (flacdec, "frame number: %" G_GINT64_FORMAT,
+      *last_sample_num);
+
+  if (flacdec->sample_rate > 0 && *last_sample_num != 0) {
     GST_DEBUG_OBJECT (flacdec, "last sample %" G_GINT64_FORMAT " = %"
         GST_TIME_FORMAT, *last_sample_num,
         GST_TIME_ARGS (*last_sample_num * GST_SECOND / flacdec->sample_rate));
@@ -470,7 +480,6 @@ static void
 gst_flac_dec_scan_for_last_block (GstFlacDec * flacdec, gint64 * samples)
 {
   GstFormat format = GST_FORMAT_BYTES;
-
   gint64 file_size, offset;
 
   GST_INFO_OBJECT (flacdec, "total number of samples unknown, scanning file");
@@ -480,6 +489,12 @@ gst_flac_dec_scan_for_last_block (GstFlacDec * flacdec, gint64 * samples)
     return;
   }
 
+  if (flacdec->min_blocksize != flacdec->max_blocksize) {
+    GST_WARNING_OBJECT (flacdec, "scanning for last sample only works "
+        "for FLAC files with constant blocksize");
+    return;
+  }
+
   GST_DEBUG_OBJECT (flacdec, "upstream size: %" G_GINT64_FORMAT, file_size);
 
   offset = file_size - 1;