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