Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_MIXER_H_ | |
| 6 #define SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_MIXER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "mojo/services/media/common/interfaces/media_types.mojom.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 namespace media { | |
| 14 namespace audio { | |
| 15 | |
| 16 class Mixer; | |
| 17 using MixerPtr = std::unique_ptr<Mixer>; | |
| 18 | |
| 19 class Mixer { | |
| 20 public: | |
| 21 virtual ~Mixer(); | |
| 22 | |
| 23 // Select | |
| 24 // | |
| 25 // Select an appropriate instance of a mixer based on the properties of the | |
| 26 // source and destination formats. | |
| 27 // | |
| 28 // TODO(johngro): Come back here and add a way to indicate user preference | |
| 29 // where appropriate. For example, where we might chose a linear | |
| 30 // interpolation sampler, the user may actually prefer cubic interpolation, or | |
| 31 // perhaps just a point sampler. | |
| 32 static MixerPtr Select(const LpcmMediaTypeDetailsPtr& src_format, | |
|
jeffbrown
2015/11/04 23:43:34
This is looking much cleaner than the first patch.
johngro
2015/11/06 02:20:26
Acknowledged.
| |
| 33 const LpcmMediaTypeDetailsPtr& dst_format); | |
| 34 | |
| 35 // Mix | |
| 36 // | |
| 37 // Perform a mixing operation from the source buffer into the destination | |
| 38 // buffer. | |
| 39 // | |
| 40 // @param dst | |
| 41 // The pointer to the destination buffer into which frames will be mixed. | |
| 42 // | |
| 43 // @param dst_frames | |
| 44 // The total number of frames of audio which comprise the destination buffer. | |
| 45 // | |
| 46 // @param dst_offset | |
| 47 // The offset (in destination frames) at which we should start to mix | |
| 48 // destination frames. | |
| 49 // | |
| 50 // @param src | |
| 51 // The pointer the the source buffer containing the frames to be mixed into | |
| 52 // the destination buffer. | |
| 53 // | |
| 54 // @param frac_src_frames | |
| 55 // The total number of fractional track frames contained by the source buffer. | |
| 56 // | |
| 57 // @param frac_src_offset | |
| 58 // A pointer to the offset (expressed in fractional track frames) at which the | |
| 59 // first frame to be mixed with the destination buffer should be sampled. | |
| 60 // When Mix has finished, frac_src_offset will be updated to indicate the | |
| 61 // offset of the sampling position of the next frame to be mixed with the | |
| 62 // output buffer. | |
| 63 // | |
| 64 // @param frac_step_size | |
| 65 // How much to increment the fractional sampling position for each output | |
|
jeffbrown
2015/11/04 23:43:34
Is this actually a fraction? Like a fixed point v
johngro
2015/11/06 02:20:26
yes, that is exactly what it is.
| |
| 66 // frame produced. | |
| 67 // | |
| 68 // TODO(johngro): Right now, this number may have some amount of rounding | |
| 69 // error which will accumulate as sampling position error as we produce more | |
| 70 // output samples for a single call to Mix. This error will reset when we | |
| 71 // swtich to the next source buffer, but could (in theory) be the source of | |
| 72 // distortion. If this becomes a problem, we should consider switching to | |
| 73 // some form of (N,M) stepping system where we count by frac_step_size for N | |
| 74 // output samples, then frac_step_size+1 for M samples, etc... | |
| 75 // | |
| 76 // @param accumulate | |
| 77 // When true, the mixer will accumulate into the destination buffer (read, | |
| 78 // sum, clip, write-back). When false, the mixer will simply replace the | |
| 79 // destination buffer with its output. | |
| 80 // | |
| 81 // @return True if the mixer is finished with this source data and will not | |
| 82 // need it in the future. False if the mixer has not consumed the entire | |
| 83 // source buffer and will need more of it in the future. | |
| 84 virtual bool Mix(void* dst, | |
| 85 uint32_t dst_frames, | |
| 86 uint32_t* dst_offset, | |
| 87 const void* src, | |
| 88 uint32_t frac_src_frames, | |
| 89 uint32_t* frac_src_offset, | |
| 90 uint32_t frac_step_size, | |
| 91 bool accumulate) = 0; | |
| 92 | |
| 93 // Reset | |
| 94 // | |
| 95 // Reset the internal state of the mixer. Will be called every time there is | |
| 96 // a discontinuity in the source stream. Mixer implementations should reset | |
| 97 // anything related to their internal filter state. | |
| 98 virtual void Reset() {} | |
| 99 | |
| 100 protected: | |
| 101 Mixer(); | |
| 102 }; | |
| 103 | |
| 104 } // namespace audio | |
| 105 } // namespace media | |
| 106 } // namespace mojo | |
| 107 | |
| 108 #endif // SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_MIXER_H_ | |
| OLD | NEW |