annotate libmpdemux/demux_ts.c @ 10861:59e3d641c48c

Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
author mosu
date Fri, 12 Sep 2003 21:56:03 +0000
parents d4cf5407d7c6
children dad43bc55cfc
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"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
37
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
38
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
39 #define TS_FEC_PACKET_SIZE 204
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
40 #define TS_PACKET_SIZE 188
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
41 #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
42
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
43 #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
44 #define MAX_CHECK_SIZE 65535
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
45 #define MAX_PROBE_SIZE 2000000
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
46 #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
47 #define NUM_CONSECUTIVE_AUDIO_PACKETS 348
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
48
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
49
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
50 int ts_prog;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
51
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
52 typedef enum
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
53 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
54 UNKNOWN = -1,
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
55 VIDEO_MPEG1 = 0x10000001,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
56 VIDEO_MPEG2 = 0x10000002,
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
57 VIDEO_MPEG4 = 0x10000004,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
58 AUDIO_MP2 = 0x50,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
59 AUDIO_A52 = 0x2000,
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
60 AUDIO_LPCM_BE = 0x10001,
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
61 AUDIO_AAC = (('A' << 24) | ('4' << 16) | ('P' << 8) | 'M')
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
62 /*,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
63 SPU_DVD = 0x3000000,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
64 SPU_DVB = 0x3000001,
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
65 */
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
66 } es_stream_type_t;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
67
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
68
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
69 typedef struct {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
70 int size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
71 unsigned char *start;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
72 uint16_t payload_size;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
73 es_stream_type_t type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
74 float pts, last_pts;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
75 int pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
76 int last_cc; // last cc code (-1 if first packet)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
77 } ES_stream_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
78
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
79
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
80 typedef struct MpegTSContext {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
81 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
82 ES_stream_t *pids[NB_PID_MAX];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
83 } MpegTSContext;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
84
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
85
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
86 typedef struct {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
87 demux_stream_t *ds;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
88 demux_packet_t *pack;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
89 int offset, buffer_size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
90 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
91 } av_fifo_t;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
92
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
93 typedef struct {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
94 uint8_t skip;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
95 uint8_t table_id;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
96 uint8_t ssi;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
97 uint16_t section_length;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
98 uint16_t ts_id;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
99 uint8_t version_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
100 uint8_t curr_next;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
101 uint8_t section_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
102 uint8_t last_section_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
103 struct pat_progs_t {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
104 uint16_t id;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
105 uint16_t pmt_pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
106 } *progs;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
107 uint16_t progs_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
108 char buffer[65535];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
109 uint8_t buffer_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
110 } pat_t;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
111
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
112 typedef struct {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
113 uint16_t progid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
114 uint8_t skip;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
115 uint8_t table_id;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
116 uint8_t ssi;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
117 uint16_t section_length;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
118 uint8_t version_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
119 uint8_t curr_next;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
120 uint8_t section_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
121 uint8_t last_section_number;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
122 uint16_t PCR_PID;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
123 uint16_t prog_descr_length;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
124 char buffer[2048];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
125 uint8_t buffer_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
126 uint16_t es_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
127 struct pmt_es_t {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
128 uint16_t pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
129 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
130 uint16_t descr_length;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
131 } *es;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
132 } pmt_t;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
133
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
134 typedef struct {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
135 MpegTSContext ts;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
136 int is_synced; //synced to the beginning of priv->last_pid PES header
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
137 int last_afc; //bytes read from the last adaption field
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
138 int last_pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
139 int is_start;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
140 int eof;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
141 av_fifo_t fifo[2]; //0 for audio, 1 for video
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
142 pat_t pat;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
143 pmt_t *pmt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
144 uint16_t pmt_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
145 uint32_t prog;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
146 } ts_priv_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
147
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
148
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
149 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
150 extern void resync_audio_stream( sh_audio_t *sh_audio );
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
151
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
152 static uint8_t get_packet_size(const unsigned char *buf, int size)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
153 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
154 int i;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
155
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
156 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
157 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
158
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
159 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
160 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
161 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
162 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
163 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
164 goto try_fec;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
165 }
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
166 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
167 return TS_PACKET_SIZE;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
168
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
169 try_fec:
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
170 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
171 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
172 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
173 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
174 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
175 return TS_FEC_PACKET_SIZE;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
176 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
177
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
178
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
179
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
180 int ts_check_file(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
181 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
182 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
183 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
184 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
185 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
186 uint8_t size = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
187 off_t pos = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
188
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
189 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
190
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
191 is_ts = 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
192 while(! done)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
193 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
194 i = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
195 c = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
196
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
197 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
198 && (c >= 0)
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
199 && (i < MAX_CHECK_SIZE)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
200 && ! demuxer->stream->eof
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
201 ) i++;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
202
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
203
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
204 if(c != 0x47)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
205 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
206 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
207 is_ts = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
208 done = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
209 continue;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
210 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
211
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
212 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
213 buf[0] = c;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
214 _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
215
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
216 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
217 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
218 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
219 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
220 return 0;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
221 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
222
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
223 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
224 if(size)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
225 {
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
226 done = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
227 is_ts = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
228 }
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
229
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
230 if(pos >= MAX_CHECK_SIZE)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
231 {
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
232 done = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
233 is_ts = 0;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
234 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
235 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
236
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
237 mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FOUND %x, packet_size= %d\n", pos, c, size);
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
238 stream_seek(demuxer->stream, pos);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
239
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
240 if(! is_ts)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
241 return 0;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
242
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
243 //LET'S CHECK continuity counters
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
244 good = bad = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
245 for(count = 0; count < NB_PID_MAX; count++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
246 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
247 cc[count] = last_cc[count] = -1;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
248 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
249
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
250 for(count = 0; count < NUM_CONSECUTIVE_TS_PACKETS; 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 ptr = &(buf[size * count]);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
253 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
254 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
255 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
256
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
257 if((pid == 8191) || (pid < 16))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
258 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
259
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
260 cc[pid] = (ptr[3] & 0xf);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
261 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
262 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
263 if(! cc_ok)
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
264 //return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
265 bad++;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
266 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
267 good++;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
268
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
269 last_cc[pid] = cc[pid];
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
270 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
271
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
272 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
273
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
274 if(good >= bad)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
275 return size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
276 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
277 return 0;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
280
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
281 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
282 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
283 int x;
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 if(priv->pmt == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
286 return -1;
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 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
289 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
290 if(priv->pmt[x].progid == progid)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
291 return x;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
294 return -1;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
295 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
296
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
297
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
298 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
299 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
300 int i, j;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
301 pmt_t *pmt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
302
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
303
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
304 if(priv->pmt == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
305 return -1;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
306
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
307
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
308 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
309 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
310 pmt = &(priv->pmt[i]);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
311
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
312 if(pmt->es == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
313 return -1;
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 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
316 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
317 if(pmt->es[j].pid == pid)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
318 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
319 if((req == 0) || (req == pmt->progid))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
320 return pmt->progid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
321 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
322 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
323
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
324 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
325 return -1;
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 static void ts_detect_streams(demuxer_t *demuxer, uint32_t *a, uint32_t *v, int *fapid, int *fvpid, int32_t *prog)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
330 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
331 int video_found = 0, audio_found = 0, i, num_packets = 0, req_apid, req_vpid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
332 int is_audio, is_video, has_tables;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
333 int32_t p, chosen_pid;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
334 off_t pos=0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
335 ES_stream_t es;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
336 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
337 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
338
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
339 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
340 priv->last_afc = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
341 priv->last_pid = 8192; //invalid pid
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
342 priv->is_start = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
343 priv->eof = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
344
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
345 req_apid = *fapid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
346 req_vpid = *fvpid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
347
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
348 has_tables = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
349 mp_msg(MSGT_DEMUXER, MSGL_INFO, "PROBING UP TO %u, PROG: %d\n", MAX_PROBE_SIZE, *prog);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
350 while(pos <= MAX_PROBE_SIZE)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
351 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
352 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
353 if(ts_parse(demuxer, &es, tmp, 1))
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
354 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
355 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
356 is_video = ((es.type == VIDEO_MPEG1) || (es.type == VIDEO_MPEG2) || (es.type == VIDEO_MPEG4));
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
357
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
358 if((! is_audio) && (! is_video))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
359 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
360
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
361 if(is_video)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
362 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
363 chosen_pid = (req_vpid == es.pid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
364 if((! chosen_pid) && (req_vpid > 0))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
365 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
366 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
367 else if(is_audio)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
368 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
369 chosen_pid = (req_apid == es.pid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
370 if((! chosen_pid) && (req_apid > 0))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
371 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
372 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
373
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
374 if(req_vpid < 0 && req_apid < 0)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
375 chosen_pid = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
376
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
377 p = progid_for_pid(priv, es.pid, *prog);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
378 if(p != -1)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
379 has_tables++;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
380
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
381 if((*prog == 0) && (p != -1))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
382 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
383 if(chosen_pid)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
384 *prog = p;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
385 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
386
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
387 if((*prog > 0) && (*prog != p))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
388 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
389 if(audio_found)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
390 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
391 if(is_video && (req_vpid == es.pid))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
392 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
393 *v = es.type;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
394 *fvpid = es.pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
395 video_found = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
396 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
397 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
398 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
399
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
400 if(video_found)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
401 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
402 if(is_audio && (req_apid == es.pid))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
403 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
404 *a = es.type;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
405 *fapid = es.pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
406 audio_found = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
407 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
408 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
409 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
410
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
411
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
412 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
413 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
414
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
415
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
416 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "TYPE: %x, PID: %d, PROG FOUND: %d\n", es.type, es.pid, *prog);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
417
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
418
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
419 if(is_video)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
420 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
421 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
422 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
423 *v = es.type;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
424 *fvpid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
425 video_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
426 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
427 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
428
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
429
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
430 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
431 {
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
432 //novideo or we have at least 348 audio packets (64 KB) without video (TS with audio only)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
433 *v = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
434 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
435 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
436
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
437
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
438 if(is_audio)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
439 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
440 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
441 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
442 *a = es.type;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
443 *fapid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
444 audio_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
445 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
446 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
447
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
448 if(audio_found && (*fapid == es.pid) && (! video_found))
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
449 num_packets++;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
450
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
451 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
452 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
453 *a = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
454 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
455 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
456
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
457 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
458 break;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
459 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
460 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
461
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
462 if(video_found)
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
463 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG%d(pid=%d)...", (*v == VIDEO_MPEG1 ? 1 : (*v == VIDEO_MPEG2 ? 2 : 4)), *fvpid);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
464 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
465 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
466 //WE DIDN'T MATCH ANY VIDEO STREAM
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
467 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO VIDEO! ");
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
468 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
469
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
470 if(*a == AUDIO_MP2)
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
471 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO MP2(pid=%d)", *fapid);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
472 else if(*a == AUDIO_A52)
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
473 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO A52(pid=%d)", *fapid);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
474 else if(*a == AUDIO_LPCM_BE)
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
475 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO LPCM(pid=%d)", *fapid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
476 else if(*a == AUDIO_AAC)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
477 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO AAC(pid=%d)", *fapid);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
478 else
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
479 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
480 //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
481 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
482 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
483
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
484 mp_msg(MSGT_DEMUXER, MSGL_INFO, " PROGRAM N. %d\n", *prog);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
485
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
486 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
487 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
488 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
489 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
490 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
491 priv->ts.pids[i]->pts = priv->ts.pids[i]->last_pts = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
492 //priv->ts.pids[i]->type = UNKNOWN;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
493 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
494 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
495 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
496
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
497
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
498
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
499 demuxer_t *demux_open_ts(demuxer_t * demuxer)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
500 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
501 int i;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
502 uint8_t packet_size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
503 sh_video_t *sh_video;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
504 sh_audio_t *sh_audio;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
505 uint32_t at = 0, vt = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
506 ts_priv_t * priv = (ts_priv_t*) demuxer->priv;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
507 demuxer_t *od;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
508
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
509 mp_msg(MSGT_DEMUX, MSGL_DBG2, "DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
510 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
511
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
512
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
513 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
514
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
515
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
516 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
517 stream_seek(demuxer->stream, 0);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
518
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
519 packet_size = ts_check_file(demuxer);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
520 if(!packet_size)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
521 return NULL;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
522
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
523 priv = malloc(sizeof(ts_priv_t));
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
524 if(priv == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
525 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
526 mp_msg(MSGT_DEMUX, MSGL_FATAL, "DEMUX_OPEN_TS, couldn't allocate %lu bytes, exit\n",
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
527 sizeof(ts_priv_t));
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
528 return NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
529 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
530
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
531 for(i=0; i < 8192; i++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
532 priv->ts.pids[i] = NULL;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
533 priv->pat.progs = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
534 priv->pat.progs_cnt = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
535
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
536 priv->pmt = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
537 priv->pmt_cnt = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
538
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
539 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
540
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
541
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
542 demuxer->priv = priv;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
543 if(demuxer->stream->type != STREAMTYPE_FILE)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
544 demuxer->seekable = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
545 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
546 demuxer->seekable = 1;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
547
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
548 stream_seek(demuxer->stream, 0); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
549 ts_detect_streams(demuxer, &at, &vt, &demuxer->audio->id, &demuxer->video->id, &ts_prog);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
550 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer, audio: %x(pid %d), video: %x(pid %d)...\n", at, demuxer->audio->id, vt, demuxer->video->id);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
551
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
552
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
553 if(vt)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
554 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
555 if(vt == VIDEO_MPEG4)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
556 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
557
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
558 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
559 sh_video->ds = demuxer->video;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
560 sh_video->format = vt;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
561 demuxer->video->sh = sh_video;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
562
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
563 mp_msg(MSGT_DEMUXER,MSGL_INFO, "OPENED_SH_VIDEO\n");
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
564 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
565
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
566 if(at)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
567 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
568 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
569 sh_audio->ds = demuxer->audio;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
570 sh_audio->format = at;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
571 demuxer->audio->sh = sh_audio;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
572
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
573 mp_msg(MSGT_DEMUXER,MSGL_INFO, "OPENED_SH_AUDIO\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
574 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
575
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
576
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
577 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer2\n");
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
578
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
579 /*
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
580 demuxer->movi_start = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
581 demuxer->movi_end = demuxer->stream->end_pos;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
582 */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
583
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
584 stream_seek(demuxer->stream, 0); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
585
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
586
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
587
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
588 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
589 priv->last_afc = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
590 priv->last_pid = 8192; //invalid pid
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
591 priv->is_start = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
592
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
593 for(i=0; i< 2; i++)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
594 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
595 priv->fifo[i].pack = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
596 priv->fifo[i].offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
597 priv->fifo[i].broken = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
598 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
599 priv->fifo[0].ds = demuxer->audio;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
600 priv->fifo[1].ds = demuxer->video;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
601
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
602 priv->fifo[0].buffer_size = 1536;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
603 priv->fifo[1].buffer_size = 32767;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
604 priv->eof = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
605
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
606 priv->pat.buffer_len = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
607
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
608 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
609 return demuxer;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
610 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
611
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
612
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
613
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
614
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
615
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
616
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
617 void demux_close_ts(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
618 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
619 if(demuxer->priv)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
620 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
621 free(demuxer->priv);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
622 demuxer->priv=NULL;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
623 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
624 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
625
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
626
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
627
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
628
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
629
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
630 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
631 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
632 unsigned char *p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
633 uint32_t header_len;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
634 int64_t pts;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
635 uint32_t stream_id;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
636 uint32_t pkt_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
637
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
638 //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
639 //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
640 //int64_t escr, dts;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
641 //uint32_t es_rate;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
642
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
643 //Here we are always at the start of a PES packet
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
644 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2(%X, %d): \n", buf, packet_len);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
645
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
646 if(packet_len == 0)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
647 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
648 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
649 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
650 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
651
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
652 if(packet_len > 184)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
653 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
654 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
655 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
656 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
657
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
658
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
659 p = buf;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
660 pkt_len = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
661
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
662
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
663 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
664 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
665 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
666 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
667 return 0 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
668 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
669
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
670 packet_len -= 6;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
671 if(packet_len==0)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
672 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
673
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
674 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
675
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
676 stream_id = p[3];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
677
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
678
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
679 if (p[7] & 0x80)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
680 { /* pts available */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
681 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
682 pts |= p[10] << 22 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
683 pts |= (p[11] & 0xFE) << 14 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
684 pts |= p[12] << 7 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
685 pts |= (p[13] & 0xFE) >> 1 ;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
686
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
687 es->pts = pts / 90000.0f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
688 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
689 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
690 es->pts = 0.0f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
691
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
692 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
693 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
694
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
695 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
696 escr_flag = p[7] & 0x20;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
697 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
698 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
699
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
700
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
701 if(es_rate_flag)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
702 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
703 char *base;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
704 int bytes = 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
705
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
706 if(pts_flag == 2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
707 bytes += 5;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
708 else if(pts_flag == 3)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
709 bytes += 10;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
710
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
711 if(escr_flag)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
712 bytes += 6;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
713
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
714 base = p[8+bytes];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
715 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
716 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
717 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
718 */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
719
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
720 header_len = p[8];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
721
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
722
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
723 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
724 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
725 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
726 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
727 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
728
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
729 p += header_len + 9;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
730 packet_len -= header_len + 3;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
731
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
732 if(es->payload_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
733 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
734
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
735
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
736 if (stream_id == 0xbd)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
737 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
738 int track; //, spu_id;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
739
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
740 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
741 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
742
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
743 track = p[0] & 0x0F;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
744 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 TRACK: %d\n", track);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
745
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
746
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
747 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
748 * we check the descriptor tag first because some stations
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
749 * do not include any of the ac3 header info in their audio tracks
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
750 * 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
751 */
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
752
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
753
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
754 if(
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
755 (type_from_pmt == AUDIO_A52) || /* ac3 - raw */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
756 (p[0] == 0x0B && p[1] == 0x77) /* ac3 - syncword */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
757 )
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
758 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
759 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 RAW OR SYNCWORD\n");
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
760 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
761 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
762 es->type = AUDIO_A52;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
763 es->payload_size -= packet_len;
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 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
766 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
767 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
768 SUBS, it seems they are not streams in g1, what to do?
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
769 else if (//m->descriptor_tag == 0x06 &&
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
770 p[0] == 0x20 && p[1] == 0x00)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
771 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
772 // DVBSUB
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
773 long payload_len = ((buf[4] << 8) | buf[5]) - header_len - 3;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
774 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
775 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
776 es->type = SPU_DVB + payload_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
777 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
778
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
779 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
780 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
781
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
782 else if ((p[0] & 0xE0) == 0x20)
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 spu_id = (p[0] & 0x1f);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
785 es->start = p+1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
786 es->size = packet_len-1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
787 es->type = SPU_DVD + spu_id;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
788 es->payload_size -= packet_len;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
789
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
790 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
791 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
792 */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
793 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
794 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
795 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 WITH HEADER\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
796 es->start = p+4;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
797 es->size = packet_len - 4;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
798 es->type = AUDIO_A52;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
799 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
800
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
801 return es->size;
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 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
804 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
805 int pcm_offset;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
806
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
807 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
808 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
809 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
810 { /* START */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
811 pcm_offset += 2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
812 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
813 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
814 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
815
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
816 es->start = p + pcm_offset;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
817 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
818 es->type = AUDIO_LPCM_BE;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
819 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
820
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
821 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
822 }
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 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
825 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
826 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
827 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
828 es->type = VIDEO_MPEG2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
829 if(es->payload_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
830 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
831
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
832 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
833 }
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
834 else if ((stream_id == 0xfa))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
835 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
836 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
837 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
838 es->start = p;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
839 es->size = packet_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
840 es->type = type_from_pmt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
841 if(es->payload_size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
842 es->payload_size -= packet_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
843
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
844 return es->size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
845 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
846 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
847 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
848 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
849 int track;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
850
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
851 track = stream_id & 0x1f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
852 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
853 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
854 es->type = AUDIO_MP2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
855 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
856
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
857 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
858 }
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
859 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
860 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
861 es->start = p;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
862 es->size = packet_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
863 es->type = type_from_pmt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
864 es->payload_size -= packet_len;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
865
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
866 return es->size;
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
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
869 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
870 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
871 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
872 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
873
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
874 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
875 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
876
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
877
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
878
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
879
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
880 static int ts_sync(stream_t *stream)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
881 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
882 int c=0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
883
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
884 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
885
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
886 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
887
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
888 if(c == 0x47)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
889 return c;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
890 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
891 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
892 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
893
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
894
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
895 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
896 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
897 int i;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
898
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
899 for(i = 0; i < 2; i++)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
900 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
901 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
902 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
903 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
904 ds_add_packet(priv->fifo[i].ds, priv->fifo[i].pack);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
905 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
906 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
907
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
908 priv->eof = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
909 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
910
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
911
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
912 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
913 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
914 int x;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
915
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
916 if(priv->pat.progs == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
917 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
918
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
919 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
920 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
921 if(priv->pat.progs[x].id == progid)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
922 return x;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
923 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
924
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
925 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
926 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
927
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
928
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
929 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
930 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
931 int x;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
932
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
933 if(priv->pat.progs == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
934 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
935
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
936 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
937 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
938 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
939 return priv->pat.progs[x].id;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
940 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
941
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
942 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
943 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
944
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
945
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
946 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
947 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
948 uint8_t skip, m = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
949 unsigned char *ptr;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
950 unsigned char *base; //, *crc;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
951 int entries, i, sections;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
952 uint16_t progid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
953 //uint32_t o_crc, calc_crc;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
954
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
955 //PRE-FILLING
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
956 if(! is_start)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
957 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
958 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
959 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
960 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
961 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
962
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
963 if(priv->pat.skip)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
964 m = min(priv->pat.skip, size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
965
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
966 priv->pat.skip -= m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
967 if(m == size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
968 return -1; //keep on buffering
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
969 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
970 else //IS_START, replace the old content
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
971 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
972 priv->pat.buffer_len = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
973 skip = buff[0]+1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
974 m = min(skip, size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
975
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
976 priv->pat.skip = skip - m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
977
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
978 if(m == size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
979 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
980 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
981
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
982 //FILLING
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
983 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
984
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
985 priv->pat.buffer_len += size - m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
986
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
987 //PARSING
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
988 ptr = priv->pat.buffer;
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 priv->pat.table_id = ptr[0];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
991 priv->pat.ssi = (ptr[1] >> 7) & 0x1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
992 priv->pat.curr_next = ptr[5] & 0x01;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
993 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
994 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
995 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
996 priv->pat.section_number = ptr[6];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
997 priv->pat.last_section_number = ptr[7];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
998
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
999 /*CRC CHECK
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1000 crc = &(priv->pat.buffer[priv->pat.section_length - 4]);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1001 o_crc = (crc[0] << 24) | (crc[1] << 16) | (crc[2] << 8) | crc[3];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1002 calc_crc = CalcCRC32(0xFFFFFFFFL, priv->pat.buffer, priv->pat.section_length);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1003 printf("CRC ORIGINALE: %x, CALCOLATO: %x\n", o_crc, calc_crc);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1004 */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1005
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1006
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1007 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
1008 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1009
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1010
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1011 //beginning of sections loop
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1012 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
1013 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
1014
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1015 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
1016 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1017 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
1018 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
1019
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1020 return -1; //KEEP ON FILLING THE TABLE
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1021 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1022
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1023 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
1024
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1025
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1026 for(i=0; i < entries; i++)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1027 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1028 int32_t idx;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1029 base = &ptr[8 + i*4];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1030 progid = (base[0] << 8) | base[1];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1031
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1032 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
1033 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1034 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
1035 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
1036 if(priv->pat.progs == NULL)
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 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
1039 break;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1042 idx = priv->pat.progs_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1043 priv->pat.progs_cnt++;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1046 priv->pat.progs[idx].id = progid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1047 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
1048 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
1049 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1050
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1051 return 1;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1055 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
1056 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1057 int i;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1058
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1059 if(pmt == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1060 return -1;
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(pmt->es == 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(i = 0; i < pmt->es_cnt; i++)
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(pmt->es[i].pid == pid)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1068 return i;
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 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1073
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1074
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1075
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1076 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
1077 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1078 unsigned char *base, *es_base;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1079 pmt_t *pmt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1080 int32_t idx, es_count, section_bytes;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1081 uint8_t skip, m=0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1082
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1083 idx = progid_idx_in_pmt(priv, progid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1084
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1085 if(idx == -1)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1086 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1087 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
1088 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
1089 if(priv->pmt == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1090 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1091 mp_msg(MSGT_DEMUX, MSGL_ERR, "FILL_PMT: 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
1092 return NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1093 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1094
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1095 idx = priv->pmt_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1096 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
1097 priv->pmt_cnt++;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1098 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1099
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1100 pmt = &(priv->pmt[idx]);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1101
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1102
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1103 if(! is_start)
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 if(pmt->buffer_len == 0)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1106 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1107 //BROKEN PMT PACKET, DISCARD
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1108 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1109 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1110
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1111 if(pmt->skip)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1112 m = min(pmt->skip, size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1113
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1114 pmt->skip -= m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1115 if(m == size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1116 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1117 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1118 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1119 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1120 pmt->buffer_len = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1121 skip = buff[0] + 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1122 m = min(skip, size);
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 pmt->skip = skip - m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1125
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1126 if(m == size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1127 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1128 }
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 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
1131 pmt->progid = progid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1132 pmt->buffer_len += size - m;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1133
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1134
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1135 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_PMT(prog=%d), PMT_len: %d, IS_START: %d, TSPID: %d\n",
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1136 progid, pmt->buffer_len, is_start, pid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1137
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1138 base = pmt->buffer;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1139
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1140
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1141 pmt->table_id = base[0];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1142 pmt->ssi = base[1] & 0x80;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1143 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
1144 pmt->version_number = (base[5] >> 1) & 0x1f;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1145 pmt->curr_next = (base[5] & 1);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1146 pmt->section_number = base[6];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1147 pmt->last_section_number = base[7];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1148 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
1149 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
1150
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1151
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 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
1154 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1155
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1156
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1157 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
1158 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1159 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);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1160 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1161 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1162
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1163 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
1164 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1165 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
1166 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1167 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1168
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 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
1171
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1172 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
1173 es_count = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1174
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1175 while(section_bytes >= 5)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1176 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1177 int es_pid, es_type;
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 es_type = es_base[0];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1180 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
1181
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1182 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
1183 if(idx == -1)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1184 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1185 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
1186 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
1187 if(pmt->es == NULL)
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 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
1190 continue;
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 idx = pmt->es_cnt;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1193 pmt->es_cnt++;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1194 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1195
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1196 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
1197
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1198
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1199 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
1200 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1201 mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PMT, ES_DESCR_LENGTH TOO LARGE %d > %d, EXIT %d bytes for PMT_ES\n",
10735
8a10d5d0ce86 serious bugs - 1l absinth (changed to absinth against cola inflation)
alex
parents: 10686
diff changeset
1202 pmt->es[idx].descr_length, section_bytes - 5, section_bytes);
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1203 return -1;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1206
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1207 pmt->es[idx].pid = es_pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1208 pmt->es[idx].type = es_type;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1209
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1210 switch(es_type)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1211 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1212 case 1:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1213 pmt->es[idx].type = VIDEO_MPEG1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1214 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1215 case 2:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1216 pmt->es[idx].type = VIDEO_MPEG2;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1217 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1218 case 3:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1219 case 4:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1220 pmt->es[idx].type = AUDIO_MP2;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1221 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1222 case 6:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1223 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1224 int j;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1225 for(j = 5; j < pmt->es[idx].descr_length; j += es_base[j+1] + 2) //possible DVB-AC3
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1226 if(es_base[j] == 0x6a)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1227 pmt->es[idx].type = AUDIO_A52;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1228 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1229 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1230
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1231 case 0x10:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1232 pmt->es[idx].type = VIDEO_MPEG4;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1233 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1234 case 0x11:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1235 pmt->es[idx].type = AUDIO_AAC;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1236 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1237
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1238 case 0x81:
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1239 pmt->es[idx].type = AUDIO_A52;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1240 break;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1241 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1242
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1243
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1244 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
1245 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
1246 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
1247
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1248
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1249 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
1250
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1251 es_count++;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1252 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1253
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1254 return 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1255 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1256
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1257
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1258 // 0 = EOF or no stream found
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1259 // 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
1260 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
1261 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
1262 ES_stream_t *tss;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1263 uint8_t done = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1264 int buf_size, is_start;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1265 int len, pid, cc, cc_ok, afc, _read;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
1266 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
1267 stream_t *stream = demuxer->stream;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1268 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
1269 demux_stream_t *ds = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1270 demux_packet_t **dp = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1271 int *dp_offset = 0, *buffer_size = 0, *broken = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1272 int32_t progid, pid_idx, pid_type;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1273
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1274
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1275 while(! done)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1276 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1277 if(stream_eof(stream))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1278 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1279 if(! priv->eof)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1280 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1281 ts_dump_streams(priv);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1282 demuxer->filepos = stream_tell(demuxer->stream);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1283 return -1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1284 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1285 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1286 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1287 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1288
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1289
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1290 if(! priv->is_synced)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1291 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1292 if(! ts_sync(stream))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1293 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1294 mp_msg(MSGT_DEMUX, MSGL_V, "TS_PARSE: COULDN'T SYNC\n");
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1295 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1296 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1297
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1298 len = stream_read(stream, &packet[1], 3);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1299 if (len != 3)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1300 return 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1301 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1302 _read = 4;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1303
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1304 if(! priv->is_synced)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1305 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1306 is_start = packet[1] & 0x40;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1307 pid = ((packet[1] & 0x1f) << 8) | packet[2];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1308 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1309 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1310 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1311 is_start = priv->is_start;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1312 pid = priv->last_pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1313 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1314
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1315 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
1316 if(tss == NULL)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1317 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1318 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
1319 if(! tss)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1320 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1321 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
1322 tss->pid = pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1323 tss->last_cc = -1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1324 tss->type = UNKNOWN;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1325 tss->payload_size = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1326 priv->ts.pids[pid] = tss;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1327 mp_msg(MSGT_DEMUX, MSGL_INFO, "\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
1328 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1329
10686
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 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
1333 continue;
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1334
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1335 cc = (packet[3] & 0xf);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1336 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
1337 if(! cc_ok)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1338 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1339 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse: CCCheck NOT OK: %d -> %d\n", tss->last_cc, cc);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1340 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1341 tss->last_cc = cc;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1342
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1343
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1344 if(! priv->is_synced)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1345 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1346 priv->last_afc = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1347 /* skip adaptation field */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1348 afc = (packet[3] >> 4) & 3;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1349 if (afc == 0) /* reserved value */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1350 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1351 if (afc == 2) /* adaptation field only */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1352 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1353 if (afc == 3)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1354 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1355 int c;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1356 stream_read(stream, &packet[_read], 1);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1357 c = packet[_read];
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1358 _read++;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1359
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1360 c = min(c, priv->ts.packet_size - _read);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1361 stream_read(stream, &packet[_read], c);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1362 _read += c;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1363
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1364 priv->last_afc = c + 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1365 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AFC: %d\n", priv->last_afc);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1366
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1367 if(_read == priv->ts.packet_size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1368 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1369 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1370 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1371 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1372 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1373 _read += priv->last_afc;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1374 priv->last_afc = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1375 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1376
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1377 // PES CONTENT STARTS HERE
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1378
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1379 buf_size = priv->ts.packet_size - _read;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1380
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1381 //LET'S PARSE TABLES
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1382
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1383 if(pid == 0)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1384 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1385 stream_read(stream,&packet[_read], buf_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1386 parse_pat(priv, is_start, &packet[_read], buf_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1387 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1388 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1389 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1390 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1391 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1392 progid = prog_id_in_pat(priv, pid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1393 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
1394 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1395 stream_read(stream,&packet[_read], buf_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1396 parse_pmt(priv, progid, pid, is_start, &packet[_read], buf_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1397 priv->is_synced = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1398 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1399 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1400 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1401
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1402
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1403
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1404 if(! probe)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1405 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1406 if(((tss->type == VIDEO_MPEG1) || (tss->type == VIDEO_MPEG2) || (tss->type == VIDEO_MPEG4))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1407 && (demuxer->video->id == tss->pid))
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 ds = demuxer->video;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1410
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1411 dp = &priv->fifo[1].pack;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1412 dp_offset = &priv->fifo[1].offset;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1413 buffer_size = &priv->fifo[1].buffer_size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1414 broken = &priv->fifo[1].broken;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1415 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1416 else if(((tss->type == AUDIO_MP2) || (tss->type == AUDIO_A52) || (tss->type == AUDIO_LPCM_BE) || (tss->type == AUDIO_AAC))
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1417 && (demuxer->audio->id == tss->pid))
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 ds = demuxer->audio;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1420
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1421 dp = &priv->fifo[0].pack;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1422 dp_offset = &priv->fifo[0].offset;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1423 buffer_size = &priv->fifo[0].buffer_size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1424 broken = &priv->fifo[0].broken;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1425 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1426 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1427 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1428 stream_skip(stream, buf_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1429 _read += buf_size;
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1433 //IS IT TIME TO QUEUE DATA to the dp_packet?
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1434 if(is_start && (*dp != NULL) && (*dp_offset > 0))
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 priv->last_pid = pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1437 priv->is_synced = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1438 priv->is_start = is_start;
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(! *broken)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1441 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1442 int ret = *dp_offset;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1443 resize_demux_packet(*dp, ret); //shrinked to the right size
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1444
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1445 ds_add_packet(ds, *dp);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1446 mp_msg(MSGT_DEMUX, MSGL_V, "ADDED %d bytes to %s fifo, PTS=%f\n", ret, (ds == demuxer->audio ? "audio" : "video"), (*dp)->pts);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1447
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1448
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1449 *dp = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1450 *dp_offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1451
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1452 return -ret;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1453 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1454 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1455 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1456 mp_msg(MSGT_DEMUX, MSGL_V, "BROKEN PES, DISCARDING\n");
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1457 free_demux_packet(*dp);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1458
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1459 *dp = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1460 *dp_offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1461
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1462 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1463 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1464 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1465
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1466 priv->last_pid = pid;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1467
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1468 if(*dp == NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1469 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1470 *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
1471 *dp_offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1472 if(! *dp)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1473 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1474 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
1475 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1476 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1477 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
1478 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1479
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1480 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
1481 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1482
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1483 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1484
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1485
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1486 if(is_start)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1487 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1488 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
1489
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1490 //priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1491
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1492 p = &packet[_read];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1493 stream_read(stream, p, buf_size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1494 _read += buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1495
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1496 pid_idx = es_pid_in_pmt(priv->pmt, pid);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1497 if(pid_idx == -1)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1498 pid_type = UNKNOWN;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1499 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1500 pid_type = priv->pmt->es[pid_idx].type;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1501
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1502
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1503 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
1504
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1505 if(len)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1506 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1507 if(es->type == UNKNOWN)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1508 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1509
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1510 es->pid = tss->pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1511 tss->type = es->type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1512
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1513 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
1514 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
1515
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1516 if(es->pts == 0.0f)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1517 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
1518 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1519 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
1520
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1521 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse, NEW pid=%d, PSIZE: %u, type=%X, start=%X, len=%d\n",
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1522 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
1523
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1524 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
1525
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1526 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse, NOW tss->PSIZE=%u\n", tss->payload_size);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1527
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1528 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
1529
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1530 if(probe)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1531 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1532 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1533 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1534 *broken = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1535 if(*dp_offset + es->size > *buffer_size)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1536 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1537 *buffer_size = *dp_offset + es->size + TS_FEC_PACKET_SIZE;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1538 resize_demux_packet(*dp, *buffer_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1539 //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
1540 mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1541 }
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1542 memcpy(&((*dp)->buffer[*dp_offset]), es->start, es->size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1543 *dp_offset += es->size;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1544 (*dp)->flags = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1545 (*dp)->pts = es->pts;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1546 (*dp)->pos = stream_tell(demuxer->stream);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1547 *broken = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1548 mp_msg(MSGT_DEMUX, MSGL_DBG2, "INIT PACKET, TYPE=%x, PTS: %f\n", es->type, es->pts);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1549
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1550 continue;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1551 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1552 }
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1553 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1554 return 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1555 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
1556 else
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
1557 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1558 uint16_t sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1559
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1560 if(tss->type == UNKNOWN)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1561 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1562 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
1563 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1564 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1565
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1566
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1567 es->pid = tss->pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1568 es->type = tss->type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1569 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
1570 es->start = &packet[_read];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1571
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1572
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1573 if(tss->payload_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1574 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1575 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
1576 tss->payload_size -= sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1577 es->size = sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1578 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1579 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1580 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1581 if((es->type == VIDEO_MPEG1) || (es->type == VIDEO_MPEG2) || (es->type == VIDEO_MPEG4))
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1582 sz = es->size = buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1583 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1584 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1585 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
1586 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1587 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1588 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1589
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1590
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1591 if(! probe)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1592 {
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1593 if(*dp_offset + sz > *buffer_size)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1594 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1595 *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
1596 resize_demux_packet(*dp, *buffer_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1597 //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
1598 mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1599 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1600
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1601
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1602 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
1603 *dp_offset += sz;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1604
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1605 if(buf_size - sz)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1606 stream_skip(stream, buf_size - sz);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1607
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1608 continue;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1609 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1610 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1611 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1612 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
1613 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
1614
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1615 _read += buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1616
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1617 if(es->size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1618 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1619 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1620 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1621 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
1622 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1623 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1624
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1625 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1626 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1627
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1628
10686
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1629 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
1630 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
1631
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1632 static void reset_fifos(ts_priv_t* priv, int a, int v)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1633 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1634 if(a)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1635 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1636 priv->fifo[0].pack = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1637 priv->fifo[0].offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1638 priv->fifo[0].buffer_size = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1639 priv->fifo[0].broken = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1640 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1641 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1642
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1643 if(v)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1644 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1645 priv->fifo[1].pack = NULL;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1646 priv->fifo[1].offset = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1647 priv->fifo[1].buffer_size = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1648 priv->fifo[1].broken = 1;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1649 priv->is_synced = 0;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1650 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1651 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1652
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1653 void demux_seek_ts(demuxer_t *demuxer,float rel_seek_secs,int flags)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1654 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1655 demux_stream_t *d_audio=demuxer->audio;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1656 demux_stream_t *d_video=demuxer->video;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1657 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
1658 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
1659 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
1660 int i, video_stats;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1661
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1662 //================= seek in MPEG ==========================
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1663 off_t newpos = (flags&1)?demuxer->movi_start:demuxer->filepos;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1664
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1665 ts_dump_streams(demuxer->priv);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1666 reset_fifos(priv, sh_audio != NULL, sh_video != NULL);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1667
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1668
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1669 video_stats = (sh_video != NULL);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1670 if(video_stats)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1671 video_stats = sh_video->i_bps;
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 if(flags & 2) // float seek 0..1
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1674 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
1675 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1676 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1677 // time seek (secs)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1678
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1679 if(! video_stats) // unspecified or VBR
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1680 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
1681 else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1682 newpos += video_stats*rel_seek_secs;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1683 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1684
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1685
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1686 if(newpos<demuxer->movi_start)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1687 newpos = demuxer->movi_start = 0; //begininng of stream
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1688
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1689 #ifdef _LARGEFILE_SOURCE
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1690 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
1691 #else
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1692 newpos &= ~(STREAM_BUFFER_SIZE - 1); /* sector boundary */
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1693 #endif
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1694
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1695 reset_fifos(priv, sh_audio != NULL, sh_video != NULL);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1696
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1697 if(sh_audio != NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1698 ds_free_packs(d_audio);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1699 if(sh_video != NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1700 ds_free_packs(d_video);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1701
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1702 stream_seek(demuxer->stream, newpos);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1703
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1704
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1705 if(sh_video != NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1706 ds_fill_buffer(d_video);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1707
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1708 if(sh_audio != NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1709 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1710 ds_fill_buffer(d_audio);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1711 resync_audio_stream(sh_audio);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1712 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1713
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1714 while(sh_video != NULL)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1715 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1716 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
1717 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1718 float a_pts=d_audio->pts;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1719 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1720 if(d_video->pts>a_pts)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1721 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1722 skip_audio_frame(sh_audio); // sync audio
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1723 continue;
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1724 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1725 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1726
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1727
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1728 i = sync_video_packet(d_video);
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1729 if(sh_video->format == VIDEO_MPEG1 || sh_video->format == VIDEO_MPEG2)
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1730 {
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1731 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
1732 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1733 else //MPEG4
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 if(i==0x1B6) break; // found it!
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
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1738 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
1739 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1740 }
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1741
8eb690f0e342 - seek() is always synchronized to keyframes, so the decoders don't
arpi
parents: 10310
diff changeset
1742
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1743 int demux_ts_fill_buffer(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1744 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1745 ES_stream_t es;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1746 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
1747
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
1748 return -ts_parse(demuxer, &es, packet, 0);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1749 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1750
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1751
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
1752