Mercurial > mplayer.hg
annotate libmpdemux/demux_ty.c @ 23648:09f454fc4d79
Remove now unused variable
author | reimar |
---|---|
date | Tue, 26 Jun 2007 15:51:47 +0000 |
parents | 300e9b7c499f |
children | 9fb716ab06a3 |
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" |
10263 | 47 |
48 extern void skip_audio_frame( sh_audio_t *sh_audio ); | |
49 extern int sub_justify; | |
50 | |
51 // 2/c0: audio data | |
52 // 3/c0: audio packet header (PES header) | |
53 // 4/c0: audio data (S/A only?) | |
54 // 9/c0: audio packet header, AC-3 audio | |
55 // 2/e0: video data | |
56 // 6/e0: video packet header (PES header) | |
57 // 7/e0: video sequence header start | |
58 // 8/e0: video I-frame header start | |
59 // a/e0: video P-frame header start | |
60 // b/e0: video B-frame header start | |
61 // c/e0: video GOP header start | |
62 // e/01: closed-caption data | |
63 // e/02: Extended data services data | |
64 | |
65 | |
66 #define TIVO_PES_FILEID ( 0xf5467abd ) | |
67 #define TIVO_PART_LENGTH ( 0x20000000 ) | |
68 | |
69 #define CHUNKSIZE ( 128 * 1024 ) | |
70 #define MAX_AUDIO_BUFFER ( 16 * 1024 ) | |
71 | |
72 #define PTS_MHZ ( 90 ) | |
73 #define PTS_KHZ ( PTS_MHZ * 1000 ) | |
74 | |
75 #define TY_V ( 1 ) | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
76 #define TY_A ( 2 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
77 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
78 typedef struct stmf_fileParts |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
79 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
80 int fileNo; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
81 off_t fileSize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
82 int chunks; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
83 off_t startOffset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
84 } tmf_fileParts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
85 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
86 #define MAX_TMF_PARTS ( 16 ) |
10263 | 87 |
88 typedef struct sTivoInfo | |
89 { | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
90 int whichChunk; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
91 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
92 unsigned char lastAudio[ MAX_AUDIO_BUFFER ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
93 int lastAudioEnd; |
10263 | 94 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
95 int tivoType; // 1 = SA, 2 = DTiVo |
10263 | 96 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
97 float firstAudioPTS; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
98 float firstVideoPTS; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
99 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
100 float lastAudioPTS; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
101 float lastVideoPTS; |
10263 | 102 |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
103 int headerOk; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
104 unsigned int pesFileId; // Should be 0xf5467abd |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
105 int streamType; // Should be 0x02 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
106 int chunkSize; // Should always be 128k |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
107 off_t size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
108 int readHeader; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
109 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
110 int tmf; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
111 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
|
112 int tmf_totalparts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
113 off_t tmf_totalsize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
114 off_t tmf_totalchunks; |
10263 | 115 |
116 } TiVoInfo; | |
117 | |
118 off_t vstream_streamsize( ); | |
119 void ty_ClearOSD( int start ); | |
120 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
121 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
122 #define TMF_SIG "showing.xml" |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
123 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
124 int ty_octaltodecimal( char *num ) |
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 int i; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
127 int result = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
128 int len; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
129 int mult; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
130 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
131 len = strlen( num ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
132 mult = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
133 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
134 for ( i = ( len - 1 ) ; i >= 0 ; i-- ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
135 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
136 result += ( ( num[ i ] - '0') * mult ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
137 mult *= 8; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
138 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
139 return( result ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
140 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
141 |
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 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
144 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
145 int ty_extensionis( char *name, char *ext ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
146 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
147 char *ptr; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
148 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
149 if ( strlen( ext ) > strlen( name ) ) return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
150 ptr = name; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
151 ptr += ( strlen( name ) - strlen( ext ) ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
152 if ( strcmp( ptr, ext ) == 0 ) return( 1 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
153 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
154 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
155 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
156 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
157 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
158 int ty_tmf_filetoparts( demuxer_t *demux, TiVoInfo *tivo ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
159 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
160 char header[ 512 ]; |
17784
1b42df5780e3
name array is too small, use strlcpy instead of strncpy
reimar
parents:
17636
diff
changeset
|
161 char name[ 100 ]; |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
162 char sizestr[ 80 ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
163 int size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
164 int count; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
165 int blocks; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
166 int done; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
167 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
168 off_t totalsize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
169 off_t skip; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
170 int error = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
171 int parts = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
172 int isty; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
173 int index; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
174 int ok; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
175 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
176 offset = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
177 totalsize = demux->stream->end_pos; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
178 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
179 done = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
180 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Dumping tar contents\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
181 while ( done == 0 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
182 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
183 ok = stream_seek( demux->stream, offset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
184 if ( ( offset + 512 ) == totalsize ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
185 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
186 done = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
187 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
188 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
189 if ( ok == 0 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
190 { |
17366 | 191 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
|
192 done = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
193 error = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
194 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
195 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
196 count = stream_read( demux->stream, header, 512 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
197 if ( count < 512 ) |
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 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
|
200 done = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
201 error = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
202 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
203 } |
17784
1b42df5780e3
name array is too small, use strlcpy instead of strncpy
reimar
parents:
17636
diff
changeset
|
204 strlcpy( name, &header[ 0 ], 100 ); |
1b42df5780e3
name array is too small, use strlcpy instead of strncpy
reimar
parents:
17636
diff
changeset
|
205 strlcpy( sizestr, &header[ 124 ], 12 ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
206 size = ty_octaltodecimal( sizestr ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
207 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
208 blocks = size / 512; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
209 if ( ( size % 512 ) > 0 ) blocks++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
210 skip = ( blocks + 1 ) * 512; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
211 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
212 if ( ( offset + skip ) > totalsize ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
213 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
214 size = totalsize - offset; |
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 isty = ty_extensionis( name, ".ty" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
218 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
219 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
|
220 name, sizestr, size, isty ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
221 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
222 if ( isty ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
223 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
224 tivo->tmfparts[ parts ].fileNo = parts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
225 // HACK - Ignore last chunk of a Part File |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
226 // Why? I have no idea. |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
227 tivo->tmfparts[ parts ].fileSize = size - 0x20000; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
228 tivo->tmfparts[ parts ].startOffset = offset + 512; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
229 tivo->tmfparts[ parts ].chunks = |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
230 ( tivo->tmfparts[ parts ].fileSize / CHUNKSIZE ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
231 mp_msg |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
232 ( |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
233 MSGT_DEMUX, MSGL_DBG3, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
234 "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
|
235 parts, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
236 tivo->tmfparts[ parts ].fileNo, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
237 tivo->tmfparts[ parts ].chunks |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
238 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
239 mp_msg |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
240 ( |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
241 MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
242 "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
|
243 tivo->tmfparts[ parts ].fileSize |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
244 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
245 mp_msg |
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 MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
248 "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
|
249 tivo->tmfparts[ parts ].startOffset |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
250 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
251 parts++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
252 if ( parts > MAX_TMF_PARTS ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
253 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
254 mp_msg( MSGT_DEMUX, MSGL_ERR, "ty:tmf too big\n" ); |
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 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
257 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
258 if ( ( offset + skip ) > totalsize ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
259 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
260 done = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
261 error = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
262 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
263 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
264 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
265 offset += skip; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
266 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
267 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
268 if ( error ) |
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 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
|
271 "WARNING : tmf parse error, not intact\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
272 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
273 tivo->tmf_totalparts = parts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
274 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
|
275 "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
|
276 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
277 tivo->tmf_totalsize = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
278 tivo->tmf_totalchunks = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
279 for( index = 0 ; index < tivo->tmf_totalparts ; index++ ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
280 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
281 tivo->tmf_totalsize += tivo->tmfparts[ index ].fileSize; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
282 tivo->tmf_totalchunks += ( tivo->tmfparts[ index ].fileSize / CHUNKSIZE ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
283 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
284 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 285 "tmf_filetoparts():total size %"PRId64"\n", (int64_t)tivo->tmf_totalsize ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
286 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 287 "tmf_filetoparts():total chunks %"PRId64"\n", (int64_t)tivo->tmf_totalchunks ); |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
288 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
289 return( 1 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
290 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
291 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
292 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
293 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
294 void tmf_filetooffset( TiVoInfo *tivo, int chunk, off_t *offset ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
295 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
296 int index; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
297 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
298 *offset = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
299 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
300 for( index = 0 ; index < tivo->tmf_totalparts ; index++ ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
301 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
302 if ( chunk >= tivo->tmfparts[ index ].chunks ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
303 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
304 chunk -= tivo->tmfparts[ index ].chunks; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
305 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
306 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
307 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
308 break; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
309 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
310 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
311 if ( chunk < tivo->tmfparts[ index ].chunks ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
312 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
313 *offset = tivo->tmfparts[ index ].startOffset + |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
314 ( chunk * CHUNKSIZE ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
315 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
316 mp_msg |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
317 ( |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
318 MSGT_DEMUX, MSGL_DBG3, |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
319 "tmf_filetooffset() offset %"PRIx64"\n", *offset |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
320 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
321 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
322 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
323 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
324 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
325 int tmf_load_chunk( demuxer_t *demux, TiVoInfo *tivo, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
326 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
|
327 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
328 off_t fileoffset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
329 int count; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
330 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
331 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
|
332 readChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
333 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
334 if ( tivo->tmf_totalparts <= 0 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
335 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
336 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
337 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
338 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
339 if ( readChunk >= tivo->tmf_totalchunks ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
340 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
341 mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
342 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
343 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
344 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
345 tmf_filetooffset( tivo, readChunk, &fileoffset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
346 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
347 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
|
348 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
349 mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
350 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
351 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
352 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
|
353 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
|
354 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
355 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
|
356 count ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
357 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
358 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
|
359 "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
|
360 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
|
361 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
|
362 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
363 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
|
364 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
365 return( count ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
366 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
367 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
368 // =========================================================================== |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
369 |
10263 | 370 // DTiVo MPEG 336, 480, 576, 768 |
371 // SA TiVo 864 | |
372 // DTiVo AC-3 1550 | |
373 // | |
374 #define SERIES1_PTS_LENGTH ( 11 ) | |
375 #define SERIES1_PTS_OFFSET ( 6 ) | |
376 #define SERIES2_PTS_LENGTH ( 16 ) | |
377 #define SERIES2_PTS_OFFSET ( 9 ) | |
378 #define AC3_PTS_LENGTH ( 16 ) | |
379 #define AC3_PTS_OFFSET ( 9 ) | |
380 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
381 #define NUMBER_DIFFERENT_AUDIO_SIZES ( 7 ) |
10263 | 382 static int Series1AudioWithPTS[ NUMBER_DIFFERENT_AUDIO_SIZES ] = |
383 { | |
384 336 + SERIES1_PTS_LENGTH, | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
385 384 + SERIES1_PTS_LENGTH, |
10263 | 386 480 + SERIES1_PTS_LENGTH, |
387 576 + SERIES1_PTS_LENGTH, | |
388 768 + SERIES1_PTS_LENGTH, | |
389 864 + SERIES1_PTS_LENGTH | |
390 }; | |
391 static int Series2AudioWithPTS[ NUMBER_DIFFERENT_AUDIO_SIZES ] = | |
392 { | |
393 336 + SERIES2_PTS_LENGTH, | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
394 384 + SERIES2_PTS_LENGTH, |
10263 | 395 480 + SERIES2_PTS_LENGTH, |
396 576 + SERIES2_PTS_LENGTH, | |
397 768 + SERIES2_PTS_LENGTH, | |
398 864 + SERIES2_PTS_LENGTH | |
399 }; | |
400 | |
401 static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen ) | |
402 { | |
403 int count; | |
404 | |
405 *ptsOffset = 0; | |
406 *ptsLen = 0; | |
407 | |
408 // AC-3 | |
409 if ( ( size == 1550 ) || ( size == 1552 ) ) | |
410 { | |
411 *ptsOffset = AC3_PTS_OFFSET; | |
412 *ptsLen = AC3_PTS_LENGTH; | |
413 return( 1 ); | |
414 } | |
415 | |
416 // MPEG | |
417 for( count = 0 ; count < NUMBER_DIFFERENT_AUDIO_SIZES ; count++ ) | |
418 { | |
419 if ( size == Series1AudioWithPTS[ count ] ) | |
420 { | |
421 *ptsOffset = SERIES1_PTS_OFFSET; | |
422 *ptsLen = SERIES1_PTS_LENGTH; | |
423 break; | |
424 } | |
425 } | |
426 if ( *ptsOffset == 0 ) | |
427 { | |
428 for( count = 0 ; count < NUMBER_DIFFERENT_AUDIO_SIZES ; count++ ) | |
429 { | |
430 if ( size == Series2AudioWithPTS[ count ] ) | |
431 { | |
432 *ptsOffset = SERIES2_PTS_OFFSET; | |
433 *ptsLen = SERIES2_PTS_LENGTH; | |
434 break; | |
435 } | |
436 } | |
437 } | |
438 if ( *ptsOffset == 0 ) | |
439 { | |
440 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Tossing Audio Packet Size %d\n", | |
441 size ); | |
442 return( 0 ); | |
443 } | |
444 else | |
445 { | |
446 return( 1 ); | |
447 } | |
448 } | |
449 | |
450 | |
451 static float get_ty_pts( unsigned char *buf ) | |
452 { | |
453 float result = 0; | |
454 unsigned char temp; | |
455 | |
456 temp = ( buf[ 0 ] & 0xE ) >> 1; | |
457 result = ( (float) temp ) * ( (float) ( 1L << 30 ) ) / ( (float)PTS_KHZ ); | |
458 temp = buf[ 1 ]; | |
459 result += ( (float) temp ) * ( (float) ( 1L << 22 ) ) / ( (float)PTS_KHZ ); | |
460 temp = ( buf[ 2 ] & 0xFE ) >> 1; | |
461 result += ( (float) temp ) * ( (float) ( 1L << 15 ) ) / ( (float)PTS_KHZ ); | |
462 temp = buf[ 3 ]; | |
463 result += ( (float) temp ) * ( (float) ( 1L << 7 ) ) / ( (float)PTS_KHZ ); | |
464 temp = ( buf[ 4 ] & 0xFE ) >> 1; | |
465 result += ( (float) temp ) / ( (float)PTS_MHZ ); | |
466 | |
467 return result; | |
468 } | |
469 | |
470 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer, | |
471 int size ) | |
472 { | |
473 if ( ( tivo->lastAudioEnd + size ) < MAX_AUDIO_BUFFER ) | |
474 { | |
475 memcpy( &( tivo->lastAudio[ tivo->lastAudioEnd ] ), | |
476 buffer, size ); | |
477 tivo->lastAudioEnd += size; | |
478 } | |
479 else | |
480 { | |
481 mp_msg( MSGT_DEMUX, MSGL_ERR, | |
482 "ty:WARNING - Would have blown my audio buffer\n" ); | |
483 } | |
484 } | |
485 | |
486 static void demux_ty_CopyToDemuxPacket( int type, TiVoInfo *tivo, demux_stream_t *ds, | |
487 unsigned char *buffer, int size, off_t pos, float pts ) | |
488 { | |
489 demux_packet_t *dp; | |
490 | |
491 // mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Calling ds_add_packet() %7.1f\n", pts ); | |
492 // printf( "%x %x %x %x\n", | |
493 // buffer[ 0 ], buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] ); | |
494 | |
495 dp = new_demux_packet( size ); | |
496 memcpy( dp->buffer, buffer, size ); | |
497 dp->pts = pts; | |
498 dp->pos = pos; | |
499 dp->flags = 0; | |
500 ds_add_packet( ds, dp ); | |
501 ds->pts = pts; | |
502 if ( type == TY_V ) | |
503 { | |
504 if ( tivo->firstVideoPTS == -1 ) | |
505 { | |
506 tivo->firstVideoPTS = pts; | |
507 } | |
508 } | |
509 if ( type == TY_A ) | |
510 { | |
511 if ( tivo->firstAudioPTS == -1 ) | |
512 { | |
513 tivo->firstAudioPTS = pts; | |
514 } | |
515 } | |
516 } | |
517 | |
518 static int demux_ty_FindESHeader( unsigned char *header, int headerSize, | |
519 unsigned char *buffer, int bufferSize, int *esOffset1 ) | |
520 { | |
521 int count; | |
522 | |
523 *esOffset1 = -1; | |
524 for( count = 0 ; count < bufferSize ; count++ ) | |
525 { | |
526 if ( ( buffer[ count + 0 ] == header[ 0 ] ) && | |
527 ( buffer[ count + 1 ] == header[ 1 ] ) && | |
528 ( buffer[ count + 2 ] == header[ 2 ] ) && | |
529 ( buffer[ count + 3 ] == header[ 3 ] ) ) | |
530 { | |
531 *esOffset1 = count; | |
532 return( 1 ); | |
533 } | |
534 } | |
535 return( -1 ); | |
536 } | |
537 | |
538 static void demux_ty_FindESPacket( unsigned char *header, int headerSize, | |
539 unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 ) | |
540 { | |
541 int count; | |
542 | |
543 *esOffset1 = -1; | |
544 *esOffset2 = -1; | |
545 | |
546 for( count = 0 ; count < bufferSize ; count++ ) | |
547 { | |
548 if ( ( buffer[ count + 0 ] == header[ 0 ] ) && | |
549 ( buffer[ count + 1 ] == header[ 1 ] ) && | |
550 ( buffer[ count + 2 ] == header[ 2 ] ) && | |
551 ( buffer[ count + 3 ] == header[ 3 ] ) ) | |
552 { | |
553 *esOffset1 = count; | |
554 break; | |
555 } | |
556 } | |
557 | |
558 if ( *esOffset1 != -1 ) | |
559 { | |
560 for( count = *esOffset1 + 1 ; | |
561 count < bufferSize ; count++ ) | |
562 { | |
563 if ( ( buffer[ count + 0 ] == header[ 0 ] ) && | |
564 ( buffer[ count + 1 ] == header[ 1 ] ) && | |
565 ( buffer[ count + 2 ] == header[ 2 ] ) && | |
566 ( buffer[ count + 3 ] == header[ 3 ] ) ) | |
567 { | |
568 *esOffset2 = count; | |
569 break; | |
570 } | |
571 } | |
572 } | |
573 } | |
574 | |
575 static int tivobuffer2hostlong( unsigned char *buffer ) | |
576 { | |
577 return | |
578 ( | |
579 buffer[ 0 ] << 24 | buffer[ 1 ] << 16 | buffer[ 2 ] << 8 | buffer[ 3 ] | |
580 ); | |
581 } | |
582 | |
583 static unsigned char ty_VideoPacket[] = { 0x00, 0x00, 0x01, 0xe0 }; | |
584 static unsigned char ty_MPEGAudioPacket[] = { 0x00, 0x00, 0x01, 0xc0 }; | |
585 static unsigned char ty_AC3AudioPacket[] = { 0x00, 0x00, 0x01, 0xbd }; | |
586 | |
16175 | 587 static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds ) |
10263 | 588 { |
589 int invalidType = 0; | |
590 int errorHeader = 0; | |
591 int recordsDecoded = 0; | |
592 off_t filePos = 0; | |
593 | |
594 unsigned char chunk[ CHUNKSIZE ]; | |
595 int whichChunk; | |
596 int readSize; | |
597 unsigned int pesFileId = 0; | |
598 | |
599 int numberRecs; | |
600 unsigned char *recPtr; | |
601 int offset; | |
602 int size; | |
603 | |
604 int type; | |
605 int nybbleType; | |
606 | |
607 int counter; | |
608 | |
609 int aid; | |
610 demux_stream_t *ds = NULL; | |
611 | |
612 int esOffset1; | |
613 int esOffset2; | |
614 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
615 unsigned char lastCC[ 16 ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
616 unsigned char lastXDS[ 16 ]; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
617 |
10263 | 618 TiVoInfo *tivo = 0; |
619 | |
620 if ( demux->stream->type == STREAMTYPE_DVD ) | |
621 { | |
622 return( 0 ); | |
623 } | |
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 processing\n" ); |
10263 | 626 if ( ( demux->a_streams[ MAX_A_STREAMS - 1 ] ) == 0 ) |
627 { | |
628 demux->a_streams[ MAX_A_STREAMS - 1 ] = malloc( sizeof( TiVoInfo ) ); | |
629 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; | |
630 memset( tivo, 0, sizeof( TiVoInfo ) ); | |
631 tivo->firstAudioPTS = -1; | |
632 tivo->firstVideoPTS = -1; | |
633 } | |
634 else | |
635 { | |
636 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; | |
637 } | |
638 | |
639 if( demux->stream->eof ) return 0; | |
640 | |
641 // ====================================================================== | |
11000 | 642 // If we haven't figured out the size of the stream, let's do so |
10263 | 643 // ====================================================================== |
644 #ifdef STREAMTYPE_STREAM_TY | |
645 if ( demux->stream->type == STREAMTYPE_STREAM_TY ) | |
646 { | |
647 // The vstream code figures out the exact size of the stream | |
648 demux->movi_start = 0; | |
649 demux->movi_end = vstream_streamsize(); | |
650 tivo->size = vstream_streamsize(); | |
651 } | |
652 else | |
653 #endif | |
654 { | |
655 // If its a local file, try to find the Part Headers, so we can | |
656 // calculate the ACTUAL stream size | |
657 // If we can't find it, go off with the file size and hope the | |
658 // extract program did the "right thing" | |
659 if ( tivo->readHeader == 0 ) | |
660 { | |
661 tivo->readHeader = 1; | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
662 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
|
663 |
10263 | 664 filePos = demux->filepos; |
665 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
|
666 |
10263 | 667 // mp_msg( MSGT_DEMUX, MSGL_DBG3, |
668 // "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
|
669 |
10263 | 670 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
|
671 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
672 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
|
673 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
674 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
|
675 tivo->tmf = 1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
676 ty_tmf_filetoparts( demux, tivo ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
677 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
|
678 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
679 |
10263 | 680 if ( readSize == CHUNKSIZE ) |
681 { | |
682 tivo->pesFileId = tivobuffer2hostlong( &chunk[ 0x00 ] ); | |
683 tivo->streamType = tivobuffer2hostlong( &chunk[ 0x04 ] ); | |
684 tivo->chunkSize = tivobuffer2hostlong( &chunk[ 0x08 ] ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
685 |
10263 | 686 if ( tivo->pesFileId == TIVO_PES_FILEID ) |
687 { | |
688 off_t numberParts; | |
689 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
690 readSize = 0; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
691 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
692 if ( tivo->tmf != 1 ) |
10263 | 693 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
694 off_t offset; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
695 |
10263 | 696 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
|
697 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
698 |
17366 | 699 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n", |
700 (int64_t)numberParts ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
701 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
702 if ( ( offset + CHUNKSIZE ) < demux->stream->end_pos ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
703 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
704 stream_seek( demux->stream, offset ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
705 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
|
706 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
707 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
708 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
709 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
710 numberParts = tivo->tmf_totalparts; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
711 offset = numberParts * TIVO_PART_LENGTH; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
712 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
|
713 ( numberParts * ( TIVO_PART_LENGTH - 0x20000 ) / |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
714 CHUNKSIZE ) ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
715 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
716 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
717 if ( readSize == CHUNKSIZE ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
718 { |
10263 | 719 pesFileId = tivobuffer2hostlong( &chunk[ 0x00 ] ); |
720 if ( pesFileId == TIVO_PES_FILEID ) | |
721 { | |
722 size = tivobuffer2hostlong( &chunk[ 0x0c ] ); | |
723 size /= 256; | |
724 size -= 4; | |
725 size *= CHUNKSIZE; | |
726 tivo->size = numberParts * TIVO_PART_LENGTH; | |
727 tivo->size += size; | |
728 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
729 "ty:Header Calc Stream Size %"PRId64"\n", tivo->size ); |
10263 | 730 } |
731 } | |
732 } | |
733 } | |
734 if ( tivo->size > demux->stream->end_pos ) | |
735 { | |
736 tivo->size = demux->stream->end_pos; | |
737 } | |
738 | |
739 if ( demux->stream->start_pos > 0 ) | |
740 { | |
741 filePos = demux->stream->start_pos; | |
742 } | |
743 stream_seek( demux->stream, filePos ); | |
744 demux->filepos = stream_tell( demux->stream ); | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
745 tivo->whichChunk = ( filePos / CHUNKSIZE ); |
10263 | 746 } |
747 demux->movi_start = 0; | |
748 demux->movi_end = tivo->size; | |
749 } | |
750 | |
751 // ====================================================================== | |
752 // Give a clue as to where we are in the stream | |
753 // ====================================================================== | |
754 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
17366 | 755 "ty:ty header size %"PRIx64"\n", (int64_t)tivo->size ); |
10263 | 756 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 757 "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
|
758 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 759 "ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos ); |
10263 | 760 mp_msg( MSGT_DEMUX, MSGL_DBG3, |
17366 | 761 "\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) ); |
10263 | 762 |
763 if ( tivo->size > 0 ) | |
764 { | |
765 if ( stream_tell( demux->stream ) > tivo->size ) | |
766 { | |
767 demux->stream->eof = 1; | |
768 return( 0 ); | |
769 } | |
770 } | |
771 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
772 if ( tivo->tmf != 1 ) |
10263 | 773 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
774 // Make sure we are on a 128k boundary |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
775 if ( ( demux->filepos % CHUNKSIZE ) != 0 ) |
10263 | 776 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
777 whichChunk = demux->filepos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
778 if ( ( demux->filepos % CHUNKSIZE ) > ( CHUNKSIZE / 2 ) ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
779 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
780 whichChunk++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
781 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
782 stream_seek( demux->stream, ( whichChunk * CHUNKSIZE ) ); |
10263 | 783 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
784 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
785 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
|
786 tivo->whichChunk = demux->filepos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
787 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
|
788 if ( readSize != CHUNKSIZE ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
789 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
790 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
791 } |
10263 | 792 } |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
793 else |
10263 | 794 { |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
795 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
|
796 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
797 if ( readSize != CHUNKSIZE ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
798 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
799 return( 0 ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
800 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
801 tivo->whichChunk++; |
10263 | 802 } |
803 | |
804 // We found a part header, skip it | |
805 pesFileId = tivobuffer2hostlong( &chunk[ 0x00 ] ); | |
806 if( pesFileId == TIVO_PES_FILEID ) | |
807 { | |
808 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
|
809 if ( tivo->tmf != 1 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
810 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
811 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
|
812 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
|
813 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
814 else |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
815 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
816 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
|
817 tivo->whichChunk ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
818 tivo->whichChunk++; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
819 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
820 |
10263 | 821 if ( readSize != CHUNKSIZE ) |
822 { | |
823 return( 0 ); | |
824 } | |
825 } | |
826 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16346
diff
changeset
|
827 "\nty:actual current offset %"PRIx64"\n", ( stream_tell( demux->stream ) - |
10263 | 828 0x20000 ) ); |
829 | |
830 | |
12860 | 831 // Let's make a Video Demux Stream for MPlayer |
10263 | 832 aid = 0x0; |
833 if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid ); | |
834 if( demux->video->id == -1 ) demux->video->id = aid; | |
835 if( demux->video->id == aid ) | |
836 { | |
837 ds = demux->video; | |
838 if( !ds->sh ) ds->sh = demux->v_streams[ aid ]; | |
839 } | |
840 | |
841 // ====================================================================== | |
842 // Finally, we get to actually parse the chunk | |
843 // ====================================================================== | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
844 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" ); |
10263 | 845 numberRecs = chunk[ 0 ]; |
846 recPtr = &chunk[ 4 ]; | |
847 offset = ( numberRecs * 16 ) + 4; | |
848 for ( counter = 0 ; counter < numberRecs ; counter++ ) | |
849 { | |
850 size = ( recPtr[ 0 ] << 8 | recPtr[ 1 ] ) << 4 | ( recPtr[ 2 ] >> 4 ); | |
851 type = recPtr[ 3 ]; | |
852 nybbleType = recPtr[ 2 ] & 0x0f; | |
853 recordsDecoded++; | |
854 | |
855 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
856 "ty:Record Type %x/%x %d\n", nybbleType, type, size ); | |
857 | |
858 // ================================================================ | |
859 // Video Parsing | |
860 // ================================================================ | |
861 if ( type == 0xe0 ) | |
862 { | |
863 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) | |
864 { | |
865 #if 0 | |
866 printf( "Video Chunk Header " ); | |
867 for( count = 0 ; count < 24 ; count++ ) | |
868 { | |
869 printf( "%2.2x ", chunk[ offset + count ] ); | |
870 } | |
871 printf( "\n" ); | |
872 #endif | |
873 demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ], | |
874 size, &esOffset1 ); | |
875 if ( esOffset1 != -1 ) | |
876 { | |
877 tivo->lastVideoPTS = get_ty_pts( | |
878 &chunk[ offset + esOffset1 + 9 ] ); | |
879 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Video PTS %7.1f\n", | |
880 tivo->lastVideoPTS ); | |
881 } | |
882 | |
883 // Do NOT Pass the PES Header onto the MPEG2 Decode | |
884 if( nybbleType != 0x06 ) | |
885 { | |
886 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, | |
887 &chunk[ offset ], size, ( demux->filepos + offset ), | |
888 tivo->lastVideoPTS ); | |
889 } | |
890 offset += size; | |
891 } | |
892 else | |
893 { | |
894 errorHeader++; | |
895 } | |
896 } | |
897 // ================================================================ | |
898 // Audio Parsing | |
899 // ================================================================ | |
900 else if ( type == 0xc0 ) | |
901 { | |
902 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) | |
903 { | |
904 #if 0 | |
905 printf( "Audio Chunk Header " ); | |
906 for( count = 0 ; count < 24 ; count++ ) | |
907 { | |
908 printf( "%2.2x ", chunk[ offset + count ] ); | |
909 } | |
910 printf( "\n" ); | |
911 #endif | |
912 | |
913 if( demux->audio->id == -1 ) | |
914 { | |
915 if ( nybbleType == 0x02 ) | |
916 { | |
917 continue; // DTiVo inconclusive, wait for more | |
918 } | |
919 else if ( nybbleType == 0x09 ) | |
920 { | |
921 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" ); | |
922 aid = 0x80; // AC-3 | |
923 } | |
924 else | |
925 { | |
926 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" ); | |
927 aid = 0x0; // MPEG Audio | |
928 } | |
929 | |
930 demux->audio->id = aid; | |
931 if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid ); | |
932 if( demux->audio->id == aid ) | |
933 { | |
934 ds = demux->audio; | |
15580 | 935 if( !ds->sh ) { |
936 sh_audio_t* sh_a; | |
937 ds->sh = demux->a_streams[ aid ]; | |
938 sh_a = (sh_audio_t*)ds->sh; | |
939 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id) | |
940 case 0x00: sh_a->format=0x50;break; // mpeg | |
941 case 0xA0: sh_a->format=0x10001;break; // dvd pcm | |
942 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts | |
943 else sh_a->format=0x2000;break; // ac3 | |
944 } | |
945 } | |
10263 | 946 } |
947 } | |
948 | |
949 aid = demux->audio->id; | |
950 | |
951 | |
952 // SA DTiVo Audio Data, no PES | |
953 // ================================================ | |
954 if ( nybbleType == 0x02 ) | |
955 { | |
956 if ( tivo->tivoType == 2 ) | |
957 { | |
958 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
959 } | |
960 else | |
961 { | |
962 | |
963 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
964 "ty:Adding Audio Packet Size %d\n", size ); | |
965 demux_ty_CopyToDemuxPacket( TY_A, tivo, demux->audio, | |
966 &chunk[ offset ], size, ( demux->filepos + offset ), | |
967 tivo->lastAudioPTS ); | |
968 } | |
969 } | |
970 | |
971 // MPEG Audio with PES Header, either SA or DTiVo | |
972 // ================================================ | |
973 if ( nybbleType == 0x03 ) | |
974 { | |
975 demux_ty_FindESHeader( ty_MPEGAudioPacket, 4, &chunk[ offset ], | |
976 size, &esOffset1 ); | |
977 | |
978 // SA PES Header, No Audio Data | |
979 // ================================================ | |
980 if ( ( esOffset1 == 0 ) && ( size == 16 ) ) | |
981 { | |
982 tivo->tivoType = 1; | |
983 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + | |
984 SERIES2_PTS_OFFSET ] ); | |
985 mp_msg( MSGT_DEMUX, MSGL_DBG3, "SA Audio PTS %7.1f\n", | |
986 tivo->lastAudioPTS ); | |
987 } | |
988 else | |
989 // DTiVo Audio with PES Header | |
990 // ================================================ | |
991 { | |
992 tivo->tivoType = 2; | |
993 | |
994 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
995 demux_ty_FindESPacket( ty_MPEGAudioPacket, 4, | |
996 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, | |
997 &esOffset2 ); | |
998 | |
999 if ( ( esOffset1 != -1 ) && ( esOffset2 != -1 ) ) | |
1000 { | |
1001 int packetSize = esOffset2 - esOffset1; | |
1002 int headerSize; | |
1003 int ptsOffset; | |
1004 | |
1005 if ( IsValidAudioPacket( packetSize, &ptsOffset, | |
1006 &headerSize ) ) | |
1007 { | |
1008 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
1009 "ty:Adding DTiVo Audio Packet Size %d\n", | |
1010 packetSize ); | |
1011 | |
1012 tivo->lastAudioPTS = get_ty_pts( | |
1013 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); | |
1014 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
1015 "MPEG Audio PTS %7.1f\n", tivo->lastAudioPTS ); | |
1016 | |
1017 demux_ty_CopyToDemuxPacket | |
1018 ( | |
1019 TY_A, | |
1020 tivo, | |
1021 demux->audio, | |
1022 &( tivo->lastAudio[ esOffset1 + headerSize ] ), | |
1023 ( packetSize - headerSize ), | |
1024 ( demux->filepos + offset ), | |
1025 tivo->lastAudioPTS | |
1026 ); | |
1027 | |
1028 } | |
1029 | |
1030 // Collapse the Audio Buffer | |
1031 memmove( &(tivo->lastAudio[ 0 ] ), | |
1032 &( tivo->lastAudio[ esOffset2 ] ), | |
1033 ( tivo->lastAudioEnd - esOffset2 ) ); | |
1034 tivo->lastAudioEnd -= esOffset2; | |
1035 } | |
1036 } | |
1037 } | |
1038 | |
1039 // SA Audio with no PES Header | |
1040 // ================================================ | |
1041 if ( nybbleType == 0x04 ) | |
1042 { | |
1043 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
1044 "ty:Adding Audio Packet Size %d\n", size ); | |
1045 demux_ty_CopyToDemuxPacket( TY_A, tivo, demux->audio, | |
1046 &chunk[ offset ], size, ( demux->filepos + offset ), | |
1047 tivo->lastAudioPTS ); | |
1048 } | |
1049 | |
1050 // DTiVo AC3 Audio Data with PES Header | |
1051 // ================================================ | |
1052 if ( nybbleType == 0x09 ) | |
1053 { | |
1054 tivo->tivoType = 2; | |
1055 | |
1056 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size ); | |
1057 demux_ty_FindESPacket( ty_AC3AudioPacket, 4, | |
1058 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1, | |
1059 &esOffset2 ); | |
1060 | |
1061 if ( ( esOffset1 != -1 ) && ( esOffset2 != -1 ) ) | |
1062 { | |
1063 int packetSize = esOffset2 - esOffset1; | |
1064 int headerSize; | |
1065 int ptsOffset; | |
1066 | |
1067 if ( IsValidAudioPacket( packetSize, &ptsOffset, | |
1068 &headerSize ) ) | |
1069 { | |
1070 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
1071 "ty:Adding DTiVo Audio Packet Size %d\n", | |
1072 packetSize ); | |
1073 | |
1074 tivo->lastAudioPTS = get_ty_pts( | |
1075 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); | |
1076 mp_msg( MSGT_DEMUX, MSGL_DBG3, | |
1077 "AC3 Audio PTS %7.1f\n", tivo->lastAudioPTS ); | |
1078 | |
1079 // AC3 Decoder WANTS the PTS | |
1080 demux_ty_CopyToDemuxPacket | |
1081 ( | |
1082 TY_A, | |
1083 tivo, | |
1084 demux->audio, | |
1085 &( tivo->lastAudio[ esOffset1 ] ), | |
1086 ( packetSize ), | |
1087 ( demux->filepos + offset ), | |
1088 tivo->lastAudioPTS | |
1089 ); | |
1090 | |
1091 } | |
1092 | |
1093 // Collapse the Audio Buffer | |
1094 memmove( &(tivo->lastAudio[ 0 ] ), | |
1095 &( tivo->lastAudio[ esOffset2 ] ), | |
1096 ( tivo->lastAudioEnd - esOffset2 ) ); | |
1097 tivo->lastAudioEnd -= esOffset2; | |
1098 } | |
1099 } | |
1100 offset += size; | |
1101 } | |
1102 else | |
1103 { | |
1104 errorHeader++; | |
1105 } | |
1106 } | |
1107 // ================================================================ | |
1108 // Closed Caption | |
1109 // ================================================================ | |
1110 else if ( type == 0x01 ) | |
1111 { | |
1112 unsigned char b1; | |
1113 unsigned char b2; | |
1114 | |
1115 b1 = ( ( ( recPtr[ 0 ] & 0x0f ) << 4 ) | | |
1116 ( ( recPtr[ 1 ] & 0xf0 ) >> 4 ) ); | |
1117 b1 &= 0x7f; | |
1118 b2 = ( ( ( recPtr[ 1 ] & 0x0f ) << 4 ) | | |
1119 ( ( recPtr[ 2 ] & 0xf0 ) >> 4 ) ); | |
1120 b2 &= 0x7f; | |
1121 | |
1122 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:CC %x %x\n", b1, b2 ); | |
1123 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1124 lastCC[ 0x00 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1125 lastCC[ 0x01 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1126 lastCC[ 0x02 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1127 lastCC[ 0x03 ] = 0xb2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1128 lastCC[ 0x04 ] = 'T'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1129 lastCC[ 0x05 ] = 'Y'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1130 lastCC[ 0x06 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1131 lastCC[ 0x07 ] = b1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1132 lastCC[ 0x08 ] = b2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1133 if ( subcc_enabled ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1134 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1135 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, lastCC, 0x09, |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1136 ( demux->filepos + offset ), tivo->lastVideoPTS ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1137 } |
10263 | 1138 } |
1139 // ================================================================ | |
1140 // Extended Data Services | |
1141 // ================================================================ | |
1142 else if ( type == 0x02 ) | |
1143 { | |
1144 unsigned char b1; | |
1145 unsigned char b2; | |
1146 | |
1147 b1 = ( ( ( recPtr[ 0 ] & 0x0f ) << 4 ) | | |
1148 ( ( recPtr[ 1 ] & 0xf0 ) >> 4 ) ); | |
1149 b1 &= 0x7f; | |
1150 b2 = ( ( ( recPtr[ 1 ] & 0x0f ) << 4 ) | | |
1151 ( ( recPtr[ 2 ] & 0xf0 ) >> 4 ) ); | |
1152 b2 &= 0x7f; | |
1153 | |
1154 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:XDS %x %x\n", b1, b2 ); | |
1155 | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1156 lastXDS[ 0x00 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1157 lastXDS[ 0x01 ] = 0x00; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1158 lastXDS[ 0x02 ] = 0x01; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1159 lastXDS[ 0x03 ] = 0xb2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1160 lastXDS[ 0x04 ] = 'T'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1161 lastXDS[ 0x05 ] = 'Y'; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1162 lastXDS[ 0x06 ] = 0x02; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1163 lastXDS[ 0x07 ] = b1; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1164 lastXDS[ 0x08 ] = b2; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1165 if ( subcc_enabled ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1166 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1167 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
|
1168 ( demux->filepos + offset ), tivo->lastVideoPTS ); |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1169 } |
10263 | 1170 } |
1171 // ================================================================ | |
1172 // Found a 0x03 on Droid's TiVo, I have no idea what it is | |
1173 // ================================================================ | |
1174 else if ( type == 0x03 ) | |
1175 { | |
1176 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) | |
1177 { | |
1178 offset += size; | |
1179 } | |
1180 } | |
1181 // ================================================================ | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1182 // Found a 0x03 on Hermit's TiVo, I have no idea what it is |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1183 // ================================================================ |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1184 else if ( type == 0x03 ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1185 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1186 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1187 { |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1188 offset += size; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1189 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1190 } |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1191 // ================================================================ |
10263 | 1192 // Unknown |
1193 // ================================================================ | |
1194 else if ( type == 0x05 ) | |
1195 { | |
1196 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) | |
1197 { | |
1198 offset += size; | |
1199 } | |
1200 } | |
1201 else | |
1202 { | |
1203 if ( ( size > 0 ) && ( ( size + offset ) <= CHUNKSIZE ) ) | |
1204 { | |
1205 offset += size; | |
1206 } | |
1207 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type ); | |
1208 invalidType++; | |
1209 } | |
1210 recPtr += 16; | |
1211 } | |
1212 | |
20141
bd3afd5a2e48
Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents:
19614
diff
changeset
|
1213 if ( errorHeader > 0 || invalidType > 0 ) |
10263 | 1214 { |
1215 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
|
1216 "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
|
1217 numberRecs, recordsDecoded, errorHeader, invalidType ); |
10263 | 1218 |
1219 // Invalid MPEG ES Size Check | |
1220 if ( errorHeader > ( numberRecs / 2 ) ) | |
1221 { | |
1222 return( 0 ); | |
1223 } | |
1224 | |
1225 // Invalid MPEG Stream Type Check | |
1226 if ( invalidType > ( numberRecs / 2 ) ) | |
1227 { | |
1228 return( 0 ); | |
1229 } | |
1230 } | |
1231 | |
1232 demux->filepos = stream_tell( demux->stream ); | |
1233 | |
1234 return( 1 ); | |
1235 } | |
1236 | |
17636 | 1237 static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) |
10263 | 1238 { |
1239 demux_stream_t *d_audio = demuxer->audio; | |
1240 demux_stream_t *d_video = demuxer->video; | |
1241 sh_audio_t *sh_audio = d_audio->sh; | |
1242 sh_video_t *sh_video = d_video->sh; | |
1243 off_t newpos; | |
1244 off_t res; | |
1245 TiVoInfo *tivo = 0; | |
1246 | |
1247 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Seeking to %7.1f\n", rel_seek_secs ); | |
1248 | |
1249 if ( ( demuxer->a_streams[ MAX_A_STREAMS - 1 ] ) != 0 ) | |
1250 { | |
1251 tivo = demuxer->a_streams[ MAX_A_STREAMS - 1 ]; | |
1252 tivo->lastAudioEnd = 0; | |
1253 tivo->lastAudioPTS = 0; | |
1254 tivo->lastVideoPTS = 0; | |
1255 } | |
1256 // | |
1257 //================= seek in MPEG ========================== | |
1258 demuxer->filepos = stream_tell( demuxer->stream ); | |
1259 | |
1260 newpos = ( flags & 1 ) ? demuxer->movi_start : demuxer->filepos; | |
1261 | |
1262 if( flags & 2 ) | |
1263 { | |
1264 // float seek 0..1 | |
1265 newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs; | |
1266 } | |
1267 else | |
1268 { | |
1269 // time seek (secs) | |
1270 if( ! sh_video->i_bps ) // unspecified or VBR | |
1271 { | |
1272 newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec | |
1273 } | |
1274 else | |
1275 { | |
1276 newpos += sh_video->i_bps * rel_seek_secs; | |
1277 } | |
1278 } | |
1279 | |
1280 if ( newpos < demuxer->movi_start ) | |
1281 { | |
1282 if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0; | |
1283 if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start; | |
1284 } | |
1285 | |
1286 res = newpos / CHUNKSIZE; | |
1287 if ( rel_seek_secs >= 0 ) | |
1288 { | |
1289 newpos = ( res + 1 ) * CHUNKSIZE; | |
1290 } | |
1291 else | |
1292 { | |
1293 newpos = res * CHUNKSIZE; | |
1294 } | |
1295 | |
1296 if ( newpos < 0 ) | |
1297 { | |
1298 newpos = 0; | |
1299 } | |
15581
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1300 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1301 tivo->whichChunk = newpos / CHUNKSIZE; |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1302 |
2e621c99354d
a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents:
15580
diff
changeset
|
1303 stream_seek( demuxer->stream, newpos ); |
10263 | 1304 |
1305 // re-sync video: | |
1306 videobuf_code_len = 0; // reset ES stream buffer | |
1307 | |
1308 ds_fill_buffer( d_video ); | |
1309 if( sh_audio ) | |
1310 { | |
1311 ds_fill_buffer( d_audio ); | |
1312 } | |
1313 | |
1314 while( 1 ) | |
1315 { | |
1316 int i; | |
1317 if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts ) | |
1318 { | |
1319 float a_pts = d_audio->pts; | |
1320 a_pts += ( ds_tell_pts( d_audio ) - sh_audio->a_in_buffer_len ) / | |
1321 (float)sh_audio->i_bps; | |
1322 if( d_video->pts > a_pts ) | |
1323 { | |
1324 skip_audio_frame( sh_audio ); // sync audio | |
1325 continue; | |
1326 } | |
1327 } | |
1328 i = sync_video_packet( d_video ); | |
1329 if( i == 0x1B3 || i == 0x1B8 ) break; // found it! | |
1330 if( !i || !skip_video_packet( d_video ) ) break; // EOF? | |
1331 } | |
1332 if ( subcc_enabled ) | |
1333 { | |
1334 ty_ClearOSD( 0 ); | |
1335 } | |
1336 } | |
1337 | |
1338 int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg ) | |
1339 { | |
1340 demux_stream_t *d_video = demuxer->video; | |
1341 sh_video_t *sh_video = d_video->sh; | |
1342 | |
1343 switch(cmd) | |
1344 { | |
1345 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
1346 if(!sh_video->i_bps) // unspecified or VBR | |
1347 return DEMUXER_CTRL_DONTKNOW; | |
16346
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16175
diff
changeset
|
1348 *((double *)arg)= |
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16175
diff
changeset
|
1349 ((double)demuxer->movi_end-demuxer->movi_start)/sh_video->i_bps; |
10263 | 1350 return DEMUXER_CTRL_GUESS; |
1351 | |
1352 case DEMUXER_CTRL_GET_PERCENT_POS: | |
1353 return DEMUXER_CTRL_DONTKNOW; | |
1354 default: | |
1355 return DEMUXER_CTRL_NOTIMPL; | |
1356 } | |
1357 } | |
1358 | |
1359 | |
17174
83a8c738be89
make demuxer seek and close functions return void, patch by Dominik Mierzejewski
wanderer
parents:
17012
diff
changeset
|
1360 static void demux_close_ty( demuxer_t *demux ) |
10263 | 1361 { |
1362 TiVoInfo *tivo = 0; | |
1363 | |
1364 if ( ( demux->a_streams[ MAX_A_STREAMS - 1 ] ) != 0 ) | |
1365 { | |
1366 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; | |
1367 free( tivo ); | |
1368 demux->a_streams[ MAX_A_STREAMS - 1 ] = 0; | |
1369 sub_justify = 0; | |
1370 } | |
1371 } | |
1372 | |
1373 | |
16175 | 1374 static int ty_check_file(demuxer_t* demuxer) |
1375 { | |
1376 return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0; | |
1377 } | |
1378 | |
1379 | |
1380 static demuxer_t* demux_open_ty(demuxer_t* demuxer) | |
1381 { | |
1382 sh_audio_t *sh_audio=NULL; | |
1383 sh_video_t *sh_video=NULL; | |
1384 | |
1385 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1386 | |
1387 if(demuxer->audio->id!=-2) { | |
1388 if(!ds_fill_buffer(demuxer->audio)){ | |
1389 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
1390 demuxer->audio->sh=NULL; | |
1391 } else { | |
1392 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
1393 } | |
1394 } | |
1395 | |
1396 return demuxer; | |
1397 } | |
1398 | |
1399 | |
1400 demuxer_desc_t demuxer_desc_mpeg_ty = { | |
1401 "TiVo demuxer", | |
1402 "tivo", | |
1403 "TiVo", | |
1404 "Christopher R. Wingert", | |
1405 "Demux streams from TiVo", | |
1406 DEMUXER_TYPE_MPEG_TY, | |
1407 0, // unsafe autodetect | |
1408 ty_check_file, | |
1409 demux_ty_fill_buffer, | |
1410 demux_open_ty, | |
1411 demux_close_ty, | |
1412 demux_seek_ty, | |
1413 demux_ty_control | |
1414 }; |