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