Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef SEEK_TARGET_H
8 : #define SEEK_TARGET_H
9 :
10 : #include "TimeUnits.h"
11 :
12 : namespace mozilla {
13 :
14 : enum class MediaDecoderEventVisibility : int8_t
15 : {
16 : Observable,
17 : Suppressed
18 : };
19 :
20 : // Stores the seek target; the time to seek to, and whether an Accurate,
21 : // "Fast" (nearest keyframe), or "Video Only" (no audio seek) seek was
22 : // requested.
23 : struct SeekTarget
24 : {
25 : enum Type
26 : {
27 : Invalid,
28 : PrevSyncPoint,
29 : Accurate,
30 : NextFrame,
31 : };
32 0 : SeekTarget()
33 0 : : mTime(media::TimeUnit::Invalid())
34 : , mType(SeekTarget::Invalid)
35 0 : , mVideoOnly(false)
36 : {
37 0 : }
38 0 : SeekTarget(int64_t aTimeUsecs, Type aType, bool aVideoOnly = false)
39 0 : : mTime(media::TimeUnit::FromMicroseconds(aTimeUsecs))
40 : , mType(aType)
41 0 : , mVideoOnly(aVideoOnly)
42 : {
43 0 : }
44 0 : SeekTarget(const media::TimeUnit& aTime, Type aType, bool aVideoOnly = false)
45 0 : : mTime(aTime)
46 : , mType(aType)
47 0 : , mVideoOnly(aVideoOnly)
48 : {
49 0 : }
50 0 : SeekTarget(const SeekTarget& aOther)
51 0 : : mTime(aOther.mTime)
52 0 : , mType(aOther.mType)
53 0 : , mVideoOnly(aOther.mVideoOnly)
54 : {
55 0 : }
56 : bool IsValid() const { return mType != SeekTarget::Invalid; }
57 : void Reset()
58 : {
59 : mTime = media::TimeUnit::Invalid();
60 : mType = SeekTarget::Invalid;
61 : mVideoOnly = false;
62 : }
63 0 : media::TimeUnit GetTime() const
64 : {
65 0 : NS_ASSERTION(mTime.IsValid(), "Invalid SeekTarget");
66 0 : return mTime;
67 : }
68 0 : void SetTime(const media::TimeUnit& aTime)
69 : {
70 0 : NS_ASSERTION(aTime.IsValid(), "Invalid SeekTarget destination");
71 0 : mTime = aTime;
72 0 : }
73 0 : void SetType(Type aType) { mType = aType; }
74 : void SetVideoOnly(bool aVideoOnly) { mVideoOnly = aVideoOnly; }
75 0 : bool IsFast() const { return mType == SeekTarget::Type::PrevSyncPoint; }
76 0 : bool IsAccurate() const { return mType == SeekTarget::Type::Accurate; }
77 0 : bool IsNextFrame() const { return mType == SeekTarget::Type::NextFrame; }
78 0 : bool IsVideoOnly() const { return mVideoOnly; }
79 :
80 : private:
81 : // Seek target time.
82 : media::TimeUnit mTime;
83 : // Whether we should seek "Fast", or "Accurate".
84 : // "Fast" seeks to the seek point preceding mTime, whereas
85 : // "Accurate" seeks as close as possible to mTime.
86 : Type mType;
87 : bool mVideoOnly;
88 : };
89 :
90 : } // namespace mozilla
91 :
92 : #endif /* SEEK_TARGET_H */
|