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

Side by Side Diff: media/filters/webm_muxer.cc

Issue 1211973012: [Experimental] MediaStreamRecorder playground (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed FFmpegMuxer, using instead libwebm::IMkvMuxer, which is partially added 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 unified diff | Download patch
« no previous file with comments | « media/filters/webm_muxer.h ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/filters/webm_muxer.h"
6
7 #include "base/time/time.h"
8
9 namespace media {
10
11 WebmMuxer::WebmMuxer(const WriteDataCB& write_data_callback)
12 : write_data_callback_(write_data_callback),
13 time_start_(base::TimeTicks::Now()),
14 position_(0),
15 segment_(new mkvmuxer::Segment()) {
16 DVLOG(3) << __FUNCTION__;
17 DCHECK(thread_checker_.CalledOnValidThread());
18 segment_->Init(this);
19 segment_->set_mode(mkvmuxer::Segment::kLive);
20
21 // DateUTC is specified in nanoseconds from 0:00 on January 1st, 2001.
22 base::Time::Exploded millennium_exploded = {};
23 millennium_exploded.year = 2001;
24 millennium_exploded.month = 1;
25 millennium_exploded.day_of_month = 1;
26 segment_->GetSegmentInfo()->set_date_utc(
27 (base::Time::Now() - base::Time::FromUTCExploded(millennium_exploded))
28 .InMicroseconds() *
29 base::Time::kNanosecondsPerMicrosecond);
30
31 mkvmuxer::SegmentInfo* const info = segment_->GetSegmentInfo();
32 info->set_writing_app("Chrome");
33 info->set_muxing_app("Chrome");
34 }
35
36 WebmMuxer::~WebmMuxer() {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 DVLOG(3) << __FUNCTION__;
39 }
40
41 void WebmMuxer::OnEncodedVideo(int track_index,
42 const std::string& encoded_data,
43 const base::TimeTicks& timestamp,
44 bool keyframe,
45 const gfx::Size& frame_size,
46 double frame_rate) {
47 DVLOG(3) << __FUNCTION__;
48 DCHECK(thread_checker_.CalledOnValidThread());
49
50 const int track_index_starting_from_one = track_index + 1;
51
52 if (std::find(track_indexes_.begin(), track_indexes_.end(),
53 track_index_starting_from_one) == track_indexes_.end()) {
54 AddVideoTrack(frame_size, frame_rate, track_index_starting_from_one);
55 track_indexes_.push_back(track_index_starting_from_one);
56 }
57
58 const int64 time_code = (timestamp - time_start_).InMicroseconds() *
59 base::Time::kNanosecondsPerMicrosecond;
60 segment_->AddFrame(reinterpret_cast<const uint8_t*>(encoded_data.data()),
61 encoded_data.size(),
62 track_index_starting_from_one,
63 time_code,
64 keyframe);
65
66 DVLOG(3) << __FUNCTION__ << " length=" << encoded_data.size()
67 << (keyframe ? " keyframe" : "") << ", time_code=" << time_code;
68 }
69
70 bool WebmMuxer::AddVideoTrack(const gfx::Size& frame_size,
71 double frame_rate,
72 int track_index_starting_from_one) {
73 DVLOG(3) << __FUNCTION__ << " size=" << frame_size.ToString() << " "
74 << frame_rate << "fps, index: " << track_index_starting_from_one;
75 DCHECK(thread_checker_.CalledOnValidThread());
76
77 segment_->AddVideoTrack(frame_size.width(), frame_size.height(),
78 track_index_starting_from_one);
79 mkvmuxer::VideoTrack* video_track = reinterpret_cast<mkvmuxer::VideoTrack*>(
80 segment_->GetTrackByNumber(track_index_starting_from_one));
81
82 video_track->set_codec_id(mkvmuxer::Tracks::kVp8CodecId);
83 video_track->set_crop_right(0);
84 video_track->set_crop_bottom(0);
85 video_track->set_frame_rate(frame_rate);
86 video_track->set_default_duration(33); // kFrameIntervalNs / 3);
87
88 return true;
89 }
90
91 mkvmuxer::int32 WebmMuxer::Write(const void* buf, mkvmuxer::uint32 len) {
92 DVLOG(3) << __FUNCTION__ << " length=" << len;
93 DCHECK(thread_checker_.CalledOnValidThread());
94 // TODO(mcasas): Last parameter is |last_in_slice|, how to calculate it?
95 write_data_callback_.Run(static_cast<const char*>(buf), len, false);
96 position_ += len;
97 return 0;
98 }
99
100 mkvmuxer::int64 WebmMuxer::Position() const {
101 return position_;
102 }
103
104 mkvmuxer::int32 WebmMuxer::Position(mkvmuxer::int64 position) {
105 // NOTREACHED();
106 return -1;
107 }
108
109 bool WebmMuxer::Seekable() const {
110 return false;
111 }
112
113 void WebmMuxer::ElementStartNotify(mkvmuxer::uint64 element_id,
114 mkvmuxer::int64 position) {
115 // NOTIMPLEMENTED();
116 }
117
118 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/webm_muxer.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698