Bug 1213517 - make getUserMedia store initial constraints on resulting tracks. r=jesup

MozReview-Commit-ID: 291CrmVmq4x

--HG--
extra : rebase_source : d29e6996ee93b01c8abe3a98a3f6d05e98bce3c5
This commit is contained in:
Jan-Ivar Bruaroey 2015-11-24 23:42:26 -05:00
Родитель 9e1ebfb7eb
Коммит 594073da3e
8 изменённых файлов: 52 добавлений и 41 удалений

Просмотреть файл

@ -16,8 +16,9 @@ class AudioStreamTrack : public MediaStreamTrack {
public:
AudioStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
TrackID aInputTrackID,
MediaStreamTrackSource* aSource)
: MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource) {}
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints = MediaTrackConstraints())
: MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource, aConstraints) {}
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -35,7 +36,8 @@ protected:
return do_AddRef(new AudioStreamTrack(aOwningStream,
aTrackID,
mInputTrackID,
mSource));
mSource,
mConstraints));
}
};

Просмотреть файл

@ -979,7 +979,8 @@ DOMMediaStream::RemovePrincipalChangeObserver(
MediaStreamTrack*
DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
MediaStreamTrackSource* aSource)
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints)
{
MOZ_RELEASE_ASSERT(mInputStream);
MOZ_RELEASE_ASSERT(mOwnedStream);
@ -989,10 +990,10 @@ DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
MediaStreamTrack* track;
switch (aType) {
case MediaSegment::AUDIO:
track = new AudioStreamTrack(this, aTrackID, aTrackID, aSource);
track = new AudioStreamTrack(this, aTrackID, aTrackID, aSource, aConstraints);
break;
case MediaSegment::VIDEO:
track = new VideoStreamTrack(this, aTrackID, aTrackID, aSource);
track = new VideoStreamTrack(this, aTrackID, aTrackID, aSource, aConstraints);
break;
default:
MOZ_CRASH("Unhandled track type");

Просмотреть файл

@ -14,6 +14,7 @@
#include "StreamTracks.h"
#include "nsIDOMWindow.h"
#include "nsIPrincipal.h"
#include "MediaTrackConstraints.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "PrincipalChangeObserver.h"
@ -48,7 +49,6 @@ class VideoTrack;
class AudioTrackList;
class VideoTrackList;
class MediaTrackListListener;
struct MediaTrackConstraints;
} // namespace dom
namespace layers {
@ -522,7 +522,8 @@ public:
* to be called from an async task.
*/
MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
MediaStreamTrackSource* aSource);
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
/**
* Creates a MediaStreamTrack cloned from aTrack, adds it to mTracks and

Просмотреть файл

@ -927,6 +927,18 @@ MediaOperationTask::ReturnCallbackError(nsresult rv, const char* errorLog)
mWindowID)));
}
static bool
IsOn(const OwningBooleanOrMediaTrackConstraints &aUnion) {
return !aUnion.IsBoolean() || aUnion.GetAsBoolean();
}
static const MediaTrackConstraints&
GetInvariant(const OwningBooleanOrMediaTrackConstraints &aUnion) {
static const MediaTrackConstraints empty;
return aUnion.IsMediaTrackConstraints() ?
aUnion.GetAsMediaTrackConstraints() : empty;
}
/**
* This class is only needed since fake tracks are added dynamically.
* Instead of refactoring to add them explicitly we let the DOMMediaStream
@ -991,10 +1003,12 @@ public:
uint64_t aWindowID,
GetUserMediaCallbackMediaStreamListener* aListener,
const nsCString& aOrigin,
const MediaStreamConstraints& aConstraints,
AudioDevice* aAudioDevice,
VideoDevice* aVideoDevice,
PeerIdentity* aPeerIdentity)
: mAudioDevice(aAudioDevice)
: mConstraints(aConstraints)
, mAudioDevice(aAudioDevice)
, mVideoDevice(aVideoDevice)
, mWindowID(aWindowID)
, mListener(aListener)
@ -1164,7 +1178,9 @@ public:
RefPtr<MediaStreamTrackSource> audioSource =
new LocalTrackSource(principal, audioDeviceName, mListener, source,
kAudioTrack, mPeerIdentity);
domStream->CreateDOMTrack(kAudioTrack, MediaSegment::AUDIO, audioSource);
MOZ_ASSERT(IsOn(mConstraints.mAudio));
domStream->CreateDOMTrack(kAudioTrack, MediaSegment::AUDIO, audioSource,
GetInvariant(mConstraints.mAudio));
}
if (mVideoDevice) {
nsString videoDeviceName;
@ -1174,7 +1190,9 @@ public:
RefPtr<MediaStreamTrackSource> videoSource =
new LocalTrackSource(principal, videoDeviceName, mListener, source,
kVideoTrack, mPeerIdentity);
domStream->CreateDOMTrack(kVideoTrack, MediaSegment::VIDEO, videoSource);
MOZ_ASSERT(IsOn(mConstraints.mVideo));
domStream->CreateDOMTrack(kVideoTrack, MediaSegment::VIDEO, videoSource,
GetInvariant(mConstraints.mVideo));
}
stream = domStream->GetInputStream()->AsSourceStream();
}
@ -1228,6 +1246,7 @@ public:
private:
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
MediaStreamConstraints mConstraints;
RefPtr<AudioDevice> mAudioDevice;
RefPtr<VideoDevice> mVideoDevice;
uint64_t mWindowID;
@ -1237,18 +1256,6 @@ private:
RefPtr<MediaManager> mManager; // get ref to this when creating the runnable
};
static bool
IsOn(const OwningBooleanOrMediaTrackConstraints &aUnion) {
return !aUnion.IsBoolean() || aUnion.GetAsBoolean();
}
static const MediaTrackConstraints&
GetInvariant(const OwningBooleanOrMediaTrackConstraints &aUnion) {
static const MediaTrackConstraints empty;
return aUnion.IsMediaTrackConstraints() ?
aUnion.GetAsMediaTrackConstraints() : empty;
}
// Source getter returning full list
template<class DeviceType>
@ -1451,8 +1458,9 @@ public:
NS_DispatchToMainThread(do_AddRef(
new GetUserMediaStreamRunnable(mOnSuccess, mOnFailure, mWindowID,
mListener, mOrigin, mAudioDevice,
mVideoDevice, peerIdentity)));
mListener, mOrigin, mConstraints,
mAudioDevice, mVideoDevice,
peerIdentity)));
MOZ_ASSERT(!mOnSuccess);
MOZ_ASSERT(!mOnFailure);
return NS_OK;

Просмотреть файл

@ -110,12 +110,14 @@ protected:
MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
TrackID aInputTrackID,
MediaStreamTrackSource* aSource)
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints)
: mOwningStream(aStream), mTrackID(aTrackID),
mInputTrackID(aInputTrackID), mSource(aSource),
mPrincipal(aSource->GetPrincipal()),
mReadyState(MediaStreamTrackState::Live),
mEnabled(true), mRemote(aSource->IsRemote())
mEnabled(true), mRemote(aSource->IsRemote()),
mConstraints(aConstraints)
{
if (!gMediaStreamTrackLog) {

Просмотреть файл

@ -132,7 +132,7 @@ public:
*/
virtual already_AddRefed<PledgeVoid>
ApplyConstraints(nsPIDOMWindowInner* aWindow,
const dom::MediaTrackConstraints& aConstraints) = 0;
const dom::MediaTrackConstraints& aConstraints);
/**
* Called by the source interface when all registered sinks have unregistered.
@ -213,13 +213,6 @@ public:
MediaSourceEnum GetMediaSource() const override { return mMediaSource; }
already_AddRefed<PledgeVoid>
ApplyConstraints(nsPIDOMWindowInner* aWindow,
const dom::MediaTrackConstraints& aConstraints) override
{
return nullptr;
}
void Stop() override {}
protected:
@ -252,8 +245,9 @@ public:
* MediaStream owned by aStream.
*/
MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
TrackID aInputTrackID,
MediaStreamTrackSource* aSource);
TrackID aInputTrackID,
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrack,

Просмотреть файл

@ -16,8 +16,9 @@ class VideoStreamTrack : public MediaStreamTrack {
public:
VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
TrackID aInputTrackID,
MediaStreamTrackSource* aSource)
: MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource) {}
MediaStreamTrackSource* aSource,
const MediaTrackConstraints& aConstraints = MediaTrackConstraints())
: MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource, aConstraints) {}
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -35,7 +36,8 @@ protected:
return do_AddRef(new VideoStreamTrack(aOwningStream,
aTrackID,
mInputTrackID,
mSource));
mSource,
mConstraints));
}
};

Просмотреть файл

@ -40,7 +40,8 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* a
new BasicUnstoppableTrackSource(doc->NodePrincipal(),
MediaSourceEnum::AudioCapture);
mDOMStream->CreateDOMTrack(AudioNodeStream::AUDIO_TRACK,
MediaSegment::AUDIO, source);
MediaSegment::AUDIO, source,
MediaTrackConstraints());
ProcessedMediaStream* outputStream = mDOMStream->GetInputStream()->AsProcessedStream();
MOZ_ASSERT(!!outputStream);