Bug 909187: Part 1-Refactor MediaStreamTrack disabling so we can call it directly and access from other threads r=roc (reland)

This commit is contained in:
Randell Jesup 2013-08-26 02:07:17 -04:00
Родитель 999cb2239a
Коммит ed90712171
4 изменённых файлов: 36 добавлений и 20 удалений

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

@ -100,6 +100,10 @@ public:
* Insert aDuration of null data at the end of the segment.
*/
virtual void AppendNullData(TrackTicks aDuration) = 0;
/**
* Replace contents with disabled data of the same duration
*/
virtual void ReplaceWithDisabled() = 0;
/**
* Remove all contents, setting duration to 0.
*/
@ -190,6 +194,15 @@ public:
}
mDuration += aDuration;
}
virtual void ReplaceWithDisabled()
{
if (GetType() != AUDIO) {
MOZ_CRASH("Disabling unknown segment type");
}
TrackTicks duration = GetDuration();
Clear();
AppendNullData(duration);
}
virtual void Clear()
{
mDuration = 0;

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

@ -1912,29 +1912,15 @@ MediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
}
void
MediaStream::ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment)
MediaStream::ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment, MediaSegment* aRawSegment)
{
// mMutex must be owned here if this is a SourceMediaStream
if (!mDisabledTrackIDs.Contains(aTrackID)) {
return;
}
switch (aSegment->GetType()) {
case MediaSegment::AUDIO: {
TrackTicks duration = aSegment->GetDuration();
aSegment->Clear();
aSegment->AppendNullData(duration);
break;
}
case MediaSegment::VIDEO: {
for (VideoSegment::ChunkIterator i(*static_cast<VideoSegment*>(aSegment));
!i.IsEnded(); i.Next()) {
VideoChunk& chunk = *i;
chunk.SetForceBlack(true);
}
break;
}
default:
MOZ_CRASH("Unknown track type");
aSegment->ReplaceWithDisabled();
if (aRawSegment) {
aRawSegment->ReplaceWithDisabled();
}
}
@ -1990,6 +1976,10 @@ SourceMediaStream::AppendToTrack(TrackID aID, MediaSegment* aSegment, MediaSegme
// Indirect listeners (via subsequent TrackUnion nodes) are synced to
// playout time, and so can be delayed by buffering.
// Apply track disabling before notifying any consumers directly
// or inserting into the graph
ApplyTrackDisabling(aID, aSegment, aRawSegment);
// Must notify first, since AppendFrom() will empty out aSegment
NotifyDirectConsumers(track, aRawSegment ? aRawSegment : aSegment);
track->mData->AppendFrom(aSegment); // note: aSegment is now dead

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

@ -459,7 +459,7 @@ public:
StreamBuffer::Track* EnsureTrack(TrackID aTrack, TrackRate aSampleRate);
void ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment);
void ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment, MediaSegment* aRawSegment = nullptr);
DOMMediaStream* GetWrapper()
{
@ -679,6 +679,11 @@ public:
FinishWithLockHeld();
}
// Overriding allows us to hold the mMutex lock while changing the track enable status
void SetTrackEnabledImpl(TrackID aTrackID, bool aEnabled) {
MutexAutoLock lock(mMutex);
MediaStream::SetTrackEnabledImpl(aTrackID, aEnabled);
}
/**
* End all tracks and Finish() this stream. Used to voluntarily revoke access

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

@ -107,6 +107,14 @@ public:
}
return &c->mFrame;
}
// Override default impl
virtual void ReplaceWithDisabled() MOZ_OVERRIDE {
for (ChunkIterator i(*this);
!i.IsEnded(); i.Next()) {
VideoChunk& chunk = *i;
chunk.SetForceBlack(true);
}
}
// Segment-generic methods not in MediaSegmentBase
static Type StaticType() { return VIDEO; }