annotate libmpdemux/demux_ts.c @ 10143:fd3cbeb388f0

removed broken swscaler support, added runtime fullscreens switching ability, and some other general cleanup thingies
author alex
date Tue, 20 May 2003 19:30:46 +0000
parents 01a9af06319a
children 4e34d468f549
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 *
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
4 * For the purposes of playing video, we make some assumptions about the
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
5 * kinds of TS we have to process. The most important simplification is to
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
6 * assume that the TS contains a single program (SPTS) because this then
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
7 * allows significant simplifications to be made in processing PATs.
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
8 *
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
9 * WARNING: Quite a hack was required in order to get files by MultiDec played back correctly.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
10 * If it breaks anything else, just comment out the "#define DEMUX_PVA_MULTIDEC_HACK" below
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
11 * and it will not be compiled in.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
12 *
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
13 * Feedback is appreciated.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
14 *
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
15 * written by Matteo Giani
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
16 * based on FFmpeg (libavformat) sources
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
17 *
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
18 *
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
19 * This file is free software; you can redistribute it and/or
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
20 * modify it under the terms of the GNU Lesser General Public
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
21 * License as published by the Free Software Foundation; either
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
22 * version 2 of the License, or (at your option) any later version.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
23 *
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
24 * This file is distributed in the hope that it will be useful,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
27 * Lesser General Public License for more details.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
28 *
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
29 * You should have received a copy of the GNU Lesser General Public
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
30 * License along with this library; if not, write to the Free Software
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
32 */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
33
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
34
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
35 #include <stdio.h>
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
36 #include <stdlib.h>
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
37 #include <string.h>
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
38
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
39 #include "config.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
40 #include "mp_msg.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
41 #include "help_mp.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
42
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
43 #include "stream.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
44 #include "demuxer.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
45 #include "stheader.h"
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
46
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
47 #include "bswap.h"
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
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
51 #define TS_FEC_PACKET_SIZE 204
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
52 #define TS_PACKET_SIZE 188
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
53 #define NB_PID_MAX 8192
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
54
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
55 #define MAX_HEADER_SIZE 6 /* enough for PES header + length */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
56 #define MAX_PROBE_SIZE 1000000
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
57 #define NUM_CONSECUTIVE_TS_PACKETS 32
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
58
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
59
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
60 int ts_fastparse = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
61
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
62 typedef enum
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
63 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
64 UNKNOWN = -1,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
65 VIDEO_MPEG2 = 0x10000002,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
66 AUDIO_MP2 = 0x50,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
67 AUDIO_A52 = 0x2000,
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
68 AUDIO_LPCM_BE = 0x10001
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
69 /*,
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
70 SPU_DVD = 0x3000000,
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
71 SPU_DVB = 0x3000001,
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
72 */
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
73 } es_stream_type_t;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
74
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
75
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
76 typedef struct {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
77 int size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
78 unsigned char *start;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
79 uint16_t payload_size;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
80 es_stream_type_t type;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
81 float pts, last_pts;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
82 int pid;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
83 int last_cc; // last cc code (-1 if first packet)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
84 } ES_stream_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
85
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
86
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
87 typedef struct MpegTSContext {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
88 int packet_size; // raw packet size, including FEC if present e.g. 188 bytes
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
89 ES_stream_t *pids[NB_PID_MAX];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
90 } MpegTSContext;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
91
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
92
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
93 typedef struct {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
94 MpegTSContext ts;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
95 } ts_priv_t;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
96
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
97
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
98
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
99 static uint8_t get_packet_size(const unsigned char *buf, int size)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
100 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
101 int i;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
102
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
103 if (size < (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
104 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
105
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
106 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
107 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
108 if (buf[i * TS_PACKET_SIZE] != 0x47)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
109 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
110 mp_msg(MSGT_DEMUX, MSGL_DBG2, "GET_PACKET_SIZE, pos %d, char: %2x\n", i, buf[i * TS_PACKET_SIZE]);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
111 goto try_fec;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
112 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
113 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
114 return TS_PACKET_SIZE;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
115
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
116 try_fec:
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
117 for(i=0; i<NUM_CONSECUTIVE_TS_PACKETS; i++)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
118 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
119 if (buf[i * TS_FEC_PACKET_SIZE] != 0x47)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
120 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
121 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
122 return TS_FEC_PACKET_SIZE;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
123 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
124
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
125
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
126
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
127 int ts_check_file(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
128 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
129 const int buf_size = (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS);
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
130 unsigned char buf[buf_size], c, done = 0, *ptr;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
131 uint32_t _read, i=1, count = 0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
132 int cc[NB_PID_MAX], last_cc[NB_PID_MAX], pid, cc_ok;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
133 uint8_t size = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
134 off_t pos = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
135
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
136 mp_msg(MSGT_DEMUX, MSGL_V, "************Checking for TS************\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
137
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
138 while(! done)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
139 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
140 while(((c=stream_read_char(demuxer->stream)) != 0x47)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
141 && (i < MAX_PROBE_SIZE)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
142 && ! demuxer->stream->eof
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
143 ) i++;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
144
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
145 if(c != 0x47)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
146 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
147 mp_msg(MSGT_DEMUX, MSGL_V, "NOT A TS FILE1\n");
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
148 done = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
149 continue;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
150 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
151
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
152 pos = stream_tell(demuxer->stream) - 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
153 buf[0] = c;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
154 _read = stream_read(demuxer->stream, &buf[1], buf_size-1);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
155
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
156 if(_read < buf_size-1)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
157 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
158 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
159 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
160 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
161 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
162
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
163 size = get_packet_size(buf, buf_size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
164 if(size)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
165 done = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
166 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
167
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
168 mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FOUND %x, packet_size= %d\n", i, c, size);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
169 stream_seek(demuxer->stream, pos);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
170
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
171 //return size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
172
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
173 for(count = 0; count < NB_PID_MAX; count++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
174 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
175 cc[count] = last_cc[count] = -1;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
176 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
177
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
178 done = 0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
179 for(count = 0; count < NUM_CONSECUTIVE_TS_PACKETS; count++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
180 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
181 ptr = &(buf[size * count]);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
182 pid = ((ptr[1] & 0x1f) << 8) | ptr[2];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
183 mp_msg(MSGT_DEMUX, MSGL_V, "BUF: %02x %02x %02x %02x, PID %d, SIZE: %d \n",
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
184 ptr[0], ptr[1], ptr[2], ptr[3], pid, size);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
185
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
186 if(pid == 8191)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
187 continue;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
188
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
189 cc[pid] = (ptr[3] & 0xf);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
190 cc_ok = (last_cc[pid] < 0) || ((((last_cc[pid] + 1) & 0x0f) == cc[pid]));
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
191 mp_msg(MSGT_DEMUX, MSGL_V, "PID %d, COMPARE CC %d AND LAST_CC %d\n", pid, cc[pid], last_cc[pid]);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
192 if(! cc_ok)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
193 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
194
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
195 last_cc[pid] = cc[pid];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
196 done++;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
197 }
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
198
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
199 return size;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
200 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
201
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
202
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
203 void ts_detect_streams(demuxer_t *demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
204 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
205 int video_found = 0, audio_found = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
206 off_t pos=0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
207 ES_stream_t es;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
208 int *apid, *vpid, *spid, fapid, fvpid, fspid;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
209 unsigned char tmp[TS_FEC_PACKET_SIZE];
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
210 sh_video_t *sh_video = demuxer->video->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
211 sh_audio_t *sh_audio = demuxer->audio->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
212
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
213 apid = &(demuxer->audio->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
214 vpid = &(demuxer->video->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
215 spid = &(demuxer->sub->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
216
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
217
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
218 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
219 while(pos <= MAX_PROBE_SIZE)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
220 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
221 if(ts_parse(demuxer, &es, tmp))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
222 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
223 mp_msg(MSGT_DEMUXER, MSGL_V, "TYPE: %x, PID: %d\n", es.type, es.pid);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
224 if(es.type == VIDEO_MPEG2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
225 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
226 sh_video->format = VIDEO_MPEG2; //MPEG2 video
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
227 if(*vpid == -1)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
228 *vpid = fvpid = es.pid;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
229 video_found = 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
230 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
231
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
232 if(es.type == AUDIO_MP2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
233 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
234 sh_audio->format = AUDIO_MP2; //MPEG1L2 audio
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
235 if(*apid == -1)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
236 *apid = fapid = es.pid;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
237 audio_found = 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
238 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
239
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
240 if(es.type == AUDIO_A52)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
241 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
242 sh_audio->format = AUDIO_A52; //A52 audio
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
243 if(*apid == -1)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
244 *apid = fapid = es.pid;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
245 audio_found = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
246 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
247
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
248 if(es.type == AUDIO_LPCM_BE) //LPCM AUDIO
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
249 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
250 sh_audio->format = AUDIO_LPCM_BE;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
251 if(*apid == -1)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
252 *apid = fapid = es.pid;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
253 audio_found = 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
254 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
255
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
256 pos = stream_tell(demuxer->stream);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
257 if(video_found && audio_found)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
258 break;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
259 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
260 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
261
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
262 if(video_found)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
263 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG2(pid=%d)...", fvpid);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
264 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
265 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
266 *vpid = -2; //WE DIDN'T MATCH ANY VIDEO STREAM, SO WE FORCE THE DEMUXER TO IGNORE VIDEO
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
267 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO VIDEO!\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
268 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
269
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
270 if(sh_audio->format == AUDIO_MP2)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
271 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO MP2(pid=%d)\n", fapid);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
272 else if(sh_audio->format == AUDIO_A52)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
273 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO A52(pid=%d)\n", fapid);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
274 else if(sh_audio->format == AUDIO_LPCM_BE)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
275 mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO LPCM(pid=%d)\n", fapid);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
276 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
277 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
278 *apid = -2; //WE DIDN'T MATCH ANY AUDIO STREAM, SO WE FORCE THE DEMUXER TO IGNORE AUDIO
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
279 mp_msg(MSGT_DEMUXER, MSGL_INFO, "NO AUDIO!\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
280 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
281 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
282
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
283
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
284
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
285 demuxer_t *demux_open_ts(demuxer_t * demuxer)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
286 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
287 int i;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
288 uint8_t packet_size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
289 sh_video_t *sh_video;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
290 sh_audio_t *sh_audio;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
291 ts_priv_t * priv = (ts_priv_t*) demuxer->priv;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
292
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
293
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
294 mp_msg(MSGT_DEMUX, MSGL_V, "DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
295 demuxer->audio->id, demuxer->video->id, demuxer->sub->id);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
296
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
297
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
298 demuxer->type= DEMUXER_TYPE_MPEG_TS;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
299
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
300 stream_reset(demuxer->stream);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
301 stream_seek(demuxer->stream, 0);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
302
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
303 packet_size = ts_check_file(demuxer);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
304 if(!packet_size)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
305 return NULL;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
306
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
307 priv = malloc(sizeof(ts_priv_t));
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
308
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
309 for(i=0; i < 8192; i++)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
310 priv->ts.pids[i] = NULL;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
311 priv->ts.packet_size = packet_size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
312
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
313
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
314 demuxer->priv = priv;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
315
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
316 if(demuxer->stream->type != STREAMTYPE_FILE) demuxer->seekable=0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
317 else demuxer->seekable = 1;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
318
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 sh_video = new_sh_video(demuxer, 0);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
321 sh_video->ds = demuxer->video;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
322 demuxer->video->sh = sh_video;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
323
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
324 sh_audio = new_sh_audio(demuxer, 0);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
325 sh_audio->ds = demuxer->audio;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
326 demuxer->audio->sh = sh_audio;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
327
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
328
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
329 mp_msg(MSGT_DEMUXER,MSGL_INFO, "Opened TS demuxer...");
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
330
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
331 if(! ts_fastparse)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
332 ts_detect_streams(demuxer);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
333
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
334
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
335 /*
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
336 demuxer->movi_start = 0;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
337 demuxer->movi_end = demuxer->stream->end_pos;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
338 */
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
339
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
340
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
341 stream_seek(demuxer->stream, 0); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
342 return demuxer;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
343 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
344
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
345
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
346
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
347
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
348
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
349
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
350 void demux_close_ts(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
351 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
352 if(demuxer->priv)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
353 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
354 free(demuxer->priv);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
355 demuxer->priv=NULL;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
356 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
357 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
358
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
359
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
360
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
361
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
362 static int pes_parse2(unsigned char *buf, uint16_t packet_len, int is_start, ES_stream_t *es)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
363 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
364 unsigned char *p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
365 uint32_t header_len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
366 int64_t pts;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
367 uint32_t stream_id;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
368 uint32_t pkt_len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
369
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
370 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2(%X, %d, %d, ): \n", buf, packet_len, is_start);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
371
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
372 if(packet_len == 0)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
373 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
374 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2(,PACKET_LEN = 0, EXIT\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
375 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
376 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
377
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
378 if(packet_len > 184)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
379 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
380 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2, BUFFER LEN IS TOO BIG: %d, EXIT\n", packet_len);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
381 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
382 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
383
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
384
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
385 p = buf;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
386 pkt_len = packet_len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
387
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
388 if(! is_start)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
389 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
390 es->pts = 0.0f;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
391 es->start = p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
392 es->size = packet_len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
393 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
394 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
395
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
396 /* we should have a PES packet here */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
397
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
398 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: HEADER %02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
399 if (p[0] || p[1] || (p[2] != 1))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
400 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
401 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: error HEADER %02x %02x %02x (should be 0x000001) \n", p[0], p[1], p[2]);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
402 return 0 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
403 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
404
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
405 packet_len -= 6;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
406
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
407 es->payload_size = p[4] << 8 | p[5];
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
408 if (es->payload_size == 0)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
409 es->payload_size = 65535;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
410
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
411 stream_id = p[3];
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
412
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
413 if(packet_len==0)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
414 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
415
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
416
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
417 if (p[7] & 0x80)
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
418 { /* pts available */
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
419 pts = (int64_t)(p[9] & 0x0E) << 29 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
420 pts |= p[10] << 22 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
421 pts |= (p[11] & 0xFE) << 14 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
422 pts |= p[12] << 7 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
423 pts |= (p[13] & 0xFE) >> 1 ;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
424
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
425 es->pts = pts / 90000.0f;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
426 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
427 else
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
428 es->pts = 0.0f;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
429
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
430 header_len = p[8];
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
431
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
432 /* sometimes corruption on header_len causes segfault in memcpy below */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
433 if (header_len + 9 > pkt_len)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
434 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
435 mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_ts: illegal value for PES_header_data_length (0x%02x)\n", header_len);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
436 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
437 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
438
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
439 p += header_len + 9;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
440 packet_len -= header_len + 3;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
441
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
442 if (stream_id == 0xbd)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
443 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
444 /* hack : ac3 track */
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
445 int track, spu_id;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
446
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
447 mp_msg(MSGT_DEMUX, MSGL_V, "pes_parse2: audio buf = %02X %02X %02X %02X %02X %02X %02X %02X, 80: %d\n",
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
448 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[0] & 0x80);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
449
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
450 track = p[0] & 0x0F;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
451 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 TRACK: %d\n", track);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
452
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
453
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
454 /*
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
455 * we check the descriptor tag first because some stations
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
456 * do not include any of the ac3 header info in their audio tracks
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
457 * these "raw" streams may begin with a byte that looks like a stream type.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
458 */
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
459 if( /* ac3 - raw or syncword */
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
460 (p[0] == 0x0B && p[1] == 0x77))
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
461 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
462 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 SYNCWORD\n");
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
463 es->start = p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
464 es->size = packet_len;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
465 es->type = AUDIO_A52;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
466 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
467 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
468 /*
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
469 else if (//m->descriptor_tag == 0x06 &&
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
470 p[0] == 0x20 && p[1] == 0x00)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
471 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
472 // DVBSUB
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
473 long payload_len = ((buf[4] << 8) | buf[5]) - header_len - 3;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
474 es->start = p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
475 es->size = packet_len;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
476 es->type = SPU_DVB + payload_len;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
477 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
478 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
479
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
480 else if ((p[0] & 0xE0) == 0x20)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
481 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
482 spu_id = (p[0] & 0x1f);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
483 es->start = p+1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
484 es->size = packet_len-1;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
485 es->type = SPU_DVD + spu_id;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
486 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
487 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
488 */
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
489 else if ((p[0] & 0xF0) == 0x80)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
490 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
491 mp_msg(MSGT_DEMUX, MSGL_DBG2, "AC3 WITH HEADER\n");
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
492 es->start = p+4;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
493 es->size = packet_len - 4;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
494 es->type = AUDIO_A52;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
495 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
496 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
497 else if ((p[0]&0xf0) == 0xa0)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
498 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
499 int pcm_offset;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
500
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
501 for (pcm_offset=0; ++pcm_offset < packet_len-1 ; )
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
502 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
503 if (p[pcm_offset] == 0x01 && p[pcm_offset+1] == 0x80)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
504 { /* START */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
505 pcm_offset += 2;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
506 break;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
507 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
508 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
509
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
510 es->start = p + pcm_offset;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
511 es->size = packet_len - pcm_offset;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
512 es->type = AUDIO_LPCM_BE;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
513 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
514 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
515 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
516 else if ((stream_id >= 0xbc) && ((stream_id & 0xf0) == 0xe0))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
517 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
518 es->start = p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
519 es->size = packet_len;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
520 es->type = VIDEO_MPEG2;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
521 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
522 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
523 else if ((stream_id & 0xe0) == 0xc0)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
524 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
525 int track;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
526 track = stream_id & 0x1f;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
527 es->start = p;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
528 es->size = packet_len;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
529 es->type = AUDIO_MP2;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
530 return es->size;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
531 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
532 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
533 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
534 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: unknown packet, id: %x\n", stream_id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
535 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
536
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
537 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
538 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
539
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
540
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
541
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
542
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
543 int ts_sync(demuxer_t *demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
544 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
545 uint8_t c=0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
546
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
547 mp_msg(MSGT_DEMUX, MSGL_DBG2, "TS_SYNC \n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
548
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
549 while(((c=stream_read_char(demuxer->stream)) != 0x47) && ! demuxer->stream->eof);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
550
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
551 if(c == 0x47)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
552 return c;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
553 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
554 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
555 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
556
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
557
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
558
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
559
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
560
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
561
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
562 // 0 = EOF or no stream found
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
563 // 1 = successfully read a packet
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
564 int ts_parse(demuxer_t * demuxer , ES_stream_t *es, unsigned char *packet)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
565 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
566 ES_stream_t *tss;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
567 uint8_t done = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
568 uint16_t buf_size, is_start;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
569 int len, pid, cc, cc_ok, afc;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
570 unsigned char *p;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
571 ts_priv_t * priv = (ts_priv_t*) demuxer->priv;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
572
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
573
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
574 while(! done)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
575 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
576 if(! ts_sync(demuxer))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
577 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
578 mp_msg(MSGT_DEMUX, MSGL_V, "TS_FILL_BUFFER: COULDN'T SYNC\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
579 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
580 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
581
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
582 len = stream_read(demuxer->stream, &packet[1], priv->ts.packet_size-1);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
583 if (len != priv->ts.packet_size-1)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
584 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
585
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
586 pid = ((packet[1] & 0x1f) << 8) | packet[2];
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
587 tss = priv->ts.pids[pid]; //an ES stream
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
588 if(tss == NULL)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
589 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
590 tss = malloc(sizeof(ES_stream_t));
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
591 if(! tss)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
592 continue;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
593 memset(tss, 0, sizeof(ES_stream_t));
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
594 tss->pid = pid;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
595 tss->last_cc = -1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
596 tss->type = UNKNOWN;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
597 priv->ts.pids[pid] = tss;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
598 mp_msg(MSGT_DEMUX, MSGL_DBG2, "new TS pid=%u\n", pid);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
599 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
600
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
601 cc = (packet[3] & 0xf);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
602 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
603 if(! cc_ok)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
604 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
605 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse: CCCheck NOT OK: %d -> %d\n", tss->last_cc, cc);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
606 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
607 tss->last_cc = cc;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
608
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
609
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
611 /* skip adaptation field */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
612 afc = (packet[3] >> 4) & 3;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
613 p = packet + 4;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
614 if (afc == 0) /* reserved value */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
615 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
616 if (afc == 2) /* adaptation field only */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
617 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
618 if (afc == 3)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
619 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
620 /* skip adapation field */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
621 p += p[0] + 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
622 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
623 /* if past the end of packet, ignore */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
624 if (p >= packet + TS_PACKET_SIZE)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
625 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
626
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
627 // PES CONTENT STARTS HERE
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
628
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
629 buf_size = TS_PACKET_SIZE - (p - packet);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
630
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
631 is_start = packet[1] & 0x40;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
632 len = pes_parse2(p, buf_size, is_start, es);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
633
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
634 if(len)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
635 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
636 es->pid = tss->pid;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
637
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
638 if(! is_start)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
639 es->type = tss->type;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
640 else
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
641 {
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
642 tss->type = es->type;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
643 tss->payload_size = es->payload_size;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
644 }
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
645
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
646 if(es->pts == 0.0f)
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
647 es->pts = tss->pts = tss->last_pts;
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
648 else
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
649 tss->pts = tss->last_pts = es->pts;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
650
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
651 mp_msg(MSGT_DEMUX, MSGL_V, "ts_parse, pid=%d, PSIZE: %u, type=%X, start=%X, len=%d\n", es->pid, es->payload_size, es->type, es->start, es->size);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
652
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
653 return len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
654 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
655 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
656
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
657 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
658 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
659
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
660
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
661
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
662 int demux_ts_fill_buffer(demuxer_t * demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
663 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
664 ES_stream_t es;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
665 demux_packet_t *dp;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
666 int len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
667 unsigned char packet[TS_FEC_PACKET_SIZE];
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
668 int *apid, *vpid, *spid;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
669
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
670 apid = &(demuxer->audio->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
671 vpid = &(demuxer->video->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
672 spid = &(demuxer->sub->id);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
673
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
674 while((len = ts_parse(demuxer, &es, packet)) > 0)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
675 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
676 mp_msg(MSGT_DEMUX, MSGL_V, "NEW_FILL_BUFFER, NEW_ADD_PACKET(%x, %d) type: %x, PTS: %f\n", es.start, es.size, es.type, es.pts);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
677
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
678 if(es.type == VIDEO_MPEG2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
679 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
680 if(ts_fastparse)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
681 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
682 if(*vpid == -2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
683 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
684
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
685 if(*vpid == -1)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
686 *vpid = es.pid;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
687 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
688
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
689 if(*vpid != es.pid)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
690 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
691
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
692 dp = new_demux_packet(es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
693 if(! dp || ! dp->buffer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
694 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
695 fprintf(stderr, "fill_buffer, NEW_ADD_PACKET(%d) FAILED\n", es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
696 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
697 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
698 memcpy(dp->buffer, es.start, es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
699 dp->pts = es.pts;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
700 dp->flags = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
701 dp->pos = stream_tell(demuxer->stream);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
702 ds_add_packet(demuxer->video, dp);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
703 mp_msg(MSGT_DEMUX, MSGL_V, "VIDEO pts=%f\n", es.pts);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
704 return len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
705 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
706
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
707 if((es.type == AUDIO_MP2) || (es.type == AUDIO_A52) || (es.type == AUDIO_LPCM_BE))
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
708 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
709 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_AUDIO %x \n", es.type);
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
710
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
711 if(ts_fastparse)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
712 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
713 if(*apid == -2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
714 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
715
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
716 if(*apid == -1)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
717 *apid = es.pid;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
718 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
719
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
720 if(*apid != es.pid)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
721 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
722
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
723 dp = new_demux_packet(es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
724 if(! dp || ! dp->buffer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
725 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
726 fprintf(stderr, "fill_buffer, NEW_ADD_PACKET(%d) FAILED\n", es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
727 continue;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
728 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
729 memcpy(dp->buffer, es.start, es.size);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
730 dp->flags = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
731 dp->pts = es.pts;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
732 dp->pos = stream_tell(demuxer->stream);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
733 ds_add_packet(demuxer->audio, dp);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
734 mp_msg(MSGT_DEMUX, MSGL_V, "AUDIO pts=%f\r\n", es.pts);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
735 return len;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
736 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
737
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
738 mp_msg(MSGT_DEMUX, MSGL_V, "SKIP--------\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
739 }
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
740 return 0;
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
741 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
742
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
743
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
744
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
745
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
746 int stringent_ts_sync(demuxer_t *demuxer)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
747 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
748 ts_priv_t *priv = demuxer->priv;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
749 uint8_t c = 0, done = 0, i, buf[TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS];
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
750 off_t pos;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
751
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
752 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STRINGENT_TS_SYNC packet_size: %d\n", priv->ts.packet_size);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
753
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
754
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
755 if(! demuxer->seekable)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
756 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
757
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
758
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
759 while(! done)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
760 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
761 while(((c=stream_read_char(demuxer->stream)) != 0x47) && !demuxer->stream->eof);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
762
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
763 if(c != 0x47)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
764 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
765 stream_reset(demuxer->stream);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
766 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
767 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
768
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
769 pos = stream_tell(demuxer->stream);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
770 if(pos < 1)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
771 pos = 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
772 mp_msg(MSGT_DEMUX, MSGL_DBG2, "dopo il while, pos=%u\n", pos);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
773
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
774 done = 1;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
775 buf[0] = c;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
776 stream_read(demuxer->stream, &buf[1], (priv->ts.packet_size * NUM_CONSECUTIVE_TS_PACKETS) - 1);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
777 for(i = 0; i < 5; i++)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
778 {
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
779 if (buf[i * priv->ts.packet_size] != 0x47)
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
780 done = 0;
10014
01a9af06319a fully reworked by Nico <nsabbi@libero.it>
alex
parents: 9638
diff changeset
781 mp_msg(MSGT_DEMUX, MSGL_DBG2, "i: %d, char: %x\n", i, buf[i * priv->ts.packet_size]);
9610
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
782 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
783
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
784 if(done)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
785 stream_seek(demuxer->stream, pos);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
786 else
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
787 stream_seek(demuxer->stream, pos);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
788 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
789 //stream_seek(demuxer->stream, pos+1);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
790 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STRINGENT_TS_SYNC, STREAM_POS: %lu\n", stream_tell(demuxer->stream));
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
791 return 0x47;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
792 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
793
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
794
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
795 extern void resync_audio_stream(sh_audio_t *);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
796
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
797
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
798 int demux_seek_ts(demuxer_t * demuxer, float rel_seek_secs, int flags)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
799 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
800 int total_bitrate=0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
801 off_t dest_offset;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
802 ts_priv_t * priv = demuxer->priv;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
803 int a_bps, v_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
804 demux_stream_t *d_audio=demuxer->audio;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
805 demux_stream_t *d_video=demuxer->video;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
806 sh_audio_t *sh_audio=d_audio->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
807 sh_video_t *sh_video=d_video->sh;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
808
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
809
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
810 /*
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
811 * Compute absolute offset inside the stream. Approximate total bitrate with sum of bitrates
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
812 * 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
813 * 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
814 * the overhead caused by PVA and PES headers.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
815 * If the calculated absolute offset is negative, seek to the beginning of the file.
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
816 */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
817
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
818
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
819 if(demuxer->audio->id != -2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
820 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
821 a_bps = ((sh_audio_t *)demuxer->audio->sh)->i_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
822 total_bitrate += a_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
823 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
824
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
825 if(demuxer->video->id != -2)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
826 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
827 v_bps = ((sh_video_t *)demuxer->video->sh)->i_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
828 total_bitrate += v_bps;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
829 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
830
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
831 if(! total_bitrate)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
832 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
833 mp_msg(MSGT_DEMUX, MSGL_V, "SEEK_TS, couldn't determine bitrate, no seek\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
834 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
835 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
836
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
837 dest_offset = stream_tell(demuxer->stream) + rel_seek_secs*total_bitrate;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
838 if(dest_offset < 0) dest_offset = 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
839
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
840 mp_msg(MSGT_DEMUX, MSGL_V, "SEEK TO: %f, BITRATE: %lu, FINAL_POS: %u \n", rel_seek_secs, total_bitrate, dest_offset);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
841
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
842 stream_seek(demuxer->stream, dest_offset);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
843
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
844 /*if(!ts_sync(demuxer))
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
845 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
846 mp_msg(MSGT_DEMUX, MSGL_V, "demux_ts: Couldn't seek!\n");
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
847 return 0;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
848 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
849 */
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
850
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
851 ds_fill_buffer(d_video);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
852 if(sh_audio)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
853 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
854 ds_fill_buffer(d_audio);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
855 resync_audio_stream(sh_audio);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
856 }
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
857
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
858 return 1;
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
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
863
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
864
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
865 static int mpegts_read_close(MpegTSContext *ts)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
866 {
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
867 int i;
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
868 for(i=0;i<NB_PID_MAX;i++)
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
869 free(ts->pids[i]);
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
870 return 0;
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
76c6d8f1ebf5 this is a combo patch that:
arpi
parents:
diff changeset
874