OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/cast/sender/audio_encoder.h" | 5 #include "media/cast/sender/audio_encoder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 num_channels, | 356 num_channels, |
357 sampling_rate, | 357 sampling_rate, |
358 kAccessUnitSamples, | 358 kAccessUnitSamples, |
359 callback), | 359 callback), |
360 input_buffer_(AudioBus::Create(num_channels, kAccessUnitSamples)), | 360 input_buffer_(AudioBus::Create(num_channels, kAccessUnitSamples)), |
361 input_bus_(AudioBus::CreateWrapper(num_channels)), | 361 input_bus_(AudioBus::CreateWrapper(num_channels)), |
362 max_access_unit_size_(0), | 362 max_access_unit_size_(0), |
363 output_buffer_(nullptr), | 363 output_buffer_(nullptr), |
364 converter_(nullptr), | 364 converter_(nullptr), |
365 file_(nullptr), | 365 file_(nullptr), |
366 num_access_units_(0), | 366 num_access_units_(0) { |
367 can_resume_(true) { | |
368 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) { | 367 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) { |
369 return; | 368 return; |
370 } | 369 } |
371 if (!Initialize(sampling_rate, bitrate)) { | 370 if (!Initialize(sampling_rate, bitrate)) { |
372 ImplBase::operational_status_ = STATUS_INVALID_CONFIGURATION; | 371 ImplBase::operational_status_ = STATUS_INVALID_CONFIGURATION; |
373 return; | 372 return; |
374 } | 373 } |
375 ImplBase::operational_status_ = STATUS_INITIALIZED; | 374 ImplBase::operational_status_ = STATUS_INITIALIZED; |
376 } | 375 } |
377 | 376 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 // or compatible with the output sampling rate or channels). | 447 // or compatible with the output sampling rate or channels). |
449 if (bitrate > 0) { | 448 if (bitrate > 0) { |
450 prop_size = sizeof(int); | 449 prop_size = sizeof(int); |
451 if (AudioConverterSetProperty( | 450 if (AudioConverterSetProperty( |
452 converter_, kAudioConverterEncodeBitRate, prop_size, &bitrate) != | 451 converter_, kAudioConverterEncodeBitRate, prop_size, &bitrate) != |
453 noErr) { | 452 noErr) { |
454 return false; | 453 return false; |
455 } | 454 } |
456 } | 455 } |
457 | 456 |
458 #if defined(OS_IOS) | |
459 // See the comment next to |can_resume_| for details on resumption. Some | |
460 // converters can return kAudioConverterErr_PropertyNotSupported, in which | |
461 // case resumption is implicitly supported. This is the only location where | |
462 // the implementation modifies |can_resume_|. | |
463 uint32_t can_resume; | |
464 prop_size = sizeof(can_resume); | |
465 OSStatus oserr = AudioConverterGetProperty( | |
466 converter_, | |
467 kAudioConverterPropertyCanResumeFromInterruption, | |
468 &prop_size, | |
469 &can_resume); | |
470 if (oserr == noErr) { | |
471 const_cast<bool&>(can_resume_) = can_resume != 0; | |
Peter Kasting
2016/05/19 07:23:29
This member is never read, and the bug associated
hubbe
2016/05/19 17:21:41
Can you point me to the bug in question?
Peter Kasting
2016/05/19 18:10:18
It's the one referred to in the other deleted bloc
| |
472 } | |
473 #endif | |
474 | |
475 // Figure out the maximum size of an access unit that the encoder can | 457 // Figure out the maximum size of an access unit that the encoder can |
476 // produce. |mBytesPerPacket| will be 0 for variable size configurations, | 458 // produce. |mBytesPerPacket| will be 0 for variable size configurations, |
477 // in which case we must query the value. | 459 // in which case we must query the value. |
478 uint32_t max_access_unit_size = out_asbd.mBytesPerPacket; | 460 uint32_t max_access_unit_size = out_asbd.mBytesPerPacket; |
479 if (max_access_unit_size == 0) { | 461 if (max_access_unit_size == 0) { |
480 prop_size = sizeof(max_access_unit_size); | 462 prop_size = sizeof(max_access_unit_size); |
481 if (AudioConverterGetProperty( | 463 if (AudioConverterGetProperty( |
482 converter_, | 464 converter_, |
483 kAudioConverterPropertyMaximumOutputPacketSize, | 465 kAudioConverterPropertyMaximumOutputPacketSize, |
484 &prop_size, | 466 &prop_size, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 | 699 |
718 // The |AudioFile| is responsible for ADTS packetization. | 700 // The |AudioFile| is responsible for ADTS packetization. |
719 AudioFileID file_; | 701 AudioFileID file_; |
720 | 702 |
721 // An |AudioBufferList| passed to the converter to store encoded samples. | 703 // An |AudioBufferList| passed to the converter to store encoded samples. |
722 AudioBufferList converter_abl_; | 704 AudioBufferList converter_abl_; |
723 | 705 |
724 // The number of access units emitted so far by the encoder. | 706 // The number of access units emitted so far by the encoder. |
725 uint64_t num_access_units_; | 707 uint64_t num_access_units_; |
726 | 708 |
727 // On iOS, audio codecs can be interrupted by other services (such as an | |
728 // audio alert or phone call). Depending on the underlying hardware and | |
729 // configuration, the codec may have to be thrown away and re-initialized | |
730 // after such an interruption. This flag tracks if we can resume or not from | |
731 // such an interruption. It is initialized to true, which is the only possible | |
732 // value on OS X and on most modern iOS hardware. | |
733 // TODO(jfroy): Implement encoder re-initialization after interruption. | |
734 // https://crbug.com/424787 | |
735 const bool can_resume_; | |
736 | |
737 DISALLOW_COPY_AND_ASSIGN(AppleAacImpl); | 709 DISALLOW_COPY_AND_ASSIGN(AppleAacImpl); |
738 }; | 710 }; |
739 #endif // defined(OS_MACOSX) | 711 #endif // defined(OS_MACOSX) |
740 | 712 |
741 class AudioEncoder::Pcm16Impl : public AudioEncoder::ImplBase { | 713 class AudioEncoder::Pcm16Impl : public AudioEncoder::ImplBase { |
742 public: | 714 public: |
743 Pcm16Impl(const scoped_refptr<CastEnvironment>& cast_environment, | 715 Pcm16Impl(const scoped_refptr<CastEnvironment>& cast_environment, |
744 int num_channels, | 716 int num_channels, |
745 int sampling_rate, | 717 int sampling_rate, |
746 const FrameEncodedCallback& callback) | 718 const FrameEncodedCallback& callback) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 cast_environment_->PostTask(CastEnvironment::AUDIO, | 838 cast_environment_->PostTask(CastEnvironment::AUDIO, |
867 FROM_HERE, | 839 FROM_HERE, |
868 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 840 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |
869 impl_, | 841 impl_, |
870 base::Passed(&audio_bus), | 842 base::Passed(&audio_bus), |
871 recorded_time)); | 843 recorded_time)); |
872 } | 844 } |
873 | 845 |
874 } // namespace cast | 846 } // namespace cast |
875 } // namespace media | 847 } // namespace media |
OLD | NEW |