| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/codec/audio_decoder_opus.h" | 5 #include "remoting/codec/audio_decoder_opus.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (!decoder_) { | 70 if (!decoder_) { |
| 71 InitDecoder(); | 71 InitDecoder(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 return decoder_ != nullptr; | 74 return decoder_ != nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 scoped_ptr<AudioPacket> AudioDecoderOpus::Decode( | 77 std::unique_ptr<AudioPacket> AudioDecoderOpus::Decode( |
| 78 scoped_ptr<AudioPacket> packet) { | 78 std::unique_ptr<AudioPacket> packet) { |
| 79 if (packet->encoding() != AudioPacket::ENCODING_OPUS) { | 79 if (packet->encoding() != AudioPacket::ENCODING_OPUS) { |
| 80 LOG(WARNING) << "Received an audio packet with encoding " | 80 LOG(WARNING) << "Received an audio packet with encoding " |
| 81 << packet->encoding() << " when an OPUS packet was expected."; | 81 << packet->encoding() << " when an OPUS packet was expected."; |
| 82 return nullptr; | 82 return nullptr; |
| 83 } | 83 } |
| 84 if (packet->data_size() > kMaxFramesPerPacket) { | 84 if (packet->data_size() > kMaxFramesPerPacket) { |
| 85 LOG(WARNING) << "Received an packet with too many frames."; | 85 LOG(WARNING) << "Received an packet with too many frames."; |
| 86 return nullptr; | 86 return nullptr; |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (!ResetForPacket(packet.get())) { | 89 if (!ResetForPacket(packet.get())) { |
| 90 return nullptr; | 90 return nullptr; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Create a new packet of decoded data. | 93 // Create a new packet of decoded data. |
| 94 scoped_ptr<AudioPacket> decoded_packet(new AudioPacket()); | 94 std::unique_ptr<AudioPacket> decoded_packet(new AudioPacket()); |
| 95 decoded_packet->set_encoding(AudioPacket::ENCODING_RAW); | 95 decoded_packet->set_encoding(AudioPacket::ENCODING_RAW); |
| 96 decoded_packet->set_sampling_rate(kSamplingRate); | 96 decoded_packet->set_sampling_rate(kSamplingRate); |
| 97 decoded_packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | 97 decoded_packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
| 98 decoded_packet->set_channels(packet->channels()); | 98 decoded_packet->set_channels(packet->channels()); |
| 99 | 99 |
| 100 int max_frame_samples = kMaxFrameSizeMs * kSamplingRate / | 100 int max_frame_samples = kMaxFrameSizeMs * kSamplingRate / |
| 101 base::Time::kMillisecondsPerSecond; | 101 base::Time::kMillisecondsPerSecond; |
| 102 int max_frame_bytes = max_frame_samples * channels_ * | 102 int max_frame_bytes = max_frame_samples * channels_ * |
| 103 decoded_packet->bytes_per_sample(); | 103 decoded_packet->bytes_per_sample(); |
| 104 | 104 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 129 if (!buffer_pos) { | 129 if (!buffer_pos) { |
| 130 return nullptr; | 130 return nullptr; |
| 131 } | 131 } |
| 132 | 132 |
| 133 decoded_data->resize(buffer_pos); | 133 decoded_data->resize(buffer_pos); |
| 134 | 134 |
| 135 return decoded_packet; | 135 return decoded_packet; |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace remoting | 138 } // namespace remoting |
| OLD | NEW |