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