nsresult PeerConnectionMedia::AddTrack(DOMMediaStream* aMediaStream, const std::string& streamId, const std::string& trackId) { ASSERT_ON_THREAD(mMainThread); if (!aMediaStream) { CSFLogError(logTag, "%s - aMediaStream is NULL", __FUNCTION__); return NS_ERROR_FAILURE; } CSFLogDebug(logTag, "%s: MediaStream: %p", __FUNCTION__, aMediaStream); RefPtr<LocalSourceStreamInfo> localSourceStream = GetLocalStreamById(streamId); if (!localSourceStream) { localSourceStream = new LocalSourceStreamInfo(aMediaStream, this, streamId); mLocalSourceStreams.AppendElement(localSourceStream); } localSourceStream->AddTrack(trackId); return NS_OK; }
/* static */ already_AddRefed<DOMMediaStream> DOMMediaStream::Constructor(const GlobalObject& aGlobal, const Sequence<OwningNonNull<MediaStreamTrack>>& aTracks, ErrorResult& aRv) { nsCOMPtr<nsIDOMWindow> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports()); if (!ownerWindow) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } RefPtr<DOMMediaStream> newStream = new DOMMediaStream(); newStream->mWindow = ownerWindow; for (MediaStreamTrack& track : aTracks) { if (!newStream->GetPlaybackStream()) { MOZ_RELEASE_ASSERT(track.GetStream()); MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream()); MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream()->Graph()); MediaStreamGraph* graph = track.GetStream()->GetPlaybackStream()->Graph(); newStream->InitPlaybackStreamCommon(graph); } newStream->AddTrack(track); } if (!newStream->GetPlaybackStream()) { MOZ_ASSERT(aTracks.IsEmpty()); MediaStreamGraph* graph = MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER, AudioChannel::Normal); newStream->InitPlaybackStreamCommon(graph); } return newStream.forget(); }
nsresult PeerConnectionMedia::AddTrack(DOMMediaStream& aMediaStream, const std::string& streamId, MediaStreamTrack& aTrack, const std::string& trackId) { ASSERT_ON_THREAD(mMainThread); CSFLogDebug(logTag, "%s: MediaStream: %p", __FUNCTION__, &aMediaStream); RefPtr<LocalSourceStreamInfo> localSourceStream = GetLocalStreamById(streamId); if (!localSourceStream) { localSourceStream = new LocalSourceStreamInfo(&aMediaStream, this, streamId); mLocalSourceStreams.AppendElement(localSourceStream); } localSourceStream->AddTrack(trackId, &aTrack); return NS_OK; }