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 LoggingImpl* logging, | |
24 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, |
25 PacedSender* const transport) | 24 PacedSender* const transport) |
26 : clock_(clock), | 25 : clock_(clock), |
27 logging_(logging), | |
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 weak_factory_(this) { | 29 weak_factory_(this) { |
32 // Randomly set sequence number start value. | 30 // Randomly set sequence number start value. |
33 config_.sequence_number = base::RandInt(0, 65535); | 31 config_.sequence_number = base::RandInt(0, 65535); |
34 } | 32 } |
35 | 33 |
36 RtpSender::~RtpSender() {} | 34 RtpSender::~RtpSender() {} |
37 | 35 |
38 void RtpSender::InitializeAudio(const CastTransportAudioConfig& config) { | 36 void RtpSender::InitializeAudio(const CastTransportAudioConfig& config) { |
39 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); | 37 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); |
40 config_.audio = true; | 38 config_.audio = true; |
41 config_.ssrc = config.base.ssrc; | 39 config_.ssrc = config.base.ssrc; |
42 config_.payload_type = config.base.rtp_config.payload_type; | 40 config_.payload_type = config.base.rtp_config.payload_type; |
43 config_.frequency = config.frequency; | 41 config_.frequency = config.frequency; |
44 config_.audio_codec = config.codec; | 42 config_.audio_codec = config.codec; |
45 packetizer_.reset( | 43 packetizer_.reset( |
46 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); | 44 new RtpPacketizer(transport_, storage_.get(), config_)); |
47 } | 45 } |
48 | 46 |
49 void RtpSender::InitializeVideo(const CastTransportVideoConfig& config) { | 47 void RtpSender::InitializeVideo(const CastTransportVideoConfig& config) { |
50 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); | 48 storage_.reset(new PacketStorage(clock_, config.base.rtp_config.history_ms)); |
51 config_.audio = false; | 49 config_.audio = false; |
52 config_.ssrc = config.base.ssrc; | 50 config_.ssrc = config.base.ssrc; |
53 config_.payload_type = config.base.rtp_config.payload_type; | 51 config_.payload_type = config.base.rtp_config.payload_type; |
54 config_.frequency = kVideoFrequency; | 52 config_.frequency = kVideoFrequency; |
55 config_.video_codec = config.codec; | 53 config_.video_codec = config.codec; |
56 packetizer_.reset( | 54 packetizer_.reset( |
57 new RtpPacketizer(transport_, storage_.get(), config_, clock_, logging_)); | 55 new RtpPacketizer(transport_, storage_.get(), config_)); |
58 } | 56 } |
59 | 57 |
60 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, | 58 void RtpSender::IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame, |
61 const base::TimeTicks& capture_time) { | 59 const base::TimeTicks& capture_time) { |
62 DCHECK(packetizer_); | 60 DCHECK(packetizer_); |
63 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); | 61 packetizer_->IncomingEncodedVideoFrame(video_frame, capture_time); |
64 } | 62 } |
65 | 63 |
66 void RtpSender::IncomingEncodedAudioFrame( | 64 void RtpSender::IncomingEncodedAudioFrame( |
67 const EncodedAudioFrame* audio_frame, | 65 const EncodedAudioFrame* audio_frame, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); | 148 packetizer_->LastSentTimestamp(&time_sent, &rtp_timestamp); |
151 sender_info.send_packet_count = packetizer_->send_packets_count(); | 149 sender_info.send_packet_count = packetizer_->send_packets_count(); |
152 sender_info.send_octet_count = packetizer_->send_octet_count(); | 150 sender_info.send_octet_count = packetizer_->send_octet_count(); |
153 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); | 151 stats_callback_.Run(sender_info, time_sent, rtp_timestamp); |
154 ScheduleNextStatsReport(); | 152 ScheduleNextStatsReport(); |
155 } | 153 } |
156 | 154 |
157 } // namespace transport | 155 } // namespace transport |
158 } // namespace cast | 156 } // namespace cast |
159 } // namespace media | 157 } // namespace media |
OLD | NEW |