Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
openfec_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc Streaming 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/target_openfec/roc_fec/openfec_encoder.h
10 //! @brief Encoder implementation using OpenFEC library.
11 
12 #ifndef ROC_FEC_OPENFEC_ENCODER_H_
13 #define ROC_FEC_OPENFEC_ENCODER_H_
14 
15 #include "roc_core/array.h"
17 #include "roc_core/iarena.h"
18 #include "roc_core/noncopyable.h"
19 #include "roc_core/slice.h"
20 #include "roc_fec/codec_config.h"
21 #include "roc_fec/iblock_encoder.h"
22 #include "roc_packet/units.h"
23 
24 extern "C" {
25 #include <of_openfec_api.h>
26 }
27 
28 #ifndef OF_USE_ENCODER
29 #error "OF_USE_ENCODER undefined"
30 #endif
31 
32 #ifndef OF_USE_LDPC_STAIRCASE_CODEC
33 #error "OF_USE_LDPC_STAIRCASE_CODEC undefined"
34 #endif
35 
36 namespace roc {
37 namespace fec {
38 
39 //! Encoder implementation using OpenFEC library.
41 public:
42  //! Initialize.
43  explicit OpenfecEncoder(const CodecConfig& config,
44  core::BufferFactory<uint8_t>& buffer_factory,
45  core::IArena& arena);
46 
47  virtual ~OpenfecEncoder();
48 
49  //! Check if object is successfully constructed.
50  bool is_valid() const;
51 
52  //! Get buffer alignment requirement.
53  virtual size_t alignment() const;
54 
55  //! Get the maximum number of encoding symbols for the scheme being used.
56  virtual size_t max_block_length() const;
57 
58  //! Start block.
59  //!
60  //! @remarks
61  //! Performs an initial setup for a block. Should be called before
62  //! any operations for the block.
63  virtual bool begin(size_t sblen, size_t rblen, size_t payload_size);
64 
65  //! Store packet data for current block.
66  virtual void set(size_t index, const core::Slice<uint8_t>& buffer);
67 
68  //! Fill repair packets.
69  virtual void fill();
70 
71  //! Finish block.
72  //!
73  //! @remarks
74  //! Cleanups the resources allocated for the block. Should be called after
75  //! all operations for the block.
76  virtual void end();
77 
78 private:
79  bool resize_tabs_(size_t size);
80  void reset_session_();
81  void update_session_params_(size_t sblen, size_t rblen, size_t payload_size);
82 
83  enum { Alignment = 8 };
84 
85  size_t sblen_;
86  size_t rblen_;
87 
88  size_t payload_size_;
89 
90  of_session_t* of_sess_;
91  of_parameters_t* of_sess_params_;
92 
93  of_codec_id_t codec_id_;
94  union {
95  of_ldpc_parameters ldpc_params_;
96  of_rs_2_m_parameters_t rs_params_;
97  } codec_params_;
98 
100  core::Array<void*> data_tab_;
101 
102  size_t max_block_length_;
103 
104  bool valid_;
105 };
106 
107 } // namespace fec
108 } // namespace roc
109 
110 #endif // ROC_FEC_OPENFEC_ENCODER_H_
Dynamic array.
Buffer factory.
Dynamic array.
Definition: array.h:39
Memory arena interface.
Definition: iarena.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
FEC block encoder interface.
Encoder implementation using OpenFEC library.
virtual bool begin(size_t sblen, size_t rblen, size_t payload_size)
Start block.
virtual void set(size_t index, const core::Slice< uint8_t > &buffer)
Store packet data for current block.
virtual size_t max_block_length() const
Get the maximum number of encoding symbols for the scheme being used.
bool is_valid() const
Check if object is successfully constructed.
OpenfecEncoder(const CodecConfig &config, core::BufferFactory< uint8_t > &buffer_factory, core::IArena &arena)
Initialize.
virtual void end()
Finish block.
virtual void fill()
Fill repair packets.
virtual size_t alignment() const
Get buffer alignment requirement.
FEC codec parameters.
Memory arena interface.
FEC block encoder interface.
Root namespace.
Non-copyable object.
Slice.
FEC codec parameters.
Definition: codec_config.h:22
Various units used in packets.