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> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
10 #include "remoting/proto/audio.pb.h" | 12 #include "remoting/proto/audio.pb.h" |
11 #include "third_party/opus/src/include/opus.h" | 13 #include "third_party/opus/src/include/opus.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 int max_frame_samples = kMaxFrameSizeMs * kSamplingRate / | 101 int max_frame_samples = kMaxFrameSizeMs * kSamplingRate / |
100 base::Time::kMillisecondsPerSecond; | 102 base::Time::kMillisecondsPerSecond; |
101 int max_frame_bytes = max_frame_samples * channels_ * | 103 int max_frame_bytes = max_frame_samples * channels_ * |
102 decoded_packet->bytes_per_sample(); | 104 decoded_packet->bytes_per_sample(); |
103 | 105 |
104 std::string* decoded_data = decoded_packet->add_data(); | 106 std::string* decoded_data = decoded_packet->add_data(); |
105 decoded_data->resize(packet->data_size() * max_frame_bytes); | 107 decoded_data->resize(packet->data_size() * max_frame_bytes); |
106 int buffer_pos = 0; | 108 int buffer_pos = 0; |
107 | 109 |
108 for (int i = 0; i < packet->data_size(); ++i) { | 110 for (int i = 0; i < packet->data_size(); ++i) { |
109 int16* pcm_buffer = | 111 int16_t* pcm_buffer = |
110 reinterpret_cast<int16*>(string_as_array(decoded_data) + buffer_pos); | 112 reinterpret_cast<int16_t*>(string_as_array(decoded_data) + buffer_pos); |
111 CHECK_LE(buffer_pos + max_frame_bytes, | 113 CHECK_LE(buffer_pos + max_frame_bytes, |
112 static_cast<int>(decoded_data->size())); | 114 static_cast<int>(decoded_data->size())); |
113 std::string* frame = packet->mutable_data(i); | 115 std::string* frame = packet->mutable_data(i); |
114 unsigned char* frame_data = | 116 unsigned char* frame_data = |
115 reinterpret_cast<unsigned char*>(string_as_array(frame)); | 117 reinterpret_cast<unsigned char*>(string_as_array(frame)); |
116 int result = opus_decode(decoder_, frame_data, frame->size(), | 118 int result = opus_decode(decoder_, frame_data, frame->size(), |
117 pcm_buffer, max_frame_samples, 0); | 119 pcm_buffer, max_frame_samples, 0); |
118 if (result < 0) { | 120 if (result < 0) { |
119 LOG(ERROR) << "Failed decoding Opus frame. Error code: " << result; | 121 LOG(ERROR) << "Failed decoding Opus frame. Error code: " << result; |
120 DestroyDecoder(); | 122 DestroyDecoder(); |
121 return nullptr; | 123 return nullptr; |
122 } | 124 } |
123 | 125 |
124 buffer_pos += result * packet->channels() * | 126 buffer_pos += result * packet->channels() * |
125 decoded_packet->bytes_per_sample(); | 127 decoded_packet->bytes_per_sample(); |
126 } | 128 } |
127 | 129 |
128 if (!buffer_pos) { | 130 if (!buffer_pos) { |
129 return nullptr; | 131 return nullptr; |
130 } | 132 } |
131 | 133 |
132 decoded_data->resize(buffer_pos); | 134 decoded_data->resize(buffer_pos); |
133 | 135 |
134 return decoded_packet.Pass(); | 136 return decoded_packet.Pass(); |
135 } | 137 } |
136 | 138 |
137 } // namespace remoting | 139 } // namespace remoting |
OLD | NEW |