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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "media/cast/receiver/audio_decoder.h" | 13 #include "media/cast/receiver/audio_decoder.h" |
14 #include "media/cast/receiver/video_decoder.h" | 14 #include "media/cast/receiver/video_decoder.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 namespace cast { | 17 namespace cast { |
18 | 18 |
19 scoped_ptr<CastReceiver> CastReceiver::Create( | 19 scoped_ptr<CastReceiver> CastReceiver::Create( |
20 scoped_refptr<CastEnvironment> cast_environment, | 20 scoped_refptr<CastEnvironment> cast_environment, |
21 const FrameReceiverConfig& audio_config, | 21 const FrameReceiverConfig& audio_config, |
22 const FrameReceiverConfig& video_config, | 22 const FrameReceiverConfig& video_config, |
23 transport::PacketSender* const packet_sender) { | 23 PacketSender* const packet_sender) { |
24 return scoped_ptr<CastReceiver>(new CastReceiverImpl( | 24 return scoped_ptr<CastReceiver>(new CastReceiverImpl( |
25 cast_environment, audio_config, video_config, packet_sender)); | 25 cast_environment, audio_config, video_config, packet_sender)); |
26 } | 26 } |
27 | 27 |
28 CastReceiverImpl::CastReceiverImpl( | 28 CastReceiverImpl::CastReceiverImpl( |
29 scoped_refptr<CastEnvironment> cast_environment, | 29 scoped_refptr<CastEnvironment> cast_environment, |
30 const FrameReceiverConfig& audio_config, | 30 const FrameReceiverConfig& audio_config, |
31 const FrameReceiverConfig& video_config, | 31 const FrameReceiverConfig& video_config, |
32 transport::PacketSender* const packet_sender) | 32 PacketSender* const packet_sender) |
33 : cast_environment_(cast_environment), | 33 : cast_environment_(cast_environment), |
34 pacer_(cast_environment->Clock(), | 34 pacer_(cast_environment->Clock(), |
35 cast_environment->Logging(), | 35 cast_environment->Logging(), |
36 packet_sender, | 36 packet_sender, |
37 cast_environment->GetTaskRunner(CastEnvironment::MAIN)), | 37 cast_environment->GetTaskRunner(CastEnvironment::MAIN)), |
38 audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, &pacer_), | 38 audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, &pacer_), |
39 video_receiver_(cast_environment, video_config, VIDEO_EVENT, &pacer_), | 39 video_receiver_(cast_environment, video_config, VIDEO_EVENT, &pacer_), |
40 ssrc_of_audio_sender_(audio_config.incoming_ssrc), | 40 ssrc_of_audio_sender_(audio_config.incoming_ssrc), |
41 ssrc_of_video_sender_(video_config.incoming_ssrc), | 41 ssrc_of_video_sender_(video_config.incoming_ssrc), |
42 num_audio_channels_(audio_config.channels), | 42 num_audio_channels_(audio_config.channels), |
(...skipping 26 matching lines...) Expand all Loading... |
69 return; | 69 return; |
70 } | 70 } |
71 cast_environment_->PostTask( | 71 cast_environment_->PostTask( |
72 CastEnvironment::MAIN, | 72 CastEnvironment::MAIN, |
73 FROM_HERE, | 73 FROM_HERE, |
74 base::Bind(base::IgnoreResult(&FrameReceiver::ProcessPacket), | 74 base::Bind(base::IgnoreResult(&FrameReceiver::ProcessPacket), |
75 target, | 75 target, |
76 base::Passed(&packet))); | 76 base::Passed(&packet))); |
77 } | 77 } |
78 | 78 |
79 transport::PacketReceiverCallback CastReceiverImpl::packet_receiver() { | 79 PacketReceiverCallback CastReceiverImpl::packet_receiver() { |
80 return base::Bind(&CastReceiverImpl::DispatchReceivedPacket, | 80 return base::Bind(&CastReceiverImpl::DispatchReceivedPacket, |
81 // TODO(miu): This code structure is dangerous, since the | 81 // TODO(miu): This code structure is dangerous, since the |
82 // callback could be stored and then invoked after | 82 // callback could be stored and then invoked after |
83 // destruction of |this|. | 83 // destruction of |this|. |
84 base::Unretained(this)); | 84 base::Unretained(this)); |
85 } | 85 } |
86 | 86 |
87 void CastReceiverImpl::RequestDecodedAudioFrame( | 87 void CastReceiverImpl::RequestDecodedAudioFrame( |
88 const AudioFrameDecodedCallback& callback) { | 88 const AudioFrameDecodedCallback& callback) { |
89 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 89 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
(...skipping 25 matching lines...) Expand all Loading... |
115 } | 115 } |
116 | 116 |
117 void CastReceiverImpl::RequestEncodedVideoFrame( | 117 void CastReceiverImpl::RequestEncodedVideoFrame( |
118 const ReceiveEncodedFrameCallback& callback) { | 118 const ReceiveEncodedFrameCallback& callback) { |
119 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 119 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
120 video_receiver_.RequestEncodedFrame(callback); | 120 video_receiver_.RequestEncodedFrame(callback); |
121 } | 121 } |
122 | 122 |
123 void CastReceiverImpl::DecodeEncodedAudioFrame( | 123 void CastReceiverImpl::DecodeEncodedAudioFrame( |
124 const AudioFrameDecodedCallback& callback, | 124 const AudioFrameDecodedCallback& callback, |
125 scoped_ptr<transport::EncodedFrame> encoded_frame) { | 125 scoped_ptr<EncodedFrame> encoded_frame) { |
126 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 126 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
127 if (!encoded_frame) { | 127 if (!encoded_frame) { |
128 callback.Run(make_scoped_ptr<AudioBus>(NULL), base::TimeTicks(), false); | 128 callback.Run(make_scoped_ptr<AudioBus>(NULL), base::TimeTicks(), false); |
129 return; | 129 return; |
130 } | 130 } |
131 | 131 |
132 if (!audio_decoder_) { | 132 if (!audio_decoder_) { |
133 audio_decoder_.reset(new AudioDecoder(cast_environment_, | 133 audio_decoder_.reset(new AudioDecoder(cast_environment_, |
134 num_audio_channels_, | 134 num_audio_channels_, |
135 audio_sampling_rate_, | 135 audio_sampling_rate_, |
136 audio_codec_)); | 136 audio_codec_)); |
137 } | 137 } |
138 const uint32 frame_id = encoded_frame->frame_id; | 138 const uint32 frame_id = encoded_frame->frame_id; |
139 const uint32 rtp_timestamp = encoded_frame->rtp_timestamp; | 139 const uint32 rtp_timestamp = encoded_frame->rtp_timestamp; |
140 const base::TimeTicks playout_time = encoded_frame->reference_time; | 140 const base::TimeTicks playout_time = encoded_frame->reference_time; |
141 audio_decoder_->DecodeFrame( | 141 audio_decoder_->DecodeFrame( |
142 encoded_frame.Pass(), | 142 encoded_frame.Pass(), |
143 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, | 143 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, |
144 cast_environment_, | 144 cast_environment_, |
145 callback, | 145 callback, |
146 frame_id, | 146 frame_id, |
147 rtp_timestamp, | 147 rtp_timestamp, |
148 playout_time)); | 148 playout_time)); |
149 } | 149 } |
150 | 150 |
151 void CastReceiverImpl::DecodeEncodedVideoFrame( | 151 void CastReceiverImpl::DecodeEncodedVideoFrame( |
152 const VideoFrameDecodedCallback& callback, | 152 const VideoFrameDecodedCallback& callback, |
153 scoped_ptr<transport::EncodedFrame> encoded_frame) { | 153 scoped_ptr<EncodedFrame> encoded_frame) { |
154 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 154 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
155 if (!encoded_frame) { | 155 if (!encoded_frame) { |
156 callback.Run( | 156 callback.Run( |
157 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); | 157 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 161 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
162 TRACE_EVENT_INSTANT2( | 162 TRACE_EVENT_INSTANT2( |
163 "cast_perf_test", "PullEncodedVideoFrame", | 163 "cast_perf_test", "PullEncodedVideoFrame", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 TRACE_EVENT_INSTANT1( | 223 TRACE_EVENT_INSTANT1( |
224 "cast_perf_test", "FrameDecoded", | 224 "cast_perf_test", "FrameDecoded", |
225 TRACE_EVENT_SCOPE_THREAD, | 225 TRACE_EVENT_SCOPE_THREAD, |
226 "rtp_timestamp", rtp_timestamp); | 226 "rtp_timestamp", rtp_timestamp); |
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 |