Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/mediasink/DecodedStream.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 DecodedStream_h_
8
#define DecodedStream_h_
9
10
#include "MediaEventSource.h"
11
#include "MediaInfo.h"
12
#include "MediaSegment.h"
13
#include "MediaSink.h"
14
15
#include "mozilla/AbstractThread.h"
16
#include "mozilla/Maybe.h"
17
#include "mozilla/MozPromise.h"
18
#include "mozilla/RefPtr.h"
19
#include "mozilla/UniquePtr.h"
20
21
namespace mozilla {
22
23
class DecodedStreamData;
24
class AudioData;
25
class VideoData;
26
class MediaStream;
27
class OutputStreamManager;
28
struct PlaybackInfoInit;
29
class ProcessedMediaStream;
30
class TimeStamp;
31
32
template <class T> class MediaQueue;
33
34
class DecodedStream : public media::MediaSink {
35
  using media::MediaSink::PlaybackParams;
36
37
public:
38
  DecodedStream(AbstractThread* aOwnerThread,
39
                AbstractThread* aMainThread,
40
                MediaQueue<AudioData>& aAudioQueue,
41
                MediaQueue<VideoData>& aVideoQueue,
42
                OutputStreamManager* aOutputStreamManager,
43
                const bool& aSameOrigin,
44
                const PrincipalHandle& aPrincipalHandle);
45
46
  // MediaSink functions.
47
  const PlaybackParams& GetPlaybackParams() const override;
48
  void SetPlaybackParams(const PlaybackParams& aParams) override;
49
50
  RefPtr<GenericPromise> OnEnded(TrackType aType) override;
51
  media::TimeUnit GetEndTime(TrackType aType) const override;
52
  media::TimeUnit GetPosition(TimeStamp* aTimeStamp = nullptr) const override;
53
  bool HasUnplayedFrames(TrackType aType) const override
54
0
  {
55
0
    // TODO: implement this.
56
0
    return false;
57
0
  }
58
59
  void SetVolume(double aVolume) override;
60
  void SetPlaybackRate(double aPlaybackRate) override;
61
  void SetPreservesPitch(bool aPreservesPitch) override;
62
  void SetPlaying(bool aPlaying) override;
63
64
  void Start(const media::TimeUnit& aStartTime, const MediaInfo& aInfo) override;
65
  void Stop() override;
66
  bool IsStarted() const override;
67
  bool IsPlaying() const override;
68
69
  nsCString GetDebugInfo() override;
70
71
protected:
72
  virtual ~DecodedStream();
73
74
private:
75
  media::TimeUnit FromMicroseconds(int64_t aTime)
76
0
  {
77
0
    return media::TimeUnit::FromMicroseconds(aTime);
78
0
  }
79
  void DestroyData(UniquePtr<DecodedStreamData> aData);
80
  void AdvanceTracks();
81
  void SendAudio(double aVolume, bool aIsSameOrigin, const PrincipalHandle& aPrincipalHandle);
82
  void SendVideo(bool aIsSameOrigin, const PrincipalHandle& aPrincipalHandle);
83
  void SendData();
84
  void NotifyOutput(int64_t aTime);
85
86
0
  void AssertOwnerThread() const {
87
0
    MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
88
0
  }
89
90
  void ConnectListener();
91
  void DisconnectListener();
92
93
  const RefPtr<AbstractThread> mOwnerThread;
94
95
  const RefPtr<AbstractThread> mAbstractMainThread;
96
97
  /*
98
   * Main thread only members.
99
   */
100
  // Data about MediaStreams that are being fed by the decoder.
101
  const RefPtr<OutputStreamManager> mOutputStreamManager;
102
103
  /*
104
   * Worker thread only members.
105
   */
106
  UniquePtr<DecodedStreamData> mData;
107
  RefPtr<GenericPromise> mFinishPromise;
108
109
  bool mPlaying;
110
  const bool& mSameOrigin; // valid until Shutdown() is called.
111
  const PrincipalHandle& mPrincipalHandle; // valid until Shutdown() is called.
112
113
  PlaybackParams mParams;
114
115
  media::NullableTimeUnit mStartTime;
116
  media::TimeUnit mLastOutputTime;
117
  MediaInfo mInfo;
118
119
  MediaQueue<AudioData>& mAudioQueue;
120
  MediaQueue<VideoData>& mVideoQueue;
121
122
  MediaEventListener mAudioPushListener;
123
  MediaEventListener mVideoPushListener;
124
  MediaEventListener mAudioFinishListener;
125
  MediaEventListener mVideoFinishListener;
126
  MediaEventListener mOutputListener;
127
};
128
129
} // namespace mozilla
130
131
#endif // DecodedStream_h_