GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_FEC_GENERIC_ENCODER_H
24 #define INCLUDED_FEC_GENERIC_ENCODER_H
25 
26 #include <gnuradio/fec/api.h>
27 #include <gnuradio/block.h>
28 #include <gnuradio/logger.h>
29 #include <boost/shared_ptr.hpp>
30 
31 namespace gr {
32  namespace fec {
33 
35  {
36  protected:
38 
39  public:
40  friend class encoder;
41  virtual void generic_work(void *in_buffer, void *out_buffer) = 0;
42  static int base_unique_id;
43  int my_id;
44  int unique_id();
45  std::string d_name;
46  std::string alias(){ return (boost::format("%s%d")%d_name%unique_id()).str(); }
47 
48  public:
50 
51  /*!
52  * Returns the rate of the code. For every 1 input bit, there
53  * are r output bits, so the rate is 1/r. Used for setting
54  * things like the encoder block's relative rate.
55  *
56  * This function MUST be reimplemented by the child class.
57  */
58  virtual double rate() = 0;
59 
60  /*!
61  * Returns the input size in items that the encoder object uses
62  * to encode a full frame. Often, this number is the number of
63  * bits per frame if the input format is unpacked. If the block
64  * expects packed bytes, then this value should be the number of
65  * bytes (number of bits / 8) per input frame.
66  *
67  * The child class MUST implement this function.
68  */
69  virtual int get_input_size() = 0;
70 
71  /*!
72  * Returns the output size in items that the encoder object
73  * produces after encoding a full frame. Often, this number is
74  * the number of bits in the outputted frame if the input format
75  * is unpacked. If the block produces packed bytes, then this
76  * value should be the number of bytes (number of bits / 8) per
77  * frame produced. This value is generally something like
78  * R*get_input_size() for a 1/R rate code.
79  *
80  * The child class MUST implement this function.
81  */
82  virtual int get_output_size() = 0;
83 
84  /*!
85  * Set up a conversion type required to setup the data properly
86  * for this encoder. The encoder itself will not implement the
87  * conversion and expects an external wrapper (e.g.,
88  * fec.extended_encoder) to read this value and "do the right
89  * thing" to format the data.
90  *
91  * The default behavior is 'none', which means no conversion is
92  * required. Whatever the get_input_item_size() value returns,
93  * the input is expected to conform directly to this. Generally,
94  * this means unpacked bytes.
95  *
96  * If 'pack', the block expects the inputs to be packed
97  * bytes. The wrapper should implement a
98  * gr::blocks::pack_k_bits_bb(8) block for this.
99  *
100  * The child class MAY implement this function. If not
101  * reimplemented, it returns "none".
102  */
103  virtual const char* get_input_conversion();
104 
105  /*!
106  * Set up a conversion type required to understand the output
107  * style of this encoder. Generally an encoder will produce
108  * unpacked bytes with a bit set in the LSB.
109  *
110  * The default behavior is 'none', which means no conversion is
111  * required and the encoder produces unpacked bytes.
112  *
113  * If 'packed_bits', the block produces packed bits and the
114  * wrapper should unpack these (using, for instance,
115  * gr::block::unpack_k_bits_bb(8)).
116  *
117  * The child class MAY implement this function. If not
118  * reimplemented, it returns "none".
119  */
120  virtual const char* get_output_conversion();
121 
122  /*!
123  * Updates the size of the frame to encode.
124  *
125  * The child class MUST implement this function and interpret
126  * how the \p frame_size information affects the block's
127  * behavior. It should also provide bounds checks.
128  */
129  virtual bool set_frame_size(unsigned int frame_size) = 0;
130 
131  generic_encoder(void) {};
132  generic_encoder(std::string name);
133  virtual ~generic_encoder();
134  };
135 
136  /*! see generic_encoder::get_output_size() */
138 
139  /*! see generic_encoder::get_input_size() */
141 
142  /*! see generic_encoder::get_input_conversion() */
144 
145  /*! see generic_encoder::get_output_conversion() */
147 
148 
149  } /* namespace fec */
150 } /* namespace gr */
151 
152 #endif /* INCLUDED_FEC_GENERIC_ENCODER_H */
std::string logger_ptr
Definition: logger.h:65
int my_id
Definition: generic_encoder.h:43
FEC_API const char * get_encoder_output_conversion(generic_encoder::sptr my_encoder)
shared_ptr documentation stub
Definition: shared_ptr_docstub.h:15
Definition: generic_encoder.h:34
boost::shared_ptr< generic_encoder > sptr
Definition: generic_encoder.h:49
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:30
static int base_unique_id
Definition: generic_encoder.h:42
gr::logger_ptr d_logger
Definition: generic_encoder.h:37
FEC_API int get_encoder_input_size(generic_encoder::sptr my_encoder)
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
std::string alias()
Definition: generic_encoder.h:46
Creates the encoder block for use in GNU Radio flowgraphs from a given FECAPI object derived from the...
Definition: encoder.h:47
FEC_API int get_encoder_output_size(generic_encoder::sptr my_encoder)
FEC_API const char * get_encoder_input_conversion(generic_encoder::sptr my_encoder)
generic_encoder(void)
Definition: generic_encoder.h:131
std::string d_name
Definition: generic_encoder.h:45