Mercurial > mplayer.hg
annotate libmpdemux/demux_ty.c @ 24473:f8971c9855a3
Simplify XDS handling
author | reimar |
---|---|
date | Fri, 14 Sep 2007 19:07:50 +0000 |
parents | 9341d242f432 |
children | 1754f9ab919e |
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 * | |
8 * Olaf Beck and Tridge (indirectly) were essential at providing | |
9 * information regarding the format of the TiVo streams. | |
10 * | |
11 * However, no code in the following subsection is directly copied from | |
12 * either author. | |
13 * | |
14 * | |
15 * This program is free software; you can redistribute it and/or | |
16 * modify it under the terms of the GNU General Public License | |
17 * as published by the Free Software Foundation; either version 2 | |
18 * of the License, or (at your option) any later version. | |
19 * | |
20 * This program is distributed in the hope that it will be useful, | |
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 * GNU General Public License for more details. | |
24 * | |
25 * You should have received a copy of the GNU General Public License | |
26 * along with this program; if not, write to the Free Software | |
19614 | 27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
10263 | 28 * |
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" |
44 #include "parse_es.h" | |
45 #include "stheader.h" | |
17012 | 46 #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
|
47 #include "libavutil/avstring.h" |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
48 #include "libavutil/intreadwrite.h" |
10263 | 49 |
50 extern void skip_audio_frame( sh_audio_t *sh_audio ); | |
51 extern int sub_justify; | |
52 | |
53 // 2/c0: audio data | |
54 // 3/c0: audio packet header (PES header) | |
55 // 4/c0: audio data (S/A only?) | |
56 // 9/c0: audio packet header, AC-3 audio | |
57 // 2/e0: video data | |
58 // 6/e0: video packet header (PES header) | |
59 // 7/e0: video sequence header start | |
60 // 8/e0: video I-frame header start | |
61 // a/e0: video P-frame header start | |
62 // b/e0: video B-frame header start | |
63 // c/e0: video GOP header start | |
64 // e/01: closed-caption data | |
65 // e/02: Extended data services data | |
66 | |
67 | |
24446 | 68 #define TIVO_PES_FILEID 0xf5467abd |
69 #define TIVO_PART_LENGTH 0x20000000 | |
10263 | 70 |
71 #define CHUNKSIZE ( 128 * 1024 ) | |
72 #define MAX_AUDIO_BUFFER ( 16 * 1024 ) | |
73 | |
24446 | 74 #define TY_V 1 |
75 #define TY_A 2 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
76 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
77 typedef struct stmf_fileParts |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
78 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
79 int fileNo; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
80 off_t fileSize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
81 int chunks; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
82 off_t startOffset; |
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 |
87 typedef struct sTivoInfo | |
88 { | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
89 int whichChunk; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
90 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
91 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
|
92 int lastAudioEnd; |
10263 | 93 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
94 int tivoType; // 1 = SA, 2 = DTiVo |
10263 | 95 |
24463 | 96 int64_t firstAudioPTS; |
97 int64_t firstVideoPTS; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
98 |
24463 | 99 int64_t lastAudioPTS; |
100 int64_t lastVideoPTS; | |
10263 | 101 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
102 int headerOk; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
103 off_t size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
104 int readHeader; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
105 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
106 int tmf; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
107 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
|
108 int tmf_totalparts; |
10263 | 109 } TiVoInfo; |
110 | |
111 off_t vstream_streamsize( ); | |
112 void ty_ClearOSD( int start ); | |
113 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
114 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
115 #define TMF_SIG "showing.xml" |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
116 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
117 // =========================================================================== |
24444 | 118 static int ty_extensionis(const char *name, const char *ext ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
119 { |
24444 | 120 int delta = strlen(name) - strlen(ext); |
121 if (delta < 0) return 0; | |
122 name += delta; | |
123 return strcmp(name, ext) == 0; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
124 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
125 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
126 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
127 // =========================================================================== |
24443 | 128 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
|
129 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
130 char header[ 512 ]; |
24448
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
131 char *name; |
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
132 char *sizestr; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
133 int size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
134 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
135 off_t totalsize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
136 off_t skip; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
137 int parts = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
138 int isty; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
139 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
140 offset = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
141 totalsize = demux->stream->end_pos; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
142 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
143 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Dumping tar contents\n" ); |
24456 | 144 while (1) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
145 { |
24457 | 146 if (!stream_seek(demux->stream, offset)) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
147 { |
17366 | 148 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Seek bad %"PRId64"\n", (int64_t)offset ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
149 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
150 } |
24457 | 151 if (stream_read(demux->stream, header, 512) < 512) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
152 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
153 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
|
154 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
155 } |
24448
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
156 name = header; |
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
157 name[99] = 0; |
044d3ec97bf7
Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents:
24447
diff
changeset
|
158 sizestr = &header[124]; |
24449 | 159 sizestr[11] = 0; |
24442
9fc610537539
Use strtol instead of horribly suboptimal ty_octaltodecimal
reimar
parents:
24423
diff
changeset
|
160 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
|
161 |
24450 | 162 // size rounded up to blocks + header size |
163 skip = 512 + ((size + 511) & ~511); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
164 |
24446 | 165 if ( offset + skip > totalsize ) |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
166 size = totalsize - offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
167 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
168 isty = ty_extensionis( name, ".ty" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
169 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
170 mp_msg( MSGT_DEMUX, MSGL_DBG3, "name %-20.20s size %-12.12s %d %d\n", |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
171 name, sizestr, size, isty ); |
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 if ( isty ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
174 { |
24455 | 175 if ( parts >= MAX_TMF_PARTS ) { |
176 mp_msg( MSGT_DEMUX, MSGL_ERR, "ty:tmf too big\n" ); | |
177 break; | |
178 } | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
179 tivo->tmfparts[ parts ].fileNo = parts; |
24447
c6253f3b5f47
Do not ignore last chunk in .tmf files, it will cause part of the file to be
reimar
parents:
24446
diff
changeset
|
180 tivo->tmfparts[ parts ].fileSize = size; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
181 tivo->tmfparts[ parts ].startOffset = offset + 512; |
24450 | 182 tivo->tmfparts[ parts ].chunks = size / CHUNKSIZE; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
183 mp_msg |
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 MSGT_DEMUX, MSGL_DBG3, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
186 "tmf_filetoparts(): index %d, file %d, chunks %d\n", |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
187 parts, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
188 tivo->tmfparts[ parts ].fileNo, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
189 tivo->tmfparts[ parts ].chunks |
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 mp_msg |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
192 ( |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
193 MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
194 "tmf_filetoparts(): size %"PRId64"\n", |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
195 tivo->tmfparts[ parts ].fileSize |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
196 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
197 mp_msg |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
198 ( |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
199 MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
200 "tmf_filetoparts(): startOffset %"PRId64"\n", |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
201 tivo->tmfparts[ parts ].startOffset |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
202 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
203 parts++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
204 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
205 |
24457 | 206 if (offset + skip >= totalsize) |
24456 | 207 break; |
24457 | 208 offset += skip; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
209 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
210 tivo->tmf_totalparts = parts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
211 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
|
212 "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
|
213 |
24446 | 214 return 1; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
215 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
216 |
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 // =========================================================================== |
24451 | 219 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
|
220 { |
24451 | 221 int i; |
222 for (i = 0; i < tivo->tmf_totalparts; i++) { | |
223 if (chunk < tivo->tmfparts[i].chunks) | |
224 return tivo->tmfparts[i].startOffset + chunk * CHUNKSIZE; | |
225 chunk -= tivo->tmfparts[i].chunks; | |
226 } | |
227 return -1; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
228 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
229 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
230 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
231 // =========================================================================== |
24443 | 232 static int tmf_load_chunk( 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
|
233 unsigned char *buff, int size, int readChunk ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
234 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
235 off_t fileoffset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
236 int count; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
237 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
238 mp_msg( MSGT_DEMUX, MSGL_DBG3, "\ntmf_load_chunk() begin %d\n", |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
239 readChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
240 |
24452 | 241 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
|
242 |
24452 | 243 if (fileoffset == -1) { |
244 mp_msg(MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n"); | |
245 return 0; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
246 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
247 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
248 if ( stream_seek( demux->stream, fileoffset ) != 1 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
249 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
250 mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" ); |
24464 | 251 return 0; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
252 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
253 count = stream_read( demux->stream, buff, size ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
254 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
|
255 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
256 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() count %x\n", |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
257 count ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
258 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
259 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
|
260 "tmf_load_chunk() bytes %x %x %x %x %x %x %x %x\n", |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
261 buff[ 0 ], buff[ 1 ], buff[ 2 ], buff[ 3 ], |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
262 buff[ 4 ], buff[ 5 ], buff[ 6 ], buff[ 7 ] ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
263 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
264 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() end\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
265 |
24446 | 266 return count; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
267 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
268 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
269 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
270 |
10263 | 271 // DTiVo MPEG 336, 480, 576, 768 |
272 // SA TiVo 864 | |
273 // DTiVo AC-3 1550 | |
274 // | |
24446 | 275 #define SERIES1_PTS_LENGTH 11 |
276 #define SERIES1_PTS_OFFSET 6 | |
277 #define SERIES2_PTS_LENGTH 16 | |
278 #define SERIES2_PTS_OFFSET 9 | |
279 #define AC3_PTS_LENGTH 16 | |
280 #define AC3_PTS_OFFSET 9 | |
10263 | 281 |
282 static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen ) | |
283 { | |
284 *ptsOffset = 0; | |
285 *ptsLen = 0; | |
286 | |
287 // AC-3 | |
24446 | 288 if ( size == 1550 || size == 1552 ) |
10263 | 289 { |
290 *ptsOffset = AC3_PTS_OFFSET; | |
291 *ptsLen = AC3_PTS_LENGTH; | |
24446 | 292 return 1; |
10263 | 293 } |
294 | |
295 // MPEG | |
24471
516c6a2277b1
Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents:
24470
diff
changeset
|
296 if ( (size & 15) == (SERIES1_PTS_LENGTH & 15) ) |
10263 | 297 { |
298 *ptsOffset = SERIES1_PTS_OFFSET; | |
299 *ptsLen = SERIES1_PTS_LENGTH; | |
24470 | 300 return 1; |
10263 | 301 } |
24471
516c6a2277b1
Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents:
24470
diff
changeset
|
302 if ( (size & 15) == (SERIES2_PTS_LENGTH & 15) ) |
10263 | 303 { |
304 *ptsOffset = SERIES2_PTS_OFFSET; | |
305 *ptsLen = SERIES2_PTS_LENGTH; | |
24470 | 306 return 1; |
10263 | 307 } |
308 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Tossing Audio Packet Size %d\n", | |
309 size ); | |
24446 | 310 return 0; |
10263 | 311 } |
312 | |
313 | |
24463 | 314 static int64_t get_ty_pts( unsigned char *buf ) |
10263 | 315 { |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
316 int a = buf[0] & 0xe; |
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
317 int b = AV_RB16(buf + 1); |
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
318 int c = AV_RB16(buf + 3); |
10263 | 319 |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
320 if (!(1 & a & b & c)) // invalid MPEG timestamp |
24463 | 321 return MP_NOPTS_VALUE; |
24461
921de822048c
Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents:
24460
diff
changeset
|
322 a >>= 1; b >>= 1; c >>= 1; |
24463 | 323 return (((uint64_t)a) << 30) | (b << 15) | c; |
10263 | 324 } |
325 | |
326 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer, | |
327 int size ) | |
328 { | |
24446 | 329 if ( tivo->lastAudioEnd + size < MAX_AUDIO_BUFFER ) |
10263 | 330 { |
24446 | 331 memcpy( &tivo->lastAudio[ tivo->lastAudioEnd ], |
10263 | 332 buffer, size ); |
333 tivo->lastAudioEnd += size; | |
334 } | |
335 else | |
336 mp_msg( MSGT_DEMUX, MSGL_ERR, | |
337 "ty:WARNING - Would have blown my audio buffer\n" ); | |
338 } | |
339 | |
340 static void demux_ty_CopyToDemuxPacket( int type, TiVoInfo *tivo, demux_stream_t *ds, | |
341 unsigned char *buffer, int size, off_t pos, float pts ) | |
342 { | |
343 demux_packet_t *dp; | |
344 | |
345 // mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Calling ds_add_packet() %7.1f\n", pts ); | |
346 // printf( "%x %x %x %x\n", | |
347 // buffer[ 0 ], buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] ); | |
348 | |
349 dp = new_demux_packet( size ); | |
350 memcpy( dp->buffer, buffer, size ); | |
24463 | 351 if (pts != MP_NOPTS_VALUE) |
352 dp->pts = pts / 90000.0; | |
10263 | 353 dp->pos = pos; |
354 dp->flags = 0; | |
355 ds_add_packet( ds, dp ); | |
24463 | 356 if ( type == TY_V && tivo->firstVideoPTS == MP_NOPTS_VALUE ) |
10263 | 357 tivo->firstVideoPTS = pts; |
24463 | 358 if ( type == TY_A && tivo->firstAudioPTS == MP_NOPTS_VALUE ) |
10263 | 359 tivo->firstAudioPTS = pts; |
360 } | |
361 | |
362 static int demux_ty_FindESHeader( unsigned char *header, int headerSize, | |
363 unsigned char *buffer, int bufferSize, int *esOffset1 ) | |
364 { | |
365 int count; | |
366 | |
367 *esOffset1 = -1; | |
368 for( count = 0 ; count < bufferSize ; count++ ) | |
369 { | |
24446 | 370 if ( buffer[ count + 0 ] == header[ 0 ] && |
371 buffer[ count + 1 ] == header[ 1 ] && | |
372 buffer[ count + 2 ] == header[ 2 ] && | |
373 buffer[ count + 3 ] == header[ 3 ] ) | |
10263 | 374 { |
375 *esOffset1 = count; | |
24446 | 376 return 1; |
10263 | 377 } |
378 } | |
24446 | 379 return -1; |
10263 | 380 } |
381 | |
382 static void demux_ty_FindESPacket( unsigned char *header, int headerSize, | |
383 unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 ) | |
384 { | |
385 int count; | |
386 | |
387 *esOffset1 = -1; | |
388 *esOffset2 = -1; | |
389 | |
390 for( count = 0 ; count < bufferSize ; count++ ) | |
391 { | |
24446 | 392 if ( buffer[ count + 0 ] == header[ 0 ] && |
393 buffer[ count + 1 ] == header[ 1 ] && | |
394 buffer[ count + 2 ] == header[ 2 ] && | |
395 buffer[ count + 3 ] == header[ 3 ] ) | |
10263 | 396 { |
397 *esOffset1 = count; | |
398 break; | |
399 } | |
400 } | |
401 | |
402 if ( *esOffset1 != -1 ) | |
403 { | |
404 for( count = *esOffset1 + 1 ; | |
405 count < bufferSize ; count++ ) | |
406 { | |
24446 | 407 if ( buffer[ count + 0 ] == header[ 0 ] && |
408 buffer[ count + 1 ] == header[ 1 ] && | |
409 buffer[ count + 2 ] == header[ 2 ] && | |
410 buffer[ count + 3 ] == header[ 3 ] ) | |
10263 | 411 { |
412 *esOffset2 = count; | |
413 break; | |
414 } | |
415 } | |
416 } | |
417 } | |
418 | |
419 static unsigned char ty_VideoPacket[] = { 0x00, 0x00, 0x01, 0xe0 }; | |
420 static unsigned char ty_MPEGAudioPacket[] = { 0x00, 0x00, 0x01, 0xc0 }; | |
421 static unsigned char ty_AC3AudioPacket[] = { 0x00, 0x00, 0x01, 0xbd }; | |
422 | |
16175 | 423 static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds ) |
10263 | 424 { |
425 int invalidType = 0; | |
426 int errorHeader = 0; | |
427 int recordsDecoded = 0; | |
428 off_t filePos = 0; | |
429 | |
430 unsigned char chunk[ CHUNKSIZE ]; | |
431 int whichChunk; | |
432 int readSize; | |
433 | |
434 int numberRecs; | |
435 unsigned char *recPtr; | |
436 int offset; | |
437 int size; | |
438 | |
439 int type; | |
440 int nybbleType; | |
441 | |
442 int counter; | |
443 | |
444 int aid; | |
445 demux_stream_t *ds = NULL; | |
446 | |
447 int esOffset1; | |
448 int esOffset2; | |
449 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
450 unsigned char lastCC[ 16 ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
451 unsigned char lastXDS[ 16 ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
452 |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
453 TiVoInfo *tivo = demux->priv; |
10263 | 454 |
455 if ( demux->stream->type == STREAMTYPE_DVD ) | |
24446 | 456 return 0; |
10263 | 457 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
458 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty processing\n" ); |
10263 | 459 |
460 if( demux->stream->eof ) return 0; | |
461 | |
462 // ====================================================================== | |
11000 | 463 // If we haven't figured out the size of the stream, let's do so |
10263 | 464 // ====================================================================== |
465 #ifdef STREAMTYPE_STREAM_TY | |
466 if ( demux->stream->type == STREAMTYPE_STREAM_TY ) | |
467 { | |
468 // The vstream code figures out the exact size of the stream | |
469 demux->movi_start = 0; | |
470 demux->movi_end = vstream_streamsize(); | |
471 tivo->size = vstream_streamsize(); | |
472 } | |
473 else | |
474 #endif | |
475 { | |
476 // If its a local file, try to find the Part Headers, so we can | |
477 // calculate the ACTUAL stream size | |
478 // If we can't find it, go off with the file size and hope the | |
479 // extract program did the "right thing" | |
480 if ( tivo->readHeader == 0 ) | |
481 { | |
482 tivo->readHeader = 1; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
483 tivo->size = demux->stream->end_pos; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
484 |
10263 | 485 filePos = demux->filepos; |
486 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
|
487 |
10263 | 488 // mp_msg( MSGT_DEMUX, MSGL_DBG3, |
489 // "ty:Reading a chunk %d\n", __LINE__ ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
490 |
10263 | 491 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
|
492 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
493 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
|
494 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
495 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
|
496 tivo->tmf = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
497 ty_tmf_filetoparts( demux, tivo ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
498 readSize = tmf_load_chunk( demux, tivo, chunk, CHUNKSIZE, 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
499 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
500 |
24467 | 501 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID ) |
10263 | 502 { |
503 off_t numberParts; | |
504 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
505 readSize = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
506 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
507 if ( tivo->tmf != 1 ) |
10263 | 508 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
509 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
510 |
10263 | 511 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
|
512 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
513 |
17366 | 514 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n", |
515 (int64_t)numberParts ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
516 |
24446 | 517 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
|
518 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
519 stream_seek( demux->stream, offset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
520 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
|
521 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
522 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
523 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
524 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
525 numberParts = tivo->tmf_totalparts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
526 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
527 readSize = tmf_load_chunk( demux, tivo, chunk, CHUNKSIZE, |
24446 | 528 numberParts * ( TIVO_PART_LENGTH - CHUNKSIZE ) / |
529 CHUNKSIZE ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
530 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
531 |
24467 | 532 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
|
533 { |
24466 | 534 size = AV_RB24(chunk + 12); |
10263 | 535 size -= 4; |
536 size *= CHUNKSIZE; | |
537 tivo->size = numberParts * TIVO_PART_LENGTH; | |
538 tivo->size += size; | |
539 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
540 "ty:Header Calc Stream Size %"PRId64"\n", tivo->size ); |
10263 | 541 } |
542 } | |
543 if ( tivo->size > demux->stream->end_pos ) | |
544 tivo->size = demux->stream->end_pos; | |
545 | |
546 if ( demux->stream->start_pos > 0 ) | |
547 filePos = demux->stream->start_pos; | |
548 stream_seek( demux->stream, filePos ); | |
549 demux->filepos = stream_tell( demux->stream ); | |
24446 | 550 tivo->whichChunk = filePos / CHUNKSIZE; |
10263 | 551 } |
552 demux->movi_start = 0; | |
553 demux->movi_end = tivo->size; | |
554 } | |
555 | |
556 // ====================================================================== | |
557 // Give a clue as to where we are in the stream | |
558 // ====================================================================== | |
559 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
17366 | 560 "ty:ty header size %"PRIx64"\n", (int64_t)tivo->size ); |
10263 | 561 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 562 "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
|
563 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 564 "ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos ); |
10263 | 565 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 566 "\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) ); |
10263 | 567 |
24464 | 568 if ( tivo->size > 0 && stream_tell( demux->stream ) > tivo->size ) |
10263 | 569 { |
570 demux->stream->eof = 1; | |
24464 | 571 return 0; |
10263 | 572 } |
573 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
574 if ( tivo->tmf != 1 ) |
10263 | 575 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
576 // Make sure we are on a 128k boundary |
24446 | 577 if ( demux->filepos % CHUNKSIZE != 0 ) |
10263 | 578 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
579 whichChunk = demux->filepos / CHUNKSIZE; |
24446 | 580 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
|
581 whichChunk++; |
24446 | 582 stream_seek( demux->stream, whichChunk * CHUNKSIZE ); |
10263 | 583 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
584 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
585 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
|
586 tivo->whichChunk = demux->filepos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
587 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
|
588 if ( readSize != CHUNKSIZE ) |
24464 | 589 return 0; |
10263 | 590 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
591 else |
10263 | 592 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
593 readSize = tmf_load_chunk( demux, tivo, chunk, CHUNKSIZE, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
594 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
595 if ( readSize != CHUNKSIZE ) |
24446 | 596 return 0; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
597 tivo->whichChunk++; |
10263 | 598 } |
599 | |
600 // We found a part header, skip it | |
24467 | 601 if( AV_RB32(chunk) == TIVO_PES_FILEID ) |
10263 | 602 { |
603 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Skipping PART Header\n" ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
604 if ( tivo->tmf != 1 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
605 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
606 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
|
607 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
|
608 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
609 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
610 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
611 readSize = tmf_load_chunk( demux, tivo, chunk, CHUNKSIZE, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
612 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
613 tivo->whichChunk++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
614 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
615 |
10263 | 616 if ( readSize != CHUNKSIZE ) |
24446 | 617 return 0; |
10263 | 618 } |
619 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
24446 | 620 "\nty:actual current offset %"PRIx64"\n", stream_tell( demux->stream ) - |
621 CHUNKSIZE ); | |
10263 | 622 |
623 | |
12860 | 624 // Let's make a Video Demux Stream for MPlayer |
10263 | 625 aid = 0x0; |
626 if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid ); | |
627 if( demux->video->id == -1 ) demux->video->id = aid; | |
628 if( demux->video->id == aid ) | |
629 { | |
630 ds = demux->video; | |
631 if( !ds->sh ) ds->sh = demux->v_streams[ aid ]; | |
632 } | |
633 | |
634 // ====================================================================== | |
635 // Finally, we get to actually parse the chunk | |
636 // ====================================================================== | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
637 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" ); |
10263 | 638 numberRecs = chunk[ 0 ]; |
639 recPtr = &chunk[ 4 ]; | |
24446 | 640 offset = numberRecs * 16 + 4; |
10263 | 641 for ( counter = 0 ; counter < numberRecs ; counter++ ) |
642 { | |
24468 | 643 size = AV_RB24(recPtr) >> 4; |
10263 | 644 type = recPtr[ 3 ]; |
645 nybbleType = recPtr[ 2 ] & 0x0f; | |
646 recordsDecoded++; | |
647 | |
648 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
649 "ty:Record Type %x/%x %d\n", nybbleType, type, size ); | |
650 | |
651 // ================================================================ | |
652 // Video Parsing | |
653 // ================================================================ | |
654 if ( type == 0xe0 ) | |
655 { | |
24446 | 656 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 657 { |
658 #if 0 | |
659 printf( "Video Chunk Header " ); | |
660 for( count = 0 ; count < 24 ; count++ ) | |
661 { | |
662 printf( "%2.2x ", chunk[ offset + count ] ); | |
663 } | |
664 printf( "\n" ); | |
665 #endif | |
666 demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ], | |
667 size, &esOffset1 ); | |
668 if ( esOffset1 != -1 ) | |
669 tivo->lastVideoPTS = get_ty_pts( | |
670 &chunk[ offset + esOffset1 + 9 ] ); | |
671 | |
672 // Do NOT Pass the PES Header onto the MPEG2 Decode | |
673 if( nybbleType != 0x06 ) | |
674 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, | |
24446 | 675 &chunk[ offset ], size, demux->filepos + offset, |
10263 | 676 tivo->lastVideoPTS ); |
677 offset += size; | |
678 } | |
679 else | |
680 errorHeader++; | |
681 } | |
682 // ================================================================ | |
683 // Audio Parsing | |
684 // ================================================================ | |
685 else if ( type == 0xc0 ) | |
686 { | |
24446 | 687 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 688 { |
689 #if 0 | |
690 printf( "Audio Chunk Header " ); | |
691 for( count = 0 ; count < 24 ; count++ ) | |
692 { | |
693 printf( "%2.2x ", chunk[ offset + count ] ); | |
694 } | |
695 printf( "\n" ); | |
696 #endif | |
697 | |
698 if( demux->audio->id == -1 ) | |
699 { | |
700 if ( nybbleType == 0x02 ) | |
701 continue; // DTiVo inconclusive, wait for more | |
702 else if ( nybbleType == 0x09 ) | |
703 { | |
704 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" ); | |
705 aid = 0x80; // AC-3 | |
706 } | |
707 else | |
708 { | |
709 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" ); | |
710 aid = 0x0; // MPEG Audio | |
711 } | |
712 | |
713 demux->audio->id = aid; | |
714 if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid ); | |
715 if( demux->audio->id == aid ) | |
716 { | |
717 ds = demux->audio; | |
15580 | 718 if( !ds->sh ) { |
719 sh_audio_t* sh_a; | |
720 ds->sh = demux->a_streams[ aid ]; | |
721 sh_a = (sh_audio_t*)ds->sh; | |
722 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id) | |
723 case 0x00: sh_a->format=0x50;break; // mpeg | |
724 case 0xA0: sh_a->format=0x10001;break; // dvd pcm | |
725 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts | |
726 else sh_a->format=0x2000;break; // ac3 | |
727 } | |
728 } | |
10263 | 729 } |
730 } | |
731 | |
732 aid = demux->audio->id; | |
733 | |
734 | |
735 // SA DTiVo Audio Data, no PES | |
736 // ================================================ | |
737 if ( nybbleType == 0x02 ) | |
738 { | |
739 if ( tivo->tivoType == 2 ) | |
740 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
741 else | |
742 { | |
743 | |
744 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
745 "ty:Adding Audio Packet Size %d\n", size ); | |
746 demux_ty_CopyToDemuxPacket( TY_A, tivo, demux->audio, | |
747 &chunk[ offset ], size, ( demux->filepos + offset ), | |
748 tivo->lastAudioPTS ); | |
749 } | |
750 } | |
751 | |
752 // MPEG Audio with PES Header, either SA or DTiVo | |
753 // ================================================ | |
754 if ( nybbleType == 0x03 ) | |
755 { | |
756 demux_ty_FindESHeader( ty_MPEGAudioPacket, 4, &chunk[ offset ], | |
757 size, &esOffset1 ); | |
758 | |
759 // SA PES Header, No Audio Data | |
760 // ================================================ | |
24446 | 761 if ( esOffset1 == 0 && size == 16 ) |
10263 | 762 { |
763 tivo->tivoType = 1; | |
764 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + | |
765 SERIES2_PTS_OFFSET ] ); | |
766 } | |
767 else | |
768 // DTiVo Audio with PES Header | |
769 // ================================================ | |
770 { | |
771 tivo->tivoType = 2; | |
772 | |
773 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
774 demux_ty_FindESPacket( ty_MPEGAudioPacket, 4, | |
775 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, | |
776 &esOffset2 ); | |
777 | |
24446 | 778 if ( esOffset1 != -1 && esOffset2 != -1 ) |
10263 | 779 { |
780 int packetSize = esOffset2 - esOffset1; | |
781 int headerSize; | |
782 int ptsOffset; | |
783 | |
784 if ( IsValidAudioPacket( packetSize, &ptsOffset, | |
785 &headerSize ) ) | |
786 { | |
787 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
788 "ty:Adding DTiVo Audio Packet Size %d\n", | |
789 packetSize ); | |
790 | |
791 tivo->lastAudioPTS = get_ty_pts( | |
792 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); | |
793 | |
794 demux_ty_CopyToDemuxPacket | |
795 ( | |
796 TY_A, | |
797 tivo, | |
798 demux->audio, | |
799 &( tivo->lastAudio[ esOffset1 + headerSize ] ), | |
800 ( packetSize - headerSize ), | |
801 ( demux->filepos + offset ), | |
802 tivo->lastAudioPTS | |
803 ); | |
804 | |
805 } | |
806 | |
807 // Collapse the Audio Buffer | |
24446 | 808 memmove( &tivo->lastAudio[ 0 ], |
809 &tivo->lastAudio[ esOffset2 ], | |
810 tivo->lastAudioEnd - esOffset2 ); | |
10263 | 811 tivo->lastAudioEnd -= esOffset2; |
812 } | |
813 } | |
814 } | |
815 | |
816 // SA Audio with no PES Header | |
817 // ================================================ | |
818 if ( nybbleType == 0x04 ) | |
819 { | |
820 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
821 "ty:Adding Audio Packet Size %d\n", size ); | |
822 demux_ty_CopyToDemuxPacket( TY_A, tivo, demux->audio, | |
823 &chunk[ offset ], size, ( demux->filepos + offset ), | |
824 tivo->lastAudioPTS ); | |
825 } | |
826 | |
827 // DTiVo AC3 Audio Data with PES Header | |
828 // ================================================ | |
829 if ( nybbleType == 0x09 ) | |
830 { | |
831 tivo->tivoType = 2; | |
832 | |
833 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
834 demux_ty_FindESPacket( ty_AC3AudioPacket, 4, | |
835 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, | |
836 &esOffset2 ); | |
837 | |
24446 | 838 if ( esOffset1 != -1 && esOffset2 != -1 ) |
10263 | 839 { |
840 int packetSize = esOffset2 - esOffset1; | |
841 int headerSize; | |
842 int ptsOffset; | |
843 | |
844 if ( IsValidAudioPacket( packetSize, &ptsOffset, | |
845 &headerSize ) ) | |
846 { | |
847 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
848 "ty:Adding DTiVo Audio Packet Size %d\n", | |
849 packetSize ); | |
850 | |
851 tivo->lastAudioPTS = get_ty_pts( | |
852 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); | |
853 | |
854 // AC3 Decoder WANTS the PTS | |
855 demux_ty_CopyToDemuxPacket | |
856 ( | |
857 TY_A, | |
858 tivo, | |
859 demux->audio, | |
24446 | 860 &tivo->lastAudio[ esOffset1 ], |
861 packetSize, | |
862 demux->filepos + offset, | |
10263 | 863 tivo->lastAudioPTS |
864 ); | |
865 | |
866 } | |
867 | |
868 // Collapse the Audio Buffer | |
24446 | 869 memmove( &tivo->lastAudio[ 0 ], |
870 &tivo->lastAudio[ esOffset2 ], | |
871 tivo->lastAudioEnd - esOffset2 ); | |
10263 | 872 tivo->lastAudioEnd -= esOffset2; |
873 } | |
874 } | |
875 offset += size; | |
876 } | |
877 else | |
878 errorHeader++; | |
879 } | |
880 // ================================================================ | |
881 // Closed Caption | |
882 // ================================================================ | |
883 else if ( type == 0x01 ) | |
884 { | |
885 unsigned char b1; | |
886 unsigned char b2; | |
887 | |
888 b1 = ( ( ( recPtr[ 0 ] & 0x0f ) << 4 ) | | |
889 ( ( recPtr[ 1 ] & 0xf0 ) >> 4 ) ); | |
890 b1 &= 0x7f; | |
891 b2 = ( ( ( recPtr[ 1 ] & 0x0f ) << 4 ) | | |
892 ( ( recPtr[ 2 ] & 0xf0 ) >> 4 ) ); | |
893 b2 &= 0x7f; | |
894 | |
895 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:CC %x %x\n", b1, b2 ); | |
896 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
897 lastCC[ 0x00 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
898 lastCC[ 0x01 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
899 lastCC[ 0x02 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
900 lastCC[ 0x03 ] = 0xb2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
901 lastCC[ 0x04 ] = 'T'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
902 lastCC[ 0x05 ] = 'Y'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
903 lastCC[ 0x06 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
904 lastCC[ 0x07 ] = b1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
905 lastCC[ 0x08 ] = b2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
906 if ( subcc_enabled ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
907 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, lastCC, 0x09, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
908 ( demux->filepos + offset ), tivo->lastVideoPTS ); |
10263 | 909 } |
910 // ================================================================ | |
911 // Extended Data Services | |
912 // ================================================================ | |
913 else if ( type == 0x02 ) | |
914 { | |
24473 | 915 int b = AV_RB24(recPtr) >> 4; |
916 b &= 0x7f7f; | |
10263 | 917 |
24473 | 918 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:XDS %04x\n", b); |
10263 | 919 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
920 lastXDS[ 0x00 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
921 lastXDS[ 0x01 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
922 lastXDS[ 0x02 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
923 lastXDS[ 0x03 ] = 0xb2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
924 lastXDS[ 0x04 ] = 'T'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
925 lastXDS[ 0x05 ] = 'Y'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
926 lastXDS[ 0x06 ] = 0x02; |
24473 | 927 lastXDS[ 0x07 ] = b >> 8; |
928 lastXDS[ 0x08 ] = b; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
929 if ( subcc_enabled ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
930 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, lastXDS, 0x09, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
931 ( demux->filepos + offset ), tivo->lastVideoPTS ); |
10263 | 932 } |
933 // ================================================================ | |
934 // Unknown | |
935 // ================================================================ | |
936 else | |
937 { | |
24446 | 938 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 939 offset += size; |
24472 | 940 if (type != 3 && type != 5) { |
10263 | 941 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type ); |
942 invalidType++; | |
24472 | 943 } |
10263 | 944 } |
945 recPtr += 16; | |
946 } | |
947 | |
20141
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
948 if ( errorHeader > 0 || invalidType > 0 ) |
10263 | 949 { |
950 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
|
951 "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
|
952 numberRecs, recordsDecoded, errorHeader, invalidType ); |
10263 | 953 |
954 // Invalid MPEG ES Size Check | |
24446 | 955 if ( errorHeader > numberRecs / 2 ) |
956 return 0; | |
10263 | 957 |
958 // Invalid MPEG Stream Type Check | |
24446 | 959 if ( invalidType > numberRecs / 2 ) |
960 return 0; | |
10263 | 961 } |
962 | |
963 demux->filepos = stream_tell( demux->stream ); | |
964 | |
24446 | 965 return 1; |
10263 | 966 } |
967 | |
17636 | 968 static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) |
10263 | 969 { |
970 demux_stream_t *d_audio = demuxer->audio; | |
971 demux_stream_t *d_video = demuxer->video; | |
972 sh_audio_t *sh_audio = d_audio->sh; | |
973 sh_video_t *sh_video = d_video->sh; | |
974 off_t newpos; | |
975 off_t res; | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
976 TiVoInfo *tivo = demuxer->priv; |
10263 | 977 |
978 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Seeking to %7.1f\n", rel_seek_secs ); | |
979 | |
980 tivo->lastAudioEnd = 0; | |
24463 | 981 tivo->lastAudioPTS = MP_NOPTS_VALUE; |
982 tivo->lastVideoPTS = MP_NOPTS_VALUE; | |
10263 | 983 // |
984 //================= seek in MPEG ========================== | |
985 demuxer->filepos = stream_tell( demuxer->stream ); | |
986 | |
987 newpos = ( flags & 1 ) ? demuxer->movi_start : demuxer->filepos; | |
988 | |
989 if( flags & 2 ) | |
990 // float seek 0..1 | |
991 newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs; | |
992 else | |
993 { | |
994 // time seek (secs) | |
995 if( ! sh_video->i_bps ) // unspecified or VBR | |
996 newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec | |
997 else | |
998 newpos += sh_video->i_bps * rel_seek_secs; | |
999 } | |
1000 | |
1001 if ( newpos < demuxer->movi_start ) | |
1002 { | |
1003 if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0; | |
1004 if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start; | |
1005 } | |
1006 | |
1007 res = newpos / CHUNKSIZE; | |
1008 if ( rel_seek_secs >= 0 ) | |
1009 newpos = ( res + 1 ) * CHUNKSIZE; | |
1010 else | |
1011 newpos = res * CHUNKSIZE; | |
1012 | |
1013 if ( newpos < 0 ) | |
1014 newpos = 0; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1015 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1016 tivo->whichChunk = newpos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1017 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1018 stream_seek( demuxer->stream, newpos ); |
10263 | 1019 |
1020 // re-sync video: | |
1021 videobuf_code_len = 0; // reset ES stream buffer | |
1022 | |
1023 ds_fill_buffer( d_video ); | |
1024 if( sh_audio ) | |
1025 ds_fill_buffer( d_audio ); | |
1026 | |
1027 while( 1 ) | |
1028 { | |
1029 int i; | |
1030 if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts ) | |
1031 { | |
1032 float a_pts = d_audio->pts; | |
1033 a_pts += ( ds_tell_pts( d_audio ) - sh_audio->a_in_buffer_len ) / | |
1034 (float)sh_audio->i_bps; | |
1035 if( d_video->pts > a_pts ) | |
1036 { | |
1037 skip_audio_frame( sh_audio ); // sync audio | |
1038 continue; | |
1039 } | |
1040 } | |
1041 i = sync_video_packet( d_video ); | |
1042 if( i == 0x1B3 || i == 0x1B8 ) break; // found it! | |
1043 if( !i || !skip_video_packet( d_video ) ) break; // EOF? | |
1044 } | |
1045 if ( subcc_enabled ) | |
1046 ty_ClearOSD( 0 ); | |
1047 } | |
1048 | |
24443 | 1049 static int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg ) |
10263 | 1050 { |
1051 demux_stream_t *d_video = demuxer->video; | |
1052 sh_video_t *sh_video = d_video->sh; | |
1053 | |
1054 switch(cmd) | |
1055 { | |
1056 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
1057 if(!sh_video->i_bps) // unspecified or VBR | |
1058 return DEMUXER_CTRL_DONTKNOW; | |
24446 | 1059 *(double *)arg= |
1060 (double)demuxer->movi_end-demuxer->movi_start/sh_video->i_bps; | |
10263 | 1061 return DEMUXER_CTRL_GUESS; |
1062 | |
1063 case DEMUXER_CTRL_GET_PERCENT_POS: | |
1064 return DEMUXER_CTRL_DONTKNOW; | |
1065 default: | |
1066 return DEMUXER_CTRL_NOTIMPL; | |
1067 } | |
1068 } | |
1069 | |
1070 | |
17174
83a8c738be89
make demuxer seek and close functions return void, patch by Dominik Mierzejewski
wanderer
parents:
17012
diff
changeset
|
1071 static void demux_close_ty( demuxer_t *demux ) |
10263 | 1072 { |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
1073 TiVoInfo *tivo = demux->priv; |
10263 | 1074 |
1075 free( tivo ); | |
1076 sub_justify = 0; | |
1077 } | |
1078 | |
1079 | |
16175 | 1080 static int ty_check_file(demuxer_t* demuxer) |
1081 { | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
1082 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
|
1083 tivo->firstAudioPTS = MP_NOPTS_VALUE; |
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
1084 tivo->firstVideoPTS = MP_NOPTS_VALUE; |
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
1085 demuxer->priv = tivo; |
16175 | 1086 return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0; |
1087 } | |
1088 | |
1089 | |
1090 static demuxer_t* demux_open_ty(demuxer_t* demuxer) | |
1091 { | |
1092 sh_audio_t *sh_audio=NULL; | |
1093 sh_video_t *sh_video=NULL; | |
1094 | |
1095 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1096 | |
1097 if(demuxer->audio->id!=-2) { | |
1098 if(!ds_fill_buffer(demuxer->audio)){ | |
1099 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
1100 demuxer->audio->sh=NULL; | |
1101 } else { | |
1102 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
1103 } | |
1104 } | |
1105 | |
1106 return demuxer; | |
1107 } | |
1108 | |
1109 | |
1110 demuxer_desc_t demuxer_desc_mpeg_ty = { | |
1111 "TiVo demuxer", | |
1112 "tivo", | |
1113 "TiVo", | |
1114 "Christopher R. Wingert", | |
1115 "Demux streams from TiVo", | |
1116 DEMUXER_TYPE_MPEG_TY, | |
1117 0, // unsafe autodetect | |
1118 ty_check_file, | |
1119 demux_ty_fill_buffer, | |
1120 demux_open_ty, | |
1121 demux_close_ty, | |
1122 demux_seek_ty, | |
1123 demux_ty_control | |
1124 }; |