summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasink
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/mediasink')
-rw-r--r--dom/media/mediasink/DecodedStream.cpp11
-rw-r--r--dom/media/mediasink/OutputStreamManager.cpp75
-rw-r--r--dom/media/mediasink/OutputStreamManager.h35
3 files changed, 94 insertions, 27 deletions
diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp
index 9501a6cde..00bc5ea49 100644
--- a/dom/media/mediasink/DecodedStream.cpp
+++ b/dom/media/mediasink/DecodedStream.cpp
@@ -181,17 +181,22 @@ DecodedStreamData::DecodedStreamData(OutputStreamManager* aOutputStreamManager,
, mOutputStreamManager(aOutputStreamManager)
{
mStream->AddListener(mListener);
- mOutputStreamManager->Connect(mStream);
+ TrackID audioTrack = TRACK_NONE;
+ TrackID videoTrack = TRACK_NONE;
// Initialize tracks.
if (aInit.mInfo.HasAudio()) {
- mStream->AddAudioTrack(aInit.mInfo.mAudio.mTrackId,
+ audioTrack = aInit.mInfo.mAudio.mTrackId;
+ mStream->AddAudioTrack(audioTrack,
aInit.mInfo.mAudio.mRate,
0, new AudioSegment());
}
if (aInit.mInfo.HasVideo()) {
- mStream->AddTrack(aInit.mInfo.mVideo.mTrackId, 0, new VideoSegment());
+ videoTrack = aInit.mInfo.mVideo.mTrackId;
+ mStream->AddTrack(videoTrack, 0, new VideoSegment());
}
+
+ mOutputStreamManager->Connect(mStream, audioTrack, videoTrack);
}
DecodedStreamData::~DecodedStreamData()
diff --git a/dom/media/mediasink/OutputStreamManager.cpp b/dom/media/mediasink/OutputStreamManager.cpp
index d5685837a..7ecc203ed 100644
--- a/dom/media/mediasink/OutputStreamManager.cpp
+++ b/dom/media/mediasink/OutputStreamManager.cpp
@@ -13,29 +13,41 @@ OutputStreamData::~OutputStreamData()
{
MOZ_ASSERT(NS_IsMainThread());
// Break the connection to the input stream if necessary.
- if (mPort) {
- mPort->Destroy();
+ for (RefPtr<MediaInputPort>& port : mPorts) {
+ port->Destroy();
}
}
void
-OutputStreamData::Init(OutputStreamManager* aOwner, ProcessedMediaStream* aStream)
+OutputStreamData::Init(OutputStreamManager* aOwner,
+ ProcessedMediaStream* aStream,
+ TrackID aNextAvailableTrackID)
{
mOwner = aOwner;
mStream = aStream;
+ mNextAvailableTrackID = aNextAvailableTrackID;
}
bool
-OutputStreamData::Connect(MediaStream* aStream)
+OutputStreamData::Connect(MediaStream* aStream,
+ TrackID aInputAudioTrackID,
+ TrackID aInputVideoTrackID)
{
MOZ_ASSERT(NS_IsMainThread());
- MOZ_ASSERT(!mPort, "Already connected?");
+ MOZ_ASSERT(mPorts.IsEmpty(), "Already connected?");
if (mStream->IsDestroyed()) {
return false;
}
- mPort = mStream->AllocateInputPort(aStream);
+ for (TrackID tid : {aInputAudioTrackID, aInputVideoTrackID}) {
+ if (tid == TRACK_NONE) {
+ continue;
+ }
+ MOZ_ASSERT(IsTrackIDExplicit(tid));
+ mPorts.AppendElement(mStream->AllocateInputPort(
+ aStream, tid, mNextAvailableTrackID++));
+ }
return true;
}
@@ -51,11 +63,11 @@ OutputStreamData::Disconnect()
return false;
}
- // Disconnect the existing port if necessary.
- if (mPort) {
- mPort->Destroy();
- mPort = nullptr;
+ // Disconnect any existing port.
+ for (RefPtr<MediaInputPort>& port : mPorts) {
+ port->Destroy();
}
+ mPorts.Clear();
return true;
}
@@ -71,8 +83,16 @@ OutputStreamData::Graph() const
return mStream->Graph();
}
+TrackID
+OutputStreamData::NextAvailableTrackID() const
+{
+ return mNextAvailableTrackID;
+}
+
void
-OutputStreamManager::Add(ProcessedMediaStream* aStream, bool aFinishWhenEnded)
+OutputStreamManager::Add(ProcessedMediaStream* aStream,
+ TrackID aNextAvailableTrackID,
+ bool aFinishWhenEnded)
{
MOZ_ASSERT(NS_IsMainThread());
// All streams must belong to the same graph.
@@ -84,12 +104,12 @@ OutputStreamManager::Add(ProcessedMediaStream* aStream, bool aFinishWhenEnded)
}
OutputStreamData* p = mStreams.AppendElement();
- p->Init(this, aStream);
+ p->Init(this, aStream, aNextAvailableTrackID);
// Connect to the input stream if we have one. Otherwise the output stream
// will be connected in Connect().
if (mInputStream) {
- p->Connect(mInputStream);
+ p->Connect(mInputStream, mInputAudioTrackID, mInputVideoTrackID);
}
}
@@ -106,12 +126,35 @@ OutputStreamManager::Remove(MediaStream* aStream)
}
void
-OutputStreamManager::Connect(MediaStream* aStream)
+OutputStreamManager::Clear()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ mStreams.Clear();
+}
+
+TrackID
+OutputStreamManager::NextAvailableTrackIDFor(MediaStream* aOutputStream) const
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ for (const OutputStreamData& out : mStreams) {
+ if (out.Equals(aOutputStream)) {
+ return out.NextAvailableTrackID();
+ }
+ }
+ return TRACK_INVALID;
+}
+
+void
+OutputStreamManager::Connect(MediaStream* aStream,
+ TrackID aAudioTrackID,
+ TrackID aVideoTrackID)
{
MOZ_ASSERT(NS_IsMainThread());
mInputStream = aStream;
+ mInputAudioTrackID = aAudioTrackID;
+ mInputVideoTrackID = aVideoTrackID;
for (int32_t i = mStreams.Length() - 1; i >= 0; --i) {
- if (!mStreams[i].Connect(aStream)) {
+ if (!mStreams[i].Connect(aStream, mInputAudioTrackID, mInputVideoTrackID)) {
// Probably the DOMMediaStream was GCed. Clean up.
mStreams.RemoveElementAt(i);
}
@@ -123,6 +166,8 @@ OutputStreamManager::Disconnect()
{
MOZ_ASSERT(NS_IsMainThread());
mInputStream = nullptr;
+ mInputAudioTrackID = TRACK_INVALID;
+ mInputVideoTrackID = TRACK_INVALID;
for (int32_t i = mStreams.Length() - 1; i >= 0; --i) {
if (!mStreams[i].Disconnect()) {
// Probably the DOMMediaStream was GCed. Clean up.
diff --git a/dom/media/mediasink/OutputStreamManager.h b/dom/media/mediasink/OutputStreamManager.h
index 7f91a60c1..941a86cf0 100644
--- a/dom/media/mediasink/OutputStreamManager.h
+++ b/dom/media/mediasink/OutputStreamManager.h
@@ -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;
};