Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/mediasink/VideoSink.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 VideoSink_h_
8
#define VideoSink_h_
9
10
#include "FrameStatistics.h"
11
#include "ImageContainer.h"
12
#include "MediaEventSource.h"
13
#include "MediaSink.h"
14
#include "MediaTimer.h"
15
#include "mozilla/AbstractThread.h"
16
#include "mozilla/MozPromise.h"
17
#include "mozilla/RefPtr.h"
18
#include "mozilla/TimeStamp.h"
19
#include "VideoFrameContainer.h"
20
21
namespace mozilla {
22
23
class VideoFrameContainer;
24
template <class T> class MediaQueue;
25
26
namespace media {
27
28
class VideoSink : public MediaSink
29
{
30
  typedef mozilla::layers::ImageContainer::ProducerID ProducerID;
31
public:
32
  VideoSink(AbstractThread* aThread,
33
            MediaSink* aAudioSink,
34
            MediaQueue<VideoData>& aVideoQueue,
35
            VideoFrameContainer* aContainer,
36
            FrameStatistics& aFrameStats,
37
            uint32_t aVQueueSentToCompositerSize);
38
39
  const PlaybackParams& GetPlaybackParams() const override;
40
41
  void SetPlaybackParams(const PlaybackParams& aParams) override;
42
43
  RefPtr<GenericPromise> OnEnded(TrackType aType) override;
44
45
  TimeUnit GetEndTime(TrackType aType) const override;
46
47
  TimeUnit GetPosition(TimeStamp* aTimeStamp = nullptr) const override;
48
49
  bool HasUnplayedFrames(TrackType aType) const override;
50
51
  void SetPlaybackRate(double aPlaybackRate) override;
52
53
  void SetVolume(double aVolume) override;
54
55
  void SetPreservesPitch(bool aPreservesPitch) override;
56
57
  void SetPlaying(bool aPlaying) override;
58
59
  void Redraw(const VideoInfo& aInfo) override;
60
61
  void Start(const TimeUnit& aStartTime, const MediaInfo& aInfo) override;
62
63
  void Stop() override;
64
65
  bool IsStarted() const override;
66
67
  bool IsPlaying() const override;
68
69
  void Shutdown() override;
70
71
  nsCString GetDebugInfo() override;
72
73
private:
74
  virtual ~VideoSink();
75
76
  // VideoQueue listener related.
77
  void OnVideoQueuePushed(RefPtr<VideoData>&& aSample);
78
  void OnVideoQueueFinished();
79
  void ConnectListener();
80
  void DisconnectListener();
81
82
  void EnsureHighResTimersOnOnlyIfPlaying();
83
84
  // Sets VideoQueue images into the VideoFrameContainer. Called on the shared
85
  // state machine thread. The first aMaxFrames (at most) are set.
86
  // aClockTime and aClockTimeStamp are used as the baseline for deriving
87
  // timestamps for the frames; when omitted, aMaxFrames must be 1 and
88
  // a null timestamp is passed to the VideoFrameContainer.
89
  // If the VideoQueue is empty, this does nothing.
90
  void RenderVideoFrames(int32_t aMaxFrames, int64_t aClockTime = 0,
91
                         const TimeStamp& aClickTimeStamp = TimeStamp());
92
93
  // Triggered while videosink is started, videosink becomes "playing" status,
94
  // or VideoQueue event arrived.
95
  void TryUpdateRenderedVideoFrames();
96
97
  // If we have video, display a video frame if it's time for display has
98
  // arrived, otherwise sleep until it's time for the next frame. Update the
99
  // current frame time as appropriate, and trigger ready state update.
100
  // Called on the shared state machine thread.
101
  void UpdateRenderedVideoFrames();
102
  void UpdateRenderedVideoFramesByTimer();
103
104
  void MaybeResolveEndPromise();
105
106
  void AssertOwnerThread() const
107
0
  {
108
0
    MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
109
0
  }
110
111
  MediaQueue<VideoData>& VideoQueue() const
112
0
  {
113
0
    return mVideoQueue;
114
0
  }
115
116
  const RefPtr<AbstractThread> mOwnerThread;
117
  RefPtr<MediaSink> mAudioSink;
118
  MediaQueue<VideoData>& mVideoQueue;
119
  VideoFrameContainer* mContainer;
120
121
  // Producer ID to help ImageContainer distinguish different streams of
122
  // FrameIDs. A unique and immutable value per VideoSink.
123
  const ProducerID mProducerID;
124
125
  // Used to notify MediaDecoder's frame statistics
126
  FrameStatistics& mFrameStats;
127
128
  RefPtr<GenericPromise> mEndPromise;
129
  MozPromiseHolder<GenericPromise> mEndPromiseHolder;
130
  MozPromiseRequestHolder<GenericPromise> mVideoSinkEndRequest;
131
132
  // The presentation end time of the last video frame which has been displayed.
133
  TimeUnit mVideoFrameEndTime;
134
135
  uint32_t mOldCompositorDroppedCount;
136
  uint32_t mPendingDroppedCount;
137
138
  // Event listeners for VideoQueue
139
  MediaEventListener mPushListener;
140
  MediaEventListener mFinishListener;
141
142
  // True if this sink is going to handle video track.
143
  bool mHasVideo;
144
145
  // Used to trigger another update of rendered frames in next round.
146
  DelayedScheduler mUpdateScheduler;
147
148
  // Max frame number sent to compositor at a time.
149
  // Based on the pref value obtained in MDSM.
150
  const uint32_t mVideoQueueSendToCompositorSize;
151
152
  // Talos tests for the compositor require at least one frame in the
153
  // video queue so that the compositor has something to composit during
154
  // the talos test when the decode is stressed. We have a minimum size
155
  // on the video queue in order to facilitate this talos test.
156
  // Note: Normal playback should not have a queue size of more than 0,
157
  // otherwise A/V sync will be ruined! *Only* make this non-zero for
158
  // testing purposes.
159
  const uint32_t mMinVideoQueueSize;
160
161
#ifdef XP_WIN
162
  // Whether we've called timeBeginPeriod(1) to request high resolution
163
  // timers. We request high resolution timers when playback starts, and
164
  // turn them off when playback is paused. Enabling high resolution
165
  // timers can cause higher CPU usage and battery drain on Windows 7,
166
  // but reduces our frame drop rate.
167
  bool mHiResTimersRequested;
168
#endif
169
};
170
171
} // namespace media
172
} // namespace mozilla
173
174
#endif