Commit 611a857d authored by Paul Adenot's avatar Paul Adenot
Browse files

Bug 1751023 - Fix static analysis warnings in MediaDecoderStateMachine....

Bug 1751023 - Fix static analysis warnings in MediaDecoderStateMachine. r=media-playback-reviewers,chunmin

Differential Revision: https://phabricator.services.mozilla.com/D136395
parent b01d2a75
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -494,7 +494,7 @@ class VideoData : public MediaData {
  // This frame's image.
  RefPtr<Image> mImage;

  int32_t mFrameID;
  uint32_t mFrameID;

  VideoData(int64_t aOffset, const media::TimeUnit& aTime,
            const media::TimeUnit& aDuration, bool aKeyframe,
+50 −34
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ static constexpr auto AMPLE_AUDIO_THRESHOLD =
static const uint32_t LOW_VIDEO_FRAMES = 2;

// Arbitrary "frame duration" when playing only audio.
static const int AUDIO_DURATION_USECS = 40000;
static const uint32_t AUDIO_DURATION_USECS = 40000;

namespace detail {

@@ -210,7 +210,8 @@ class MediaDecoderStateMachine::StateObject {
  virtual void HandleVideoCanceled() { Crash("Unexpected event!", __func__); }
  virtual void HandleEndOfVideo() { Crash("Unexpected event!", __func__); }

  virtual RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget);
  virtual RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget);

  virtual RefPtr<ShutdownPromise> HandleShutdown();

@@ -269,7 +270,7 @@ class MediaDecoderStateMachine::StateObject {
    auto copiedArgs = MakeTuple(std::forward<Ts>(aArgs)...);

    // Copy mMaster which will reset to null.
    auto master = mMaster;
    auto* master = mMaster;

    auto* s = new S(master);

@@ -342,7 +343,8 @@ class MediaDecoderStateMachine::DecodeMetadataState

  State GetState() const override { return DECODER_STATE_DECODING_METADATA; }

  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override {
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget) override {
    MOZ_DIAGNOSTIC_ASSERT(false, "Can't seek while decoding metadata.");
    return MediaDecoder::SeekPromise::CreateAndReject(true, __func__);
  }
@@ -422,7 +424,8 @@ class MediaDecoderStateMachine::DormantState

  State GetState() const override { return DECODER_STATE_DORMANT; }

  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override;
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget) override;

  void HandleVideoSuspendTimeout() override {
    // Do nothing since we've released decoders in Enter().
@@ -532,7 +535,8 @@ class MediaDecoderStateMachine::DecodingFirstFrameState
    MOZ_ASSERT(false, "Shouldn't have suspended video decoding.");
  }

  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override {
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget) override {
    if (mMaster->mIsMSE) {
      return StateObject::HandleSeek(aTarget);
    }
@@ -701,8 +705,9 @@ class MediaDecoderStateMachine::DecodingState
  }

  uint32_t VideoPrerollFrames() const {
    return std::min<uint32_t>(
        (mMaster->GetAmpleVideoFrames() / 2) * mMaster->mPlaybackRate + 1,
    return std::min(
        static_cast<uint32_t>(
            mMaster->GetAmpleVideoFrames() / 2. * mMaster->mPlaybackRate + 1),
        sVideoQueueDefaultSize);
  }

@@ -736,7 +741,9 @@ class MediaDecoderStateMachine::DecodingState
    if (timeout < 0) {
      // Disabled when timeout is negative.
      return;
    } else if (timeout == 0) {
    }

    if (timeout == 0) {
      // Enter dormant immediately without scheduling a timer.
      SetState<DormantState>();
      return;
@@ -901,7 +908,7 @@ class MediaDecoderStateMachine::LoopingDecodingState
                  ->RequestAudioData()
                  ->Then(
                      OwnerThread(), __func__,
                      [this](RefPtr<AudioData> aAudio) {
                      [this](const RefPtr<AudioData>& aAudio) {
                        AUTO_PROFILER_LABEL(
                            "LoopingDecodingState::"
                            "RequestAudioDataFromStartPosition:"
@@ -1090,13 +1097,14 @@ class MediaDecoderStateMachine::SeekingState

  // We specially handle next frame seeks by ignoring them if we're already
  // seeking.
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override {
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget) override {
    if (aTarget.IsNextFrame()) {
      // We ignore next frame seeks if we already have a seek pending
      SLOG("Already SEEKING, ignoring seekToNextFrame");
      MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
      return MediaDecoder::SeekPromise::CreateAndReject(/* aIgnored = */ true,
                                                        __func__);
      return MediaDecoder::SeekPromise::CreateAndReject(
          /* aRejectValue = */ true, __func__);
    }

    return StateObject::HandleSeek(aTarget);
@@ -1891,7 +1899,7 @@ constexpr TimeUnit MediaDecoderStateMachine::VideoOnlySeekingState::
    sSkipToNextKeyFrameThreshold;

RefPtr<MediaDecoder::SeekPromise>
MediaDecoderStateMachine::DormantState::HandleSeek(SeekTarget aTarget) {
MediaDecoderStateMachine::DormantState::HandleSeek(const SeekTarget& aTarget) {
  if (aTarget.IsNextFrame()) {
    // NextFrameSeekingState doesn't reset the decoder unlike
    // AccurateSeekingState. So we first must come out of dormant by seeking to
@@ -2141,7 +2149,8 @@ class MediaDecoderStateMachine::ShutdownState

  State GetState() const override { return DECODER_STATE_SHUTDOWN; }

  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override {
  RefPtr<MediaDecoder::SeekPromise> HandleSeek(
      const SeekTarget& aTarget) override {
    MOZ_DIAGNOSTIC_ASSERT(false, "Can't seek in shutdown state.");
    return MediaDecoder::SeekPromise::CreateAndReject(true, __func__);
  }
@@ -2161,7 +2170,7 @@ class MediaDecoderStateMachine::ShutdownState
};

RefPtr<MediaDecoder::SeekPromise>
MediaDecoderStateMachine::StateObject::HandleSeek(SeekTarget aTarget) {
MediaDecoderStateMachine::StateObject::HandleSeek(const SeekTarget& aTarget) {
  SLOG("Changed state to SEEKING (to %" PRId64 ")",
       aTarget.GetTime().ToMicroseconds());
  SeekJob seekJob;
@@ -2207,9 +2216,9 @@ static void ReportRecoveryTelemetry(const TimeStamp& aRecoveryStart,
  TimeDuration duration = TimeStamp::Now() - aRecoveryStart;
  double duration_ms = duration.ToMilliseconds();
  Telemetry::Accumulate(Telemetry::VIDEO_SUSPEND_RECOVERY_TIME_MS, key,
                        uint32_t(duration_ms + 0.5));
                        static_cast<uint32_t>(lround(duration_ms)));
  Telemetry::Accumulate(Telemetry::VIDEO_SUSPEND_RECOVERY_TIME_MS, "All"_ns,
                        uint32_t(duration_ms + 0.5));
                        static_cast<uint32_t>(lround(duration_ms)));
}

void MediaDecoderStateMachine::StateObject::HandleResumeVideoDecoding(
@@ -2224,7 +2233,7 @@ void MediaDecoderStateMachine::StateObject::HandleResumeVideoDecoding(
  TimeStamp start = TimeStamp::Now();

  // Local reference to mInfo, so that it will be copied in the lambda below.
  auto& info = Info();
  const auto& info = Info();
  bool hw = Reader()->VideoIsHardwareAccelerated();

  // Start video-only seek to the current time.
@@ -2674,7 +2683,7 @@ void MediaDecoderStateMachine::BufferingState::HandleEndOfVideo() {

RefPtr<ShutdownPromise> MediaDecoderStateMachine::ShutdownState::Enter() {
  PROFILER_MARKER_UNTYPED("MDSM::EnterShutdownState", MEDIA_PLAYBACK);
  auto master = mMaster;
  auto* master = mMaster;

  master->mDelayedScheduler.Reset();

@@ -2912,7 +2921,8 @@ bool MediaDecoderStateMachine::HaveEnoughDecodedAudio() const {

bool MediaDecoderStateMachine::HaveEnoughDecodedVideo() const {
  MOZ_ASSERT(OnTaskQueue());
  return VideoQueue().GetSize() >= GetAmpleVideoFrames() * mPlaybackRate + 1 &&
  return VideoQueue().GetSize() >=
             static_cast<size_t>(GetAmpleVideoFrames() * mPlaybackRate + 1) &&
         IsVideoDataEnoughComparedWithAudio();
}

@@ -3252,13 +3262,13 @@ RefPtr<MediaDecoder::SeekPromise> MediaDecoderStateMachine::Seek(
  // We need to be able to seek in some way
  if (!mMediaSeekable && !mMediaSeekableOnlyInBufferedRanges) {
    LOGW("Seek() should not be called on a non-seekable media");
    return MediaDecoder::SeekPromise::CreateAndReject(/* aIgnored = */ true,
    return MediaDecoder::SeekPromise::CreateAndReject(/* aRejectValue = */ true,
                                                      __func__);
  }

  if (aTarget.IsNextFrame() && !HasVideo()) {
    LOGW("Ignore a NextFrameSeekTask on a media file without video track.");
    return MediaDecoder::SeekPromise::CreateAndReject(/* aIgnored = */ true,
    return MediaDecoder::SeekPromise::CreateAndReject(/* aRejectValue = */ true,
                                                      __func__);
  }

@@ -3300,7 +3310,7 @@ void MediaDecoderStateMachine::RequestAudioData() {
      ->Then(
          OwnerThread(), __func__,
          [this, self, perfRecorder(std::move(perfRecorder))](
              RefPtr<AudioData> aAudio) mutable {
              const RefPtr<AudioData>& aAudio) mutable {
            perfRecorder.End();
            AUTO_PROFILER_LABEL(
                "MediaDecoderStateMachine::RequestAudioData:Resolved",
@@ -3362,7 +3372,7 @@ void MediaDecoderStateMachine::RequestVideoData(
      ->Then(
          OwnerThread(), __func__,
          [this, self, perfRecorder(std::move(perfRecorder))](
              RefPtr<VideoData> aVideo) mutable {
              const RefPtr<VideoData>& aVideo) mutable {
            perfRecorder.End();
            AUTO_PROFILER_LABEL(
                "MediaDecoderStateMachine::RequestVideoData:Resolved",
@@ -3498,7 +3508,8 @@ bool MediaDecoderStateMachine::HasLowDecodedAudio() {
bool MediaDecoderStateMachine::HasLowDecodedVideo() {
  MOZ_ASSERT(OnTaskQueue());
  return IsVideoDecoding() &&
         VideoQueue().GetSize() < LOW_VIDEO_FRAMES * mPlaybackRate;
         VideoQueue().GetSize() <
             static_cast<size_t>(ceill(LOW_VIDEO_FRAMES * mPlaybackRate));
}

bool MediaDecoderStateMachine::HasLowDecodedData() {
@@ -3623,7 +3634,7 @@ void MediaDecoderStateMachine::RunStateMachine() {
  mStateObj->Step();
}

void MediaDecoderStateMachine::ResetDecode(TrackSet aTracks) {
void MediaDecoderStateMachine::ResetDecode(const TrackSet& aTracks) {
  MOZ_ASSERT(OnTaskQueue());
  LOG("MediaDecoderStateMachine::Reset");

@@ -3697,7 +3708,8 @@ void MediaDecoderStateMachine::UpdatePlaybackPositionPeriodically() {
  // the monitor and get a staled value from GetCurrentTimeUs() which hits the
  // assertion in GetClock().

  int64_t delay = std::max<int64_t>(1, AUDIO_DURATION_USECS / mPlaybackRate);
  int64_t delay = std::max<int64_t>(
      1, static_cast<int64_t>(AUDIO_DURATION_USECS / mPlaybackRate));
  ScheduleStateMachineIn(TimeUnit::FromMicroseconds(delay));

  // Notify the listener as we progress in the playback offset. Note it would
@@ -3844,7 +3856,7 @@ void MediaDecoderStateMachine::OutputPrincipalChanged() {
}

RefPtr<GenericPromise> MediaDecoderStateMachine::InvokeSetSink(
    RefPtr<AudioDeviceInfo> aSink) {
    const RefPtr<AudioDeviceInfo>& aSink) {
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aSink);

@@ -3853,7 +3865,7 @@ RefPtr<GenericPromise> MediaDecoderStateMachine::InvokeSetSink(
}

RefPtr<GenericPromise> MediaDecoderStateMachine::SetSink(
    RefPtr<AudioDeviceInfo> aSinkDevice) {
    const RefPtr<AudioDeviceInfo>& aDevice) {
  MOZ_ASSERT(OnTaskQueue());
  if (mIsMediaSinkSuspended) {
    // Don't change sink id in a suspended sink.
@@ -3865,12 +3877,12 @@ RefPtr<GenericPromise> MediaDecoderStateMachine::SetSink(
    return GenericPromise::CreateAndReject(NS_ERROR_ABORT, __func__);
  }

  if (mSinkDevice.Ref() != aSinkDevice) {
  if (mSinkDevice.Ref() != aDevice) {
    // A new sink was set before this ran.
    return GenericPromise::CreateAndResolve(IsPlaying(), __func__);
  }

  if (mMediaSink->AudioDevice() == aSinkDevice) {
  if (mMediaSink->AudioDevice() == aDevice) {
    // The sink has not changed.
    return GenericPromise::CreateAndResolve(IsPlaying(), __func__);
  }
@@ -4131,7 +4143,9 @@ const char* MediaDecoderStateMachine::AudioRequestStatus() const {
  if (IsRequestingAudioData()) {
    MOZ_DIAGNOSTIC_ASSERT(!IsWaitingAudioData());
    return "pending";
  } else if (IsWaitingAudioData()) {
  }

  if (IsWaitingAudioData()) {
    return "waiting";
  }
  return "idle";
@@ -4142,7 +4156,9 @@ const char* MediaDecoderStateMachine::VideoRequestStatus() const {
  if (IsRequestingVideoData()) {
    MOZ_DIAGNOSTIC_ASSERT(!IsWaitingVideoData());
    return "pending";
  } else if (IsWaitingVideoData()) {
  }

  if (IsWaitingVideoData()) {
    return "waiting";
  }
  return "idle";
+4 −4
Original line number Diff line number Diff line
@@ -275,7 +275,7 @@ class MediaDecoderStateMachine
  // Sets the video decode mode. Used by the suspend-video-decoder feature.
  void SetVideoDecodeMode(VideoDecodeMode aMode);

  RefPtr<GenericPromise> InvokeSetSink(RefPtr<AudioDeviceInfo> aSink);
  RefPtr<GenericPromise> InvokeSetSink(const RefPtr<AudioDeviceInfo>& aSink);

  void InvokeSuspendMediaSink();
  void InvokeResumeMediaSink();
@@ -351,7 +351,7 @@ class MediaDecoderStateMachine

  // Resets all states related to decoding and aborts all pending requests
  // to the decoders.
  void ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
  void ResetDecode(const TrackSet& aTracks = TrackSet(TrackInfo::kAudioTrack,
                                                      TrackInfo::kVideoTrack));

  void SetVideoDecodeModeInternal(VideoDecodeMode aMode);
@@ -364,7 +364,7 @@ class MediaDecoderStateMachine
  // If there are multiple pending requests only the last one will be
  // executed, for all previous requests the promise will be resolved
  // with true or false similar to above.
  RefPtr<GenericPromise> SetSink(RefPtr<AudioDeviceInfo> aSink);
  RefPtr<GenericPromise> SetSink(const RefPtr<AudioDeviceInfo>& aDevice);

  // Shutdown MediaSink on suspend to clean up resources.
  void SuspendMediaSink();