Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/capture/webm_muxer.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 namespace media { | |
| 10 | |
| 11 WebmMuxer::WebmMuxer(const WriteDataCB& write_data_callback) | |
| 12 : write_data_callback_(write_data_callback), | |
| 13 position_(0) { | |
| 14 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 15 segment_.Init(this); | |
| 16 segment_.set_mode(mkvmuxer::Segment::kLive); | |
| 17 segment_.OutputCues(false); | |
| 18 | |
| 19 mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); | |
| 20 info->set_writing_app("Chrome"); | |
| 21 info->set_muxing_app("Chrome"); | |
| 22 } | |
| 23 | |
| 24 WebmMuxer::~WebmMuxer() { | |
| 25 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 26 segment_.Finalize(); | |
| 27 } | |
| 28 | |
| 29 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.
| |
| 30 double frame_rate) { | |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 32 | |
| 33 const mkvmuxer::uint64 track_index = | |
| 34 segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); | |
| 35 | |
| 36 mkvmuxer::VideoTrack* const video_track = | |
| 37 reinterpret_cast<mkvmuxer::VideoTrack*>( | |
| 38 segment_.GetTrackByNumber(track_index)); | |
| 39 DCHECK(video_track); | |
| 40 video_track->set_codec_id(mkvmuxer::Tracks::kVp8CodecId); | |
| 41 DCHECK_EQ(video_track->crop_right(), 0ull); | |
| 42 DCHECK_EQ(video_track->crop_left(), 0ull); | |
| 43 DCHECK_EQ(video_track->crop_top(), 0ull); | |
| 44 DCHECK_EQ(video_track->crop_bottom(), 0ull); | |
| 45 | |
| 46 video_track->set_frame_rate(frame_rate); | |
| 47 video_track->set_default_duration(base::Time::kMicrosecondsPerSecond / | |
| 48 frame_rate); | |
| 49 // Segment's timestamps should be in milliseconds, dcheck it. See | |
| 50 // http://www.webmproject.org/docs/container/#muxer-guidelines | |
| 51 DCHECK_EQ(segment_.GetSegmentInfo()->timecode_scale(), 1000000ull); | |
| 52 | |
| 53 return track_index; | |
| 54 } | |
| 55 | |
| 56 void WebmMuxer::OnEncodedVideo(mkvmuxer::uint64 track_number, | |
| 57 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
| |
| 58 const base::TimeDelta& timestamp, | |
| 59 bool keyframe) { | |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 61 // |track_number|, a caller-side identifier, cannot be zero (!), see | |
| 62 // http://www.matroska.org/technical/specs/index.html#Tracks | |
| 63 DCHECK_GT(track_number, 0u); | |
| 64 DCHECK(segment_.GetTrackByNumber(track_number)); | |
| 65 | |
| 66 segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data.data()), | |
| 67 encoded_data.size(), | |
| 68 track_number, | |
| 69 timestamp.InMilliseconds(), | |
| 70 keyframe); | |
| 71 } | |
| 72 | |
| 73 mkvmuxer::int32 WebmMuxer::Write(const void* buf, mkvmuxer::uint32 len) { | |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 75 write_data_callback_.Run(static_cast<const char*>(buf), len); | |
| 76 position_ += len; | |
| 77 return 0; | |
| 78 } | |
| 79 | |
| 80 mkvmuxer::int64 WebmMuxer::Position() const { | |
| 81 return position_.ValueOrDie(); | |
| 82 } | |
| 83 | |
| 84 mkvmuxer::int32 WebmMuxer::Position(mkvmuxer::int64 position) { | |
| 85 // The stream is not Seekable() so indicate we cannot set the position. | |
| 86 return -1; | |
| 87 } | |
| 88 | |
| 89 bool WebmMuxer::Seekable() const { | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 void WebmMuxer::ElementStartNotify(mkvmuxer::uint64 element_id, | |
| 94 mkvmuxer::int64 position) { | |
| 95 // This method gets pinged before items are sent to |write_data_callback_|. | |
| 96 DCHECK_GE(position, position_.ValueOrDefault(0)) | |
| 97 << "Can't go back in a Live Mkv stream."; | |
| 98 } | |
| 99 | |
| 100 } // namespace media | |
| OLD | NEW |