Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Unified Diff: media/muxers/webm_muxer.cc

Issue 2633623002: MediaRecorder: handle libwebm::Segment::AddFrame() errors and wire up to Blink (Closed)
Patch Set: I can haz moar testing? Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/muxers/webm_muxer.h ('k') | media/muxers/webm_muxer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/muxers/webm_muxer.cc
diff --git a/media/muxers/webm_muxer.cc b/media/muxers/webm_muxer.cc
index 616e7b99247d66f30739cb61e234e0e07912a36a..02a4ca9fb2bcbe51b872c5b9f8fc3046c353b264 100644
--- a/media/muxers/webm_muxer.cc
+++ b/media/muxers/webm_muxer.cc
@@ -106,7 +106,8 @@ WebmMuxer::WebmMuxer(VideoCodec codec,
has_video_(has_video),
has_audio_(has_audio),
write_data_callback_(write_data_callback),
- position_(0) {
+ position_(0),
+ force_one_libwebm_error_(false) {
DCHECK(has_video_ || has_audio_);
DCHECK(!write_data_callback_.is_null());
DCHECK(codec == kCodecVP8 || codec == kCodecVP9 || codec == kCodecH264)
@@ -131,7 +132,7 @@ WebmMuxer::~WebmMuxer() {
segment_.Finalize();
}
-void WebmMuxer::OnEncodedVideo(const VideoParameters& params,
+bool WebmMuxer::OnEncodedVideo(const VideoParameters& params,
std::unique_ptr<std::string> encoded_data,
base::TimeTicks timestamp,
bool is_key_frame) {
@@ -154,23 +155,17 @@ void WebmMuxer::OnEncodedVideo(const VideoParameters& params,
encoded_frames_queue_.push_back(base::MakeUnique<EncodedVideoFrame>(
std::move(encoded_data), timestamp, is_key_frame));
- return;
+ return true;
}
- // Dump all saved encoded video frames if any.
- while (!encoded_frames_queue_.empty()) {
- AddFrame(
- std::move(encoded_frames_queue_.front()->data), video_track_index_,
- encoded_frames_queue_.front()->timestamp - first_frame_timestamp_video_,
- encoded_frames_queue_.front()->is_keyframe);
- encoded_frames_queue_.pop_front();
- }
+ // Any saved encoded video frames must have been dumped in OnEncodedAudio();
+ DCHECK(encoded_frames_queue_.empty());
- AddFrame(std::move(encoded_data), video_track_index_,
- timestamp - first_frame_timestamp_video_, is_key_frame);
+ return AddFrame(std::move(encoded_data), video_track_index_,
+ timestamp - first_frame_timestamp_video_, is_key_frame);
}
-void WebmMuxer::OnEncodedAudio(const media::AudioParameters& params,
+bool WebmMuxer::OnEncodedAudio(const media::AudioParameters& params,
std::unique_ptr<std::string> encoded_data,
base::TimeTicks timestamp) {
DVLOG(2) << __func__ << " - " << encoded_data->size() << "B";
@@ -186,21 +181,24 @@ void WebmMuxer::OnEncodedAudio(const media::AudioParameters& params,
// TODO(ajose): Support multiple tracks: http://crbug.com/528523
if (has_video_ && !video_track_index_) {
DVLOG(1) << __func__ << ": delaying until video track ready.";
- return;
+ return true;
}
// Dump all saved encoded video frames if any.
while (!encoded_frames_queue_.empty()) {
- AddFrame(
- std::move(encoded_frames_queue_.front()->data), video_track_index_,
+ const bool res = AddFrame(
+ base::MakeUnique<std::string>(*encoded_frames_queue_.front()->data),
+ video_track_index_,
encoded_frames_queue_.front()->timestamp - first_frame_timestamp_video_,
encoded_frames_queue_.front()->is_keyframe);
+ if (!res)
+ return false;
encoded_frames_queue_.pop_front();
}
- AddFrame(std::move(encoded_data), audio_track_index_,
- timestamp - first_frame_timestamp_audio_,
- true /* is_key_frame -- always true for audio */);
+ return AddFrame(std::move(encoded_data), audio_track_index_,
+ timestamp - first_frame_timestamp_audio_,
+ true /* is_key_frame -- always true for audio */);
}
void WebmMuxer::Pause() {
@@ -309,7 +307,7 @@ void WebmMuxer::ElementStartNotify(mkvmuxer::uint64 element_id,
<< "Can't go back in a live WebM stream.";
}
-void WebmMuxer::AddFrame(std::unique_ptr<std::string> encoded_data,
+bool WebmMuxer::AddFrame(std::unique_ptr<std::string> encoded_data,
uint8_t track_index,
base::TimeDelta timestamp,
bool is_key_frame) {
@@ -320,11 +318,19 @@ void WebmMuxer::AddFrame(std::unique_ptr<std::string> encoded_data,
most_recent_timestamp_ =
std::max(most_recent_timestamp_, timestamp - total_time_in_pause_);
- segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data->data()),
- encoded_data->size(), track_index,
- most_recent_timestamp_.InMicroseconds() *
- base::Time::kNanosecondsPerMicrosecond,
- is_key_frame);
+ if (force_one_libwebm_error_) {
+ DVLOG(1) << "Forcing a libwebm error";
+ force_one_libwebm_error_ = false;
+ return false;
+ }
+
+ DCHECK(encoded_data->data());
+ return segment_.AddFrame(
+ reinterpret_cast<const uint8_t*>(encoded_data->data()),
+ encoded_data->size(), track_index,
+ most_recent_timestamp_.InMicroseconds() *
+ base::Time::kNanosecondsPerMicrosecond,
+ is_key_frame);
}
WebmMuxer::EncodedVideoFrame::EncodedVideoFrame(
« no previous file with comments | « media/muxers/webm_muxer.h ('k') | media/muxers/webm_muxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698