Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
codec_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_fec/codec_map.h
10 //! @brief FEC codec map.
11 
12 #ifndef ROC_FEC_CODEC_MAP_H_
13 #define ROC_FEC_CODEC_MAP_H_
14 
15 #include "roc_core/buffer_pool.h"
16 #include "roc_core/iallocator.h"
17 #include "roc_core/noncopyable.h"
18 #include "roc_fec/codec_config.h"
19 #include "roc_fec/iblock_decoder.h"
20 #include "roc_fec/iblock_encoder.h"
21 
22 namespace roc {
23 namespace fec {
24 
25 //! FEC codec map.
26 class CodecMap : public core::NonCopyable<> {
27 public:
28  //! Initialize.
29  CodecMap();
30 
31  //! Create a new block encoder.
32  //!
33  //! @remarks
34  //! The codec type is determined by @p config.
35  //!
36  //! @returns
37  //! NULL if parameters are invalid or given codec support is not enabled.
38  IBlockEncoder* new_encoder(const CodecConfig& config,
40  core::IAllocator& allocator) const;
41 
42  //! Create a new block decoder.
43  //!
44  //! @remarks
45  //! The codec type is determined by @p config.
46  //!
47  //! @returns
48  //! NULL if parameters are invalid or given codec support is not enabled.
49  IBlockDecoder* new_decoder(const CodecConfig& config,
51  core::IAllocator& allocator) const;
52 
53 private:
54  enum { MaxCodecs = 2 };
55 
56  struct Codec {
57  packet::FECScheme scheme;
58 
59  IBlockEncoder* (*encoder_ctor)(const CodecConfig& config,
61  core::IAllocator& allocator);
62 
63  IBlockDecoder* (*decoder_ctor)(const CodecConfig& config,
65  core::IAllocator& allocator);
66  };
67 
68  void add_codec_(const Codec& codec);
69  const Codec* find_codec_(packet::FECScheme scheme) const;
70 
71  size_t n_codecs_;
72  Codec codecs_[MaxCodecs];
73 };
74 
75 } // namespace fec
76 } // namespace roc
77 
78 #endif // ROC_FEC_CODEC_MAP_H_
Memory allocator interface.
Definition: iallocator.h:23
Root namespace.
Base class for non-copyable objects.
Definition: noncopyable.h:23
FEC block decoder interface.
FEC codec parameters.
FEC block encoder interface.
FECScheme
FECFRAME scheme.
Definition: fec.h:23
Buffer pool.
Non-copyable object.
FEC codec map.
Definition: codec_map.h:26
CodecMap()
Initialize.
IBlockEncoder * new_encoder(const CodecConfig &config, core::BufferPool< uint8_t > &pool, core::IAllocator &allocator) const
Create a new block encoder.
IBlockDecoder * new_decoder(const CodecConfig &config, core::BufferPool< uint8_t > &pool, core::IAllocator &allocator) const
Create a new block decoder.
FEC codec parameters.
Definition: codec_config.h:22
FEC block encoder interface.
Memory allocator interface.
FEC block decoder interface.