channel_mixing_matrix.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2012 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. #ifndef MEDIA_BASE_CHANNEL_MIXING_MATRIX_H_
  5. #define MEDIA_BASE_CHANNEL_MIXING_MATRIX_H_
  6. #include <vector>
  7. #include "base/memory/raw_ptr.h"
  8. #include "media/base/channel_layout.h"
  9. #include "media/base/media_export.h"
  10. namespace media {
  11. class MEDIA_EXPORT ChannelMixingMatrix {
  12. public:
  13. ChannelMixingMatrix(ChannelLayout input_layout,
  14. int input_channels,
  15. ChannelLayout output_layout,
  16. int output_channels);
  17. ChannelMixingMatrix(const ChannelMixingMatrix&) = delete;
  18. ChannelMixingMatrix& operator=(const ChannelMixingMatrix&) = delete;
  19. ~ChannelMixingMatrix();
  20. // Create the transformation matrix of input channels to output channels.
  21. // Updates the empty matrix with the transformation, and returns true
  22. // if the transformation is just a remapping of channels (no mixing).
  23. bool CreateTransformationMatrix(std::vector<std::vector<float>>* matrix);
  24. private:
  25. // Result transformation of input channels to output channels
  26. raw_ptr<std::vector<std::vector<float>>> matrix_;
  27. // Input and output channel layout provided during construction.
  28. ChannelLayout input_layout_;
  29. int input_channels_;
  30. ChannelLayout output_layout_;
  31. int output_channels_;
  32. // Helper variable for tracking which inputs are currently unaccounted,
  33. // should be empty after construction completes.
  34. std::vector<Channels> unaccounted_inputs_;
  35. // Helper methods for managing unaccounted input channels.
  36. void AccountFor(Channels ch);
  37. bool IsUnaccounted(Channels ch) const;
  38. // Helper methods for checking if |ch| exists in either |input_layout_| or
  39. // |output_layout_| respectively.
  40. bool HasInputChannel(Channels ch) const;
  41. bool HasOutputChannel(Channels ch) const;
  42. // Helper methods for updating |matrix_| with the proper value for
  43. // mixing |input_ch| into |output_ch|. MixWithoutAccounting() does not
  44. // remove the channel from |unaccounted_inputs_|.
  45. void Mix(Channels input_ch, Channels output_ch, float scale);
  46. void MixWithoutAccounting(Channels input_ch, Channels output_ch, float scale);
  47. };
  48. } // namespace media
  49. #endif // MEDIA_BASE_CHANNEL_MIXING_MATRIX_H_