dvbd / src / psfilter.cpp @ 59be6a47
History | View | Annotate | Download (2.23 KB)
1 |
/*
|
---|---|
2 |
Copyright 2003 John Knottenbelt
|
3 |
|
4 |
This program is free software; you can redistribute it and/or modify
|
5 |
it under the terms of the GNU General Public License as published by
|
6 |
the Free Software Foundation; either version 2 of the License, or
|
7 |
(at your option) any later version.
|
8 |
|
9 |
This program is distributed in the hope that it will be useful,
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
GNU General Public License for more details.
|
13 |
You should have received a copy of the GNU General Public License
|
14 |
along with this program; if not, write to the Free Software
|
15 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
16 |
*/
|
17 |
|
18 |
#include "config.h" |
19 |
#include "psfilter.h" |
20 |
|
21 |
#define IPACKS 2048 |
22 |
#define TS_SIZE 188 |
23 |
|
24 |
PSFilter::PSFilter(Source *source) |
25 |
: source(source) |
26 |
{ |
27 |
init_ipack(&packer, IPACKS, output, 1);
|
28 |
packer.data = this;
|
29 |
} |
30 |
|
31 |
PSFilter::~PSFilter() |
32 |
{ |
33 |
unsubscribeAll(); |
34 |
free_ipack(&packer); |
35 |
} |
36 |
|
37 |
// Static function for use by the ipack code
|
38 |
void PSFilter::output(uint8_t *data, int size, void *priv) |
39 |
{ |
40 |
PSFilter *d = static_cast<PSFilter *>(priv);
|
41 |
d->sendData(data, (unsigned) size);
|
42 |
} |
43 |
|
44 |
void PSFilter::unsubscribe(Sink *s)
|
45 |
{ |
46 |
Source::unsubscribe(s); |
47 |
if (getNumSubscribers() == 0) { |
48 |
source->unsubscribe(this);
|
49 |
reset_ipack(&packer); |
50 |
} |
51 |
} |
52 |
|
53 |
void PSFilter::notifyUnsubscribe(Source *)
|
54 |
{ |
55 |
// Since our source is no longer available
|
56 |
// we should unsubscribe the clients.
|
57 |
unsubscribeAll(); |
58 |
} |
59 |
|
60 |
bool PSFilter::subscribe(Sink *s)
|
61 |
{ |
62 |
if (getNumSubscribers() == 0) { |
63 |
if (!source->subscribe(this)) |
64 |
return false; |
65 |
} |
66 |
return Source::subscribe(s);
|
67 |
} |
68 |
|
69 |
void PSFilter::receiveData(unsigned char *data, unsigned size) |
70 |
{ |
71 |
// adapted from my_ts_to_ps( uint8_t* buf, uint16_t pida, uint16_t pidv)
|
72 |
// in dvbstream.c (Dave Chapman)
|
73 |
|
74 |
ipack *p = &packer; |
75 |
uint8_t off = 0;
|
76 |
uint8_t *buf = (uint8_t *) data; |
77 |
|
78 |
if (!(buf[3]&0x10)) // no payload? |
79 |
return;
|
80 |
|
81 |
if ( buf[1]&0x40) { |
82 |
if (p->plength == MMAX_PLENGTH-6){ |
83 |
p->plength = p->found-6;
|
84 |
p->found = 0;
|
85 |
send_ipack(p); |
86 |
reset_ipack(p); |
87 |
} |
88 |
} |
89 |
|
90 |
if ( buf[3] & 0x20) { // adaptation field? |
91 |
off = buf[4] + 1; |
92 |
} |
93 |
|
94 |
instant_repack(buf+4+off, TS_SIZE-4-off, p); |
95 |
} |