00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _TS_H
00024 #define _TS_H
00025
00026 #include <stdint.h>
00027 #include <pthread.h>
00028
00029 #include "types.h"
00030 #include "dvb.h"
00031 #include "services.h"
00032 #include "multiplexes.h"
00033 #include "list.h"
00034
00035
00044 #define TSPACKET_SIZE (188)
00045
00050 typedef struct TSPacket_t
00051 {
00052 uint8_t header[4];
00053 uint8_t payload[TSPACKET_SIZE - 4];
00054 }
00055 TSPacket_t;
00056
00062 #define TSPACKET_GETPID(packet) \
00063 (((((packet).header[1] & 0x1f) << 8) | ((packet).header[2] & 0xff)))
00064
00070 #define TSPACKET_SETPID(packet, pid) \
00071 do{ \
00072 (packet).header[1] = ((packet).header[1] & 0xe0) | ((pid >> 8) & 0x1f); \
00073 (packet).header[2] = pid & 0xff; \
00074 }while(0)
00075
00080 #define TSPACKET_GETCOUNT(packet) \
00081 ((packet).header[3] & 0x0f)
00082
00088 #define TSPACKET_SETCOUNT(packet, count) \
00089 ((packet).header[3] = ((packet).header[3] & 0xf0) | ((count) & 0x0f))
00090
00095 #define TSPACKET_ISPAYLOADUNITSTART(packet) \
00096 (((packet).header[1] & 0x40) == 0x40)
00097
00103 #define TSPACKET_ISVALID(packet) \
00104 (((packet).header[1] & 0x80) == 0x00)
00105
00111 #define TSPACKET_GETPRIORITY(packet) \
00112 (((packet).header[1] & 0x20) >> 4)
00113
00119 #define TSPACKET_SETPRIORITY(packet, priority) \
00120 ((packet).header[1] = ((packet).header[1] & 0xdf) | (((priority) << 4) & 0x20))
00121
00127 #define TSPACKET_GETADAPTATION(packet) \
00128 (((packet).header[3] & 0x30) >> 4)
00129
00135 #define TSPACKET_SETADAPTATION(packet, adaptation) \
00136 ((packet).header[3] = ((packet).header[3] & 0xcf) | (((adaptation) << 4) & 0x30))
00137
00143 #define TSPACKET_GETADAPTATION_LEN(packet) \
00144 ((packet).payload[0])
00145
00146
00154 struct PIDFilter_s;
00155
00156
00163 typedef void (*MultiplexChanged)(struct PIDFilter_s *pidfilter, void *userarg, Multiplex_t *multiplex);
00164
00171 typedef void (*TSStructureChanged)(struct PIDFilter_s *pidfilter, void *userarg);
00172
00184 typedef int (*PacketFilter)(struct PIDFilter_s *pidfilter, void *userarg, uint16_t pid, TSPacket_t* packet);
00185
00196 typedef TSPacket_t* (*PacketProcessor)(struct PIDFilter_s *pidfilter, void *userarg, TSPacket_t* packet);
00197
00204 typedef void (*PacketOutput)(struct PIDFilter_s *pidfilter, void *userarg, TSPacket_t* packet);
00205
00206
00210 typedef struct PIDFilter_s
00211 {
00212 char *name;
00213 char *type;
00214 struct TSFilter_t *tsFilter;
00215 volatile bool enabled;
00217 MultiplexChanged multiplexChanged;
00218 void *mcArg;
00220 TSStructureChanged tsStructureChanged;
00221 void *tscArg;
00223 PacketFilter filterPacket;
00224 void *fpArg;
00226 PacketProcessor processPacket;
00227 void *ppArg;
00229 PacketOutput outputPacket;
00230 void *opArg;
00232
00233 volatile unsigned long long packetsFiltered;
00234 volatile unsigned long long packetsProcessed;
00235 volatile unsigned long long packetsOutput;
00236 }PIDFilter_t;
00237
00241 extern char PSISIPIDFilterType[];
00242
00250
00254 #define MAX_PIDS 20
00255
00260 typedef struct PIDFilterSimpleFilter_t
00261 {
00262 int pidcount;
00263 uint16_t pids[MAX_PIDS];
00264 }
00265 PIDFilterSimpleFilter_t;
00266
00269
00277 #define MAX_FILTERS 20
00278
00282 #define MAX_PACKETS 20
00283
00287 typedef struct TSFilter_t
00288 {
00289 bool quit;
00290 TSPacket_t readBuffer[MAX_PACKETS];
00291 DVBAdapter_t *adapter;
00292 pthread_t thread;
00293 bool enabled;
00294 pthread_mutex_t mutex;
00295 bool multiplexChanged;
00296 Multiplex_t *multiplex;
00297 bool tsStructureChanged;
00299 volatile unsigned long long totalPackets;
00300 volatile unsigned long bitrate;
00302 List_t *pidFilters;
00303 }
00304 TSFilter_t;
00305
00312 TSFilter_t* TSFilterCreate(DVBAdapter_t *adapter);
00313
00318 void TSFilterDestroy(TSFilter_t * tsfilter);
00319
00325 void TSFilterEnable(TSFilter_t * tsfilter, bool enable);
00326
00332 void TSFilterZeroStats(TSFilter_t *tsfilter);
00333
00339 void TSFilterMultiplexChanged(TSFilter_t *tsfilter, Multiplex_t *newmultiplex);
00340
00345 #define TSFilterLock(tsfilter) pthread_mutex_lock(&(tsfilter)->mutex)
00346
00351 #define TSFilterUnLock(tsfilter) pthread_mutex_unlock(&(tsfilter)->mutex)
00352
00360 PIDFilter_t* TSFilterFindPIDFilter(TSFilter_t *tsfilter, const char *name, const char *type);
00361
00373 PIDFilter_t* PIDFilterAllocate(TSFilter_t* tsfilter);
00378 void PIDFilterFree(PIDFilter_t * pidfilter);
00379
00391 PIDFilter_t *PIDFilterSetup(TSFilter_t *tsfilter,
00392 PacketFilter filterpacket, void *fparg,
00393 PacketProcessor processpacket, void *pparg,
00394 PacketOutput outputpacket, void *oparg);
00395
00402 #define PIDFilterFilterPacketSet(_pidfilter, _callback, _arg) \
00403 do{ (_pidfilter)->fpArg = _arg; (_pidfilter)->filterPacket = _callback; } while(0)
00404
00410 #define PIDFilterProcessPacketSet(_pidfilter, _callback, _arg) \
00411 do{ (_pidfilter)->ppArg = _arg; (_pidfilter)->processPacket = _callback; } while(0)
00412
00418 #define PIDFilterOutputPacketSet(_pidfilter, _callback, _arg) \
00419 do{ (_pidfilter)->opArg = _arg; (_pidfilter)->outputPacket = _callback; } while(0)
00420
00426 #define PIDFilterTSStructureChangeSet(_pidfilter, _callback, _arg) \
00427 do{ (_pidfilter)->tscArg = _arg; (_pidfilter)->tsStructureChanged = _callback; } while(0)
00428
00434 #define PIDFilterMultiplexChangeSet(_pidfilter, _callback, _arg) \
00435 do{ (_pidfilter)->mcArg = _arg; (_pidfilter)->multiplexChanged = _callback; } while(0)
00436
00446 int PIDFilterSimpleFilter(PIDFilter_t *pidfilter, void *arg, uint16_t pid, TSPacket_t *packet);
00447
00448 #endif