Bug 1540740 - part2 : using TimeUnit as input parameter for 'AdjustForStartTime()'. r=jya
authorAlastor Wu <alwu@mozilla.com>
Thu, 11 Apr 2019 17:32:54 +0000
changeset 469082 0b26cd4c1c21b14cd42032ec08b13ffcdc7f5866
parent 469081 ffb3ec9486e6d2be697658db3b51ccf043a33890
child 469083 4febe6f32b23f8d40d597b6a6a9675ba989835bb
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1540740
milestone68.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 1540740 - part2 : using TimeUnit as input parameter for 'AdjustForStartTime()'. r=jya There is no need to cast to `TimeUnit` to `int64` and then cast to `TimeUnit` again. Differential Revision: https://phabricator.services.mozilla.com/D26758
dom/media/MediaData.cpp
dom/media/MediaData.h
dom/media/ReaderProxy.cpp
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -51,22 +51,20 @@ AudioData::AudioData(int64_t aOffset, co
       mOriginalTime(aTime),
       mAudioData(std::move(aData)),
       mFrames(mAudioData.Length() / aChannels) {}
 
 Span<AudioDataValue> AudioData::Data() const {
   return MakeSpan(GetAdjustedData(), mFrames * mChannels);
 }
 
-bool AudioData::AdjustForStartTime(int64_t aStartTime) {
-  const TimeUnit startTimeOffset =
-      media::TimeUnit::FromMicroseconds(aStartTime);
-  mOriginalTime -= startTimeOffset;
+bool AudioData::AdjustForStartTime(const media::TimeUnit& aStartTime) {
+  mOriginalTime -= aStartTime;
   if (mTrimWindow) {
-    *mTrimWindow -= startTimeOffset;
+    *mTrimWindow -= aStartTime;
   }
   return MediaData::AdjustForStartTime(aStartTime) && mOriginalTime.IsValid();
 }
 
 bool AudioData::SetTrimWindow(const media::TimeInterval& aTrim) {
   MOZ_DIAGNOSTIC_ASSERT(aTrim.mStart.IsValid() && aTrim.mEnd.IsValid(),
                         "An overflow occurred on the provided TimeInterval");
   if (!mAudioData) {
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -293,18 +293,18 @@ class MediaData {
   media::TimeUnit mDuration;
 
   bool mKeyframe;
 
   media::TimeUnit GetEndTime() const { return mTime + mDuration; }
 
   // Return true if the adjusted time is valid. Caller should handle error when
   // the result is invalid.
-  virtual bool AdjustForStartTime(int64_t aStartTime) {
-    mTime -= media::TimeUnit::FromMicroseconds(aStartTime);
+  virtual bool AdjustForStartTime(const media::TimeUnit& aStartTime) {
+    mTime -= aStartTime;
     return mTime.IsValid();
   }
 
   template <typename ReturnType>
   const ReturnType* As() const {
     MOZ_ASSERT(this->mType == ReturnType::sType);
     return static_cast<const ReturnType*>(this);
   }
@@ -366,17 +366,17 @@ class AudioData : public MediaData {
   void EnsureAudioBuffer();
 
   // To check whether mAudioData has audible signal, it's used to distinguish
   // the audiable data and silent data.
   bool IsAudible() const;
 
   // Return true if the adjusted time is valid. Caller should handle error when
   // the result is invalid.
-  bool AdjustForStartTime(int64_t aStartTime) override;
+  bool AdjustForStartTime(const media::TimeUnit& aStartTime) override;
 
   const uint32_t mChannels;
   // The AudioConfig::ChannelLayout map. Channels are ordered as per SMPTE
   // definition. A value of UNKNOWN_MAP indicates unknown layout.
   // ChannelMap is an unsigned bitmap compatible with Windows' WAVE and FFmpeg
   // channel map.
   const AudioConfig::ChannelLayout::ChannelMap mChannelMap;
   const uint32_t mRate;
--- a/dom/media/ReaderProxy.cpp
+++ b/dom/media/ReaderProxy.cpp
@@ -38,17 +38,17 @@ RefPtr<ReaderProxy::MetadataPromise> Rea
       ->Then(mOwnerThread, __func__, this, &ReaderProxy::OnMetadataRead,
              &ReaderProxy::OnMetadataNotRead);
 }
 
 RefPtr<ReaderProxy::AudioDataPromise> ReaderProxy::OnAudioDataRequestCompleted(
     RefPtr<AudioData> aAudio) {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
 
-  if (aAudio->AdjustForStartTime(StartTime().ToMicroseconds())) {
+  if (aAudio->AdjustForStartTime(StartTime())) {
     return AudioDataPromise::CreateAndResolve(aAudio.forget(), __func__);
   }
   return AudioDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_OVERFLOW_ERR,
                                            __func__);
 }
 
 RefPtr<ReaderProxy::AudioDataPromise> ReaderProxy::OnAudioDataRequestFailed(
     const MediaResult& aError) {
@@ -71,17 +71,17 @@ RefPtr<ReaderProxy::VideoDataPromise> Re
     const media::TimeUnit& aTimeThreshold) {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   MOZ_ASSERT(!mShutdown);
 
   const auto threshold = aTimeThreshold > media::TimeUnit::Zero()
                              ? aTimeThreshold + StartTime()
                              : aTimeThreshold;
 
-  int64_t startTime = StartTime().ToMicroseconds();
+  auto startTime = StartTime();
   return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
                      &MediaFormatReader::RequestVideoData, threshold)
       ->Then(
           mOwnerThread, __func__,
           [startTime](RefPtr<VideoData> aVideo) {
             return aVideo->AdjustForStartTime(startTime)
                        ? VideoDataPromise::CreateAndResolve(aVideo.forget(),
                                                             __func__)