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