annotate libmpdemux/demux_ts.c @ 11269:669e67c3d6b3

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