NextFrameSeekTask.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef NEXTFRAME_SEEK_TASK_H
  6. #define NEXTFRAME_SEEK_TASK_H
  7. #include "SeekTask.h"
  8. #include "MediaDecoderReader.h"
  9. namespace mozilla {
  10. namespace media {
  11. /*
  12. * While invoking a NextFrameSeekTask, we don't know the seek target time, what
  13. * we know is the media's currant position. We use the media's currant position
  14. * to find out what the next frame is, by traversing through the video queue or
  15. * asking the decoder to decode more video frames. Once we confirm the next
  16. * frame, we then know the target time of the NextFrameSeekTask and we update it
  17. * so that the MDSM will be able to update the media element's position.
  18. */
  19. class NextFrameSeekTask final : public SeekTask {
  20. public:
  21. NextFrameSeekTask(const void* aDecoderID,
  22. AbstractThread* aThread,
  23. MediaDecoderReaderWrapper* aReader,
  24. const SeekTarget& aTarget,
  25. const MediaInfo& aInfo,
  26. const media::TimeUnit& aDuration,
  27. int64_t aCurrentTime,
  28. MediaQueue<MediaData>& aAudioQueue,
  29. MediaQueue<MediaData>& aVideoQueue);
  30. void Discard() override;
  31. RefPtr<SeekTaskPromise> Seek(const media::TimeUnit& aDuration) override;
  32. bool NeedToResetMDSM() const override;
  33. private:
  34. ~NextFrameSeekTask();
  35. void RequestVideoData();
  36. bool NeedMoreVideo() const;
  37. bool IsVideoRequestPending() const;
  38. bool IsAudioSeekComplete() const;
  39. bool IsVideoSeekComplete() const;
  40. void MaybeFinishSeek();
  41. void OnAudioDecoded(MediaData* aAudioSample);
  42. void OnAudioNotDecoded(const MediaResult& aError);
  43. void OnVideoDecoded(MediaData* aVideoSample);
  44. void OnVideoNotDecoded(const MediaResult& aError);
  45. void SetCallbacks();
  46. void CancelCallbacks();
  47. // Update the seek target's time before resolving this seek task, the updated
  48. // time will be used in the MDSM::SeekCompleted() to update the MDSM's position.
  49. void UpdateSeekTargetTime();
  50. /*
  51. * Data shared with MDSM.
  52. */
  53. MediaQueue<MediaData>& mAudioQueue;
  54. MediaQueue<MediaData>& mVideoQueue;
  55. /*
  56. * Internal state.
  57. */
  58. const int64_t mCurrentTime;
  59. media::TimeUnit mDuration;
  60. MediaEventListener mAudioCallback;
  61. MediaEventListener mVideoCallback;
  62. MediaEventListener mAudioWaitCallback;
  63. MediaEventListener mVideoWaitCallback;
  64. };
  65. } // namespace media
  66. } // namespace mozilla
  67. #endif /* NEXTFRAME_SEEK_TASK_H */