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 uint64_t WebmMuxer::AddVideoTrack(const gfx::Size& frame_size, | |
| 30 double frame_rate) { | |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 32 | |
| 33 const uint64_t 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(uint64_t track_number, | |
| 57 const uint8_t* encoded_data, | |
| 58 size_t encoded_data_len, | |
| 59 const base::TimeDelta& timestamp, | |
| 60 bool keyframe) { | |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 62 // |track_number|, a caller-side identifier, cannot be zero (!), see | |
| 63 // http://www.matroska.org/technical/specs/index.html#Tracks | |
| 64 DCHECK_GT(track_number, 0u); | |
| 65 DCHECK(segment_.GetTrackByNumber(track_number)); | |
| 66 | |
| 67 segment_.AddFrame(encoded_data, encoded_data_len, track_number, | |
| 68 timestamp.InMilliseconds(), keyframe); | |
| 69 } | |
| 70 | |
| 71 mkvmuxer::int32 WebmMuxer::Write(const void* buf, mkvmuxer::uint32 len) { | |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 73 write_data_callback_.Run(static_cast<const char*>(buf), len); | |
| 74 position_ += len; | |
| 75 return 0; | |
|
DaleCurtis
2015/07/21 16:52:30
Is this the right return value, generally a Write(
mcasas
2015/07/21 19:46:59
[1] "returns 0 on success"
[1] https://code.googl
| |
| 76 } | |
| 77 | |
| 78 mkvmuxer::int64 WebmMuxer::Position() const { | |
| 79 return position_.ValueOrDie(); | |
| 80 } | |
| 81 | |
| 82 mkvmuxer::int32 WebmMuxer::Position(mkvmuxer::int64 position) { | |
| 83 // The stream is not Seekable() so indicate we cannot set the position. | |
|
DaleCurtis
2015/07/21 16:52:30
Does NOTREACHED() get hit?
mcasas
2015/07/21 19:46:59
I doubt it, because the stream is "Live".
Returnin
| |
| 84 return -1; | |
| 85 } | |
| 86 | |
| 87 bool WebmMuxer::Seekable() const { | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 void WebmMuxer::ElementStartNotify(mkvmuxer::uint64 element_id, | |
| 92 mkvmuxer::int64 position) { | |
| 93 // This method gets pinged before items are sent to |write_data_callback_|. | |
| 94 DCHECK_GE(position, position_.ValueOrDefault(0)) | |
| 95 << "Can't go back in a Live Mkv stream."; | |
|
DaleCurtis
2015/07/21 16:52:30
live webm stream
mcasas
2015/07/21 19:46:59
Done.
| |
| 96 } | |
| 97 | |
| 98 } // namespace media | |
| OLD | NEW |