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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
105 std::string* decoded_data = decoded_packet->add_data(); | 105 std::string* decoded_data = decoded_packet->add_data(); |
106 decoded_data->resize(packet->data_size() * max_frame_bytes); | 106 decoded_data->resize(packet->data_size() * max_frame_bytes); |
107 int buffer_pos = 0; | 107 int buffer_pos = 0; |
108 | 108 |
109 for (int i = 0; i < packet->data_size(); ++i) { | 109 for (int i = 0; i < packet->data_size(); ++i) { |
110 int16_t* pcm_buffer = | 110 int16_t* pcm_buffer = reinterpret_cast<int16_t*>( |
111 reinterpret_cast<int16_t*>(string_as_array(decoded_data) + buffer_pos); | 111 base::string_as_array(decoded_data) + buffer_pos); |
112 CHECK_LE(buffer_pos + max_frame_bytes, | 112 CHECK_LE(buffer_pos + max_frame_bytes, |
113 static_cast<int>(decoded_data->size())); | 113 static_cast<int>(decoded_data->size())); |
114 std::string* frame = packet->mutable_data(i); | 114 std::string* frame = packet->mutable_data(i); |
115 unsigned char* frame_data = | 115 unsigned char* frame_data = |
116 reinterpret_cast<unsigned char*>(string_as_array(frame)); | 116 reinterpret_cast<unsigned char*>(base::string_as_array(frame)); |
117 int result = opus_decode(decoder_, frame_data, frame->size(), | 117 int result = opus_decode(decoder_, frame_data, frame->size(), |
118 pcm_buffer, max_frame_samples, 0); | 118 pcm_buffer, max_frame_samples, 0); |
119 if (result < 0) { | 119 if (result < 0) { |
120 LOG(ERROR) << "Failed decoding Opus frame. Error code: " << result; | 120 LOG(ERROR) << "Failed decoding Opus frame. Error code: " << result; |
121 DestroyDecoder(); | 121 DestroyDecoder(); |
122 return nullptr; | 122 return nullptr; |
123 } | 123 } |
124 | 124 |
125 buffer_pos += result * packet->channels() * | 125 buffer_pos += result * packet->channels() * |
126 decoded_packet->bytes_per_sample(); | 126 decoded_packet->bytes_per_sample(); |
127 } | 127 } |
128 | 128 |
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 |