annotate libmpdemux/demux_ts.c @ 9980:7bd7a1aa605f

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