blob: 61832e4f1052f0cc8987a2b13f8eee48d1123561 [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
kjellander3e6db232015-11-26 04:44:54 -080011#ifndef WEBRTC_MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_
12#define WEBRTC_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
Henrik Lundin45c64492015-03-30 19:00:44 +020016#include "webrtc/base/constructormagic.h"
Karl Wibergbe579832015-11-10 22:34:18 +010017#include "webrtc/base/optional.h"
Karl Wiberg2ea71c32015-05-07 15:49:23 +020018#include "webrtc/base/scoped_ptr.h"
Henrik Lundin45c64492015-03-30 19:00:44 +020019#include "webrtc/base/thread_checker.h"
kjellander3e6db232015-11-26 04:44:54 -080020#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
21#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
Henrik Lundin45c64492015-03-30 19:00:44 +020022#include "webrtc/common_types.h"
23
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
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020036 int RegisterEncoder(const CodecInst& send_codec);
Henrik Lundin45c64492015-03-30 19:00:44 +020037
kwiberg12cfc9b2015-09-08 05:57:53 -070038 void RegisterEncoder(AudioEncoder* external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020039
Karl Wibergbe579832015-11-10 22:34:18 +010040 rtc::Optional<CodecInst> GetCodecInst() const;
Henrik Lundin45c64492015-03-30 19:00:44 +020041
Henrik Lundin45c64492015-03-30 19:00:44 +020042 bool SetCopyRed(bool enable);
43
Karl Wiberg2ea71c32015-05-07 15:49:23 +020044 int SetVAD(bool enable, ACMVADMode mode);
Henrik Lundin45c64492015-03-30 19:00:44 +020045
46 void VAD(bool* dtx_enabled, bool* vad_enabled, ACMVADMode* mode) const;
47
48 int SetCodecFEC(bool enable_codec_fec);
49
Karl Wibergbd1bc472015-05-18 12:18:54 +020050 // Returns a pointer to AudioDecoder of the given codec. For iSAC, encoding
51 // and decoding have to be performed on a shared codec instance. By calling
52 // this method, we get the codec instance that ACM owns.
53 // If |codec| does not share an instance between encoder and decoder, returns
54 // null.
55 AudioDecoder* GetAudioDecoder(const CodecInst& codec);
56
kwiberg1379f1f2015-11-23 04:30:52 -080057 bool red_enabled() const { return codec_stack_params_.use_red; }
Henrik Lundin45c64492015-03-30 19:00:44 +020058
kwiberg1379f1f2015-11-23 04:30:52 -080059 bool codec_fec_enabled() const { return codec_stack_params_.use_codec_fec; }
Henrik Lundin45c64492015-03-30 19:00:44 +020060
kwiberge155ae62015-11-16 04:49:54 -080061 AudioEncoder* CurrentEncoder() { return rent_a_codec_.GetEncoderStack(); }
62 const AudioEncoder* CurrentEncoder() const {
63 return rent_a_codec_.GetEncoderStack();
64 }
Henrik Lundin45c64492015-03-30 19:00:44 +020065
kwiberg12cfc9b2015-09-08 05:57:53 -070066 bool CurrentEncoderIsOpus() const { return encoder_is_opus_; }
67
Henrik Lundin45c64492015-03-30 19:00:44 +020068 private:
Henrik Lundin45c64492015-03-30 19:00:44 +020069 rtc::ThreadChecker thread_checker_;
Henrik Lundin45c64492015-03-30 19:00:44 +020070 CodecInst send_codec_inst_;
kwibergc95c3662015-11-10 06:35:21 -080071 RentACodec rent_a_codec_;
kwiberg1379f1f2015-11-23 04:30:52 -080072 RentACodec::StackParameters codec_stack_params_;
kwiberge1a27d42015-11-18 07:32:49 -080073
kwiberg12cfc9b2015-09-08 05:57:53 -070074 bool encoder_is_opus_;
Henrik Lundin45c64492015-03-30 19:00:44 +020075
henrikg3c089d72015-09-16 05:37:44 -070076 RTC_DISALLOW_COPY_AND_ASSIGN(CodecManager);
Henrik Lundin45c64492015-03-30 19:00:44 +020077};
78
79} // namespace acm2
80} // namespace webrtc
kjellander3e6db232015-11-26 04:44:54 -080081#endif // WEBRTC_MODULES_AUDIO_CODING_ACM2_CODEC_MANAGER_H_