OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cast/receiver/cast_receiver_impl.h" | 5 #include "media/cast/receiver/cast_receiver_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "media/cast/receiver/audio_decoder.h" | 16 #include "media/cast/receiver/audio_decoder.h" |
16 #include "media/cast/receiver/video_decoder.h" | 17 #include "media/cast/receiver/video_decoder.h" |
17 | 18 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (!audio_decoder_) { | 123 if (!audio_decoder_) { |
123 audio_decoder_.reset(new AudioDecoder(cast_environment_, | 124 audio_decoder_.reset(new AudioDecoder(cast_environment_, |
124 num_audio_channels_, | 125 num_audio_channels_, |
125 audio_sampling_rate_, | 126 audio_sampling_rate_, |
126 audio_codec_)); | 127 audio_codec_)); |
127 } | 128 } |
128 const uint32_t frame_id = encoded_frame->frame_id; | 129 const uint32_t frame_id = encoded_frame->frame_id; |
129 const uint32_t rtp_timestamp = encoded_frame->rtp_timestamp; | 130 const uint32_t rtp_timestamp = encoded_frame->rtp_timestamp; |
130 const base::TimeTicks playout_time = encoded_frame->reference_time; | 131 const base::TimeTicks playout_time = encoded_frame->reference_time; |
131 audio_decoder_->DecodeFrame( | 132 audio_decoder_->DecodeFrame( |
132 encoded_frame.Pass(), | 133 std::move(encoded_frame), |
133 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, | 134 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, cast_environment_, |
134 cast_environment_, | 135 callback, frame_id, rtp_timestamp, playout_time)); |
135 callback, | |
136 frame_id, | |
137 rtp_timestamp, | |
138 playout_time)); | |
139 } | 136 } |
140 | 137 |
141 void CastReceiverImpl::DecodeEncodedVideoFrame( | 138 void CastReceiverImpl::DecodeEncodedVideoFrame( |
142 const VideoFrameDecodedCallback& callback, | 139 const VideoFrameDecodedCallback& callback, |
143 scoped_ptr<EncodedFrame> encoded_frame) { | 140 scoped_ptr<EncodedFrame> encoded_frame) { |
144 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 141 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
145 if (!encoded_frame) { | 142 if (!encoded_frame) { |
146 callback.Run( | 143 callback.Run( |
147 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); | 144 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); |
148 return; | 145 return; |
149 } | 146 } |
150 | 147 |
151 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 148 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
152 TRACE_EVENT_INSTANT2( | 149 TRACE_EVENT_INSTANT2( |
153 "cast_perf_test", "PullEncodedVideoFrame", | 150 "cast_perf_test", "PullEncodedVideoFrame", |
154 TRACE_EVENT_SCOPE_THREAD, | 151 TRACE_EVENT_SCOPE_THREAD, |
155 "rtp_timestamp", encoded_frame->rtp_timestamp, | 152 "rtp_timestamp", encoded_frame->rtp_timestamp, |
156 "render_time", encoded_frame->reference_time.ToInternalValue()); | 153 "render_time", encoded_frame->reference_time.ToInternalValue()); |
157 | 154 |
158 if (!video_decoder_) | 155 if (!video_decoder_) |
159 video_decoder_.reset(new VideoDecoder(cast_environment_, video_codec_)); | 156 video_decoder_.reset(new VideoDecoder(cast_environment_, video_codec_)); |
160 const uint32_t frame_id = encoded_frame->frame_id; | 157 const uint32_t frame_id = encoded_frame->frame_id; |
161 const uint32_t rtp_timestamp = encoded_frame->rtp_timestamp; | 158 const uint32_t rtp_timestamp = encoded_frame->rtp_timestamp; |
162 const base::TimeTicks playout_time = encoded_frame->reference_time; | 159 const base::TimeTicks playout_time = encoded_frame->reference_time; |
163 video_decoder_->DecodeFrame( | 160 video_decoder_->DecodeFrame( |
164 encoded_frame.Pass(), | 161 std::move(encoded_frame), |
165 base::Bind(&CastReceiverImpl::EmitDecodedVideoFrame, | 162 base::Bind(&CastReceiverImpl::EmitDecodedVideoFrame, cast_environment_, |
166 cast_environment_, | 163 callback, frame_id, rtp_timestamp, playout_time)); |
167 callback, | |
168 frame_id, | |
169 rtp_timestamp, | |
170 playout_time)); | |
171 } | 164 } |
172 | 165 |
173 // static | 166 // static |
174 void CastReceiverImpl::EmitDecodedAudioFrame( | 167 void CastReceiverImpl::EmitDecodedAudioFrame( |
175 const scoped_refptr<CastEnvironment>& cast_environment, | 168 const scoped_refptr<CastEnvironment>& cast_environment, |
176 const AudioFrameDecodedCallback& callback, | 169 const AudioFrameDecodedCallback& callback, |
177 uint32_t frame_id, | 170 uint32_t frame_id, |
178 uint32_t rtp_timestamp, | 171 uint32_t rtp_timestamp, |
179 const base::TimeTicks& playout_time, | 172 const base::TimeTicks& playout_time, |
180 scoped_ptr<AudioBus> audio_bus, | 173 scoped_ptr<AudioBus> audio_bus, |
181 bool is_continuous) { | 174 bool is_continuous) { |
182 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); | 175 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); |
183 | 176 |
184 if (audio_bus.get()) { | 177 if (audio_bus.get()) { |
185 // TODO(miu): This is reporting incorrect timestamp and delay. | 178 // TODO(miu): This is reporting incorrect timestamp and delay. |
186 // http://crbug.com/547251 | 179 // http://crbug.com/547251 |
187 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); | 180 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); |
188 playout_event->timestamp = cast_environment->Clock()->NowTicks(); | 181 playout_event->timestamp = cast_environment->Clock()->NowTicks(); |
189 playout_event->type = FRAME_PLAYOUT; | 182 playout_event->type = FRAME_PLAYOUT; |
190 playout_event->media_type = AUDIO_EVENT; | 183 playout_event->media_type = AUDIO_EVENT; |
191 playout_event->rtp_timestamp = rtp_timestamp; | 184 playout_event->rtp_timestamp = rtp_timestamp; |
192 playout_event->frame_id = frame_id; | 185 playout_event->frame_id = frame_id; |
193 playout_event->delay_delta = playout_time - playout_event->timestamp; | 186 playout_event->delay_delta = playout_time - playout_event->timestamp; |
194 cast_environment->logger()->DispatchFrameEvent(playout_event.Pass()); | 187 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); |
195 } | 188 } |
196 | 189 |
197 callback.Run(audio_bus.Pass(), playout_time, is_continuous); | 190 callback.Run(std::move(audio_bus), playout_time, is_continuous); |
198 } | 191 } |
199 | 192 |
200 // static | 193 // static |
201 void CastReceiverImpl::EmitDecodedVideoFrame( | 194 void CastReceiverImpl::EmitDecodedVideoFrame( |
202 const scoped_refptr<CastEnvironment>& cast_environment, | 195 const scoped_refptr<CastEnvironment>& cast_environment, |
203 const VideoFrameDecodedCallback& callback, | 196 const VideoFrameDecodedCallback& callback, |
204 uint32_t frame_id, | 197 uint32_t frame_id, |
205 uint32_t rtp_timestamp, | 198 uint32_t rtp_timestamp, |
206 const base::TimeTicks& playout_time, | 199 const base::TimeTicks& playout_time, |
207 const scoped_refptr<VideoFrame>& video_frame, | 200 const scoped_refptr<VideoFrame>& video_frame, |
208 bool is_continuous) { | 201 bool is_continuous) { |
209 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); | 202 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); |
210 | 203 |
211 if (video_frame.get()) { | 204 if (video_frame.get()) { |
212 // TODO(miu): This is reporting incorrect timestamp and delay. | 205 // TODO(miu): This is reporting incorrect timestamp and delay. |
213 // http://crbug.com/547251 | 206 // http://crbug.com/547251 |
214 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); | 207 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); |
215 playout_event->timestamp = cast_environment->Clock()->NowTicks(); | 208 playout_event->timestamp = cast_environment->Clock()->NowTicks(); |
216 playout_event->type = FRAME_PLAYOUT; | 209 playout_event->type = FRAME_PLAYOUT; |
217 playout_event->media_type = VIDEO_EVENT; | 210 playout_event->media_type = VIDEO_EVENT; |
218 playout_event->rtp_timestamp = rtp_timestamp; | 211 playout_event->rtp_timestamp = rtp_timestamp; |
219 playout_event->frame_id = frame_id; | 212 playout_event->frame_id = frame_id; |
220 playout_event->delay_delta = playout_time - playout_event->timestamp; | 213 playout_event->delay_delta = playout_time - playout_event->timestamp; |
221 cast_environment->logger()->DispatchFrameEvent(playout_event.Pass()); | 214 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); |
222 | 215 |
223 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 216 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
224 TRACE_EVENT_INSTANT1( | 217 TRACE_EVENT_INSTANT1( |
225 "cast_perf_test", "FrameDecoded", | 218 "cast_perf_test", "FrameDecoded", |
226 TRACE_EVENT_SCOPE_THREAD, | 219 TRACE_EVENT_SCOPE_THREAD, |
227 "rtp_timestamp", rtp_timestamp); | 220 "rtp_timestamp", rtp_timestamp); |
228 } | 221 } |
229 | 222 |
230 callback.Run(video_frame, playout_time, is_continuous); | 223 callback.Run(video_frame, playout_time, is_continuous); |
231 } | 224 } |
232 | 225 |
233 } // namespace cast | 226 } // namespace cast |
234 } // namespace media | 227 } // namespace media |
OLD | NEW |