Bug 1057612 - Tell Apple AAC decoder about seeks. r=cpearce
authorRalph Giles <giles@mozilla.com>
Fri, 22 Aug 2014 16:39:00 -0700
changeset 201212 6478460e5dd0d51be2b7f7e65cead08b91f52ecb
parent 201211 0ae7772c79778408cf10731476759487ff9c39aa
child 201213 e7236c73a81c1746d2137bd3060a5a1b18bd428e
push id48108
push userrgiles@mozilla.com
push dateSat, 23 Aug 2014 06:01:54 +0000
treeherdermozilla-inbound@6478460e5dd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1057612
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1057612 - Tell Apple AAC decoder about seeks. r=cpearce According to the documentation we should set this flag to mark data discontinuities after seeking.
content/media/fmp4/apple/AppleATDecoder.cpp
content/media/fmp4/apple/AppleATDecoder.h
--- a/content/media/fmp4/apple/AppleATDecoder.cpp
+++ b/content/media/fmp4/apple/AppleATDecoder.cpp
@@ -30,16 +30,17 @@ AppleATDecoder::AppleATDecoder(const mp4
   : mConfig(aConfig)
   , mTaskQueue(aAudioTaskQueue)
   , mCallback(aCallback)
   , mConverter(nullptr)
   , mStream(nullptr)
   , mCurrentAudioTimestamp(0)
   , mSamplePosition(0)
   , mHaveOutput(false)
+  , mFlushed(false)
 {
   MOZ_COUNT_CTOR(AppleATDecoder);
   LOG("Creating Apple AudioToolbox Audio decoder");
   LOG("Audio Decoder configuration: %s %d Hz %d channels %d bits per channel",
       mConfig.mime_type,
       mConfig.samples_per_second,
       mConfig.channel_count,
       mConfig.bits_per_sample);
@@ -130,16 +131,19 @@ AppleATDecoder::Flush()
 {
   LOG("Flushing AudioToolbox AAC decoder");
   mTaskQueue->Flush();
   OSStatus rv = AudioConverterReset(mConverter);
   if (rv) {
     LOG("Error %d resetting AudioConverter", rv);
     return NS_ERROR_FAILURE;
   }
+  // Notify our task queue of the coming input discontinuity.
+  mTaskQueue->Dispatch(
+      NS_NewRunnableMethod(this, &AppleATDecoder::SignalFlush));
   return NS_OK;
 }
 
 nsresult
 AppleATDecoder::Drain()
 {
   LOG("Draining AudioToolbox AAC decoder");
   mTaskQueue->AwaitIdle();
@@ -348,26 +352,33 @@ AppleATDecoder::SetupDecoder()
   }
 }
 
 void
 AppleATDecoder::SubmitSample(nsAutoPtr<mp4_demuxer::MP4Sample> aSample)
 {
   mSamplePosition = aSample->byte_offset;
   mCurrentAudioTimestamp = aSample->composition_timestamp;
+  uint32_t flags = mFlushed ? kAudioFileStreamParseFlag_Discontinuity : 0;
   OSStatus rv = AudioFileStreamParseBytes(mStream,
                                           aSample->size,
                                           aSample->data,
-                                          0);
+                                          flags);
   if (rv != noErr) {
     LOG("Error %d parsing audio data", rv);
     mCallback->Error();
   }
 
   // Sometimes we need multiple input samples before AudioToolbox
   // starts decoding. If we haven't seen any output yet, ask for
   // more data here.
   if (!mHaveOutput) {
     mCallback->InputExhausted();
   }
 }
 
+void
+AppleATDecoder::SignalFlush()
+{
+  mFlushed = true;
+}
+
 } // namespace mozilla
--- a/content/media/fmp4/apple/AppleATDecoder.h
+++ b/content/media/fmp4/apple/AppleATDecoder.h
@@ -47,18 +47,20 @@ public:
 private:
   RefPtr<MediaTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
   AudioConverterRef mConverter;
   AudioFileStreamID mStream;
   Microseconds mCurrentAudioTimestamp;
   int64_t mSamplePosition;
   bool mHaveOutput;
+  bool mFlushed;
   AudioStreamBasicDescription mOutputFormat;
   AudioFileTypeID mFileType;
 
   void SetupDecoder();
   void SubmitSample(nsAutoPtr<mp4_demuxer::MP4Sample> aSample);
+  void SignalFlush();
 };
 
 } // namespace mozilla
 
 #endif // mozilla_AppleATDecoder_h