blob: c31424956fd29f4705e7d8566a56642044486660 [file] [log] [blame]
Niels Möllera0f44302018-11-30 09:45:121/*
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
11#ifndef TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
12#define TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
13
14#include <functional>
15#include <memory>
16#include <utility>
17#include <vector>
18
19#include "absl/memory/memory.h"
20#include "api/audio_codecs/audio_decoder_factory.h"
21#include "api/audio_codecs/audio_format.h"
Danil Chapovalove0fe4202024-08-14 17:17:0522#include "api/environment/environment.h"
Niels Möllera0f44302018-11-30 09:45:1223#include "rtc_base/checks.h"
24
25namespace webrtc {
26namespace test {
27
28// A decoder factory producing decoders by calling a supplied create function.
29class FunctionAudioDecoderFactory : public AudioDecoderFactory {
30 public:
31 explicit FunctionAudioDecoderFactory(
32 std::function<std::unique_ptr<AudioDecoder>()> create)
Danil Chapovalove0fe4202024-08-14 17:17:0533 : create_([create](const Environment&,
34 const SdpAudioFormat&,
Florent Castelli8037fc62024-08-29 13:00:4035 std::optional<AudioCodecPairId> codec_pair_id) {
Niels Möllera0f44302018-11-30 09:45:1236 return create();
37 }) {}
38 explicit FunctionAudioDecoderFactory(
39 std::function<std::unique_ptr<AudioDecoder>(
Danil Chapovalove0fe4202024-08-14 17:17:0540 const Environment&,
Niels Möllera0f44302018-11-30 09:45:1241 const SdpAudioFormat&,
Florent Castelli8037fc62024-08-29 13:00:4042 std::optional<AudioCodecPairId> codec_pair_id)> create)
Niels Möllera0f44302018-11-30 09:45:1243 : create_(std::move(create)) {}
44
45 // Unused by tests.
46 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
Artem Titovd3251962021-11-15 15:57:0747 RTC_DCHECK_NOTREACHED();
Niels Möllera0f44302018-11-30 09:45:1248 return {};
49 }
50
51 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
52 return true;
53 }
54
Danil Chapovalove0fe4202024-08-14 17:17:0555 std::unique_ptr<AudioDecoder> Create(
56 const Environment& env,
Niels Möllera0f44302018-11-30 09:45:1257 const SdpAudioFormat& format,
Florent Castelli8037fc62024-08-29 13:00:4058 std::optional<AudioCodecPairId> codec_pair_id) override {
Danil Chapovalove0fe4202024-08-14 17:17:0559 return create_(env, format, codec_pair_id);
Niels Möllera0f44302018-11-30 09:45:1260 }
61
62 private:
63 const std::function<std::unique_ptr<AudioDecoder>(
Danil Chapovalove0fe4202024-08-14 17:17:0564 const Environment&,
Niels Möllera0f44302018-11-30 09:45:1265 const SdpAudioFormat&,
Florent Castelli8037fc62024-08-29 13:00:4066 std::optional<AudioCodecPairId> codec_pair_id)>
Niels Möllera0f44302018-11-30 09:45:1267 create_;
68};
69
70} // namespace test
71} // namespace webrtc
72
73#endif // TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_