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

Unified Diff: media/capture/webm_muxer.cc

Issue 1225123006: media/capture: Adding WebmMuxer class and unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@m_crbug262211__MSRecorder__2__libwebm_reland_in_third_party
Patch Set: dalecurtis@ and tomfinegan@ comments Created 5 years, 5 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/capture/webm_muxer.h ('k') | media/capture/webm_muxer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/capture/webm_muxer.cc
diff --git a/media/capture/webm_muxer.cc b/media/capture/webm_muxer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b02b75fb277b04cdc9c1d3e26e763f0f1cc6a215
--- /dev/null
+++ b/media/capture/webm_muxer.cc
@@ -0,0 +1,100 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/capture/webm_muxer.h"
+
+#include <limits>
+
+namespace media {
+
+WebmMuxer::WebmMuxer(const WriteDataCB& write_data_callback)
+ : write_data_callback_(write_data_callback),
+ position_(0) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ segment_.Init(this);
+ segment_.set_mode(mkvmuxer::Segment::kLive);
+ segment_.OutputCues(false);
+
+ mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo();
+ info->set_writing_app("Chrome");
+ info->set_muxing_app("Chrome");
+}
+
+WebmMuxer::~WebmMuxer() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ segment_.Finalize();
+}
+
+mkvmuxer::uint64 WebmMuxer::AddVideoTrack(const gfx::Size& frame_size,
DaleCurtis 2015/07/20 20:23:07 Since this is the Chrome side interface, can we ju
mcasas 2015/07/21 12:56:20 Done.
+ double frame_rate) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ const mkvmuxer::uint64 track_index =
+ segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0);
+
+ mkvmuxer::VideoTrack* const video_track =
+ reinterpret_cast<mkvmuxer::VideoTrack*>(
+ segment_.GetTrackByNumber(track_index));
+ DCHECK(video_track);
+ video_track->set_codec_id(mkvmuxer::Tracks::kVp8CodecId);
+ DCHECK_EQ(video_track->crop_right(), 0ull);
+ DCHECK_EQ(video_track->crop_left(), 0ull);
+ DCHECK_EQ(video_track->crop_top(), 0ull);
+ DCHECK_EQ(video_track->crop_bottom(), 0ull);
+
+ video_track->set_frame_rate(frame_rate);
+ video_track->set_default_duration(base::Time::kMicrosecondsPerSecond /
+ frame_rate);
+ // Segment's timestamps should be in milliseconds, dcheck it. See
+ // http://www.webmproject.org/docs/container/#muxer-guidelines
+ DCHECK_EQ(segment_.GetSegmentInfo()->timecode_scale(), 1000000ull);
+
+ return track_index;
+}
+
+void WebmMuxer::OnEncodedVideo(mkvmuxer::uint64 track_number,
+ const std::string& encoded_data,
DaleCurtis 2015/07/20 20:23:07 Do you want std::string& here? Should you instead
mcasas 2015/07/21 12:56:20 Hmm at this point I'm happy with std::string&, rea
DaleCurtis 2015/07/21 16:52:30 I didn't realize that about the vp8 encode api, so
mcasas 2015/07/21 19:46:59 Acknowledged.
Tom Finegan 2015/07/21 21:19:09 By default, this is true, but you can make the lib
+ const base::TimeDelta& timestamp,
+ bool keyframe) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // |track_number|, a caller-side identifier, cannot be zero (!), see
+ // http://www.matroska.org/technical/specs/index.html#Tracks
+ DCHECK_GT(track_number, 0u);
+ DCHECK(segment_.GetTrackByNumber(track_number));
+
+ segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data.data()),
+ encoded_data.size(),
+ track_number,
+ timestamp.InMilliseconds(),
+ keyframe);
+}
+
+mkvmuxer::int32 WebmMuxer::Write(const void* buf, mkvmuxer::uint32 len) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ write_data_callback_.Run(static_cast<const char*>(buf), len);
+ position_ += len;
+ return 0;
+}
+
+mkvmuxer::int64 WebmMuxer::Position() const {
+ return position_.ValueOrDie();
+}
+
+mkvmuxer::int32 WebmMuxer::Position(mkvmuxer::int64 position) {
+ // The stream is not Seekable() so indicate we cannot set the position.
+ return -1;
+}
+
+bool WebmMuxer::Seekable() const {
+ return false;
+}
+
+void WebmMuxer::ElementStartNotify(mkvmuxer::uint64 element_id,
+ mkvmuxer::int64 position) {
+ // This method gets pinged before items are sent to |write_data_callback_|.
+ DCHECK_GE(position, position_.ValueOrDefault(0))
+ << "Can't go back in a Live Mkv stream.";
+}
+
+} // namespace media
« no previous file with comments | « media/capture/webm_muxer.h ('k') | media/capture/webm_muxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698