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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 69 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
70 media_stream_.videoTracks(video_tracks); | 70 media_stream_.videoTracks(video_tracks); |
71 | 71 |
72 if (video_tracks.isEmpty()) { | 72 if (video_tracks.isEmpty()) { |
73 // TODO(mcasas): Add audio_tracks and update the code in this function | 73 // TODO(mcasas): Add audio_tracks and update the code in this function |
74 // correspondingly, see http://crbug.com/528519. As of now, only video | 74 // correspondingly, see http://crbug.com/528519. As of now, only video |
75 // tracks are supported. | 75 // tracks are supported. |
76 LOG(WARNING) << "Recording no video tracks is not implemented"; | 76 LOG(WARNING) << "Recording no video tracks is not implemented"; |
77 return false; | 77 return false; |
78 } | 78 } |
79 // TODO(mcasas): The muxer API supports only one video track. Extend it to | |
80 // several video tracks, see http://crbug.com/528523. | |
81 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" | |
82 << " tracks is not implemented. Only recording first video track."; | |
83 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | |
84 if (video_track.isNull()) | |
85 return false; | |
86 | 79 |
87 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | 80 for (const blink::WebMediaStreamTrack& video_track : video_tracks) { |
88 media::BindToCurrentLoop(base::Bind(&MediaRecorderHandler::OnEncodedVideo, | 81 if (video_track.isNull()) { |
mcasas
2015/10/06 17:53:13
Is this possible at all?
msu.koo
2015/10/07 04:52:19
I cannot see the routine checking the validity of
| |
89 weak_factory_.GetWeakPtr())); | 82 LOG(WARNING) << "|video_track| is null"; |
83 continue; | |
84 } | |
90 | 85 |
91 video_recorders_.push_back(new VideoTrackRecorder(video_track, | 86 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = |
92 on_encoded_video_cb)); | 87 media::BindToCurrentLoop( |
88 base::Bind(&MediaRecorderHandler::OnEncodedVideo, | |
89 weak_factory_.GetWeakPtr(), | |
90 webm_muxer_->GetNextVideoTrackIndex())); | |
91 video_recorders_.push_back( | |
92 new VideoTrackRecorder(video_track, on_encoded_video_cb)); | |
93 recording_ = true; | |
94 } | |
93 | 95 |
94 recording_ = true; | |
95 return true; | 96 return true; |
96 } | 97 } |
97 | 98 |
98 void MediaRecorderHandler::stop() { | 99 void MediaRecorderHandler::stop() { |
99 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 100 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
100 DCHECK(recording_); | 101 DCHECK(recording_); |
101 | 102 |
102 recording_ = false; | 103 recording_ = false; |
103 video_recorders_.clear(); | 104 video_recorders_.clear(); |
104 webm_muxer_.reset(); | 105 webm_muxer_.reset(); |
105 } | 106 } |
106 | 107 |
107 void MediaRecorderHandler::pause() { | 108 void MediaRecorderHandler::pause() { |
108 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 109 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
109 DCHECK(recording_); | 110 DCHECK(recording_); |
110 recording_ = false; | 111 recording_ = false; |
111 NOTIMPLEMENTED(); | 112 NOTIMPLEMENTED(); |
112 } | 113 } |
113 | 114 |
114 void MediaRecorderHandler::resume() { | 115 void MediaRecorderHandler::resume() { |
115 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 116 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
116 DCHECK(!recording_); | 117 DCHECK(!recording_); |
117 recording_ = true; | 118 recording_ = true; |
118 NOTIMPLEMENTED(); | 119 NOTIMPLEMENTED(); |
119 } | 120 } |
120 | 121 |
121 void MediaRecorderHandler::OnEncodedVideo( | 122 void MediaRecorderHandler::OnEncodedVideo( |
123 int track_index, | |
122 const scoped_refptr<media::VideoFrame>& video_frame, | 124 const scoped_refptr<media::VideoFrame>& video_frame, |
123 scoped_ptr<std::string> encoded_data, | 125 scoped_ptr<std::string> encoded_data, |
124 base::TimeTicks timestamp, | 126 base::TimeTicks timestamp, |
125 bool is_key_frame) { | 127 bool is_key_frame) { |
126 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 128 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
127 if (webm_muxer_) { | 129 if (webm_muxer_) { |
128 webm_muxer_->OnEncodedVideo(video_frame, encoded_data.Pass(), timestamp, | 130 webm_muxer_->OnEncodedVideo(track_index, video_frame, encoded_data.Pass(), |
129 is_key_frame); | 131 timestamp, is_key_frame); |
130 } | 132 } |
131 } | 133 } |
132 | 134 |
133 void MediaRecorderHandler::WriteData(base::StringPiece data) { | 135 void MediaRecorderHandler::WriteData(base::StringPiece data) { |
134 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 136 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
135 client_->writeData(data.data(), data.length(), false /* lastInSlice */); | 137 client_->writeData(data.data(), data.length(), false /* lastInSlice */); |
136 } | 138 } |
137 | 139 |
138 void MediaRecorderHandler::OnVideoFrameForTesting( | 140 void MediaRecorderHandler::OnVideoFrameForTesting( |
139 const scoped_refptr<media::VideoFrame>& frame, | 141 const scoped_refptr<media::VideoFrame>& frame, |
140 const base::TimeTicks& timestamp) { | 142 const base::TimeTicks& timestamp) { |
141 for (auto* recorder : video_recorders_) | 143 for (auto* recorder : video_recorders_) |
142 recorder->OnVideoFrameForTesting(frame, timestamp); | 144 recorder->OnVideoFrameForTesting(frame, timestamp); |
143 } | 145 } |
144 | 146 |
145 } // namespace content | 147 } // namespace content |
OLD | NEW |