GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
generic_decoder.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_DECODER_H
12#define INCLUDED_FEC_GENERIC_DECODER_H
13
14#include <gnuradio/fec/api.h>
15#include <gnuradio/logger.h>
16#include <memory>
17
18namespace gr {
19namespace fec {
20
21/*!
22 * \brief Parent class for FECAPI objects.
23 *
24 * \ingroup error_coding_blk
25 *
26 * \details
27 *
28 * Parent of a decoder variable class for FECAPI that will fit
29 * into the gr::fec::decoder block to handle FEC decoding. This
30 * class provides the basic information required to fit into the
31 * FECAPI structure. It provides information about input and
32 * output data types, potential data conversions, and a few other
33 * parameters useful to establish the decoder's behavior.
34 *
35 * We create objects from FECAPI-derived classes to go into the
36 * actual GNU Radio decoder block. Each object contains its own
37 * state and so there should be a one-to-one mapping of an FECAPI
38 * object and a GR decoder block. Sharing these objects is not
39 * guaranteed to be thread-safe.
40 *
41 * This is a pure virtual class and must be derived from by a
42 * child class.
43 *
44 * \sa gr::fec::code::cc_decoder
45 * \sa gr::fec::code::ccsds_decoder
46 */
48{
49protected:
51
52public:
53 friend class decoder;
54 virtual void generic_work(void* inbuffer, void* outbuffer) = 0;
55 static int base_unique_id;
56 int my_id;
57 int unique_id();
58 std::string d_name;
59 std::string alias() { return d_name + std::to_string(unique_id()); }
60
61public:
62 typedef std::shared_ptr<generic_decoder> sptr;
63
65 generic_decoder(std::string name);
67
68 /*!
69 * Returns the rate of the code. For every r input bits, there
70 * is 1 output bit, so the rate is 1/r. Used for setting things
71 * like the encoder block's relative rate.
72 *
73 * This function MUST be reimplemented by the child class.
74 */
75 virtual double rate() = 0;
76
77 /*!
78 * Returns the input size in items that the decoder object uses
79 * to decode a full frame. Often, this number is the number of
80 * bits per frame if the input format is unpacked. If the block
81 * expects packed bytes, then this value should be the number of
82 * bytes (number of bits / 8) per input frame.
83 *
84 * The child class MUST implement this function.
85 */
86 virtual int get_input_size() = 0;
87
88 /*!
89 * Returns the output size in items that the decoder object
90 * produces after decoding a full frame. Often, this number is
91 * the number of bits in the outputted frame if the input format
92 * is unpacked. If the block produces packed bytes, then this
93 * value should be the number of bytes (number of bits / 8) per
94 * frame produced. This value is generally something like
95 * get_input_size()/R for a 1/R rate code.
96 *
97 * The child class MUST implement this function.
98 */
99 virtual int get_output_size() = 0;
100
101 /*!
102 * Sets up history for the decoder when the decoder is required
103 * to look ahead in the data stream in order to finish
104 * its processing.
105 *
106 * The child class MAY implement this function. If not
107 * reimplemented, it returns 0.
108 */
109 virtual int get_history();
110
111 /*!
112 * Some decoders require the input items to float around a
113 * particular soft value. We can set that floating value by
114 * setting this value to return some non-zero number.
115 *
116 * The fec.extended_decoder block will use this to create an
117 * add_const_ff block before the decoder block to adjust all
118 * input samples appropriately.
119 *
120 * The child class MAY implement this function. If not
121 * reimplemented, it returns 0.
122 */
123 virtual float get_shift();
124
125 /*!
126 * Sets the size of an input item, as in the size of a char or
127 * float item.
128 *
129 * The child class SHOULD implement this function. If not
130 * reimplemented, it returns sizeof(float) as the decoders
131 * typically expect floating point input types.
132 */
133 virtual int get_input_item_size();
134
135 /*!
136 * Sets the size of an output item, as in the size of a char or
137 * float item.
138 *
139 * The child class SHOULD implement this function. If not
140 * reimplemented, it returns sizeof(char) as the decoders
141 * typically expect to produce bits or bytes.
142 */
143 virtual int get_output_item_size();
144
145 /*!
146 * Set up a conversion type required to setup the data properly
147 * for this decoder. The decoder itself will not implement the
148 * conversion and expects an external wrapper (e.g.,
149 * fec.extended_decoder) to read this value and "do the right
150 * thing" to format the data.
151 *
152 * The default behavior is 'none', which means no conversion is
153 * required. Whatever the get_input_item_size() value returns,
154 * the input is expected to conform directly to this.
155 *
156 * This may also return 'uchar', which indicates that the
157 * wrapper should convert the standard float samples to unsigned
158 * characters, either hard sliced or 8-bit soft symbols. See
159 * gr::fec::code::cc_decoder as an example decoder that uses
160 * this conversion format.
161 *
162 * If 'packed_bits', the block expects the inputs to be packed
163 * hard bits. Each input item is a unsigned char where each of
164 * the 8-bits is a hard bit value.
165 *
166 * The child class SHOULD implement this function. If not
167 * reimplemented, it returns "none".
168 */
169 virtual const char* get_input_conversion();
170
171 /*!
172 * Set up a conversion type required to understand the output
173 * style of this decoder. Generally, follow-on processing
174 * expects unpacked bits, so we specify the conversion type here
175 * to indicate what the wrapper (e.g., fec.extended_decoder)
176 * should do to convert the output samples from the decoder into
177 * unpacked bits.
178 *
179 * The default behavior is 'none', which means no conversion is
180 * required. This should mean that the output data is produced
181 * from this decoder as unpacked bit.
182 *
183 * If 'unpack', the block produces packed bytes that should be
184 * unpacked by the wrapper. See gr::fec::code::ccsds_decoder as
185 * an example of a decoder that produces packed bytes.
186 *
187 * The child class SHOULD implement this function. If not
188 * reimplemented, it returns "none".
189 */
190 virtual const char* get_output_conversion();
191
192 /*!
193 * Updates the size of a decoded frame.
194 *
195 * The child class MUST implement this function and interpret
196 * how the \p frame_size information affects the block's
197 * behavior. It should also provide bounds checks.
198 */
199 virtual bool set_frame_size(unsigned int frame_size) = 0;
200
201
202 /*!
203 * Get repetitions to decode.
204 *
205 * The child class should implement this function and return the
206 * number of iterations required to decode.
207 */
208 virtual float get_iterations() { return -1; }
209};
210
211/*! see generic_decoder::get_output_size() */
213
214/*! see generic_decoder::get_input_size() */
216
217/*! see generic_decoder::get_shift() */
219
220/*! see generic_decoder::get_history() */
222
223/*! see generic_decoder::get_input_item_size() */
225
226/*! see generic_decoder::get_output_item_size() */
228
229/*! see generic_decoder::get_input_conversion() */
231
232/*! see generic_decoder::get_output_conversion() */
234
235} /* namespace fec */
236} /* namespace gr */
237
238#endif /* INCLUDED_FEC_GENRIC_DECODER_H */
General FEC decoding block that takes in a decoder variable object (derived from gr::fec::general_dec...
Definition: decoder.h:53
Parent class for FECAPI objects.
Definition: generic_decoder.h:48
static int base_unique_id
Definition: generic_decoder.h:55
virtual int get_output_size()=0
virtual const char * get_input_conversion()
virtual int get_input_item_size()
gr::logger_ptr d_logger
Definition: generic_decoder.h:50
int my_id
Definition: generic_decoder.h:56
virtual double rate()=0
virtual int get_output_item_size()
virtual int get_input_size()=0
generic_decoder(void)
Definition: generic_decoder.h:64
virtual bool set_frame_size(unsigned int frame_size)=0
virtual float get_iterations()
Definition: generic_decoder.h:208
virtual float get_shift()
std::shared_ptr< generic_decoder > sptr
Definition: generic_decoder.h:62
virtual int get_history()
std::string d_name
Definition: generic_decoder.h:58
std::string alias()
Definition: generic_decoder.h:59
generic_decoder(std::string name)
virtual const char * get_output_conversion()
virtual void generic_work(void *inbuffer, void *outbuffer)=0
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18
FEC_API int get_decoder_input_size(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_input_item_size(generic_decoder::sptr my_decoder)
FEC_API int get_history(generic_decoder::sptr my_decoder)
FEC_API float get_shift(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_output_size(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_output_item_size(generic_decoder::sptr my_decoder)
FEC_API const char * get_decoder_input_conversion(generic_decoder::sptr my_decoder)
FEC_API const char * get_decoder_output_conversion(generic_decoder::sptr my_decoder)
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225