Revision 59be6a47 src/demuxer.cpp

View differences:

src/demuxer.cpp
36 36

  
37 37
#include <linux/dvb/dmx.h>
38 38

  
39
#define IPACKS 2048
40
#define TS_SIZE 188
41

  
42 39
static void set_ts_filt(int fd,uint16_t pid, dmx_pes_type_t pestype);
43 40

  
44
Demuxer::Demuxer(Tuner *tuner, int pid, bool convertToPS, Demuxer::PESType pestype)
41
Demuxer::Demuxer(Tuner *tuner, int pid, Demuxer::PESType pestype)
45 42
  : tuner(tuner), pid(pid), demuxFD(-1)
46 43
{
47
  init_ipack(&packer, IPACKS, output, 1);
48

  
49 44
  switch (pestype) {
50 45
  case Video: this->pesType = int(DMX_PES_VIDEO); break;
51 46
  case Audio: this->pesType = int(DMX_PES_AUDIO); break;
52 47
  case Teletext: this->pesType = int(DMX_PES_TELETEXT); break;
53 48
  }
54
  packer.data = this;
55 49
}
56 50

  
57 51
Demuxer::~Demuxer()
58 52
{
59 53
  unsubscribeAll();
60
  free_ipack(&packer);
61
}
62

  
63
// Static function for use by the ipack code
64
void Demuxer::output(uint8_t *data, int size, void *priv)
65
{
66
  Demuxer *d = (Demuxer *) priv;
67
  d->sendData(data, (unsigned) size);
68 54
}
69 55

  
70 56
bool Demuxer::openDemux()
......
136 122
}
137 123

  
138 124

  
139
void Demuxer::receiveData(unsigned char *data, unsigned size)
125
// From transform.c (Marcus Metzler)
126
#define PID_MASK_HI 0x1F
127
static inline uint16_t get_pid(uint8_t *pid)
140 128
{
141
  if (convertToPS) {
142
    // adapted from my_ts_to_ps( uint8_t* buf, uint16_t pida, uint16_t pidv)
143
    // in dvbstream.c (Dave Chapman)
144

  
145
    uint16_t pid;
146
    ipack *p = &this->packer;
147
    uint8_t off = 0;
148
    uint8_t *buf = (uint8_t *) data;
149

  
150
    pid = get_pid(buf+1);
151
    if (!(buf[3]&0x10)) // no payload?
152
      return;
153

  
154
    // Is this our packet?
155
    if (pid != this->pid)
156
      return;
157

  
158
    if ( buf[1]&0x40) {
159
      if (p->plength == MMAX_PLENGTH-6){
160
	p->plength = p->found-6;
161
	p->found = 0;
162
	send_ipack(p);
163
	reset_ipack(p);
164
      }
165
    }
129
  uint16_t pp = 0;
166 130

  
167
    if ( buf[3] & 0x20) {  // adaptation field?
168
      off = buf[4] + 1;
169
    }
170
        
171
    instant_repack(buf+4+off, TS_SIZE-4-off, p);
172
  }
173
  else {
174
    if (get_pid(data + 1) == pid)
175
      sendData(data, (unsigned) size);
176
  }
131
  pp = (pid[0] & PID_MASK_HI)<<8;
132
  pp |= pid[1];
133

  
134
  return pp;
135
}
136

  
137
void Demuxer::receiveData(unsigned char *data, unsigned size)
138
{
139
  if (get_pid(data + 1) == pid)
140
    sendData(data, (unsigned) size);
177 141
}
178 142

  
179 143
static void set_ts_filt(int fd,uint16_t pid, dmx_pes_type_t pestype)

Also available in: Unified diff