Merge commit 'v3.3.0' into upstream
[debian/gnuradio] / gr-atsc / src / lib / GrAtscRSDecoder.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 #include <GrAtscRSDecoder.h>
24
25 // typedefs for fundamental i/o types
26
27 typedef atsc_mpeg_packet_rs_encoded     iType;
28 typedef atsc_mpeg_packet_no_sync        oType;
29
30 static const int NUMBER_OF_OUTPUTS = 1; // # of output streams (almost always one)
31
32
33 GrAtscRSDecoder::GrAtscRSDecoder ()
34   : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS)
35 {
36   // 1 + number of extra input elements at which we look.  This is
37   // used by the superclass's forecast routine to get us the correct
38   // range on our inputs.
39   // We're one-to-one input-to-output so set it to 1.
40   history = 1;  
41
42   // any other init here.
43 }
44
45 GrAtscRSDecoder::~GrAtscRSDecoder ()
46 {
47   // Anything that isn't automatically cleaned up...
48 }
49
50 /*
51  * This is the real work horse.  In general this interface can handle
52  * multiple streams of input and output, but we almost always
53  * use a single input and output stream.
54  */
55
56 int 
57 GrAtscRSDecoder::work (VrSampleRange output, void *ao[],
58                           VrSampleRange inputs[], void *ai[])
59 {
60   // construct some nicer i/o pointers to work with.
61
62   iType *in  = ((iType **) ai)[0];
63   oType *out = ((oType **) ao)[0];
64
65
66   // We must produce output.size units of output.
67
68   for (unsigned int i = 0; i < output.size; i++){
69     assert (in[i].pli.regular_seg_p ());
70     out[i].pli = in[i].pli;             // copy pipeline info
71
72     int nerrors_not_corrected = rs_decoder.decode (out[i], in[i]);
73     out[i].pli.set_transport_error (nerrors_not_corrected == -1);
74   }
75
76   // Return the number of units we produced.
77   // Note that for all intents and purposes, it is an error to
78   // produce less than you are asked for.
79
80   return output.size;   
81 }