Index: media/capture/webm_muxer.cc |
diff --git a/media/capture/webm_muxer.cc b/media/capture/webm_muxer.cc |
index c59bbae805293bc02d0463dc9fb37c5f1960756b..e582c7787068ed3769aa163a37d739d74d4d7e38 100644 |
--- a/media/capture/webm_muxer.cc |
+++ b/media/capture/webm_muxer.cc |
@@ -26,10 +26,17 @@ static double GetFrameRate(const scoped_refptr<VideoFrame>& video_frame) { |
} |
WebmMuxer::WebmMuxer(const WriteDataCB& write_data_callback) |
- : track_index_(0), |
- write_data_callback_(write_data_callback), |
- position_(0) { |
+ : write_data_callback_(write_data_callback), position_(0) { |
DCHECK(!write_data_callback_.is_null()); |
+ |
+ 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"); |
+ |
// Creation is done on a different thread than main activities. |
thread_checker_.DetachFromThread(); |
} |
@@ -41,46 +48,54 @@ WebmMuxer::~WebmMuxer() { |
segment_.Finalize(); |
} |
-void WebmMuxer::OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, |
+WebmMuxer::EncodedVideoCB WebmMuxer::GenerateOnEncodedVideoCallback() { |
+ return base::Bind(&WebmMuxer::OnEncodedVideo, base::Unretained(this), |
+ GetNextVideoTrackIndex()); |
+} |
+ |
+void WebmMuxer::OnEncodedVideo(int track_index, |
+ const scoped_refptr<VideoFrame>& video_frame, |
scoped_ptr<std::string> encoded_data, |
base::TimeTicks timestamp, |
bool is_key_frame) { |
DVLOG(1) << __FUNCTION__ << " - " << encoded_data->size() << "B"; |
DCHECK(thread_checker_.CalledOnValidThread()); |
- if (!track_index_) { |
- // |track_index_|, cannot be zero (!), initialize WebmMuxer in that case. |
+ int args_size = video_muxer_args_.size(); |
+ DCHECK(track_index <= args_size); |
+ |
+ if (args_size == 0 || args_size == track_index) { |
+ // If the track is not added muxer, add it in here. |
// http://www.matroska.org/technical/specs/index.html#Tracks |
- AddVideoTrack(video_frame->visible_rect().size(), |
- GetFrameRate(video_frame)); |
- first_frame_timestamp_ = timestamp; |
+ uint64 track_num = AddVideoTrack(video_frame->visible_rect().size(), |
+ GetFrameRate(video_frame)); |
+ video_muxer_args_.emplace_back(VideoMuxerArg(timestamp, track_num)); |
} |
- segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data->data()), |
- encoded_data->size(), |
- track_index_, |
- (timestamp - first_frame_timestamp_).InMicroseconds() * |
- base::Time::kNanosecondsPerMicrosecond, |
- is_key_frame); |
-} |
-void WebmMuxer::AddVideoTrack(const gfx::Size& frame_size, double frame_rate) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- DCHECK_EQ(track_index_, 0u) << "WebmMuxer can only be initialised once."; |
+ base::TimeDelta timestamp_delta = |
+ timestamp - video_muxer_args_[track_index].first_frame_timestamp; |
+ segment_.AddFrame( |
+ reinterpret_cast<const uint8_t*>(encoded_data->data()), |
+ encoded_data->size(), |
+ video_muxer_args_[track_index].track_number, |
+ timestamp_delta.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond, |
+ is_key_frame); |
+} |
- segment_.Init(this); |
- segment_.set_mode(mkvmuxer::Segment::kLive); |
- segment_.OutputCues(false); |
+int WebmMuxer::GetNextVideoTrackIndex() const { |
+ return video_muxer_args_.size(); |
+} |
- mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); |
- info->set_writing_app("Chrome"); |
- info->set_muxing_app("Chrome"); |
+uint64 WebmMuxer::AddVideoTrack( |
+ const gfx::Size& frame_size, double frame_rate) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
- track_index_ = |
+ uint64 track_num = |
segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); |
- DCHECK_GT(track_index_, 0u); |
+ DCHECK_GT(track_num, 0u); |
mkvmuxer::VideoTrack* const video_track = |
reinterpret_cast<mkvmuxer::VideoTrack*>( |
- segment_.GetTrackByNumber(track_index_)); |
+ segment_.GetTrackByNumber(track_num)); |
DCHECK(video_track); |
video_track->set_codec_id(mkvmuxer::Tracks::kVp8CodecId); |
DCHECK_EQ(video_track->crop_right(), 0ull); |
@@ -94,6 +109,8 @@ void WebmMuxer::AddVideoTrack(const gfx::Size& frame_size, double 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_num; |
} |
mkvmuxer::int32 WebmMuxer::Write(const void* buf, mkvmuxer::uint32 len) { |