function_audio_decoder_factory.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
  11. #define TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
  12. #include <functional>
  13. #include <memory>
  14. #include <utility>
  15. #include <vector>
  16. #include "absl/memory/memory.h"
  17. #include "api/audio_codecs/audio_decoder_factory.h"
  18. #include "api/audio_codecs/audio_format.h"
  19. #include "rtc_base/checks.h"
  20. namespace webrtc {
  21. namespace test {
  22. // A decoder factory producing decoders by calling a supplied create function.
  23. class FunctionAudioDecoderFactory : public AudioDecoderFactory {
  24. public:
  25. explicit FunctionAudioDecoderFactory(
  26. std::function<std::unique_ptr<AudioDecoder>()> create)
  27. : create_([create](const SdpAudioFormat&,
  28. absl::optional<AudioCodecPairId> codec_pair_id) {
  29. return create();
  30. }) {}
  31. explicit FunctionAudioDecoderFactory(
  32. std::function<std::unique_ptr<AudioDecoder>(
  33. const SdpAudioFormat&,
  34. absl::optional<AudioCodecPairId> codec_pair_id)> create)
  35. : create_(std::move(create)) {}
  36. // Unused by tests.
  37. std::vector<AudioCodecSpec> GetSupportedDecoders() override {
  38. RTC_NOTREACHED();
  39. return {};
  40. }
  41. bool IsSupportedDecoder(const SdpAudioFormat& format) override {
  42. return true;
  43. }
  44. std::unique_ptr<AudioDecoder> MakeAudioDecoder(
  45. const SdpAudioFormat& format,
  46. absl::optional<AudioCodecPairId> codec_pair_id) override {
  47. return create_(format, codec_pair_id);
  48. }
  49. private:
  50. const std::function<std::unique_ptr<AudioDecoder>(
  51. const SdpAudioFormat&,
  52. absl::optional<AudioCodecPairId> codec_pair_id)>
  53. create_;
  54. };
  55. } // namespace test
  56. } // namespace webrtc
  57. #endif // TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_