| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "mojo/services/media/common/cpp/linear_transform.h" | 6 #include "mojo/services/media/common/cpp/linear_transform.h" |
| 7 #include "services/media/audio/platform/generic/mixer.h" | 7 #include "services/media/audio/platform/generic/mixer.h" |
| 8 #include "services/media/audio/platform/generic/mixers/linear_sampler.h" | 8 #include "services/media/audio/platform/generic/mixers/linear_sampler.h" |
| 9 #include "services/media/audio/platform/generic/mixers/no_op.h" | 9 #include "services/media/audio/platform/generic/mixers/no_op.h" |
| 10 #include "services/media/audio/platform/generic/mixers/point_sampler.h" | 10 #include "services/media/audio/platform/generic/mixers/point_sampler.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 namespace media { | 13 namespace media { |
| 14 namespace audio { | 14 namespace audio { |
| 15 | 15 |
| 16 constexpr uint32_t Mixer::FRAC_ONE; | 16 constexpr uint32_t Mixer::FRAC_ONE; |
| 17 constexpr uint32_t Mixer::FRAC_MASK; | 17 constexpr uint32_t Mixer::FRAC_MASK; |
| 18 | 18 |
| 19 Mixer::~Mixer() {} | 19 Mixer::~Mixer() {} |
| 20 | 20 |
| 21 Mixer::Mixer(uint32_t pos_filter_width, | 21 Mixer::Mixer(uint32_t pos_filter_width, |
| 22 uint32_t neg_filter_width) | 22 uint32_t neg_filter_width) |
| 23 : pos_filter_width_(pos_filter_width), | 23 : pos_filter_width_(pos_filter_width), |
| 24 neg_filter_width_(neg_filter_width) { | 24 neg_filter_width_(neg_filter_width) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 MixerPtr Mixer::Select(const LpcmMediaTypeDetailsPtr& src_format, | 27 MixerPtr Mixer::Select(const LpcmMediaTypeDetailsPtr& src_format, |
| 28 const LpcmMediaTypeDetailsPtr& dst_format) { | 28 const LpcmMediaTypeDetailsPtr* optional_dst_format) { |
| 29 // We should always have a source format. | 29 // We should always have a source format. |
| 30 DCHECK(src_format); | 30 DCHECK(src_format); |
| 31 | 31 |
| 32 // If we don't have a destination format, just stick with no-op. This is | 32 // If we don't have a destination format, just stick with no-op. This is |
| 33 // probably the ThrottleOutput we are picking a mixer for. | 33 // probably the ThrottleOutput we are picking a mixer for. |
| 34 if (!dst_format) { return MixerPtr(new mixers::NoOp()); } | 34 if (!optional_dst_format) { return MixerPtr(new mixers::NoOp()); } |
| 35 |
| 36 const LpcmMediaTypeDetailsPtr& dst_format = *optional_dst_format; |
| 37 DCHECK(dst_format); |
| 35 | 38 |
| 36 // If the source sample rate is an integer multiple of the destination sample | 39 // If the source sample rate is an integer multiple of the destination sample |
| 37 // rate, just use the point sampler. Otherwise, use the linear re-sampler. | 40 // rate, just use the point sampler. Otherwise, use the linear re-sampler. |
| 38 LinearTransform::Ratio src_to_dst(src_format->frames_per_second, | 41 LinearTransform::Ratio src_to_dst(src_format->frames_per_second, |
| 39 dst_format->frames_per_second); | 42 dst_format->frames_per_second); |
| 40 if (src_to_dst.numerator == 1) { | 43 if (src_to_dst.numerator == 1) { |
| 41 return mixers::PointSampler::Select(src_format, dst_format); | 44 return mixers::PointSampler::Select(src_format, dst_format); |
| 42 } else { | 45 } else { |
| 43 return mixers::LinearSampler::Select(src_format, dst_format); | 46 return mixers::LinearSampler::Select(src_format, dst_format); |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 } // namespace audio | 50 } // namespace audio |
| 48 } // namespace media | 51 } // namespace media |
| 49 } // namespace mojo | 52 } // namespace mojo |
| OLD | NEW |