Bug 1156472 - Part 7 - Allow to un-capture an HTMLMediaElement. r=pehrsons,jwwang

This commit is contained in:
Paul Adenot 2015-07-24 14:28:17 +02:00
Родитель 2ab300ac7b
Коммит f7bb3fd5bd
7 изменённых файлов: 67 добавлений и 1 удалений

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

@ -4708,7 +4708,23 @@ NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged()
mCaptureStreamPort = msg->ConnectToCaptureStream(id, mPlaybackStream->GetStream());
}
} else {
// TODO: uncapture
mAudioCapturedByWindow = false;
if (mDecoder) {
ProcessedMediaStream* ps =
mCaptureStreamPort->GetSource()->AsProcessedStream();
MOZ_ASSERT(ps);
for (uint32_t i = 0; i < mOutputStreams.Length(); i++) {
if (mOutputStreams[i].mStream->GetStream() == ps) {
mOutputStreams.RemoveElementAt(i);
break;
}
}
mDecoder->RemoveOutputStream(ps);
}
mCaptureStreamPort->Destroy();
mCaptureStreamPort = nullptr;
}
}

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

@ -289,6 +289,14 @@ DecodedStream::OutputStreams()
return mOutputStreams;
}
bool
DecodedStream::HasConsumers() const
{
MOZ_ASSERT(NS_IsMainThread());
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
return mOutputStreams.IsEmpty();
}
ReentrantMonitor&
DecodedStream::GetReentrantMonitor() const
{

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

@ -114,6 +114,7 @@ public:
int64_t AudioEndTime() const;
int64_t GetPosition() const;
bool IsFinished() const;
bool HasConsumers() const;
// Return true if stream is finished.
bool SendData(double aVolume, bool aIsSameOrigin);

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

@ -326,6 +326,13 @@ void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream,
mDecoderStateMachine->AddOutputStream(aStream, aFinishWhenEnded);
}
void MediaDecoder::RemoveOutputStream(MediaStream* aStream)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load().");
mDecoderStateMachine->RemoveOutputStream(aStream);
}
double MediaDecoder::GetDuration()
{
MOZ_ASSERT(NS_IsMainThread());

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

@ -399,6 +399,8 @@ public:
// The stream is initially blocked. The decoder is responsible for unblocking
// it while it is playing back.
virtual void AddOutputStream(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
// Remove an output stream added with AddOutputStream.
virtual void RemoveOutputStream(MediaStream* aStream);
// Return the duration of the video in seconds.
virtual double GetDuration();

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

@ -3140,6 +3140,25 @@ void MediaDecoderStateMachine::DispatchAudioCaptured()
OwnerThread()->Dispatch(r.forget());
}
void MediaDecoderStateMachine::DispatchAudioUncaptured()
{
nsRefPtr<MediaDecoderStateMachine> self = this;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([self] () -> void
{
MOZ_ASSERT(self->OnTaskQueue());
ReentrantMonitorAutoEnter mon(self->mDecoder->GetReentrantMonitor());
if (self->mAudioCaptured) {
// Start again the audio sink
self->mAudioCaptured = false;
if (self->IsPlaying()) {
self->StartAudioThread();
}
self->ScheduleStateMachine();
}
});
OwnerThread()->Dispatch(r.forget());
}
void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
bool aFinishWhenEnded)
{
@ -3149,6 +3168,16 @@ void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
DispatchAudioCaptured();
}
void MediaDecoderStateMachine::RemoveOutputStream(MediaStream* aStream)
{
MOZ_ASSERT(NS_IsMainThread());
DECODER_LOG("RemoveOutputStream=%p!", aStream);
mDecodedStream->Remove(aStream);
if (!mDecodedStream->HasConsumers()) {
DispatchAudioUncaptured();
}
}
} // namespace mozilla
// avoid redefined macro in unified build

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

@ -148,6 +148,8 @@ public:
};
void AddOutputStream(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
// Remove an output stream added with AddOutputStream.
void RemoveOutputStream(MediaStream* aStream);
// Set/Unset dormant state.
void SetDormant(bool aDormant);
@ -159,6 +161,7 @@ private:
void InitializationTask();
void DispatchAudioCaptured();
void DispatchAudioUncaptured();
void Shutdown();
public: