Bug 1323931. Part 2 - use raw pointers to reduce unnecessary ref-counting. r?kaku draft
authorJW Wang <jwwang@mozilla.com>
Fri, 16 Dec 2016 15:11:19 +0800
changeset 450843 856d8edf743c111f7588fd88aaa0f551bb6edff8
parent 450842 2da811186fcfd7fd98b760ef331d5e37b10b5e4f
child 450844 f65ea76ae5b908a522b66aebdf29da61d700b871
push id38961
push userjwwang@mozilla.com
push dateMon, 19 Dec 2016 03:21:27 +0000
reviewerskaku
bugs1323931
milestone53.0a1
Bug 1323931. Part 2 - use raw pointers to reduce unnecessary ref-counting. r?kaku MozReview-Commit-ID: 1iVaCGLqFCy
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -862,64 +862,60 @@ public:
 
     // Disconnect MediaDecoderReaderWrapper.
     mSeekRequest.DisconnectIfExists();
   }
 
   void HandleAudioDecoded(MediaData* aAudio) override
   {
     MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
-
-    RefPtr<MediaData> audio(aAudio);
-    MOZ_ASSERT(audio);
+    MOZ_ASSERT(aAudio);
 
     // Video-only seek doesn't reset audio decoder. There might be pending audio
     // requests when AccurateSeekTask::Seek() begins. We will just store the data
     // without checking |mDiscontinuity| or calling DropAudioUpToSeekTarget().
     if (mSeekJob.mTarget.IsVideoOnly()) {
-      mSeekedAudioData = audio.forget();
+      mSeekedAudioData = aAudio;
       return;
     }
 
-    AdjustFastSeekIfNeeded(audio);
+    AdjustFastSeekIfNeeded(aAudio);
 
     if (mSeekJob.mTarget.IsFast()) {
       // Non-precise seek; we can stop the seek at the first sample.
-      mSeekedAudioData = audio;
+      mSeekedAudioData = aAudio;
       mDoneAudioSeeking = true;
     } else {
-      nsresult rv = DropAudioUpToSeekTarget(audio);
+      nsresult rv = DropAudioUpToSeekTarget(aAudio->As<AudioData>());
       if (NS_FAILED(rv)) {
         OnSeekTaskRejected(rv);
         return;
       }
     }
 
     if (!mDoneAudioSeeking) {
       RequestAudioData();
       return;
     }
     MaybeFinishSeek();
   }
 
   void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
   {
     MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
-
-    RefPtr<MediaData> video(aVideo);
-    MOZ_ASSERT(video);
-
-    AdjustFastSeekIfNeeded(video);
+    MOZ_ASSERT(aVideo);
+
+    AdjustFastSeekIfNeeded(aVideo);
 
     if (mSeekJob.mTarget.IsFast()) {
       // Non-precise seek. We can stop the seek at the first sample.
-      mSeekedVideoData = video;
+      mSeekedVideoData = aVideo;
       mDoneVideoSeeking = true;
     } else {
-      nsresult rv = DropVideoUpToSeekTarget(video.get());
+      nsresult rv = DropVideoUpToSeekTarget(aVideo);
       if (NS_FAILED(rv)) {
         OnSeekTaskRejected(rv);
         return;
       }
     }
 
     if (!mDoneVideoSeeking) {
       RequestVideoData();
@@ -1105,88 +1101,87 @@ private:
       // seek and decode to the seek target. This is not conformant to the
       // spec, fastSeek should always be fast, but until we get the time to
       // change all Readers to seek to the keyframe after the currentTime
       // in this case, we'll just decode forward. Bug 1026330.
       mSeekJob.mTarget.SetType(SeekTarget::Accurate);
     }
   }
 
-  nsresult DropAudioUpToSeekTarget(MediaData* aSample)
+  nsresult DropAudioUpToSeekTarget(AudioData* aAudio)
   {
-    RefPtr<AudioData> audio(aSample->As<AudioData>());
-    MOZ_ASSERT(audio && mSeekJob.mTarget.IsAccurate());
-
-    CheckedInt64 sampleDuration = FramesToUsecs(audio->mFrames, Info().mAudio.mRate);
+    MOZ_ASSERT(aAudio && mSeekJob.mTarget.IsAccurate());
+
+    CheckedInt64 sampleDuration = FramesToUsecs(aAudio->mFrames, Info().mAudio.mRate);
     if (!sampleDuration.isValid()) {
       return NS_ERROR_DOM_MEDIA_OVERFLOW_ERR;
     }
 
-    if (audio->mTime + sampleDuration.value() <= mSeekJob.mTarget.GetTime().ToMicroseconds()) {
+    if (aAudio->mTime + sampleDuration.value() <= mSeekJob.mTarget.GetTime().ToMicroseconds()) {
       // Our seek target lies after the frames in this AudioData. Don't
       // push it onto the audio queue, and keep decoding forwards.
       return NS_OK;
     }
 
-    if (audio->mTime > mSeekJob.mTarget.GetTime().ToMicroseconds()) {
+    if (aAudio->mTime > mSeekJob.mTarget.GetTime().ToMicroseconds()) {
       // The seek target doesn't lie in the audio block just after the last
       // audio frames we've seen which were before the seek target. This
       // could have been the first audio data we've seen after seek, i.e. the
       // seek terminated after the seek target in the audio stream. Just
       // abort the audio decode-to-target, the state machine will play
       // silence to cover the gap. Typically this happens in poorly muxed
       // files.
       SWARN("Audio not synced after seek, maybe a poorly muxed file?");
-      mSeekedAudioData = audio;
+      mSeekedAudioData = aAudio;
       mDoneAudioSeeking = true;
       return NS_OK;
     }
 
     // The seek target lies somewhere in this AudioData's frames, strip off
     // any frames which lie before the seek target, so we'll begin playback
     // exactly at the seek target.
-    NS_ASSERTION(mSeekJob.mTarget.GetTime().ToMicroseconds() >= audio->mTime,
+    NS_ASSERTION(mSeekJob.mTarget.GetTime().ToMicroseconds() >= aAudio->mTime,
                  "Target must at or be after data start.");
-    NS_ASSERTION(mSeekJob.mTarget.GetTime().ToMicroseconds() < audio->mTime + sampleDuration.value(),
+    NS_ASSERTION(mSeekJob.mTarget.GetTime().ToMicroseconds() < aAudio->mTime + sampleDuration.value(),
                  "Data must end after target.");
 
     CheckedInt64 framesToPrune =
-      UsecsToFrames(mSeekJob.mTarget.GetTime().ToMicroseconds() - audio->mTime, Info().mAudio.mRate);
+      UsecsToFrames(mSeekJob.mTarget.GetTime().ToMicroseconds() - aAudio->mTime, Info().mAudio.mRate);
     if (!framesToPrune.isValid()) {
       return NS_ERROR_DOM_MEDIA_OVERFLOW_ERR;
     }
-    if (framesToPrune.value() > audio->mFrames) {
+    if (framesToPrune.value() > aAudio->mFrames) {
       // We've messed up somehow. Don't try to trim frames, the |frames|
       // variable below will overflow.
       SWARN("Can't prune more frames that we have!");
       return NS_ERROR_FAILURE;
     }
-    uint32_t frames = audio->mFrames - static_cast<uint32_t>(framesToPrune.value());
-    uint32_t channels = audio->mChannels;
+    uint32_t frames = aAudio->mFrames - static_cast<uint32_t>(framesToPrune.value());
+    uint32_t channels = aAudio->mChannels;
     AlignedAudioBuffer audioData(frames * channels);
     if (!audioData) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     memcpy(audioData.get(),
-           audio->mAudioData.get() + (framesToPrune.value() * channels),
+           aAudio->mAudioData.get() + (framesToPrune.value() * channels),
            frames * channels * sizeof(AudioDataValue));
     CheckedInt64 duration = FramesToUsecs(frames, Info().mAudio.mRate);
     if (!duration.isValid()) {
       return NS_ERROR_DOM_MEDIA_OVERFLOW_ERR;
     }
-    RefPtr<AudioData> data(new AudioData(audio->mOffset,
+    RefPtr<AudioData> data(new AudioData(aAudio->mOffset,
                                          mSeekJob.mTarget.GetTime().ToMicroseconds(),
                                          duration.value(),
                                          frames,
                                          Move(audioData),
                                          channels,
-                                         audio->mRate));
+                                         aAudio->mRate));
     MOZ_ASSERT(!mSeekedAudioData, "Should be the 1st sample after seeking");
-    mSeekedAudioData = data;
+    mSeekedAudioData = data.forget();
     mDoneAudioSeeking = true;
 
     return NS_OK;
   }
 
   nsresult DropVideoUpToSeekTarget(MediaData* aSample)
   {
     RefPtr<VideoData> video(aSample->As<VideoData>());