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 |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
16 #include "media/cast/net/rtcp/rtcp_utility.h" | 18 #include "media/cast/net/rtcp/rtcp_utility.h" |
17 #include "media/cast/receiver/audio_decoder.h" | 19 #include "media/cast/receiver/audio_decoder.h" |
18 #include "media/cast/receiver/video_decoder.h" | 20 #include "media/cast/receiver/video_decoder.h" |
19 | 21 |
20 namespace media { | 22 namespace media { |
21 namespace cast { | 23 namespace cast { |
22 | 24 |
23 scoped_ptr<CastReceiver> CastReceiver::Create( | 25 std::unique_ptr<CastReceiver> CastReceiver::Create( |
24 scoped_refptr<CastEnvironment> cast_environment, | 26 scoped_refptr<CastEnvironment> cast_environment, |
25 const FrameReceiverConfig& audio_config, | 27 const FrameReceiverConfig& audio_config, |
26 const FrameReceiverConfig& video_config, | 28 const FrameReceiverConfig& video_config, |
27 CastTransport* const transport) { | 29 CastTransport* const transport) { |
28 return scoped_ptr<CastReceiver>(new CastReceiverImpl( | 30 return std::unique_ptr<CastReceiver>(new CastReceiverImpl( |
29 cast_environment, audio_config, video_config, transport)); | 31 cast_environment, audio_config, video_config, transport)); |
30 } | 32 } |
31 | 33 |
32 CastReceiverImpl::CastReceiverImpl( | 34 CastReceiverImpl::CastReceiverImpl( |
33 scoped_refptr<CastEnvironment> cast_environment, | 35 scoped_refptr<CastEnvironment> cast_environment, |
34 const FrameReceiverConfig& audio_config, | 36 const FrameReceiverConfig& audio_config, |
35 const FrameReceiverConfig& video_config, | 37 const FrameReceiverConfig& video_config, |
36 CastTransport* const transport) | 38 CastTransport* const transport) |
37 : cast_environment_(cast_environment), | 39 : cast_environment_(cast_environment), |
38 audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, transport), | 40 audio_receiver_(cast_environment, audio_config, AUDIO_EVENT, transport), |
39 video_receiver_(cast_environment, video_config, VIDEO_EVENT, transport), | 41 video_receiver_(cast_environment, video_config, VIDEO_EVENT, transport), |
40 ssrc_of_audio_sender_(audio_config.sender_ssrc), | 42 ssrc_of_audio_sender_(audio_config.sender_ssrc), |
41 ssrc_of_video_sender_(video_config.sender_ssrc), | 43 ssrc_of_video_sender_(video_config.sender_ssrc), |
42 num_audio_channels_(audio_config.channels), | 44 num_audio_channels_(audio_config.channels), |
43 audio_sampling_rate_(audio_config.rtp_timebase), | 45 audio_sampling_rate_(audio_config.rtp_timebase), |
44 audio_codec_(audio_config.codec), | 46 audio_codec_(audio_config.codec), |
45 video_codec_(video_config.codec) {} | 47 video_codec_(video_config.codec) {} |
46 | 48 |
47 CastReceiverImpl::~CastReceiverImpl() {} | 49 CastReceiverImpl::~CastReceiverImpl() {} |
48 | 50 |
49 void CastReceiverImpl::ReceivePacket(scoped_ptr<Packet> packet) { | 51 void CastReceiverImpl::ReceivePacket(std::unique_ptr<Packet> packet) { |
50 const uint8_t* const data = &packet->front(); | 52 const uint8_t* const data = &packet->front(); |
51 const size_t length = packet->size(); | 53 const size_t length = packet->size(); |
52 | 54 |
53 uint32_t ssrc_of_sender; | 55 uint32_t ssrc_of_sender; |
54 if (IsRtcpPacket(data, length)) { | 56 if (IsRtcpPacket(data, length)) { |
55 ssrc_of_sender = GetSsrcOfSender(data, length); | 57 ssrc_of_sender = GetSsrcOfSender(data, length); |
56 } else if (!RtpParser::ParseSsrc(data, length, &ssrc_of_sender)) { | 58 } else if (!RtpParser::ParseSsrc(data, length, &ssrc_of_sender)) { |
57 VLOG(1) << "Invalid RTP packet."; | 59 VLOG(1) << "Invalid RTP packet."; |
58 return; | 60 return; |
59 } | 61 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 109 } |
108 | 110 |
109 void CastReceiverImpl::RequestEncodedVideoFrame( | 111 void CastReceiverImpl::RequestEncodedVideoFrame( |
110 const ReceiveEncodedFrameCallback& callback) { | 112 const ReceiveEncodedFrameCallback& callback) { |
111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 113 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
112 video_receiver_.RequestEncodedFrame(callback); | 114 video_receiver_.RequestEncodedFrame(callback); |
113 } | 115 } |
114 | 116 |
115 void CastReceiverImpl::DecodeEncodedAudioFrame( | 117 void CastReceiverImpl::DecodeEncodedAudioFrame( |
116 const AudioFrameDecodedCallback& callback, | 118 const AudioFrameDecodedCallback& callback, |
117 scoped_ptr<EncodedFrame> encoded_frame) { | 119 std::unique_ptr<EncodedFrame> encoded_frame) { |
118 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 120 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
119 if (!encoded_frame) { | 121 if (!encoded_frame) { |
120 callback.Run(make_scoped_ptr<AudioBus>(NULL), base::TimeTicks(), false); | 122 callback.Run(base::WrapUnique<AudioBus>(NULL), base::TimeTicks(), false); |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 if (!audio_decoder_) { | 126 if (!audio_decoder_) { |
125 audio_decoder_.reset(new AudioDecoder(cast_environment_, | 127 audio_decoder_.reset(new AudioDecoder(cast_environment_, |
126 num_audio_channels_, | 128 num_audio_channels_, |
127 audio_sampling_rate_, | 129 audio_sampling_rate_, |
128 audio_codec_)); | 130 audio_codec_)); |
129 } | 131 } |
130 const uint32_t frame_id = encoded_frame->frame_id; | 132 const uint32_t frame_id = encoded_frame->frame_id; |
131 const RtpTimeTicks rtp_timestamp = encoded_frame->rtp_timestamp; | 133 const RtpTimeTicks rtp_timestamp = encoded_frame->rtp_timestamp; |
132 const base::TimeTicks playout_time = encoded_frame->reference_time; | 134 const base::TimeTicks playout_time = encoded_frame->reference_time; |
133 audio_decoder_->DecodeFrame( | 135 audio_decoder_->DecodeFrame( |
134 std::move(encoded_frame), | 136 std::move(encoded_frame), |
135 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, cast_environment_, | 137 base::Bind(&CastReceiverImpl::EmitDecodedAudioFrame, cast_environment_, |
136 callback, frame_id, rtp_timestamp, playout_time)); | 138 callback, frame_id, rtp_timestamp, playout_time)); |
137 } | 139 } |
138 | 140 |
139 void CastReceiverImpl::DecodeEncodedVideoFrame( | 141 void CastReceiverImpl::DecodeEncodedVideoFrame( |
140 const VideoFrameDecodedCallback& callback, | 142 const VideoFrameDecodedCallback& callback, |
141 scoped_ptr<EncodedFrame> encoded_frame) { | 143 std::unique_ptr<EncodedFrame> encoded_frame) { |
142 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 144 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
143 if (!encoded_frame) { | 145 if (!encoded_frame) { |
144 callback.Run( | 146 callback.Run( |
145 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); | 147 make_scoped_refptr<VideoFrame>(NULL), base::TimeTicks(), false); |
146 return; | 148 return; |
147 } | 149 } |
148 | 150 |
149 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 151 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
150 TRACE_EVENT_INSTANT2( | 152 TRACE_EVENT_INSTANT2( |
151 "cast_perf_test", "PullEncodedVideoFrame", | 153 "cast_perf_test", "PullEncodedVideoFrame", |
(...skipping 12 matching lines...) Expand all Loading... |
164 callback, frame_id, rtp_timestamp, playout_time)); | 166 callback, frame_id, rtp_timestamp, playout_time)); |
165 } | 167 } |
166 | 168 |
167 // static | 169 // static |
168 void CastReceiverImpl::EmitDecodedAudioFrame( | 170 void CastReceiverImpl::EmitDecodedAudioFrame( |
169 const scoped_refptr<CastEnvironment>& cast_environment, | 171 const scoped_refptr<CastEnvironment>& cast_environment, |
170 const AudioFrameDecodedCallback& callback, | 172 const AudioFrameDecodedCallback& callback, |
171 uint32_t frame_id, | 173 uint32_t frame_id, |
172 RtpTimeTicks rtp_timestamp, | 174 RtpTimeTicks rtp_timestamp, |
173 const base::TimeTicks& playout_time, | 175 const base::TimeTicks& playout_time, |
174 scoped_ptr<AudioBus> audio_bus, | 176 std::unique_ptr<AudioBus> audio_bus, |
175 bool is_continuous) { | 177 bool is_continuous) { |
176 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); | 178 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); |
177 | 179 |
178 if (audio_bus.get()) { | 180 if (audio_bus.get()) { |
179 // TODO(miu): This is reporting incorrect timestamp and delay. | 181 // TODO(miu): This is reporting incorrect timestamp and delay. |
180 // http://crbug.com/547251 | 182 // http://crbug.com/547251 |
181 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); | 183 std::unique_ptr<FrameEvent> playout_event(new FrameEvent()); |
182 playout_event->timestamp = cast_environment->Clock()->NowTicks(); | 184 playout_event->timestamp = cast_environment->Clock()->NowTicks(); |
183 playout_event->type = FRAME_PLAYOUT; | 185 playout_event->type = FRAME_PLAYOUT; |
184 playout_event->media_type = AUDIO_EVENT; | 186 playout_event->media_type = AUDIO_EVENT; |
185 playout_event->rtp_timestamp = rtp_timestamp; | 187 playout_event->rtp_timestamp = rtp_timestamp; |
186 playout_event->frame_id = frame_id; | 188 playout_event->frame_id = frame_id; |
187 playout_event->delay_delta = playout_time - playout_event->timestamp; | 189 playout_event->delay_delta = playout_time - playout_event->timestamp; |
188 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); | 190 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); |
189 } | 191 } |
190 | 192 |
191 callback.Run(std::move(audio_bus), playout_time, is_continuous); | 193 callback.Run(std::move(audio_bus), playout_time, is_continuous); |
192 } | 194 } |
193 | 195 |
194 // static | 196 // static |
195 void CastReceiverImpl::EmitDecodedVideoFrame( | 197 void CastReceiverImpl::EmitDecodedVideoFrame( |
196 const scoped_refptr<CastEnvironment>& cast_environment, | 198 const scoped_refptr<CastEnvironment>& cast_environment, |
197 const VideoFrameDecodedCallback& callback, | 199 const VideoFrameDecodedCallback& callback, |
198 uint32_t frame_id, | 200 uint32_t frame_id, |
199 RtpTimeTicks rtp_timestamp, | 201 RtpTimeTicks rtp_timestamp, |
200 const base::TimeTicks& playout_time, | 202 const base::TimeTicks& playout_time, |
201 const scoped_refptr<VideoFrame>& video_frame, | 203 const scoped_refptr<VideoFrame>& video_frame, |
202 bool is_continuous) { | 204 bool is_continuous) { |
203 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); | 205 DCHECK(cast_environment->CurrentlyOn(CastEnvironment::MAIN)); |
204 | 206 |
205 if (video_frame.get()) { | 207 if (video_frame.get()) { |
206 // TODO(miu): This is reporting incorrect timestamp and delay. | 208 // TODO(miu): This is reporting incorrect timestamp and delay. |
207 // http://crbug.com/547251 | 209 // http://crbug.com/547251 |
208 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); | 210 std::unique_ptr<FrameEvent> playout_event(new FrameEvent()); |
209 playout_event->timestamp = cast_environment->Clock()->NowTicks(); | 211 playout_event->timestamp = cast_environment->Clock()->NowTicks(); |
210 playout_event->type = FRAME_PLAYOUT; | 212 playout_event->type = FRAME_PLAYOUT; |
211 playout_event->media_type = VIDEO_EVENT; | 213 playout_event->media_type = VIDEO_EVENT; |
212 playout_event->rtp_timestamp = rtp_timestamp; | 214 playout_event->rtp_timestamp = rtp_timestamp; |
213 playout_event->frame_id = frame_id; | 215 playout_event->frame_id = frame_id; |
214 playout_event->delay_delta = playout_time - playout_event->timestamp; | 216 playout_event->delay_delta = playout_time - playout_event->timestamp; |
215 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); | 217 cast_environment->logger()->DispatchFrameEvent(std::move(playout_event)); |
216 | 218 |
217 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 219 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
218 TRACE_EVENT_INSTANT1( | 220 TRACE_EVENT_INSTANT1( |
219 "cast_perf_test", "FrameDecoded", | 221 "cast_perf_test", "FrameDecoded", |
220 TRACE_EVENT_SCOPE_THREAD, | 222 TRACE_EVENT_SCOPE_THREAD, |
221 "rtp_timestamp", rtp_timestamp.lower_32_bits()); | 223 "rtp_timestamp", rtp_timestamp.lower_32_bits()); |
222 } | 224 } |
223 | 225 |
224 callback.Run(video_frame, playout_time, is_continuous); | 226 callback.Run(video_frame, playout_time, is_continuous); |
225 } | 227 } |
226 | 228 |
227 } // namespace cast | 229 } // namespace cast |
228 } // namespace media | 230 } // namespace media |
OLD | NEW |