| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/media/audio_track_recorder.h" | 5 #include "content/renderer/media/audio_track_recorder.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" |
| 8 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 9 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
| 10 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
| 11 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 12 #include "third_party/opus/src/include/opus.h" | 15 #include "third_party/opus/src/include/opus.h" |
| 13 | 16 |
| 14 // Note that this code follows the Chrome media convention of defining a "frame" | 17 // Note that this code follows the Chrome media convention of defining a "frame" |
| 15 // as "one multi-channel sample" as opposed to another common definition | 18 // as "one multi-channel sample" as opposed to another common definition |
| 16 // meaning "a chunk of samples". Here this second definition of "frame" is | 19 // meaning "a chunk of samples". Here this second definition of "frame" is |
| 17 // called a "buffer"; so what might be called "frame duration" is instead | 20 // called a "buffer"; so what might be called "frame duration" is instead |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 226 } |
| 224 | 227 |
| 225 bool AudioTrackRecorder::AudioEncoder::EncodeFromFilledBuffer( | 228 bool AudioTrackRecorder::AudioEncoder::EncodeFromFilledBuffer( |
| 226 std::string* out) { | 229 std::string* out) { |
| 227 DCHECK(encoder_thread_checker_.CalledOnValidThread()); | 230 DCHECK(encoder_thread_checker_.CalledOnValidThread()); |
| 228 DCHECK(is_initialized()); | 231 DCHECK(is_initialized()); |
| 229 | 232 |
| 230 out->resize(OPUS_MAX_PAYLOAD_SIZE); | 233 out->resize(OPUS_MAX_PAYLOAD_SIZE); |
| 231 const opus_int32 result = opus_encode_float( | 234 const opus_int32 result = opus_encode_float( |
| 232 opus_encoder_, buffer_.get(), frames_per_buffer_, | 235 opus_encoder_, buffer_.get(), frames_per_buffer_, |
| 233 reinterpret_cast<uint8*>(string_as_array(out)), OPUS_MAX_PAYLOAD_SIZE); | 236 reinterpret_cast<uint8_t*>(string_as_array(out)), OPUS_MAX_PAYLOAD_SIZE); |
| 234 if (result > 1) { | 237 if (result > 1) { |
| 235 // TODO(ajose): Investigate improving this. http://crbug.com/547918 | 238 // TODO(ajose): Investigate improving this. http://crbug.com/547918 |
| 236 out->resize(result); | 239 out->resize(result); |
| 237 return true; | 240 return true; |
| 238 } | 241 } |
| 239 // If |result| in {0,1}, do nothing; the documentation says that a return | 242 // If |result| in {0,1}, do nothing; the documentation says that a return |
| 240 // value of zero or one means the packet does not need to be transmitted. | 243 // value of zero or one means the packet does not need to be transmitted. |
| 241 // Otherwise, we have an error. | 244 // Otherwise, we have an error. |
| 242 DLOG_IF(ERROR, result < 0) << __FUNCTION__ | 245 DLOG_IF(ERROR, result < 0) << __FUNCTION__ |
| 243 << " failed: " << opus_strerror(result); | 246 << " failed: " << opus_strerror(result); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 if (sample_rate * possible_duration % 1000 == 0) { | 308 if (sample_rate * possible_duration % 1000 == 0) { |
| 306 return possible_duration; | 309 return possible_duration; |
| 307 } | 310 } |
| 308 } | 311 } |
| 309 | 312 |
| 310 // Otherwise, couldn't find a good duration. | 313 // Otherwise, couldn't find a good duration. |
| 311 return 0; | 314 return 0; |
| 312 } | 315 } |
| 313 | 316 |
| 314 } // namespace content | 317 } // namespace content |
| OLD | NEW |