Mercurial > mplayer.hg
annotate libmpdemux/demux_ty.c @ 24477:8c9d86adb28e
Move variable declarations into the block where they are used
author | reimar |
---|---|
date | Fri, 14 Sep 2007 19:46:54 +0000 |
parents | b42dd327f81f |
children | 43c9c72b8c54 |
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 | |
429 unsigned char chunk[ CHUNKSIZE ]; | |
430 int readSize; | |
431 | |
432 int numberRecs; | |
433 unsigned char *recPtr; | |
434 int offset; | |
435 | |
436 int counter; | |
437 | |
438 int aid; | |
439 | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
440 TiVoInfo *tivo = demux->priv; |
10263 | 441 |
442 if ( demux->stream->type == STREAMTYPE_DVD ) | |
24446 | 443 return 0; |
10263 | 444 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
445 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty processing\n" ); |
10263 | 446 |
447 if( demux->stream->eof ) return 0; | |
448 | |
449 // ====================================================================== | |
11000 | 450 // If we haven't figured out the size of the stream, let's do so |
10263 | 451 // ====================================================================== |
452 #ifdef STREAMTYPE_STREAM_TY | |
453 if ( demux->stream->type == STREAMTYPE_STREAM_TY ) | |
454 { | |
455 // The vstream code figures out the exact size of the stream | |
456 demux->movi_start = 0; | |
457 demux->movi_end = vstream_streamsize(); | |
458 tivo->size = vstream_streamsize(); | |
459 } | |
460 else | |
461 #endif | |
462 { | |
463 // If its a local file, try to find the Part Headers, so we can | |
464 // calculate the ACTUAL stream size | |
465 // If we can't find it, go off with the file size and hope the | |
466 // extract program did the "right thing" | |
467 if ( tivo->readHeader == 0 ) | |
468 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
469 off_t filePos; |
10263 | 470 tivo->readHeader = 1; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
471 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
|
472 |
10263 | 473 filePos = demux->filepos; |
474 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
|
475 |
10263 | 476 // mp_msg( MSGT_DEMUX, MSGL_DBG3, |
477 // "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
|
478 |
10263 | 479 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
|
480 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
481 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
|
482 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
483 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
|
484 tivo->tmf = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
485 ty_tmf_filetoparts( demux, tivo ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
486 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
|
487 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
488 |
24467 | 489 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID ) |
10263 | 490 { |
491 off_t numberParts; | |
492 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
493 readSize = 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 if ( tivo->tmf != 1 ) |
10263 | 496 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
497 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
498 |
10263 | 499 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
|
500 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
501 |
17366 | 502 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n", |
503 (int64_t)numberParts ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
504 |
24446 | 505 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
|
506 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
507 stream_seek( demux->stream, offset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
508 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
|
509 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
510 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
511 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
512 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
513 numberParts = tivo->tmf_totalparts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
514 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
515 readSize = tmf_load_chunk( demux, tivo, chunk, CHUNKSIZE, |
24446 | 516 numberParts * ( TIVO_PART_LENGTH - CHUNKSIZE ) / |
517 CHUNKSIZE ); | |
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 |
24467 | 520 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
|
521 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
522 int size = AV_RB24(chunk + 12); |
10263 | 523 size -= 4; |
524 size *= CHUNKSIZE; | |
525 tivo->size = numberParts * TIVO_PART_LENGTH; | |
526 tivo->size += size; | |
527 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
528 "ty:Header Calc Stream Size %"PRId64"\n", tivo->size ); |
10263 | 529 } |
530 } | |
531 if ( tivo->size > demux->stream->end_pos ) | |
532 tivo->size = demux->stream->end_pos; | |
533 | |
534 if ( demux->stream->start_pos > 0 ) | |
535 filePos = demux->stream->start_pos; | |
536 stream_seek( demux->stream, filePos ); | |
537 demux->filepos = stream_tell( demux->stream ); | |
24446 | 538 tivo->whichChunk = filePos / CHUNKSIZE; |
10263 | 539 } |
540 demux->movi_start = 0; | |
541 demux->movi_end = tivo->size; | |
542 } | |
543 | |
544 // ====================================================================== | |
545 // Give a clue as to where we are in the stream | |
546 // ====================================================================== | |
547 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
17366 | 548 "ty:ty header size %"PRIx64"\n", (int64_t)tivo->size ); |
10263 | 549 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 550 "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
|
551 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 552 "ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos ); |
10263 | 553 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 554 "\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) ); |
10263 | 555 |
24464 | 556 if ( tivo->size > 0 && stream_tell( demux->stream ) > tivo->size ) |
10263 | 557 { |
558 demux->stream->eof = 1; | |
24464 | 559 return 0; |
10263 | 560 } |
561 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
562 if ( tivo->tmf != 1 ) |
10263 | 563 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
564 // Make sure we are on a 128k boundary |
24446 | 565 if ( demux->filepos % CHUNKSIZE != 0 ) |
10263 | 566 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
567 int whichChunk = demux->filepos / CHUNKSIZE; |
24446 | 568 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
|
569 whichChunk++; |
24446 | 570 stream_seek( demux->stream, whichChunk * CHUNKSIZE ); |
10263 | 571 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
572 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
573 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
|
574 tivo->whichChunk = demux->filepos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
575 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
|
576 if ( readSize != CHUNKSIZE ) |
24464 | 577 return 0; |
10263 | 578 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
579 else |
10263 | 580 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
581 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
|
582 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
583 if ( readSize != CHUNKSIZE ) |
24446 | 584 return 0; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
585 tivo->whichChunk++; |
10263 | 586 } |
587 | |
588 // We found a part header, skip it | |
24467 | 589 if( AV_RB32(chunk) == TIVO_PES_FILEID ) |
10263 | 590 { |
591 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
|
592 if ( tivo->tmf != 1 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
593 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
594 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
|
595 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
|
596 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
597 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
598 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
599 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
|
600 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
601 tivo->whichChunk++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
602 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
603 |
10263 | 604 if ( readSize != CHUNKSIZE ) |
24446 | 605 return 0; |
10263 | 606 } |
607 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
24446 | 608 "\nty:actual current offset %"PRIx64"\n", stream_tell( demux->stream ) - |
609 CHUNKSIZE ); | |
10263 | 610 |
611 | |
12860 | 612 // Let's make a Video Demux Stream for MPlayer |
10263 | 613 aid = 0x0; |
614 if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid ); | |
615 if( demux->video->id == -1 ) demux->video->id = aid; | |
616 if( demux->video->id == aid ) | |
617 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
618 demux_stream_t *ds = demux->video; |
10263 | 619 if( !ds->sh ) ds->sh = demux->v_streams[ aid ]; |
620 } | |
621 | |
622 // ====================================================================== | |
623 // Finally, we get to actually parse the chunk | |
624 // ====================================================================== | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
625 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" ); |
10263 | 626 numberRecs = chunk[ 0 ]; |
627 recPtr = &chunk[ 4 ]; | |
24446 | 628 offset = numberRecs * 16 + 4; |
10263 | 629 for ( counter = 0 ; counter < numberRecs ; counter++ ) |
630 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
631 int size = AV_RB24(recPtr) >> 4; |
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
632 int type = recPtr[ 3 ]; |
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
633 int nybbleType = recPtr[ 2 ] & 0x0f; |
10263 | 634 recordsDecoded++; |
635 | |
636 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
637 "ty:Record Type %x/%x %d\n", nybbleType, type, size ); | |
638 | |
639 // ================================================================ | |
640 // Video Parsing | |
641 // ================================================================ | |
642 if ( type == 0xe0 ) | |
643 { | |
24446 | 644 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 645 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
646 int esOffset1; |
10263 | 647 #if 0 |
648 printf( "Video Chunk Header " ); | |
649 for( count = 0 ; count < 24 ; count++ ) | |
650 { | |
651 printf( "%2.2x ", chunk[ offset + count ] ); | |
652 } | |
653 printf( "\n" ); | |
654 #endif | |
655 demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ], | |
656 size, &esOffset1 ); | |
657 if ( esOffset1 != -1 ) | |
658 tivo->lastVideoPTS = get_ty_pts( | |
659 &chunk[ offset + esOffset1 + 9 ] ); | |
660 | |
661 // Do NOT Pass the PES Header onto the MPEG2 Decode | |
662 if( nybbleType != 0x06 ) | |
663 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, | |
24446 | 664 &chunk[ offset ], size, demux->filepos + offset, |
10263 | 665 tivo->lastVideoPTS ); |
666 offset += size; | |
667 } | |
668 else | |
669 errorHeader++; | |
670 } | |
671 // ================================================================ | |
672 // Audio Parsing | |
673 // ================================================================ | |
674 else if ( type == 0xc0 ) | |
675 { | |
24446 | 676 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 677 { |
678 #if 0 | |
679 printf( "Audio Chunk Header " ); | |
680 for( count = 0 ; count < 24 ; count++ ) | |
681 { | |
682 printf( "%2.2x ", chunk[ offset + count ] ); | |
683 } | |
684 printf( "\n" ); | |
685 #endif | |
686 | |
687 if( demux->audio->id == -1 ) | |
688 { | |
689 if ( nybbleType == 0x02 ) | |
690 continue; // DTiVo inconclusive, wait for more | |
691 else if ( nybbleType == 0x09 ) | |
692 { | |
693 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" ); | |
694 aid = 0x80; // AC-3 | |
695 } | |
696 else | |
697 { | |
698 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" ); | |
699 aid = 0x0; // MPEG Audio | |
700 } | |
701 | |
702 demux->audio->id = aid; | |
703 if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid ); | |
704 if( demux->audio->id == aid ) | |
705 { | |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
706 demux_stream_t *ds = demux->audio; |
15580 | 707 if( !ds->sh ) { |
708 sh_audio_t* sh_a; | |
709 ds->sh = demux->a_streams[ aid ]; | |
710 sh_a = (sh_audio_t*)ds->sh; | |
711 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id) | |
712 case 0x00: sh_a->format=0x50;break; // mpeg | |
713 case 0xA0: sh_a->format=0x10001;break; // dvd pcm | |
714 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts | |
715 else sh_a->format=0x2000;break; // ac3 | |
716 } | |
717 } | |
10263 | 718 } |
719 } | |
720 | |
721 aid = demux->audio->id; | |
722 | |
723 | |
724 // SA DTiVo Audio Data, no PES | |
725 // ================================================ | |
24476 | 726 if ( nybbleType == 0x02 || nybbleType == 0x04 ) |
10263 | 727 { |
24476 | 728 if ( nybbleType == 0x02 && tivo->tivoType == 2 ) |
10263 | 729 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); |
730 else | |
731 { | |
732 | |
733 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
734 "ty:Adding Audio Packet Size %d\n", size ); | |
735 demux_ty_CopyToDemuxPacket( TY_A, tivo, demux->audio, | |
736 &chunk[ offset ], size, ( demux->filepos + offset ), | |
737 tivo->lastAudioPTS ); | |
738 } | |
739 } | |
740 | |
24475 | 741 // 3 - MPEG Audio with PES Header, either SA or DTiVo |
742 // 9 - DTiVo AC3 Audio Data with PES Header | |
10263 | 743 // ================================================ |
24475 | 744 if ( nybbleType == 0x03 || nybbleType == 0x09 ) |
10263 | 745 { |
24477
8c9d86adb28e
Move variable declarations into the block where they are used
reimar
parents:
24476
diff
changeset
|
746 int esOffset1, esOffset2; |
24475 | 747 if ( nybbleType == 0x03 ) |
10263 | 748 demux_ty_FindESHeader( ty_MPEGAudioPacket, 4, &chunk[ offset ], |
749 size, &esOffset1 ); | |
750 | |
751 // SA PES Header, No Audio Data | |
752 // ================================================ | |
24475 | 753 if ( nybbleType == 0x03 && esOffset1 == 0 && size == 16 ) |
10263 | 754 { |
755 tivo->tivoType = 1; | |
756 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + | |
757 SERIES2_PTS_OFFSET ] ); | |
758 } | |
759 else | |
760 // DTiVo Audio with PES Header | |
761 // ================================================ | |
762 { | |
763 tivo->tivoType = 2; | |
764 | |
765 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
24475 | 766 demux_ty_FindESPacket( nybbleType == 9 ? ty_AC3AudioPacket : ty_MPEGAudioPacket, 4, |
10263 | 767 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, |
768 &esOffset2 ); | |
769 | |
24446 | 770 if ( esOffset1 != -1 && esOffset2 != -1 ) |
10263 | 771 { |
772 int packetSize = esOffset2 - esOffset1; | |
773 int headerSize; | |
774 int ptsOffset; | |
775 | |
776 if ( IsValidAudioPacket( packetSize, &ptsOffset, | |
777 &headerSize ) ) | |
778 { | |
779 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
780 "ty:Adding DTiVo Audio Packet Size %d\n", | |
781 packetSize ); | |
782 | |
783 tivo->lastAudioPTS = get_ty_pts( | |
784 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); | |
785 | |
24475 | 786 if (nybbleType == 9) headerSize = 0; |
10263 | 787 demux_ty_CopyToDemuxPacket |
788 ( | |
789 TY_A, | |
790 tivo, | |
791 demux->audio, | |
792 &( tivo->lastAudio[ esOffset1 + headerSize ] ), | |
793 ( packetSize - headerSize ), | |
794 ( demux->filepos + offset ), | |
795 tivo->lastAudioPTS | |
796 ); | |
797 | |
798 } | |
799 | |
800 // Collapse the Audio Buffer | |
24446 | 801 memmove( &tivo->lastAudio[ 0 ], |
802 &tivo->lastAudio[ esOffset2 ], | |
803 tivo->lastAudioEnd - esOffset2 ); | |
10263 | 804 tivo->lastAudioEnd -= esOffset2; |
805 } | |
806 } | |
807 } | |
808 | |
809 offset += size; | |
810 } | |
811 else | |
812 errorHeader++; | |
813 } | |
814 // ================================================================ | |
24474 | 815 // 1 = Closed Caption |
816 // 2 = Extended Data Services | |
10263 | 817 // ================================================================ |
24474 | 818 else if ( type == 0x01 || type == 0x02 ) |
10263 | 819 { |
24474 | 820 unsigned char lastXDS[ 16 ]; |
24473 | 821 int b = AV_RB24(recPtr) >> 4; |
822 b &= 0x7f7f; | |
10263 | 823 |
24474 | 824 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:%s %04x\n", type == 1 ? "CC" : "XDS", b); |
10263 | 825 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
826 lastXDS[ 0x00 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
827 lastXDS[ 0x01 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
828 lastXDS[ 0x02 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
829 lastXDS[ 0x03 ] = 0xb2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
830 lastXDS[ 0x04 ] = 'T'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
831 lastXDS[ 0x05 ] = 'Y'; |
24474 | 832 lastXDS[ 0x06 ] = type; |
24473 | 833 lastXDS[ 0x07 ] = b >> 8; |
834 lastXDS[ 0x08 ] = b; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
835 if ( subcc_enabled ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
836 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
|
837 ( demux->filepos + offset ), tivo->lastVideoPTS ); |
10263 | 838 } |
839 // ================================================================ | |
840 // Unknown | |
841 // ================================================================ | |
842 else | |
843 { | |
24446 | 844 if ( size > 0 && size + offset <= CHUNKSIZE ) |
10263 | 845 offset += size; |
24472 | 846 if (type != 3 && type != 5) { |
10263 | 847 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type ); |
848 invalidType++; | |
24472 | 849 } |
10263 | 850 } |
851 recPtr += 16; | |
852 } | |
853 | |
20141
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
854 if ( errorHeader > 0 || invalidType > 0 ) |
10263 | 855 { |
856 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
|
857 "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
|
858 numberRecs, recordsDecoded, errorHeader, invalidType ); |
10263 | 859 |
860 // Invalid MPEG ES Size Check | |
24446 | 861 if ( errorHeader > numberRecs / 2 ) |
862 return 0; | |
10263 | 863 |
864 // Invalid MPEG Stream Type Check | |
24446 | 865 if ( invalidType > numberRecs / 2 ) |
866 return 0; | |
10263 | 867 } |
868 | |
869 demux->filepos = stream_tell( demux->stream ); | |
870 | |
24446 | 871 return 1; |
10263 | 872 } |
873 | |
17636 | 874 static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) |
10263 | 875 { |
876 demux_stream_t *d_audio = demuxer->audio; | |
877 demux_stream_t *d_video = demuxer->video; | |
878 sh_audio_t *sh_audio = d_audio->sh; | |
879 sh_video_t *sh_video = d_video->sh; | |
880 off_t newpos; | |
881 off_t res; | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
882 TiVoInfo *tivo = demuxer->priv; |
10263 | 883 |
884 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Seeking to %7.1f\n", rel_seek_secs ); | |
885 | |
886 tivo->lastAudioEnd = 0; | |
24463 | 887 tivo->lastAudioPTS = MP_NOPTS_VALUE; |
888 tivo->lastVideoPTS = MP_NOPTS_VALUE; | |
10263 | 889 // |
890 //================= seek in MPEG ========================== | |
891 demuxer->filepos = stream_tell( demuxer->stream ); | |
892 | |
893 newpos = ( flags & 1 ) ? demuxer->movi_start : demuxer->filepos; | |
894 | |
895 if( flags & 2 ) | |
896 // float seek 0..1 | |
897 newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs; | |
898 else | |
899 { | |
900 // time seek (secs) | |
901 if( ! sh_video->i_bps ) // unspecified or VBR | |
902 newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec | |
903 else | |
904 newpos += sh_video->i_bps * rel_seek_secs; | |
905 } | |
906 | |
907 if ( newpos < demuxer->movi_start ) | |
908 { | |
909 if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0; | |
910 if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start; | |
911 } | |
912 | |
913 res = newpos / CHUNKSIZE; | |
914 if ( rel_seek_secs >= 0 ) | |
915 newpos = ( res + 1 ) * CHUNKSIZE; | |
916 else | |
917 newpos = res * CHUNKSIZE; | |
918 | |
919 if ( newpos < 0 ) | |
920 newpos = 0; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
921 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
922 tivo->whichChunk = newpos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
923 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
924 stream_seek( demuxer->stream, newpos ); |
10263 | 925 |
926 // re-sync video: | |
927 videobuf_code_len = 0; // reset ES stream buffer | |
928 | |
929 ds_fill_buffer( d_video ); | |
930 if( sh_audio ) | |
931 ds_fill_buffer( d_audio ); | |
932 | |
933 while( 1 ) | |
934 { | |
935 int i; | |
936 if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts ) | |
937 { | |
938 float a_pts = d_audio->pts; | |
939 a_pts += ( ds_tell_pts( d_audio ) - sh_audio->a_in_buffer_len ) / | |
940 (float)sh_audio->i_bps; | |
941 if( d_video->pts > a_pts ) | |
942 { | |
943 skip_audio_frame( sh_audio ); // sync audio | |
944 continue; | |
945 } | |
946 } | |
947 i = sync_video_packet( d_video ); | |
948 if( i == 0x1B3 || i == 0x1B8 ) break; // found it! | |
949 if( !i || !skip_video_packet( d_video ) ) break; // EOF? | |
950 } | |
951 if ( subcc_enabled ) | |
952 ty_ClearOSD( 0 ); | |
953 } | |
954 | |
24443 | 955 static int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg ) |
10263 | 956 { |
957 demux_stream_t *d_video = demuxer->video; | |
958 sh_video_t *sh_video = d_video->sh; | |
959 | |
960 switch(cmd) | |
961 { | |
962 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
963 if(!sh_video->i_bps) // unspecified or VBR | |
964 return DEMUXER_CTRL_DONTKNOW; | |
24446 | 965 *(double *)arg= |
966 (double)demuxer->movi_end-demuxer->movi_start/sh_video->i_bps; | |
10263 | 967 return DEMUXER_CTRL_GUESS; |
968 | |
969 case DEMUXER_CTRL_GET_PERCENT_POS: | |
970 return DEMUXER_CTRL_DONTKNOW; | |
971 default: | |
972 return DEMUXER_CTRL_NOTIMPL; | |
973 } | |
974 } | |
975 | |
976 | |
17174
83a8c738be89
make demuxer seek and close functions return void, patch by Dominik Mierzejewski
wanderer
parents:
17012
diff
changeset
|
977 static void demux_close_ty( demuxer_t *demux ) |
10263 | 978 { |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
979 TiVoInfo *tivo = demux->priv; |
10263 | 980 |
981 free( tivo ); | |
982 sub_justify = 0; | |
983 } | |
984 | |
985 | |
16175 | 986 static int ty_check_file(demuxer_t* demuxer) |
987 { | |
24469
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
988 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
|
989 tivo->firstAudioPTS = MP_NOPTS_VALUE; |
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
990 tivo->firstVideoPTS = MP_NOPTS_VALUE; |
afbab72dbf2c
Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents:
24468
diff
changeset
|
991 demuxer->priv = tivo; |
16175 | 992 return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0; |
993 } | |
994 | |
995 | |
996 static demuxer_t* demux_open_ty(demuxer_t* demuxer) | |
997 { | |
998 sh_audio_t *sh_audio=NULL; | |
999 sh_video_t *sh_video=NULL; | |
1000 | |
1001 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1002 | |
1003 if(demuxer->audio->id!=-2) { | |
1004 if(!ds_fill_buffer(demuxer->audio)){ | |
1005 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
1006 demuxer->audio->sh=NULL; | |
1007 } else { | |
1008 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
1009 } | |
1010 } | |
1011 | |
1012 return demuxer; | |
1013 } | |
1014 | |
1015 | |
1016 demuxer_desc_t demuxer_desc_mpeg_ty = { | |
1017 "TiVo demuxer", | |
1018 "tivo", | |
1019 "TiVo", | |
1020 "Christopher R. Wingert", | |
1021 "Demux streams from TiVo", | |
1022 DEMUXER_TYPE_MPEG_TY, | |
1023 0, // unsafe autodetect | |
1024 ty_check_file, | |
1025 demux_ty_fill_buffer, | |
1026 demux_open_ty, | |
1027 demux_close_ty, | |
1028 demux_seek_ty, | |
1029 demux_ty_control | |
1030 }; |