mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Backed out changeset abf7a473323c (bug 1089798)
--HG-- extra : rebase_source : c1248ca0d1b5f136c935a606f2968cc16aed2b7d
This commit is contained in:
parent
51d447f32c
commit
dc0853c72b
@ -5,7 +5,6 @@
|
||||
|
||||
#include "DOMMediaStream.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
#include "mozilla/dom/MediaStreamBinding.h"
|
||||
#include "mozilla/dom/LocalMediaStreamBinding.h"
|
||||
#include "mozilla/dom/AudioNode.h"
|
||||
@ -147,20 +146,6 @@ DOMMediaStream::DOMMediaStream()
|
||||
mStream(nullptr), mHintContents(0), mTrackTypesAvailable(0),
|
||||
mNotifiedOfMediaStreamGraphShutdown(false), mCORSMode(CORS_NONE)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||
do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && uuidgen) {
|
||||
nsID uuid;
|
||||
memset(&uuid, 0, sizeof(uuid));
|
||||
rv = uuidgen->GenerateUUIDInPlace(&uuid);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
char buffer[NSID_LENGTH];
|
||||
uuid.ToProvidedString(buffer);
|
||||
mID = NS_ConvertASCIItoUTF16(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOMMediaStream::~DOMMediaStream()
|
||||
|
@ -180,10 +180,6 @@ public:
|
||||
*/
|
||||
void NotifyStreamStateChanged();
|
||||
|
||||
// Webrtc allows the remote side to name a stream whatever it wants, and we
|
||||
// need to surface this to content.
|
||||
void AssignId(const nsAString& aID) { mID = aID; }
|
||||
|
||||
// Indicate what track types we eventually expect to add to this stream
|
||||
enum {
|
||||
HINT_CONTENTS_AUDIO = 1 << 0,
|
||||
|
@ -200,11 +200,14 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
CSFLogInfo(logTag, "Returning success for OnAddStream()");
|
||||
// We are running on main thread here so we shouldn't have a race
|
||||
// on this callback
|
||||
|
||||
nsTArray<nsRefPtr<MediaStreamTrack>> tracks;
|
||||
aStream->GetTracks(tracks);
|
||||
|
||||
std::string streamId = PeerConnectionImpl::GetStreamId(*aStream);
|
||||
bool notifyStream = true;
|
||||
bool newStream = true;
|
||||
|
||||
for (size_t i = 0; i < tracks.Length(); i++) {
|
||||
std::string trackId;
|
||||
@ -212,7 +215,7 @@ public:
|
||||
// track. It would be nice if we could specify this along with the numeric
|
||||
// track id from the start, but we're stuck doing this fixup after the
|
||||
// fact.
|
||||
nsresult rv = wrapper.impl()->GetRemoteTrackId(streamId,
|
||||
nsresult rv = wrapper.impl()->GetRemoteTrackId(aStream,
|
||||
tracks[i]->GetTrackID(),
|
||||
&trackId);
|
||||
|
||||
@ -229,15 +232,16 @@ public:
|
||||
|
||||
if (origTrackId == trackId) {
|
||||
// Pre-existing track
|
||||
notifyStream = false;
|
||||
newStream = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
tracks[i]->AssignId(NS_ConvertUTF8toUTF16(trackId.c_str()));
|
||||
|
||||
JSErrorResult jrv;
|
||||
CSFLogInfo(logTag, "Calling OnAddTrack(%s)", trackId.c_str());
|
||||
mObserver->OnAddTrack(*tracks[i], jrv);
|
||||
CSFLogInfo(logTag, "Calling OnAddTrack(%s)",
|
||||
PeerConnectionImpl::GetTrackId(*tracks[i]).c_str());
|
||||
if (jrv.Failed()) {
|
||||
CSFLogError(logTag, ": OnAddTrack(%u) failed! Error: %u",
|
||||
static_cast<unsigned>(i),
|
||||
@ -245,14 +249,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (notifyStream) {
|
||||
if (newStream) {
|
||||
// Start currentTime from the point where this stream was successfully
|
||||
// returned.
|
||||
aStream->SetLogicalStreamStartTime(
|
||||
aStream->GetStream()->GetCurrentTime());
|
||||
|
||||
JSErrorResult rv;
|
||||
CSFLogInfo(logTag, "Calling OnAddStream(%s)", streamId.c_str());
|
||||
CSFLogInfo(logTag, "Calling OnAddStream");
|
||||
mObserver->OnAddStream(*aStream, rv);
|
||||
if (rv.Failed()) {
|
||||
CSFLogError(logTag, ": OnAddStream() failed! Error: %u",
|
||||
@ -1659,12 +1663,6 @@ PeerConnectionImpl::SetRemoteDescription(int32_t action, const char* aSDP)
|
||||
return NS_OK;
|
||||
}
|
||||
CSFLogDebug(logTag, "Added remote stream %s", info->GetId().c_str());
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
info->GetMediaStream()->AssignId(NS_ConvertUTF8toUTF16(streamId.c_str()));
|
||||
#else
|
||||
info->GetMediaStream()->AssignId((streamId));
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t numNewAudioTracks = 0;
|
||||
@ -1931,7 +1929,7 @@ PeerConnectionImpl::PrincipalChanged(DOMMediaStream* aMediaStream) {
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
nsresult
|
||||
PeerConnectionImpl::GetRemoteTrackId(const std::string streamId,
|
||||
PeerConnectionImpl::GetRemoteTrackId(DOMMediaStream* mediaStream,
|
||||
TrackID numericTrackId,
|
||||
std::string* trackId) const
|
||||
{
|
||||
@ -1939,7 +1937,7 @@ PeerConnectionImpl::GetRemoteTrackId(const std::string streamId,
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
return mMedia->GetRemoteTrackId(streamId, numericTrackId, trackId);
|
||||
return mMedia->GetRemoteTrackId(mediaStream, numericTrackId, trackId);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1955,18 +1953,6 @@ PeerConnectionImpl::GetTrackId(const MediaStreamTrack& aTrack)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string
|
||||
PeerConnectionImpl::GetStreamId(const DOMMediaStream& aStream)
|
||||
{
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
nsString wideStreamId;
|
||||
aStream.GetId(wideStreamId);
|
||||
return NS_ConvertUTF16toUTF8(wideStreamId).get();
|
||||
#else
|
||||
return aStream.GetId();
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
PeerConnectionImpl::AddTrack(MediaStreamTrack& aTrack,
|
||||
const Sequence<OwningNonNull<DOMMediaStream>>& aStreams)
|
||||
@ -1990,9 +1976,10 @@ PeerConnectionImpl::AddTrack(MediaStreamTrack& aTrack,
|
||||
}
|
||||
uint32_t num = mMedia->LocalStreamsLength();
|
||||
|
||||
std::string streamId = PeerConnectionImpl::GetStreamId(aMediaStream);
|
||||
std::string streamId;
|
||||
std::string trackId = PeerConnectionImpl::GetTrackId(aTrack);
|
||||
nsresult res = mMedia->AddTrack(&aMediaStream, streamId, trackId);
|
||||
// TODO(bug 1089798): streamId should really come from the MS.
|
||||
nsresult res = mMedia->AddTrack(&aMediaStream, &streamId, trackId);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
@ -2056,8 +2043,8 @@ PeerConnectionImpl::RemoveTrack(MediaStreamTrack& aTrack) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
std::string streamId = PeerConnectionImpl::GetStreamId(*stream);
|
||||
nsRefPtr<LocalSourceStreamInfo> info = media()->GetLocalStreamById(streamId);
|
||||
nsRefPtr<LocalSourceStreamInfo> info =
|
||||
media()->GetLocalStreamByDomStream(*stream);
|
||||
|
||||
if (!info) {
|
||||
CSFLogError(logTag, "%s: Unknown stream", __FUNCTION__);
|
||||
@ -2127,8 +2114,8 @@ PeerConnectionImpl::ReplaceTrack(MediaStreamTrack& aThisTrack,
|
||||
// TrackID thisID = aThisTrack.GetTrackID();
|
||||
//
|
||||
|
||||
std::string streamId = PeerConnectionImpl::GetStreamId(aStream);
|
||||
nsRefPtr<LocalSourceStreamInfo> info = media()->GetLocalStreamById(streamId);
|
||||
nsRefPtr<LocalSourceStreamInfo> info =
|
||||
media()->GetLocalStreamByDomStream(aStream);
|
||||
|
||||
if (!info || !info->HasTrack(origTrackId)) {
|
||||
CSFLogError(logTag, "Track to replace (%s) was never added",
|
||||
|
@ -598,12 +598,11 @@ public:
|
||||
// PeerConnectionMedia can't do it because it doesn't know about principals
|
||||
virtual void PrincipalChanged(DOMMediaStream* aMediaStream) MOZ_OVERRIDE;
|
||||
|
||||
nsresult GetRemoteTrackId(const std::string streamId,
|
||||
nsresult GetRemoteTrackId(DOMMediaStream* mediaStream,
|
||||
TrackID numericTrackId,
|
||||
std::string* trackId) const;
|
||||
#endif
|
||||
|
||||
static std::string GetStreamId(const DOMMediaStream& aStream);
|
||||
static std::string GetTrackId(const dom::MediaStreamTrack& track);
|
||||
|
||||
private:
|
||||
|
@ -581,7 +581,7 @@ PeerConnectionMedia::UpdateIceMediaStream_s(size_t aMLine,
|
||||
|
||||
nsresult
|
||||
PeerConnectionMedia::AddTrack(DOMMediaStream* aMediaStream,
|
||||
const std::string& streamId,
|
||||
std::string* streamId,
|
||||
const std::string& trackId)
|
||||
{
|
||||
ASSERT_ON_THREAD(mMainThread);
|
||||
@ -594,14 +594,21 @@ PeerConnectionMedia::AddTrack(DOMMediaStream* aMediaStream,
|
||||
CSFLogDebug(logTag, "%s: MediaStream: %p", __FUNCTION__, aMediaStream);
|
||||
|
||||
nsRefPtr<LocalSourceStreamInfo> localSourceStream =
|
||||
GetLocalStreamById(streamId);
|
||||
GetLocalStreamByDomStream(*aMediaStream);
|
||||
|
||||
if (!localSourceStream) {
|
||||
localSourceStream = new LocalSourceStreamInfo(aMediaStream, this, streamId);
|
||||
std::string id;
|
||||
if (!mUuidGen->Generate(&id)) {
|
||||
CSFLogError(logTag, "Failed to generate UUID for stream");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
localSourceStream = new LocalSourceStreamInfo(aMediaStream, this, id);
|
||||
mLocalSourceStreams.AppendElement(localSourceStream);
|
||||
}
|
||||
|
||||
localSourceStream->AddTrack(trackId);
|
||||
*streamId = localSourceStream->GetId();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -614,15 +621,20 @@ PeerConnectionMedia::RemoveLocalTrack(const std::string& streamId,
|
||||
CSFLogDebug(logTag, "%s: stream: %s track: %s", __FUNCTION__,
|
||||
streamId.c_str(), trackId.c_str());
|
||||
|
||||
nsRefPtr<LocalSourceStreamInfo> localSourceStream =
|
||||
GetLocalStreamById(streamId);
|
||||
if (!localSourceStream) {
|
||||
size_t i;
|
||||
for (i = 0; i < mLocalSourceStreams.Length(); ++i) {
|
||||
if (mLocalSourceStreams[i]->GetId() == streamId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == mLocalSourceStreams.Length()) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
localSourceStream->RemoveTrack(trackId);
|
||||
if (!localSourceStream->GetTrackCount()) {
|
||||
mLocalSourceStreams.RemoveElement(localSourceStream);
|
||||
mLocalSourceStreams[i]->RemoveTrack(trackId);
|
||||
if (!(mLocalSourceStreams[i]->GetTrackCount())) {
|
||||
mLocalSourceStreams.RemoveElementAt(i);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -636,27 +648,32 @@ PeerConnectionMedia::RemoveRemoteTrack(const std::string& streamId,
|
||||
CSFLogDebug(logTag, "%s: stream: %s track: %s", __FUNCTION__,
|
||||
streamId.c_str(), trackId.c_str());
|
||||
|
||||
nsRefPtr<RemoteSourceStreamInfo> remoteSourceStream =
|
||||
GetRemoteStreamById(streamId);
|
||||
if (!remoteSourceStream) {
|
||||
size_t i;
|
||||
for (i = 0; i < mRemoteSourceStreams.Length(); ++i) {
|
||||
if (mRemoteSourceStreams[i]->GetId() == streamId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == mRemoteSourceStreams.Length()) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
remoteSourceStream->RemoveTrack(trackId);
|
||||
if (!remoteSourceStream->GetTrackCount()) {
|
||||
mRemoteSourceStreams.RemoveElement(remoteSourceStream);
|
||||
mRemoteSourceStreams[i]->RemoveTrack(trackId);
|
||||
if (!(mRemoteSourceStreams[i]->GetTrackCount())) {
|
||||
mRemoteSourceStreams.RemoveElementAt(i);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
PeerConnectionMedia::GetRemoteTrackId(const std::string streamId,
|
||||
PeerConnectionMedia::GetRemoteTrackId(DOMMediaStream* mediaStream,
|
||||
TrackID numericTrackId,
|
||||
std::string* trackId) const
|
||||
{
|
||||
auto* ncThis = const_cast<PeerConnectionMedia*>(this);
|
||||
const RemoteSourceStreamInfo* info =
|
||||
ncThis->GetRemoteStreamById(streamId);
|
||||
ncThis->GetRemoteStreamByDomStream(*mediaStream);
|
||||
|
||||
if (!info) {
|
||||
CSFLogError(logTag, "%s: Could not find stream info", __FUNCTION__);
|
||||
@ -759,6 +776,35 @@ PeerConnectionMedia::GetLocalStreamById(const std::string& id)
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LocalSourceStreamInfo*
|
||||
PeerConnectionMedia::GetLocalStreamByDomStream(const DOMMediaStream& stream)
|
||||
{
|
||||
ASSERT_ON_THREAD(mMainThread);
|
||||
for (size_t i = 0; i < mLocalSourceStreams.Length(); ++i) {
|
||||
if (&stream == mLocalSourceStreams[i]->GetMediaStream()) {
|
||||
return mLocalSourceStreams[i];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RemoteSourceStreamInfo*
|
||||
PeerConnectionMedia::GetRemoteStreamByDomStream(
|
||||
const DOMMediaStream& stream)
|
||||
{
|
||||
ASSERT_ON_THREAD(mMainThread);
|
||||
for (size_t i = 0; i < mRemoteSourceStreams.Length(); ++i) {
|
||||
if (&stream == mRemoteSourceStreams[i]->GetMediaStream()) {
|
||||
return mRemoteSourceStreams[i];
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -780,6 +826,10 @@ PeerConnectionMedia::GetRemoteStreamById(const std::string& id)
|
||||
}
|
||||
}
|
||||
|
||||
// This does not have a MOZ_ASSERT like GetLocalStreamById because in the
|
||||
// case of local streams, the stream id and stream info are created
|
||||
// simultaneously, whereas in the remote case the stream id exists first,
|
||||
// meaning we have to be able to check.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -241,8 +241,10 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
|
||||
nsresult UpdateMediaPipelines(const JsepSession& session);
|
||||
|
||||
// Add a track (main thread only)
|
||||
// TODO(bug 1089798): Once DOMMediaStream has an id field, use it instead of
|
||||
// letting PCMedia choose a streamId
|
||||
nsresult AddTrack(DOMMediaStream* aMediaStream,
|
||||
const std::string& streamId,
|
||||
std::string* streamId,
|
||||
const std::string& trackId);
|
||||
|
||||
nsresult RemoveLocalTrack(const std::string& streamId,
|
||||
@ -250,7 +252,7 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
|
||||
nsresult RemoveRemoteTrack(const std::string& streamId,
|
||||
const std::string& trackId);
|
||||
|
||||
nsresult GetRemoteTrackId(const std::string streamId,
|
||||
nsresult GetRemoteTrackId(DOMMediaStream* mediaStream,
|
||||
TrackID numericTrackId,
|
||||
std::string* trackId) const;
|
||||
|
||||
@ -261,6 +263,8 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
|
||||
}
|
||||
LocalSourceStreamInfo* GetLocalStreamByIndex(int index);
|
||||
LocalSourceStreamInfo* GetLocalStreamById(const std::string& id);
|
||||
LocalSourceStreamInfo* GetLocalStreamByDomStream(
|
||||
const DOMMediaStream& stream);
|
||||
|
||||
// Get a specific remote stream
|
||||
uint32_t RemoteStreamsLength()
|
||||
@ -270,6 +274,8 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
|
||||
|
||||
RemoteSourceStreamInfo* GetRemoteStreamByIndex(size_t index);
|
||||
RemoteSourceStreamInfo* GetRemoteStreamById(const std::string& id);
|
||||
RemoteSourceStreamInfo* GetRemoteStreamByDomStream(
|
||||
const DOMMediaStream& stream);
|
||||
|
||||
// Add a remote stream.
|
||||
nsresult AddRemoteStream(nsRefPtr<RemoteSourceStreamInfo> aInfo);
|
||||
|
@ -285,8 +285,6 @@ public:
|
||||
virtual void RemoveDirectListener(Fake_MediaStreamListener *aListener) {}
|
||||
|
||||
Fake_MediaStream *GetStream() { return mMediaStream; }
|
||||
std::string GetId() const { return mID; }
|
||||
void AssignId(const std::string& id) { mID = id; }
|
||||
|
||||
// Hints to tell the SDP generator about whether this
|
||||
// MediaStream probably has audio and/or video
|
||||
@ -345,8 +343,6 @@ private:
|
||||
uint32_t mHintContents;
|
||||
nsRefPtr<Fake_MediaStreamTrack> mVideoTrack;
|
||||
nsRefPtr<Fake_MediaStreamTrack> mAudioTrack;
|
||||
|
||||
std::string mID;
|
||||
};
|
||||
|
||||
class Fake_MediaStreamBase : public Fake_MediaStream {
|
||||
|
Loading…
x
Reference in New Issue
Block a user