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 // Get a local copy under lock. |
Alpha Left Google
2013/11/22 20:03:53
Do you expect to have a race condition using the l
pwestin
2013/11/22 21:16:36
We don't care about the race where a thread ask fo
| |
56 lock_.Acquire(); | |
57 bool have_received_packets = have_received_packets_; | |
58 lock_.Release(); | |
59 | |
60 if (!have_received_packets) return false; | |
56 | 61 |
57 audio_frame->samples.clear(); | 62 audio_frame->samples.clear(); |
58 | 63 |
59 for (int i = 0; i < number_of_10ms_blocks; ++i) { | 64 for (int i = 0; i < number_of_10ms_blocks; ++i) { |
60 webrtc::AudioFrame webrtc_audio_frame; | 65 webrtc::AudioFrame webrtc_audio_frame; |
61 if (0 != audio_decoder_->PlayoutData10Ms(desired_frequency, | 66 if (0 != audio_decoder_->PlayoutData10Ms(desired_frequency, |
62 &webrtc_audio_frame)) { | 67 &webrtc_audio_frame)) { |
63 return false; | 68 return false; |
64 } | 69 } |
65 if (webrtc_audio_frame.speech_type_ == webrtc::AudioFrame::kPLCCNG || | 70 if (webrtc_audio_frame.speech_type_ == webrtc::AudioFrame::kPLCCNG || |
(...skipping 19 matching lines...) Expand all Loading... | |
85 } | 90 } |
86 return true; | 91 return true; |
87 } | 92 } |
88 | 93 |
89 void AudioDecoder::IncomingParsedRtpPacket(const uint8* payload_data, | 94 void AudioDecoder::IncomingParsedRtpPacket(const uint8* payload_data, |
90 size_t payload_size, | 95 size_t payload_size, |
91 const RtpCastHeader& rtp_header) { | 96 const RtpCastHeader& rtp_header) { |
92 DCHECK_LE(payload_size, kIpPacketSize); | 97 DCHECK_LE(payload_size, kIpPacketSize); |
93 audio_decoder_->IncomingPacket(payload_data, static_cast<int32>(payload_size), | 98 audio_decoder_->IncomingPacket(payload_data, static_cast<int32>(payload_size), |
94 rtp_header.webrtc); | 99 rtp_header.webrtc); |
100 | |
101 lock_.Acquire(); | |
95 have_received_packets_ = true; | 102 have_received_packets_ = true; |
103 lock_.Release(); | |
96 } | 104 } |
97 | 105 |
98 } // namespace cast | 106 } // namespace cast |
99 } // namespace media | 107 } // namespace media |
OLD | NEW |