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 "chrome/renderer/media/cast_receiver_session_delegate.h" | 5 #include "chrome/renderer/media/cast_receiver_session_delegate.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const base::TimeTicks& playout_time, | 56 const base::TimeTicks& playout_time, |
57 bool is_continous) { | 57 bool is_continous) { |
58 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 58 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
59 if (!audio_valve_) | 59 if (!audio_valve_) |
60 return; | 60 return; |
61 | 61 |
62 // We're on the IO thread, which doesn't allow blocking | 62 // We're on the IO thread, which doesn't allow blocking |
63 // operations. Since we don't know what the Capture callback | 63 // operations. Since we don't know what the Capture callback |
64 // will do exactly, we need to jump to a different thread. | 64 // will do exactly, we need to jump to a different thread. |
65 // Let's re-use the audio decoder thread. | 65 // Let's re-use the audio decoder thread. |
66 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | |
67 cast_environment_->PostTask( | 66 cast_environment_->PostTask( |
68 media::cast::CastEnvironment::AUDIO, | 67 media::cast::CastEnvironment::AUDIO, FROM_HERE, |
69 FROM_HERE, | 68 base::Bind(&CastReceiverAudioValve::DeliverDecodedAudio, audio_valve_, |
70 base::Bind(&CastReceiverAudioValve::Capture, | 69 base::Owned(audio_bus.release()), playout_time)); |
71 audio_valve_, | |
72 base::Owned(audio_bus.release()), | |
73 (playout_time - now).InMilliseconds(), | |
74 1.0, | |
75 false)); | |
76 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); | 70 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_); |
77 } | 71 } |
78 | 72 |
79 void CastReceiverSessionDelegate::StartVideo( | 73 void CastReceiverSessionDelegate::StartVideo( |
80 content::VideoCaptureDeliverFrameCB video_callback) { | 74 content::VideoCaptureDeliverFrameCB video_callback) { |
81 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 75 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
82 frame_callback_ = video_callback; | 76 frame_callback_ = video_callback; |
83 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); | 77 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); |
84 } | 78 } |
85 | 79 |
86 void CastReceiverSessionDelegate::StopVideo() { | 80 void CastReceiverSessionDelegate::StopVideo() { |
87 frame_callback_ = content::VideoCaptureDeliverFrameCB(); | 81 frame_callback_ = content::VideoCaptureDeliverFrameCB(); |
88 } | 82 } |
89 | 83 |
90 void CastReceiverSessionDelegate::OnDecodedVideoFrame( | 84 void CastReceiverSessionDelegate::OnDecodedVideoFrame( |
91 const scoped_refptr<media::VideoFrame>& video_frame, | 85 const scoped_refptr<media::VideoFrame>& video_frame, |
92 const base::TimeTicks& playout_time, | 86 const base::TimeTicks& playout_time, |
93 bool is_continous) { | 87 bool is_continous) { |
94 if (frame_callback_.is_null()) | 88 if (frame_callback_.is_null()) |
95 return; | 89 return; |
96 frame_callback_.Run(video_frame, playout_time); | 90 frame_callback_.Run(video_frame, playout_time); |
97 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); | 91 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_); |
98 } | 92 } |
OLD | NEW |