diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc b/chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc index bf8c6c7216f..47da141fed3 100644 --- a/chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc +++ b/chromium/third_party/blink/renderer/modules/mediarecorder/media_recorder.cc @@ -87,7 +87,7 @@ void AllocateVideoAndAudioBitrates(ExceptionState& exception_state, // Limit audio bitrate values if set explicitly or calculated. if (options->hasAudioBitsPerSecond() || options->hasBitsPerSecond()) { if (audio_bps > kLargestAutoAllocatedOpusBitRate) { - context->AddConsoleMessage(ConsoleMessage::Create( + context->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kWarning, "Clamping calculated audio bitrate (" + String::Number(audio_bps) + @@ -97,7 +97,7 @@ void AllocateVideoAndAudioBitrates(ExceptionState& exception_state, } if (audio_bps < kSmallestPossibleOpusBitRate) { - context->AddConsoleMessage(ConsoleMessage::Create( + context->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kWarning, "Clamping calculated audio bitrate (" + String::Number(audio_bps) + @@ -118,7 +118,7 @@ void AllocateVideoAndAudioBitrates(ExceptionState& exception_state, // explicitly. if (options->hasVideoBitsPerSecond() || options->hasBitsPerSecond()) { if (video_bps < kSmallestPossibleVpxBitRate) { - context->AddConsoleMessage(ConsoleMessage::Create( + context->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kWarning, "Clamping calculated video bitrate (" + String::Number(video_bps) + @@ -157,7 +157,7 @@ MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, const MediaRecorderOptions* options, ExceptionState& exception_state) - : ContextLifecycleObserver(context), + : ExecutionContextLifecycleObserver(context), stream_(stream), mime_type_(options->mimeType()), stopped_(true), @@ -193,12 +193,6 @@ MediaRecorder::MediaRecorder(ExecutionContext* context, mime_type_ + ") is not supported."); return; } - // If the user requested no mimeType, query |recorder_handler_|. - if (options->mimeType().IsEmpty()) { - const String actual_mime_type = recorder_handler_->ActualMimeType(); - if (!actual_mime_type.IsEmpty()) - mime_type_ = actual_mime_type; - } stopped_ = false; } @@ -241,7 +235,6 @@ void MediaRecorder::start(int time_slice, ExceptionState& exception_state) { "There was an error starting the MediaRecorder."); return; } - ScheduleDispatchEvent(Event::Create(event_type_names::kStart)); } void MediaRecorder::stop(ExceptionState& exception_state) { @@ -341,10 +334,10 @@ const AtomicString& MediaRecorder::InterfaceName() const { } ExecutionContext* MediaRecorder::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextLifecycleObserver::GetExecutionContext(); } -void MediaRecorder::ContextDestroyed(ExecutionContext*) { +void MediaRecorder::ContextDestroyed() { if (stopped_) return; @@ -361,9 +354,20 @@ void MediaRecorder::WriteData(const char* data, size_t length, bool last_in_slice, double timecode) { + // Update mime_type_ when "onstart" is sent by the MediaRecorder. This method + // is used also from StopRecording, with a zero length. If we never wrote + // anything we don't want to send start or associated actions (update the mime + // type in that case). + if (!first_write_received_ && length) { + mime_type_ = recorder_handler_->ActualMimeType(); + } if (stopped_ && !last_in_slice) { stopped_ = false; ScheduleDispatchEvent(Event::Create(event_type_names::kStart)); + first_write_received_ = true; + } else if (!first_write_received_ && length) { + ScheduleDispatchEvent(Event::Create(event_type_names::kStart)); + first_write_received_ = true; } if (!blob_data_) { @@ -389,13 +393,29 @@ void MediaRecorder::OnError(const String& message) { ScheduleDispatchEvent(Event::Create(event_type_names::kError)); } +void MediaRecorder::OnAllTracksEnded() { + StopRecording(); +} + void MediaRecorder::CreateBlobEvent(Blob* blob, double timecode) { ScheduleDispatchEvent(MakeGarbageCollected<BlobEvent>( event_type_names::kDataavailable, blob, timecode)); } void MediaRecorder::StopRecording() { - DCHECK(state_ != State::kInactive); + if (state_ == State::kInactive) { + // This may happen if all tracks have ended and recording has stopped or + // never started. + return; + } + if (!recorder_handler_) { + // This may happen when ContextDestroyed has executed, but the + // MediaRecorderHandler still exists and all tracks + // have ended leading to a call to OnAllTracksEnded. + return; + } + // Make sure that starting the recorder again yields an onstart event. + first_write_received_ = false; state_ = State::kInactive; recorder_handler_->Stop(); @@ -428,12 +448,12 @@ void MediaRecorder::DispatchScheduledEvent() { DispatchEvent(*event); } -void MediaRecorder::Trace(blink::Visitor* visitor) { +void MediaRecorder::Trace(Visitor* visitor) { visitor->Trace(stream_); visitor->Trace(recorder_handler_); visitor->Trace(scheduled_events_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } } // namespace blink |