annotate libmpdemux/demux_ty.c @ 30374:e216d80cd56c

typo fix, accidently reverted the new year patch with previous commit
author Gabrov
date Sun, 24 Jan 2010 03:19:47 +0000
parents 83425130939d
children 737b7fd47ef4
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 *
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
8 * Olaf Beck and Tridge (indirectly) were essential at providing
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
9 * information regarding the format of the TiVo streams.
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
10 *
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
11 * However, no code in the following subsection is directly copied from
10263
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 *
26742
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
14 * This file is part of MPlayer.
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
15 *
26742
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
16 * MPlayer is free software; you can redistribute it and/or modify
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
17 * it under the terms of the GNU General Public License as published by
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
18 * the Free Software Foundation; either version 2 of the License, or
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
19 * (at your option) any later version.
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
20 *
26742
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
21 * MPlayer is distributed in the hope that it will be useful,
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
24 * GNU General Public License for more details.
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
25 *
26742
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
26 * You should have received a copy of the GNU General Public License along
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
27 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0c1db5fd3f79 Use standard license headers with standard formatting.
diego
parents: 25883
diff changeset
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
10263
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
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 20141
diff changeset
42 #include "stream/stream.h"
10263
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"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16877
diff changeset
46 #include "sub_cc.h"
23703
9fb716ab06a3 Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents: 23381
diff changeset
47 #include "libavutil/avstring.h"
24461
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
48 #include "libavutil/intreadwrite.h"
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
49
28051
9e739bdb049c Get rid of pointless 'extern' keywords.
diego
parents: 26742
diff changeset
50 void skip_audio_frame( sh_audio_t *sh_audio );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
51 extern int sub_justify;
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 // 2/c0: audio data
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
54 // 3/c0: audio packet header (PES header)
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
55 // 4/c0: audio data (S/A only?)
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
56 // 9/c0: audio packet header, AC-3 audio
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
57 // 2/e0: video data
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
58 // 6/e0: video packet header (PES header)
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
59 // 7/e0: video sequence header start
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
60 // 8/e0: video I-frame header start
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
61 // a/e0: video P-frame header start
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
62 // b/e0: video B-frame header start
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
63 // c/e0: video GOP header start
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
64 // e/01: closed-caption data
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
65 // e/02: Extended data services data
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
66
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
67
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
68 #define TIVO_PES_FILEID 0xf5467abd
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
69 #define TIVO_PART_LENGTH 0x20000000
10263
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 #define CHUNKSIZE ( 128 * 1024 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
72 #define MAX_AUDIO_BUFFER ( 16 * 1024 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
73
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
74 #define TY_V 1
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
75 #define TY_A 2
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
76
24499
1e57ce7abdbd Do not uselessly name structs
reimar
parents: 24498
diff changeset
77 typedef struct
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
78 {
24498
7d955b1de13c Remove another variable and reorder to avoid wasting space due to alignment
reimar
parents: 24497
diff changeset
79 off_t startOffset;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
80 off_t fileSize;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
81 int chunks;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
82 } tmf_fileParts;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
83
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
84 #define MAX_TMF_PARTS 16
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
85
24499
1e57ce7abdbd Do not uselessly name structs
reimar
parents: 24498
diff changeset
86 typedef struct
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
87 {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
88 int whichChunk;
29898
83425130939d Move 128kB buffer from stack to demuxer context.
reimar
parents: 28051
diff changeset
89 unsigned char chunk[ CHUNKSIZE ];
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
90
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
91 unsigned char lastAudio[ MAX_AUDIO_BUFFER ];
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
92 int lastAudioEnd;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
93
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
94 int tivoType; // 1 = SA, 2 = DTiVo
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
95
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
96 int64_t lastAudioPTS;
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
97 int64_t lastVideoPTS;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
98
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
99 off_t size;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
100 int readHeader;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
101
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
102 int tmf;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
103 tmf_fileParts tmfparts[ MAX_TMF_PARTS ];
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
104 int tmf_totalparts;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
105 } TiVoInfo;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
106
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
107 off_t vstream_streamsize( );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
108 void ty_ClearOSD( int start );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
109
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
110 // ===========================================================================
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
111 #define TMF_SIG "showing.xml"
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
112
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
113 // ===========================================================================
24443
96dc3e753182 Make demux_ty internal functions static
reimar
parents: 24442
diff changeset
114 static int ty_tmf_filetoparts( demuxer_t *demux, TiVoInfo *tivo )
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
115 {
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
116 int parts = 0;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
117
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
118 stream_seek(demux->stream, 0);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
119
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
120 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Dumping tar contents\n" );
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
121 while (!demux->stream->eof)
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
122 {
24488
d6c49e8a8046 Move some more variable declarations
reimar
parents: 24487
diff changeset
123 char header[ 512 ];
d6c49e8a8046 Move some more variable declarations
reimar
parents: 24487
diff changeset
124 char *name;
24500
dcb02dadd06c Get rid of bloated ty_extension function
reimar
parents: 24499
diff changeset
125 char *extension;
24488
d6c49e8a8046 Move some more variable declarations
reimar
parents: 24487
diff changeset
126 char *sizestr;
d6c49e8a8046 Move some more variable declarations
reimar
parents: 24487
diff changeset
127 int size;
d6c49e8a8046 Move some more variable declarations
reimar
parents: 24487
diff changeset
128 off_t skip;
24457
fd8830d276ca More simplifications
reimar
parents: 24456
diff changeset
129 if (stream_read(demux->stream, header, 512) < 512)
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
130 {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
131 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Read bad\n" );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
132 break;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
133 }
24448
044d3ec97bf7 Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents: 24447
diff changeset
134 name = header;
044d3ec97bf7 Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents: 24447
diff changeset
135 name[99] = 0;
044d3ec97bf7 Avoid strlcpy, tar headers already have space to ensure 0-termination
reimar
parents: 24447
diff changeset
136 sizestr = &header[124];
24449
1007f99949af 10l, placed terminating 0 at the wrong place.
reimar
parents: 24448
diff changeset
137 sizestr[11] = 0;
24442
9fc610537539 Use strtol instead of horribly suboptimal ty_octaltodecimal
reimar
parents: 24423
diff changeset
138 size = strtol(sizestr, NULL, 8);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
139
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
140 mp_msg( MSGT_DEMUX, MSGL_DBG3, "name %-20.20s size %-12.12s %d\n",
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
141 name, sizestr, size );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
142
24500
dcb02dadd06c Get rid of bloated ty_extension function
reimar
parents: 24499
diff changeset
143 extension = strrchr(name, '.');
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
144 if (extension && strcmp(extension, ".ty") == 0)
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
145 {
24455
3ae0e3067f99 Move boundary check before use!
reimar
parents: 24453
diff changeset
146 if ( parts >= MAX_TMF_PARTS ) {
3ae0e3067f99 Move boundary check before use!
reimar
parents: 24453
diff changeset
147 mp_msg( MSGT_DEMUX, MSGL_ERR, "ty:tmf too big\n" );
3ae0e3067f99 Move boundary check before use!
reimar
parents: 24453
diff changeset
148 break;
3ae0e3067f99 Move boundary check before use!
reimar
parents: 24453
diff changeset
149 }
24447
c6253f3b5f47 Do not ignore last chunk in .tmf files, it will cause part of the file to be
reimar
parents: 24446
diff changeset
150 tivo->tmfparts[ parts ].fileSize = size;
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
151 tivo->tmfparts[ parts ].startOffset = stream_tell(demux->stream);
24450
d8b25c8a4ea4 Small simplifications
reimar
parents: 24449
diff changeset
152 tivo->tmfparts[ parts ].chunks = size / CHUNKSIZE;
24502
0266e095b2d7 Make one mp_msg call out of 3
reimar
parents: 24501
diff changeset
153 mp_msg(MSGT_DEMUX, MSGL_DBG3,
0266e095b2d7 Make one mp_msg call out of 3
reimar
parents: 24501
diff changeset
154 "tmf_filetoparts(): index %d, chunks %d\n"
0266e095b2d7 Make one mp_msg call out of 3
reimar
parents: 24501
diff changeset
155 "tmf_filetoparts(): size %"PRId64"\n"
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16346
diff changeset
156 "tmf_filetoparts(): startOffset %"PRId64"\n",
24502
0266e095b2d7 Make one mp_msg call out of 3
reimar
parents: 24501
diff changeset
157 parts, tivo->tmfparts[ parts ].chunks,
0266e095b2d7 Make one mp_msg call out of 3
reimar
parents: 24501
diff changeset
158 tivo->tmfparts[ parts ].fileSize, tivo->tmfparts[ parts ].startOffset
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
159 );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
160 parts++;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
161 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
162
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
163 // size rounded up to blocks
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
164 skip = (size + 511) & ~511;
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
165 stream_skip(demux->stream, skip);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
166 }
24501
0d9578ee65cf Simpler and more robust tar parsing
reimar
parents: 24500
diff changeset
167 stream_reset(demux->stream);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
168 tivo->tmf_totalparts = parts;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
169 mp_msg( MSGT_DEMUX, MSGL_DBG3,
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
170 "tmf_filetoparts(): No More Part Files %d\n", parts );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
171
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
172 return 1;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
173 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
174
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
175
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
176 // ===========================================================================
24451
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
177 static off_t tmf_filetooffset(TiVoInfo *tivo, int chunk)
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
178 {
24451
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
179 int i;
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
180 for (i = 0; i < tivo->tmf_totalparts; i++) {
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
181 if (chunk < tivo->tmfparts[i].chunks)
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
182 return tivo->tmfparts[i].startOffset + chunk * CHUNKSIZE;
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
183 chunk -= tivo->tmfparts[i].chunks;
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
184 }
abcfa91fcc9a Simplify tmf_filetooffset
reimar
parents: 24450
diff changeset
185 return -1;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
186 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
187
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
188
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
189 // ===========================================================================
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
190 static int tmf_load_chunk( demuxer_t *demux, TiVoInfo *tivo,
24506
1639f5402540 get rid of pointless size parameter for tmf_load_chunk
reimar
parents: 24505
diff changeset
191 unsigned char *buff, int readChunk )
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
192 {
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
193 off_t fileoffset;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
194 int count;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
195
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
196 mp_msg( MSGT_DEMUX, MSGL_DBG3, "\ntmf_load_chunk() begin %d\n",
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
197 readChunk );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
198
24452
f71e3d4c2816 Simplify EOF handling
reimar
parents: 24451
diff changeset
199 fileoffset = tmf_filetooffset(tivo, readChunk);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
200
24503
5a70ac2aea03 Simplify another two ifs into one
reimar
parents: 24502
diff changeset
201 if (fileoffset == -1 || !stream_seek(demux->stream, fileoffset)) {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
202 mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" );
24464
41c96af4be72 Yet more cosmetics
reimar
parents: 24463
diff changeset
203 return 0;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
204 }
24506
1639f5402540 get rid of pointless size parameter for tmf_load_chunk
reimar
parents: 24505
diff changeset
205 count = stream_read( demux->stream, buff, CHUNKSIZE );
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
206 demux->filepos = stream_tell( demux->stream );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
207
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
208 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() count %x\n",
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
209 count );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
210
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
211 mp_msg( MSGT_DEMUX, MSGL_DBG3,
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
212 "tmf_load_chunk() bytes %x %x %x %x %x %x %x %x\n",
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
213 buff[ 0 ], buff[ 1 ], buff[ 2 ], buff[ 3 ],
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
214 buff[ 4 ], buff[ 5 ], buff[ 6 ], buff[ 7 ] );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
215
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
216 mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() end\n" );
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
217
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
218 return count;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
219 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
220
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
221 // ===========================================================================
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
222
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
223 // DTiVo MPEG 336, 480, 576, 768
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
224 // SA TiVo 864
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
225 // DTiVo AC-3 1550
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
226 //
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
227 #define SERIES1_PTS_LENGTH 11
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
228 #define SERIES1_PTS_OFFSET 6
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
229 #define SERIES2_PTS_LENGTH 16
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
230 #define SERIES2_PTS_OFFSET 9
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
231 #define AC3_PTS_LENGTH 16
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
232 #define AC3_PTS_OFFSET 9
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
233
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
234 static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
235 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
236 // AC-3
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
237 if ( size == 1550 || size == 1552 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
238 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
239 *ptsOffset = AC3_PTS_OFFSET;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
240 *ptsLen = AC3_PTS_LENGTH;
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
241 return 1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
242 }
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 // MPEG
24471
516c6a2277b1 Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents: 24470
diff changeset
245 if ( (size & 15) == (SERIES1_PTS_LENGTH & 15) )
10263
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 *ptsOffset = SERIES1_PTS_OFFSET;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
248 *ptsLen = SERIES1_PTS_LENGTH;
24470
656a62a00e94 Simplify IsValidAudioPacket
reimar
parents: 24469
diff changeset
249 return 1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
250 }
24471
516c6a2277b1 Greatly simplify IsValidAudioPacket, though this might break something
reimar
parents: 24470
diff changeset
251 if ( (size & 15) == (SERIES2_PTS_LENGTH & 15) )
10263
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 *ptsOffset = SERIES2_PTS_OFFSET;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
254 *ptsLen = SERIES2_PTS_LENGTH;
24470
656a62a00e94 Simplify IsValidAudioPacket
reimar
parents: 24469
diff changeset
255 return 1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
256 }
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
257 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Tossing Audio Packet Size %d\n",
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
258 size );
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
259 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
260 }
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
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
263 static int64_t get_ty_pts( unsigned char *buf )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
264 {
24461
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
265 int a = buf[0] & 0xe;
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
266 int b = AV_RB16(buf + 1);
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
267 int c = AV_RB16(buf + 3);
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
268
24461
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
269 if (!(1 & a & b & c)) // invalid MPEG timestamp
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
270 return MP_NOPTS_VALUE;
24461
921de822048c Fix completely broken get_ty_pts (it's an ordinary MPEG timestamp)
reimar
parents: 24460
diff changeset
271 a >>= 1; b >>= 1; c >>= 1;
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
272 return (((uint64_t)a) << 30) | (b << 15) | c;
10263
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
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
275 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer,
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
276 int size )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
277 {
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
278 if ( tivo->lastAudioEnd + size < MAX_AUDIO_BUFFER )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
279 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
280 memcpy( &tivo->lastAudio[ tivo->lastAudioEnd ],
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
281 buffer, size );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
282 tivo->lastAudioEnd += size;
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 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
285 mp_msg( MSGT_DEMUX, MSGL_ERR,
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
286 "ty:WARNING - Would have blown my audio buffer\n" );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
287 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
288
24496
42693ad6dd30 Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents: 24495
diff changeset
289 static void demux_ty_CopyToDemuxPacket( demux_stream_t *ds,
24497
713ad2d3878d PTS should be passed as int64_t to demux_ty_CopyToDemuxPacket
reimar
parents: 24496
diff changeset
290 unsigned char *buffer, int size, off_t pos, int64_t pts )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
291 {
24482
e5eb9ccd6679 Remove some commented-out debugging code
reimar
parents: 24481
diff changeset
292 demux_packet_t *dp = new_demux_packet( size );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
293 memcpy( dp->buffer, buffer, size );
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
294 if (pts != MP_NOPTS_VALUE)
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
295 dp->pts = pts / 90000.0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
296 dp->pos = pos;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
297 dp->flags = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
298 ds_add_packet( ds, dp );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
299 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
300
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
301 static int demux_ty_FindESHeader( uint8_t nal,
24478
43c9c72b8c54 Simplify demux_ty_FindESHeader
reimar
parents: 24477
diff changeset
302 unsigned char *buffer, int bufferSize )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
303 {
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
304 uint32_t search = 0x00000100 | nal;
24483
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
305 uint32_t found = -1;
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
306 uint8_t *p = buffer;
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
307 uint8_t *end = p + bufferSize;
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
308 while (p < end) {
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
309 found <<= 8;
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
310 found |= *p++;
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
311 if (found == search)
e24dd407fb58 Optimize demux_ty_FindESHeader
reimar
parents: 24482
diff changeset
312 return p - buffer - 4;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
313 }
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
314 return -1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
315 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
316
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
317 static void demux_ty_FindESPacket( uint8_t nal,
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
318 unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
319 {
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
320 *esOffset1 = demux_ty_FindESHeader(nal, buffer, bufferSize);
24480
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
321 if (*esOffset1 == -1) {
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
322 *esOffset2 = -1;
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
323 return;
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
324 }
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
325 buffer += *esOffset1 + 1;
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
326 bufferSize -= *esOffset1 + 1;
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
327 *esOffset2 = demux_ty_FindESHeader(nal, buffer, bufferSize);
24480
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
328 if (*esOffset2 != -1)
a365d70938b3 Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
reimar
parents: 24479
diff changeset
329 *esOffset2 += *esOffset1 + 1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
330 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
331
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
332 #define VIDEO_NAL 0xe0
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
333 #define AUDIO_NAL 0xc0
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
334 #define AC3_NAL 0xbd
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
335
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
336 static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
10263
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 invalidType = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
339 int errorHeader = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
340 int recordsDecoded = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
341
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
342 int readSize;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
343
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
344 int numberRecs;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
345 unsigned char *recPtr;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
346 int offset;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
347
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
348 int counter;
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 aid;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
351
24469
afbab72dbf2c Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents: 24468
diff changeset
352 TiVoInfo *tivo = demux->priv;
29898
83425130939d Move 128kB buffer from stack to demuxer context.
reimar
parents: 28051
diff changeset
353 unsigned char *chunk = tivo->chunk;
10263
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 if ( demux->stream->type == STREAMTYPE_DVD )
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
356 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
357
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
358 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty processing\n" );
10263
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 if( demux->stream->eof ) return 0;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
361
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
362 // ======================================================================
11000
6e35326c742f many small typo and grammar fixes
gabucino
parents: 10263
diff changeset
363 // 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
364 // ======================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
365 #ifdef STREAMTYPE_STREAM_TY
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
366 if ( demux->stream->type == STREAMTYPE_STREAM_TY )
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 // The vstream code figures out the exact size of the stream
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
369 demux->movi_start = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
370 demux->movi_end = vstream_streamsize();
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
371 tivo->size = vstream_streamsize();
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 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
374 #endif
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 // 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
377 // calculate the ACTUAL stream size
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
378 // 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
379 // extract program did the "right thing"
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
380 if ( tivo->readHeader == 0 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
381 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
382 off_t filePos;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
383 tivo->readHeader = 1;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
384
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
385 filePos = demux->filepos;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
386 stream_seek( demux->stream, 0 );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
387
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
388 readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
389
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
390 if ( memcmp( chunk, TMF_SIG, sizeof( TMF_SIG ) ) == 0 )
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
391 {
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
392 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Detected a tmf\n" );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
393 tivo->tmf = 1;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
394 ty_tmf_filetoparts( demux, tivo );
24506
1639f5402540 get rid of pointless size parameter for tmf_load_chunk
reimar
parents: 24505
diff changeset
395 readSize = tmf_load_chunk( demux, tivo, chunk, 0 );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
396 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
397
24467
8231358722ed get rid of pointless pesFileId variables
reimar
parents: 24466
diff changeset
398 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID )
10263
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 off_t numberParts;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
401
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
402 readSize = 0;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
403
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
404 if ( tivo->tmf != 1 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
405 {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
406 off_t offset;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
407
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
408 numberParts = demux->stream->end_pos / TIVO_PART_LENGTH;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
409 offset = numberParts * TIVO_PART_LENGTH;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
410
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
411 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n",
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
412 (int64_t)numberParts );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
413
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
414 if ( offset + CHUNKSIZE < demux->stream->end_pos )
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
415 {
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
416 stream_seek( demux->stream, offset );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
417 readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
418 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
419 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
420 else
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
421 {
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
422 numberParts = tivo->tmf_totalparts;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
423 offset = numberParts * TIVO_PART_LENGTH;
24506
1639f5402540 get rid of pointless size parameter for tmf_load_chunk
reimar
parents: 24505
diff changeset
424 readSize = tmf_load_chunk( demux, tivo, chunk,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
425 numberParts * ( TIVO_PART_LENGTH - CHUNKSIZE ) /
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
426 CHUNKSIZE );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
427 }
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
428
24467
8231358722ed get rid of pointless pesFileId variables
reimar
parents: 24466
diff changeset
429 if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID )
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
430 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
431 int size = AV_RB24(chunk + 12);
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
432 size -= 4;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
433 size *= CHUNKSIZE;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
434 tivo->size = numberParts * TIVO_PART_LENGTH;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
435 tivo->size += size;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
436 mp_msg( MSGT_DEMUX, MSGL_DBG3,
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16346
diff changeset
437 "ty:Header Calc Stream Size %"PRId64"\n", tivo->size );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
438 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
439 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
440
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
441 if ( demux->stream->start_pos > 0 )
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
442 filePos = demux->stream->start_pos;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
443 stream_seek( demux->stream, filePos );
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
444 demux->filepos = stream_tell( demux->stream );
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
445 tivo->whichChunk = filePos / CHUNKSIZE;
10263
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 demux->movi_start = 0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
448 demux->movi_end = tivo->size;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
449 }
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 // Give a clue as to where we are in the stream
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 mp_msg( MSGT_DEMUX, MSGL_DBG3,
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
455 "ty:ty header size %"PRIx64"\n", (int64_t)tivo->size );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
456 mp_msg( MSGT_DEMUX, MSGL_DBG3,
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
457 "ty:ty which Chunk %d\n", tivo->whichChunk );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
458 mp_msg( MSGT_DEMUX, MSGL_DBG3,
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
459 "ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
460 mp_msg( MSGT_DEMUX, MSGL_DBG3,
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17174
diff changeset
461 "\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
462
24464
41c96af4be72 Yet more cosmetics
reimar
parents: 24463
diff changeset
463 if ( tivo->size > 0 && stream_tell( demux->stream ) > tivo->size )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
464 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
465 demux->stream->eof = 1;
24464
41c96af4be72 Yet more cosmetics
reimar
parents: 24463
diff changeset
466 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
467 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
468
24507
e28f9913f48a Avoid one more code duplication
reimar
parents: 24506
diff changeset
469 do {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
470 if ( tivo->tmf != 1 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
471 {
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
472 // Make sure we are on a 128k boundary
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
473 if ( demux->filepos % CHUNKSIZE != 0 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
474 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
475 int whichChunk = demux->filepos / CHUNKSIZE;
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
476 if ( demux->filepos % CHUNKSIZE > CHUNKSIZE / 2 )
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
477 whichChunk++;
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
478 stream_seek( demux->stream, whichChunk * CHUNKSIZE );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
479 }
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
480
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
481 demux->filepos = stream_tell( demux->stream );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
482 tivo->whichChunk = demux->filepos / CHUNKSIZE;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
483 readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
484 if ( readSize != CHUNKSIZE )
24464
41c96af4be72 Yet more cosmetics
reimar
parents: 24463
diff changeset
485 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
486 }
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
487 else
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
488 {
24506
1639f5402540 get rid of pointless size parameter for tmf_load_chunk
reimar
parents: 24505
diff changeset
489 readSize = tmf_load_chunk( demux, tivo, chunk, tivo->whichChunk );
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
490 if ( readSize != CHUNKSIZE )
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
491 return 0;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
492 tivo->whichChunk++;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
493 }
24507
e28f9913f48a Avoid one more code duplication
reimar
parents: 24506
diff changeset
494 if (AV_RB32(chunk) == TIVO_PES_FILEID)
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
495 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Skipping PART Header\n" );
24507
e28f9913f48a Avoid one more code duplication
reimar
parents: 24506
diff changeset
496 } while (AV_RB32(chunk) == TIVO_PES_FILEID);
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
497
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
498 mp_msg( MSGT_DEMUX, MSGL_DBG3,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
499 "\nty:actual current offset %"PRIx64"\n", stream_tell( demux->stream ) -
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
500 CHUNKSIZE );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
501
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
502
12860
03d3ab9f6400 embarassing typo
diego
parents: 11000
diff changeset
503 // Let's make a Video Demux Stream for MPlayer
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
504 aid = 0x0;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
505 if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
506 if( demux->video->id == -1 ) demux->video->id = aid;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
507 if( demux->video->id == aid )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
508 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
509 demux_stream_t *ds = demux->video;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
510 if( !ds->sh ) ds->sh = demux->v_streams[ aid ];
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
511 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
512
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
513 // ======================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
514 // Finally, we get to actually parse the chunk
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
515 // ======================================================================
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
516 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
517 numberRecs = chunk[ 0 ];
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
518 recPtr = &chunk[ 4 ];
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
519 offset = numberRecs * 16 + 4;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
520 for ( counter = 0 ; counter < numberRecs ; counter++ )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
521 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
522 int size = AV_RB24(recPtr) >> 4;
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
523 int type = recPtr[ 3 ];
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
524 int nybbleType = recPtr[ 2 ] & 0x0f;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
525 recordsDecoded++;
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 mp_msg( MSGT_DEMUX, MSGL_DBG3,
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
528 "ty:Record Type %x/%x %d\n", nybbleType, type, size );
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 // ================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
531 // Video Parsing
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
532 // ================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
533 if ( type == 0xe0 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
534 {
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
535 if ( size > 0 && size + offset <= CHUNKSIZE )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
536 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
537 int esOffset1 = demux_ty_FindESHeader( VIDEO_NAL, &chunk[ offset ],
24478
43c9c72b8c54 Simplify demux_ty_FindESHeader
reimar
parents: 24477
diff changeset
538 size);
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
539 if ( esOffset1 != -1 )
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
540 tivo->lastVideoPTS = get_ty_pts(
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
541 &chunk[ offset + esOffset1 + 9 ] );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
542
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
543 // Do NOT Pass the PES Header onto the MPEG2 Decode
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
544 if( nybbleType != 0x06 )
24496
42693ad6dd30 Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents: 24495
diff changeset
545 demux_ty_CopyToDemuxPacket( demux->video,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
546 &chunk[ offset ], size, demux->filepos + offset,
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
547 tivo->lastVideoPTS );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
548 offset += size;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
549 }
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
550 else
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
551 errorHeader++;
10263
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 // ================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
554 // Audio Parsing
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
555 // ================================================================
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
556 else if ( type == 0xc0 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
557 {
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
558 if ( size > 0 && size + offset <= CHUNKSIZE )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
559 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
560 if( demux->audio->id == -1 )
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 if ( nybbleType == 0x02 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
563 continue; // DTiVo inconclusive, wait for more
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
564 else if ( nybbleType == 0x09 )
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 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
567 aid = 0x80; // AC-3
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
568 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
569 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
570 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
571 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
572 aid = 0x0; // MPEG Audio
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
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
575 demux->audio->id = aid;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
576 if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
577 if( demux->audio->id == aid )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
578 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
579 demux_stream_t *ds = demux->audio;
15580
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
580 if( !ds->sh ) {
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
581 sh_audio_t* sh_a;
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
582 ds->sh = demux->a_streams[ aid ];
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
583 sh_a = (sh_audio_t*)ds->sh;
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
584 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id)
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
585 case 0x00: sh_a->format=0x50;break; // mpeg
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
586 case 0xA0: sh_a->format=0x10001;break; // dvd pcm
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
587 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
588 else sh_a->format=0x2000;break; // ac3
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
589 }
fa5573007038 fix audio init crash
joey
parents: 14502
diff changeset
590 }
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
591 }
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
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
594 aid = demux->audio->id;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
595
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 // SA DTiVo Audio Data, no PES
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
598 // ================================================
24476
b42dd327f81f Another piece of duplicate code
reimar
parents: 24475
diff changeset
599 if ( nybbleType == 0x02 || nybbleType == 0x04 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
600 {
24476
b42dd327f81f Another piece of duplicate code
reimar
parents: 24475
diff changeset
601 if ( nybbleType == 0x02 && tivo->tivoType == 2 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
602 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
603 else
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
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
606 mp_msg( MSGT_DEMUX, MSGL_DBG3,
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
607 "ty:Adding Audio Packet Size %d\n", size );
24496
42693ad6dd30 Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents: 24495
diff changeset
608 demux_ty_CopyToDemuxPacket( demux->audio,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
609 &chunk[ offset ], size, ( demux->filepos + offset ),
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
610 tivo->lastAudioPTS );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
611 }
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
24475
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
614 // 3 - MPEG Audio with PES Header, either SA or DTiVo
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
615 // 9 - DTiVo AC3 Audio Data with PES Header
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
616 // ================================================
24475
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
617 if ( nybbleType == 0x03 || nybbleType == 0x09 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
618 {
24477
8c9d86adb28e Move variable declarations into the block where they are used
reimar
parents: 24476
diff changeset
619 int esOffset1, esOffset2;
24475
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
620 if ( nybbleType == 0x03 )
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
621 esOffset1 = demux_ty_FindESHeader( AUDIO_NAL, &chunk[ offset ],
24478
43c9c72b8c54 Simplify demux_ty_FindESHeader
reimar
parents: 24477
diff changeset
622 size);
10263
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 // SA PES Header, No Audio Data
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
625 // ================================================
24475
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
626 if ( nybbleType == 0x03 && esOffset1 == 0 && size == 16 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
627 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
628 tivo->tivoType = 1;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
629 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset +
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
630 SERIES2_PTS_OFFSET ] );
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 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
633 // DTiVo Audio with PES Header
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
634 // ================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
635 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
636 tivo->tivoType = 2;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
637
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
638 demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size );
24484
cf224658fbe2 Further simplify demux_ty_FindESHeader
reimar
parents: 24483
diff changeset
639 demux_ty_FindESPacket( nybbleType == 9 ? AC3_NAL : AUDIO_NAL,
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
640 tivo->lastAudio, tivo->lastAudioEnd, &esOffset1,
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
641 &esOffset2 );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
642
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
643 if ( esOffset1 != -1 && esOffset2 != -1 )
10263
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 int packetSize = esOffset2 - esOffset1;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
646 int headerSize;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
647 int ptsOffset;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
648
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
649 if ( IsValidAudioPacket( packetSize, &ptsOffset,
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
650 &headerSize ) )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
651 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
652 mp_msg( MSGT_DEMUX, MSGL_DBG3,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
653 "ty:Adding DTiVo Audio Packet Size %d\n",
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
654 packetSize );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
655
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
656 tivo->lastAudioPTS = get_ty_pts(
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
657 &tivo->lastAudio[ esOffset1 + ptsOffset ] );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
658
24475
7e10a426b257 Avoid a big piece of duplicated code
reimar
parents: 24474
diff changeset
659 if (nybbleType == 9) headerSize = 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
660 demux_ty_CopyToDemuxPacket
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
661 (
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
662 demux->audio,
24486
20a8ee3f041a A few more useless ()
reimar
parents: 24485
diff changeset
663 &tivo->lastAudio[ esOffset1 + headerSize ],
20a8ee3f041a A few more useless ()
reimar
parents: 24485
diff changeset
664 packetSize - headerSize,
20a8ee3f041a A few more useless ()
reimar
parents: 24485
diff changeset
665 demux->filepos + offset,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
666 tivo->lastAudioPTS
10263
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
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
669 }
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 // Collapse the Audio Buffer
24485
cb919d4b54e8 Minor simplifications
reimar
parents: 24484
diff changeset
672 tivo->lastAudioEnd -= esOffset2;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
673 memmove( &tivo->lastAudio[ 0 ],
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
674 &tivo->lastAudio[ esOffset2 ],
24485
cb919d4b54e8 Minor simplifications
reimar
parents: 24484
diff changeset
675 tivo->lastAudioEnd );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
676 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
677 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
678 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
679
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
680 offset += size;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
681 }
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
682 else
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
683 errorHeader++;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
684 }
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
685 // ================================================================
24474
1754f9ab919e Get rid of more code duplication
reimar
parents: 24473
diff changeset
686 // 1 = Closed Caption
1754f9ab919e Get rid of more code duplication
reimar
parents: 24473
diff changeset
687 // 2 = Extended Data Services
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
688 // ================================================================
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
689 else if ( type == 0x01 || type == 0x02 )
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
690 {
24474
1754f9ab919e Get rid of more code duplication
reimar
parents: 24473
diff changeset
691 unsigned char lastXDS[ 16 ];
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
692 int b = AV_RB24(recPtr) >> 4;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
693 b &= 0x7f7f;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
694
24474
1754f9ab919e Get rid of more code duplication
reimar
parents: 24473
diff changeset
695 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:%s %04x\n", type == 1 ? "CC" : "XDS", b);
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
696
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
697 lastXDS[ 0x00 ] = 0x00;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
698 lastXDS[ 0x01 ] = 0x00;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
699 lastXDS[ 0x02 ] = 0x01;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
700 lastXDS[ 0x03 ] = 0xb2;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
701 lastXDS[ 0x04 ] = 'T';
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
702 lastXDS[ 0x05 ] = 'Y';
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
703 lastXDS[ 0x06 ] = type;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
704 lastXDS[ 0x07 ] = b >> 8;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
705 lastXDS[ 0x08 ] = b;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
706 if ( subcc_enabled )
24496
42693ad6dd30 Remove now useless parameters from demux_ty_CopyToDemuxPacket
reimar
parents: 24495
diff changeset
707 demux_ty_CopyToDemuxPacket( demux->video, lastXDS, 0x09,
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
708 demux->filepos + offset, tivo->lastVideoPTS );
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
709 }
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
710 // ================================================================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
711 // Unknown
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
712 // ================================================================
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
713 else
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
714 {
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
715 if ( size > 0 && size + offset <= CHUNKSIZE )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
716 offset += size;
24489
97eba82233f5 live recordings can contain 0-size type 0 chunks, ignore them instead
reimar
parents: 24488
diff changeset
717 if (type != 3 && type != 5 && (type != 0 || size > 0)) {
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
718 mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type );
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
719 invalidType++;
24472
9341d242f432 Reduce code duplication
reimar
parents: 24471
diff changeset
720 }
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
721 }
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
722 recPtr += 16;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
723 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
724
20141
bd3afd5a2e48 Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents: 19614
diff changeset
725 if ( errorHeader > 0 || invalidType > 0 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
726 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
727 mp_msg( MSGT_DEMUX, MSGL_DBG3,
20141
bd3afd5a2e48 Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents: 19614
diff changeset
728 "ty:Error Check - Records %d, Parsed %d, Errors %d + %d\n",
bd3afd5a2e48 Fix misdetection of http://samples.mplayerhq.hu/tta/tivo_misdetect.tta as TiVo file
reimar
parents: 19614
diff changeset
729 numberRecs, recordsDecoded, errorHeader, invalidType );
10263
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 // Invalid MPEG ES Size Check
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
732 if ( errorHeader > numberRecs / 2 )
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
733 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
734
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
735 // Invalid MPEG Stream Type Check
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
736 if ( invalidType > numberRecs / 2 )
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
737 return 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
738 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
739
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
740 demux->filepos = stream_tell( demux->stream );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
741
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
742 return 1;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
743 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
744
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
745 static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags )
10263
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 demux_stream_t *d_audio = demuxer->audio;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
748 demux_stream_t *d_video = demuxer->video;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
749 sh_audio_t *sh_audio = d_audio->sh;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
750 sh_video_t *sh_video = d_video->sh;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
751 off_t newpos;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
752 off_t res;
24469
afbab72dbf2c Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents: 24468
diff changeset
753 TiVoInfo *tivo = demuxer->priv;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
754
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
755 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
756
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
757 tivo->lastAudioEnd = 0;
24463
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
758 tivo->lastAudioPTS = MP_NOPTS_VALUE;
f93cfdc6f4f5 Move timestamps to int64_t and use MP_NOPTS_VALUE
reimar
parents: 24462
diff changeset
759 tivo->lastVideoPTS = MP_NOPTS_VALUE;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
760 //
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
761 //================= seek in MPEG ==========================
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
762 demuxer->filepos = stream_tell( demuxer->stream );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
763
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
764 newpos = ( flags & SEEK_ABSOLUTE ) ? demuxer->movi_start : demuxer->filepos;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
765
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
766 if( flags & SEEK_FACTOR )
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
767 // float seek 0..1
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
768 newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
769 else
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
770 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
771 // time seek (secs)
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
772 if( ! sh_video->i_bps ) // unspecified or VBR
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
773 newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
774 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
775 newpos += sh_video->i_bps * rel_seek_secs;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
776 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
777
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
778 if ( newpos < demuxer->movi_start )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
779 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
780 if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
781 if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
782 }
10263
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 res = newpos / CHUNKSIZE;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
785 if ( rel_seek_secs >= 0 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
786 newpos = ( res + 1 ) * CHUNKSIZE;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
787 else
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
788 newpos = res * CHUNKSIZE;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
789
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
790 if ( newpos < 0 )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
791 newpos = 0;
15581
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
792
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
793 tivo->whichChunk = newpos / CHUNKSIZE;
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
794
2e621c99354d a cleaned-up version of ty demuxer improvements found in tivo-mplayer fork.
joey
parents: 15580
diff changeset
795 stream_seek( demuxer->stream, newpos );
10263
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 // re-sync video:
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
798 videobuf_code_len = 0; // reset ES stream buffer
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
799
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
800 ds_fill_buffer( d_video );
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
801 if( sh_audio )
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
802 ds_fill_buffer( d_audio );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
803
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
804 while( 1 )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
805 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
806 int i;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
807 if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts )
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
808 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
809 float a_pts = d_audio->pts;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
810 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
811 (float)sh_audio->i_bps;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
812 if( d_video->pts > a_pts )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
813 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
814 skip_audio_frame( sh_audio ); // sync audio
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
815 continue;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
816 }
10263
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 i = sync_video_packet( d_video );
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
819 if( i == 0x1B3 || i == 0x1B8 ) break; // found it!
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
820 if( !i || !skip_video_packet( d_video ) ) break; // EOF?
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
821 }
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
822 if ( subcc_enabled )
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
823 ty_ClearOSD( 0 );
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
824 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
825
24443
96dc3e753182 Make demux_ty internal functions static
reimar
parents: 24442
diff changeset
826 static int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
827 {
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
828 demux_stream_t *d_video = demuxer->video;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
829 sh_video_t *sh_video = d_video->sh;
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
830
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
831 switch(cmd)
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
832 {
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
833 case DEMUXER_CTRL_GET_TIME_LENGTH:
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
834 if(!sh_video->i_bps) // unspecified or VBR
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
835 return DEMUXER_CTRL_DONTKNOW;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
836 *(double *)arg=
24446
c9870762ddb5 Cosmetics: remove lots of useless () and {}.
reimar
parents: 24445
diff changeset
837 (double)demuxer->movi_end-demuxer->movi_start/sh_video->i_bps;
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
838 return DEMUXER_CTRL_GUESS;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
839
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
840 case DEMUXER_CTRL_GET_PERCENT_POS:
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
841 return DEMUXER_CTRL_DONTKNOW;
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
842 default:
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
843 return DEMUXER_CTRL_NOTIMPL;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
844 }
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
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
847
17174
83a8c738be89 make demuxer seek and close functions return void, patch by Dominik Mierzejewski
wanderer
parents: 17012
diff changeset
848 static void demux_close_ty( demuxer_t *demux )
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
849 {
24469
afbab72dbf2c Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents: 24468
diff changeset
850 TiVoInfo *tivo = demux->priv;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
851
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
852 free( tivo );
24487
f364db0d1067 Remove tabs and trailing whitespace
reimar
parents: 24486
diff changeset
853 sub_justify = 0;
10263
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
854 }
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
855
0df8816f4665 TiVo demuxer and sub-cc/osd decoder
arpi
parents:
diff changeset
856
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
857 static int ty_check_file(demuxer_t* demuxer)
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
858 {
24469
afbab72dbf2c Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents: 24468
diff changeset
859 TiVoInfo *tivo = calloc(1, sizeof(TiVoInfo));
afbab72dbf2c Do not misuse a_streams for private info, demuxer->priv is for that!
reimar
parents: 24468
diff changeset
860 demuxer->priv = tivo;
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
861 return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
862 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
863
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
864
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
865 static demuxer_t* demux_open_ty(demuxer_t* demuxer)
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
866 {
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
867 sh_audio_t *sh_audio=NULL;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
868 sh_video_t *sh_video=NULL;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
869
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
870 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
871
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
872 if(demuxer->audio->id!=-2) {
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
873 if(!ds_fill_buffer(demuxer->audio)){
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
874 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream);
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
875 demuxer->audio->sh=NULL;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
876 } else {
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
877 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
878 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
879 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
880
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
881 return demuxer;
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
882 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
883
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
884
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 24507
diff changeset
885 const demuxer_desc_t demuxer_desc_mpeg_ty = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
886 "TiVo demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
887 "tivo",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
888 "TiVo",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
889 "Christopher R. Wingert",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
890 "Demux streams from TiVo",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
891 DEMUXER_TYPE_MPEG_TY,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
892 0, // unsafe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
893 ty_check_file,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
894 demux_ty_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
895 demux_open_ty,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
896 demux_close_ty,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
897 demux_seek_ty,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
898 demux_ty_control
6b86089c2edd Demuxer modularization
rtognimp
parents: 15581
diff changeset
899 };