annotate libmpdemux/demux_ty.c @ 11869:c10bd91a4eb2

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