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