Mercurial > mplayer.hg
annotate libmpdemux/demux_ts.c @ 13153:4fd062533921
fixed the removal of French maintainer of the Doc Nicolas Le Gaillart
author | gpoirier |
---|---|
date | Thu, 26 Aug 2004 13:32:36 +0000 |
parents | a731d98a3382 |
children | ec342714b8a9 |
rev | line source |
---|---|
9610 | 1 /* |
2 * Demultiplexer for MPEG2 Transport Streams. | |
3 * | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
4 * Written by Nico <nsabbi@libero.it> |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
5 * Kind feedback is appreciated; 'sucks' and alike is not. |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
6 * Originally based on demux_pva.c written by Matteo Giani and FFmpeg (libavformat) sources |
10014 | 7 * |
8 * This file is free software; you can redistribute it and/or | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
9 * modify it under the terms of the GNU General Public |
9610 | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | |
12 * | |
10014 | 13 * This file is distributed in the hope that it will be useful, |
9610 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this library; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
22 |
9610 | 23 |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 | |
28 #include "config.h" | |
29 #include "mp_msg.h" | |
30 #include "help_mp.h" | |
31 | |
32 #include "stream.h" | |
33 #include "demuxer.h" | |
11412 | 34 #include "parse_es.h" |
9610 | 35 #include "stheader.h" |
36 | |
37 #include "bswap.h" | |
11190 | 38 #include "../unrarlib.h" |
9610 | 39 |
40 | |
41 #define TS_FEC_PACKET_SIZE 204 | |
42 #define TS_PACKET_SIZE 188 | |
43 #define NB_PID_MAX 8192 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
44 |
9610 | 45 #define MAX_HEADER_SIZE 6 /* enough for PES header + length */ |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
46 #define MAX_CHECK_SIZE 65535 |
11190 | 47 #define TS_MAX_PROBE_SIZE 2000000 /* dont forget to change this in cfg-common.h too */ |
10014 | 48 #define NUM_CONSECUTIVE_TS_PACKETS 32 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
49 #define NUM_CONSECUTIVE_AUDIO_PACKETS 348 |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
50 #define MAX_A52_FRAME_SIZE 3840 |
9610 | 51 |
52 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
53 int ts_prog; |
11190 | 54 int ts_keep_broken=0; |
55 off_t ts_probe = TS_MAX_PROBE_SIZE; | |
56 extern char *dvdsub_lang, *audio_lang; //for -alang | |
9610 | 57 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
58 typedef enum |
9610 | 59 { |
60 UNKNOWN = -1, | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
61 VIDEO_MPEG1 = 0x10000001, |
9610 | 62 VIDEO_MPEG2 = 0x10000002, |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
63 VIDEO_MPEG4 = 0x10000004, |
9610 | 64 AUDIO_MP2 = 0x50, |
65 AUDIO_A52 = 0x2000, | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
66 AUDIO_LPCM_BE = 0x10001, |
11190 | 67 AUDIO_AAC = mmioFOURCC('M', 'P', '4', 'A'), |
9610 | 68 SPU_DVD = 0x3000000, |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
69 SPU_DVB = 0x3000001, |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
70 PES_PRIVATE1 = 0xBD00000 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
71 } es_stream_type_t; |
9610 | 72 |
73 | |
74 typedef struct { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
75 int size; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
76 unsigned char *start; |
10014 | 77 uint16_t payload_size; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
78 es_stream_type_t type; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
79 float pts, last_pts; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
80 int pid; |
11190 | 81 char lang[4]; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
82 int last_cc; // last cc code (-1 if first packet) |
11190 | 83 uint64_t seen; |
10014 | 84 } ES_stream_t; |
85 | |
9610 | 86 |
10014 | 87 typedef struct MpegTSContext { |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
88 int packet_size; // raw packet size, including FEC if present e.g. 188 bytes |
10014 | 89 ES_stream_t *pids[NB_PID_MAX]; |
90 } MpegTSContext; | |
9610 | 91 |
10014 | 92 |
93 typedef struct { | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
94 demux_stream_t *ds; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
95 demux_packet_t *pack; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
96 int offset, buffer_size; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
97 } av_fifo_t; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
98 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
99 typedef struct { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
100 uint8_t skip; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
101 uint8_t table_id; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
102 uint8_t ssi; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
103 uint16_t section_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
104 uint16_t ts_id; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
105 uint8_t version_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
106 uint8_t curr_next; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
107 uint8_t section_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
108 uint8_t last_section_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
109 struct pat_progs_t { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
110 uint16_t id; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
111 uint16_t pmt_pid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
112 } *progs; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
113 uint16_t progs_cnt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
114 char buffer[65535]; |
11190 | 115 uint16_t buffer_len; |
116 } pat_t; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
117 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
118 typedef struct { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
119 uint16_t progid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
120 uint8_t skip; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
121 uint8_t table_id; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
122 uint8_t ssi; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
123 uint16_t section_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
124 uint8_t version_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
125 uint8_t curr_next; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
126 uint8_t section_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
127 uint8_t last_section_number; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
128 uint16_t PCR_PID; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
129 uint16_t prog_descr_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
130 char buffer[2048]; |
11190 | 131 uint16_t buffer_len; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
132 uint16_t es_cnt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
133 struct pmt_es_t { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
134 uint16_t pid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
135 uint32_t type; //it's 8 bit long, but cast to the right type as FOURCC |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
136 uint16_t descr_length; |
11190 | 137 uint8_t format_descriptor[5]; |
138 uint8_t lang[4]; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
139 } *es; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
140 } pmt_t; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
141 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
142 typedef struct { |
10014 | 143 MpegTSContext ts; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
144 int last_pid; |
11190 | 145 av_fifo_t fifo[3]; //0 for audio, 1 for video, 2 for subs |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
146 pat_t pat; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
147 pmt_t *pmt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
148 uint16_t pmt_cnt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
149 uint32_t prog; |
11190 | 150 int keep_broken; |
10014 | 151 } ts_priv_t; |
152 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
153 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
154 static int ts_parse(demuxer_t *demuxer, ES_stream_t *es, unsigned char *packet, int probe); |
10310
68e714ed669f
fix one missing #include, one missing extern and one 10l error.
rathann
parents:
10259
diff
changeset
|
155 extern void resync_audio_stream( sh_audio_t *sh_audio ); |
9610 | 156 |
157 static uint8_t get_packet_size(const unsigned char *buf, int size) | |
158 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
159 int i; |
9610 | 160 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
161 if (size < (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS)) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
162 return 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
163 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
164 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++) |
9610 | 165 { |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
166 if (buf[i * TS_PACKET_SIZE] != 0x47) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
167 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
168 mp_msg(MSGT_DEMUX, MSGL_DBG2, "GET_PACKET_SIZE, pos %d, char: %2x\n", i, buf[i * TS_PACKET_SIZE]); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
169 goto try_fec; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
170 } |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
171 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
172 return TS_PACKET_SIZE; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
173 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
174 try_fec: |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
175 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
176 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
177 if (buf[i * TS_FEC_PACKET_SIZE] != 0x47) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
178 return 0; |
9610 | 179 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
180 return TS_FEC_PACKET_SIZE; |
9610 | 181 } |
182 | |
183 | |
184 | |
185 int ts_check_file(demuxer_t * demuxer) | |
186 { | |
187 const int buf_size = (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS); | |
10841
d4cf5407d7c6
Fix a gcc 3.x crash when compiling demux_ts.c with -g -O4 (or -O3). Patch by Arpi.
mosu
parents:
10735
diff
changeset
|
188 unsigned char buf[TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS], done = 0, *ptr; |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
189 uint32_t _read, i, count = 0, is_ts; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
190 int cc[NB_PID_MAX], last_cc[NB_PID_MAX], pid, cc_ok, c, good, bad; |
9610 | 191 uint8_t size = 0; |
192 off_t pos = 0; | |
11190 | 193 off_t init_pos; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
194 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
195 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for MPEG-TS...\n"); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
196 |
11190 | 197 init_pos = stream_tell(demuxer->stream); |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
198 is_ts = 0; |
9610 | 199 while(! done) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
200 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
201 i = 1; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
202 c = 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
203 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
204 while(((c=stream_read_char(demuxer->stream)) != 0x47) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
205 && (c >= 0) |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
206 && (i < MAX_CHECK_SIZE) |
10014 | 207 && ! demuxer->stream->eof |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
208 ) i++; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
209 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
210 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
211 if(c != 0x47) |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
212 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
213 mp_msg(MSGT_DEMUX, MSGL_V, "THIS DOESN'T LOOK LIKE AN MPEG-TS FILE!\n"); |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
214 is_ts = 0; |
10014 | 215 done = 1; |
216 continue; | |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
217 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
218 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
219 pos = stream_tell(demuxer->stream) - 1; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
220 buf[0] = c; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
221 _read = stream_read(demuxer->stream, &buf[1], buf_size-1); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
222 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
223 if(_read < buf_size-1) |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
224 { |
10014 | 225 mp_msg(MSGT_DEMUX, MSGL_V, "COULDN'T READ ENOUGH DATA, EXITING TS_CHECK\n"); |
226 stream_reset(demuxer->stream); | |
227 return 0; | |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
228 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
229 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
230 size = get_packet_size(buf, buf_size); |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
231 if(size) |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
232 { |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
233 done = 1; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
234 is_ts = 1; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
235 } |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
236 |
11190 | 237 if(pos - init_pos >= MAX_CHECK_SIZE) |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
238 { |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
239 done = 1; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
240 is_ts = 0; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
241 } |
10014 | 242 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
243 |
11190 | 244 mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %llu, FOUND %x, packet_size= %d, SEEMS A TS? %d\n", (uint64_t) pos, c, size, is_ts); |
10014 | 245 stream_seek(demuxer->stream, pos); |
246 | |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
247 if(! is_ts) |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
248 return 0; |
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
249 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
250 //LET'S CHECK continuity counters |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
251 good = bad = 0; |
10014 | 252 for(count = 0; count < NB_PID_MAX; count++) |
253 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
254 cc[count] = last_cc[count] = -1; |
9610 | 255 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
256 |
10014 | 257 for(count = 0; count < NUM_CONSECUTIVE_TS_PACKETS; count++) |
258 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
259 ptr = &(buf[size * count]); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
260 pid = ((ptr[1] & 0x1f) << 8) | ptr[2]; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
261 mp_msg(MSGT_DEMUX, MSGL_DBG2, "BUF: %02x %02x %02x %02x, PID %d, SIZE: %d \n", |
10014 | 262 ptr[0], ptr[1], ptr[2], ptr[3], pid, size); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
263 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
264 if((pid == 8191) || (pid < 16)) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
265 continue; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
266 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
267 cc[pid] = (ptr[3] & 0xf); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
268 cc_ok = (last_cc[pid] < 0) || ((((last_cc[pid] + 1) & 0x0f) == cc[pid])); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
269 mp_msg(MSGT_DEMUX, MSGL_DBG2, "PID %d, COMPARE CC %d AND LAST_CC %d\n", pid, cc[pid], last_cc[pid]); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
270 if(! cc_ok) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
271 //return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
272 bad++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
273 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
274 good++; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
275 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
276 last_cc[pid] = cc[pid]; |
10014 | 277 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
278 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
279 mp_msg(MSGT_DEMUX, MSGL_V, "GOOD CC: %d, BAD CC: %d\n", good, bad); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
280 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
281 if(good >= bad) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
282 return size; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
283 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
284 return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
285 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
286 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
287 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
288 static inline int32_t progid_idx_in_pmt(ts_priv_t *priv, uint16_t progid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
289 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
290 int x; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
291 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
292 if(priv->pmt == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
293 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
294 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
295 for(x = 0; x < priv->pmt_cnt; x++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
296 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
297 if(priv->pmt[x].progid == progid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
298 return x; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
299 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
300 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
301 return -1; |
9610 | 302 } |
303 | |
304 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
305 static inline int32_t progid_for_pid(ts_priv_t *priv, int pid, int32_t req) //finds the first program listing a pid |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
306 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
307 int i, j; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
308 pmt_t *pmt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
309 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
310 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
311 if(priv->pmt == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
312 return -1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
313 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
314 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
315 for(i=0; i < priv->pmt_cnt; i++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
316 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
317 pmt = &(priv->pmt[i]); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
318 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
319 if(pmt->es == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
320 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
321 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
322 for(j = 0; j < pmt->es_cnt; j++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
323 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
324 if(pmt->es[j].pid == pid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
325 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
326 if((req == 0) || (req == pmt->progid)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
327 return pmt->progid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
328 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
329 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
330 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
331 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
332 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
333 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
334 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
335 |
11190 | 336 static inline int pid_match_lang(ts_priv_t *priv, uint16_t pid, char *lang) |
9610 | 337 { |
11190 | 338 uint16_t i, j; |
339 pmt_t *pmt; | |
340 | |
341 if(priv->pmt == NULL) | |
342 return -1; | |
343 | |
344 for(i=0; i < priv->pmt_cnt; i++) | |
345 { | |
346 pmt = &(priv->pmt[i]); | |
347 | |
348 if(pmt->es == NULL) | |
349 return -1; | |
350 | |
351 for(j = 0; j < pmt->es_cnt; j++) | |
352 { | |
353 if(pmt->es[j].pid != pid) | |
354 continue; | |
355 | |
356 mp_msg(MSGT_DEMUXER, MSGL_V, "CMP LANG %s AND %s, pids: %d %d\n",pmt->es[j].lang, lang, pmt->es[j].pid, pid); | |
357 if(strncmp(pmt->es[j].lang, lang, 3) == 0) | |
358 { | |
359 return 1; | |
360 } | |
361 } | |
362 | |
363 } | |
364 | |
365 return -1; | |
366 } | |
367 | |
368 typedef struct { | |
369 int32_t atype, vtype, stype; //types | |
370 int32_t apid, vpid, spid; //stream ids | |
371 char slang[4], alang[4]; //languages | |
372 int16_t prog; | |
373 off_t probe; | |
374 } tsdemux_init_t; | |
375 | |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
376 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
377 //second stage: returns the count of A52 syncwords found |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
378 static int a52_check(char *buf, int len) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
379 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
380 int cnt, frame_length, flags, sample_rate, bit_rate, ok; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
381 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
382 cnt = ok = 0; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
383 if(len < 8) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
384 return 0; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
385 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
386 while(cnt < len - 7) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
387 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
388 if(buf[cnt] == 0x0B && buf[cnt+1] == 0x77) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
389 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
390 frame_length = a52_syncinfo(&buf[cnt], &flags, &sample_rate, &bit_rate); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
391 if(frame_length>=7 && frame_length<=3840) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
392 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
393 cnt += frame_length; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
394 ok++; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
395 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
396 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
397 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
398 cnt++; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
399 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
400 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
401 mp_msg(MSGT_DEMUXER, MSGL_V, "A52_CHECK(%d input bytes), found %d frame syncwords of %d bytes length\n", len, ok, frame_length); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
402 return ok; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
403 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
404 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
405 |
11190 | 406 static off_t ts_detect_streams(demuxer_t *demuxer, tsdemux_init_t *param) |
407 { | |
408 int video_found = 0, audio_found = 0, sub_found = 0, i, num_packets = 0, req_apid, req_vpid, req_spid; | |
409 int is_audio, is_video, is_sub, has_tables; | |
410 int32_t p, chosen_pid = 0; | |
411 off_t pos=0, ret = 0, init_pos; | |
10014 | 412 ES_stream_t es; |
9610 | 413 unsigned char tmp[TS_FEC_PACKET_SIZE]; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
414 ts_priv_t *priv = (ts_priv_t*) demuxer->priv; |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
415 struct { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
416 char *buf; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
417 int pos; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
418 } pes_priv1[8192], *pptr; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
419 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
420 priv->last_pid = 8192; //invalid pid |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
421 |
11190 | 422 req_apid = param->apid; |
423 req_vpid = param->vpid; | |
424 req_spid = param->spid; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
425 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
426 has_tables = 0; |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
427 bzero(pes_priv1, sizeof(pes_priv1)); |
11190 | 428 init_pos = stream_tell(demuxer->stream); |
429 mp_msg(MSGT_DEMUXER, MSGL_INFO, "PROBING UP TO %llu, PROG: %d\n", (uint64_t) param->probe, param->prog); | |
430 while((pos <= init_pos + param->probe) && (! demuxer->stream->eof)) | |
9610 | 431 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
432 pos = stream_tell(demuxer->stream); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
433 if(ts_parse(demuxer, &es, tmp, 1)) |
9610 | 434 { |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
435 //Non PES-aligned A52 audio may escape detection if PMT is not present; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
436 //in this case we try to find at least 3 A52 syncwords |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
437 if((es.type == PES_PRIVATE1) && (! audio_found)) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
438 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
439 pptr = &pes_priv1[es.pid]; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
440 pptr->buf = (char*) realloc(pptr->buf, pptr->pos + es.size); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
441 if(pptr->buf != NULL) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
442 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
443 memcpy(&(pptr->buf[ pptr->pos ]), es.start, es.size); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
444 pptr->pos += es.size; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
445 if(a52_check(pptr->buf, pptr->pos) > 2) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
446 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
447 param->atype = AUDIO_A52; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
448 es.type = AUDIO_A52; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
449 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
450 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
451 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
452 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
453 is_audio = ((es.type == AUDIO_MP2) || (es.type == AUDIO_A52) || (es.type == AUDIO_LPCM_BE) || (es.type == AUDIO_AAC)); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
454 is_video = ((es.type == VIDEO_MPEG1) || (es.type == VIDEO_MPEG2) || (es.type == VIDEO_MPEG4)); |
11190 | 455 is_sub = ((es.type == SPU_DVD) || (es.type == SPU_DVB)); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
456 |
11190 | 457 |
458 if((! is_audio) && (! is_video) && (! is_sub)) | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
459 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
460 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
461 if(is_video) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
462 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
463 chosen_pid = (req_vpid == es.pid); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
464 if((! chosen_pid) && (req_vpid > 0)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
465 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
466 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
467 else if(is_audio) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
468 { |
11190 | 469 if(req_apid > 0) |
470 { | |
471 chosen_pid = (req_apid == es.pid); | |
472 if(! chosen_pid) | |
473 continue; | |
474 } | |
475 else if(param->alang[0] > 0) | |
476 { | |
477 if(pid_match_lang(priv, es.pid, param->alang) == -1) | |
478 continue; | |
479 | |
480 chosen_pid = 1; | |
481 param->apid = req_apid = es.pid; | |
482 } | |
483 } | |
484 else if(is_sub) | |
485 { | |
486 chosen_pid = (req_spid == es.pid); | |
487 if((! chosen_pid) && (req_spid > 0)) | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
488 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
489 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
490 |
11190 | 491 if(req_apid < 0 && (param->alang[0] == 0) && req_vpid < 0 && req_spid < 0) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
492 chosen_pid = 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
493 |
11190 | 494 if((ret == 0) && chosen_pid) |
495 { | |
496 ret = stream_tell(demuxer->stream); | |
497 } | |
498 | |
499 p = progid_for_pid(priv, es.pid, param->prog); | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
500 if(p != -1) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
501 has_tables++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
502 |
11190 | 503 if((param->prog == 0) && (p != -1)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
504 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
505 if(chosen_pid) |
11190 | 506 param->prog = p; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
507 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
508 |
11190 | 509 if((param->prog > 0) && (param->prog != p)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
510 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
511 if(audio_found) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
512 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
513 if(is_video && (req_vpid == es.pid)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
514 { |
11190 | 515 param->vtype = es.type; |
516 param->vpid = es.pid; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
517 video_found = 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
518 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
519 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
520 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
521 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
522 if(video_found) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
523 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
524 if(is_audio && (req_apid == es.pid)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
525 { |
11190 | 526 param->atype = es.type; |
527 param->apid = es.pid; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
528 audio_found = 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
529 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
530 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
531 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
532 |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
533 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
534 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
535 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
536 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
537 |
11190 | 538 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "TYPE: %x, PID: %d, PROG FOUND: %d\n", es.type, es.pid, param->prog); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
539 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
540 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
541 if(is_video) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
542 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
543 if((req_vpid == -1) || (req_vpid == es.pid)) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
544 { |
11190 | 545 param->vtype = es.type; |
546 param->vpid = es.pid; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
547 video_found = 1; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
548 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
549 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
550 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
551 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
552 if(((req_vpid == -2) || (num_packets >= NUM_CONSECUTIVE_AUDIO_PACKETS)) && audio_found) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
553 { |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
554 //novideo or we have at least 348 audio packets (64 KB) without video (TS with audio only) |
11190 | 555 param->vtype = 0; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
556 break; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
557 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
558 |
11190 | 559 if(is_sub) |
560 { | |
561 if((req_spid == -1) || (req_spid == es.pid)) | |
562 { | |
563 param->stype = es.type; | |
564 param->spid = es.pid; | |
565 sub_found = 1; | |
566 } | |
567 } | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
568 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
569 if(is_audio) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
570 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
571 if((req_apid == -1) || (req_apid == es.pid)) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
572 { |
11190 | 573 param->atype = es.type; |
574 param->apid = es.pid; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
575 audio_found = 1; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
576 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
577 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
578 |
11190 | 579 if(audio_found && (param->apid == es.pid) && (! video_found)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
580 num_packets++; |
10259
b60e89268837
- discard soon non TS files (previously it took too long, as in the case
arpi
parents:
10253
diff
changeset
|
581 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
582 if((req_apid == -2) && video_found) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
583 { |
11190 | 584 param->atype = 0; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
585 break; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
586 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
587 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
588 if((has_tables==0) && (video_found && audio_found) && (pos >= 1000000)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
589 break; |
9610 | 590 } |
591 } | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
592 |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
593 for(i=0; i<8192; i++) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
594 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
595 if(pes_priv1[i].buf != NULL) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
596 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
597 free(pes_priv1[i].buf); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
598 pes_priv1[i].buf = NULL; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
599 pes_priv1[i].pos = 0; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
600 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
601 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
602 |
9610 | 603 if(video_found) |
11190 | 604 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG%d(pid=%d)...", (param->vtype == VIDEO_MPEG1 ? 1 : (param->vtype == VIDEO_MPEG2 ? 2 : 4)), param->vpid); |
9610 | 605 else |
606 { | |
11190 | 607 video_found = 0; |
608 param->vtype = UNKNOWN; | |
609 //WE DIDN'T MATCH ANY VIDEO STREAM | |
610 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO VIDEO! "); | |
9610 | 611 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
612 |
11190 | 613 if(param->atype == AUDIO_MP2) |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
614 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO MPA(pid=%d)", param->apid); |
11190 | 615 else if(param->atype == AUDIO_A52) |
616 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO A52(pid=%d)", param->apid); | |
617 else if(param->atype == AUDIO_LPCM_BE) | |
618 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO LPCM(pid=%d)", param->apid); | |
619 else if(param->atype == AUDIO_AAC) | |
620 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO AAC(pid=%d)", param->apid); | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
621 else |
9610 | 622 { |
11190 | 623 audio_found = 0; |
624 param->atype = UNKNOWN; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
625 //WE DIDN'T MATCH ANY AUDIO STREAM, SO WE FORCE THE DEMUXER TO IGNORE AUDIO |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
626 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO AUDIO! "); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
627 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
628 |
11190 | 629 if(param->stype == SPU_DVD || param->stype == SPU_DVB) |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
630 mp_msg(MSGT_DEMUXER, MSGL_INFO, " SUB %s(pid=%d) ", (param->stype==SPU_DVD ? "DVD" : "DVB"), param->spid); |
11190 | 631 else |
632 { | |
633 param->stype = UNKNOWN; | |
634 mp_msg(MSGT_DEMUXER, MSGL_INFO, " NO SUBS (yet)! "); | |
635 } | |
636 | |
637 if(video_found || audio_found) | |
638 { | |
639 if(demuxer->stream->eof && (ret == 0)) | |
640 ret = init_pos; | |
641 mp_msg(MSGT_DEMUXER, MSGL_INFO, " PROGRAM N. %d\n", param->prog); | |
642 } | |
643 else | |
644 mp_msg(MSGT_DEMUXER, MSGL_INFO, "\n"); | |
645 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
646 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
647 for(i=0; i<8192; i++) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
648 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
649 if(priv->ts.pids[i] != NULL) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
650 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
651 priv->ts.pids[i]->payload_size = 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
652 priv->ts.pids[i]->pts = priv->ts.pids[i]->last_pts = 0; |
11190 | 653 priv->ts.pids[i]->seen = 0; |
654 priv->ts.pids[i]->last_cc = -1; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
655 } |
9610 | 656 } |
11190 | 657 |
658 return ret; | |
9610 | 659 } |
660 | |
661 | |
10014 | 662 demuxer_t *demux_open_ts(demuxer_t * demuxer) |
663 { | |
664 int i; | |
665 uint8_t packet_size; | |
666 sh_video_t *sh_video; | |
667 sh_audio_t *sh_audio; | |
11190 | 668 off_t start_pos; |
669 tsdemux_init_t params; | |
10014 | 670 ts_priv_t * priv = (ts_priv_t*) demuxer->priv; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
671 |
11190 | 672 mp_msg(MSGT_DEMUX, MSGL_INFO, "DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n", |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
673 demuxer->audio->id, demuxer->video->id, demuxer->sub->id); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
674 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
675 |
10014 | 676 demuxer->type= DEMUXER_TYPE_MPEG_TS; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
677 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
678 |
10014 | 679 stream_reset(demuxer->stream); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
680 |
10014 | 681 packet_size = ts_check_file(demuxer); |
682 if(!packet_size) | |
683 return NULL; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
684 |
10014 | 685 priv = malloc(sizeof(ts_priv_t)); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
686 if(priv == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
687 { |
11190 | 688 mp_msg(MSGT_DEMUX, MSGL_FATAL, "DEMUX_OPEN_TS, couldn't allocate enough memory for ts->priv, exit\n"); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
689 return NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
690 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
691 |
10014 | 692 for(i=0; i < 8192; i++) |
693 priv->ts.pids[i] = NULL; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
694 priv->pat.progs = NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
695 priv->pat.progs_cnt = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
696 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
697 priv->pmt = NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
698 priv->pmt_cnt = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
699 |
11190 | 700 priv->keep_broken = ts_keep_broken; |
10014 | 701 priv->ts.packet_size = packet_size; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
702 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
703 |
10014 | 704 demuxer->priv = priv; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
705 if(demuxer->stream->type != STREAMTYPE_FILE) |
11190 | 706 demuxer->seekable = 1; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
707 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
708 demuxer->seekable = 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
709 |
11190 | 710 |
711 params.atype = params.vtype = params.stype = UNKNOWN; | |
712 params.apid = demuxer->audio->id; | |
713 params.vpid = demuxer->video->id; | |
714 params.spid = demuxer->sub->id; | |
715 params.prog = ts_prog; | |
716 params.probe = ts_probe; | |
717 | |
718 if(dvdsub_lang != NULL) | |
719 { | |
720 strncpy(params.slang, dvdsub_lang, 3); | |
721 params.slang[3] = 0; | |
722 } | |
723 else | |
724 memset(params.slang, 0, 4); | |
725 | |
726 if(audio_lang != NULL) | |
727 { | |
728 strncpy(params.alang, audio_lang, 3); | |
729 params.alang[3] = 0; | |
730 } | |
731 else | |
732 memset(params.alang, 0, 4); | |
733 | |
734 start_pos = ts_detect_streams(demuxer, ¶ms); | |
735 | |
736 demuxer->audio->id = params.apid; | |
737 demuxer->video->id = params.vpid; | |
738 demuxer->sub->id = params.spid; | |
739 priv->prog = params.prog; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
740 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
741 |
11190 | 742 if(params.vtype != UNKNOWN) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
743 { |
11190 | 744 if(params.vtype == VIDEO_MPEG4) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
745 demuxer->file_format= DEMUXER_TYPE_MPEG4_IN_TS; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
746 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
747 sh_video = new_sh_video(demuxer, 0); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
748 sh_video->ds = demuxer->video; |
11190 | 749 sh_video->format = params.vtype; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
750 demuxer->video->sh = sh_video; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
751 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
752 |
11190 | 753 if(params.atype != UNKNOWN) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
754 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
755 sh_audio = new_sh_audio(demuxer, 0); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
756 sh_audio->ds = demuxer->audio; |
11190 | 757 sh_audio->format = params.atype; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
758 demuxer->audio->sh = sh_audio; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
759 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
760 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
761 |
11190 | 762 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer, audio: %x(pid %d), video: %x(pid %d)...POS=%llu\n", params.atype, demuxer->audio->id, params.vtype, demuxer->video->id, (uint64_t) start_pos); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
763 |
10014 | 764 |
11190 | 765 start_pos = (start_pos <= priv->ts.packet_size ? 0 : start_pos - priv->ts.packet_size); |
766 demuxer->movi_start = start_pos; | |
767 stream_reset(demuxer->stream); | |
768 stream_seek(demuxer->stream, start_pos); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES? | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
769 |
11190 | 770 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
771 priv->last_pid = 8192; //invalid pid |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
772 |
11190 | 773 for(i = 0; i < 3; i++) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
774 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
775 priv->fifo[i].pack = NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
776 priv->fifo[i].offset = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
777 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
778 priv->fifo[0].ds = demuxer->audio; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
779 priv->fifo[1].ds = demuxer->video; |
11190 | 780 priv->fifo[2].ds = demuxer->sub; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
781 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
782 priv->fifo[0].buffer_size = 1536; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
783 priv->fifo[1].buffer_size = 32767; |
11190 | 784 priv->fifo[2].buffer_size = 32767; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
785 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
786 priv->pat.buffer_len = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
787 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
788 demuxer->filepos = stream_tell(demuxer->stream); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
789 return demuxer; |
10014 | 790 } |
791 | |
9610 | 792 void demux_close_ts(demuxer_t * demuxer) |
793 { | |
794 if(demuxer->priv) | |
795 { | |
796 free(demuxer->priv); | |
797 demuxer->priv=NULL; | |
798 } | |
799 } | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
800 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
801 static int pes_parse2(unsigned char *buf, uint16_t packet_len, ES_stream_t *es, int32_t type_from_pmt) |
9610 | 802 { |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
803 unsigned char *p; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
804 uint32_t header_len; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
805 int64_t pts; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
806 uint32_t stream_id; |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
807 uint32_t pkt_len, pes_is_aligned; |
9610 | 808 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
809 //Here we are always at the start of a PES packet |
11190 | 810 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2(%p, %d): \n", buf, (uint32_t) packet_len); |
9610 | 811 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
812 if(packet_len == 0) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
813 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
814 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2(,PACKET_LEN = 0, EXIT\n"); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
815 return 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
816 } |
9610 | 817 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
818 if(packet_len > 184) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
819 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
820 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2, BUFFER LEN IS TOO BIG: %d, EXIT\n", packet_len); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
821 return 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
822 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
823 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
824 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
825 p = buf; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
826 pkt_len = packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
827 |
9610 | 828 |
10014 | 829 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: HEADER %02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
830 if (p[0] || p[1] || (p[2] != 1)) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
831 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
832 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: error HEADER %02x %02x %02x (should be 0x000001) \n", p[0], p[1], p[2]); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
833 return 0 ; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
834 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
835 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
836 packet_len -= 6; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
837 if(packet_len==0) |
11190 | 838 { |
839 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: packet too short: %d, exit\n", packet_len); | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
840 return 0; |
11190 | 841 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
842 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
843 es->payload_size = (p[4] << 8 | p[5]); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
844 pes_is_aligned = (p[6] & 4); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
845 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
846 stream_id = p[3]; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
847 |
9610 | 848 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
849 if (p[7] & 0x80) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
850 { /* pts available */ |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
851 pts = (int64_t)(p[9] & 0x0E) << 29 ; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
852 pts |= p[10] << 22 ; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
853 pts |= (p[11] & 0xFE) << 14 ; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
854 pts |= p[12] << 7 ; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
855 pts |= (p[13] & 0xFE) >> 1 ; |
9610 | 856 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
857 es->pts = pts / 90000.0f; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
858 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
859 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
860 es->pts = 0.0f; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
861 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
862 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
863 header_len = p[8]; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
864 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
865 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
866 if (header_len + 9 > pkt_len) //9 are the bytes read up to the header_length field |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
867 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
868 mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_ts: illegal value for PES_header_data_length (0x%02x)\n", header_len); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
869 return 0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
870 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
871 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
872 p += header_len + 9; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
873 packet_len -= header_len + 3; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
874 |
11190 | 875 /* |
876 if(packet_len <= 0) | |
877 mp_msg(MSGT_DEMUX, MSGL_INFO, "\n\nNow: %d, prima: %d, ORIG: %d\n\n\n", packet_len, packet_len+3+header_len, pkt_len); | |
878 */ | |
879 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
880 if(es->payload_size) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
881 es->payload_size -= header_len + 3; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
882 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
883 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
884 if (stream_id == 0xbd) |
9610 | 885 { |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
886 mp_msg(MSGT_DEMUX, MSGL_DBG3, "pes_parse2: audio buf = %02X %02X %02X %02X %02X %02X %02X %02X, 80: %d\n", |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
887 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[0] & 0x80); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
888 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
889 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
890 /* |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
891 * we check the descriptor tag first because some stations |
11190 | 892 * do not include any of the A52 header info in their audio tracks |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
893 * these "raw" streams may begin with a byte that looks like a stream type. |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
894 */ |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
895 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
896 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
897 if( |
11190 | 898 (type_from_pmt == AUDIO_A52) || /* A52 - raw */ |
899 (p[0] == 0x0B && p[1] == 0x77) /* A52 - syncword */ | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
900 ) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
901 { |
11190 | 902 mp_msg(MSGT_DEMUX, MSGL_DBG2, "A52 RAW OR SYNCWORD\n"); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
903 es->start = p; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
904 es->size = packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
905 es->type = AUDIO_A52; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
906 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
907 |
11190 | 908 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
909 } |
11190 | 910 /* SPU SUBS */ |
911 else if(type_from_pmt == SPU_DVB || | |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
912 ((p[0] == 0x20) && pes_is_aligned)) // && p[1] == 0x00)) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
913 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
914 es->start = p; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
915 es->size = packet_len; |
11190 | 916 es->type = SPU_DVB; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
917 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
918 |
11190 | 919 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
920 } |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
921 else if (pes_is_aligned && ((p[0] & 0xE0) == 0x20)) //SPU_DVD |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
922 { |
11190 | 923 //DVD SUBS |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
924 es->start = p+1; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
925 es->size = packet_len-1; |
11190 | 926 es->type = SPU_DVD; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
927 es->payload_size -= packet_len; |
9610 | 928 |
11190 | 929 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
930 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
931 else if ((p[0] & 0xF0) == 0x80) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
932 { |
11190 | 933 mp_msg(MSGT_DEMUX, MSGL_DBG2, "A52 WITH HEADER\n"); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
934 es->start = p+4; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
935 es->size = packet_len - 4; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
936 es->type = AUDIO_A52; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
937 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
938 |
11190 | 939 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
940 } |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
941 else if (pes_is_aligned && ((p[0]&0xf0) == 0xa0)) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
942 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
943 int pcm_offset; |
9610 | 944 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
945 for (pcm_offset=0; ++pcm_offset < packet_len-1 ; ) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
946 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
947 if (p[pcm_offset] == 0x01 && p[pcm_offset+1] == 0x80) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
948 { /* START */ |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
949 pcm_offset += 2; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
950 break; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
951 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
952 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
953 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
954 es->start = p + pcm_offset; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
955 es->size = packet_len - pcm_offset; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
956 es->type = AUDIO_LPCM_BE; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
957 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
958 |
11190 | 959 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
960 } |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
961 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
962 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
963 mp_msg(MSGT_DEMUX, MSGL_DBG2, "PES_PRIVATE1\n"); |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
964 es->start = p; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
965 es->size = packet_len; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
966 es->type = PES_PRIVATE1; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
967 es->payload_size -= packet_len; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
968 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
969 return 1; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
970 } |
9610 | 971 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
972 else if ((stream_id >= 0xbc) && ((stream_id & 0xf0) == 0xe0)) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
973 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
974 es->start = p; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
975 es->size = packet_len; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
976 if(type_from_pmt != UNKNOWN) |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
977 es->type = type_from_pmt; |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
978 else |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
979 es->type = VIDEO_MPEG2; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
980 if(es->payload_size) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
981 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
982 |
11190 | 983 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: M2V size %d\n", es->size); |
984 return 1; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
985 } |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
986 else if ((stream_id == 0xfa)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
987 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
988 if(type_from_pmt != -1) //MP4 A/V |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
989 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
990 es->start = p; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
991 es->size = packet_len; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
992 es->type = type_from_pmt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
993 if(es->payload_size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
994 es->payload_size -= packet_len; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
995 |
11190 | 996 return 1; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
997 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
998 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
999 else if ((stream_id & 0xe0) == 0xc0) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1000 { |
11190 | 1001 int profile = 0, srate = 0, channels = 0; |
1002 uint32_t hdr, l = 0; | |
9610 | 1003 |
11190 | 1004 hdr = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; |
1005 if((hdr & 0xfff00000) == 0xfff00000) | |
1006 { | |
1007 // ADTS AAC shows with MPA layer 4 (00 in the layer bitstream) | |
1008 l = 4 - ((hdr & 0x00060000) >> 17); | |
1009 profile = ((hdr & 0x0000C000) >> 14); | |
1010 srate = ((hdr & 0x00003c00) >> 10); | |
1011 channels = ((hdr & 0x000001E0) >> 5); | |
1012 } | |
1013 mp_msg(MSGT_DEMUX, MSGL_DBG2, "\n\naudio header: %2X %2X %2X %2X\nLAYER: %d, PROFILE: %d, SRATE=%d, CHANNELS=%d\n\n", p[0], p[1], p[3], p[4], l, profile, srate, channels); | |
1014 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1015 es->start = p; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1016 es->size = packet_len; |
11190 | 1017 |
1018 | |
1019 //if((type_from_pmt == 0x0f) || (l == 4)) //see in parse_pmt() | |
1020 if(l==4) | |
1021 es->type = AUDIO_AAC; | |
1022 else | |
1023 es->type = AUDIO_MP2; | |
1024 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1025 es->payload_size -= packet_len; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1026 |
11190 | 1027 return 1; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1028 } |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1029 else if (type_from_pmt != -1) //as a last resort here we trust the PMT, if present |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1030 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1031 es->start = p; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1032 es->size = packet_len; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1033 es->type = type_from_pmt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1034 es->payload_size -= packet_len; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1035 |
11190 | 1036 return 1; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1037 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1038 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1039 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1040 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: unknown packet, id: %x\n", stream_id); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1041 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1042 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1043 return 0; |
9610 | 1044 } |
1045 | |
1046 | |
1047 | |
1048 | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1049 static int ts_sync(stream_t *stream) |
9610 | 1050 { |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1051 int c=0; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1052 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1053 mp_msg(MSGT_DEMUX, MSGL_DBG2, "TS_SYNC \n"); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1054 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1055 while(((c=stream_read_char(stream)) != 0x47) && ! stream->eof); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1056 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1057 if(c == 0x47) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1058 return c; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1059 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1060 return 0; |
9610 | 1061 } |
1062 | |
1063 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1064 static void ts_dump_streams(ts_priv_t *priv) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1065 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1066 int i; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1067 |
11190 | 1068 for(i = 0; i < 3; i++) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1069 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1070 if((priv->fifo[i].pack != NULL) && (priv->fifo[i].offset != 0)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1071 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1072 resize_demux_packet(priv->fifo[i].pack, priv->fifo[i].offset); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1073 ds_add_packet(priv->fifo[i].ds, priv->fifo[i].pack); |
11190 | 1074 priv->fifo[i].offset = 0; |
1075 priv->fifo[i].pack = NULL; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1076 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1077 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1078 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1079 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1080 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1081 static inline int32_t prog_idx_in_pat(ts_priv_t *priv, uint16_t progid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1082 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1083 int x; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1084 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1085 if(priv->pat.progs == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1086 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1087 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1088 for(x = 0; x < priv->pat.progs_cnt; x++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1089 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1090 if(priv->pat.progs[x].id == progid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1091 return x; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1092 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1093 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1094 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1095 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1096 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1097 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1098 static inline int32_t prog_id_in_pat(ts_priv_t *priv, uint16_t pid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1099 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1100 int x; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1101 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1102 if(priv->pat.progs == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1103 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1104 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1105 for(x = 0; x < priv->pat.progs_cnt; x++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1106 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1107 if(priv->pat.progs[x].pmt_pid == pid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1108 return priv->pat.progs[x].id; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1109 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1110 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1111 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1112 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1113 |
11190 | 1114 /* |
1115 DON'T REMOVE, I'LL NEED IT IN THE (NEAR) FUTURE) | |
1116 static int check_crc32(uint32_t val, uint8_t *ptr, uint16_t len, uint8_t *vbase) | |
1117 { | |
1118 uint32_t tab_crc32, calc_crc32; | |
1119 | |
1120 calc_crc32 = CalcCRC32(val, ptr, len); | |
1121 | |
1122 tab_crc32 = (vbase[0] << 24) | (vbase[1] << 16) | (vbase[2] << 8) | vbase[3]; | |
1123 | |
1124 printf("CRC32, TAB: %x, CALC: %x, eq: %x\n", tab_crc32, calc_crc32, tab_crc32 == calc_crc32); | |
1125 return (tab_crc32 == calc_crc32); | |
1126 | |
1127 } | |
1128 */ | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1129 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1130 static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1131 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1132 uint8_t skip, m = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1133 unsigned char *ptr; |
11190 | 1134 unsigned char *base; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1135 int entries, i, sections; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1136 uint16_t progid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1137 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1138 //PRE-FILLING |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1139 if(! is_start) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1140 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1141 if(priv->pat.buffer_len == 0) //a broken packet |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1142 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1143 return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1144 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1145 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1146 if(priv->pat.skip) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1147 m = min(priv->pat.skip, size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1148 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1149 priv->pat.skip -= m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1150 if(m == size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1151 return -1; //keep on buffering |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1152 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1153 else //IS_START, replace the old content |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1154 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1155 priv->pat.buffer_len = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1156 skip = buff[0]+1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1157 m = min(skip, size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1158 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1159 priv->pat.skip = skip - m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1160 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1161 if(m == size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1162 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1163 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1164 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1165 //FILLING |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1166 memcpy(&(priv->pat.buffer[priv->pat.buffer_len]), &buff[m], size - m); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1167 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1168 priv->pat.buffer_len += size - m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1169 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1170 //PARSING |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1171 ptr = priv->pat.buffer; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1172 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1173 priv->pat.table_id = ptr[0]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1174 priv->pat.ssi = (ptr[1] >> 7) & 0x1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1175 priv->pat.curr_next = ptr[5] & 0x01; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1176 priv->pat.ts_id = (ptr[3] << 8 ) | ptr[4]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1177 priv->pat.version_number = (ptr[5] >> 1) & 0x1F; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1178 priv->pat.section_length = ((ptr[1] & 0x03) << 8 ) | ptr[2]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1179 priv->pat.section_number = ptr[6]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1180 priv->pat.last_section_number = ptr[7]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1181 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1182 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1183 if((! priv->pat.curr_next) || (priv->pat.table_id != 0)) // || (! priv->pat.ssi)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1184 return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1185 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1186 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1187 //beginning of sections loop |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1188 sections = priv->pat.last_section_number - priv->pat.section_number + 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1189 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PAT, section %d of %d, TOTAL: %d\n", priv->pat.section_number, priv->pat.last_section_number, sections); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1190 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1191 if(priv->pat.section_length + 3 > priv->pat.buffer_len) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1192 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1193 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PAT, section larger than buffer size: %d > %d, EXIT\n", |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1194 priv->pat.section_length, priv->pat.buffer_len - 3); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1195 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1196 return -1; //KEEP ON FILLING THE TABLE |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1197 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1198 |
11190 | 1199 //check_crc32(0xFFFFFFFFL, ptr, priv->pat.buffer_len - 4, &ptr[priv->pat.buffer_len - 4]); |
1200 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1201 entries = (int) (priv->pat.section_length - 9) / 4; //entries per section |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1202 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1203 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1204 for(i=0; i < entries; i++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1205 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1206 int32_t idx; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1207 base = &ptr[8 + i*4]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1208 progid = (base[0] << 8) | base[1]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1209 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1210 if((idx = prog_idx_in_pat(priv, progid)) == -1) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1211 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1212 int sz = sizeof(struct pat_progs_t) * (priv->pat.progs_cnt+1); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1213 priv->pat.progs = (struct pat_progs_t*) realloc(priv->pat.progs, sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1214 if(priv->pat.progs == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1215 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1216 mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PAT: COULDN'T REALLOC %d bytes, NEXT\n", sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1217 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1218 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1219 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1220 idx = priv->pat.progs_cnt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1221 priv->pat.progs_cnt++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1222 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1223 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1224 priv->pat.progs[idx].id = progid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1225 priv->pat.progs[idx].pmt_pid = ((base[2] & 0x1F) << 8) | base[3]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1226 mp_msg(MSGT_DEMUX, MSGL_V, "PROG: %d (%d-th of %d), PMT: %d\n", priv->pat.progs[idx].id, i+1, entries, priv->pat.progs[idx].pmt_pid); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1227 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1228 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1229 return 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1230 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1231 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1232 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1233 static inline int32_t es_pid_in_pmt(pmt_t * pmt, uint16_t pid) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1234 { |
11190 | 1235 uint16_t i; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1236 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1237 if(pmt == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1238 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1239 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1240 if(pmt->es == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1241 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1242 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1243 for(i = 0; i < pmt->es_cnt; i++) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1244 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1245 if(pmt->es[i].pid == pid) |
11190 | 1246 return (int32_t) i; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1247 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1248 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1249 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1250 } |
9610 | 1251 |
1252 | |
11190 | 1253 static int parse_descriptors(struct pmt_es_t *es, uint8_t *ptr) |
1254 { | |
1255 int j, descr_len, len; | |
1256 | |
1257 j = 0; | |
1258 len = es->descr_length; | |
1259 while(len > 2) | |
1260 { | |
1261 descr_len = ptr[j+1]; | |
1262 mp_msg(MSGT_DEMUX, MSGL_DBG2, "...descr id: 0x%x, len=%d\n", ptr[j], descr_len); | |
1263 if(descr_len > len) | |
1264 { | |
1265 mp_msg(MSGT_DEMUX, MSGL_DBG2, "INVALID DESCR LEN: %d vs %d max, EXIT LOOP\n", descr_len, len); | |
1266 return -1; | |
1267 } | |
1268 | |
1269 | |
1270 if(ptr[j] == 0x6a) //A52 Descriptor | |
1271 { | |
1272 es->type = AUDIO_A52; | |
1273 mp_msg(MSGT_DEMUX, MSGL_DBG2, "DVB A52 Descriptor\n"); | |
1274 } | |
1275 else if(ptr[j] == 0x59) //Subtitling Descriptor | |
1276 { | |
1277 uint8_t subtype; | |
1278 | |
1279 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Subtitling Descriptor\n"); | |
1280 if(descr_len < 8) | |
1281 { | |
1282 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Descriptor length too short for DVB Subtitle Descriptor: %d, SKIPPING\n", descr_len); | |
1283 } | |
1284 else | |
1285 { | |
1286 memcpy(es->lang, &ptr[j+2], 3); | |
1287 es->lang[3] = 0; | |
1288 subtype = ptr[j+5]; | |
1289 if( | |
1290 (subtype >= 0x10 && subtype <= 0x13) || | |
1291 (subtype >= 0x20 && subtype <= 0x23) | |
1292 ) | |
1293 { | |
1294 es->type = SPU_DVB; | |
1295 //page parameters: compo page 2 bytes, ancillary page 2 bytes | |
1296 } | |
1297 else | |
1298 es->type = UNKNOWN; | |
1299 } | |
1300 } | |
1301 else if(ptr[j] == 0x50) //Component Descriptor | |
1302 { | |
1303 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Component Descriptor\n"); | |
1304 memcpy(es->lang, &ptr[j+5], 3); | |
1305 es->lang[3] = 0; | |
1306 } | |
1307 else if(ptr[j] == 0xa) //Language Descriptor | |
1308 { | |
1309 memcpy(es->lang, &ptr[j+2], 3); | |
1310 es->lang[3] = 0; | |
1311 mp_msg(MSGT_DEMUX, MSGL_V, "Language Descriptor: %s\n", es->lang); | |
1312 } | |
1313 else if(ptr[j] == 0x5) //Registration Descriptor (looks like e fourCC :) ) | |
1314 { | |
1315 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Registration Descriptor\n"); | |
1316 if(descr_len < 4) | |
1317 { | |
1318 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Registration Descriptor length too short: %d, SKIPPING\n", descr_len); | |
1319 } | |
1320 else | |
1321 { | |
1322 char *d; | |
1323 memcpy(es->format_descriptor, &ptr[j+2], 4); | |
1324 es->format_descriptor[4] = 0; | |
1325 | |
1326 d = &ptr[j+2]; | |
1327 if(d[0] == 'A' && d[1] == 'C' && d[2] == '-' && d[3] == '3') | |
1328 { | |
1329 es->type = AUDIO_A52; | |
1330 } | |
1331 else | |
1332 es->type = UNKNOWN; | |
1333 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FORMAT %s\n", es->format_descriptor); | |
1334 } | |
1335 } | |
1336 else | |
1337 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Unknown descriptor 0x%x, SKIPPING\n", ptr[j]); | |
1338 | |
1339 len -= 2 + descr_len; | |
1340 j += 2 + descr_len; | |
1341 } | |
1342 | |
1343 return 1; | |
1344 } | |
1345 | |
1346 | |
9610 | 1347 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1348 static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_start, unsigned char *buff, int size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1349 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1350 unsigned char *base, *es_base; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1351 pmt_t *pmt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1352 int32_t idx, es_count, section_bytes; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1353 uint8_t skip, m=0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1354 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1355 idx = progid_idx_in_pmt(priv, progid); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1356 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1357 if(idx == -1) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1358 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1359 int sz = (priv->pmt_cnt + 1) * sizeof(pmt_t); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1360 priv->pmt = (pmt_t *) realloc(priv->pmt, sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1361 if(priv->pmt == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1362 { |
11190 | 1363 mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PMT: COULDN'T REALLOC %d bytes, NEXT\n", sz); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1364 return NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1365 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1366 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1367 idx = priv->pmt_cnt; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1368 memset(&(priv->pmt[idx]), 0, sizeof(pmt_t)); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1369 priv->pmt_cnt++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1370 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1371 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1372 pmt = &(priv->pmt[idx]); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1373 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1374 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1375 if(! is_start) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1376 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1377 if(pmt->buffer_len == 0) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1378 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1379 //BROKEN PMT PACKET, DISCARD |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1380 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1381 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1382 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1383 if(pmt->skip) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1384 m = min(pmt->skip, size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1385 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1386 pmt->skip -= m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1387 if(m == size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1388 return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1389 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1390 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1391 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1392 pmt->buffer_len = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1393 skip = buff[0] + 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1394 m = min(skip, size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1395 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1396 pmt->skip = skip - m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1397 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1398 if(m == size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1399 return 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1400 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1401 |
11190 | 1402 |
1403 if(size-m + pmt->buffer_len > 2048) | |
1404 { | |
1405 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_PMT(prog=%d, PID=%d), ERROR! PMT TOO LONG, IGNORING\n", progid, pid); | |
1406 pmt->buffer_len = 0; | |
1407 return NULL; | |
1408 } | |
1409 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1410 memcpy(&(pmt->buffer[pmt->buffer_len]), &buff[m], size - m); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1411 pmt->progid = progid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1412 pmt->buffer_len += size - m; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1413 |
11190 | 1414 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_PMT(prog=%d), PMT_len: %d, IS_START: %d, TS_PID: %d, SIZE=%d, M=%d, ES_CNT=%d, IDX=%d, PMT_PTR=%p\n", |
1415 progid, pmt->buffer_len, is_start, pid, size, m, pmt->es_cnt, idx, pmt); | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1416 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1417 base = pmt->buffer; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1418 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1419 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1420 pmt->table_id = base[0]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1421 pmt->ssi = base[1] & 0x80; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1422 pmt->section_length = (((base[1] & 0xf) << 8 ) | base[2]); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1423 pmt->version_number = (base[5] >> 1) & 0x1f; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1424 pmt->curr_next = (base[5] & 1); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1425 pmt->section_number = base[6]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1426 pmt->last_section_number = base[7]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1427 pmt->PCR_PID = ((base[8] & 0x1f) << 8 ) | base[9]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1428 pmt->prog_descr_length = ((base[10] & 0xf) << 8 ) | base[11]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1429 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1430 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1431 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1432 if((pmt->curr_next == 0) || (pmt->table_id != 2)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1433 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1434 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1435 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1436 if(pmt->section_length + 3 > pmt->buffer_len) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1437 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1438 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PMT, SECTION LENGTH TOO LARGE FOR CURRENT BUFFER (%d vs %d), NEXT TIME\n", pmt->section_length, pmt->buffer_len); |
11190 | 1439 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1440 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1441 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1442 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1443 if(pmt->prog_descr_length > pmt->section_length - 9) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1444 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1445 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PMT, INVALID PROG_DESCR LENGTH (%d vs %d)\n", pmt->prog_descr_length, pmt->section_length - 9); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1446 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1447 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1448 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1449 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1450 es_base = &base[12 + pmt->prog_descr_length]; //the beginning of th ES loop |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1451 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1452 section_bytes= pmt->section_length - 13 - pmt->prog_descr_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1453 es_count = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1454 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1455 while(section_bytes >= 5) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1456 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1457 int es_pid, es_type; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1458 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1459 es_type = es_base[0]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1460 es_pid = ((es_base[1] & 0x1f) << 8) | es_base[2]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1461 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1462 idx = es_pid_in_pmt(pmt, es_pid); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1463 if(idx == -1) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1464 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1465 int sz = sizeof(struct pmt_es_t) * (pmt->es_cnt + 1); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1466 pmt->es = (struct pmt_es_t *) realloc(pmt->es, sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1467 if(pmt->es == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1468 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1469 mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PMT, COULDN'T ALLOCATE %d bytes for PMT_ES\n", sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1470 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1471 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1472 idx = pmt->es_cnt; |
11190 | 1473 memset(&(pmt->es[idx]), 0, sizeof(struct pmt_es_t)); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1474 pmt->es_cnt++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1475 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1476 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1477 pmt->es[idx].descr_length = ((es_base[3] & 0xf) << 8) | es_base[4]; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1478 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1479 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1480 if(pmt->es[idx].descr_length > section_bytes - 5) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1481 { |
11190 | 1482 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PMT, ES_DESCR_LENGTH TOO LARGE %d > %d, EXIT\n", |
1483 pmt->es[idx].descr_length, section_bytes - 5); | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1484 return -1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1485 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1486 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1487 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1488 pmt->es[idx].pid = es_pid; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1489 pmt->es[idx].type = es_type; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1490 |
11190 | 1491 pmt->es[idx].type = UNKNOWN; |
1492 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1493 switch(es_type) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1494 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1495 case 1: |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1496 pmt->es[idx].type = VIDEO_MPEG1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1497 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1498 case 2: |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1499 pmt->es[idx].type = VIDEO_MPEG2; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1500 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1501 case 3: |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1502 case 4: |
11190 | 1503 parse_descriptors(&pmt->es[idx], &es_base[5]); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1504 pmt->es[idx].type = AUDIO_MP2; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1505 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1506 case 6: |
11190 | 1507 parse_descriptors(&pmt->es[idx], &es_base[5]); |
1508 if(pmt->es[idx].type == 0x6) | |
1509 pmt->es[idx].type = UNKNOWN; | |
1510 break; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1511 case 0x10: |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1512 pmt->es[idx].type = VIDEO_MPEG4; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1513 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1514 case 0x11: |
11190 | 1515 parse_descriptors(&pmt->es[idx], &es_base[5]); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1516 pmt->es[idx].type = AUDIO_AAC; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1517 break; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1518 |
11190 | 1519 /* seems to indicate an AAC in a certain broadcaster's tables, but |
1520 it's deceiving, so it's commented out | |
1521 case 0x0f: | |
1522 parse_descriptors(&pmt->es[idx], &es_base[5]); | |
1523 pmt->es[idx].type = 0x0f; | |
1524 break; | |
1525 */ | |
1526 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1527 case 0x81: |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1528 pmt->es[idx].type = AUDIO_A52; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1529 break; |
11190 | 1530 |
1531 default: | |
1532 { | |
1533 if(es_type > 0x80) | |
1534 { | |
1535 parse_descriptors(&pmt->es[idx], &es_base[5]); | |
1536 } | |
1537 else | |
1538 { | |
1539 mp_msg(MSGT_DEMUX, MSGL_DBG2, "UNKNOWN ES TYPE=0x%x\n", es_type); | |
1540 pmt->es[idx].type = UNKNOWN; | |
1541 } | |
1542 } | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1543 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1544 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1545 section_bytes -= 5 + pmt->es[idx].descr_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1546 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_PMT(%d INDEX %d), STREAM: %d, FOUND pid=0x%x (%d), type=0x%x, ES_DESCR_LENGTH: %d, bytes left: %d\n", |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1547 progid, idx, es_count, pmt->es[idx].pid, pmt->es[idx].pid, pmt->es[idx].type, pmt->es[idx].descr_length, section_bytes); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1548 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1549 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1550 es_base += 5 + pmt->es[idx].descr_length; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1551 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1552 es_count++; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1553 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1554 |
11190 | 1555 mp_msg(MSGT_DEMUX, MSGL_V, "----------------------------\n"); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1556 return 1; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1557 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1558 |
9610 | 1559 |
11190 | 1560 static inline int32_t pid_type_from_pmt(ts_priv_t *priv, int pid) |
1561 { | |
1562 int32_t pmt_idx, pid_idx, i, j; | |
1563 | |
1564 pmt_idx = progid_idx_in_pmt(priv, priv->prog); | |
1565 | |
1566 if(pmt_idx != -1) | |
1567 { | |
1568 pid_idx = es_pid_in_pmt(&(priv->pmt[pmt_idx]), pid); | |
1569 if(pid_idx != -1) | |
1570 return priv->pmt[pmt_idx].es[pid_idx].type; | |
1571 } | |
1572 //else | |
1573 //{ | |
1574 for(i = 0; i < priv->pmt_cnt; i++) | |
1575 { | |
1576 pmt_t *pmt = &(priv->pmt[i]); | |
1577 for(j = 0; j < pmt->es_cnt; j++) | |
1578 if(pmt->es[j].pid == pid) | |
1579 return pmt->es[j].type; | |
1580 } | |
1581 //} | |
1582 | |
1583 return UNKNOWN; | |
1584 } | |
1585 | |
1586 | |
1587 static inline uint8_t *pid_lang_from_pmt(ts_priv_t *priv, int pid) | |
1588 { | |
1589 int32_t pmt_idx, pid_idx, i, j; | |
1590 | |
1591 pmt_idx = progid_idx_in_pmt(priv, priv->prog); | |
1592 | |
1593 if(pmt_idx != -1) | |
1594 { | |
1595 pid_idx = es_pid_in_pmt(&(priv->pmt[pmt_idx]), pid); | |
1596 if(pid_idx != -1) | |
1597 return priv->pmt[pmt_idx].es[pid_idx].lang; | |
1598 } | |
1599 else | |
1600 { | |
1601 for(i = 0; i < priv->pmt_cnt; i++) | |
1602 { | |
1603 pmt_t *pmt = &(priv->pmt[i]); | |
1604 for(j = 0; j < pmt->es_cnt; j++) | |
1605 if(pmt->es[j].pid == pid) | |
1606 return pmt->es[j].lang; | |
1607 } | |
1608 } | |
1609 | |
1610 return NULL; | |
1611 } | |
1612 | |
1613 | |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1614 static int fill_packet(demuxer_t *demuxer, demux_stream_t *ds, demux_packet_t **dp, int *dp_offset) |
11190 | 1615 { |
1616 int ret = 0; | |
1617 | |
1618 if((*dp != NULL) && (*dp_offset > 0)) | |
1619 { | |
1620 ret = *dp_offset; | |
1621 resize_demux_packet(*dp, ret); //shrinked to the right size | |
1622 ds_add_packet(ds, *dp); | |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1623 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ADDED %d bytes to %s fifo, PTS=%f\n", ret, (ds == demuxer->audio ? "audio" : (ds == demuxer->video ? "video" : "sub")), (*dp)->pts); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1624 } |
11190 | 1625 |
1626 *dp = NULL; | |
1627 *dp_offset = 0; | |
1628 | |
1629 return ret; | |
1630 } | |
1631 | |
9610 | 1632 // 0 = EOF or no stream found |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1633 // else = [-] number of bytes written to the packet |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1634 static int ts_parse(demuxer_t *demuxer , ES_stream_t *es, unsigned char *packet, int probe) |
9610 | 1635 { |
10014 | 1636 ES_stream_t *tss; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1637 uint8_t done = 0; |
11190 | 1638 int buf_size, is_start, pid, base; |
1639 int len, cc, cc_ok, afc, retv = 0, is_video, is_audio, is_sub; | |
10014 | 1640 ts_priv_t * priv = (ts_priv_t*) demuxer->priv; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1641 stream_t *stream = demuxer->stream; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1642 char *p, tmp[TS_FEC_PACKET_SIZE]; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1643 demux_stream_t *ds = NULL; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1644 demux_packet_t **dp = NULL; |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1645 int *dp_offset = 0, *buffer_size = 0; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1646 int32_t progid, pid_type, bad, ts_error; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1647 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1648 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1649 while(! done) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1650 { |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1651 bad = ts_error = 0; |
11190 | 1652 ds = (demux_stream_t*) NULL; |
1653 dp = (demux_packet_t **) NULL; | |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1654 dp_offset = buffer_size = NULL; |
11190 | 1655 |
1656 buf_size = priv->ts.packet_size; | |
1657 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1658 if(stream_eof(stream)) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1659 { |
11190 | 1660 if(! probe) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1661 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1662 ts_dump_streams(priv); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1663 demuxer->filepos = stream_tell(demuxer->stream); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1664 } |
11190 | 1665 |
1666 return 0; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1667 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1668 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1669 |
11190 | 1670 if(! ts_sync(stream)) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1671 { |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1672 mp_msg(MSGT_DEMUX, MSGL_INFO, "TS_PARSE: COULDN'T SYNC\n"); |
11190 | 1673 return 0; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1674 } |
11190 | 1675 |
1676 len = stream_read(stream, &packet[1], 3); | |
1677 if (len != 3) | |
1678 return 0; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1679 |
11190 | 1680 if((packet[1] >> 7) & 0x01) //transport error |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1681 ts_error = 1; |
11190 | 1682 |
1683 buf_size -= 4; | |
1684 | |
1685 is_start = packet[1] & 0x40; | |
1686 pid = ((packet[1] & 0x1f) << 8) | packet[2]; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1687 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1688 tss = priv->ts.pids[pid]; //an ES stream |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1689 if(tss == NULL) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1690 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1691 tss = malloc(sizeof(ES_stream_t)); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1692 if(! tss) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1693 continue; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1694 memset(tss, 0, sizeof(ES_stream_t)); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1695 tss->pid = pid; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1696 tss->last_cc = -1; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1697 tss->type = UNKNOWN; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1698 tss->payload_size = 0; |
11190 | 1699 tss->seen = 0; |
1700 priv->ts.pids[pid] = tss; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1701 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1702 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1703 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1704 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1705 if(((pid > 1) && (pid < 16)) || (pid == 8191)) //invalid pid |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1706 { |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1707 stream_skip(stream, buf_size-1); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1708 continue; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1709 } |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1710 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1711 cc = (packet[3] & 0xf); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1712 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1713 tss->last_cc = cc; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1714 |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1715 bad = ts_error || (! cc_ok); |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1716 |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1717 if(! bad) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1718 { |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1719 // skip adaptation field, but only if cc_ok is not corrupt, |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1720 //otherwise we may throw away good data |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1721 afc = (packet[3] >> 4) & 3; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1722 if(! (afc % 2)) //no payload in this TS packet |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1723 { |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1724 stream_skip(stream, buf_size-1); |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1725 continue; |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1726 } |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1727 |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1728 if(afc == 3) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1729 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1730 int c; |
11190 | 1731 c = stream_read_char(stream); |
1732 buf_size--; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1733 |
11190 | 1734 c = min(c, buf_size); |
1735 stream_skip(stream, c); | |
1736 buf_size -= c; | |
1737 if(buf_size == 0) | |
1738 continue; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1739 |
11190 | 1740 afc = c + 1; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1741 } |
11190 | 1742 else |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1743 afc = 0; //payload only |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1744 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1745 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1746 { |
11190 | 1747 // logically this packet should be dropped, but if I do it |
1748 // certain streams play corrupted. Maybe the decoders know | |
1749 // how to deal with it, but at least I consider the packet | |
1750 // as "not initial" | |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1751 mp_msg(MSGT_DEMUX, MSGL_V, "ts_parse: PID=%d, Transport error: %d, CC_OK: %s\n\n", tss->pid, ts_error, (cc_ok ? "yes" : "no")); |
11190 | 1752 |
1753 if(priv->keep_broken == 0) | |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1754 { |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1755 stream_skip(stream, buf_size-1); |
11190 | 1756 continue; |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1757 } |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1758 |
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1759 is_start = 0; //queued to the packet data |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1760 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1761 |
11190 | 1762 tss->seen++; |
1763 if(tss->seen == 16 && cc_ok) //at least a complete round | |
1764 mp_msg(MSGT_DEMUX, MSGL_V, "\nNew TS pid=%u\n", pid); | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1765 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1766 |
11190 | 1767 //TABLE PARSING |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1768 |
11190 | 1769 base = priv->ts.packet_size - buf_size; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1770 if(pid == 0) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1771 { |
11190 | 1772 stream_read(stream,&packet[base], buf_size); |
1773 parse_pat(priv, is_start, &packet[base], buf_size); | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1774 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1775 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1776 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1777 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1778 progid = prog_id_in_pat(priv, pid); |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1779 if(progid != -1) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1780 { |
11190 | 1781 if(pid != demuxer->video->id && pid != demuxer->audio->id && pid != demuxer->sub->id) |
1782 { | |
1783 stream_read(stream,&packet[base], buf_size); | |
1784 parse_pmt(priv, progid, pid, is_start, &packet[base], buf_size); | |
1785 continue; | |
1786 } | |
1787 else | |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1788 mp_msg(MSGT_DEMUX, MSGL_ERR, "Argh! Data pid %d used in the PMT, Skipping PMT parsing!\n", pid); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1789 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1790 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1791 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1792 |
11190 | 1793 priv->last_pid = pid; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1794 |
11190 | 1795 is_video = ((tss->type == VIDEO_MPEG1) || (tss->type == VIDEO_MPEG2) || (tss->type == VIDEO_MPEG4)); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1796 is_audio = ((tss->type == AUDIO_MP2) || (tss->type == AUDIO_A52) || (tss->type == AUDIO_LPCM_BE) || (tss->type == AUDIO_AAC) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1797 || (tss->type == PES_PRIVATE1)); |
11190 | 1798 is_sub = ((tss->type == SPU_DVD) || (tss->type == SPU_DVB)); |
1799 pid_type = pid_type_from_pmt(priv, pid); | |
1800 | |
1801 // PES CONTENT STARTS HERE | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1802 if(! probe) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1803 { |
11190 | 1804 if((pid == demuxer->sub->id)) //or the lang is right |
1805 { | |
1806 pid_type = SPU_DVD; | |
1807 } | |
1808 | |
1809 if(is_video && (demuxer->video->id == tss->pid)) | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1810 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1811 ds = demuxer->video; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1812 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1813 dp = &priv->fifo[1].pack; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1814 dp_offset = &priv->fifo[1].offset; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1815 buffer_size = &priv->fifo[1].buffer_size; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1816 } |
11190 | 1817 else if(is_audio && (demuxer->audio->id == tss->pid)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1818 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1819 ds = demuxer->audio; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1820 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1821 dp = &priv->fifo[0].pack; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1822 dp_offset = &priv->fifo[0].offset; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1823 buffer_size = &priv->fifo[0].buffer_size; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1824 } |
11190 | 1825 else if(is_sub |
1826 || (pid_type == SPU_DVD) || (pid_type == SPU_DVB)) | |
1827 { | |
1828 //SUBS are infrequent, so the initial detection may fail | |
1829 // and we may need to add them at play-time | |
1830 if(demuxer->sub->id == -1) | |
1831 { | |
1832 uint16_t p; | |
1833 p = progid_for_pid(priv, tss->pid, priv->prog); | |
1834 | |
1835 if(p == priv->prog) | |
1836 { | |
1837 int asgn = 0; | |
1838 uint8_t *lang; | |
1839 | |
1840 if(!strcmp(dvdsub_lang, "")) | |
1841 asgn = 1; | |
1842 else | |
1843 { | |
1844 lang = pid_lang_from_pmt(priv, pid); | |
1845 if(lang != NULL) | |
1846 asgn = (strncmp(lang, dvdsub_lang, 3) == 0); | |
1847 else | |
1848 asgn = 0; | |
1849 } | |
1850 | |
1851 if(asgn) | |
1852 { | |
1853 demuxer->sub->id = tss->pid; | |
1854 mp_msg(MSGT_DEMUX, MSGL_INFO, "CHOSEN SUBs pid 0x%x (%d) FROM PROG %d\n", tss->pid, tss->pid, priv->prog); | |
1855 } | |
1856 } | |
1857 else | |
1858 { | |
1859 mp_msg(MSGT_DEMUX, MSGL_V, "DISCARDED SUBs pid 0x%x (%d) NOT CHOSEN OR NOT IN PROG %d\n", tss->pid, tss->pid, priv->prog); | |
1860 } | |
1861 } | |
1862 | |
1863 if(demuxer->sub->id == tss->pid) | |
1864 { | |
1865 ds = demuxer->sub; | |
1866 | |
1867 dp = &priv->fifo[2].pack; | |
1868 dp_offset = &priv->fifo[2].offset; | |
1869 buffer_size = &priv->fifo[2].buffer_size; | |
1870 } | |
1871 else | |
1872 { | |
1873 stream_skip(stream, buf_size); | |
1874 continue; | |
1875 } | |
1876 } | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1877 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1878 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1879 stream_skip(stream, buf_size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1880 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1881 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1882 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1883 //IS IT TIME TO QUEUE DATA to the dp_packet? |
11190 | 1884 if(is_start && (dp != NULL)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1885 { |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1886 retv = fill_packet(demuxer, ds, dp, dp_offset); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1887 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1888 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1889 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1890 if(*dp == NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1891 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1892 *dp = new_demux_packet(*buffer_size); //es->size |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1893 *dp_offset = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1894 if(! *dp) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1895 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1896 fprintf(stderr, "fill_buffer, NEW_ADD_PACKET(%d)FAILED\n", *buffer_size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1897 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1898 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1899 mp_msg(MSGT_DEMUX, MSGL_DBG2, "CREATED DP(%d)\n", *buffer_size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1900 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1901 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1902 mp_msg(MSGT_DEMUX, MSGL_DBG2, "NOW PACKET_SIZE = %d, DP_OFFSET = %d\n", *buffer_size, *dp_offset); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1903 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1904 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1905 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1906 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1907 if(is_start) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1908 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1909 mp_msg(MSGT_DEMUX, MSGL_DBG2, "IS_START\n"); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1910 |
11190 | 1911 p = &packet[base]; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1912 stream_read(stream, p, buf_size); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1913 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1914 len = pes_parse2(p, buf_size, es, pid_type); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1915 es->pid = tss->pid; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1916 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1917 if(probe) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1918 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1919 if(es->type == UNKNOWN) |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1920 return 0; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1921 if(len == 0) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1922 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1923 if(tss->type != UNKNOWN) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1924 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1925 es->size = buf_size; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1926 es->start = p; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1927 return 1; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1928 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1929 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1930 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1931 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1932 tss->type = es->type; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1933 return 1; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1934 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1935 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1936 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1937 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1938 if(len == 0) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1939 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1940 if(tss->type != UNKNOWN) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1941 { |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1942 len = es->size = buf_size; //push the whole packet to the fifo |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1943 //(we already learned what it is during the probe phase) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1944 es->start = p; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1945 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1946 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1947 continue; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1948 } |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1949 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1950 if((es->pts < tss->last_pts) && es->pts) |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1951 mp_msg(MSGT_DEMUX, MSGL_DBG2, "BACKWARDS PTS! : NEW: %f -> LAST: %f, PID %d\n", es->pts, tss->last_pts, tss->pid); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1952 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1953 if(es->pts == 0.0f) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1954 es->pts = tss->pts = tss->last_pts; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1955 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1956 tss->pts = tss->last_pts = es->pts; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1957 |
12049
5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
nicodvb
parents:
11412
diff
changeset
|
1958 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse, NEW pid=%d, PSIZE: %u, type=%X, start=%p, len=%d\n", |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1959 es->pid, es->payload_size, es->type, es->start, es->size); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1960 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1961 tss->payload_size = es->payload_size; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1962 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1963 demuxer->filepos = stream_tell(demuxer->stream) - es->size; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1964 |
11190 | 1965 if(*dp_offset + es->size > *buffer_size) |
1966 { | |
1967 *buffer_size = *dp_offset + es->size + TS_FEC_PACKET_SIZE; | |
1968 resize_demux_packet(*dp, *buffer_size); | |
1969 //we'll skip at least one RESIZE() in the next iteration of ts_parse() | |
1970 mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size); | |
1971 } | |
1972 memcpy(&((*dp)->buffer[*dp_offset]), es->start, es->size); | |
1973 *dp_offset += es->size; | |
1974 (*dp)->flags = 0; | |
1975 (*dp)->pos = stream_tell(demuxer->stream); | |
1976 (*dp)->pts = es->pts; | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1977 |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1978 if(is_audio) |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1979 { |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1980 retv = fill_packet(demuxer, ds, dp, dp_offset); |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1981 return 1; |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
1982 } |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1983 |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1984 if(retv > 0) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1985 return retv; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1986 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1987 continue; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1988 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1989 } |
10014 | 1990 else |
1991 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1992 uint16_t sz; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1993 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1994 if(tss->type == UNKNOWN) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
1995 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
1996 stream_skip(stream, buf_size); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1997 if(probe) |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1998 return 0; |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
1999 else |
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
2000 continue; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2001 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2002 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2003 |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2004 es->pid = tss->pid; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2005 es->type = tss->type; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2006 es->pts = tss->pts = tss->last_pts; |
11190 | 2007 es->start = &packet[base]; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2008 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2009 |
11190 | 2010 if(tss->payload_size > 0) |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2011 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2012 sz = min(tss->payload_size, buf_size); |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2013 tss->payload_size -= sz; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2014 es->size = sz; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2015 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2016 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2017 { |
11190 | 2018 if(is_video) |
2019 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2020 sz = es->size = buf_size; |
11190 | 2021 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2022 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2023 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2024 stream_skip(stream, buf_size); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2025 continue; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2026 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2027 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2028 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2029 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2030 if(! probe) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2031 { |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2032 if(*dp_offset + sz > *buffer_size) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2033 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2034 *buffer_size = *dp_offset + sz + TS_FEC_PACKET_SIZE; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2035 resize_demux_packet(*dp, *buffer_size); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2036 //we'll skip at least one RESIZE() in the next iteration of ts_parse() |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2037 mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size); |
11190 | 2038 //mp_msg(MSGT_DEMUX, MSGL_INFO, "SECOND TYPE=%x, bytes=%d, afc=%d, psize=%d, tell=%llu\n", es->type, sz, afc, tss->payload_size, (uint64_t) stream_tell(demuxer->stream)); |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2039 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2040 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2041 stream_read(stream, &((*dp)->buffer[*dp_offset]), sz); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2042 *dp_offset += sz; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2043 |
11190 | 2044 if(buf_size - sz > 0) |
2045 { | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2046 stream_skip(stream, buf_size - sz); |
11190 | 2047 } |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2048 |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2049 if(is_audio) |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2050 { |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
2051 (*dp)->pts = tss->last_pts; |
12518
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2052 retv = fill_packet(demuxer, ds, dp, dp_offset); |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2053 return 1; |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2054 } |
996757299a82
removed unused and commented code; audio is pushed synchronously (reported to work better); pid 16 is not default PMT (100l); trails of data are add_packet()ed
nicodvb
parents:
12049
diff
changeset
|
2055 |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2056 continue; |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2057 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2058 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2059 { |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2060 stream_read(stream, es->start, sz); |
12612
a731d98a3382
added support for ac3 in non-pes aligned private1 streams; removed useless and commented code
nicodvb
parents:
12518
diff
changeset
|
2061 if(buf_size - sz) stream_skip(stream, buf_size-sz); |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2062 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2063 if(es->size) |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2064 return es->size; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2065 else |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2066 continue; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2067 } |
10014 | 2068 } |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2069 } |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2070 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2071 return 0; |
9610 | 2072 } |
2073 | |
2074 | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2075 extern void resync_audio_stream(sh_audio_t *sh_audio); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2076 extern void skip_audio_frame(sh_audio_t *sh_audio); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2077 |
11190 | 2078 static void reset_fifos(ts_priv_t* priv, int a, int v, int s) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2079 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2080 if(a) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2081 { |
11190 | 2082 if(priv->fifo[0].pack != NULL) |
2083 { | |
2084 free_demux_packet(priv->fifo[0].pack); | |
2085 priv->fifo[0].pack = NULL; | |
2086 } | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2087 priv->fifo[0].offset = 0; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2088 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2089 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2090 if(v) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2091 { |
11190 | 2092 if(priv->fifo[1].pack != NULL) |
2093 { | |
2094 free_demux_packet(priv->fifo[1].pack); | |
2095 priv->fifo[1].pack = NULL; | |
2096 } | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2097 priv->fifo[1].offset = 0; |
11190 | 2098 } |
2099 | |
2100 if(s) | |
2101 { | |
2102 if(priv->fifo[2].pack != NULL) | |
2103 { | |
2104 free_demux_packet(priv->fifo[2].pack); | |
2105 priv->fifo[2].pack = NULL; | |
2106 } | |
2107 priv->fifo[2].offset = 0; | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2108 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2109 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2110 |
11190 | 2111 extern int videobuf_code_len; |
2112 extern int sync_video_packet(demux_stream_t *); | |
2113 extern int skip_video_packet(demux_stream_t *); | |
2114 | |
2115 void demux_seek_ts(demuxer_t *demuxer, float rel_seek_secs, int flags) | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2116 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2117 demux_stream_t *d_audio=demuxer->audio; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2118 demux_stream_t *d_video=demuxer->video; |
11190 | 2119 demux_stream_t *d_sub=demuxer->sub; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2120 sh_audio_t *sh_audio=d_audio->sh; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2121 sh_video_t *sh_video=d_video->sh; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2122 ts_priv_t * priv = (ts_priv_t*) demuxer->priv; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2123 int i, video_stats; |
11190 | 2124 off_t newpos; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2125 |
11190 | 2126 //================= seek in MPEG-TS ========================== |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2127 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2128 ts_dump_streams(demuxer->priv); |
11190 | 2129 reset_fifos(priv, sh_audio != NULL, sh_video != NULL, demuxer->sub->id > 0); |
2130 | |
2131 | |
2132 if(sh_audio != NULL) | |
2133 ds_free_packs(d_audio); | |
2134 if(sh_video != NULL) | |
2135 ds_free_packs(d_video); | |
2136 if(demuxer->sub->id > 0) | |
2137 ds_free_packs(d_sub); | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2138 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2139 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2140 video_stats = (sh_video != NULL); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2141 if(video_stats) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2142 video_stats = sh_video->i_bps; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2143 |
11190 | 2144 newpos = (flags & 1) ? demuxer->movi_start : demuxer->filepos; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2145 if(flags & 2) // float seek 0..1 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2146 newpos+=(demuxer->movi_end-demuxer->movi_start)*rel_seek_secs; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2147 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2148 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2149 // time seek (secs) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2150 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2151 if(! video_stats) // unspecified or VBR |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2152 newpos += 2324*75*rel_seek_secs; // 174.3 kbyte/sec |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2153 else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2154 newpos += video_stats*rel_seek_secs; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2155 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2156 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2157 |
11190 | 2158 if(newpos < demuxer->movi_start) |
2159 newpos = demuxer->movi_start; //begininng of stream | |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2160 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2161 #ifdef _LARGEFILE_SOURCE |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2162 newpos &= ~((long long) (STREAM_BUFFER_SIZE - 1)); /* sector boundary */ |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2163 #else |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2164 newpos &= ~(STREAM_BUFFER_SIZE - 1); /* sector boundary */ |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2165 #endif |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2166 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2167 stream_seek(demuxer->stream, newpos); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2168 |
11190 | 2169 videobuf_code_len = 0; |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2170 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2171 if(sh_video != NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2172 ds_fill_buffer(d_video); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2173 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2174 if(sh_audio != NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2175 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2176 ds_fill_buffer(d_audio); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2177 resync_audio_stream(sh_audio); |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2178 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2179 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2180 while(sh_video != NULL) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2181 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2182 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts) |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2183 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2184 float a_pts=d_audio->pts; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2185 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
11190 | 2186 if(d_video->pts > a_pts) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2187 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2188 skip_audio_frame(sh_audio); // sync audio |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2189 continue; |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2190 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2191 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2192 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2193 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2194 i = sync_video_packet(d_video); |
11190 | 2195 if((sh_video->format == VIDEO_MPEG1) || (sh_video->format == VIDEO_MPEG2)) |
10686
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2196 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2197 if(i==0x1B3 || i==0x1B8) break; // found it! |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2198 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2199 else //MPEG4 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2200 { |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2201 if(i==0x1B6) break; // found it! |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2202 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2203 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2204 if(!i || !skip_video_packet(d_video)) break; // EOF? |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2205 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2206 } |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2207 |
8eb690f0e342
- seek() is always synchronized to keyframes, so the decoders don't
arpi
parents:
10310
diff
changeset
|
2208 |
9610 | 2209 int demux_ts_fill_buffer(demuxer_t * demuxer) |
2210 { | |
10253
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2211 ES_stream_t es; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2212 char packet[TS_FEC_PACKET_SIZE]; |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2213 |
978b12dcb9ef
- open new_ds_[audio | video] only when the relative streams are really available
arpi
parents:
10242
diff
changeset
|
2214 return -ts_parse(demuxer, &es, packet, 0); |
9610 | 2215 } |
2216 | |
2217 | |
2218 |