Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_ |
| 12 | #define MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_ |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 13 | |
kwiberg | e1a27d4 | 2015-11-18 07:32:49 -0800 | [diff] [blame] | 14 | #include <map> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 16 | #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 Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class AudioDecoder; |
Karl Wiberg | bd1bc47 | 2015-05-18 12:18:54 +0200 | [diff] [blame] | 27 | class AudioEncoder; |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 28 | |
| 29 | namespace acm2 { |
| 30 | |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 31 | class CodecManager final { |
| 32 | public: |
Karl Wiberg | bd1bc47 | 2015-05-18 12:18:54 +0200 | [diff] [blame] | 33 | CodecManager(); |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 34 | ~CodecManager(); |
| 35 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 36 | // 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 Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 39 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 40 | static CodecInst ForgeCodecInst(const AudioEncoder* external_speech_encoder); |
Karl Wiberg | 7e0c7d4 | 2015-05-18 14:52:29 +0200 | [diff] [blame] | 41 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 42 | const CodecInst* GetCodecInst() const { |
| 43 | return send_codec_inst_ ? &*send_codec_inst_ : nullptr; |
| 44 | } |
kwiberg | 6030a12 | 2016-03-08 06:01:31 -0800 | [diff] [blame] | 45 | |
| 46 | void UnsetCodecInst() { send_codec_inst_ = rtc::Optional<CodecInst>(); } |
| 47 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 48 | const RentACodec::StackParameters* GetStackParams() const { |
| 49 | return &codec_stack_params_; |
| 50 | } |
| 51 | RentACodec::StackParameters* GetStackParams() { return &codec_stack_params_; } |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 52 | |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 53 | bool SetCopyRed(bool enable); |
| 54 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 55 | bool SetVAD(bool enable, ACMVADMode mode); |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 56 | |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 57 | bool SetCodecFEC(bool enable_codec_fec); |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 58 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 59 | // 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. |
kwiberg | 3f81fcd | 2016-06-23 03:58:36 -0700 | [diff] [blame] | 62 | bool MakeEncoder(RentACodec* rac, AudioCodingModule* acm); |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 63 | |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 64 | private: |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 65 | rtc::ThreadChecker thread_checker_; |
kwiberg | a6db495 | 2015-12-16 04:19:08 -0800 | [diff] [blame] | 66 | rtc::Optional<CodecInst> send_codec_inst_; |
kwiberg | 1379f1f | 2015-11-23 04:30:52 -0800 | [diff] [blame] | 67 | RentACodec::StackParameters codec_stack_params_; |
kwiberg | 3f81fcd | 2016-06-23 03:58:36 -0700 | [diff] [blame] | 68 | bool recreate_encoder_ = true; // Need to recreate encoder? |
kwiberg | e1a27d4 | 2015-11-18 07:32:49 -0800 | [diff] [blame] | 69 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 70 | RTC_DISALLOW_COPY_AND_ASSIGN(CodecManager); |
Henrik Lundin | 45c6449 | 2015-03-30 19:00:44 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace acm2 |
| 74 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 75 | #endif // MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_ |