| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "media/cast/audio_receiver/audio_decoder.h" | 6 #include "media/cast/audio_receiver/audio_decoder.h" |
| 7 | 7 |
| 8 #include "third_party/webrtc/modules/audio_coding/main/interface/audio_coding_mo
dule.h" | 8 #include "third_party/webrtc/modules/audio_coding/main/interface/audio_coding_mo
dule.h" |
| 9 #include "third_party/webrtc/modules/interface/module_common_types.h" | 9 #include "third_party/webrtc/modules/interface/module_common_types.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 audio_decoder_->SetMaximumPlayoutDelay(audio_config.rtp_max_delay_ms); | 45 audio_decoder_->SetMaximumPlayoutDelay(audio_config.rtp_max_delay_ms); |
| 46 audio_decoder_->SetPlayoutMode(webrtc::streaming); | 46 audio_decoder_->SetPlayoutMode(webrtc::streaming); |
| 47 } | 47 } |
| 48 | 48 |
| 49 AudioDecoder::~AudioDecoder() {} | 49 AudioDecoder::~AudioDecoder() {} |
| 50 | 50 |
| 51 bool AudioDecoder::GetRawAudioFrame(int number_of_10ms_blocks, | 51 bool AudioDecoder::GetRawAudioFrame(int number_of_10ms_blocks, |
| 52 int desired_frequency, | 52 int desired_frequency, |
| 53 PcmAudioFrame* audio_frame, | 53 PcmAudioFrame* audio_frame, |
| 54 uint32* rtp_timestamp) { | 54 uint32* rtp_timestamp) { |
| 55 if (!have_received_packets_) return false; | 55 // We don't care about the race case where a packet arrives at the same time |
| 56 // as this function in called. The data will be there the next time this |
| 57 // function is called. |
| 58 lock_.Acquire(); |
| 59 // Get a local copy under lock. |
| 60 bool have_received_packets = have_received_packets_; |
| 61 lock_.Release(); |
| 62 |
| 63 if (!have_received_packets) return false; |
| 56 | 64 |
| 57 audio_frame->samples.clear(); | 65 audio_frame->samples.clear(); |
| 58 | 66 |
| 59 for (int i = 0; i < number_of_10ms_blocks; ++i) { | 67 for (int i = 0; i < number_of_10ms_blocks; ++i) { |
| 60 webrtc::AudioFrame webrtc_audio_frame; | 68 webrtc::AudioFrame webrtc_audio_frame; |
| 61 if (0 != audio_decoder_->PlayoutData10Ms(desired_frequency, | 69 if (0 != audio_decoder_->PlayoutData10Ms(desired_frequency, |
| 62 &webrtc_audio_frame)) { | 70 &webrtc_audio_frame)) { |
| 63 return false; | 71 return false; |
| 64 } | 72 } |
| 65 if (webrtc_audio_frame.speech_type_ == webrtc::AudioFrame::kPLCCNG || | 73 if (webrtc_audio_frame.speech_type_ == webrtc::AudioFrame::kPLCCNG || |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 } | 93 } |
| 86 return true; | 94 return true; |
| 87 } | 95 } |
| 88 | 96 |
| 89 void AudioDecoder::IncomingParsedRtpPacket(const uint8* payload_data, | 97 void AudioDecoder::IncomingParsedRtpPacket(const uint8* payload_data, |
| 90 size_t payload_size, | 98 size_t payload_size, |
| 91 const RtpCastHeader& rtp_header) { | 99 const RtpCastHeader& rtp_header) { |
| 92 DCHECK_LE(payload_size, kIpPacketSize); | 100 DCHECK_LE(payload_size, kIpPacketSize); |
| 93 audio_decoder_->IncomingPacket(payload_data, static_cast<int32>(payload_size), | 101 audio_decoder_->IncomingPacket(payload_data, static_cast<int32>(payload_size), |
| 94 rtp_header.webrtc); | 102 rtp_header.webrtc); |
| 103 |
| 104 lock_.Acquire(); |
| 95 have_received_packets_ = true; | 105 have_received_packets_ = true; |
| 106 lock_.Release(); |
| 96 } | 107 } |
| 97 | 108 |
| 98 } // namespace cast | 109 } // namespace cast |
| 99 } // namespace media | 110 } // namespace media |
| OLD | NEW |