Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: media/cast/audio_sender/audio_sender.cc

Issue 281453003: Cast: Simplify code path for RTCP sender report (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/audio_sender/audio_sender.h" 5 #include "media/cast/audio_sender/audio_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "media/cast/audio_sender/audio_encoder.h" 10 #include "media/cast/audio_sender/audio_encoder.h"
(...skipping 23 matching lines...) Expand all
34 34
35 DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtcpAudioSenderFeedback); 35 DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtcpAudioSenderFeedback);
36 }; 36 };
37 37
38 // TODO(mikhal): Reduce heap allocation when not needed. 38 // TODO(mikhal): Reduce heap allocation when not needed.
39 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, 39 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
40 const AudioSenderConfig& audio_config, 40 const AudioSenderConfig& audio_config,
41 transport::CastTransportSender* const transport_sender) 41 transport::CastTransportSender* const transport_sender)
42 : cast_environment_(cast_environment), 42 : cast_environment_(cast_environment),
43 transport_sender_(transport_sender), 43 transport_sender_(transport_sender),
44 rtp_stats_(audio_config.frequency), 44 rtp_timestamp_helper_(audio_config.frequency),
45 rtcp_feedback_(new LocalRtcpAudioSenderFeedback(this)), 45 rtcp_feedback_(new LocalRtcpAudioSenderFeedback(this)),
46 rtcp_(cast_environment, 46 rtcp_(cast_environment,
47 rtcp_feedback_.get(), 47 rtcp_feedback_.get(),
48 transport_sender_, 48 transport_sender_,
49 NULL, // paced sender. 49 NULL, // paced sender.
50 NULL, 50 NULL,
51 audio_config.rtcp_mode, 51 audio_config.rtcp_mode,
52 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), 52 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval),
53 audio_config.rtp_config.ssrc, 53 audio_config.rtp_config.ssrc,
54 audio_config.incoming_feedback_ssrc, 54 audio_config.incoming_feedback_ssrc,
(...skipping 13 matching lines...) Expand all
68 } 68 }
69 69
70 media::cast::transport::CastTransportAudioConfig transport_config; 70 media::cast::transport::CastTransportAudioConfig transport_config;
71 transport_config.codec = audio_config.codec; 71 transport_config.codec = audio_config.codec;
72 transport_config.rtp.config = audio_config.rtp_config; 72 transport_config.rtp.config = audio_config.rtp_config;
73 transport_config.frequency = audio_config.frequency; 73 transport_config.frequency = audio_config.frequency;
74 transport_config.channels = audio_config.channels; 74 transport_config.channels = audio_config.channels;
75 transport_config.rtp.max_outstanding_frames = 75 transport_config.rtp.max_outstanding_frames =
76 audio_config.rtp_config.max_delay_ms / 100 + 1; 76 audio_config.rtp_config.max_delay_ms / 100 + 1;
77 transport_sender_->InitializeAudio(transport_config); 77 transport_sender_->InitializeAudio(transport_config);
78
79 transport_sender_->SubscribeAudioRtpStatsCallback(
80 base::Bind(&AudioSender::StoreStatistics, weak_factory_.GetWeakPtr()));
81 } 78 }
82 79
83 AudioSender::~AudioSender() {} 80 AudioSender::~AudioSender() {}
84 81
85 void AudioSender::InitializeTimers() { 82 void AudioSender::InitializeTimers() {
86 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 83 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
87 if (!timers_initialized_) { 84 if (!timers_initialized_) {
88 timers_initialized_ = true; 85 timers_initialized_ = true;
89 ScheduleNextRtcpReport(); 86 ScheduleNextRtcpReport();
90 } 87 }
91 } 88 }
92 89
93 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, 90 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus,
94 const base::TimeTicks& recorded_time) { 91 const base::TimeTicks& recorded_time) {
95 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 92 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
96 DCHECK(audio_encoder_.get()) << "Invalid internal state"; 93 DCHECK(audio_encoder_.get()) << "Invalid internal state";
97 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); 94 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time);
98 } 95 }
99 96
100 void AudioSender::SendEncodedAudioFrame( 97 void AudioSender::SendEncodedAudioFrame(
101 scoped_ptr<transport::EncodedAudioFrame> audio_frame, 98 scoped_ptr<transport::EncodedAudioFrame> audio_frame,
102 const base::TimeTicks& recorded_time) { 99 const base::TimeTicks& recorded_time) {
103 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 100 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
101 rtp_timestamp_helper_.StoreLatestTime(recorded_time,
102 audio_frame->rtp_timestamp);
104 InitializeTimers(); 103 InitializeTimers();
105 transport_sender_->InsertCodedAudioFrame(audio_frame.get(), recorded_time); 104 transport_sender_->InsertCodedAudioFrame(audio_frame.get(), recorded_time);
106 } 105 }
107 106
108 void AudioSender::ResendPackets( 107 void AudioSender::ResendPackets(
109 const MissingFramesAndPacketsMap& missing_frames_and_packets) { 108 const MissingFramesAndPacketsMap& missing_frames_and_packets) {
110 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 109 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
111 transport_sender_->ResendPackets(true, missing_frames_and_packets); 110 transport_sender_->ResendPackets(true, missing_frames_and_packets);
112 } 111 }
113 112
(...skipping 10 matching lines...) Expand all
124 time_to_next = std::max( 123 time_to_next = std::max(
125 time_to_next, base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); 124 time_to_next, base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs));
126 125
127 cast_environment_->PostDelayedTask( 126 cast_environment_->PostDelayedTask(
128 CastEnvironment::MAIN, 127 CastEnvironment::MAIN,
129 FROM_HERE, 128 FROM_HERE,
130 base::Bind(&AudioSender::SendRtcpReport, weak_factory_.GetWeakPtr()), 129 base::Bind(&AudioSender::SendRtcpReport, weak_factory_.GetWeakPtr()),
131 time_to_next); 130 time_to_next);
132 } 131 }
133 132
134 void AudioSender::StoreStatistics(
135 const transport::RtcpSenderInfo& sender_info,
136 base::TimeTicks time_sent,
137 uint32 rtp_timestamp) {
138 rtp_stats_.Store(sender_info, time_sent, rtp_timestamp);
139 }
140
141 void AudioSender::SendRtcpReport() { 133 void AudioSender::SendRtcpReport() {
142 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 134 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
143 // We don't send audio logging messages since all captured audio frames will 135 const base::TimeTicks now = cast_environment_->Clock()->NowTicks();
144 // be sent. 136 uint32 now_as_rtp_timestamp = 0;
145 rtp_stats_.UpdateInfo(cast_environment_->Clock()->NowTicks()); 137 if (rtp_timestamp_helper_.GetCurrentTimeAsRtpTimestamp(
146 rtcp_.SendRtcpFromRtpSender(rtp_stats_.sender_info()); 138 now, &now_as_rtp_timestamp)) {
139 rtcp_.SendRtcpFromRtpSender(now, now_as_rtp_timestamp);
140 }
147 ScheduleNextRtcpReport(); 141 ScheduleNextRtcpReport();
148 } 142 }
149 143
150 } // namespace cast 144 } // namespace cast
151 } // namespace media 145 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698