atsc_types.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2001,2006 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef _ATSC_TYPES_H_
00024 #define _ATSC_TYPES_H_
00025 
00026 #include <atsc_consts.h>
00027 #include <string.h>
00028 #include <cstring>
00029 #include <cassert>
00030 
00031 
00037 class plinfo {  
00038 public:
00039   plinfo () : _flags (0), _segno (0) { }
00040 
00041   // accessors
00042 
00043   bool field_sync1_p () const { return (_flags & fl_field_sync1) != 0; }
00044   bool field_sync2_p () const { return (_flags & fl_field_sync2) != 0; }
00045   bool field_sync_p ()  const { return field_sync1_p () || field_sync2_p (); }
00046 
00047   bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; }
00048 
00049   bool in_field1_p ()   const { return (_flags & fl_field2) == 0; }
00050   bool in_field2_p ()   const { return (_flags & fl_field2) != 0; }
00051 
00052   bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; }
00053 
00054   bool transport_error_p ()   const { return (_flags & fl_transport_error) != 0; }
00055 
00056   unsigned int segno () const { return _segno; }
00057   unsigned int flags () const { return _flags; }
00058 
00059   // setters
00060 
00061   void set_field_sync1 ()
00062   {
00063     _segno = 0;
00064     _flags = fl_field_sync1;
00065   }
00066 
00067   void set_field_sync2 ()
00068   {
00069     _segno = 0;
00070     _flags = fl_field_sync2 | fl_field2;
00071   }
00072 
00073   void set_regular_seg (bool field2, int segno)
00074   {
00075     assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD);
00076     _segno = segno;
00077     _flags = fl_regular_seg;
00078     if (segno == 0)
00079       _flags |= fl_first_regular_seg;
00080     if (segno >= ATSC_DSEGS_PER_FIELD)
00081       _flags |= fl_transport_error;
00082     if (field2)
00083       _flags |= fl_field2;
00084   }
00085 
00086   void set_transport_error (bool error){
00087     if (error)
00088       _flags |= fl_transport_error;
00089     else
00090       _flags &= ~fl_transport_error;
00091   }
00092 
00093   // overload equality operator
00094   bool operator== (const plinfo &other) const {
00095     return (_flags == other._flags && _segno == other._segno);
00096   }
00097 
00098   bool operator!= (const plinfo &other) const {
00099     return !(_flags == other._flags && _segno == other._segno);
00100   }
00101 
00106   static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay);
00107 
00111   static void sanity_check (const plinfo &in);
00112   
00113 
00114 protected:
00115   unsigned short        _flags;         // bitmask
00116   unsigned short        _segno;         // segment number [0,311]
00117 
00118   // these three are mutually exclusive
00119   //     This is a regular data segment.
00120   static const int      fl_regular_seg          = 0x0001;
00121   //     This is a field sync segment, for 1st half of a field.
00122   static const int      fl_field_sync1          = 0x0002;
00123   //     This is a field sync segment, for 2nd half of a field.
00124   static const int      fl_field_sync2          = 0x0004;
00125 
00126   // This bit is on ONLY when fl_regular_seg is set AND when this is
00127   // the first regular data segment AFTER a field sync segment.  This
00128   // segment causes various processing modules to reset.
00129   static const int      fl_first_regular_seg    = 0x0008;
00130 
00131   // which field are we in?
00132   static const int      fl_field2               = 0x0010;       // else field 1
00133 
00134   // This bit is set when Reed-Solomon decoding detects an error that it
00135   // can't correct.  Note that other error detection (e.g. Viterbi) do not
00136   // set it, since Reed-Solomon will correct many of those.  This bit is
00137   // then copied into the final Transport Stream packet so that MPEG
00138   // software can see that the 188-byte data segment has been corrupted.
00139   static const int      fl_transport_error      = 0x0020;
00140 };
00141 
00142 
00143 
00144 
00145 class atsc_mpeg_packet {
00146  public:
00147   static const int NPAD  = 68;
00148   unsigned char data[ATSC_MPEG_DATA_LENGTH + 1];        // first byte is sync
00149   unsigned char _pad_[NPAD];                            // pad to power of 2 (256)
00150 
00151   // overload equality operator
00152   bool operator== (const atsc_mpeg_packet &other) const {
00153     return std::memcmp (data, other.data, sizeof (data)) == 0;
00154   };
00155 
00156   bool operator!= (const atsc_mpeg_packet &other) const {
00157     return !(std::memcmp (data, other.data, sizeof (data)) == 0);
00158   };
00159 };
00160 
00161 class atsc_mpeg_packet_no_sync {
00162  public:
00163   static const int NPAD = 65;
00164   plinfo        pli;
00165   unsigned char data[ATSC_MPEG_DATA_LENGTH];
00166   unsigned char _pad_[NPAD];                            // pad to power of 2 (256)
00167 
00168   // overload equality operator
00169   bool operator== (const atsc_mpeg_packet_no_sync &other) const {
00170     return std::memcmp (data, other.data, sizeof (data)) == 0;
00171   }
00172 
00173   bool operator!= (const atsc_mpeg_packet_no_sync &other) const {
00174     return !(std::memcmp (data, other.data, sizeof (data)) == 0);
00175   }
00176 };
00177 
00178 class atsc_mpeg_packet_rs_encoded {
00179  public:
00180   static const int NPAD = 45;
00181   plinfo        pli;
00182   unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH];
00183   unsigned char _pad_[NPAD];                            // pad to power of 2 (256)
00184 
00185   // overload equality operator
00186   bool operator== (const atsc_mpeg_packet_rs_encoded &other) const {
00187     return std::memcmp (data, other.data, sizeof (data)) == 0;
00188   }
00189 
00190   bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const {
00191     return !(std::memcmp (data, other.data, sizeof (data)) == 0);
00192   }
00193 };
00194 
00195 
00197 
00198 class atsc_data_segment {
00199  public:
00200   static const int NPAD = 188;
00201   plinfo        pli;
00202   unsigned char data[ATSC_DATA_SEGMENT_LENGTH];
00203   unsigned char _pad_[NPAD];                            // pad to power of 2 (1024)
00204 
00205   // overload equality operator
00206   bool operator== (const atsc_data_segment &other) const {
00207     return std::memcmp (data, other.data, sizeof (data)) == 0;
00208   }
00209 
00210   bool operator!= (const atsc_data_segment &other) const {
00211     return !(std::memcmp (data, other.data, sizeof (data)) == 0);
00212   }
00213 };
00214 
00221 class atsc_soft_data_segment {
00222  public:
00223   static const int NPAD = 764;
00224   plinfo        pli;
00225   float         data[ATSC_DATA_SEGMENT_LENGTH];
00226   unsigned char _pad_[NPAD];                    // pad to power of 2 (4096)
00227 
00228   // overload equality operator
00229   bool operator== (const atsc_data_segment &other) const {
00230     return std::memcmp (data, other.data, sizeof (data)) == 0;
00231   }
00232 
00233   bool operator!= (const atsc_data_segment &other) const {
00234     return !(std::memcmp (data, other.data, sizeof (data)) == 0);
00235   }
00236 };
00237 
00238 
00239 #endif /* _ATSC_TYPES_H_ */

Generated on Wed Jun 11 10:17:11 2008 for GNU Radio 3.1.2 by  doxygen 1.5.6