blob: 00652cc2b7aa35eba77d40bd27a1656357a4ee3d [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
kwiberge1a27d42015-11-18 07:32:49 -080014#include <map>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/optional.h"
17#include "common_types.h"
18#include "modules/audio_coding/acm2/rent_a_codec.h"
19#include "modules/audio_coding/include/audio_coding_module.h"
20#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
21#include "rtc_base/constructormagic.h"
22#include "rtc_base/thread_checker.h"
Henrik Lundin45c64492015-03-30 19:00:44 +020023
24namespace webrtc {
25
26class AudioDecoder;
Karl Wibergbd1bc472015-05-18 12:18:54 +020027class AudioEncoder;
Henrik Lundin45c64492015-03-30 19:00:44 +020028
29namespace acm2 {
30
Henrik Lundin45c64492015-03-30 19:00:44 +020031class CodecManager final {
32 public:
Karl Wibergbd1bc472015-05-18 12:18:54 +020033 CodecManager();
Henrik Lundin45c64492015-03-30 19:00:44 +020034 ~CodecManager();
35
kwiberga6db4952015-12-16 04:19:08 -080036 // Parses the given specification. On success, returns true and updates the
37 // stored CodecInst and stack parameters; on error, returns false.
38 bool RegisterEncoder(const CodecInst& send_codec);
Henrik Lundin45c64492015-03-30 19:00:44 +020039
kwiberga6db4952015-12-16 04:19:08 -080040 static CodecInst ForgeCodecInst(const AudioEncoder* external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020041
kwiberga6db4952015-12-16 04:19:08 -080042 const CodecInst* GetCodecInst() const {
43 return send_codec_inst_ ? &*send_codec_inst_ : nullptr;
44 }
kwiberg6030a122016-03-08 06:01:31 -080045
46 void UnsetCodecInst() { send_codec_inst_ = rtc::Optional<CodecInst>(); }
47
kwiberga6db4952015-12-16 04:19:08 -080048 const RentACodec::StackParameters* GetStackParams() const {
49 return &codec_stack_params_;
50 }
51 RentACodec::StackParameters* GetStackParams() { return &codec_stack_params_; }
Henrik Lundin45c64492015-03-30 19:00:44 +020052
Henrik Lundin45c64492015-03-30 19:00:44 +020053 bool SetCopyRed(bool enable);
54
kwiberga6db4952015-12-16 04:19:08 -080055 bool SetVAD(bool enable, ACMVADMode mode);
Henrik Lundin45c64492015-03-30 19:00:44 +020056
kwiberga6db4952015-12-16 04:19:08 -080057 bool SetCodecFEC(bool enable_codec_fec);
Henrik Lundin45c64492015-03-30 19:00:44 +020058
kwibergc8d071e2016-04-06 12:22:38 -070059 // Uses the provided Rent-A-Codec to create a new encoder stack, if we have a
60 // complete specification; if so, it is then passed to set_encoder. On error,
61 // returns false.
kwiberg3f81fcd2016-06-23 03:58:36 -070062 bool MakeEncoder(RentACodec* rac, AudioCodingModule* acm);
kwibergc8d071e2016-04-06 12:22:38 -070063
Henrik Lundin45c64492015-03-30 19:00:44 +020064 private:
Henrik Lundin45c64492015-03-30 19:00:44 +020065 rtc::ThreadChecker thread_checker_;
kwiberga6db4952015-12-16 04:19:08 -080066 rtc::Optional<CodecInst> send_codec_inst_;
kwiberg1379f1f2015-11-23 04:30:52 -080067 RentACodec::StackParameters codec_stack_params_;
kwiberg3f81fcd2016-06-23 03:58:36 -070068 bool recreate_encoder_ = true; // Need to recreate encoder?
kwiberge1a27d42015-11-18 07:32:49 -080069
henrikg3c089d72015-09-16 05:37:44 -070070 RTC_DISALLOW_COPY_AND_ASSIGN(CodecManager);
Henrik Lundin45c64492015-03-30 19:00:44 +020071};
72
73} // namespace acm2
74} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020075#endif // MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_