Merge commit '38516ad367128d83f9e156529018adb4433cd328' into 0.11
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 27 Feb 2012 00:48:57 +0000 (00:48 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 27 Feb 2012 00:48:57 +0000 (00:48 +0000)
Conflicts:
ext/pulse/pulseaudiosink.c
gst/audioparsers/gstmpegaudioparse.c

1  2 
ext/flac/gstflacenc.c
gst/audioparsers/gstmpegaudioparse.c

Simple merge
@@@ -413,9 -421,8 +416,8 @@@ gst_mp3parse_validate_extended (GstMpeg
            (guint) header, (guint) header & HDRMASK, (guint) next_header,
            (guint) next_header & HDRMASK, bpf);
        *valid = FALSE;
 -      return TRUE;
 +      goto cleanup;
-     } else if ((((next_header >> 12) & 0xf) == 0) ||
-         (((next_header >> 12) & 0xf) == 0xf)) {
+     } else if (((next_header >> 12) & 0xf) == 0xf) {
        /* The essential parts were the same, but the bitrate held an
           invalid value - also reject */
        GST_DEBUG_OBJECT (mp3parse, "next header invalid (bitrate)");
@@@ -484,9 -490,118 +488,118 @@@ gst_mpeg_audio_parse_head_check (GstMpe
    return TRUE;
  }
  
 -static gboolean
 -gst_mpeg_audio_parse_check_valid_frame (GstBaseParse * parse,
 -    GstBaseParseFrame * frame, guint * framesize, gint * skipsize)
+ /* Determines possible freeform frame rate/size by looking for next
+  * header with valid bitrate (0 or otherwise valid) (and sufficiently
+  * matching current header).
+  *
+  * Returns TRUE if we've found such one, and *rate then contains rate
+  * (or *rate contains 0 if decided no freeframe size could be determined).
+  * If not enough data, returns FALSE.
+  */
+ static gboolean
+ gst_mp3parse_find_freerate (GstMpegAudioParse * mp3parse, GstBuffer * buf,
+     guint32 header, gboolean at_eos, gint * _rate)
+ {
+   guint32 next_header;
+   const guint8 *data;
+   guint available;
+   int offset = 4;
+   gulong samplerate, rate, layer, padding;
+   gboolean valid;
+   gint lsf, mpg25;
+   available = GST_BUFFER_SIZE (buf);
+   data = GST_BUFFER_DATA (buf);
+   *_rate = 0;
+   /* pick apart header again partially */
+   if (header & (1 << 20)) {
+     lsf = (header & (1 << 19)) ? 0 : 1;
+     mpg25 = 0;
+   } else {
+     lsf = 1;
+     mpg25 = 1;
+   }
+   layer = 4 - ((header >> 17) & 0x3);
+   samplerate = (header >> 10) & 0x3;
+   samplerate = mp3types_freqs[lsf + mpg25][samplerate];
+   padding = (header >> 9) & 0x1;
+   for (; offset < available; ++offset) {
+     /* Check if we have enough data for all these frames, plus the next
+        frame header. */
+     if (available < offset + 4) {
+       if (at_eos) {
+         /* Running out of data; failed to determine size */
+         return TRUE;
+       } else {
+         return FALSE;
+       }
+     }
+     valid = FALSE;
+     next_header = GST_READ_UINT32_BE (data + offset);
+     if ((next_header & 0xFFE00000) != 0xFFE00000)
+       goto next;
+     GST_DEBUG_OBJECT (mp3parse, "At %d: header=%08X, header2=%08X",
+         offset, (unsigned int) header, (unsigned int) next_header);
+     if ((next_header & HDRMASK) != (header & HDRMASK)) {
+       /* If any of the unmasked bits don't match, then it's not valid */
+       GST_DEBUG_OBJECT (mp3parse, "next header doesn't match "
+           "(header=%08X (%08X), header2=%08X (%08X))",
+           (guint) header, (guint) header & HDRMASK, (guint) next_header,
+           (guint) next_header & HDRMASK);
+       goto next;
+     } else if (((next_header >> 12) & 0xf) == 0xf) {
+       /* The essential parts were the same, but the bitrate held an
+          invalid value - also reject */
+       GST_DEBUG_OBJECT (mp3parse, "next header invalid (bitrate)");
+       goto next;
+     }
+     valid = TRUE;
+   next:
+     /* almost accept as free frame */
+     if (layer == 1) {
+       rate = samplerate * (offset - 4 * padding + 4) / 48000;
+     } else {
+       rate = samplerate * (offset - padding + 1) / (144 >> lsf) / 1000;
+     }
+     if (valid) {
+       GST_LOG_OBJECT (mp3parse, "calculated rate %d", rate * 1000);
+       if (rate < 8 || (layer == 3 && rate > 640)) {
+         GST_DEBUG_OBJECT (mp3parse, "rate invalid");
+         if (rate < 8) {
+           /* maybe some hope */
+           continue;
+         } else {
+           GST_DEBUG_OBJECT (mp3parse, "aborting");
+           /* give up */
+           break;
+         }
+       }
+       *_rate = rate * 1000;
+       break;
+     } else {
+       /* avoid indefinite searching */
+       if (rate > 1000) {
+         GST_DEBUG_OBJECT (mp3parse, "exceeded sanity rate; aborting");
+         break;
+       }
+     }
+   }
+   return TRUE;
+ }
 +static GstFlowReturn
 +gst_mpeg_audio_parse_handle_frame (GstBaseParse * parse,
 +    GstBaseParseFrame * frame, gint * skipsize)
  {
    GstMpegAudioParse *mp3parse = GST_MPEG_AUDIO_PARSE (parse);
    GstBuffer *buf = frame->buffer;