| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/renderer/media/video_track_recorder.h" | 10 #include "content/renderer/media/video_track_recorder.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 MediaRecorderHandler::~MediaRecorderHandler() { | 25 MediaRecorderHandler::~MediaRecorderHandler() { |
| 26 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 26 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 27 // Send a |last_in_slice| to our |client_|. | 27 // Send a |last_in_slice| to our |client_|. |
| 28 if (client_) | 28 if (client_) |
| 29 client_->writeData(nullptr, 0u, true); | 29 client_->writeData(nullptr, 0u, true); |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool MediaRecorderHandler::canSupportMimeType( | 32 bool MediaRecorderHandler::canSupportMimeType( |
| 33 const blink::WebString& mimeType) { | 33 const blink::WebString& mimeType) { |
| 34 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 34 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 35 // TODO(mcasas): For the time being only empty or "video/vp8" are supported. | 35 // TODO(mcasas): So far only empty or "video/vp{8,9}" are supported. |
| 36 return mimeType.isEmpty() || mimeType.utf8().compare("video/vp8") == 0; | 36 return mimeType.isEmpty() || mimeType.utf8().compare("video/vp8") == 0 || |
| 37 mimeType.utf8().compare("video/vp9") == 0; |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool MediaRecorderHandler::initialize( | 40 bool MediaRecorderHandler::initialize( |
| 40 blink::WebMediaRecorderHandlerClient* client, | 41 blink::WebMediaRecorderHandlerClient* client, |
| 41 const blink::WebMediaStream& media_stream, | 42 const blink::WebMediaStream& media_stream, |
| 42 const blink::WebString& mimeType) { | 43 const blink::WebString& mimeType) { |
| 43 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 44 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 44 // Save histogram data so we can see how much MediaStream Recorder is used. | 45 // Save histogram data so we can see how much MediaStream Recorder is used. |
| 45 // The histogram counts the number of calls to the JS API. | 46 // The histogram counts the number of calls to the JS API. |
| 46 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); | 47 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); |
| 47 | 48 |
| 48 if (!canSupportMimeType(mimeType)) { | 49 if (!canSupportMimeType(mimeType)) { |
| 49 DLOG(ERROR) << "Can't support type " << mimeType.utf8(); | 50 DLOG(ERROR) << "Can't support type " << mimeType.utf8(); |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 53 use_vp9_ = mimeType.utf8().compare("video/vp9") == 0; |
| 52 media_stream_ = media_stream; | 54 media_stream_ = media_stream; |
| 53 DCHECK(client); | 55 DCHECK(client); |
| 54 client_ = client; | 56 client_ = client; |
| 55 | 57 |
| 56 return true; | 58 return true; |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool MediaRecorderHandler::start() { | 61 bool MediaRecorderHandler::start() { |
| 60 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 62 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 61 DCHECK(!recording_); | 63 DCHECK(!recording_); |
| 62 return start(0); | 64 return start(0); |
| 63 } | 65 } |
| 64 | 66 |
| 65 bool MediaRecorderHandler::start(int timeslice) { | 67 bool MediaRecorderHandler::start(int timeslice) { |
| 66 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 68 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 67 DCHECK(!recording_); | 69 DCHECK(!recording_); |
| 68 DCHECK(!media_stream_.isNull()); | 70 DCHECK(!media_stream_.isNull()); |
| 69 DCHECK(!webm_muxer_); | 71 DCHECK(!webm_muxer_); |
| 70 | 72 |
| 71 webm_muxer_.reset(new media::WebmMuxer(base::Bind( | 73 webm_muxer_.reset( |
| 72 &MediaRecorderHandler::WriteData, weak_factory_.GetWeakPtr()))); | 74 new media::WebmMuxer(use_vp9_ ? media::kCodecVP9 : media::kCodecVP8, |
| 75 base::Bind(&MediaRecorderHandler::WriteData, |
| 76 weak_factory_.GetWeakPtr()))); |
| 73 | 77 |
| 74 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 78 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 75 media_stream_.videoTracks(video_tracks); | 79 media_stream_.videoTracks(video_tracks); |
| 76 | 80 |
| 77 if (video_tracks.isEmpty()) { | 81 if (video_tracks.isEmpty()) { |
| 78 // TODO(mcasas): Add audio_tracks and update the code in this function | 82 // TODO(mcasas): Add audio_tracks and update the code in this function |
| 79 // correspondingly, see http://crbug.com/528519. As of now, only video | 83 // correspondingly, see http://crbug.com/528519. As of now, only video |
| 80 // tracks are supported. | 84 // tracks are supported. |
| 81 LOG(WARNING) << "Recording no video tracks is not implemented"; | 85 LOG(WARNING) << "Recording no video tracks is not implemented"; |
| 82 return false; | 86 return false; |
| 83 } | 87 } |
| 84 // TODO(mcasas): The muxer API supports only one video track. Extend it to | 88 // TODO(mcasas): The muxer API supports only one video track. Extend it to |
| 85 // several video tracks, see http://crbug.com/528523. | 89 // several video tracks, see http://crbug.com/528523. |
| 86 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" | 90 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" |
| 87 << " tracks is not implemented. Only recording first video track."; | 91 << " tracks is not implemented. Only recording first video track."; |
| 88 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | 92 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; |
| 89 if (video_track.isNull()) | 93 if (video_track.isNull()) |
| 90 return false; | 94 return false; |
| 91 | 95 |
| 92 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | 96 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = |
| 93 media::BindToCurrentLoop(base::Bind(&MediaRecorderHandler::OnEncodedVideo, | 97 media::BindToCurrentLoop(base::Bind(&MediaRecorderHandler::OnEncodedVideo, |
| 94 weak_factory_.GetWeakPtr())); | 98 weak_factory_.GetWeakPtr())); |
| 95 | 99 |
| 96 video_recorders_.push_back(new VideoTrackRecorder(video_track, | 100 video_recorders_.push_back(new VideoTrackRecorder(use_vp9_, |
| 101 video_track, |
| 97 on_encoded_video_cb)); | 102 on_encoded_video_cb)); |
| 98 | 103 |
| 99 recording_ = true; | 104 recording_ = true; |
| 100 return true; | 105 return true; |
| 101 } | 106 } |
| 102 | 107 |
| 103 void MediaRecorderHandler::stop() { | 108 void MediaRecorderHandler::stop() { |
| 104 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 109 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 105 DCHECK(recording_); | 110 DCHECK(recording_); |
| 106 | 111 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 146 } |
| 142 | 147 |
| 143 void MediaRecorderHandler::OnVideoFrameForTesting( | 148 void MediaRecorderHandler::OnVideoFrameForTesting( |
| 144 const scoped_refptr<media::VideoFrame>& frame, | 149 const scoped_refptr<media::VideoFrame>& frame, |
| 145 const base::TimeTicks& timestamp) { | 150 const base::TimeTicks& timestamp) { |
| 146 for (auto* recorder : video_recorders_) | 151 for (auto* recorder : video_recorders_) |
| 147 recorder->OnVideoFrameForTesting(frame, timestamp); | 152 recorder->OnVideoFrameForTesting(frame, timestamp); |
| 148 } | 153 } |
| 149 | 154 |
| 150 } // namespace content | 155 } // namespace content |
| OLD | NEW |