summaryrefslogtreecommitdiffstats
path: root/dom/media/NextFrameSeekTask.h
blob: debd58c6668a2eed7384fa37932d362984eb5efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef NEXTFRAME_SEEK_TASK_H
#define NEXTFRAME_SEEK_TASK_H

#include "SeekTask.h"
#include "MediaDecoderReader.h"

namespace mozilla {
namespace media {

/*
 * While invoking a NextFrameSeekTask, we don't know the seek target time, what
 * we know is the media's currant position. We use the media's currant position
 * to find out what the next frame is, by traversing through the video queue or
 * asking the decoder to decode more video frames. Once we confirm the next
 * frame, we then know the target time of the NextFrameSeekTask and we update it
 * so that the MDSM will be able to update the media element's position.
 */

class NextFrameSeekTask final : public SeekTask {
public:
  NextFrameSeekTask(const void* aDecoderID,
                   AbstractThread* aThread,
                   MediaDecoderReaderWrapper* aReader,
                   const SeekTarget& aTarget,
                   const MediaInfo& aInfo,
                   const media::TimeUnit& aDuration,
                   int64_t aCurrentTime,
                   MediaQueue<MediaData>& aAudioQueue,
                   MediaQueue<MediaData>& aVideoQueue);

  void Discard() override;

  RefPtr<SeekTaskPromise> Seek(const media::TimeUnit& aDuration) override;

  bool NeedToResetMDSM() const override;

private:
  ~NextFrameSeekTask();

  void RequestVideoData();

  bool NeedMoreVideo() const;

  bool IsVideoRequestPending() const;

  bool IsAudioSeekComplete() const;

  bool IsVideoSeekComplete() const;

  void MaybeFinishSeek();

  void OnAudioDecoded(MediaData* aAudioSample);

  void OnAudioNotDecoded(const MediaResult& aError);

  void OnVideoDecoded(MediaData* aVideoSample);

  void OnVideoNotDecoded(const MediaResult& aError);

  void SetCallbacks();

  void CancelCallbacks();

  // Update the seek target's time before resolving this seek task, the updated
  // time will be used in the MDSM::SeekCompleted() to update the MDSM's position.
  void UpdateSeekTargetTime();

  /*
   * Data shared with MDSM.
   */
  MediaQueue<MediaData>& mAudioQueue;
  MediaQueue<MediaData>& mVideoQueue;

  /*
   * Internal state.
   */
  const int64_t mCurrentTime;
  media::TimeUnit mDuration;

  MediaEventListener mAudioCallback;
  MediaEventListener mVideoCallback;
  MediaEventListener mAudioWaitCallback;
  MediaEventListener mVideoWaitCallback;
};

} // namespace media
} // namespace mozilla

#endif /* NEXTFRAME_SEEK_TASK_H */