Media: harden TrackID handling.

This commit is contained in:
wolfbeast 2018-06-07 16:04:56 +02:00 • committed by Roy Tam
commit 0bdecfc6ea
9 changed files with 183 additions and 37 deletions

View file

@ -9,6 +9,7 @@
#include "mozilla/RefPtr.h"
#include "nsTArray.h"
#include "MediaSegment.h"
namespace mozilla {
@ -21,11 +22,13 @@ class ProcessedMediaStream;
class OutputStreamData {
public:
~OutputStreamData();
void Init(OutputStreamManager* aOwner, ProcessedMediaStream* aStream);
void Init(OutputStreamManager* aOwner,
ProcessedMediaStream* aStream,
TrackID aNextAvailableTrackID);
// Connect mStream to the input stream.
// Connect the given input stream's audio and video tracks to mStream.
// Return false is mStream is already destroyed, otherwise true.
bool Connect(MediaStream* aStream);
bool Connect(MediaStream* aStream, TrackID aAudioTrackID, TrackID aVideoTrackID);
// Disconnect mStream from its input stream.
// Return false is mStream is already destroyed, otherwise true.
bool Disconnect();
@ -34,12 +37,16 @@ public:
bool Equals(MediaStream* aStream) const;
// Return the graph mStream belongs to.
MediaStreamGraph* Graph() const;
// The next TrackID that will not cause a collision in mStream.
TrackID NextAvailableTrackID() const;
private:
OutputStreamManager* mOwner;
RefPtr<ProcessedMediaStream> mStream;
// mPort connects our mStream to an input stream.
RefPtr<MediaInputPort> mPort;
// mPort connects an input stream to our mStream.
nsTArray<RefPtr<MediaInputPort>> mPorts;
// For guaranteeing TrackID uniqueness in our mStream.
TrackID mNextAvailableTrackID = TRACK_INVALID;
};
class OutputStreamManager {
@ -47,18 +54,26 @@ class OutputStreamManager {
public:
// Add the output stream to the collection.
void Add(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
void Add(ProcessedMediaStream* aStream,
TrackID aNextAvailableTrackID,
bool aFinishWhenEnded);
// Remove the output stream from the collection.
void Remove(MediaStream* aStream);
// Clear all output streams from the collection.
void Clear();
// The next TrackID that will not cause a collision in aOutputStream.
TrackID NextAvailableTrackIDFor(MediaStream* aOutputStream) const;
// Return true if the collection empty.
bool IsEmpty() const
{
MOZ_ASSERT(NS_IsMainThread());
return mStreams.IsEmpty();
}
// Connect all output streams in the collection to the input stream.
void Connect(MediaStream* aStream);
// Disconnect all output streams from the input stream.
// Connect the given input stream's tracks to all output streams.
void Connect(MediaStream* aStream,
TrackID aAudioTrackID,
TrackID aVideoTrackID);
// Disconnect the input stream to all output streams.
void Disconnect();
// Return the graph these streams belong to or null if empty.
MediaStreamGraph* Graph() const
@ -72,6 +87,8 @@ private:
// Keep the input stream so we can connect the output streams that
// are added after Connect().
RefPtr<MediaStream> mInputStream;
TrackID mInputAudioTrackID = TRACK_INVALID;
TrackID mInputVideoTrackID = TRACK_INVALID;
nsTArray<OutputStreamData> mStreams;
};