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 "media/cast/transport/rtp_sender/rtp_sender.h" | 5 #include "media/cast/transport/rtp_sender/rtp_sender.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "media/cast/transport/cast_transport_defines.h" | 9 #include "media/cast/transport/cast_transport_defines.h" |
10 #include "media/cast/transport/pacing/paced_sender.h" | 10 #include "media/cast/transport/pacing/paced_sender.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 namespace cast { | 13 namespace cast { |
14 namespace transport { | 14 namespace transport { |
15 | 15 |
16 // Schedule the RTP statistics callback every 33mS. As this interval affects the | 16 // Schedule the RTP statistics callback every 33mS. As this interval affects the |
17 // time offset of the render and playout times, we want it in the same ball park | 17 // time offset of the render and playout times, we want it in the same ball park |
18 // as the frame rate. | 18 // as the frame rate. |
19 static const int kStatsCallbackIntervalMs = 33; | 19 static const int kStatsCallbackIntervalMs = 33; |
20 | 20 |
21 RtpSender::RtpSender( | 21 RtpSender::RtpSender( |
22 base::TickClock* clock, | 22 base::TickClock* clock, |
23 const CastTransportConfig& config, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, |
24 bool is_audio, | |
25 const scoped_refptr<base::TaskRunner>& transport_task_runner, | |
26 PacedSender* const transport) | 24 PacedSender* const transport) |
27 : config_(), | 25 : clock_(clock), |
28 transport_(transport), | 26 transport_(transport), |
29 stats_callback_(), | 27 stats_callback_(), |
30 transport_task_runner_(transport_task_runner) { | 28 transport_task_runner_(transport_task_runner), |
31 // Store generic cast config and create packetizer config. | 29 weak_factory_(this) { |
32 if (is_audio) { | 30 // Randomly set sequence number start value. |
33 storage_.reset( | |
34 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | |
35 config_.audio = true; | |
36 config_.ssrc = config.audio_ssrc; | |
37 config_.payload_type = config.audio_rtp_config.payload_type; | |
38 config_.frequency = config.audio_frequency; | |
39 config_.audio_codec = config.audio_codec; | |
40 } else { | |
41 storage_.reset( | |
42 new PacketStorage(clock, config.audio_rtp_config.history_ms)); | |
43 config_.audio = false; | |
44 config_.ssrc = config.video_ssrc; | |
45 config_.payload_type = config.video_rtp_config.payload_type; | |
46 config_.frequency = kVideoFrequency; | |
47 config_.video_codec = config.video_codec; | |
48 } | |
49 // Randomly set start values. | |
50 config_.sequence_number = base::RandInt(0, 65535); | 31 config_.sequence_number = base::RandInt(0, 65535); |
51 packetizer_.reset( | |
52 new RtpPacketizer(transport, storage_.get(), config_)); | |
53 } | 32 } |
54 | 33 |
55 RtpSender::~RtpSender() {} | 34 RtpSender::~RtpSender() {} |
56 | 35 |
| 36 void RtpSender::InitializeAudio(const CastTransportAudioConfig& config) { |
| 37 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); |
| 38 config_.audio = true; |
| 39 config_.ssrc = config.base.ssrc; |
| 40 config_.payload_type = config.base.rtp_config.payload_type; |
| 41 config_.frequency = config.frequency; |
| 42 config_.audio_codec = config.codec; |
| 43 packetizer_.reset(new RtpPacketizer(transport_, storage_.get(), config_)); |
| 44 } |
| 45 |
| 46 void RtpSender::InitializeVideo(const CastTransportVideoConfig& config) { |
| 47 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); |
| 48 config_.audio = false; |
| 49 config_.ssrc = config.base.ssrc; |
| 50 config_.payload_type = config.base.rtp_config.payload_type; |
| 51 config_.frequency = kVideoFrequency; |
| 52 config_.video_codec = config.codec; |
| 53 packetizer_.reset(new RtpPacketizer(transport_, storage_.get(), config_)); |
| 54 } |
| 55 |
57 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, | 56 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, |
58 const base::TimeTicks& capture_time) { | 57 const base::TimeTicks& capture_time) { |
| 58 DCHECK(packetizer_); |
59 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); | 59 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); |
60 } | 60 } |
61 | 61 |
62 void RtpSender::IncomingEncodedAudioFrame( | 62 void RtpSender::IncomingEncodedAudioFrame( |
63 const EncodedAudioFrame* audio_frame, | 63 const EncodedAudioFrame* audio_frame, |
64 const base::TimeTicks& recorded_time) { | 64 const base::TimeTicks& recorded_time) { |
| 65 DCHECK(packetizer_); |
65 packetizer_->IncomingEncodedAudioFrame(audio_frame, recorded_time); | 66 packetizer_->IncomingEncodedAudioFrame(audio_frame, recorded_time); |
66 } | 67 } |
67 | 68 |
68 void RtpSender::ResendPackets( | 69 void RtpSender::ResendPackets( |
69 const MissingFramesAndPacketsMap& missing_frames_and_packets) { | 70 const MissingFramesAndPacketsMap& missing_frames_and_packets) { |
| 71 DCHECK(storage_); |
70 // Iterate over all frames in the list. | 72 // Iterate over all frames in the list. |
71 for (MissingFramesAndPacketsMap::const_iterator it = | 73 for (MissingFramesAndPacketsMap::const_iterator it = |
72 missing_frames_and_packets.begin(); | 74 missing_frames_and_packets.begin(); |
73 it != missing_frames_and_packets.end(); | 75 it != missing_frames_and_packets.end(); |
74 ++it) { | 76 ++it) { |
75 PacketList packets_to_resend; | 77 PacketList packets_to_resend; |
76 uint8 frame_id = it->first; | 78 uint8 frame_id = it->first; |
77 const PacketIdSet& packets_set = it->second; | 79 const PacketIdSet& packets_set = it->second; |
78 bool success = false; | 80 bool success = false; |
79 | 81 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 128 |
127 void RtpSender::SubscribeRtpStatsCallback( | 129 void RtpSender::SubscribeRtpStatsCallback( |
128 const CastTransportRtpStatistics& callback) { | 130 const CastTransportRtpStatistics& callback) { |
129 stats_callback_ = callback; | 131 stats_callback_ = callback; |
130 ScheduleNextStatsReport(); | 132 ScheduleNextStatsReport(); |
131 } | 133 } |
132 | 134 |
133 void RtpSender::ScheduleNextStatsReport() { | 135 void RtpSender::ScheduleNextStatsReport() { |
134 transport_task_runner_->PostDelayedTask( | 136 transport_task_runner_->PostDelayedTask( |
135 FROM_HERE, | 137 FROM_HERE, |
136 base::Bind(&RtpSender::RtpStatistics, base::AsWeakPtr(this)), | 138 base::Bind(&RtpSender::RtpStatistics, weak_factory_.GetWeakPtr()), |
137 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); | 139 base::TimeDelta::FromMilliseconds(kStatsCallbackIntervalMs)); |
138 } | 140 } |
139 | 141 |
140 void RtpSender::RtpStatistics() { | 142 void RtpSender::RtpStatistics() { |
141 RtcpSenderInfo sender_info; | 143 RtcpSenderInfo sender_info; |
142 base::TimeTicks time_sent; | 144 base::TimeTicks time_sent; |
143 uint32 rtp_timestamp = 0; | 145 uint32 rtp_timestamp = 0; |
144 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); | 146 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); |
145 sender_info.send_packet_count = packetizer_->send_packets_count(); | 147 sender_info.send_packet_count = packetizer_->send_packets_count(); |
146 sender_info.send_octet_count = packetizer_->send_octet_count(); | 148 sender_info.send_octet_count = packetizer_->send_octet_count(); |
147 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); | 149 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); |
148 ScheduleNextStatsReport(); | 150 ScheduleNextStatsReport(); |
149 } | 151 } |
150 | 152 |
151 } // namespace transport | 153 } // namespace transport |
152 } // namespace cast | 154 } // namespace cast |
153 } // namespace media | 155 } // namespace media |
OLD | NEW |