| 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(new media::WebmMuxer( |
| 72 &MediaRecorderHandler::WriteData, weak_factory_.GetWeakPtr()))); | 74 use_vp9_, base::Bind(&MediaRecorderHandler::WriteData, |
| 75 weak_factory_.GetWeakPtr()))); |
| 73 | 76 |
| 74 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 77 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 75 media_stream_.videoTracks(video_tracks); | 78 media_stream_.videoTracks(video_tracks); |
| 76 | 79 |
| 77 if (video_tracks.isEmpty()) { | 80 if (video_tracks.isEmpty()) { |
| 78 // TODO(mcasas): Add audio_tracks and update the code in this function | 81 // TODO(mcasas): Add audio_tracks and update the code in this function |
| 79 // correspondingly, see http://crbug.com/528519. As of now, only video | 82 // correspondingly, see http://crbug.com/528519. As of now, only video |
| 80 // tracks are supported. | 83 // tracks are supported. |
| 81 LOG(WARNING) << "Recording no video tracks is not implemented"; | 84 LOG(WARNING) << "Recording no video tracks is not implemented"; |
| 82 return false; | 85 return false; |
| 83 } | 86 } |
| 84 // TODO(mcasas): The muxer API supports only one video track. Extend it to | 87 // TODO(mcasas): The muxer API supports only one video track. Extend it to |
| 85 // several video tracks, see http://crbug.com/528523. | 88 // several video tracks, see http://crbug.com/528523. |
| 86 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" | 89 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" |
| 87 << " tracks is not implemented. Only recording first video track."; | 90 << " tracks is not implemented. Only recording first video track."; |
| 88 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | 91 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; |
| 89 if (video_track.isNull()) | 92 if (video_track.isNull()) |
| 90 return false; | 93 return false; |
| 91 | 94 |
| 92 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | 95 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = |
| 93 media::BindToCurrentLoop(base::Bind(&MediaRecorderHandler::OnEncodedVideo, | 96 media::BindToCurrentLoop(base::Bind(&MediaRecorderHandler::OnEncodedVideo, |
| 94 weak_factory_.GetWeakPtr())); | 97 weak_factory_.GetWeakPtr())); |
| 95 | 98 |
| 96 video_recorders_.push_back(new VideoTrackRecorder(video_track, | 99 video_recorders_.push_back(new VideoTrackRecorder(use_vp9_, |
| 100 video_track, |
| 97 on_encoded_video_cb)); | 101 on_encoded_video_cb)); |
| 98 | 102 |
| 99 recording_ = true; | 103 recording_ = true; |
| 100 return true; | 104 return true; |
| 101 } | 105 } |
| 102 | 106 |
| 103 void MediaRecorderHandler::stop() { | 107 void MediaRecorderHandler::stop() { |
| 104 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 108 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 105 DCHECK(recording_); | 109 DCHECK(recording_); |
| 106 | 110 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 145 } |
| 142 | 146 |
| 143 void MediaRecorderHandler::OnVideoFrameForTesting( | 147 void MediaRecorderHandler::OnVideoFrameForTesting( |
| 144 const scoped_refptr<media::VideoFrame>& frame, | 148 const scoped_refptr<media::VideoFrame>& frame, |
| 145 const base::TimeTicks& timestamp) { | 149 const base::TimeTicks& timestamp) { |
| 146 for (auto* recorder : video_recorders_) | 150 for (auto* recorder : video_recorders_) |
| 147 recorder->OnVideoFrameForTesting(frame, timestamp); | 151 recorder->OnVideoFrameForTesting(frame, timestamp); |
| 148 } | 152 } |
| 149 | 153 |
| 150 } // namespace content | 154 } // namespace content |
| OLD | NEW |