Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/ReaderProxy.h
Line
Count
Source (jump to first uncovered line)
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 ReaderProxy_h_
8
#define ReaderProxy_h_
9
10
#include "mozilla/AbstractThread.h"
11
#include "mozilla/RefPtr.h"
12
#include "mozilla/Variant.h"
13
#include "nsISupportsImpl.h"
14
15
#include "MediaEventSource.h"
16
#include "MediaFormatReader.h"
17
18
namespace mozilla {
19
20
/**
21
 * A wrapper around MediaFormatReader to offset the timestamps of Audio/Video
22
 * samples by the start time to ensure MDSM can always assume zero start time.
23
 * It also adjusts the seek target passed to Seek() to ensure correct seek time
24
 * is passed to the underlying reader.
25
 */
26
class ReaderProxy
27
{
28
  using MetadataPromise = MediaFormatReader::MetadataPromise;
29
  using AudioDataPromise = MediaFormatReader::AudioDataPromise;
30
  using VideoDataPromise = MediaFormatReader::VideoDataPromise;
31
  using SeekPromise = MediaFormatReader::SeekPromise;
32
  using WaitForDataPromise = MediaFormatReader::WaitForDataPromise;
33
  using TrackSet = MediaFormatReader::TrackSet;
34
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ReaderProxy);
35
36
public:
37
  ReaderProxy(AbstractThread* aOwnerThread, MediaFormatReader* aReader);
38
39
  media::TimeUnit StartTime() const;
40
  RefPtr<MetadataPromise> ReadMetadata();
41
42
  RefPtr<AudioDataPromise> RequestAudioData();
43
44
  RefPtr<VideoDataPromise>
45
  RequestVideoData(const media::TimeUnit& aTimeThreshold);
46
47
  RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType);
48
49
  RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
50
  RefPtr<ShutdownPromise> Shutdown();
51
52
  void ReleaseResources();
53
  void ResetDecode(TrackSet aTracks);
54
55
0
  nsresult Init() { return mReader->Init(); }
56
0
  bool UseBufferingHeuristics() const { return mReader->UseBufferingHeuristics(); }
57
58
0
  bool VideoIsHardwareAccelerated() const {
59
0
    return mReader->VideoIsHardwareAccelerated();
60
0
  }
61
0
  TimedMetadataEventSource& TimedMetadataEvent() {
62
0
    return mReader->TimedMetadataEvent();
63
0
  }
64
0
  MediaEventSource<void>& OnMediaNotSeekable() {
65
0
    return mReader->OnMediaNotSeekable();
66
0
  }
67
0
  size_t SizeOfAudioQueueInFrames() const {
68
0
    return mReader->SizeOfAudioQueueInFrames();
69
0
  }
70
0
  size_t SizeOfVideoQueueInFrames() const {
71
0
    return mReader->SizeOfVideoQueueInFrames();
72
0
  }
73
0
  void ReadUpdatedMetadata(MediaInfo* aInfo) {
74
0
    mReader->ReadUpdatedMetadata(aInfo);
75
0
  }
76
0
  AbstractCanonical<media::TimeIntervals>* CanonicalBuffered() {
77
0
    return mReader->CanonicalBuffered();
78
0
  }
79
80
0
  void SetCDMProxy(CDMProxy* aProxy) { mReader->SetCDMProxy(aProxy); }
81
82
  void SetVideoBlankDecode(bool aIsBlankDecode);
83
84
  void SetCanonicalDuration(
85
    AbstractCanonical<media::NullableTimeUnit>* aCanonical);
86
87
  void SetSeamlessLoopingEnabled(bool aEnabled);
88
89
  void AdjustByLooping(media::TimeUnit& aTime);
90
91
private:
92
  ~ReaderProxy();
93
  RefPtr<MetadataPromise> OnMetadataRead(MetadataHolder&& aMetadata);
94
  RefPtr<MetadataPromise> OnMetadataNotRead(const MediaResult& aError);
95
  void UpdateDuration();
96
  RefPtr<SeekPromise> SeekInternal(const SeekTarget& aTarget);
97
98
  RefPtr<ReaderProxy::AudioDataPromise> OnAudioDataRequestCompleted(
99
    RefPtr<AudioData> aAudio);
100
  RefPtr<ReaderProxy::AudioDataPromise> OnAudioDataRequestFailed(
101
    const MediaResult& aError);
102
103
  const RefPtr<AbstractThread> mOwnerThread;
104
  const RefPtr<MediaFormatReader> mReader;
105
106
  bool mShutdown = false;
107
  Maybe<media::TimeUnit> mStartTime;
108
109
  // State-watching manager.
110
  WatchManager<ReaderProxy> mWatchManager;
111
112
  // Duration, mirrored from the state machine task queue.
113
  Mirror<media::NullableTimeUnit> mDuration;
114
115
  // The total duration of audio looping in previous rounds.
116
  media::TimeUnit mLoopingOffset = media::TimeUnit::Zero();
117
  // To keep tracking the latest time of decoded audio data.
118
  media::TimeUnit mLastAudioEndTime = media::TimeUnit::Zero();
119
  // The duration of the audio track.
120
  media::TimeUnit mAudioDuration = media::TimeUnit::Invalid();
121
122
  // To prevent seamless looping while seeking.
123
  bool mSeamlessLoopingBlocked;
124
  // Indicates whether we should loop the media.
125
  bool mSeamlessLoopingEnabled;
126
};
127
128
} // namespace mozilla
129
130
#endif // ReaderProxy_h_