Bug 1208371 - Add convenience method for checking if TrackID is explicit. r?roc draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:22 +0800
changeset 342095 84240bb72ad01fa5938f34a8d1065695aeb980c4
parent 342094 564768f60d7eeb7d78d922af28284fe20c9a5444
child 342096 3c8104515d957e533d74eead9b16a01cc592f65d
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersroc
bugs1208371
milestone47.0a1
Bug 1208371 - Add convenience method for checking if TrackID is explicit. r?roc MozReview-Commit-ID: 330Fk17FJD4
dom/media/DOMMediaStream.cpp
dom/media/MediaStreamGraph.cpp
dom/media/StreamBuffer.h
media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -228,20 +228,17 @@ public:
     }
 
     LOG(LogLevel::Debug, ("DOMMediaStream %p Playback track; notifying stream listeners.",
                            mStream));
     mStream->NotifyTrackRemoved(track);
 
     RefPtr<TrackPort> endedPort = mStream->FindPlaybackTrackPort(*track);
     NS_ASSERTION(endedPort, "Playback track should have a TrackPort");
-    if (endedPort &&
-        endedPort->GetSourceTrackId() != TRACK_ANY &&
-        endedPort->GetSourceTrackId() != TRACK_INVALID &&
-        endedPort->GetSourceTrackId() != TRACK_NONE) {
+    if (endedPort && IsTrackIDExplicit(endedPort->GetSourceTrackId())) {
       // If a track connected to a locked-track input port ends, we destroy the
       // port to allow our playback stream to finish.
       // XXX (bug 1208316) This should not be necessary when MediaStreams don't
       // finish but instead become inactive.
       endedPort->DestroyInputPort();
     }
   }
 
@@ -859,19 +856,17 @@ DOMMediaStream::FindPlaybackDOMTrack(Med
         info->GetTrack()->GetInputTrackID() == aInputTrackID) {
       // This track is in our owned and playback streams.
       return info->GetTrack();
     }
     if (info->GetInputPort() &&
         info->GetInputPort()->GetSource() == aInputStream &&
         info->GetSourceTrackId() == aInputTrackID) {
       // This track is owned externally but in our playback stream.
-      MOZ_ASSERT(aInputTrackID != TRACK_NONE);
-      MOZ_ASSERT(aInputTrackID != TRACK_INVALID);
-      MOZ_ASSERT(aInputTrackID != TRACK_ANY);
+      MOZ_ASSERT(IsTrackIDExplicit(aInputTrackID));
       return info->GetTrack();
     }
   }
   return nullptr;
 }
 
 DOMMediaStream::TrackPort*
 DOMMediaStream::FindPlaybackTrackPort(const MediaStreamTrack& aTrack) const
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -2736,17 +2736,17 @@ MediaInputPort::BlockTrackId(TrackID aTr
     void RunDuringShutdown() override
     {
       Run();
     }
     RefPtr<MediaInputPort> mPort;
     TrackID mTrackId;
   };
 
-  MOZ_ASSERT(aTrackId != TRACK_NONE && aTrackId != TRACK_INVALID && aTrackId != TRACK_ANY,
+  MOZ_ASSERT(IsTrackIDExplicit(aTrackId),
              "Only explicit TrackID is allowed");
   GraphImpl()->AppendMessage(MakeUnique<Message>(this, aTrackId));
 }
 
 already_AddRefed<MediaInputPort>
 ProcessedMediaStream::AllocateInputPort(MediaStream* aStream, TrackID aTrackID,
                                         uint16_t aInputNumber, uint16_t aOutputNumber)
 {
@@ -2767,18 +2767,18 @@ ProcessedMediaStream::AllocateInputPort(
     void RunDuringShutdown() override
     {
       Run();
     }
     RefPtr<MediaInputPort> mPort;
   };
 
   MOZ_ASSERT(aStream->GraphImpl() == GraphImpl());
-  MOZ_ASSERT(aTrackID != TRACK_NONE && aTrackID != TRACK_INVALID,
-             "Only TRACK_ANY and explicit ID are allowed");
+  MOZ_ASSERT(aTrackID == TRACK_ANY || IsTrackIDExplicit(aTrackID),
+             "Only TRACK_ANY and explicit ID are allowed for source track");
   RefPtr<MediaInputPort> port = new MediaInputPort(aStream, aTrackID, this,
                                                      aInputNumber, aOutputNumber);
   port->SetGraphImpl(GraphImpl());
   GraphImpl()->AppendMessage(MakeUnique<Message>(port));
   return port.forget();
 }
 
 void
--- a/dom/media/StreamBuffer.h
+++ b/dom/media/StreamBuffer.h
@@ -16,16 +16,20 @@ namespace mozilla {
  * StreamBuffers may have the same ID; this matters when appending StreamBuffers,
  * since tracks with the same ID are matched. Only IDs greater than 0 are allowed.
  */
 typedef int32_t TrackID;
 const TrackID TRACK_NONE = 0;
 const TrackID TRACK_INVALID = -1;
 const TrackID TRACK_ANY = -2;
 
+inline bool IsTrackIDExplicit(const TrackID& aId) {
+  return aId > TRACK_NONE;
+}
+
 inline TrackTicks RateConvertTicksRoundDown(TrackRate aOutRate,
                                             TrackRate aInRate,
                                             TrackTicks aTicks)
 {
   NS_ASSERTION(0 < aOutRate && aOutRate <= TRACK_RATE_MAX, "Bad out rate");
   NS_ASSERTION(0 < aInRate && aInRate <= TRACK_RATE_MAX, "Bad in rate");
   NS_WARN_IF_FALSE(0 <= aTicks && aTicks <= TRACK_TICKS_MAX, "Bad ticks"); // bug 957691
   return (aTicks * aOutRate) / aInRate;
--- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
@@ -485,17 +485,17 @@ MediaPipelineFactory::CreateMediaPipelin
 {
   // We will error out earlier if this isn't here.
   RefPtr<RemoteSourceStreamInfo> stream =
       mPCMedia->GetRemoteStreamById(aTrack.GetStreamId());
 
   RefPtr<MediaPipelineReceive> pipeline;
 
   TrackID numericTrackId = stream->GetNumericTrackId(aTrack.GetTrackId());
-  MOZ_ASSERT(numericTrackId != TRACK_INVALID);
+  MOZ_ASSERT(IsTrackIDExplicit(numericTrackId));
 
   bool queue_track = stream->ShouldQueueTracks();
 
   MOZ_MTLOG(ML_DEBUG, __FUNCTION__ << ": Creating pipeline for "
             << numericTrackId << " -> " << aTrack.GetTrackId());
 
   if (aTrack.GetMediaType() == SdpMediaSection::kAudio) {
     pipeline = new MediaPipelineReceiveAudio(