| 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/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 17 matching lines...) Expand all Loading... |
| 28 transport_sender_, | 28 transport_sender_, |
| 29 NULL, // paced sender. | 29 NULL, // paced sender. |
| 30 NULL, | 30 NULL, |
| 31 audio_config.rtcp_mode, | 31 audio_config.rtcp_mode, |
| 32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), | 32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), |
| 33 audio_config.rtp_config.ssrc, | 33 audio_config.rtp_config.ssrc, |
| 34 audio_config.incoming_feedback_ssrc, | 34 audio_config.incoming_feedback_ssrc, |
| 35 audio_config.rtcp_c_name, | 35 audio_config.rtcp_c_name, |
| 36 true), | 36 true), |
| 37 num_aggressive_rtcp_reports_sent_(0), | 37 num_aggressive_rtcp_reports_sent_(0), |
| 38 cast_initialization_cb_(STATUS_AUDIO_UNINITIALIZED), | 38 cast_initialization_status_(STATUS_AUDIO_UNINITIALIZED), |
| 39 weak_factory_(this) { | 39 weak_factory_(this) { |
| 40 rtcp_.SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize); | 40 rtcp_.SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize); |
| 41 if (!audio_config.use_external_encoder) { | 41 if (!audio_config.use_external_encoder) { |
| 42 audio_encoder_.reset( | 42 audio_encoder_.reset( |
| 43 new AudioEncoder(cast_environment, | 43 new AudioEncoder(cast_environment, |
| 44 audio_config, | 44 audio_config, |
| 45 base::Bind(&AudioSender::SendEncodedAudioFrame, | 45 base::Bind(&AudioSender::SendEncodedAudioFrame, |
| 46 weak_factory_.GetWeakPtr()))); | 46 weak_factory_.GetWeakPtr()))); |
| 47 cast_initialization_cb_ = audio_encoder_->InitializationResult(); | 47 cast_initialization_status_ = audio_encoder_->InitializationResult(); |
| 48 } else { |
| 49 NOTREACHED(); // No support for external audio encoding. |
| 50 cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; |
| 48 } | 51 } |
| 49 | 52 |
| 50 media::cast::transport::CastTransportAudioConfig transport_config; | 53 media::cast::transport::CastTransportAudioConfig transport_config; |
| 51 transport_config.codec = audio_config.codec; | 54 transport_config.codec = audio_config.codec; |
| 52 transport_config.rtp.config = audio_config.rtp_config; | 55 transport_config.rtp.config = audio_config.rtp_config; |
| 53 transport_config.frequency = audio_config.frequency; | 56 transport_config.frequency = audio_config.frequency; |
| 54 transport_config.channels = audio_config.channels; | 57 transport_config.channels = audio_config.channels; |
| 55 transport_config.rtp.max_outstanding_frames = | 58 transport_config.rtp.max_outstanding_frames = |
| 56 audio_config.rtp_config.max_delay_ms / 100 + 1; | 59 audio_config.rtp_config.max_delay_ms / 100 + 1; |
| 57 transport_sender_->InitializeAudio(transport_config); | 60 transport_sender_->InitializeAudio(transport_config); |
| 58 | 61 |
| 59 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_)); | 62 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_)); |
| 60 } | 63 } |
| 61 | 64 |
| 62 AudioSender::~AudioSender() {} | 65 AudioSender::~AudioSender() {} |
| 63 | 66 |
| 64 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, | 67 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
| 65 const base::TimeTicks& recorded_time) { | 68 const base::TimeTicks& recorded_time) { |
| 66 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 69 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 70 if (cast_initialization_status_ != STATUS_AUDIO_INITIALIZED) { |
| 71 NOTREACHED(); |
| 72 return; |
| 73 } |
| 67 DCHECK(audio_encoder_.get()) << "Invalid internal state"; | 74 DCHECK(audio_encoder_.get()) << "Invalid internal state"; |
| 68 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); | 75 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); |
| 69 } | 76 } |
| 70 | 77 |
| 71 void AudioSender::SendEncodedAudioFrame( | 78 void AudioSender::SendEncodedAudioFrame( |
| 72 scoped_ptr<transport::EncodedFrame> audio_frame) { | 79 scoped_ptr<transport::EncodedFrame> audio_frame) { |
| 73 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 80 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 81 |
| 74 DCHECK(!audio_frame->reference_time.is_null()); | 82 DCHECK(!audio_frame->reference_time.is_null()); |
| 75 rtp_timestamp_helper_.StoreLatestTime(audio_frame->reference_time, | 83 rtp_timestamp_helper_.StoreLatestTime(audio_frame->reference_time, |
| 76 audio_frame->rtp_timestamp); | 84 audio_frame->rtp_timestamp); |
| 77 | 85 |
| 78 // At the start of the session, it's important to send reports before each | 86 // At the start of the session, it's important to send reports before each |
| 79 // frame so that the receiver can properly compute playout times. The reason | 87 // frame so that the receiver can properly compute playout times. The reason |
| 80 // more than one report is sent is because transmission is not guaranteed, | 88 // more than one report is sent is because transmission is not guaranteed, |
| 81 // only best effort, so we send enough that one should almost certainly get | 89 // only best effort, so we send enough that one should almost certainly get |
| 82 // through. | 90 // through. |
| 83 if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) { | 91 if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 uint32 acked_frame_id = static_cast<uint32>(cast_feedback.ack_frame_id_); | 167 uint32 acked_frame_id = static_cast<uint32>(cast_feedback.ack_frame_id_); |
| 160 VLOG(2) << "Received audio ACK: " << acked_frame_id; | 168 VLOG(2) << "Received audio ACK: " << acked_frame_id; |
| 161 cast_environment_->Logging()->InsertFrameEvent( | 169 cast_environment_->Logging()->InsertFrameEvent( |
| 162 cast_environment_->Clock()->NowTicks(), | 170 cast_environment_->Clock()->NowTicks(), |
| 163 FRAME_ACK_RECEIVED, AUDIO_EVENT, | 171 FRAME_ACK_RECEIVED, AUDIO_EVENT, |
| 164 frame_id_to_rtp_timestamp_[acked_frame_id & 0xff], acked_frame_id); | 172 frame_id_to_rtp_timestamp_[acked_frame_id & 0xff], acked_frame_id); |
| 165 } | 173 } |
| 166 | 174 |
| 167 } // namespace cast | 175 } // namespace cast |
| 168 } // namespace media | 176 } // namespace media |
| OLD | NEW |