| 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 "content/renderer/media/media_recorder_handler.h" | 5 #include "content/renderer/media/media_recorder_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return true; | 56 return true; |
| 57 | 57 |
| 58 const std::string type(web_type.utf8()); | 58 const std::string type(web_type.utf8()); |
| 59 const bool video = base::EqualsCaseInsensitiveASCII(type, "video/webm"); | 59 const bool video = base::EqualsCaseInsensitiveASCII(type, "video/webm"); |
| 60 const bool audio = | 60 const bool audio = |
| 61 video ? false : base::EqualsCaseInsensitiveASCII(type, "audio/webm"); | 61 video ? false : base::EqualsCaseInsensitiveASCII(type, "audio/webm"); |
| 62 if (!video && !audio) | 62 if (!video && !audio) |
| 63 return false; | 63 return false; |
| 64 | 64 |
| 65 // Both |video| and |audio| support empty |codecs|; |type| == "video" supports | 65 // Both |video| and |audio| support empty |codecs|; |type| == "video" supports |
| 66 // vp8, vp9 or opus; |type| = "audio", supports only opus. | 66 // vp8, vp9, h264 or opus; |type| = "audio", supports only opus. |
| 67 // http://www.webmproject.org/docs/container Sec:"HTML5 Video Type Parameters" | 67 // http://www.webmproject.org/docs/container Sec:"HTML5 Video Type Parameters" |
| 68 static const char* const kVideoCodecs[] = { "vp8", "vp9", "opus" }; | 68 static const char* const kVideoCodecs[] = { "vp8", "vp9", "opus", "h264" }; |
| 69 static const char* const kAudioCodecs[] = { "opus" }; | 69 static const char* const kAudioCodecs[] = { "opus" }; |
| 70 const char* const* codecs = video ? &kVideoCodecs[0] : &kAudioCodecs[0]; | 70 const char* const* codecs = video ? &kVideoCodecs[0] : &kAudioCodecs[0]; |
| 71 int codecs_count = video ? arraysize(kVideoCodecs) : arraysize(kAudioCodecs); | 71 int codecs_count = video ? arraysize(kVideoCodecs) : arraysize(kAudioCodecs); |
| 72 | 72 |
| 73 std::vector<std::string> codecs_list; | 73 std::vector<std::string> codecs_list; |
| 74 media::ParseCodecString(web_codecs.utf8(), &codecs_list, true /* strip */); | 74 media::ParseCodecString(web_codecs.utf8(), &codecs_list, true /* strip */); |
| 75 for (const auto& codec : codecs_list) { | 75 for (const auto& codec : codecs_list) { |
| 76 const auto found = std::find_if( | 76 const auto found = std::find_if( |
| 77 &codecs[0], &codecs[codecs_count], [&codec](const char* name) { | 77 &codecs[0], &codecs[codecs_count], [&codec](const char* name) { |
| 78 return base::EqualsCaseInsensitiveASCII(codec, name); | 78 return base::EqualsCaseInsensitiveASCII(codec, name); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 // Save histogram data so we can see how much MediaStream Recorder is used. | 94 // Save histogram data so we can see how much MediaStream Recorder is used. |
| 95 // The histogram counts the number of calls to the JS API. | 95 // The histogram counts the number of calls to the JS API. |
| 96 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); | 96 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); |
| 97 | 97 |
| 98 if (!canSupportMimeType(type, codecs)) { | 98 if (!canSupportMimeType(type, codecs)) { |
| 99 DLOG(ERROR) << "Can't support " << type.utf8() | 99 DLOG(ERROR) << "Can't support " << type.utf8() |
| 100 << ";codecs=" << codecs.utf8(); | 100 << ";codecs=" << codecs.utf8(); |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 use_vp9_ = base::ToLowerASCII(codecs.utf8()).find("vp9") != std::string::npos; | 103 use_vp9_ = base::ToLowerASCII(codecs.utf8()).find("vp9") != std::string::npos; |
| 104 use_h264_ = base::ToLowerASCII(codecs.utf8()).find("h264") != std::string::npo
s; |
| 105 |
| 106 use_h264_ = true; |
| 107 |
| 104 media_stream_ = media_stream; | 108 media_stream_ = media_stream; |
| 105 DCHECK(client); | 109 DCHECK(client); |
| 106 client_ = client; | 110 client_ = client; |
| 107 | 111 |
| 108 audio_bits_per_second_ = audio_bits_per_second; | 112 audio_bits_per_second_ = audio_bits_per_second; |
| 109 video_bits_per_second_ = video_bits_per_second; | 113 video_bits_per_second_ = video_bits_per_second; |
| 110 return true; | 114 return true; |
| 111 } | 115 } |
| 112 | 116 |
| 113 bool MediaRecorderHandler::start() { | 117 bool MediaRecorderHandler::start() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 video_tracks[0].isEnabled() && | 143 video_tracks[0].isEnabled() && |
| 140 video_tracks[0].source().getReadyState() == | 144 video_tracks[0].source().getReadyState() == |
| 141 blink::WebMediaStreamSource::ReadyStateLive; | 145 blink::WebMediaStreamSource::ReadyStateLive; |
| 142 const bool use_audio_tracks = !audio_tracks.isEmpty() && | 146 const bool use_audio_tracks = !audio_tracks.isEmpty() && |
| 143 MediaStreamAudioTrack::From(audio_tracks[0]) && | 147 MediaStreamAudioTrack::From(audio_tracks[0]) && |
| 144 audio_tracks[0].isEnabled() && | 148 audio_tracks[0].isEnabled() && |
| 145 audio_tracks[0].source().getReadyState() == | 149 audio_tracks[0].source().getReadyState() == |
| 146 blink::WebMediaStreamSource::ReadyStateLive; | 150 blink::WebMediaStreamSource::ReadyStateLive; |
| 147 | 151 |
| 148 webm_muxer_.reset(new media::WebmMuxer( | 152 webm_muxer_.reset(new media::WebmMuxer( |
| 149 use_vp9_ ? media::kCodecVP9 : media::kCodecVP8, use_video_tracks, | 153 |
| 154 use_h264_ |
| 155 ? media::kCodecH264 |
| 156 : (use_vp9_ ? media::kCodecVP9 : media::kCodecVP8), use_video_tracks, |
| 150 use_audio_tracks, base::Bind(&MediaRecorderHandler::WriteData, | 157 use_audio_tracks, base::Bind(&MediaRecorderHandler::WriteData, |
| 151 weak_factory_.GetWeakPtr()))); | 158 weak_factory_.GetWeakPtr()))); |
| 152 | 159 |
| 153 if (use_video_tracks) { | 160 if (use_video_tracks) { |
| 154 // TODO(mcasas): The muxer API supports only one video track. Extend it to | 161 // TODO(mcasas): The muxer API supports only one video track. Extend it to |
| 155 // several video tracks, see http://crbug.com/528523. | 162 // several video tracks, see http://crbug.com/528523. |
| 156 LOG_IF(WARNING, video_tracks.size() > 1u) | 163 LOG_IF(WARNING, video_tracks.size() > 1u) |
| 157 << "Recording multiple video tracks is not implemented. " | 164 << "Recording multiple video tracks is not implemented. " |
| 158 << "Only recording first video track."; | 165 << "Only recording first video track."; |
| 159 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | 166 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; |
| 160 if (video_track.isNull()) | 167 if (video_track.isNull()) |
| 161 return false; | 168 return false; |
| 162 | 169 |
| 163 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | 170 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = |
| 164 media::BindToCurrentLoop(base::Bind( | 171 media::BindToCurrentLoop(base::Bind( |
| 165 &MediaRecorderHandler::OnEncodedVideo, weak_factory_.GetWeakPtr())); | 172 &MediaRecorderHandler::OnEncodedVideo, weak_factory_.GetWeakPtr())); |
| 166 | 173 |
| 174 const VideoTrackRecorder::CodecId codec = |
| 175 use_h264_ ? VideoTrackRecorder::CodecId::H264 |
| 176 : (use_vp9_ ? VideoTrackRecorder::CodecId::VP9 |
| 177 : VideoTrackRecorder::CodecId::VP8); |
| 167 video_recorders_.push_back(new VideoTrackRecorder( | 178 video_recorders_.push_back(new VideoTrackRecorder( |
| 168 use_vp9_, video_track, on_encoded_video_cb, video_bits_per_second_)); | 179 codec, video_track, on_encoded_video_cb, video_bits_per_second_)); |
| 169 } | 180 } |
| 170 | 181 |
| 171 if (use_audio_tracks) { | 182 if (use_audio_tracks) { |
| 172 // TODO(ajose): The muxer API supports only one audio track. Extend it to | 183 // TODO(ajose): The muxer API supports only one audio track. Extend it to |
| 173 // several tracks. | 184 // several tracks. |
| 174 LOG_IF(WARNING, audio_tracks.size() > 1u) | 185 LOG_IF(WARNING, audio_tracks.size() > 1u) |
| 175 << "Recording multiple audio" | 186 << "Recording multiple audio" |
| 176 << " tracks is not implemented. Only recording first audio track."; | 187 << " tracks is not implemented. Only recording first audio track."; |
| 177 const blink::WebMediaStreamTrack& audio_track = audio_tracks[0]; | 188 const blink::WebMediaStreamTrack& audio_track = audio_tracks[0]; |
| 178 if (audio_track.isNull()) | 189 if (audio_track.isNull()) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 recorder->OnData(audio_bus, timestamp); | 285 recorder->OnData(audio_bus, timestamp); |
| 275 } | 286 } |
| 276 | 287 |
| 277 void MediaRecorderHandler::SetAudioFormatForTesting( | 288 void MediaRecorderHandler::SetAudioFormatForTesting( |
| 278 const media::AudioParameters& params) { | 289 const media::AudioParameters& params) { |
| 279 for (auto* recorder : audio_recorders_) | 290 for (auto* recorder : audio_recorders_) |
| 280 recorder->OnSetFormat(params); | 291 recorder->OnSetFormat(params); |
| 281 } | 292 } |
| 282 | 293 |
| 283 } // namespace content | 294 } // namespace content |
| OLD | NEW |