blob: 22dbf4e72bbd6dec4349b52e9c2b3e9be1f31665 [file] [log] [blame]
Henrik Lundin45c64492015-03-30 19:00:44 +02001/*
2 * Copyright (c) 2015 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_
12#define MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_
Henrik Lundin45c64492015-03-30 19:00:44 +020013
Danil Chapovalovb6021232018-06-19 13:26:36 +020014#include "absl/types/optional.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_coding/acm2/rent_a_codec.h"
17#include "modules/audio_coding/include/audio_coding_module.h"
18#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
19#include "rtc_base/constructormagic.h"
20#include "rtc_base/thread_checker.h"
Henrik Lundin45c64492015-03-30 19:00:44 +020021
22namespace webrtc {
23
Karl Wibergbd1bc472015-05-18 12:18:54 +020024class AudioEncoder;
Henrik Lundin45c64492015-03-30 19:00:44 +020025
26namespace acm2 {
27
Henrik Lundin45c64492015-03-30 19:00:44 +020028class CodecManager final {
29 public:
Karl Wibergbd1bc472015-05-18 12:18:54 +020030 CodecManager();
Henrik Lundin45c64492015-03-30 19:00:44 +020031 ~CodecManager();
32
kwiberga6db4952015-12-16 04:19:08 -080033 // Parses the given specification. On success, returns true and updates the
34 // stored CodecInst and stack parameters; on error, returns false.
35 bool RegisterEncoder(const CodecInst& send_codec);
Henrik Lundin45c64492015-03-30 19:00:44 +020036
kwiberga6db4952015-12-16 04:19:08 -080037 static CodecInst ForgeCodecInst(const AudioEncoder* external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020038
kwiberga6db4952015-12-16 04:19:08 -080039 const CodecInst* GetCodecInst() const {
40 return send_codec_inst_ ? &*send_codec_inst_ : nullptr;
41 }
kwiberg6030a122016-03-08 06:01:31 -080042
Danil Chapovalovb6021232018-06-19 13:26:36 +020043 void UnsetCodecInst() { send_codec_inst_ = absl::nullopt; }
kwiberg6030a122016-03-08 06:01:31 -080044
kwiberga6db4952015-12-16 04:19:08 -080045 const RentACodec::StackParameters* GetStackParams() const {
46 return &codec_stack_params_;
47 }
48 RentACodec::StackParameters* GetStackParams() { return &codec_stack_params_; }
Henrik Lundin45c64492015-03-30 19:00:44 +020049
Henrik Lundin45c64492015-03-30 19:00:44 +020050 bool SetCopyRed(bool enable);
51
kwiberga6db4952015-12-16 04:19:08 -080052 bool SetVAD(bool enable, ACMVADMode mode);
Henrik Lundin45c64492015-03-30 19:00:44 +020053
kwiberga6db4952015-12-16 04:19:08 -080054 bool SetCodecFEC(bool enable_codec_fec);
Henrik Lundin45c64492015-03-30 19:00:44 +020055
kwibergc8d071e2016-04-06 12:22:38 -070056 // Uses the provided Rent-A-Codec to create a new encoder stack, if we have a
57 // complete specification; if so, it is then passed to set_encoder. On error,
58 // returns false.
kwiberg3f81fcd2016-06-23 03:58:36 -070059 bool MakeEncoder(RentACodec* rac, AudioCodingModule* acm);
kwibergc8d071e2016-04-06 12:22:38 -070060
Henrik Lundin45c64492015-03-30 19:00:44 +020061 private:
Henrik Lundin45c64492015-03-30 19:00:44 +020062 rtc::ThreadChecker thread_checker_;
Danil Chapovalovb6021232018-06-19 13:26:36 +020063 absl::optional<CodecInst> send_codec_inst_;
kwiberg1379f1f2015-11-23 04:30:52 -080064 RentACodec::StackParameters codec_stack_params_;
kwiberg3f81fcd2016-06-23 03:58:36 -070065 bool recreate_encoder_ = true; // Need to recreate encoder?
kwiberge1a27d42015-11-18 07:32:49 -080066
henrikg3c089d72015-09-16 05:37:44 -070067 RTC_DISALLOW_COPY_AND_ASSIGN(CodecManager);
Henrik Lundin45c64492015-03-30 19:00:44 +020068};
69
70} // namespace acm2
71} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020072#endif // MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_