annotate libmpdemux/demux_ts.c @ 10304:0adc47bc98aa

lossless jpeg related docs
author michael
date Tue, 17 Jun 2003 23:43:52 +0000
parents b60e89268837
children 68e714ed669f
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
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
45 #define MAX_PROBE_SIZE 1000000
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
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
50 int ts_fastparse = 0;
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,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
55 VIDEO_MPEG2 = 0x10000002,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
56 AUDIO_MP2 = 0x50,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
57 AUDIO_A52 = 0x2000,
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
58 AUDIO_LPCM_BE = 0x10001
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
59 /*,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
60 SPU_DVD = 0x3000000,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
61 SPU_DVB = 0x3000001,
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
62 */
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
63 } es_stream_type_t;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
64
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
65
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
66 typedef struct {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
67 int size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
68 unsigned char *start;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
69 uint16_t payload_size;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
70 es_stream_type_t type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
71 float pts, last_pts;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
72 int pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
73 int last_cc; // last cc code (-1 if first packet)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
74 } ES_stream_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
75
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
76
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
77 typedef struct MpegTSContext {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
78 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
79 ES_stream_t *pids[NB_PID_MAX];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
80 } MpegTSContext;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
81
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
82
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
83 typedef struct {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
84 MpegTSContext ts;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
85 } ts_priv_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
86
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
87
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
88 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
89
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
90 static uint8_t get_packet_size(const unsigned char *buf, int size)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
91 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
92 int i;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
93
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
94 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
95 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
96
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
97 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
98 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
99 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
100 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
101 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
102 goto try_fec;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
103 }
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
104 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
105 return TS_PACKET_SIZE;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
106
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
107 try_fec:
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
108 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
109 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
110 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
111 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
112 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
113 return TS_FEC_PACKET_SIZE;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
114 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
115
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
116
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
117
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
118 int ts_check_file(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
119 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
120 const int buf_size = (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
121 unsigned char buf[buf_size], done = 0, *ptr;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
122 uint32_t _read, i, count = 0, is_ts;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
123 int cc[NB_PID_MAX], last_cc[NB_PID_MAX], pid, cc_ok, c;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
124 uint8_t size = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
125 off_t pos = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
126
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
127 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for TS...\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
128
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
129 is_ts = 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
130 while(! done)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
131 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
132 i = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
133 c = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
134
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
135 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
136 && (c >= 0)
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
137 && (i < MAX_CHECK_SIZE)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
138 && ! demuxer->stream->eof
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
139 ) i++;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
140
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
141
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
142 if(c != 0x47)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
143 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
144 mp_msg(MSGT_DEMUX, MSGL_V, "NOT A TS FILE1\n");
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
145 is_ts = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
146 done = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
147 continue;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
148 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
149
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
150 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
151 buf[0] = c;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
152 _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
153
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
154 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
155 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
156 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
157 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
158 return 0;
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
159 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
160
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
161 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
162 if(size)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
163 {
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
164 done = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
165 is_ts = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
166 }
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
167
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
168 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
169 {
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
170 done = 1;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
171 is_ts = 0;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
172 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
173 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
174
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
175 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
176 stream_seek(demuxer->stream, pos);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
177
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
178 if(! is_ts)
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
179 return 0;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
180
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
181 //LET'S CHECK continuity counters
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
182 for(count = 0; count < NB_PID_MAX; count++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
183 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
184 cc[count] = last_cc[count] = -1;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
185 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
186
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
187 for(count = 0; count < NUM_CONSECUTIVE_TS_PACKETS; count++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
188 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
189 ptr = &(buf[size * count]);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
190 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
191 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
192 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
193
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
194 if((pid == 8191) || (pid < 16))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
195 continue;
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 cc[pid] = (ptr[3] & 0xf);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
198 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
199 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
200 if(! cc_ok)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
201 return 0;
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 last_cc[pid] = cc[pid];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
204 done++;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
205 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
206
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
207 return size;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
208 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
209
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
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
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
213 static void ts_detect_streams(demuxer_t *demuxer, uint32_t *a, uint32_t *v, int *fapid, int *fvpid)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
214 {
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
215 int video_found = 0, audio_found = 0, i, num_packets = 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
216 off_t pos=0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
217 ES_stream_t es;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
218 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
219 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
220
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
221
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
222 mp_msg(MSGT_DEMUXER, MSGL_INFO, "PROBING UP TO %u\n", MAX_PROBE_SIZE);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
223 while(pos <= MAX_PROBE_SIZE)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
224 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
225 if(ts_parse(demuxer, &es, tmp, 1))
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
226 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
227 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "TYPE: %x, PID: %d\n", es.type, es.pid);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
228
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
229
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
230 if((*fvpid == -1) || (*fvpid == es.pid))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
231 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
232 if(es.type == VIDEO_MPEG2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
233 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
234 *v = VIDEO_MPEG2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
235 *fvpid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
236 video_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
237 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
238 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
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(((*fvpid == -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
241 {
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
242 //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
243 *v = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
244 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
245 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
246
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
247
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
248 if((*fapid == -1) || (*fapid == es.pid))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
249 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
250 if(es.type == AUDIO_MP2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
251 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
252 *a = AUDIO_MP2; //MPEG1L2 audio
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
253 *fapid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
254 audio_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
255 }
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(es.type == AUDIO_A52)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
258 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
259 *a = AUDIO_A52; //A52 audio
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
260 *fapid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
261 audio_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
262 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
263
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
264 if(es.type == AUDIO_LPCM_BE) //LPCM AUDIO
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
265 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
266 *a = AUDIO_LPCM_BE;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
267 *fapid = es.pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
268 audio_found = 1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
269 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
270 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
271
10259
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
272 if(audio_found && (*fapid == es.pid) && (! video_found))
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
273 num_packets++;
b60e89268837 - discard soon non TS files (previously it took too long, as in the case
arpi
parents: 10253
diff changeset
274
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
275 if((*fapid == -2) && video_found)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
276 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
277 *a = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
278 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
279 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
280
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
281 pos = stream_tell(demuxer->stream);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
282 if(video_found && audio_found)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
283 break;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
284 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
285 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
286
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
287 if(video_found)
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
288 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG2(pid=%d)...", *fvpid);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
289 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
290 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
291 //WE DIDN'T MATCH ANY VIDEO STREAM
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
292 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO VIDEO!\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
293 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
294
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
295 if(*a == AUDIO_MP2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
296 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO MP2(pid=%d)\n", *fapid);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
297 else if(*a == AUDIO_A52)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
298 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO A52(pid=%d)\n", *fapid);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
299 else if(*a == AUDIO_LPCM_BE)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
300 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO LPCM(pid=%d)\n", *fapid);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
301 else
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
302 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
303 //WE DIDN'T MATCH ANY AUDIO STREAM, SO WE FORCE THE DEMUXER TO IGNORE AUDIO
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
304 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO AUDIO!\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
305 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
306
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
307 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
308 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
309 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
310 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
311 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
312 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
313 //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
314 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
315 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
316 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
317
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
318
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
319
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
320 demuxer_t *demux_open_ts(demuxer_t * demuxer)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
321 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
322 int i;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
323 uint8_t packet_size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
324 sh_video_t *sh_video;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
325 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
326 uint32_t at = 0, vt = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
327 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
328
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
329 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
330 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
331
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
332
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
333 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
334
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
335 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
336 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
337
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
338 packet_size = ts_check_file(demuxer);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
339 if(!packet_size)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
340 return NULL;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
341
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
342 priv = malloc(sizeof(ts_priv_t));
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
343
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
344 for(i=0; i < 8192; i++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
345 priv->ts.pids[i] = NULL;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
346 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
347
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
348
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
349 demuxer->priv = priv;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
350
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
351 if(demuxer->stream->type != STREAMTYPE_FILE) demuxer->seekable=0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
352 else demuxer->seekable = 1;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
353
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
354
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
355 ts_detect_streams(demuxer, &at, &vt, &demuxer->audio->id, &demuxer->video->id);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
356 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer2, audio: %x(pid %d), video: %x(pid %d)...\n", at, demuxer->audio->id, vt, demuxer->video->id);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
357
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
358
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
359 if(vt)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
360 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
361 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
362 sh_video->ds = demuxer->video;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
363 sh_video->format = vt;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
364 demuxer->video->sh = sh_video;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
365
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
366 mp_msg(MSGT_DEMUXER,MSGL_INFO, "OPENED_SH_VIDEO, VD: %x\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
367 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
368
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
369 if(at)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
370 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
371 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
372 sh_audio->ds = demuxer->audio;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
373 sh_audio->format = at;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
374 demuxer->audio->sh = sh_audio;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
375
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
376 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
377 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
378
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
379
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
380 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer...");
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
381
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
382
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
383 demuxer->movi_start = 0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
384 demuxer->movi_end = demuxer->stream->end_pos;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
385
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
386 stream_seek(demuxer->stream, 0); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
387
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
388 return demuxer;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
389 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
390
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
391
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
392
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
393
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
394
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
395
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
396 void demux_close_ts(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
397 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
398 if(demuxer->priv)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
399 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
400 free(demuxer->priv);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
401 demuxer->priv=NULL;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
402 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
403 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
404
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
405
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
406
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
407
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
408
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
409 static int pes_parse2(unsigned char *buf, uint16_t packet_len, ES_stream_t *es)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
410 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
411 unsigned char *p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
412 uint32_t header_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
413 int64_t pts, escr, dts;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
414 uint32_t stream_id;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
415 uint32_t pkt_len, es_rate;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
416 //NEXT might be needed:
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
417 //uint8_t es_rate_flag, escr_flag, pts_flag;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
418
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
419 //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
420 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
421
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
422 if(packet_len == 0)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
423 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
424 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
425 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
426 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
427
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
428 if(packet_len > 184)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
429 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
430 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
431 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
432 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
433
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
434
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
435 p = buf;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
436 pkt_len = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
437
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
438
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
439 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
440 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
441 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
442 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
443 return 0 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
444 }
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 packet_len -= 6;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
447 if(packet_len==0)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
448 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
449
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
450 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
451
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
452 stream_id = p[3];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
453
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
454
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
455 if (p[7] & 0x80)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
456 { /* pts available */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
457 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
458 pts |= p[10] << 22 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
459 pts |= (p[11] & 0xFE) << 14 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
460 pts |= p[12] << 7 ;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
461 pts |= (p[13] & 0xFE) >> 1 ;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
462
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
463 es->pts = pts / 90000.0f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
464 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
465 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
466 es->pts = 0.0f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
467
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
468 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
469 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
470
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
471 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
472 escr_flag = p[7] & 0x20;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
473 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
474 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
475
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
476
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
477 if(es_rate_flag)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
478 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
479 char *base;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
480 int bytes = 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
481
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
482 if(pts_flag == 2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
483 bytes += 5;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
484 else if(pts_flag == 3)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
485 bytes += 10;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
486
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
487 if(escr_flag)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
488 bytes += 6;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
489
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
490 base = p[8+bytes];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
491 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
492 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
493 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
494 */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
495
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
496 header_len = p[8];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
497
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
498 /* sometimes corruption on header_len causes segfault in memcpy below */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
499 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
500 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
501 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
502 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
503 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
504
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
505 p += header_len + 9;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
506 packet_len -= header_len + 3;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
507
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
508 if(es->payload_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
509 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
510
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
511 if (stream_id == 0xbd)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
512 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
513 /* hack : ac3 track */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
514 int track, spu_id;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
515
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
516 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
517 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
518
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
519 track = p[0] & 0x0F;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
520 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
521
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
522
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
523 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
524 * 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
525 * 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
526 * 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
527 */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
528 if( /* ac3 - raw or syncword */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
529 (p[0] == 0x0B && p[1] == 0x77))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
530 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
531 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 SYNCWORD\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
532 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
533 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
534 es->type = AUDIO_A52;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
535 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
536
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
537 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
538 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
539 /*
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
540 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
541 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
542 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
543 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
544 // DVBSUB
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
545 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
546 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
547 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
548 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
549 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
550
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
551 return es->size;
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
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
554 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
555 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
556 spu_id = (p[0] & 0x1f);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
557 es->start = p+1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
558 es->size = packet_len-1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
559 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
560 es->payload_size -= packet_len;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
561
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
562 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
563 }
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 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
566 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
567 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
568 es->start = p+4;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
569 es->size = packet_len - 4;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
570 es->type = AUDIO_A52;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
571 es->payload_size -= packet_len;
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 return es->size;
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 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
576 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
577 int pcm_offset;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
578
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
579 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
580 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
581 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
582 { /* START */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
583 pcm_offset += 2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
584 break;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
585 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
586 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
587
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
588 es->start = p + pcm_offset;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
589 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
590 es->type = AUDIO_LPCM_BE;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
591 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
592
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
593 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
594 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
595 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
596 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
597 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
598 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
599 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
600 es->type = VIDEO_MPEG2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
601 if(es->payload_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
602 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
603
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
604 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
605 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
606 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
607 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
608 int track;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
609
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
610 track = stream_id & 0x1f;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
611 es->start = p;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
612 es->size = packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
613 es->type = AUDIO_MP2;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
614 es->payload_size -= packet_len;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
615
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
616 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
617 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
618 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
619 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
620 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
621 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
622
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
623 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
624 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
625
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
626
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
627
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
628
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
629 static int ts_sync(stream_t *stream)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
630 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
631 int c=0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
632
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
633 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
634
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
635 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
636
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
637 if(c == 0x47)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
638 return c;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
639 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
640 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
641 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
642
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
643
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
644
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
645
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
646
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
647
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
648 // 0 = EOF or no stream found
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
649 // 1 = successfully read a packet
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
650 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
651 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
652 ES_stream_t *tss;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
653 uint8_t done = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
654 int buf_size, is_start;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
655 int len, pid, last_pid, cc, cc_ok, afc, _read;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
656 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
657 stream_t *stream = demuxer->stream;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
658 char *p, tmp[TS_FEC_PACKET_SIZE];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
659 demux_stream_t *ds;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
660 demux_packet_t *dp;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
661
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
662
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
663 while(! done) //while pid=last_pid add_to_buffer
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
664 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
665 if(! ts_sync(stream))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
666 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
667 mp_msg(MSGT_DEMUX, MSGL_V, "TS_PARSE: COULDN'T SYNC\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
668 return 0;
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
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
671 len = stream_read(stream, &packet[1], 3);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
672 if (len != 3)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
673 return 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
674 _read = 4;
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 is_start = packet[1] & 0x40;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
677 pid = ((packet[1] & 0x1f) << 8) | packet[2];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
678
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
679 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
680 if(tss == NULL)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
681 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
682 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
683 if(! tss)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
684 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
685 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
686 tss->pid = pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
687 tss->last_cc = -1;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
688 tss->type = UNKNOWN;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
689 tss->payload_size = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
690 priv->ts.pids[pid] = tss;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
691 mp_msg(MSGT_DEMUX, MSGL_V, "new TS pid=%u\n", pid);
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
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
694 if((pid < 16) || (pid == 8191)) //invalid pid
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
695 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
696 cc = (packet[3] & 0xf);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
697 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
698 if(! cc_ok)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
699 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
700 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
701 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
702 tss->last_cc = cc;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
703
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
704 /* skip adaptation field */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
705 afc = (packet[3] >> 4) & 3;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
706 if (afc == 0) /* reserved value */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
707 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
708 if (afc == 2) /* adaptation field only */
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
709 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
710 if (afc == 3)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
711 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
712 int c;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
713 stream_read(stream, &packet[_read], 1);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
714 c = packet[_read];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
715 _read++;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
716
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
717 c = min(c, priv->ts.packet_size - _read);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
718 stream_read(stream, &packet[_read], c);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
719 _read += c;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
720
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
721 if(_read == priv->ts.packet_size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
722 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
723 }
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 // PES CONTENT STARTS HERE
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
726
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
727 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
728
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
729 if(! probe)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
730 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
731 if((tss->type == VIDEO_MPEG2) && (demuxer->video->id == tss->pid))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
732 ds = demuxer->video;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
733 else if(((tss->type == AUDIO_MP2) || (tss->type == AUDIO_A52) || (tss->type == AUDIO_LPCM_BE))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
734 && (demuxer->audio->id == tss->pid))
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
735 ds = demuxer->audio;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
736 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
737 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
738 stream_read(stream, tmp, buf_size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
739 _read += buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
740 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
741 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
742 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
743
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
744
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
745 if(is_start)
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 p = &packet[_read];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
748 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
749 _read += buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
750
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
751 len = pes_parse2(p, buf_size, es);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
752
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
753 if(len)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
754 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
755 if(es->type == UNKNOWN)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
756 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
757
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
758 es->pid = tss->pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
759 tss->type = es->type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
760
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
761 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
762 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
763
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
764 if(es->pts == 0.0f)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
765 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
766 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
767 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
768
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
769 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
770 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
771
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
772 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
773
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
774 mp_msg(MSGT_DEMUX, MSGL_V, "ts_parse, NOW tss->PSIZE=%u\n", tss->payload_size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
775
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
776
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
777 if(probe)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
778 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
779 else
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 dp = new_demux_packet(es->size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
782 if(! dp || ! dp->buffer)
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 fprintf(stderr, "fill_buffer, NEW_ADD_PACKET(%d)FAILED\n", es->size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
785 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
786 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
787
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
788 memcpy(dp->buffer, es->start, es->size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
789 dp->flags = 0;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
790 dp->pts = es->pts;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
791 dp->pos = stream_tell(demuxer->stream);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
792 ds_add_packet(ds, dp);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
793
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
794 return -es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
795 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
796 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
797 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
798 else
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
799 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
800 uint16_t sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
801
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
802 if(tss->type == UNKNOWN)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
803 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
804 stream_read(stream, tmp, buf_size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
805 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
806 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
807
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
808 es->pid = tss->pid;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
809 es->type = tss->type;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
810 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
811 es->start = &packet[_read];
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
812
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
813
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
814 if(tss->payload_size)
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 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
817 tss->payload_size -= sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
818 es->size = sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
819 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
820 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
821 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
822 if(es->type == VIDEO_MPEG2)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
823 sz = es->size = buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
824 else
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 stream_read(stream, tmp, buf_size);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
827 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
828 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
829 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
830
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
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
833 if(! probe)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
834 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
835 ds_read_packet(ds, stream, sz, tss->last_pts, stream_tell(stream), 0);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
836 if(buf_size - sz)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
837 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
838
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
839 mp_msg(MSGT_DEMUX, MSGL_V, "DOPO DS_READ_PACKET pid %d, size %d DS=%p\n", tss->pid, sz, ds);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
840 return -sz;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
841
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
842 }
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
843 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
844 {
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
845 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
846 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
847
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
848 _read += buf_size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
849
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
850 if(es->size)
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
851 return es->size;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
852 else
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
853 continue;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
854 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
855 }
10253
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
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
858 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
859 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
860
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
861
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
862 int demux_ts_fill_buffer(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
863 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
864 ES_stream_t es;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
865 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
866
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
867 return -ts_parse(demuxer, &es, packet, 0);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
868 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
869
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
870
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
871
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
872
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
873 int demux_seek_ts(demuxer_t * demuxer, float rel_seek_secs, int flags)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
874 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
875 int total_bitrate=0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
876 off_t dest_offset;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
877 ts_priv_t * priv = demuxer->priv;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
878 int a_bps, v_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
879 demux_stream_t *d_audio=demuxer->audio;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
880 demux_stream_t *d_video=demuxer->video;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
881 sh_audio_t *sh_audio=d_audio->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
882 sh_video_t *sh_video=d_video->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
883
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
884
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
885 /*
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
886 * Compute absolute offset inside the stream. Approximate total bitrate with sum of bitrates
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
887 * reported by the audio and video codecs. The seek is not accurate because, just like
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
888 * with MPEG streams, the bitrate is not constant. Moreover, we do not take into account
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
889 * the overhead caused by PVA and PES headers.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
890 * If the calculated absolute offset is negative, seek to the beginning of the file.
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
891
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
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
894
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
895 if(demuxer->audio->id != -2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
896 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
897 a_bps = ((sh_audio_t *)demuxer->audio->sh)->i_bps;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
898 total_bitrate += a_bps;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
899 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
900
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
901 if(demuxer->video->id != -2)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
902 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
903 v_bps = ((sh_video_t *)demuxer->video->sh)->i_bps;
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
904 total_bitrate += v_bps;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
905 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
906
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
907 if(! total_bitrate)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
908 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
909 mp_msg(MSGT_DEMUX, MSGL_V, "SEEK_TS, couldn't determine bitrate, no seek\n");
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
910 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
911 }
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
912
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
913 dest_offset = stream_tell(demuxer->stream) + rel_seek_secs*total_bitrate;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
914 if(dest_offset < 0) dest_offset = 0;
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
915
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
916 mp_msg(MSGT_DEMUX, MSGL_V, "SEEK TO: %f, BITRATE: %lu, FINAL_POS: %u \n", rel_seek_secs, total_bitrate, dest_offset);
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
917
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
918 stream_seek(demuxer->stream, dest_offset);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
919
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
920 ds_fill_buffer(d_video);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
921 if(sh_audio)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
922 {
10253
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
923 ds_fill_buffer(d_audio);
978b12dcb9ef - open new_ds_[audio | video] only when the relative streams are really available
arpi
parents: 10242
diff changeset
924 resync_audio_stream(sh_audio);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
925 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
926
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
927 return 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
928 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
929
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
930