2003-06-09 00:24:49 +00:00
|
|
|
/*
|
|
|
|
* tivo@wingert.org, February 2003
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Christopher R. Wingert
|
|
|
|
*
|
|
|
|
* The license covers the portions of this file regarding TiVo additions.
|
|
|
|
*
|
2007-09-14 20:59:05 +00:00
|
|
|
* Olaf Beck and Tridge (indirectly) were essential at providing
|
|
|
|
* information regarding the format of the TiVo streams.
|
2003-06-09 00:24:49 +00:00
|
|
|
*
|
2007-09-14 20:59:05 +00:00
|
|
|
* However, no code in the following subsection is directly copied from
|
2003-06-09 00:24:49 +00:00
|
|
|
* either author.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-01 12:11:11 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-06-09 00:24:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2003-06-09 00:24:49 +00:00
|
|
|
#include "demuxer.h"
|
|
|
|
#include "parse_es.h"
|
|
|
|
#include "stheader.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "sub_cc.h"
|
2007-07-05 22:01:07 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2007-09-14 17:39:48 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
extern void skip_audio_frame( sh_audio_t *sh_audio );
|
|
|
|
extern int sub_justify;
|
|
|
|
|
|
|
|
// 2/c0: audio data
|
|
|
|
// 3/c0: audio packet header (PES header)
|
|
|
|
// 4/c0: audio data (S/A only?)
|
|
|
|
// 9/c0: audio packet header, AC-3 audio
|
|
|
|
// 2/e0: video data
|
|
|
|
// 6/e0: video packet header (PES header)
|
|
|
|
// 7/e0: video sequence header start
|
|
|
|
// 8/e0: video I-frame header start
|
|
|
|
// a/e0: video P-frame header start
|
|
|
|
// b/e0: video B-frame header start
|
|
|
|
// c/e0: video GOP header start
|
|
|
|
// e/01: closed-caption data
|
2007-09-14 20:59:05 +00:00
|
|
|
// e/02: Extended data services data
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
#define TIVO_PES_FILEID 0xf5467abd
|
|
|
|
#define TIVO_PART_LENGTH 0x20000000
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
#define CHUNKSIZE ( 128 * 1024 )
|
|
|
|
#define MAX_AUDIO_BUFFER ( 16 * 1024 )
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
#define TY_V 1
|
|
|
|
#define TY_A 2
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-15 10:59:27 +00:00
|
|
|
typedef struct
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
2007-09-15 10:58:06 +00:00
|
|
|
off_t startOffset;
|
2005-05-28 20:16:33 +00:00
|
|
|
off_t fileSize;
|
|
|
|
int chunks;
|
|
|
|
} tmf_fileParts;
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
#define MAX_TMF_PARTS 16
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-15 10:59:27 +00:00
|
|
|
typedef struct
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2005-05-28 20:16:33 +00:00
|
|
|
int whichChunk;
|
|
|
|
|
|
|
|
unsigned char lastAudio[ MAX_AUDIO_BUFFER ];
|
|
|
|
int lastAudioEnd;
|
|
|
|
|
|
|
|
int tivoType; // 1 = SA, 2 = DTiVo
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 18:03:36 +00:00
|
|
|
int64_t lastAudioPTS;
|
|
|
|
int64_t lastVideoPTS;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
off_t size;
|
|
|
|
int readHeader;
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
int tmf;
|
|
|
|
tmf_fileParts tmfparts[ MAX_TMF_PARTS ];
|
|
|
|
int tmf_totalparts;
|
2003-06-09 00:24:49 +00:00
|
|
|
} TiVoInfo;
|
|
|
|
|
|
|
|
off_t vstream_streamsize( );
|
|
|
|
void ty_ClearOSD( int start );
|
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
// ===========================================================================
|
|
|
|
#define TMF_SIG "showing.xml"
|
|
|
|
|
|
|
|
// ===========================================================================
|
2007-09-14 15:19:45 +00:00
|
|
|
static int ty_tmf_filetoparts( demuxer_t *demux, TiVoInfo *tivo )
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
|
|
|
int parts = 0;
|
|
|
|
|
2007-09-15 11:33:31 +00:00
|
|
|
stream_seek(demux->stream, 0);
|
2005-05-28 20:16:33 +00:00
|
|
|
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "Dumping tar contents\n" );
|
2007-09-15 11:33:31 +00:00
|
|
|
while (!demux->stream->eof)
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
2007-09-14 21:03:08 +00:00
|
|
|
char header[ 512 ];
|
|
|
|
char *name;
|
2007-09-15 11:03:38 +00:00
|
|
|
char *extension;
|
2007-09-14 21:03:08 +00:00
|
|
|
char *sizestr;
|
|
|
|
int size;
|
|
|
|
off_t skip;
|
2007-09-14 17:03:26 +00:00
|
|
|
if (stream_read(demux->stream, header, 512) < 512)
|
2007-09-14 20:59:05 +00:00
|
|
|
{
|
2005-05-28 20:16:33 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "Read bad\n" );
|
|
|
|
break;
|
|
|
|
}
|
2007-09-14 16:12:02 +00:00
|
|
|
name = header;
|
|
|
|
name[99] = 0;
|
|
|
|
sizestr = &header[124];
|
2007-09-14 16:12:33 +00:00
|
|
|
sizestr[11] = 0;
|
2007-09-14 15:12:46 +00:00
|
|
|
size = strtol(sizestr, NULL, 8);
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-15 11:33:31 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "name %-20.20s size %-12.12s %d\n",
|
|
|
|
name, sizestr, size );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-15 11:03:38 +00:00
|
|
|
extension = strrchr(name, '.');
|
2007-09-15 11:33:31 +00:00
|
|
|
if (extension && strcmp(extension, ".ty") == 0)
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
2007-09-14 16:58:31 +00:00
|
|
|
if ( parts >= MAX_TMF_PARTS ) {
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_ERR, "ty:tmf too big\n" );
|
|
|
|
break;
|
|
|
|
}
|
2007-09-14 16:04:12 +00:00
|
|
|
tivo->tmfparts[ parts ].fileSize = size;
|
2007-09-15 11:33:31 +00:00
|
|
|
tivo->tmfparts[ parts ].startOffset = stream_tell(demux->stream);
|
2007-09-14 16:21:12 +00:00
|
|
|
tivo->tmfparts[ parts ].chunks = size / CHUNKSIZE;
|
2007-09-15 11:35:35 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_DBG3,
|
|
|
|
"tmf_filetoparts(): index %d, chunks %d\n"
|
|
|
|
"tmf_filetoparts(): size %"PRId64"\n"
|
2005-10-13 18:33:56 +00:00
|
|
|
"tmf_filetoparts(): startOffset %"PRId64"\n",
|
2007-09-15 11:35:35 +00:00
|
|
|
parts, tivo->tmfparts[ parts ].chunks,
|
|
|
|
tivo->tmfparts[ parts ].fileSize, tivo->tmfparts[ parts ].startOffset
|
2005-05-28 20:16:33 +00:00
|
|
|
);
|
|
|
|
parts++;
|
|
|
|
}
|
|
|
|
|
2007-09-15 11:33:31 +00:00
|
|
|
// size rounded up to blocks
|
|
|
|
skip = (size + 511) & ~511;
|
|
|
|
stream_skip(demux->stream, skip);
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
2007-09-15 11:33:31 +00:00
|
|
|
stream_reset(demux->stream);
|
2005-05-28 20:16:33 +00:00
|
|
|
tivo->tmf_totalparts = parts;
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
|
|
|
"tmf_filetoparts(): No More Part Files %d\n", parts );
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
return 1;
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
2007-09-14 16:42:46 +00:00
|
|
|
static off_t tmf_filetooffset(TiVoInfo *tivo, int chunk)
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
2007-09-14 16:42:46 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < tivo->tmf_totalparts; i++) {
|
|
|
|
if (chunk < tivo->tmfparts[i].chunks)
|
|
|
|
return tivo->tmfparts[i].startOffset + chunk * CHUNKSIZE;
|
|
|
|
chunk -= tivo->tmfparts[i].chunks;
|
|
|
|
}
|
|
|
|
return -1;
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
2007-09-14 20:59:05 +00:00
|
|
|
static int tmf_load_chunk( demuxer_t *demux, TiVoInfo *tivo,
|
2007-09-15 12:13:45 +00:00
|
|
|
unsigned char *buff, int readChunk )
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
|
|
|
off_t fileoffset;
|
|
|
|
int count;
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "\ntmf_load_chunk() begin %d\n",
|
2005-05-28 20:16:33 +00:00
|
|
|
readChunk );
|
|
|
|
|
2007-09-14 16:44:52 +00:00
|
|
|
fileoffset = tmf_filetooffset(tivo, readChunk);
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-15 11:41:47 +00:00
|
|
|
if (fileoffset == -1 || !stream_seek(demux->stream, fileoffset)) {
|
2005-05-28 20:16:33 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_ERR, "Read past EOF()\n" );
|
2007-09-14 18:19:10 +00:00
|
|
|
return 0;
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
2007-09-15 12:13:45 +00:00
|
|
|
count = stream_read( demux->stream, buff, CHUNKSIZE );
|
2007-09-14 20:59:05 +00:00
|
|
|
demux->filepos = stream_tell( demux->stream );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() count %x\n",
|
|
|
|
count );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
|
|
|
"tmf_load_chunk() bytes %x %x %x %x %x %x %x %x\n",
|
|
|
|
buff[ 0 ], buff[ 1 ], buff[ 2 ], buff[ 3 ],
|
|
|
|
buff[ 4 ], buff[ 5 ], buff[ 6 ], buff[ 7 ] );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "tmf_load_chunk() end\n" );
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
return count;
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
// DTiVo MPEG 336, 480, 576, 768
|
|
|
|
// SA TiVo 864
|
|
|
|
// DTiVo AC-3 1550
|
|
|
|
//
|
2007-09-14 15:52:46 +00:00
|
|
|
#define SERIES1_PTS_LENGTH 11
|
|
|
|
#define SERIES1_PTS_OFFSET 6
|
|
|
|
#define SERIES2_PTS_LENGTH 16
|
|
|
|
#define SERIES2_PTS_OFFSET 9
|
|
|
|
#define AC3_PTS_LENGTH 16
|
|
|
|
#define AC3_PTS_OFFSET 9
|
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen )
|
|
|
|
{
|
|
|
|
// AC-3
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( size == 1550 || size == 1552 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
*ptsOffset = AC3_PTS_OFFSET;
|
|
|
|
*ptsLen = AC3_PTS_LENGTH;
|
2007-09-14 15:52:46 +00:00
|
|
|
return 1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MPEG
|
2007-09-14 18:54:14 +00:00
|
|
|
if ( (size & 15) == (SERIES1_PTS_LENGTH & 15) )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
*ptsOffset = SERIES1_PTS_OFFSET;
|
|
|
|
*ptsLen = SERIES1_PTS_LENGTH;
|
2007-09-14 18:50:25 +00:00
|
|
|
return 1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
2007-09-14 18:54:14 +00:00
|
|
|
if ( (size & 15) == (SERIES2_PTS_LENGTH & 15) )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
*ptsOffset = SERIES2_PTS_OFFSET;
|
|
|
|
*ptsLen = SERIES2_PTS_LENGTH;
|
2007-09-14 18:50:25 +00:00
|
|
|
return 1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Tossing Audio Packet Size %d\n",
|
2003-06-09 00:24:49 +00:00
|
|
|
size );
|
2007-09-14 15:52:46 +00:00
|
|
|
return 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 18:03:36 +00:00
|
|
|
static int64_t get_ty_pts( unsigned char *buf )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 17:39:48 +00:00
|
|
|
int a = buf[0] & 0xe;
|
|
|
|
int b = AV_RB16(buf + 1);
|
|
|
|
int c = AV_RB16(buf + 3);
|
|
|
|
|
|
|
|
if (!(1 & a & b & c)) // invalid MPEG timestamp
|
2007-09-14 18:03:36 +00:00
|
|
|
return MP_NOPTS_VALUE;
|
2007-09-14 17:39:48 +00:00
|
|
|
a >>= 1; b >>= 1; c >>= 1;
|
2007-09-14 18:03:36 +00:00
|
|
|
return (((uint64_t)a) << 30) | (b << 15) | c;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer,
|
2003-06-09 00:24:49 +00:00
|
|
|
int size )
|
|
|
|
{
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( tivo->lastAudioEnd + size < MAX_AUDIO_BUFFER )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
memcpy( &tivo->lastAudio[ tivo->lastAudioEnd ],
|
2003-06-09 00:24:49 +00:00
|
|
|
buffer, size );
|
|
|
|
tivo->lastAudioEnd += size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_ERR,
|
|
|
|
"ty:WARNING - Would have blown my audio buffer\n" );
|
|
|
|
}
|
|
|
|
|
2007-09-15 10:54:37 +00:00
|
|
|
static void demux_ty_CopyToDemuxPacket( demux_stream_t *ds,
|
2007-09-15 10:55:30 +00:00
|
|
|
unsigned char *buffer, int size, off_t pos, int64_t pts )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:18:00 +00:00
|
|
|
demux_packet_t *dp = new_demux_packet( size );
|
2003-06-09 00:24:49 +00:00
|
|
|
memcpy( dp->buffer, buffer, size );
|
2007-09-14 18:03:36 +00:00
|
|
|
if (pts != MP_NOPTS_VALUE)
|
|
|
|
dp->pts = pts / 90000.0;
|
2003-06-09 00:24:49 +00:00
|
|
|
dp->pos = pos;
|
|
|
|
dp->flags = 0;
|
|
|
|
ds_add_packet( ds, dp );
|
|
|
|
}
|
|
|
|
|
2007-09-14 20:41:32 +00:00
|
|
|
static int demux_ty_FindESHeader( uint8_t nal,
|
2007-09-14 19:53:09 +00:00
|
|
|
unsigned char *buffer, int bufferSize )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:41:32 +00:00
|
|
|
uint32_t search = 0x00000100 | nal;
|
2007-09-14 20:37:30 +00:00
|
|
|
uint32_t found = -1;
|
|
|
|
uint8_t *p = buffer;
|
|
|
|
uint8_t *end = p + bufferSize;
|
|
|
|
while (p < end) {
|
|
|
|
found <<= 8;
|
|
|
|
found |= *p++;
|
|
|
|
if (found == search)
|
|
|
|
return p - buffer - 4;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
2007-09-14 15:52:46 +00:00
|
|
|
return -1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
static void demux_ty_FindESPacket( uint8_t nal,
|
2003-06-09 00:24:49 +00:00
|
|
|
unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 )
|
|
|
|
{
|
2007-09-14 20:41:32 +00:00
|
|
|
*esOffset1 = demux_ty_FindESHeader(nal, buffer, bufferSize);
|
2007-09-14 20:08:42 +00:00
|
|
|
if (*esOffset1 == -1) {
|
|
|
|
*esOffset2 = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buffer += *esOffset1 + 1;
|
|
|
|
bufferSize -= *esOffset1 + 1;
|
2007-09-14 20:41:32 +00:00
|
|
|
*esOffset2 = demux_ty_FindESHeader(nal, buffer, bufferSize);
|
2007-09-14 20:08:42 +00:00
|
|
|
if (*esOffset2 != -1)
|
|
|
|
*esOffset2 += *esOffset1 + 1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 20:41:32 +00:00
|
|
|
#define VIDEO_NAL 0xe0
|
|
|
|
#define AUDIO_NAL 0xc0
|
|
|
|
#define AC3_NAL 0xbd
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
int invalidType = 0;
|
|
|
|
int errorHeader = 0;
|
|
|
|
int recordsDecoded = 0;
|
|
|
|
|
|
|
|
unsigned char chunk[ CHUNKSIZE ];
|
|
|
|
int readSize;
|
|
|
|
|
|
|
|
int numberRecs;
|
|
|
|
unsigned char *recPtr;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
int counter;
|
|
|
|
|
|
|
|
int aid;
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2007-09-14 18:40:57 +00:00
|
|
|
TiVoInfo *tivo = demux->priv;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
if ( demux->stream->type == STREAMTYPE_DVD )
|
2007-09-14 20:59:05 +00:00
|
|
|
return 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty processing\n" );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
if( demux->stream->eof ) return 0;
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
// ======================================================================
|
2003-10-04 17:29:08 +00:00
|
|
|
// If we haven't figured out the size of the stream, let's do so
|
2003-06-09 00:24:49 +00:00
|
|
|
// ======================================================================
|
|
|
|
#ifdef STREAMTYPE_STREAM_TY
|
|
|
|
if ( demux->stream->type == STREAMTYPE_STREAM_TY )
|
|
|
|
{
|
|
|
|
// The vstream code figures out the exact size of the stream
|
|
|
|
demux->movi_start = 0;
|
|
|
|
demux->movi_end = vstream_streamsize();
|
|
|
|
tivo->size = vstream_streamsize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// If its a local file, try to find the Part Headers, so we can
|
|
|
|
// calculate the ACTUAL stream size
|
|
|
|
// If we can't find it, go off with the file size and hope the
|
|
|
|
// extract program did the "right thing"
|
|
|
|
if ( tivo->readHeader == 0 )
|
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
off_t filePos;
|
2003-06-09 00:24:49 +00:00
|
|
|
tivo->readHeader = 1;
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
filePos = demux->filepos;
|
|
|
|
stream_seek( demux->stream, 0 );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
|
|
|
if ( memcmp( chunk, TMF_SIG, sizeof( TMF_SIG ) ) == 0 )
|
|
|
|
{
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Detected a tmf\n" );
|
|
|
|
tivo->tmf = 1;
|
|
|
|
ty_tmf_filetoparts( demux, tivo );
|
2007-09-15 12:13:45 +00:00
|
|
|
readSize = tmf_load_chunk( demux, tivo, chunk, 0 );
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 18:31:14 +00:00
|
|
|
if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
off_t numberParts;
|
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
readSize = 0;
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
if ( tivo->tmf != 1 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2005-05-28 20:16:33 +00:00
|
|
|
off_t offset;
|
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
numberParts = demux->stream->end_pos / TIVO_PART_LENGTH;
|
2005-05-28 20:16:33 +00:00
|
|
|
offset = numberParts * TIVO_PART_LENGTH;
|
|
|
|
|
2006-01-12 20:04:36 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty/ty+Number Parts %"PRId64"\n",
|
|
|
|
(int64_t)numberParts );
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( offset + CHUNKSIZE < demux->stream->end_pos )
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
|
|
|
stream_seek( demux->stream, offset );
|
|
|
|
readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numberParts = tivo->tmf_totalparts;
|
|
|
|
offset = numberParts * TIVO_PART_LENGTH;
|
2007-09-15 12:13:45 +00:00
|
|
|
readSize = tmf_load_chunk( demux, tivo, chunk,
|
2007-09-14 20:59:05 +00:00
|
|
|
numberParts * ( TIVO_PART_LENGTH - CHUNKSIZE ) /
|
2007-09-14 15:52:46 +00:00
|
|
|
CHUNKSIZE );
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 18:31:14 +00:00
|
|
|
if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID )
|
2005-05-28 20:16:33 +00:00
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
int size = AV_RB24(chunk + 12);
|
2003-06-09 00:24:49 +00:00
|
|
|
size -= 4;
|
|
|
|
size *= CHUNKSIZE;
|
|
|
|
tivo->size = numberParts * TIVO_PART_LENGTH;
|
|
|
|
tivo->size += size;
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2005-10-13 18:33:56 +00:00
|
|
|
"ty:Header Calc Stream Size %"PRId64"\n", tivo->size );
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
if ( demux->stream->start_pos > 0 )
|
|
|
|
filePos = demux->stream->start_pos;
|
2003-06-09 00:24:49 +00:00
|
|
|
stream_seek( demux->stream, filePos );
|
2007-09-14 20:59:05 +00:00
|
|
|
demux->filepos = stream_tell( demux->stream );
|
2007-09-14 15:52:46 +00:00
|
|
|
tivo->whichChunk = filePos / CHUNKSIZE;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
demux->movi_start = 0;
|
|
|
|
demux->movi_end = tivo->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================================================================
|
|
|
|
// Give a clue as to where we are in the stream
|
|
|
|
// ======================================================================
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2006-01-12 20:04:36 +00:00
|
|
|
"ty:ty header size %"PRIx64"\n", (int64_t)tivo->size );
|
2005-05-28 20:16:33 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2006-01-12 20:04:36 +00:00
|
|
|
"ty:ty which Chunk %d\n", tivo->whichChunk );
|
2003-06-09 00:24:49 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2006-01-12 20:04:36 +00:00
|
|
|
"ty:file end_pos %"PRIx64"\n", (int64_t)demux->stream->end_pos );
|
2003-06-09 00:24:49 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2006-01-12 20:04:36 +00:00
|
|
|
"\nty:wanted current offset %"PRIx64"\n", (int64_t)stream_tell( demux->stream ) );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 18:19:10 +00:00
|
|
|
if ( tivo->size > 0 && stream_tell( demux->stream ) > tivo->size )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
demux->stream->eof = 1;
|
2007-09-14 18:19:10 +00:00
|
|
|
return 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-15 13:25:56 +00:00
|
|
|
do {
|
2005-05-28 20:16:33 +00:00
|
|
|
if ( tivo->tmf != 1 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2005-05-28 20:16:33 +00:00
|
|
|
// Make sure we are on a 128k boundary
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( demux->filepos % CHUNKSIZE != 0 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
int whichChunk = demux->filepos / CHUNKSIZE;
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( demux->filepos % CHUNKSIZE > CHUNKSIZE / 2 )
|
2005-05-28 20:16:33 +00:00
|
|
|
whichChunk++;
|
2007-09-14 15:52:46 +00:00
|
|
|
stream_seek( demux->stream, whichChunk * CHUNKSIZE );
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2005-05-28 20:16:33 +00:00
|
|
|
demux->filepos = stream_tell( demux->stream );
|
|
|
|
tivo->whichChunk = demux->filepos / CHUNKSIZE;
|
|
|
|
readSize = stream_read( demux->stream, chunk, CHUNKSIZE );
|
|
|
|
if ( readSize != CHUNKSIZE )
|
2007-09-14 18:19:10 +00:00
|
|
|
return 0;
|
2005-05-28 20:16:33 +00:00
|
|
|
}
|
|
|
|
else
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-15 12:13:45 +00:00
|
|
|
readSize = tmf_load_chunk( demux, tivo, chunk, tivo->whichChunk );
|
2005-05-28 20:16:33 +00:00
|
|
|
if ( readSize != CHUNKSIZE )
|
2007-09-14 15:52:46 +00:00
|
|
|
return 0;
|
2005-05-28 20:16:33 +00:00
|
|
|
tivo->whichChunk++;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
2007-09-15 13:25:56 +00:00
|
|
|
if (AV_RB32(chunk) == TIVO_PES_FILEID)
|
2003-06-09 00:24:49 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Skipping PART Header\n" );
|
2007-09-15 13:25:56 +00:00
|
|
|
} while (AV_RB32(chunk) == TIVO_PES_FILEID);
|
2005-05-28 20:16:33 +00:00
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2007-09-14 20:59:05 +00:00
|
|
|
"\nty:actual current offset %"PRIx64"\n", stream_tell( demux->stream ) -
|
|
|
|
CHUNKSIZE );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
|
2004-07-19 23:19:07 +00:00
|
|
|
// Let's make a Video Demux Stream for MPlayer
|
2003-06-09 00:24:49 +00:00
|
|
|
aid = 0x0;
|
|
|
|
if( !demux->v_streams[ aid ] ) new_sh_video( demux, aid );
|
|
|
|
if( demux->video->id == -1 ) demux->video->id = aid;
|
|
|
|
if( demux->video->id == aid )
|
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
demux_stream_t *ds = demux->video;
|
2003-06-09 00:24:49 +00:00
|
|
|
if( !ds->sh ) ds->sh = demux->v_streams[ aid ];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================================================================
|
|
|
|
// Finally, we get to actually parse the chunk
|
|
|
|
// ======================================================================
|
2005-05-28 20:16:33 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:ty parsing a chunk\n" );
|
2003-06-09 00:24:49 +00:00
|
|
|
numberRecs = chunk[ 0 ];
|
|
|
|
recPtr = &chunk[ 4 ];
|
2007-09-14 15:52:46 +00:00
|
|
|
offset = numberRecs * 16 + 4;
|
2003-06-09 00:24:49 +00:00
|
|
|
for ( counter = 0 ; counter < numberRecs ; counter++ )
|
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
int size = AV_RB24(recPtr) >> 4;
|
|
|
|
int type = recPtr[ 3 ];
|
|
|
|
int nybbleType = recPtr[ 2 ] & 0x0f;
|
2003-06-09 00:24:49 +00:00
|
|
|
recordsDecoded++;
|
|
|
|
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
|
|
|
"ty:Record Type %x/%x %d\n", nybbleType, type, size );
|
|
|
|
|
|
|
|
// ================================================================
|
|
|
|
// Video Parsing
|
|
|
|
// ================================================================
|
|
|
|
if ( type == 0xe0 )
|
|
|
|
{
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( size > 0 && size + offset <= CHUNKSIZE )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
int esOffset1 = demux_ty_FindESHeader( VIDEO_NAL, &chunk[ offset ],
|
2007-09-14 19:53:09 +00:00
|
|
|
size);
|
2003-06-09 00:24:49 +00:00
|
|
|
if ( esOffset1 != -1 )
|
2007-09-14 20:59:05 +00:00
|
|
|
tivo->lastVideoPTS = get_ty_pts(
|
2003-06-09 00:24:49 +00:00
|
|
|
&chunk[ offset + esOffset1 + 9 ] );
|
|
|
|
|
|
|
|
// Do NOT Pass the PES Header onto the MPEG2 Decode
|
|
|
|
if( nybbleType != 0x06 )
|
2007-09-15 10:54:37 +00:00
|
|
|
demux_ty_CopyToDemuxPacket( demux->video,
|
2007-09-14 20:59:05 +00:00
|
|
|
&chunk[ offset ], size, demux->filepos + offset,
|
|
|
|
tivo->lastVideoPTS );
|
2003-06-09 00:24:49 +00:00
|
|
|
offset += size;
|
|
|
|
}
|
2007-09-14 20:59:05 +00:00
|
|
|
else
|
|
|
|
errorHeader++;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
// ================================================================
|
|
|
|
// Audio Parsing
|
|
|
|
// ================================================================
|
2007-09-14 20:59:05 +00:00
|
|
|
else if ( type == 0xc0 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( size > 0 && size + offset <= CHUNKSIZE )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
if( demux->audio->id == -1 )
|
|
|
|
{
|
|
|
|
if ( nybbleType == 0x02 )
|
|
|
|
continue; // DTiVo inconclusive, wait for more
|
|
|
|
else if ( nybbleType == 0x09 )
|
|
|
|
{
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting AC-3 Audio\n" );
|
|
|
|
aid = 0x80; // AC-3
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Setting MPEG Audio\n" );
|
|
|
|
aid = 0x0; // MPEG Audio
|
|
|
|
}
|
|
|
|
|
|
|
|
demux->audio->id = aid;
|
|
|
|
if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid );
|
|
|
|
if( demux->audio->id == aid )
|
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
demux_stream_t *ds = demux->audio;
|
2005-05-28 20:12:09 +00:00
|
|
|
if( !ds->sh ) {
|
|
|
|
sh_audio_t* sh_a;
|
|
|
|
ds->sh = demux->a_streams[ aid ];
|
|
|
|
sh_a = (sh_audio_t*)ds->sh;
|
|
|
|
switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id)
|
|
|
|
case 0x00: sh_a->format=0x50;break; // mpeg
|
|
|
|
case 0xA0: sh_a->format=0x10001;break; // dvd pcm
|
|
|
|
case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts
|
|
|
|
else sh_a->format=0x2000;break; // ac3
|
|
|
|
}
|
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aid = demux->audio->id;
|
|
|
|
|
|
|
|
|
|
|
|
// SA DTiVo Audio Data, no PES
|
|
|
|
// ================================================
|
2007-09-14 19:34:17 +00:00
|
|
|
if ( nybbleType == 0x02 || nybbleType == 0x04 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 19:34:17 +00:00
|
|
|
if ( nybbleType == 0x02 && tivo->tivoType == 2 )
|
2003-06-09 00:24:49 +00:00
|
|
|
demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
|
|
|
"ty:Adding Audio Packet Size %d\n", size );
|
2007-09-15 10:54:37 +00:00
|
|
|
demux_ty_CopyToDemuxPacket( demux->audio,
|
2007-09-14 20:59:05 +00:00
|
|
|
&chunk[ offset ], size, ( demux->filepos + offset ),
|
|
|
|
tivo->lastAudioPTS );
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-14 19:30:25 +00:00
|
|
|
// 3 - MPEG Audio with PES Header, either SA or DTiVo
|
|
|
|
// 9 - DTiVo AC3 Audio Data with PES Header
|
2003-06-09 00:24:49 +00:00
|
|
|
// ================================================
|
2007-09-14 19:30:25 +00:00
|
|
|
if ( nybbleType == 0x03 || nybbleType == 0x09 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 19:46:54 +00:00
|
|
|
int esOffset1, esOffset2;
|
2007-09-14 19:30:25 +00:00
|
|
|
if ( nybbleType == 0x03 )
|
2007-09-14 20:59:05 +00:00
|
|
|
esOffset1 = demux_ty_FindESHeader( AUDIO_NAL, &chunk[ offset ],
|
2007-09-14 19:53:09 +00:00
|
|
|
size);
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
// SA PES Header, No Audio Data
|
|
|
|
// ================================================
|
2007-09-14 19:30:25 +00:00
|
|
|
if ( nybbleType == 0x03 && esOffset1 == 0 && size == 16 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
tivo->tivoType = 1;
|
2007-09-14 20:59:05 +00:00
|
|
|
tivo->lastAudioPTS = get_ty_pts( &chunk[ offset +
|
2003-06-09 00:24:49 +00:00
|
|
|
SERIES2_PTS_OFFSET ] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// DTiVo Audio with PES Header
|
|
|
|
// ================================================
|
|
|
|
{
|
|
|
|
tivo->tivoType = 2;
|
|
|
|
|
|
|
|
demux_ty_AddToAudioBuffer( tivo, &chunk[ offset ], size );
|
2007-09-14 20:41:32 +00:00
|
|
|
demux_ty_FindESPacket( nybbleType == 9 ? AC3_NAL : AUDIO_NAL,
|
2003-06-09 00:24:49 +00:00
|
|
|
tivo->lastAudio, tivo->lastAudioEnd, &esOffset1,
|
|
|
|
&esOffset2 );
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( esOffset1 != -1 && esOffset2 != -1 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
int packetSize = esOffset2 - esOffset1;
|
|
|
|
int headerSize;
|
|
|
|
int ptsOffset;
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
if ( IsValidAudioPacket( packetSize, &ptsOffset,
|
2003-06-09 00:24:49 +00:00
|
|
|
&headerSize ) )
|
|
|
|
{
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2007-09-14 20:59:05 +00:00
|
|
|
"ty:Adding DTiVo Audio Packet Size %d\n",
|
2003-06-09 00:24:49 +00:00
|
|
|
packetSize );
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
tivo->lastAudioPTS = get_ty_pts(
|
2003-06-09 00:24:49 +00:00
|
|
|
&tivo->lastAudio[ esOffset1 + ptsOffset ] );
|
|
|
|
|
2007-09-14 19:30:25 +00:00
|
|
|
if (nybbleType == 9) headerSize = 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
demux_ty_CopyToDemuxPacket
|
2007-09-14 20:59:05 +00:00
|
|
|
(
|
|
|
|
demux->audio,
|
2007-09-14 20:49:36 +00:00
|
|
|
&tivo->lastAudio[ esOffset1 + headerSize ],
|
|
|
|
packetSize - headerSize,
|
|
|
|
demux->filepos + offset,
|
2007-09-14 20:59:05 +00:00
|
|
|
tivo->lastAudioPTS
|
2003-06-09 00:24:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse the Audio Buffer
|
2007-09-14 20:48:04 +00:00
|
|
|
tivo->lastAudioEnd -= esOffset2;
|
2007-09-14 20:59:05 +00:00
|
|
|
memmove( &tivo->lastAudio[ 0 ],
|
|
|
|
&tivo->lastAudio[ esOffset2 ],
|
2007-09-14 20:48:04 +00:00
|
|
|
tivo->lastAudioEnd );
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
2007-09-14 20:59:05 +00:00
|
|
|
else
|
|
|
|
errorHeader++;
|
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
// ================================================================
|
2007-09-14 19:13:47 +00:00
|
|
|
// 1 = Closed Caption
|
|
|
|
// 2 = Extended Data Services
|
2003-06-09 00:24:49 +00:00
|
|
|
// ================================================================
|
2007-09-14 20:59:05 +00:00
|
|
|
else if ( type == 0x01 || type == 0x02 )
|
|
|
|
{
|
2007-09-14 19:13:47 +00:00
|
|
|
unsigned char lastXDS[ 16 ];
|
2007-09-14 20:59:05 +00:00
|
|
|
int b = AV_RB24(recPtr) >> 4;
|
|
|
|
b &= 0x7f7f;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 19:13:47 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:%s %04x\n", type == 1 ? "CC" : "XDS", b);
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
lastXDS[ 0x00 ] = 0x00;
|
|
|
|
lastXDS[ 0x01 ] = 0x00;
|
|
|
|
lastXDS[ 0x02 ] = 0x01;
|
|
|
|
lastXDS[ 0x03 ] = 0xb2;
|
|
|
|
lastXDS[ 0x04 ] = 'T';
|
|
|
|
lastXDS[ 0x05 ] = 'Y';
|
|
|
|
lastXDS[ 0x06 ] = type;
|
|
|
|
lastXDS[ 0x07 ] = b >> 8;
|
|
|
|
lastXDS[ 0x08 ] = b;
|
2005-05-28 20:16:33 +00:00
|
|
|
if ( subcc_enabled )
|
2007-09-15 10:54:37 +00:00
|
|
|
demux_ty_CopyToDemuxPacket( demux->video, lastXDS, 0x09,
|
2007-09-14 20:59:05 +00:00
|
|
|
demux->filepos + offset, tivo->lastVideoPTS );
|
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
// ================================================================
|
|
|
|
// Unknown
|
|
|
|
// ================================================================
|
2007-09-14 20:59:05 +00:00
|
|
|
else
|
|
|
|
{
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( size > 0 && size + offset <= CHUNKSIZE )
|
2003-06-09 00:24:49 +00:00
|
|
|
offset += size;
|
2007-09-14 21:17:48 +00:00
|
|
|
if (type != 3 && type != 5 && (type != 0 || size > 0)) {
|
2003-06-09 00:24:49 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Invalid Type %x\n", type );
|
2007-09-14 20:59:05 +00:00
|
|
|
invalidType++;
|
2007-09-14 18:58:32 +00:00
|
|
|
}
|
2007-09-14 20:59:05 +00:00
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
recPtr += 16;
|
|
|
|
}
|
|
|
|
|
2006-10-10 19:21:33 +00:00
|
|
|
if ( errorHeader > 0 || invalidType > 0 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3,
|
2006-10-10 19:21:33 +00:00
|
|
|
"ty:Error Check - Records %d, Parsed %d, Errors %d + %d\n",
|
|
|
|
numberRecs, recordsDecoded, errorHeader, invalidType );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
// Invalid MPEG ES Size Check
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( errorHeader > numberRecs / 2 )
|
|
|
|
return 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
// Invalid MPEG Stream Type Check
|
2007-09-14 15:52:46 +00:00
|
|
|
if ( invalidType > numberRecs / 2 )
|
|
|
|
return 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
demux->filepos = stream_tell( demux->stream );
|
|
|
|
|
2007-09-14 15:52:46 +00:00
|
|
|
return 1;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2006-02-17 01:57:41 +00:00
|
|
|
static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
demux_stream_t *d_audio = demuxer->audio;
|
|
|
|
demux_stream_t *d_video = demuxer->video;
|
|
|
|
sh_audio_t *sh_audio = d_audio->sh;
|
|
|
|
sh_video_t *sh_video = d_video->sh;
|
|
|
|
off_t newpos;
|
|
|
|
off_t res;
|
2007-09-14 18:40:57 +00:00
|
|
|
TiVoInfo *tivo = demuxer->priv;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
mp_msg( MSGT_DEMUX, MSGL_DBG3, "ty:Seeking to %7.1f\n", rel_seek_secs );
|
|
|
|
|
|
|
|
tivo->lastAudioEnd = 0;
|
2007-09-14 18:03:36 +00:00
|
|
|
tivo->lastAudioPTS = MP_NOPTS_VALUE;
|
|
|
|
tivo->lastVideoPTS = MP_NOPTS_VALUE;
|
2003-06-09 00:24:49 +00:00
|
|
|
//
|
|
|
|
//================= seek in MPEG ==========================
|
|
|
|
demuxer->filepos = stream_tell( demuxer->stream );
|
|
|
|
|
|
|
|
newpos = ( flags & 1 ) ? demuxer->movi_start : demuxer->filepos;
|
2007-09-14 20:59:05 +00:00
|
|
|
|
2003-06-09 00:24:49 +00:00
|
|
|
if( flags & 2 )
|
2007-09-14 20:59:05 +00:00
|
|
|
// float seek 0..1
|
|
|
|
newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs;
|
|
|
|
else
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
// time seek (secs)
|
2003-06-09 00:24:49 +00:00
|
|
|
if( ! sh_video->i_bps ) // unspecified or VBR
|
|
|
|
newpos += 2324 * 75 * rel_seek_secs; // 174.3 kbyte/sec
|
|
|
|
else
|
|
|
|
newpos += sh_video->i_bps * rel_seek_secs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newpos < demuxer->movi_start )
|
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
if( demuxer->stream->type != STREAMTYPE_VCD ) demuxer->movi_start = 0;
|
|
|
|
if( newpos < demuxer->movi_start ) newpos = demuxer->movi_start;
|
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
res = newpos / CHUNKSIZE;
|
|
|
|
if ( rel_seek_secs >= 0 )
|
|
|
|
newpos = ( res + 1 ) * CHUNKSIZE;
|
|
|
|
else
|
|
|
|
newpos = res * CHUNKSIZE;
|
|
|
|
|
|
|
|
if ( newpos < 0 )
|
|
|
|
newpos = 0;
|
2005-05-28 20:16:33 +00:00
|
|
|
|
|
|
|
tivo->whichChunk = newpos / CHUNKSIZE;
|
|
|
|
|
|
|
|
stream_seek( demuxer->stream, newpos );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
// re-sync video:
|
|
|
|
videobuf_code_len = 0; // reset ES stream buffer
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
ds_fill_buffer( d_video );
|
|
|
|
if( sh_audio )
|
|
|
|
ds_fill_buffer( d_audio );
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
while( 1 )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
int i;
|
2003-06-09 00:24:49 +00:00
|
|
|
if( sh_audio && !d_audio->eof && d_video->pts && d_audio->pts )
|
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
float a_pts = d_audio->pts;
|
2003-06-09 00:24:49 +00:00
|
|
|
a_pts += ( ds_tell_pts( d_audio ) - sh_audio->a_in_buffer_len ) /
|
|
|
|
(float)sh_audio->i_bps;
|
2007-09-14 20:59:05 +00:00
|
|
|
if( d_video->pts > a_pts )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
skip_audio_frame( sh_audio ); // sync audio
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
i = sync_video_packet( d_video );
|
|
|
|
if( i == 0x1B3 || i == 0x1B8 ) break; // found it!
|
|
|
|
if( !i || !skip_video_packet( d_video ) ) break; // EOF?
|
|
|
|
}
|
2007-09-14 20:59:05 +00:00
|
|
|
if ( subcc_enabled )
|
|
|
|
ty_ClearOSD( 0 );
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 15:19:45 +00:00
|
|
|
static int demux_ty_control( demuxer_t *demuxer,int cmd, void *arg )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
|
|
|
demux_stream_t *d_video = demuxer->video;
|
|
|
|
sh_video_t *sh_video = d_video->sh;
|
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
switch(cmd)
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 20:59:05 +00:00
|
|
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
|
|
|
if(!sh_video->i_bps) // unspecified or VBR
|
|
|
|
return DEMUXER_CTRL_DONTKNOW;
|
|
|
|
*(double *)arg=
|
2007-09-14 15:52:46 +00:00
|
|
|
(double)demuxer->movi_end-demuxer->movi_start/sh_video->i_bps;
|
2007-09-14 20:59:05 +00:00
|
|
|
return DEMUXER_CTRL_GUESS;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
2007-09-14 20:59:05 +00:00
|
|
|
case DEMUXER_CTRL_GET_PERCENT_POS:
|
|
|
|
return DEMUXER_CTRL_DONTKNOW;
|
|
|
|
default:
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-11 17:21:02 +00:00
|
|
|
static void demux_close_ty( demuxer_t *demux )
|
2003-06-09 00:24:49 +00:00
|
|
|
{
|
2007-09-14 18:40:57 +00:00
|
|
|
TiVoInfo *tivo = demux->priv;
|
2003-06-09 00:24:49 +00:00
|
|
|
|
|
|
|
free( tivo );
|
2007-09-14 20:59:05 +00:00
|
|
|
sub_justify = 0;
|
2003-06-09 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static int ty_check_file(demuxer_t* demuxer)
|
|
|
|
{
|
2007-09-14 18:40:57 +00:00
|
|
|
TiVoInfo *tivo = calloc(1, sizeof(TiVoInfo));
|
|
|
|
demuxer->priv = tivo;
|
2005-08-05 19:57:47 +00:00
|
|
|
return ds_fill_buffer(demuxer->video) ? DEMUXER_TYPE_MPEG_TY : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static demuxer_t* demux_open_ty(demuxer_t* demuxer)
|
|
|
|
{
|
|
|
|
sh_audio_t *sh_audio=NULL;
|
|
|
|
sh_video_t *sh_video=NULL;
|
|
|
|
|
|
|
|
sh_video=demuxer->video->sh;sh_video->ds=demuxer->video;
|
|
|
|
|
|
|
|
if(demuxer->audio->id!=-2) {
|
|
|
|
if(!ds_fill_buffer(demuxer->audio)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream);
|
|
|
|
demuxer->audio->sh=NULL;
|
|
|
|
} else {
|
|
|
|
sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return demuxer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
demuxer_desc_t demuxer_desc_mpeg_ty = {
|
|
|
|
"TiVo demuxer",
|
|
|
|
"tivo",
|
|
|
|
"TiVo",
|
|
|
|
"Christopher R. Wingert",
|
|
|
|
"Demux streams from TiVo",
|
|
|
|
DEMUXER_TYPE_MPEG_TY,
|
|
|
|
0, // unsafe autodetect
|
|
|
|
ty_check_file,
|
|
|
|
demux_ty_fill_buffer,
|
|
|
|
demux_open_ty,
|
|
|
|
demux_close_ty,
|
|
|
|
demux_seek_ty,
|
|
|
|
demux_ty_control
|
|
|
|
};
|