summaryrefslogtreecommitdiff
path: root/dom/media/SeekTarget.h
blob: ac35ca501f9bf84cd6dea7d0a004059236b2c54a (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
96
97
98
99
100
101
102
103
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 SEEK_TARGET_H
#define SEEK_TARGET_H

#include "TimeUnits.h"

namespace mozilla {

enum class MediaDecoderEventVisibility : int8_t {
  Observable,
  Suppressed
};

// Stores the seek target; the time to seek to, and whether an Accurate,
// "Fast" (nearest keyframe), or "Video Only" (no audio seek) seek was
// requested.
struct SeekTarget {
  enum Type {
    Invalid,
    PrevSyncPoint,
    Accurate,
    NextFrame,
  };
  SeekTarget()
    : mTime(media::TimeUnit::Invalid())
    , mType(SeekTarget::Invalid)
    , mVideoOnly(false)
  {
  }
  SeekTarget(int64_t aTimeUsecs,
             Type aType,
             bool aVideoOnly = false)
    : mTime(media::TimeUnit::FromMicroseconds(aTimeUsecs))
    , mType(aType)
    , mVideoOnly(aVideoOnly)
  {
  }
  SeekTarget(const media::TimeUnit& aTime,
             Type aType,
             bool aVideoOnly = false)
    : mTime(aTime)
    , mType(aType)
    , mVideoOnly(aVideoOnly)
  {
  }
  SeekTarget(const SeekTarget& aOther)
    : mTime(aOther.mTime)
    , mType(aOther.mType)
    , mVideoOnly(aOther.mVideoOnly)
  {
  }
  bool IsValid() const {
    return mType != SeekTarget::Invalid;
  }
  void Reset() {
    mTime = media::TimeUnit::Invalid();
    mType = SeekTarget::Invalid;
    mVideoOnly = false;
  }
  media::TimeUnit GetTime() const {
    NS_ASSERTION(mTime.IsValid(), "Invalid SeekTarget");
    return mTime;
  }
  void SetTime(const media::TimeUnit& aTime) {
    NS_ASSERTION(aTime.IsValid(), "Invalid SeekTarget destination");
    mTime = aTime;
  }
  void SetType(Type aType) {
    mType = aType;
  }
  void SetVideoOnly(bool aVideoOnly) {
    mVideoOnly = aVideoOnly;
  }
  bool IsFast() const {
    return mType == SeekTarget::Type::PrevSyncPoint;
  }
  bool IsAccurate() const {
    return mType == SeekTarget::Type::Accurate;
  }
  bool IsNextFrame() const {
    return mType == SeekTarget::Type::NextFrame;
  }
  bool IsVideoOnly() const {
    return mVideoOnly;
  }

private:
  // Seek target time.
  media::TimeUnit mTime;
  // Whether we should seek "Fast", or "Accurate".
  // "Fast" seeks to the seek point preceding mTime, whereas
  // "Accurate" seeks as close as possible to mTime.
  Type mType;
  bool mVideoOnly;
};

} // namespace mozilla

#endif /* SEEK_TARGET_H */