GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
generic_encoder.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013-2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_FEC_GENERIC_ENCODER_H
12 #define INCLUDED_FEC_GENERIC_ENCODER_H
13 
14 #include <gnuradio/block.h>
15 #include <gnuradio/fec/api.h>
16 #include <gnuradio/logger.h>
17 #include <memory>
18 
19 namespace gr {
20 namespace fec {
21 
23 {
24 protected:
26 
27 public:
28  friend class encoder;
29  virtual void generic_work(void* in_buffer, void* out_buffer) = 0;
30  static int base_unique_id;
31  int my_id;
32  int unique_id();
33  std::string d_name;
34  std::string alias();
35 
36 public:
37  typedef std::shared_ptr<generic_encoder> sptr;
38 
39  /*!
40  * Returns the rate of the code. For every 1 input bit, there
41  * are r output bits, so the rate is 1/r. Used for setting
42  * things like the encoder block's relative rate.
43  *
44  * This function MUST be reimplemented by the child class.
45  */
46  virtual double rate() = 0;
47 
48  /*!
49  * Returns the input size in items that the encoder object uses
50  * to encode a full frame. Often, this number is the number of
51  * bits per frame if the input format is unpacked. If the block
52  * expects packed bytes, then this value should be the number of
53  * bytes (number of bits / 8) per input frame.
54  *
55  * The child class MUST implement this function.
56  */
57  virtual int get_input_size() = 0;
58 
59  /*!
60  * Returns the output size in items that the encoder object
61  * produces after encoding a full frame. Often, this number is
62  * the number of bits in the outputted frame if the input format
63  * is unpacked. If the block produces packed bytes, then this
64  * value should be the number of bytes (number of bits / 8) per
65  * frame produced. This value is generally something like
66  * R*get_input_size() for a 1/R rate code.
67  *
68  * The child class MUST implement this function.
69  */
70  virtual int get_output_size() = 0;
71 
72  /*!
73  * Set up a conversion type required to setup the data properly
74  * for this encoder. The encoder itself will not implement the
75  * conversion and expects an external wrapper (e.g.,
76  * fec.extended_encoder) to read this value and "do the right
77  * thing" to format the data.
78  *
79  * The default behavior is 'none', which means no conversion is
80  * required. Whatever the get_input_item_size() value returns,
81  * the input is expected to conform directly to this. Generally,
82  * this means unpacked bytes.
83  *
84  * If 'pack', the block expects the inputs to be packed
85  * bytes. The wrapper should implement a
86  * gr::blocks::pack_k_bits_bb(8) block for this.
87  *
88  * The child class MAY implement this function. If not
89  * reimplemented, it returns "none".
90  */
91  virtual const char* get_input_conversion();
92 
93  /*!
94  * Set up a conversion type required to understand the output
95  * style of this encoder. Generally an encoder will produce
96  * unpacked bytes with a bit set in the LSB.
97  *
98  * The default behavior is 'none', which means no conversion is
99  * required and the encoder produces unpacked bytes.
100  *
101  * If 'packed_bits', the block produces packed bits and the
102  * wrapper should unpack these (using, for instance,
103  * gr::block::unpack_k_bits_bb(8)).
104  *
105  * The child class MAY implement this function. If not
106  * reimplemented, it returns "none".
107  */
108  virtual const char* get_output_conversion();
109 
110  /*!
111  * Updates the size of the frame to encode.
112  *
113  * The child class MUST implement this function and interpret
114  * how the \p frame_size information affects the block's
115  * behavior. It should also provide bounds checks.
116  */
117  virtual bool set_frame_size(unsigned int frame_size) = 0;
118 
120  generic_encoder(std::string name);
121  virtual ~generic_encoder();
122 };
123 
124 /*! see generic_encoder::get_output_size() */
126 
127 /*! see generic_encoder::get_input_size() */
129 
130 /*! see generic_encoder::get_input_conversion() */
132 
133 /*! see generic_encoder::get_output_conversion() */
135 
136 
137 } /* namespace fec */
138 } /* namespace gr */
139 
140 #endif /* INCLUDED_FEC_GENERIC_ENCODER_H */
Creates the encoder block for use in GNU Radio flowgraphs from a given FECAPI object derived from the...
Definition: gr-fec/include/gnuradio/fec/encoder.h:36
Definition: generic_encoder.h:23
virtual double rate()=0
virtual void generic_work(void *in_buffer, void *out_buffer)=0
gr::logger_ptr d_logger
Definition: generic_encoder.h:25
static int base_unique_id
Definition: generic_encoder.h:30
std::shared_ptr< generic_encoder > sptr
Definition: generic_encoder.h:37
generic_encoder(void)
Definition: generic_encoder.h:119
generic_encoder(std::string name)
virtual int get_input_size()=0
virtual int get_output_size()=0
std::string d_name
Definition: generic_encoder.h:33
virtual bool set_frame_size(unsigned int frame_size)=0
virtual const char * get_output_conversion()
virtual const char * get_input_conversion()
int my_id
Definition: generic_encoder.h:31
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18
FEC_API int get_encoder_input_size(generic_encoder::sptr my_encoder)
FEC_API const char * get_encoder_input_conversion(generic_encoder::sptr my_encoder)
FEC_API const char * get_encoder_output_conversion(generic_encoder::sptr my_encoder)
FEC_API int get_encoder_output_size(generic_encoder::sptr my_encoder)
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:250