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