Bug 1056394: OS X: Properly propagate timestamps. r=rillian
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 22 Aug 2014 15:47:00 -0700
changeset 222905 78fc4d778b8f37871543ea43bdf1bdad315ca0c6
parent 222904 ebeaf707ed6bd503b2331d8f4be3049fe0e96174
child 222906 53f7b6fdd6dbb62b3167498952fbaabd62b6bc1d
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1056394
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 1056394: OS X: Properly propagate timestamps. r=rillian This isn't strictly correct, but is non-decreasing except at seeks and appears to work in practice.
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
@@ -27,17 +27,17 @@ namespace mozilla {
 AppleATDecoder::AppleATDecoder(const mp4_demuxer::AudioDecoderConfig& aConfig,
                                MediaTaskQueue* aAudioTaskQueue,
                                MediaDataDecoderCallback* aCallback)
   : mConfig(aConfig)
   , mTaskQueue(aAudioTaskQueue)
   , mCallback(aCallback)
   , mConverter(nullptr)
   , mStream(nullptr)
-  , mCurrentAudioFrame(0)
+  , mCurrentAudioTimestamp(0)
   , mSamplePosition(0)
   , mHaveOutput(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,
@@ -281,31 +281,29 @@ AppleATDecoder::SampleCallback(uint32_t 
       LOG("FillComplexBuffer out of data exactly\n");
       mCallback->InputExhausted();
       break;
     }
 
     const int rate = mOutputFormat.mSampleRate;
     const int channels = mOutputFormat.mChannelsPerFrame;
 
-    int64_t time = FramesToUsecs(mCurrentAudioFrame, rate).value();
+    int64_t time = mCurrentAudioTimestamp;
     int64_t duration = FramesToUsecs(numFrames, rate).value();
 
     LOG("pushed audio at time %lfs; duration %lfs\n",
         (double)time / USECS_PER_S, (double)duration / USECS_PER_S);
 
     AudioData* audio = new AudioData(mSamplePosition,
                                      time, duration, numFrames,
                                      reinterpret_cast<AudioDataValue*>(decoded.forget()),
                                      channels, rate);
     mCallback->Output(audio);
     mHaveOutput = true;
 
-    mCurrentAudioFrame += numFrames;
-
     if (rv == kNeedMoreData) {
       // No error; we just need more data.
       LOG("FillComplexBuffer out of data\n");
       mCallback->InputExhausted();
       break;
     }
   } while (true);
 }
@@ -349,16 +347,17 @@ AppleATDecoder::SetupDecoder()
     mCallback->Error();
   }
 }
 
 void
 AppleATDecoder::SubmitSample(nsAutoPtr<mp4_demuxer::MP4Sample> aSample)
 {
   mSamplePosition = aSample->byte_offset;
+  mCurrentAudioTimestamp = aSample->composition_timestamp;
   OSStatus rv = AudioFileStreamParseBytes(mStream,
                                           aSample->size,
                                           aSample->data,
                                           0);
   if (rv != noErr) {
     LOG("Error %d parsing audio data", rv);
     mCallback->Error();
   }
--- a/content/media/fmp4/apple/AppleATDecoder.h
+++ b/content/media/fmp4/apple/AppleATDecoder.h
@@ -44,17 +44,17 @@ public:
   // Callbacks also need access to the config.
   const mp4_demuxer::AudioDecoderConfig& mConfig;
 
 private:
   RefPtr<MediaTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
   AudioConverterRef mConverter;
   AudioFileStreamID mStream;
-  uint64_t mCurrentAudioFrame;
+  Microseconds mCurrentAudioTimestamp;
   int64_t mSamplePosition;
   bool mHaveOutput;
   AudioStreamBasicDescription mOutputFormat;
   AudioFileTypeID mFileType;
 
   void SetupDecoder();
   void SubmitSample(nsAutoPtr<mp4_demuxer::MP4Sample> aSample);
 };