| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "services/media/framework/formatting.h" | 6 #include "services/media/framework/formatting.h" |
| 7 #include "services/media/framework/lpcm_util.h" | 7 #include "services/media/framework/lpcm_util.h" |
| 8 | 8 |
| 9 namespace mojo { | 9 namespace mojo { |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 // LpcmUtil implementation that processes samples of type T. | 12 // LpcmUtil implementation that processes samples of type T. |
| 13 template <typename T> | 13 template <typename T> |
| 14 class LpcmUtilImpl : public LpcmUtil { | 14 class LpcmUtilImpl : public LpcmUtil { |
| 15 public: | 15 public: |
| 16 ~LpcmUtilImpl(); | 16 ~LpcmUtilImpl(); |
| 17 | 17 |
| 18 void Silence(void* buffer, size_t frame_count) const override; | 18 void Silence(void* buffer, size_t frame_count) const override; |
| 19 | 19 |
| 20 void Copy(const void* in, void* out, size_t frame_count) const override; | 20 void Copy(const void* in, void* out, size_t frame_count) const override; |
| 21 | 21 |
| 22 void Mix(const void* in, void* out, size_t frame_count) const override; | 22 void Mix(const void* in, void* out, size_t frame_count) const override; |
| 23 | 23 |
| 24 void Interleave(const void* in, | 24 void Interleave(const void* in, |
| 25 size_t in_byte_count, | 25 size_t in_byte_count, |
| 26 void* out, | 26 void* out, |
| 27 size_t frame_count) const override; | 27 size_t frame_count) const override; |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 LpcmUtilImpl(const LpcmStreamType& stream_type); | 30 LpcmUtilImpl(const AudioStreamType& stream_type); |
| 31 | 31 |
| 32 LpcmStreamType stream_type_; | 32 AudioStreamType stream_type_; |
| 33 | 33 |
| 34 friend class LpcmUtil; | 34 friend class LpcmUtil; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 std::unique_ptr<LpcmUtil> LpcmUtil::Create(const LpcmStreamType& stream_type) { | 37 std::unique_ptr<LpcmUtil> LpcmUtil::Create(const AudioStreamType& stream_type) { |
| 38 LpcmUtil* result; | 38 LpcmUtil* result; |
| 39 switch (stream_type.sample_format()) { | 39 switch (stream_type.sample_format()) { |
| 40 case LpcmStreamType::SampleFormat::kUnsigned8: | 40 case AudioStreamType::SampleFormat::kUnsigned8: |
| 41 case LpcmStreamType::SampleFormat::kAny: | |
| 42 result = new LpcmUtilImpl<uint8_t>(stream_type); | 41 result = new LpcmUtilImpl<uint8_t>(stream_type); |
| 43 break; | 42 break; |
| 44 case LpcmStreamType::SampleFormat::kSigned16: | 43 case AudioStreamType::SampleFormat::kSigned16: |
| 45 result = new LpcmUtilImpl<int16_t>(stream_type); | 44 result = new LpcmUtilImpl<int16_t>(stream_type); |
| 46 break; | 45 break; |
| 47 case LpcmStreamType::SampleFormat::kSigned24In32: | 46 case AudioStreamType::SampleFormat::kSigned24In32: |
| 48 result = new LpcmUtilImpl<int32_t>(stream_type); | 47 result = new LpcmUtilImpl<int32_t>(stream_type); |
| 49 break; | 48 break; |
| 50 case LpcmStreamType::SampleFormat::kFloat: | 49 case AudioStreamType::SampleFormat::kFloat: |
| 51 result = new LpcmUtilImpl<float>(stream_type); | 50 result = new LpcmUtilImpl<float>(stream_type); |
| 52 break; | 51 break; |
| 53 default: | 52 default: |
| 54 NOTREACHED() << "unsupported sample format " | 53 NOTREACHED() << "unsupported sample format " |
| 55 << stream_type.sample_format(); | 54 << stream_type.sample_format(); |
| 56 result = nullptr; | 55 result = nullptr; |
| 57 break; | 56 break; |
| 58 } | 57 } |
| 59 | 58 |
| 60 return std::unique_ptr<LpcmUtil>(result); | 59 return std::unique_ptr<LpcmUtil>(result); |
| 61 } | 60 } |
| 62 | 61 |
| 63 template <typename T> | 62 template <typename T> |
| 64 LpcmUtilImpl<T>::LpcmUtilImpl(const LpcmStreamType& stream_type) | 63 LpcmUtilImpl<T>::LpcmUtilImpl(const AudioStreamType& stream_type) |
| 65 : stream_type_(stream_type) {} | 64 : stream_type_(stream_type) {} |
| 66 | 65 |
| 67 template <typename T> | 66 template <typename T> |
| 68 LpcmUtilImpl<T>::~LpcmUtilImpl() {} | 67 LpcmUtilImpl<T>::~LpcmUtilImpl() {} |
| 69 | 68 |
| 70 template <typename T> | 69 template <typename T> |
| 71 void LpcmUtilImpl<T>::Silence(void* buffer, size_t frame_count) const { | 70 void LpcmUtilImpl<T>::Silence(void* buffer, size_t frame_count) const { |
| 72 T* sample = reinterpret_cast<T*>(buffer); | 71 T* sample = reinterpret_cast<T*>(buffer); |
| 73 for (size_t sample_countdown = frame_count * stream_type_.channels(); | 72 for (size_t sample_countdown = frame_count * stream_type_.channels(); |
| 74 sample_countdown != 0; --sample_countdown) { | 73 sample_countdown != 0; --sample_countdown) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ++in_sample; | 152 ++in_sample; |
| 154 out_sample += channels; | 153 out_sample += channels; |
| 155 } | 154 } |
| 156 in_channel += in_channel_stride; | 155 in_channel += in_channel_stride; |
| 157 ++out_channel; | 156 ++out_channel; |
| 158 } | 157 } |
| 159 } | 158 } |
| 160 | 159 |
| 161 } // namespace media | 160 } // namespace media |
| 162 } // namespace mojo | 161 } // namespace mojo |
| OLD | NEW |