Bug 1208328 - Implement MediaStream.onaddtrack. r=jib, r=smaug

MozReview-Commit-ID: JVZO5mlxvgW

--HG--
extra : rebase_source : 49b0ebaff593c28b727602d7b61bab5feea80485
extra : source : ba0529f6b0733534d50fa842dfebd52c6b477140
This commit is contained in:
Andreas Pehrson 2016-05-31 09:29:52 +02:00
Родитель fedd99c881
Коммит e93d5f7b7d
4 изменённых файлов: 38 добавлений и 10 удалений

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

@ -10,6 +10,7 @@
#include "nsIUUIDGenerator.h" #include "nsIUUIDGenerator.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "mozilla/dom/MediaStreamBinding.h" #include "mozilla/dom/MediaStreamBinding.h"
#include "mozilla/dom/MediaStreamTrackEvent.h"
#include "mozilla/dom/LocalMediaStreamBinding.h" #include "mozilla/dom/LocalMediaStreamBinding.h"
#include "mozilla/dom/AudioNode.h" #include "mozilla/dom/AudioNode.h"
#include "AudioChannelAgent.h" #include "AudioChannelAgent.h"
@ -1002,6 +1003,9 @@ DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
new TrackPort(mPlaybackPort, track, TrackPort::InputPortOwnership::EXTERNAL)); new TrackPort(mPlaybackPort, track, TrackPort::InputPortOwnership::EXTERNAL));
NotifyTrackAdded(track); NotifyTrackAdded(track);
DispatchTrackEvent(NS_LITERAL_STRING("addtrack"), track);
return track; return track;
} }
@ -1241,6 +1245,22 @@ DOMMediaStream::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
// track has been confirmed removed by the graph. See BlockPlaybackTrack(). // track has been confirmed removed by the graph. See BlockPlaybackTrack().
} }
nsresult
DOMMediaStream::DispatchTrackEvent(const nsAString& aName,
const RefPtr<MediaStreamTrack>& aTrack)
{
MOZ_ASSERT(aName == NS_LITERAL_STRING("addtrack"),
"Only 'addtrack' is supported at this time");
MediaStreamTrackEventInit init;
init.mTrack = aTrack;
RefPtr<MediaStreamTrackEvent> event =
MediaStreamTrackEvent::Constructor(this, aName, init);
return DispatchTrustedEvent(event);
}
void void
DOMMediaStream::CreateAndAddPlaybackStreamListener(MediaStream* aStream) DOMMediaStream::CreateAndAddPlaybackStreamListener(MediaStream* aStream)
{ {

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

@ -363,6 +363,8 @@ public:
/** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */ /** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */
already_AddRefed<DOMMediaStream> Clone(); already_AddRefed<DOMMediaStream> Clone();
IMPL_EVENT_HANDLER(addtrack)
// NON-WebIDL // NON-WebIDL
/** /**
@ -523,7 +525,12 @@ public:
* Called for each track in our owned stream to indicate to JS that we * Called for each track in our owned stream to indicate to JS that we
* are carrying that track. * are carrying that track.
* *
* Creates a MediaStreamTrack, adds it to mTracks and returns it. * Creates a MediaStreamTrack, adds it to mTracks, raises "addtrack" and
* returns it.
*
* Note that "addtrack" is raised synchronously and only has an effect if
* this MediaStream is already exposed to script. For spec compliance this is
* to be called from an async task.
*/ */
MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType, MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
MediaStreamTrackSource* aSource); MediaStreamTrackSource* aSource);
@ -604,6 +611,10 @@ protected:
// Dispatches NotifyTrackRemoved() to all registered track listeners. // Dispatches NotifyTrackRemoved() to all registered track listeners.
void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack); void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack);
// Dispatches "addtrack" or "removetrack".
nsresult DispatchTrackEvent(const nsAString& aName,
const RefPtr<MediaStreamTrack>& aTrack);
class OwnedStreamListener; class OwnedStreamListener;
friend class OwnedStreamListener; friend class OwnedStreamListener;

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

@ -43,7 +43,7 @@ interface MediaStream : EventTarget {
// readonly attribute boolean active; // readonly attribute boolean active;
// attribute EventHandler onactive; // attribute EventHandler onactive;
// attribute EventHandler oninactive; // attribute EventHandler oninactive;
// attribute EventHandler onaddtrack; attribute EventHandler onaddtrack;
// attribute EventHandler onremovetrack; // attribute EventHandler onremovetrack;
readonly attribute double currentTime; readonly attribute double currentTime;
}; };

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

@ -8,15 +8,12 @@
*/ */
dictionary MediaStreamTrackEventInit : EventInit { dictionary MediaStreamTrackEventInit : EventInit {
MediaStreamTrack? track = null; required MediaStreamTrack track;
RTCRtpReceiver? receiver = null;
MediaStream? stream = null;
}; };
[Pref="media.peerconnection.enabled", [Exposed=Window,
Constructor(DOMString type, optional MediaStreamTrackEventInit eventInitDict)] Constructor (DOMString type, MediaStreamTrackEventInit eventInitDict)]
interface MediaStreamTrackEvent : Event { interface MediaStreamTrackEvent : Event {
readonly attribute RTCRtpReceiver? receiver; [SameObject]
readonly attribute MediaStreamTrack? track; readonly attribute MediaStreamTrack track;
readonly attribute MediaStream? stream;
}; };