Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/muxers/webm_muxer.h" | 5 #include "media/muxers/webm_muxer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "media/audio/audio_parameters.h" | 8 #include "media/audio/audio_parameters.h" |
| 9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 double frame_rate = kDefaultFrameRate; | 61 double frame_rate = kDefaultFrameRate; |
| 62 if (!video_frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, | 62 if (!video_frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, |
| 63 &frame_rate) || | 63 &frame_rate) || |
| 64 frame_rate <= kZeroFrameRate || | 64 frame_rate <= kZeroFrameRate || |
| 65 frame_rate > media::limits::kMaxFramesPerSecond) { | 65 frame_rate > media::limits::kMaxFramesPerSecond) { |
| 66 frame_rate = kDefaultFrameRate; | 66 frame_rate = kDefaultFrameRate; |
| 67 } | 67 } |
| 68 return frame_rate; | 68 return frame_rate; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(mcasas): Change |kH264CodecId| to "V_MPEG4/ISO/AVC" when | |
| 72 // https://chromium-review.googlesource.com/340298/ is rolled into Chromium. | |
| 73 static const char kH264CodecId[] = ""; | |
| 74 | |
| 75 static const char* MkvCodeIcForMediaVideoCodecId(VideoCodec video_codec) { | |
| 76 switch (video_codec) { | |
| 77 case kCodecVP8: | |
| 78 return mkvmuxer::Tracks::kVp8CodecId; | |
| 79 case kCodecVP9: | |
| 80 return mkvmuxer::Tracks::kVp9CodecId; | |
| 81 case kCodecH264: | |
| 82 return kH264CodecId; | |
| 83 default: | |
|
emircan
2016/04/25 19:26:15
ditto
mcasas
2016/04/26 18:13:38
Can't be done in this case because media::VideoCod
| |
| 84 NOTREACHED() << "Unsupported codec " << GetCodecName(video_codec); | |
| 85 return ""; | |
| 86 } | |
| 87 } | |
| 88 | |
| 71 } // anonymous namespace | 89 } // anonymous namespace |
| 72 | 90 |
| 73 WebmMuxer::WebmMuxer(VideoCodec codec, | 91 WebmMuxer::WebmMuxer(VideoCodec codec, |
| 74 bool has_video, | 92 bool has_video, |
| 75 bool has_audio, | 93 bool has_audio, |
| 76 const WriteDataCB& write_data_callback) | 94 const WriteDataCB& write_data_callback) |
| 77 : use_vp9_(codec == kCodecVP9), | 95 : video_codec_(codec), |
| 78 video_track_index_(0), | 96 video_track_index_(0), |
| 79 audio_track_index_(0), | 97 audio_track_index_(0), |
| 80 has_video_(has_video), | 98 has_video_(has_video), |
| 81 has_audio_(has_audio), | 99 has_audio_(has_audio), |
| 82 write_data_callback_(write_data_callback), | 100 write_data_callback_(write_data_callback), |
| 83 position_(0) { | 101 position_(0) { |
| 84 DCHECK(has_video_ || has_audio_); | 102 DCHECK(has_video_ || has_audio_); |
| 85 DCHECK(!write_data_callback_.is_null()); | 103 DCHECK(!write_data_callback_.is_null()); |
| 86 DCHECK(codec == kCodecVP8 || codec == kCodecVP9) | 104 DCHECK(codec == kCodecVP8 || codec == kCodecVP9 || codec == kCodecH264) |
| 87 << " Only Vp8 and VP9 are supported in WebmMuxer"; | 105 << " Unsupported codec: " << GetCodecName(codec); |
| 88 | 106 |
| 89 segment_.Init(this); | 107 segment_.Init(this); |
| 90 segment_.set_mode(mkvmuxer::Segment::kLive); | 108 segment_.set_mode(mkvmuxer::Segment::kLive); |
| 91 segment_.OutputCues(false); | 109 segment_.OutputCues(false); |
| 92 | 110 |
| 93 mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); | 111 mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); |
| 94 info->set_writing_app("Chrome"); | 112 info->set_writing_app("Chrome"); |
| 95 info->set_muxing_app("Chrome"); | 113 info->set_muxing_app("Chrome"); |
| 96 | 114 |
| 97 // Creation is done on a different thread than main activities. | 115 // Creation is done on a different thread than main activities. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 << "WebmMuxer can only be initialized once."; | 218 << "WebmMuxer can only be initialized once."; |
| 201 | 219 |
| 202 video_track_index_ = | 220 video_track_index_ = |
| 203 segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); | 221 segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); |
| 204 DCHECK_GT(video_track_index_, 0u); | 222 DCHECK_GT(video_track_index_, 0u); |
| 205 | 223 |
| 206 mkvmuxer::VideoTrack* const video_track = | 224 mkvmuxer::VideoTrack* const video_track = |
| 207 reinterpret_cast<mkvmuxer::VideoTrack*>( | 225 reinterpret_cast<mkvmuxer::VideoTrack*>( |
| 208 segment_.GetTrackByNumber(video_track_index_)); | 226 segment_.GetTrackByNumber(video_track_index_)); |
| 209 DCHECK(video_track); | 227 DCHECK(video_track); |
| 210 video_track->set_codec_id(use_vp9_ ? mkvmuxer::Tracks::kVp9CodecId | 228 video_track->set_codec_id(MkvCodeIcForMediaVideoCodecId(video_codec_)); |
| 211 : mkvmuxer::Tracks::kVp8CodecId); | |
| 212 DCHECK_EQ(0ull, video_track->crop_right()); | 229 DCHECK_EQ(0ull, video_track->crop_right()); |
| 213 DCHECK_EQ(0ull, video_track->crop_left()); | 230 DCHECK_EQ(0ull, video_track->crop_left()); |
| 214 DCHECK_EQ(0ull, video_track->crop_top()); | 231 DCHECK_EQ(0ull, video_track->crop_top()); |
| 215 DCHECK_EQ(0ull, video_track->crop_bottom()); | 232 DCHECK_EQ(0ull, video_track->crop_bottom()); |
| 216 DCHECK_EQ(0.0f, video_track->frame_rate()); | 233 DCHECK_EQ(0.0f, video_track->frame_rate()); |
| 217 | 234 |
| 218 video_track->set_default_duration(base::Time::kNanosecondsPerSecond / | 235 video_track->set_default_duration(base::Time::kNanosecondsPerSecond / |
| 219 frame_rate); | 236 frame_rate); |
| 220 // Segment's timestamps should be in milliseconds, DCHECK it. See | 237 // Segment's timestamps should be in milliseconds, DCHECK it. See |
| 221 // http://www.webmproject.org/docs/container/#muxer-guidelines | 238 // http://www.webmproject.org/docs/container/#muxer-guidelines |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 } | 317 } |
| 301 | 318 |
| 302 WebmMuxer::EncodedVideoFrame::EncodedVideoFrame(scoped_ptr<std::string> data, | 319 WebmMuxer::EncodedVideoFrame::EncodedVideoFrame(scoped_ptr<std::string> data, |
| 303 base::TimeTicks timestamp, | 320 base::TimeTicks timestamp, |
| 304 bool is_keyframe) | 321 bool is_keyframe) |
| 305 : data(std::move(data)), timestamp(timestamp), is_keyframe(is_keyframe) {} | 322 : data(std::move(data)), timestamp(timestamp), is_keyframe(is_keyframe) {} |
| 306 | 323 |
| 307 WebmMuxer::EncodedVideoFrame::~EncodedVideoFrame() {} | 324 WebmMuxer::EncodedVideoFrame::~EncodedVideoFrame() {} |
| 308 | 325 |
| 309 } // namespace media | 326 } // namespace media |
| OLD | NEW |