Mercurial > mplayer.hg
annotate libmpdemux/demux_ty.c @ 31446:a9475c68aa47
Adjust printf length modifier, fixes the warning:
stream/stream_cdda.c:358: warning: format '%ld' expects type 'long int', but argument 4 has type 'int'
author | diego |
---|---|
date | Mon, 21 Jun 2010 10:51:31 +0000 |
parents | 0b68c2893cac |
children | cd81fce1f010 |
rev | line source |
---|---|
10263 | 1 /* |
2 * tivo@wingert.org, February 2003 | |
3 * | |
4 * Copyright (C) 2003 Christopher R. Wingert | |
5 * | |
6 * The license covers the portions of this file regarding TiVo additions. | |
7 * | |
24487 | 8 * Olaf Beck and Tridge (indirectly) were essential at providing |
9 * information regarding the format of the TiVo streams. | |
10263 | 10 * |
24487 | 11 * However, no code in the following subsection is directly copied from |
10263 | 12 * either author. |
13 * | |
26742
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
14 * This file is part of MPlayer. |
10263 | 15 * |
26742
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
16 * MPlayer is free software; you can redistribute it and/or modify |
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
17 * it under the terms of the GNU General Public License as published by |
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
18 * the Free Software Foundation; either version 2 of the License, or |
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
19 * (at your option) any later version. |
10263 | 20 * |
26742
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
21 * MPlayer is distributed in the hope that it will be useful, |
10263 | 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 * GNU General Public License for more details. | |
25 * | |
26742
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
26 * You should have received a copy of the GNU General Public License along |
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
27 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
0c1db5fd3f79
Use standard license headers with standard formatting.
diego
parents:
25883
diff
changeset
|
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
10263 | 29 */ |
30 | |
31 | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
34 #include <unistd.h> | |
35 #include <time.h> | |
36 #include <stdarg.h> | |
37 | |
38 #include "config.h" | |
39 #include "mp_msg.h" | |
40 #include "help_mp.h" | |
41 | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
20141
diff
changeset
|
42 #include "stream/stream.h" |
10263 | 43 #include "demuxer.h" |
30577
737b7fd47ef4
Add header for ty_ClearOSD(), ty_processuserdata(); avoids forward declarations.
diego
parents:
29898
diff
changeset
|
44 #include "demux_ty_osd.h" |
10263 | 45 #include "parse_es.h" |
46 #include "stheader.h" | |
17012 | 47 #include "sub_cc.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23381
diff
changeset
|
48 #include "libavutil/avstring.h" |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
49 #include "libavutil/intreadwrite.h" |
10263 | 50 |
28051 | 51 void skip_audio_frame( sh_audio_t *sh_audio ); |
10263 | 52 extern int sub_justify; |
53 | |
54 // 2/c0: audio data | |
55 // 3/c0: audio packet header (PES header) | |
56 // 4/c0: audio data (S/A only?) | |
57 // 9/c0: audio packet header, AC-3 audio | |
58 // 2/e0: video data | |
59 // 6/e0: video packet header (PES header) | |
60 // 7/e0: video sequence header start | |
61 // 8/e0: video I-frame header start | |
62 // a/e0: video P-frame header start | |
63 // b/e0: video B-frame header start | |
64 // c/e0: video GOP header start | |
65 // e/01: closed-caption data | |
24487 | 66 // e/02: Extended data services data |
10263 | 67 |
68 | |
24446 | 69 #define TIVO_PES_FILEID 0xf5467abd |
70 #define TIVO_PART_LENGTH 0x20000000 | |
10263 | 71 |
72 #define CHUNKSIZE ( 128 * 1024 ) | |
73 #define MAX_AUDIO_BUFFER ( 16 * 1024 ) | |
74 | |
24446 | 75 #define TY_V 1 |
76 #define TY_A 2 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
77 |
24499 | 78 typedef struct |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
79 { |
24498
7d955b1de13c
Remove another variable and reorder to avoid wasting space due to alignment
reimar
parents:
24497
diff
changeset
|
80 off_t startOffset; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
81 off_t fileSize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
82 int chunks; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
83 } tmf_fileParts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
84 |
24446 | 85 #define MAX_TMF_PARTS 16 |
10263 | 86 |
24499 | 87 typedef struct |
10263 | 88 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
89 int whichChunk; |
29898 | 90 unsigned char chunk[ CHUNKSIZE ]; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
91 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
92 unsigned char lastAudio[ MAX_AUDIO_BUFFER ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
93 int lastAudioEnd; |
10263 | 94 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
95 int tivoType; // 1 = SA, 2 = DTiVo |
10263 | 96 |
24463 | 97 int64_t lastAudioPTS; |
98 int64_t lastVideoPTS; | |
10263 | 99 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
100 off_t size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
101 int readHeader; |
24487 | 102 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
103 int tmf; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
104 tmf_fileParts tmfparts[ MAX_TMF_PARTS ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
105 int tmf_totalparts; |
10263 | 106 } TiVoInfo; |
107 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
108 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
109 #define TMF_SIG "showing.xml" |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
110 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
111 // =========================================================================== |
24443 | 112 static int ty_tmf_filetoparts( demuxer_t *demux, TiVoInfo *tivo ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
113 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
114 int parts = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
115 |
24501 | 116 stream_seek(demux->stream, 0); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
117 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
118 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Dumping tar contents\n" ); |
24501 | 119 while (!demux->stream->eof) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
120 { |
24488 | 121 char header[ 512 ]; |
122 char *name; | |
24500 | 123 char *extension; |
24488 | 124 char *sizestr; |
125 int size; | |
126 off_t skip; | |
24457 | 127 if (stream_read(demux->stream, header, 512) < 512) |
24487 | 128 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
129 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Read bad\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
130 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
131 } |
24448
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
132 name = header; |
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
133 name[99] = 0; |
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
134 sizestr = &header[124]; |
24449 | 135 sizestr[11] = 0; |
24442
9fc610537539
Use strtol instead of horribly suboptimal ty_octaltodecimal
reimar
parents:
24423
diff
changeset
|
136 size = strtol(sizestr, NULL, 8); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
137 |
24501 | 138 mp_msg( MSGT_DEMUX, MSGL_DBG3, "name %-20.20s size %-12.12s %d\n", |
139 name, sizestr, size ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
140 |
24500 | 141 extension = strrchr(name, '.'); |
24501 | 142 if (extension && strcmp(extension, ".ty") == 0) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
143 { |
24455 | 144 if ( parts >= MAX_TMF_PARTS ) { |
145 mp_msg( MSGT_DEMUX, MSGL_ERR, "ty:tmf too big\n" ); | |
146 break; | |
147 } | |
24447
c6253f3b5f47
Do not ignore last chunk in .tmf files, it will cause part of the file to be
reimar
parents:
24446
diff
changeset
|
148 tivo->tmfparts[ parts ].fileSize = size; |
24501 | 149 tivo->tmfparts[ parts ].startOffset = stream_tell(demux->stream); |
24450 | 150 tivo->tmfparts[ parts ].chunks = size / CHUNKSIZE; |
24502 | 151 mp_msg(MSGT_DEMUX, MSGL_DBG3, |
152 "tmf_filetoparts(): index %d, chunks %d\n" | |
153 "tmf_filetoparts(): size %"PRId64"\n" | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
154 "tmf_filetoparts(): startOffset %"PRId64"\n", |
24502 | 155 parts, tivo->tmfparts[ parts ].chunks, |
156 tivo->tmfparts[ parts ].fileSize, tivo->tmfparts[ parts ].startOffset | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
157 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
158 parts++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
159 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
160 |
24501 | 161 // size rounded up to blocks |
162 skip = (size + 511) & ~511; | |
163 stream_skip(demux->stream, skip); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
164 } |
24501 | 165 stream_reset(demux->stream); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
166 tivo->tmf_totalparts = parts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
167 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
168 "tmf_filetoparts(): No More Part Files %d\n", parts ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
169 |
24446 | 170 return 1; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
171 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
172 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
173 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
174 // =========================================================================== |
24451 | 175 static off_t tmf_filetooffset(TiVoInfo *tivo, int chunk) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
176 { |
24451 | 177 int i; |
178 for (i = 0; i < tivo->tmf_totalparts; i++) { | |
179 if (chunk < tivo->tmfparts[i].chunks) | |
180 return tivo->tmfparts[i].startOffset + chunk * CHUNKSIZE; | |
181 chunk -= tivo->tmfparts[i].chunks; | |
182 } | |
183 return -1; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
184 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
185 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
186 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
187 // =========================================================================== |
24487 | 188 static int tmf_load_chunk( demuxer_t *demux, TiVoInfo *tivo, |
24506
1639f5402540
get rid of pointless size parameter for tmf_load_chunk
reimar
parents:
24505
diff
changeset
|
189 unsigned char *buff, int readChunk ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
190 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
191 off_t fileoffset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
192 int count; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
193 |
24487 | 194 mp_msg( MSGT_DEMUX, MSGL_DBG3, "\ntmf_load_chunk() begin %d\n", |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
195 readChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
196 |
24452 | 197 fileoffset = tmf_filetooffset(tivo, readChunk); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
198 |
24503 | 199 if (fileoffset == -1 || !stream_seek(demux->stream, fileoffset)) { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
200 mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" ); |
24464 | 201 return 0; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
202 } |
24506
1639f5402540
get rid of pointless size parameter for tmf_load_chunk
reimar
parents:
24505
diff
changeset
|
203 count = stream_read( demux->stream, buff, CHUNKSIZE ); |
24487 | 204 demux->filepos = stream_tell( demux->stream ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
205 |
24487 | 206 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() count %x\n", |
207 count ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
208 |
24487 | 209 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
210 "tmf_load_chunk() bytes %x %x %x %x %x %x %x %x\n", | |
211 buff[ 0 ], buff[ 1 ], buff[ 2 ], buff[ 3 ], | |
212 buff[ 4 ], buff[ 5 ], buff[ 6 ], buff[ 7 ] ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
213 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
214 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() end\n" ); |
24487 | 215 |
24446 | 216 return count; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
217 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
218 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
219 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
220 |
10263 | 221 // DTiVo MPEG 336, 480, 576, 768 |
222 // SA TiVo 864 | |
223 // DTiVo AC-3 1550 | |
224 // | |
24446 | 225 #define SERIES1_PTS_LENGTH 11 |
226 #define SERIES1_PTS_OFFSET 6 | |
227 #define SERIES2_PTS_LENGTH 16 | |
228 #define SERIES2_PTS_OFFSET 9 | |
229 #define AC3_PTS_LENGTH 16 | |
230 #define AC3_PTS_OFFSET 9 | |
10263 | 231 |
232 static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen ) | |
233 { | |
234 // AC-3 | |
24446 | 235 if ( size == 1550 || size == 1552 ) |
10263 | 236 { |
237 *ptsOffset = AC3_PTS_OFFSET; | |
238 *ptsLen = AC3_PTS_LENGTH; | |
24446 | 239 return 1; |
10263 | 240 } |
241 | |
242 // MPEG | |
24471
516c6a2277b1
Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents:
24470
diff
changeset
|
243 if ( (size & 15) == (SERIES1_PTS_LENGTH & 15) ) |
10263 | 244 { |
245 *ptsOffset = SERIES1_PTS_OFFSET; | |
246 *ptsLen = SERIES1_PTS_LENGTH; | |
24470 | 247 return 1; |
10263 | 248 } |
24471
516c6a2277b1
Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents:
24470
diff
changeset
|
249 if ( (size & 15) == (SERIES2_PTS_LENGTH & 15) ) |
10263 | 250 { |
251 *ptsOffset = SERIES2_PTS_OFFSET; | |
252 *ptsLen = SERIES2_PTS_LENGTH; | |
24470 | 253 return 1; |
10263 | 254 } |
24487 | 255 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Tossing Audio Packet Size %d\n", |
10263 | 256 size ); |
24446 | 257 return 0; |
10263 | 258 } |
259 | |
260 | |
24463 | 261 static int64_t get_ty_pts( unsigned char *buf ) |
10263 | 262 { |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
263 int a = buf[0] & 0xe; |
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
264 int b = AV_RB16(buf + 1); |
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
265 int c = AV_RB16(buf + 3); |
10263 | 266 |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
267 if (!(1 & a & b & c)) // invalid MPEG timestamp |
24463 | 268 return MP_NOPTS_VALUE; |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
269 a >>= 1; b >>= 1; c >>= 1; |
24463 | 270 return (((uint64_t)a) << 30) | (b << 15) | c; |
10263 | 271 } |
272 | |
24487 | 273 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer, |
10263 | 274 int size ) |
275 { | |
24446 | 276 if ( tivo->lastAudioEnd + size < MAX_AUDIO_BUFFER ) |
10263 | 277 { |
24487 | 278 memcpy( &tivo->lastAudio[ tivo->lastAudioEnd ], |
10263 | 279 buffer, size ); |
280 tivo->lastAudioEnd += size; | |
281 } | |
282 else | |
283 mp_msg( MSGT_DEMUX, MSGL_ERR, | |
284 "ty:WARNING - Would have blown my audio buffer\n" ); | |
285 } | |
286 | |
24496
42693ad6dd30
Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents:
24495
diff
changeset
|
287 static void demux_ty_CopyToDemuxPacket( demux_stream_t *ds, |
24497
713ad2d3878d
PTS should be passed as int64_t to demux_ty_CopyToDemuxPacket
reimar
parents:
24496
diff
changeset
|
288 unsigned char *buffer, int size, off_t pos, int64_t pts ) |
10263 | 289 { |
24482 | 290 demux_packet_t *dp = new_demux_packet( size ); |
10263 | 291 memcpy( dp->buffer, buffer, size ); |
24463 | 292 if (pts != MP_NOPTS_VALUE) |
293 dp->pts = pts / 90000.0; | |
10263 | 294 dp->pos = pos; |
295 dp->flags = 0; | |
296 ds_add_packet( ds, dp ); | |
297 } | |
298 | |
24484 | 299 static int demux_ty_FindESHeader( uint8_t nal, |
24478 | 300 unsigned char *buffer, int bufferSize ) |
10263 | 301 { |
24484 | 302 uint32_t search = 0x00000100 | nal; |
24483 | 303 uint32_t found = -1; |
304 uint8_t *p = buffer; | |
305 uint8_t *end = p + bufferSize; | |
306 while (p < end) { | |
307 found <<= 8; | |
308 found |= *p++; | |
309 if (found == search) | |
310 return p - buffer - 4; | |
10263 | 311 } |
24446 | 312 return -1; |
10263 | 313 } |
314 | |
24487 | 315 static void demux_ty_FindESPacket( uint8_t nal, |
10263 | 316 unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 ) |
317 { | |
24484 | 318 *esOffset1 = demux_ty_FindESHeader(nal, buffer, bufferSize); |
24480
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
319 if (*esOffset1 == -1) { |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
320 *esOffset2 = -1; |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
321 return; |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
322 } |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
323 buffer += *esOffset1 + 1; |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
324 bufferSize -= *esOffset1 + 1; |
24484 | 325 *esOffset2 = demux_ty_FindESHeader(nal, buffer, bufferSize); |
24480
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
326 if (*esOffset2 != -1) |
a365d70938b3
Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents:
24479
diff
changeset
|
327 *esOffset2 += *esOffset1 + 1; |
10263 | 328 } |
329 | |
24484 | 330 #define VIDEO_NAL 0xe0 |
331 #define AUDIO_NAL 0xc0 | |
332 #define AC3_NAL 0xbd | |
10263 | 333 |
16175 | 334 static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds ) |
10263 | 335 { |
336 int invalidType = 0; | |
337 int errorHeader = 0; | |
338 int recordsDecoded = 0; | |
339 | |
340 int readSize; | |
341 | |
342 int numberRecs; | |
343 unsigned char *recPtr; | |
344 int offset; | |
345 | |
346 int counter; | |
347 | |
348 int aid; | |
24487 | 349 |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
350 TiVoInfo *tivo = demux->priv; |
29898 | 351 unsigned char *chunk = tivo->chunk; |
10263 | 352 |
353 if ( demux->stream->type == STREAMTYPE_DVD ) | |
24487 | 354 return 0; |
10263 | 355 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
356 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty processing\n" ); |
10263 | 357 |
358 if( demux->stream->eof ) return 0; | |
24487 | 359 |
10263 | 360 // ====================================================================== |
11000 | 361 // If we haven't figured out the size of the stream, let's do so |
10263 | 362 // ====================================================================== |
31357
0b68c2893cac
Cleanup some demux_ty code and at the same time possibly fix vstream support (untested).
reimar
parents:
30577
diff
changeset
|
363 if ( demux->stream->type == STREAMTYPE_VSTREAM ) |
10263 | 364 { |
365 // The vstream code figures out the exact size of the stream | |
366 demux->movi_start = 0; | |
31357
0b68c2893cac
Cleanup some demux_ty code and at the same time possibly fix vstream support (untested).
reimar
parents:
30577
diff
changeset
|
367 demux->movi_end = demux->stream->end_pos; |
0b68c2893cac
Cleanup some demux_ty code and at the same time possibly fix vstream support (untested).
reimar
parents:
30577
diff
changeset
|
368 tivo->size = demux->stream->end_pos; |
10263 | 369 } |
370 else | |
371 { | |
372 // If its a local file, try to find the Part Headers, so we can | |
373 // calculate the ACTUAL stream size | |
374 // If we can't find it, go off with the file size and hope the | |
375 // extract program did the "right thing" | |
376 if ( tivo->readHeader == 0 ) | |
377 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
378 off_t filePos; |
10263 | 379 tivo->readHeader = 1; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
380 |
10263 | 381 filePos = demux->filepos; |
382 stream_seek( demux->stream, 0 ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
383 |
10263 | 384 readSize = stream_read( demux->stream, chunk, CHUNKSIZE ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
385 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
386 if ( memcmp( chunk, TMF_SIG, sizeof( TMF_SIG ) ) == 0 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
387 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
388 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Detected a tmf\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
389 tivo->tmf = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
390 ty_tmf_filetoparts( demux, tivo ); |
24506
1639f5402540
get rid of pointless size parameter for tmf_load_chunk
reimar
parents:
24505
diff
changeset
|
391 readSize = tmf_load_chunk( demux, tivo, chunk, 0 ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
392 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
393 |
24467 | 394 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID ) |
10263 | 395 { |
396 off_t numberParts; | |
397 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
398 readSize = 0; |
24487 | 399 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
400 if ( tivo->tmf != 1 ) |
10263 | 401 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
402 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
403 |
10263 | 404 numberParts = demux->stream->end_pos / TIVO_PART_LENGTH; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
405 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
406 |
17366 | 407 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n", |
408 (int64_t)numberParts ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
409 |
24446 | 410 if ( offset + CHUNKSIZE < demux->stream->end_pos ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
411 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
412 stream_seek( demux->stream, offset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
413 readSize = stream_read( demux->stream, chunk, CHUNKSIZE ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
414 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
415 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
416 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
417 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
418 numberParts = tivo->tmf_totalparts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
419 offset = numberParts * TIVO_PART_LENGTH; |
24506
1639f5402540
get rid of pointless size parameter for tmf_load_chunk
reimar
parents:
24505
diff
changeset
|
420 readSize = tmf_load_chunk( demux, tivo, chunk, |
24487 | 421 numberParts * ( TIVO_PART_LENGTH - CHUNKSIZE ) / |
24446 | 422 CHUNKSIZE ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
423 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
424 |
24467 | 425 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
426 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
427 int size = AV_RB24(chunk + 12); |
10263 | 428 size -= 4; |
429 size *= CHUNKSIZE; | |
430 tivo->size = numberParts * TIVO_PART_LENGTH; | |
431 tivo->size += size; | |
24487 | 432 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
433 "ty:Header Calc Stream Size %"PRId64"\n", tivo->size ); |
10263 | 434 } |
435 } | |
436 | |
24487 | 437 if ( demux->stream->start_pos > 0 ) |
438 filePos = demux->stream->start_pos; | |
10263 | 439 stream_seek( demux->stream, filePos ); |
24487 | 440 demux->filepos = stream_tell( demux->stream ); |
24446 | 441 tivo->whichChunk = filePos / CHUNKSIZE; |
10263 | 442 } |
443 demux->movi_start = 0; | |
444 demux->movi_end = tivo->size; | |
445 } | |
446 | |
447 // ====================================================================== | |
448 // Give a clue as to where we are in the stream | |
449 // ====================================================================== | |
450 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
17366 | 451 "ty:ty header size %"PRIx64"\n", (int64_t)tivo->size ); |
10263 | 452 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 453 "ty:ty which Chunk %d\n", tivo->whichChunk ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
454 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 455 "ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos ); |
10263 | 456 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 457 "\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) ); |
10263 | 458 |
24464 | 459 if ( tivo->size > 0 && stream_tell( demux->stream ) > tivo->size ) |
10263 | 460 { |
461 demux->stream->eof = 1; | |
24464 | 462 return 0; |
10263 | 463 } |
464 | |
24507 | 465 do { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
466 if ( tivo->tmf != 1 ) |
10263 | 467 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
468 // Make sure we are on a 128k boundary |
24446 | 469 if ( demux->filepos % CHUNKSIZE != 0 ) |
10263 | 470 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
471 int whichChunk = demux->filepos / CHUNKSIZE; |
24446 | 472 if ( demux->filepos % CHUNKSIZE > CHUNKSIZE / 2 ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
473 whichChunk++; |
24446 | 474 stream_seek( demux->stream, whichChunk * CHUNKSIZE ); |
10263 | 475 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
476 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
477 demux->filepos = stream_tell( demux->stream ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
478 tivo->whichChunk = demux->filepos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
479 readSize = stream_read( demux->stream, chunk, CHUNKSIZE ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
480 if ( readSize != CHUNKSIZE ) |
24464 | 481 return 0; |
10263 | 482 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
483 else |
10263 | 484 { |
24506
1639f5402540
get rid of pointless size parameter for tmf_load_chunk
reimar
parents:
24505
diff
changeset
|
485 readSize = tmf_load_chunk( demux, tivo, chunk, tivo->whichChunk ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
486 if ( readSize != CHUNKSIZE ) |
24446 | 487 return 0; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
488 tivo->whichChunk++; |
10263 | 489 } |
24507 | 490 if (AV_RB32(chunk) == TIVO_PES_FILEID) |
10263 | 491 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Skipping PART Header\n" ); |
24507 | 492 } while (AV_RB32(chunk) == TIVO_PES_FILEID); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
493 |
10263 | 494 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
24487 | 495 "\nty:actual current offset %"PRIx64"\n", stream_tell( demux->stream ) - |
496 CHUNKSIZE ); | |
10263 | 497 |
498 | |
12860 | 499 // Let's make a Video Demux Stream for MPlayer |
10263 | 500 aid = 0x0; |
501 if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid ); | |
502 if( demux->video->id == -1 ) demux->video->id = aid; | |
503 if( demux->video->id == aid ) | |
504 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
505 demux_stream_t *ds = demux->video; |
10263 | 506 if( !ds->sh ) ds->sh = demux->v_streams[ aid ]; |
507 } | |
508 | |
509 // ====================================================================== | |
510 // Finally, we get to actually parse the chunk | |
511 // ====================================================================== | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
512 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" ); |
10263 | 513 numberRecs = chunk[ 0 ]; |
514 recPtr = &chunk[ 4 ]; | |
24446 | 515 offset = numberRecs * 16 + 4; |
10263 | 516 for ( counter = 0 ; counter < numberRecs ; counter++ ) |
517 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
518 int size = AV_RB24(recPtr) >> 4; |
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
519 int type = recPtr[ 3 ]; |
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
520 int nybbleType = recPtr[ 2 ] & 0x0f; |
10263 | 521 recordsDecoded++; |
522 | |
523 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
524 "ty:Record Type %x/%x %d\n", nybbleType, type, size ); | |
525 | |
526 // ================================================================ | |
527 // Video Parsing | |
528 // ================================================================ | |
529 if ( type == 0xe0 ) | |
530 { | |
24446 | 531 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 532 { |
24487 | 533 int esOffset1 = demux_ty_FindESHeader( VIDEO_NAL, &chunk[ offset ], |
24478 | 534 size); |
10263 | 535 if ( esOffset1 != -1 ) |
24487 | 536 tivo->lastVideoPTS = get_ty_pts( |
10263 | 537 &chunk[ offset + esOffset1 + 9 ] ); |
538 | |
539 // Do NOT Pass the PES Header onto the MPEG2 Decode | |
540 if( nybbleType != 0x06 ) | |
24496
42693ad6dd30
Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents:
24495
diff
changeset
|
541 demux_ty_CopyToDemuxPacket( demux->video, |
24487 | 542 &chunk[ offset ], size, demux->filepos + offset, |
543 tivo->lastVideoPTS ); | |
10263 | 544 offset += size; |
545 } | |
24487 | 546 else |
547 errorHeader++; | |
10263 | 548 } |
549 // ================================================================ | |
550 // Audio Parsing | |
551 // ================================================================ | |
24487 | 552 else if ( type == 0xc0 ) |
10263 | 553 { |
24446 | 554 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 555 { |
556 if( demux->audio->id == -1 ) | |
557 { | |
558 if ( nybbleType == 0x02 ) | |
559 continue; // DTiVo inconclusive, wait for more | |
560 else if ( nybbleType == 0x09 ) | |
561 { | |
562 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" ); | |
563 aid = 0x80; // AC-3 | |
564 } | |
565 else | |
566 { | |
567 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" ); | |
568 aid = 0x0; // MPEG Audio | |
569 } | |
570 | |
571 demux->audio->id = aid; | |
572 if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid ); | |
573 if( demux->audio->id == aid ) | |
574 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
575 demux_stream_t *ds = demux->audio; |
15580 | 576 if( !ds->sh ) { |
577 sh_audio_t* sh_a; | |
578 ds->sh = demux->a_streams[ aid ]; | |
579 sh_a = (sh_audio_t*)ds->sh; | |
580 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id) | |
581 case 0x00: sh_a->format=0x50;break; // mpeg | |
582 case 0xA0: sh_a->format=0x10001;break; // dvd pcm | |
583 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts | |
584 else sh_a->format=0x2000;break; // ac3 | |
585 } | |
586 } | |
10263 | 587 } |
588 } | |
589 | |
590 aid = demux->audio->id; | |
591 | |
592 | |
593 // SA DTiVo Audio Data, no PES | |
594 // ================================================ | |
24476 | 595 if ( nybbleType == 0x02 || nybbleType == 0x04 ) |
10263 | 596 { |
24476 | 597 if ( nybbleType == 0x02 && tivo->tivoType == 2 ) |
10263 | 598 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); |
599 else | |
600 { | |
601 | |
602 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
603 "ty:Adding Audio Packet Size %d\n", size ); | |
24496
42693ad6dd30
Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents:
24495
diff
changeset
|
604 demux_ty_CopyToDemuxPacket( demux->audio, |
24487 | 605 &chunk[ offset ], size, ( demux->filepos + offset ), |
606 tivo->lastAudioPTS ); | |
10263 | 607 } |
608 } | |
609 | |
24475 | 610 // 3 - MPEG Audio with PES Header, either SA or DTiVo |
611 // 9 - DTiVo AC3 Audio Data with PES Header | |
10263 | 612 // ================================================ |
24475 | 613 if ( nybbleType == 0x03 || nybbleType == 0x09 ) |
10263 | 614 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
615 int esOffset1, esOffset2; |
24475 | 616 if ( nybbleType == 0x03 ) |
24487 | 617 esOffset1 = demux_ty_FindESHeader( AUDIO_NAL, &chunk[ offset ], |
24478 | 618 size); |
10263 | 619 |
620 // SA PES Header, No Audio Data | |
621 // ================================================ | |
24475 | 622 if ( nybbleType == 0x03 && esOffset1 == 0 && size == 16 ) |
10263 | 623 { |
624 tivo->tivoType = 1; | |
24487 | 625 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + |
10263 | 626 SERIES2_PTS_OFFSET ] ); |
627 } | |
628 else | |
629 // DTiVo Audio with PES Header | |
630 // ================================================ | |
631 { | |
632 tivo->tivoType = 2; | |
633 | |
634 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
24484 | 635 demux_ty_FindESPacket( nybbleType == 9 ? AC3_NAL : AUDIO_NAL, |
10263 | 636 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, |
637 &esOffset2 ); | |
638 | |
24446 | 639 if ( esOffset1 != -1 && esOffset2 != -1 ) |
10263 | 640 { |
641 int packetSize = esOffset2 - esOffset1; | |
642 int headerSize; | |
643 int ptsOffset; | |
644 | |
24487 | 645 if ( IsValidAudioPacket( packetSize, &ptsOffset, |
10263 | 646 &headerSize ) ) |
647 { | |
648 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
24487 | 649 "ty:Adding DTiVo Audio Packet Size %d\n", |
10263 | 650 packetSize ); |
651 | |
24487 | 652 tivo->lastAudioPTS = get_ty_pts( |
10263 | 653 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); |
654 | |
24475 | 655 if (nybbleType == 9) headerSize = 0; |
10263 | 656 demux_ty_CopyToDemuxPacket |
24487 | 657 ( |
658 demux->audio, | |
24486 | 659 &tivo->lastAudio[ esOffset1 + headerSize ], |
660 packetSize - headerSize, | |
661 demux->filepos + offset, | |
24487 | 662 tivo->lastAudioPTS |
10263 | 663 ); |
664 | |
665 } | |
666 | |
667 // Collapse the Audio Buffer | |
24485 | 668 tivo->lastAudioEnd -= esOffset2; |
24487 | 669 memmove( &tivo->lastAudio[ 0 ], |
670 &tivo->lastAudio[ esOffset2 ], | |
24485 | 671 tivo->lastAudioEnd ); |
10263 | 672 } |
673 } | |
674 } | |
675 | |
676 offset += size; | |
677 } | |
24487 | 678 else |
679 errorHeader++; | |
680 } | |
10263 | 681 // ================================================================ |
24474 | 682 // 1 = Closed Caption |
683 // 2 = Extended Data Services | |
10263 | 684 // ================================================================ |
24487 | 685 else if ( type == 0x01 || type == 0x02 ) |
686 { | |
24474 | 687 unsigned char lastXDS[ 16 ]; |
24487 | 688 int b = AV_RB24(recPtr) >> 4; |
689 b &= 0x7f7f; | |
10263 | 690 |
24474 | 691 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:%s %04x\n", type == 1 ? "CC" : "XDS", b); |
10263 | 692 |
24487 | 693 lastXDS[ 0x00 ] = 0x00; |
694 lastXDS[ 0x01 ] = 0x00; | |
695 lastXDS[ 0x02 ] = 0x01; | |
696 lastXDS[ 0x03 ] = 0xb2; | |
697 lastXDS[ 0x04 ] = 'T'; | |
698 lastXDS[ 0x05 ] = 'Y'; | |
699 lastXDS[ 0x06 ] = type; | |
700 lastXDS[ 0x07 ] = b >> 8; | |
701 lastXDS[ 0x08 ] = b; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
702 if ( subcc_enabled ) |
24496
42693ad6dd30
Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents:
24495
diff
changeset
|
703 demux_ty_CopyToDemuxPacket( demux->video, lastXDS, 0x09, |
24487 | 704 demux->filepos + offset, tivo->lastVideoPTS ); |
705 } | |
10263 | 706 // ================================================================ |
707 // Unknown | |
708 // ================================================================ | |
24487 | 709 else |
710 { | |
24446 | 711 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 712 offset += size; |
24489
97eba82233f5
live recordings can contain 0-size type 0 chunks, ignore them instead
reimar
parents:
24488
diff
changeset
|
713 if (type != 3 && type != 5 && (type != 0 || size > 0)) { |
10263 | 714 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type ); |
24487 | 715 invalidType++; |
24472 | 716 } |
24487 | 717 } |
10263 | 718 recPtr += 16; |
719 } | |
720 | |
20141
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
721 if ( errorHeader > 0 || invalidType > 0 ) |
10263 | 722 { |
24487 | 723 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
20141
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
724 "ty:Error Check - Records %d, Parsed %d, Errors %d + %d\n", |
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
725 numberRecs, recordsDecoded, errorHeader, invalidType ); |
10263 | 726 |
727 // Invalid MPEG ES Size Check | |
24446 | 728 if ( errorHeader > numberRecs / 2 ) |
729 return 0; | |
10263 | 730 |
731 // Invalid MPEG Stream Type Check | |
24446 | 732 if ( invalidType > numberRecs / 2 ) |
733 return 0; | |
10263 | 734 } |
735 | |
736 demux->filepos = stream_tell( demux->stream ); | |
737 | |
24446 | 738 return 1; |
10263 | 739 } |
740 | |
17636 | 741 static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) |
10263 | 742 { |
743 demux_stream_t *d_audio = demuxer->audio; | |
744 demux_stream_t *d_video = demuxer->video; | |
745 sh_audio_t *sh_audio = d_audio->sh; | |
746 sh_video_t *sh_video = d_video->sh; | |
747 off_t newpos; | |
748 off_t res; | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
749 TiVoInfo *tivo = demuxer->priv; |
10263 | 750 |
751 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Seeking to %7.1f\n", rel_seek_secs ); | |
752 | |
753 tivo->lastAudioEnd = 0; | |
24463 | 754 tivo->lastAudioPTS = MP_NOPTS_VALUE; |
755 tivo->lastVideoPTS = MP_NOPTS_VALUE; | |
10263 | 756 // |
757 //================= seek in MPEG ========================== | |
758 demuxer->filepos = stream_tell( demuxer->stream ); | |
759 | |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
760 newpos = ( flags & SEEK_ABSOLUTE ) ? demuxer->movi_start : demuxer->filepos; |
24487 | 761 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
762 if( flags & SEEK_FACTOR ) |
24487 | 763 // float seek 0..1 |
764 newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs; | |
765 else | |
10263 | 766 { |
24487 | 767 // time seek (secs) |
10263 | 768 if( ! sh_video->i_bps ) // unspecified or VBR |
769 newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec | |
770 else | |
771 newpos += sh_video->i_bps * rel_seek_secs; | |
772 } | |
773 | |
774 if ( newpos < demuxer->movi_start ) | |
775 { | |
24487 | 776 if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0; |
777 if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start; | |
778 } | |
10263 | 779 |
780 res = newpos / CHUNKSIZE; | |
781 if ( rel_seek_secs >= 0 ) | |
782 newpos = ( res + 1 ) * CHUNKSIZE; | |
783 else | |
784 newpos = res * CHUNKSIZE; | |
785 | |
786 if ( newpos < 0 ) | |
787 newpos = 0; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
788 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
789 tivo->whichChunk = newpos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
790 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
791 stream_seek( demuxer->stream, newpos ); |
10263 | 792 |
793 // re-sync video: | |
794 videobuf_code_len = 0; // reset ES stream buffer | |
795 | |
24487 | 796 ds_fill_buffer( d_video ); |
797 if( sh_audio ) | |
798 ds_fill_buffer( d_audio ); | |
10263 | 799 |
24487 | 800 while( 1 ) |
10263 | 801 { |
24487 | 802 int i; |
10263 | 803 if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts ) |
804 { | |
24487 | 805 float a_pts = d_audio->pts; |
10263 | 806 a_pts += ( ds_tell_pts( d_audio ) - sh_audio->a_in_buffer_len ) / |
807 (float)sh_audio->i_bps; | |
24487 | 808 if( d_video->pts > a_pts ) |
10263 | 809 { |
24487 | 810 skip_audio_frame( sh_audio ); // sync audio |
811 continue; | |
812 } | |
10263 | 813 } |
814 i = sync_video_packet( d_video ); | |
815 if( i == 0x1B3 || i == 0x1B8 ) break; // found it! | |
816 if( !i || !skip_video_packet( d_video ) ) break; // EOF? | |
817 } | |
24487 | 818 if ( subcc_enabled ) |
819 ty_ClearOSD( 0 ); | |
10263 | 820 } |
821 | |
24443 | 822 static int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg ) |
10263 | 823 { |
824 demux_stream_t *d_video = demuxer->video; | |
825 sh_video_t *sh_video = d_video->sh; | |
826 | |
24487 | 827 switch(cmd) |
10263 | 828 { |
24487 | 829 case DEMUXER_CTRL_GET_TIME_LENGTH: |
830 if(!sh_video->i_bps) // unspecified or VBR | |
831 return DEMUXER_CTRL_DONTKNOW; | |
832 *(double *)arg= | |
24446 | 833 (double)demuxer->movi_end-demuxer->movi_start/sh_video->i_bps; |
24487 | 834 return DEMUXER_CTRL_GUESS; |
10263 | 835 |
24487 | 836 case DEMUXER_CTRL_GET_PERCENT_POS: |
837 return DEMUXER_CTRL_DONTKNOW; | |
838 default: | |
839 return DEMUXER_CTRL_NOTIMPL; | |
10263 | 840 } |
841 } | |
842 | |
843 | |
17174
83a8c738be89
make demuxer seek and close functions return void, patch by Dominik Mierzejewski
wanderer
parents:
17012
diff
changeset
|
844 static void demux_close_ty( demuxer_t *demux ) |
10263 | 845 { |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
846 TiVoInfo *tivo = demux->priv; |
10263 | 847 |
848 free( tivo ); | |
24487 | 849 sub_justify = 0; |
10263 | 850 } |
851 | |
852 | |
16175 | 853 static int ty_check_file(demuxer_t* demuxer) |
854 { | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
855 TiVoInfo *tivo = calloc(1, sizeof(TiVoInfo)); |
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
856 demuxer->priv = tivo; |
16175 | 857 return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0; |
858 } | |
859 | |
860 | |
861 static demuxer_t* demux_open_ty(demuxer_t* demuxer) | |
862 { | |
863 sh_audio_t *sh_audio=NULL; | |
864 sh_video_t *sh_video=NULL; | |
865 | |
866 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
867 | |
868 if(demuxer->audio->id!=-2) { | |
869 if(!ds_fill_buffer(demuxer->audio)){ | |
870 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
871 demuxer->audio->sh=NULL; | |
872 } else { | |
873 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
874 } | |
875 } | |
876 | |
877 return demuxer; | |
878 } | |
879 | |
880 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24507
diff
changeset
|
881 const demuxer_desc_t demuxer_desc_mpeg_ty = { |
16175 | 882 "TiVo demuxer", |
883 "tivo", | |
884 "TiVo", | |
885 "Christopher R. Wingert", | |
886 "Demux streams from TiVo", | |
887 DEMUXER_TYPE_MPEG_TY, | |
888 0, // unsafe autodetect | |
889 ty_check_file, | |
890 demux_ty_fill_buffer, | |
891 demux_open_ty, | |
892 demux_close_ty, | |
893 demux_seek_ty, | |
894 demux_ty_control | |
895 }; |