/src/mozilla-central/dom/media/mediasink/OutputStreamManager.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 OutputStreamManager_h |
8 | | #define OutputStreamManager_h |
9 | | |
10 | | #include "mozilla/RefPtr.h" |
11 | | #include "nsTArray.h" |
12 | | #include "TrackID.h" |
13 | | |
14 | | namespace mozilla { |
15 | | |
16 | | class MediaInputPort; |
17 | | class MediaStream; |
18 | | class MediaStreamGraph; |
19 | | class OutputStreamManager; |
20 | | class ProcessedMediaStream; |
21 | | |
22 | | class OutputStreamData { |
23 | | public: |
24 | | ~OutputStreamData(); |
25 | | void Init(OutputStreamManager* aOwner, |
26 | | ProcessedMediaStream* aStream, |
27 | | TrackID aNextAvailableTrackID); |
28 | | |
29 | | // Connect the given input stream's audio and video tracks to mStream. |
30 | | // Return false is mStream is already destroyed, otherwise true. |
31 | | bool Connect(MediaStream* aStream, TrackID aAudioTrackID, TrackID aVideoTrackID); |
32 | | // Disconnect mStream from its input stream. |
33 | | // Return false is mStream is already destroyed, otherwise true. |
34 | | bool Disconnect(); |
35 | | // Return true if aStream points to the same object as mStream. |
36 | | // Used by OutputStreamManager to remove an output stream. |
37 | | bool Equals(MediaStream* aStream) const; |
38 | | // Return the graph mStream belongs to. |
39 | | MediaStreamGraph* Graph() const; |
40 | | // The next TrackID that will not cause a collision in mStream. |
41 | | TrackID NextAvailableTrackID() const; |
42 | | |
43 | | private: |
44 | | OutputStreamManager* mOwner; |
45 | | RefPtr<ProcessedMediaStream> mStream; |
46 | | // mPort connects an input stream to our mStream. |
47 | | nsTArray<RefPtr<MediaInputPort>> mPorts; |
48 | | // For guaranteeing TrackID uniqueness in our mStream. |
49 | | TrackID mNextAvailableTrackID = TRACK_INVALID; |
50 | | }; |
51 | | |
52 | | class OutputStreamManager { |
53 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OutputStreamManager); |
54 | | |
55 | | public: |
56 | | // Add the output stream to the collection. |
57 | | void Add(ProcessedMediaStream* aStream, |
58 | | TrackID aNextAvailableTrackID, |
59 | | bool aFinishWhenEnded); |
60 | | // Remove the output stream from the collection. |
61 | | void Remove(MediaStream* aStream); |
62 | | // Clear all output streams from the collection. |
63 | | void Clear(); |
64 | | // The next TrackID that will not cause a collision in aOutputStream. |
65 | | TrackID NextAvailableTrackIDFor(MediaStream* aOutputStream) const; |
66 | | // Return true if the collection empty. |
67 | | bool IsEmpty() const |
68 | 0 | { |
69 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
70 | 0 | return mStreams.IsEmpty(); |
71 | 0 | } |
72 | | // Connect the given input stream's tracks to all output streams. |
73 | | void Connect(MediaStream* aStream, |
74 | | TrackID aAudioTrackID, |
75 | | TrackID aVideoTrackID); |
76 | | // Disconnect the input stream to all output streams. |
77 | | void Disconnect(); |
78 | | // Return the graph these streams belong to or null if empty. |
79 | | MediaStreamGraph* Graph() const |
80 | 0 | { |
81 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
82 | 0 | return !IsEmpty() ? mStreams[0].Graph() : nullptr; |
83 | 0 | } |
84 | | |
85 | | private: |
86 | 0 | ~OutputStreamManager() {} |
87 | | // Keep the input stream so we can connect the output streams that |
88 | | // are added after Connect(). |
89 | | RefPtr<MediaStream> mInputStream; |
90 | | TrackID mInputAudioTrackID = TRACK_INVALID; |
91 | | TrackID mInputVideoTrackID = TRACK_INVALID; |
92 | | nsTArray<OutputStreamData> mStreams; |
93 | | }; |
94 | | |
95 | | } // namespace mozilla |
96 | | |
97 | | #endif // OutputStreamManager_h |