| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <climits> | 6 #include <climits> |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 #include <cstdio> | 8 #include <cstdio> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 video_config.max_frame_rate), | 197 video_config.max_frame_rate), |
| 198 #if defined(USE_X11) | 198 #if defined(USE_X11) |
| 199 render_(0, 0, window_width, window_height, "Cast_receiver"), | 199 render_(0, 0, window_width, window_height, "Cast_receiver"), |
| 200 #endif // defined(USE_X11) | 200 #endif // defined(USE_X11) |
| 201 num_video_frames_processed_(0), | 201 num_video_frames_processed_(0), |
| 202 num_audio_frames_processed_(0), | 202 num_audio_frames_processed_(0), |
| 203 currently_playing_audio_frame_start_(-1) {} | 203 currently_playing_audio_frame_start_(-1) {} |
| 204 | 204 |
| 205 virtual ~NaivePlayer() {} | 205 virtual ~NaivePlayer() {} |
| 206 | 206 |
| 207 virtual void Start() OVERRIDE { | 207 virtual void Start() override { |
| 208 AudioManager::Get()->GetTaskRunner()->PostTask( | 208 AudioManager::Get()->GetTaskRunner()->PostTask( |
| 209 FROM_HERE, | 209 FROM_HERE, |
| 210 base::Bind(&NaivePlayer::StartAudioOutputOnAudioManagerThread, | 210 base::Bind(&NaivePlayer::StartAudioOutputOnAudioManagerThread, |
| 211 base::Unretained(this))); | 211 base::Unretained(this))); |
| 212 // Note: No need to wait for audio polling to start since the push-and-pull | 212 // Note: No need to wait for audio polling to start since the push-and-pull |
| 213 // mechanism is synchronized via the |audio_playout_queue_|. | 213 // mechanism is synchronized via the |audio_playout_queue_|. |
| 214 InProcessReceiver::Start(); | 214 InProcessReceiver::Start(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 virtual void Stop() OVERRIDE { | 217 virtual void Stop() override { |
| 218 // First, stop audio output to the Chromium audio stack. | 218 // First, stop audio output to the Chromium audio stack. |
| 219 base::WaitableEvent done(false, false); | 219 base::WaitableEvent done(false, false); |
| 220 DCHECK(!AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 220 DCHECK(!AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 221 AudioManager::Get()->GetTaskRunner()->PostTask( | 221 AudioManager::Get()->GetTaskRunner()->PostTask( |
| 222 FROM_HERE, | 222 FROM_HERE, |
| 223 base::Bind(&NaivePlayer::StopAudioOutputOnAudioManagerThread, | 223 base::Bind(&NaivePlayer::StopAudioOutputOnAudioManagerThread, |
| 224 base::Unretained(this), | 224 base::Unretained(this), |
| 225 &done)); | 225 &done)); |
| 226 done.Wait(); | 226 done.Wait(); |
| 227 | 227 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 audio_output_stream_.reset(); | 260 audio_output_stream_.reset(); |
| 261 } | 261 } |
| 262 done->Signal(); | 262 done->Signal(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 //////////////////////////////////////////////////////////////////// | 265 //////////////////////////////////////////////////////////////////// |
| 266 // InProcessReceiver overrides. | 266 // InProcessReceiver overrides. |
| 267 | 267 |
| 268 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 268 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
| 269 const base::TimeTicks& playout_time, | 269 const base::TimeTicks& playout_time, |
| 270 bool is_continuous) OVERRIDE { | 270 bool is_continuous) override { |
| 271 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 271 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
| 272 LOG_IF(WARNING, !is_continuous) | 272 LOG_IF(WARNING, !is_continuous) |
| 273 << "Video: Discontinuity in received frames."; | 273 << "Video: Discontinuity in received frames."; |
| 274 video_playout_queue_.push_back(std::make_pair(playout_time, video_frame)); | 274 video_playout_queue_.push_back(std::make_pair(playout_time, video_frame)); |
| 275 ScheduleVideoPlayout(); | 275 ScheduleVideoPlayout(); |
| 276 uint16 frame_no; | 276 uint16 frame_no; |
| 277 if (media::cast::test::DecodeBarcode(video_frame, &frame_no)) { | 277 if (media::cast::test::DecodeBarcode(video_frame, &frame_no)) { |
| 278 video_play_times_.insert( | 278 video_play_times_.insert( |
| 279 std::pair<uint16, base::TimeTicks>(frame_no, playout_time)); | 279 std::pair<uint16, base::TimeTicks>(frame_no, playout_time)); |
| 280 } else { | 280 } else { |
| 281 VLOG(2) << "Barcode decode failed!"; | 281 VLOG(2) << "Barcode decode failed!"; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 virtual void OnAudioFrame(scoped_ptr<AudioBus> audio_frame, | 285 virtual void OnAudioFrame(scoped_ptr<AudioBus> audio_frame, |
| 286 const base::TimeTicks& playout_time, | 286 const base::TimeTicks& playout_time, |
| 287 bool is_continuous) OVERRIDE { | 287 bool is_continuous) override { |
| 288 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 288 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
| 289 LOG_IF(WARNING, !is_continuous) | 289 LOG_IF(WARNING, !is_continuous) |
| 290 << "Audio: Discontinuity in received frames."; | 290 << "Audio: Discontinuity in received frames."; |
| 291 base::AutoLock auto_lock(audio_lock_); | 291 base::AutoLock auto_lock(audio_lock_); |
| 292 uint16 frame_no; | 292 uint16 frame_no; |
| 293 if (media::cast::DecodeTimestamp(audio_frame->channel(0), | 293 if (media::cast::DecodeTimestamp(audio_frame->channel(0), |
| 294 audio_frame->frames(), | 294 audio_frame->frames(), |
| 295 &frame_no)) { | 295 &frame_no)) { |
| 296 // Since there are lots of audio packets with the same frame_no, | 296 // Since there are lots of audio packets with the same frame_no, |
| 297 // we really want to make sure that we get the playout_time from | 297 // we really want to make sure that we get the playout_time from |
| (...skipping 12 matching lines...) Expand all Loading... |
| 310 std::make_pair(playout_time, audio_frame.release())); | 310 std::make_pair(playout_time, audio_frame.release())); |
| 311 } | 311 } |
| 312 | 312 |
| 313 // End of InProcessReceiver overrides. | 313 // End of InProcessReceiver overrides. |
| 314 //////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////// |
| 315 | 315 |
| 316 //////////////////////////////////////////////////////////////////// | 316 //////////////////////////////////////////////////////////////////// |
| 317 // AudioSourceCallback implementation. | 317 // AudioSourceCallback implementation. |
| 318 | 318 |
| 319 virtual int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) | 319 virtual int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) |
| 320 OVERRIDE { | 320 override { |
| 321 // Note: This method is being invoked by a separate thread unknown to us | 321 // Note: This method is being invoked by a separate thread unknown to us |
| 322 // (i.e., outside of CastEnvironment). | 322 // (i.e., outside of CastEnvironment). |
| 323 | 323 |
| 324 int samples_remaining = dest->frames(); | 324 int samples_remaining = dest->frames(); |
| 325 | 325 |
| 326 while (samples_remaining > 0) { | 326 while (samples_remaining > 0) { |
| 327 // Get next audio frame ready for playout. | 327 // Get next audio frame ready for playout. |
| 328 if (!currently_playing_audio_frame_.get()) { | 328 if (!currently_playing_audio_frame_.get()) { |
| 329 base::AutoLock auto_lock(audio_lock_); | 329 base::AutoLock auto_lock(audio_lock_); |
| 330 | 330 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Note: Only logging underruns after the first frame has been received. | 370 // Note: Only logging underruns after the first frame has been received. |
| 371 LOG_IF(WARNING, currently_playing_audio_frame_start_ != -1) | 371 LOG_IF(WARNING, currently_playing_audio_frame_start_ != -1) |
| 372 << "Audio: Playback underrun of " << samples_remaining << " samples!"; | 372 << "Audio: Playback underrun of " << samples_remaining << " samples!"; |
| 373 dest->ZeroFramesPartial(dest->frames() - samples_remaining, | 373 dest->ZeroFramesPartial(dest->frames() - samples_remaining, |
| 374 samples_remaining); | 374 samples_remaining); |
| 375 } | 375 } |
| 376 | 376 |
| 377 return dest->frames(); | 377 return dest->frames(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 virtual void OnError(AudioOutputStream* stream) OVERRIDE { | 380 virtual void OnError(AudioOutputStream* stream) override { |
| 381 LOG(ERROR) << "AudioOutputStream reports an error. " | 381 LOG(ERROR) << "AudioOutputStream reports an error. " |
| 382 << "Playback is unlikely to continue."; | 382 << "Playback is unlikely to continue."; |
| 383 } | 383 } |
| 384 | 384 |
| 385 // End of AudioSourceCallback implementation. | 385 // End of AudioSourceCallback implementation. |
| 386 //////////////////////////////////////////////////////////////////// | 386 //////////////////////////////////////////////////////////////////// |
| 387 | 387 |
| 388 void ScheduleVideoPlayout() { | 388 void ScheduleVideoPlayout() { |
| 389 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 389 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
| 390 | 390 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 audio_config, | 592 audio_config, |
| 593 video_config, | 593 video_config, |
| 594 window_width, | 594 window_width, |
| 595 window_height); | 595 window_height); |
| 596 player.Start(); | 596 player.Start(); |
| 597 | 597 |
| 598 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). | 598 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). |
| 599 NOTREACHED(); | 599 NOTREACHED(); |
| 600 return 0; | 600 return 0; |
| 601 } | 601 } |
| OLD | NEW |