1 /*****************************************************************************
2  * ts_pid.h: Transport Stream input module for VLC.
3  *****************************************************************************
4  * Copyright (C) 2004-2016 VLC authors and VideoLAN
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *****************************************************************************/
19 #ifndef VLC_TS_PID_H
20 #define VLC_TS_PID_H
21 
22 #include "ts_pid_fwd.h"
23 
24 #define MIN_ES_PID 4    /* Should be 32.. broken muxers */
25 #define MAX_ES_PID 8190
26 
27 #include "ts_streams.h"
28 
29 typedef enum
30 {
31     TYPE_FREE = 0,
32     TYPE_CAT,
33     TYPE_PAT,
34     TYPE_PMT,
35     TYPE_STREAM,
36     TYPE_SI,
37     TYPE_PSIP,
38 } ts_pid_type_t;
39 
40 enum
41 {
42     FLAGS_NONE = 0,
43     FLAG_SEEN  = 1,
44     FLAG_SCRAMBLED = 2,
45     FLAG_FILTERED = 4
46 };
47 
48 #define SEEN(x) ((x)->i_flags & FLAG_SEEN)
49 #define SCRAMBLED(x) ((x).i_flags & FLAG_SCRAMBLED)
50 #define PREVPKTKEEPBYTES 16
51 
52 struct ts_pid_t
53 {
54     uint16_t    i_pid;
55 
56     uint8_t     i_flags;
57     uint8_t     i_cc;   /* countinuity counter */
58     uint8_t     i_dup;  /* duplicate counter */
59     uint8_t     type;
60     uint8_t     prevpktbytes[PREVPKTKEEPBYTES];
61 
62     uint16_t    i_refcount;
63 
64     /* */
65     union
66     {
67         ts_pat_t    *p_pat;
68         ts_pmt_t    *p_pmt;
69         ts_stream_t    *p_stream;
70         ts_si_t     *p_si;
71         ts_psip_t   *p_psip;
72     } u;
73 
74     struct
75     {
76         vlc_fourcc_t i_fourcc;
77         vlc_fourcc_t i_original_fourcc;
78         int i_cat;
79         int i_pcr_count;
80         uint8_t i_stream_id;
81     } probed;
82 
83 };
84 
85 struct ts_pid_list_t
86 {
87     ts_pid_t   pat;
88     ts_pid_t   dummy;
89     ts_pid_t   base_si;
90     /* all non commons ones, dynamically allocated */
91     ts_pid_t **pp_all;
92     int        i_all;
93     int        i_all_alloc;
94     /* last recently used */
95     uint16_t   i_last_pid;
96     ts_pid_t  *p_last;
97 
98 };
99 
100 /* opacified pid list */
101 void ts_pid_list_Init( ts_pid_list_t * );
102 void ts_pid_list_Release( demux_t *, ts_pid_list_t * );
103 
104 /* creates missing pid on the fly */
105 ts_pid_t * ts_pid_Get( ts_pid_list_t *, uint16_t i_pid );
106 
107 /* returns NULL on end. requires context */
108 typedef struct
109 {
110     int i_pos;
111 } ts_pid_next_context_t;
112 #define ts_pid_NextContextInitValue { 0 }
113 ts_pid_t * ts_pid_Next( ts_pid_list_t *, ts_pid_next_context_t * );
114 
115 /* for legacy only: don't use and pass directly list reference */
116 #define GetPID(p_sys, i_pid) ts_pid_Get((&(p_sys)->pids), i_pid)
117 
118 int UpdateHWFilter( demux_sys_t *, ts_pid_t * );
119 int SetPIDFilter( demux_sys_t *, ts_pid_t *, bool b_selected );
120 
121 bool PIDSetup( demux_t *p_demux, ts_pid_type_t i_type, ts_pid_t *pid, ts_pid_t *p_parent );
122 void PIDRelease( demux_t *p_demux, ts_pid_t *pid );
123 
124 
125 #endif
126