Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / general / gr_stream_mux.h @ 47c39028

History | View | Annotate | Download (2.7 kB)

1 43819f0f jcorgan
/* -*- c++ -*- */
2 43819f0f jcorgan
/*
3 43819f0f jcorgan
 * Copyright 2006 Free Software Foundation, Inc.
4 43819f0f jcorgan
 * 
5 43819f0f jcorgan
 * This file is part of GNU Radio
6 43819f0f jcorgan
 * 
7 43819f0f jcorgan
 * GNU Radio is free software; you can redistribute it and/or modify
8 43819f0f jcorgan
 * it under the terms of the GNU General Public License as published by
9 937b719d eb
 * the Free Software Foundation; either version 3, or (at your option)
10 43819f0f jcorgan
 * any later version.
11 43819f0f jcorgan
 * 
12 43819f0f jcorgan
 * GNU Radio is distributed in the hope that it will be useful,
13 43819f0f jcorgan
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 43819f0f jcorgan
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 43819f0f jcorgan
 * GNU General Public License for more details.
16 43819f0f jcorgan
 * 
17 43819f0f jcorgan
 * You should have received a copy of the GNU General Public License
18 43819f0f jcorgan
 * along with GNU Radio; see the file COPYING.  If not, write to
19 43819f0f jcorgan
 * the Free Software Foundation, Inc., 51 Franklin Street,
20 43819f0f jcorgan
 * Boston, MA 02110-1301, USA.
21 43819f0f jcorgan
 */
22 43819f0f jcorgan
23 43819f0f jcorgan
#ifndef INCLUDED_GR_STREAM_MUX_H
24 43819f0f jcorgan
#define INCLUDED_GR_STREAM_MUX_H
25 43819f0f jcorgan
26 43819f0f jcorgan
27 f914499f Josh Blum
#include <gr_core_api.h>
28 43819f0f jcorgan
#include <gr_block.h>
29 43819f0f jcorgan
#include <vector>
30 43819f0f jcorgan
31 43819f0f jcorgan
/*!
32 43819f0f jcorgan
 * \brief Creates a stream muxing block to multiplex many streams into
33 43819f0f jcorgan
 * one with a specified format.
34 ed236703 eb
 * \ingroup converter_blk
35 43819f0f jcorgan
 *
36 43819f0f jcorgan
 * \param itemsize the item size of the stream
37 43819f0f jcorgan
 * \param length   a vector (list/tuple) specifying the number of
38 43819f0f jcorgan
 *                 items from each stream the mux together.
39 43819f0f jcorgan
 *                 Warning: this requires that at least as many items
40 43819f0f jcorgan
 *                 per stream are available or the system will wait
41 43819f0f jcorgan
 *                 indefinitely for the items.
42 43819f0f jcorgan
 *
43 43819f0f jcorgan
 */
44 cda71d95 eb
class gr_stream_mux;
45 cda71d95 eb
typedef boost::shared_ptr<gr_stream_mux> gr_stream_mux_sptr;
46 cda71d95 eb
47 cda71d95 eb
48 43819f0f jcorgan
49 f914499f Josh Blum
GR_CORE_API gr_stream_mux_sptr 
50 43819f0f jcorgan
gr_make_stream_mux (size_t itemsize, const std::vector<int> &lengths);
51 43819f0f jcorgan
52 43819f0f jcorgan
53 43819f0f jcorgan
/*!
54 43819f0f jcorgan
 * \brief Stream muxing block to multiplex many streams into
55 43819f0f jcorgan
 * one with a specified format.
56 43819f0f jcorgan
 * 
57 43819f0f jcorgan
 * Muxes N streams together producing an output stream that
58 43819f0f jcorgan
 * contains N0 items from the first stream, N1 items from the second,
59 43819f0f jcorgan
 * etc. and repeats:
60 43819f0f jcorgan
 *
61 43819f0f jcorgan
 * [N0, N1, N2, ..., Nm, N0, N1, ...]
62 43819f0f jcorgan
 */
63 43819f0f jcorgan
64 f914499f Josh Blum
class GR_CORE_API gr_stream_mux : public gr_block
65 43819f0f jcorgan
{
66 f914499f Josh Blum
  friend GR_CORE_API gr_stream_mux_sptr
67 43819f0f jcorgan
    gr_make_stream_mux (size_t itemsize, const std::vector<int> &lengths);
68 43819f0f jcorgan
  
69 43819f0f jcorgan
 protected:
70 43819f0f jcorgan
   gr_stream_mux (size_t itemsize, const std::vector<int> &lengths);
71 c7dbfcc7 trondeau
72 43819f0f jcorgan
 private:
73 c7dbfcc7 trondeau
  size_t d_itemsize;
74 c7dbfcc7 trondeau
  unsigned int d_stream;    // index of currently selected stream
75 c7dbfcc7 trondeau
  int d_residual;           // number if items left to put into current stream
76 c7dbfcc7 trondeau
  gr_vector_int d_lengths;  // number if items to pack per stream
77 c7dbfcc7 trondeau
 
78 c7dbfcc7 trondeau
  void increment_stream();
79 c7dbfcc7 trondeau
80 43819f0f jcorgan
 public:
81 43819f0f jcorgan
  ~gr_stream_mux(void);
82 43819f0f jcorgan
83 43819f0f jcorgan
 void forecast (int noutput_items, gr_vector_int &ninput_items_required);
84 43819f0f jcorgan
85 43819f0f jcorgan
  int general_work(int noutput_items,
86 43819f0f jcorgan
                   gr_vector_int &ninput_items,
87 43819f0f jcorgan
                   gr_vector_const_void_star &input_items,
88 43819f0f jcorgan
                   gr_vector_void_star &output_items);
89 43819f0f jcorgan
90 43819f0f jcorgan
};
91 43819f0f jcorgan
92 43819f0f jcorgan
93 43819f0f jcorgan
#endif