| 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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "media/base/audio_parameters.h" | 9 #include "media/base/audio_parameters.h" |
| 10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 double frame_rate = kDefaultFrameRate; | 62 double frame_rate = kDefaultFrameRate; |
| 63 if (!video_frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, | 63 if (!video_frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, |
| 64 &frame_rate) || | 64 &frame_rate) || |
| 65 frame_rate <= kZeroFrameRate || | 65 frame_rate <= kZeroFrameRate || |
| 66 frame_rate > media::limits::kMaxFramesPerSecond) { | 66 frame_rate > media::limits::kMaxFramesPerSecond) { |
| 67 frame_rate = kDefaultFrameRate; | 67 frame_rate = kDefaultFrameRate; |
| 68 } | 68 } |
| 69 return frame_rate; | 69 return frame_rate; |
| 70 } | 70 } |
| 71 | 71 |
| 72 static const char kH264CodecId[] = "V_MPEG4/ISO/AVC"; |
| 73 |
| 74 static const char* MkvCodeIcForMediaVideoCodecId(VideoCodec video_codec) { |
| 75 switch (video_codec) { |
| 76 case kCodecVP8: |
| 77 return mkvmuxer::Tracks::kVp8CodecId; |
| 78 case kCodecVP9: |
| 79 return mkvmuxer::Tracks::kVp9CodecId; |
| 80 case kCodecH264: |
| 81 return kH264CodecId; |
| 82 default: |
| 83 NOTREACHED() << "Unsupported codec " << GetCodecName(video_codec); |
| 84 return ""; |
| 85 } |
| 86 } |
| 87 |
| 72 } // anonymous namespace | 88 } // anonymous namespace |
| 73 | 89 |
| 74 WebmMuxer::WebmMuxer(VideoCodec codec, | 90 WebmMuxer::WebmMuxer(VideoCodec codec, |
| 75 bool has_video, | 91 bool has_video, |
| 76 bool has_audio, | 92 bool has_audio, |
| 77 const WriteDataCB& write_data_callback) | 93 const WriteDataCB& write_data_callback) |
| 78 : use_vp9_(codec == kCodecVP9), | 94 : video_codec_(codec), |
| 79 video_track_index_(0), | 95 video_track_index_(0), |
| 80 audio_track_index_(0), | 96 audio_track_index_(0), |
| 81 has_video_(has_video), | 97 has_video_(has_video), |
| 82 has_audio_(has_audio), | 98 has_audio_(has_audio), |
| 83 write_data_callback_(write_data_callback), | 99 write_data_callback_(write_data_callback), |
| 84 position_(0) { | 100 position_(0) { |
| 85 DCHECK(has_video_ || has_audio_); | 101 DCHECK(has_video_ || has_audio_); |
| 86 DCHECK(!write_data_callback_.is_null()); | 102 DCHECK(!write_data_callback_.is_null()); |
| 87 DCHECK(codec == kCodecVP8 || codec == kCodecVP9) | 103 DCHECK(codec == kCodecVP8 || codec == kCodecVP9 || codec == kCodecH264) |
| 88 << " Only Vp8 and VP9 are supported in WebmMuxer"; | 104 << " Unsupported codec: " << GetCodecName(codec); |
| 89 | 105 |
| 90 segment_.Init(this); | 106 segment_.Init(this); |
| 91 segment_.set_mode(mkvmuxer::Segment::kLive); | 107 segment_.set_mode(mkvmuxer::Segment::kLive); |
| 92 segment_.OutputCues(false); | 108 segment_.OutputCues(false); |
| 93 | 109 |
| 94 mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); | 110 mkvmuxer::SegmentInfo* const info = segment_.GetSegmentInfo(); |
| 95 info->set_writing_app("Chrome"); | 111 info->set_writing_app("Chrome"); |
| 96 info->set_muxing_app("Chrome"); | 112 info->set_muxing_app("Chrome"); |
| 97 | 113 |
| 98 // Creation is done on a different thread than main activities. | 114 // Creation is done on a different thread than main activities. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 << "WebmMuxer can only be initialized once."; | 217 << "WebmMuxer can only be initialized once."; |
| 202 | 218 |
| 203 video_track_index_ = | 219 video_track_index_ = |
| 204 segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); | 220 segment_.AddVideoTrack(frame_size.width(), frame_size.height(), 0); |
| 205 DCHECK_GT(video_track_index_, 0u); | 221 DCHECK_GT(video_track_index_, 0u); |
| 206 | 222 |
| 207 mkvmuxer::VideoTrack* const video_track = | 223 mkvmuxer::VideoTrack* const video_track = |
| 208 reinterpret_cast<mkvmuxer::VideoTrack*>( | 224 reinterpret_cast<mkvmuxer::VideoTrack*>( |
| 209 segment_.GetTrackByNumber(video_track_index_)); | 225 segment_.GetTrackByNumber(video_track_index_)); |
| 210 DCHECK(video_track); | 226 DCHECK(video_track); |
| 211 video_track->set_codec_id(use_vp9_ ? mkvmuxer::Tracks::kVp9CodecId | 227 video_track->set_codec_id(MkvCodeIcForMediaVideoCodecId(video_codec_)); |
| 212 : mkvmuxer::Tracks::kVp8CodecId); | |
| 213 DCHECK_EQ(0ull, video_track->crop_right()); | 228 DCHECK_EQ(0ull, video_track->crop_right()); |
| 214 DCHECK_EQ(0ull, video_track->crop_left()); | 229 DCHECK_EQ(0ull, video_track->crop_left()); |
| 215 DCHECK_EQ(0ull, video_track->crop_top()); | 230 DCHECK_EQ(0ull, video_track->crop_top()); |
| 216 DCHECK_EQ(0ull, video_track->crop_bottom()); | 231 DCHECK_EQ(0ull, video_track->crop_bottom()); |
| 217 DCHECK_EQ(0.0f, video_track->frame_rate()); | 232 DCHECK_EQ(0.0f, video_track->frame_rate()); |
| 218 | 233 |
| 219 video_track->set_default_duration(base::Time::kNanosecondsPerSecond / | 234 video_track->set_default_duration(base::Time::kNanosecondsPerSecond / |
| 220 frame_rate); | 235 frame_rate); |
| 221 // Segment's timestamps should be in milliseconds, DCHECK it. See | 236 // Segment's timestamps should be in milliseconds, DCHECK it. See |
| 222 // http://www.webmproject.org/docs/container/#muxer-guidelines | 237 // http://www.webmproject.org/docs/container/#muxer-guidelines |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 317 |
| 303 WebmMuxer::EncodedVideoFrame::EncodedVideoFrame( | 318 WebmMuxer::EncodedVideoFrame::EncodedVideoFrame( |
| 304 std::unique_ptr<std::string> data, | 319 std::unique_ptr<std::string> data, |
| 305 base::TimeTicks timestamp, | 320 base::TimeTicks timestamp, |
| 306 bool is_keyframe) | 321 bool is_keyframe) |
| 307 : data(std::move(data)), timestamp(timestamp), is_keyframe(is_keyframe) {} | 322 : data(std::move(data)), timestamp(timestamp), is_keyframe(is_keyframe) {} |
| 308 | 323 |
| 309 WebmMuxer::EncodedVideoFrame::~EncodedVideoFrame() {} | 324 WebmMuxer::EncodedVideoFrame::~EncodedVideoFrame() {} |
| 310 | 325 |
| 311 } // namespace media | 326 } // namespace media |
| OLD | NEW |