Commit 42886fbe authored by Gildas Bazin's avatar Gildas Bazin

* modules/codec/tarkin.c: ported to the new decoders api (I know, this is a waste of time ;).
parent 4033ecea
/***************************************************************************** /*****************************************************************************
* tarkin.c: tarkin decoder module making use of libtarkin. * tarkin.c: tarkin decoder module making use of libtarkin.
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: tarkin.c,v 1.7 2003/11/16 21:07:30 gbazin Exp $ * $Id: tarkin.c,v 1.8 2003/11/22 15:06:50 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -25,13 +25,9 @@ ...@@ -25,13 +25,9 @@
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/vout.h>
#include <vlc/input.h> #include <vlc/input.h>
#include <vlc/decoder.h> #include <vlc/decoder.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* memcpy(), memset() */
#include <ogg/ogg.h> #include <ogg/ogg.h>
/* FIXME */ /* FIXME */
...@@ -45,15 +41,10 @@ ...@@ -45,15 +41,10 @@
#include <tarkin.h> #include <tarkin.h>
/***************************************************************************** /*****************************************************************************
* dec_thread_t : tarkin decoder thread descriptor * decoder_sys_t : tarkin decoder descriptor
*****************************************************************************/ *****************************************************************************/
typedef struct dec_thread_t struct decoder_sys_t
{ {
/*
* Thread properties
*/
vlc_thread_t thread_id; /* id for thread functions */
/* /*
* Tarkin properties * Tarkin properties
*/ */
...@@ -63,30 +54,20 @@ typedef struct dec_thread_t ...@@ -63,30 +54,20 @@ typedef struct dec_thread_t
TarkinComment tc; /* tarkin bitstream user comments */ TarkinComment tc; /* tarkin bitstream user comments */
TarkinTime tarkdate; TarkinTime tarkdate;
/* int i_headers;
* Input properties mtime_t i_pts;
*/ };
decoder_fifo_t *p_fifo; /* stores the PES stream data */
pes_packet_t *p_pes; /* current PES we are decoding */
/*
* Output properties
*/
vout_thread_t *p_vout;
} dec_thread_t;
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int OpenDecoder ( vlc_object_t * ); static int OpenDecoder ( vlc_object_t * );
static int RunDecoder ( decoder_fifo_t * ); static void CloseDecoder ( vlc_object_t * );
static void CloseDecoder ( dec_thread_t * );
static void DecodePacket ( dec_thread_t * ); static void *DecodeBlock ( decoder_t *, block_t ** );
static int GetOggPacket ( dec_thread_t *, ogg_packet *, mtime_t * ); static picture_t *DecodePacket ( decoder_t *, block_t **, ogg_packet * );
static void tarkin_CopyPicture( dec_thread_t *, picture_t *, uint8_t *, int ); static void tarkin_CopyPicture( decoder_t *, picture_t *, uint8_t *, int );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -94,7 +75,7 @@ static void tarkin_CopyPicture( dec_thread_t *, picture_t *, uint8_t *, int ); ...@@ -94,7 +75,7 @@ static void tarkin_CopyPicture( dec_thread_t *, picture_t *, uint8_t *, int );
vlc_module_begin(); vlc_module_begin();
set_description( _("Tarkin decoder module") ); set_description( _("Tarkin decoder module") );
set_capability( "decoder", 100 ); set_capability( "decoder", 100 );
set_callbacks( OpenDecoder, NULL ); set_callbacks( OpenDecoder, CloseDecoder );
add_shortcut( "tarkin" ); add_shortcut( "tarkin" );
vlc_module_end(); vlc_module_end();
...@@ -104,139 +85,158 @@ vlc_module_end(); ...@@ -104,139 +85,158 @@ vlc_module_end();
static int OpenDecoder( vlc_object_t *p_this ) static int OpenDecoder( vlc_object_t *p_this )
{ {
decoder_t *p_dec = (decoder_t*)p_this; decoder_t *p_dec = (decoder_t*)p_this;
decoder_sys_t *p_sys;
if( p_dec->fmt_in.i_codec != VLC_FOURCC('t','a','r','k') ) if( p_dec->fmt_in.i_codec != VLC_FOURCC('t','a','r','k') )
{ {
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_dec->pf_run = RunDecoder; /* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
{
msg_Err( p_dec, "out of memory" );
return VLC_EGENERIC;
}
/* Set output properties */
p_dec->fmt_out.i_cat = VIDEO_ES;
p_sys->i_headers = 0;
/* Set callbacks */
p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
DecodeBlock;
p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **))
DecodeBlock;
/* Init supporting Tarkin structures needed in header parsing */
p_sys->tarkin_stream = tarkin_stream_new();
tarkin_info_init( &p_sys->ti );
tarkin_comment_init( &p_sys->tc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/***************************************************************************** /****************************************************************************
* RunDecoder: the tarkin decoder * DecodeBlock: the whole thing
*****************************************************************************/ ****************************************************************************
static int RunDecoder( decoder_fifo_t *p_fifo ) * This function must be fed with ogg packets.
****************************************************************************/
static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{ {
dec_thread_t *p_dec; decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_block;
ogg_packet oggpacket; ogg_packet oggpacket;
mtime_t i_pts;
/* Allocate the memory needed to store the thread's structure */ if( !pp_block ) return NULL;
if( (p_dec = (dec_thread_t *)malloc (sizeof(dec_thread_t)) )
== NULL) if( *pp_block )
{ {
msg_Err( p_fifo, "out of memory" ); /* Block to Ogg packet */
goto error; oggpacket.packet = (*pp_block)->p_buffer;
oggpacket.bytes = (*pp_block)->i_buffer;
}
else
{
/* Block to Ogg packet */
oggpacket.packet = NULL;
oggpacket.bytes = 0;
} }
/* Initialize the thread properties */ p_block = *pp_block;
memset( p_dec, 0, sizeof(dec_thread_t) );
p_dec->p_fifo = p_fifo;
p_dec->p_pes = NULL;
p_dec->p_vout = NULL;
/* Take care of the initial Tarkin header */ oggpacket.granulepos = -1;
p_dec->tarkin_stream = tarkin_stream_new(); oggpacket.b_o_s = 0;
tarkin_info_init(&p_dec->ti); oggpacket.e_o_s = 0;
tarkin_comment_init(&p_dec->tc); oggpacket.packetno = 0;
if( GetOggPacket( p_dec, &oggpacket, &i_pts ) != VLC_SUCCESS ) if( p_sys->i_headers == 0 )
goto error; {
/* Take care of the initial Tarkin header */
oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */
if( tarkin_synthesis_headerin( &p_dec->ti, &p_dec->tc, &oggpacket ) < 0 ) if( tarkin_synthesis_headerin( &p_sys->ti, &p_sys->tc, &oggpacket )
< 0 )
{ {
msg_Err( p_dec->p_fifo, "This bitstream does not contain Tarkin " msg_Err( p_dec, "This bitstream does not contain Tarkin "
"video data"); "video data");
goto error; block_Release( p_block );
return NULL;
} }
p_sys->i_headers++;
/* The next two packets in order are the comment and codebook headers. block_Release( p_block );
We need to watch out that these packets are not missing as a return NULL;
missing or corrupted header is fatal. */
if( GetOggPacket( p_dec, &oggpacket, &i_pts ) != VLC_SUCCESS )
goto error;
if( tarkin_synthesis_headerin( &p_dec->ti, &p_dec->tc, &oggpacket ) < 0 )
{
msg_Err( p_dec->p_fifo, "2nd Tarkin header is corrupted" );
goto error;
} }
if( GetOggPacket( p_dec, &oggpacket, &i_pts ) != VLC_SUCCESS ) if( p_sys->i_headers == 1 )
goto error;
if( tarkin_synthesis_headerin( &p_dec->ti, &p_dec->tc, &oggpacket ) < 0 )
{ {
msg_Err( p_dec->p_fifo, "3rd Tarkin header is corrupted" ); if( tarkin_synthesis_headerin( &p_sys->ti, &p_sys->tc, &oggpacket )
goto error; < 0 )
}
/* Initialize the tarkin decoder */
tarkin_synthesis_init( p_dec->tarkin_stream, &p_dec->ti );
/* tarkin decoder thread's main loop */
while( (!p_dec->p_fifo->b_die) && (!p_dec->p_fifo->b_error) )
{ {
DecodePacket( p_dec ); msg_Err( p_dec, "2nd Tarkin header is corrupted" );
block_Release( p_block );
return NULL;
}
p_sys->i_headers++;
block_Release( p_block );
return NULL;
} }
/* If b_error is set, the tarkin decoder thread enters the error loop */ if( p_sys->i_headers == 2 )
if( p_dec->p_fifo->b_error ) {
if( tarkin_synthesis_headerin( &p_sys->ti, &p_sys->tc, &oggpacket )
< 0 )
{ {
DecoderError( p_dec->p_fifo ); msg_Err( p_dec->p_fifo, "3rd Tarkin header is corrupted" );
block_Release( p_block );
return NULL;
} }
p_sys->i_headers++;
/* End of the tarkin decoder thread */ /* Initialize the tarkin decoder */
CloseDecoder( p_dec ); tarkin_synthesis_init( p_sys->tarkin_stream, &p_sys->ti );
return 0; msg_Err( p_dec, "Tarkin codec initialized");
error: block_Release( p_block );
DecoderError( p_fifo ); return NULL;
if( p_dec )
{
if( p_dec->p_fifo )
p_dec->p_fifo->b_error = 1;
/* End of the tarkin decoder thread */
CloseDecoder( p_dec );
} }
return -1; return DecodePacket( p_dec, pp_block, &oggpacket );
} }
/***************************************************************************** /*****************************************************************************
* DecodePacket: decodes a Tarkin packet. * DecodePacket: decodes a Tarkin packet.
*****************************************************************************/ *****************************************************************************/
static void DecodePacket( dec_thread_t *p_dec ) static picture_t *DecodePacket( decoder_t *p_dec, block_t **pp_block,
ogg_packet *p_oggpacket )
{ {
ogg_packet oggpacket; decoder_sys_t *p_sys = p_dec->p_sys;
picture_t *p_pic;
mtime_t i_pts;
int i_width, i_height, i_chroma, i_stride, i_aspect;
uint8_t *rgb; uint8_t *rgb;
if( GetOggPacket( p_dec, &oggpacket, &i_pts ) != VLC_SUCCESS ) if( p_oggpacket->bytes )
{ {
/* This should mean an eos */ tarkin_synthesis_packetin( p_sys->tarkin_stream, p_oggpacket );
return; //block_Release( *pp_block ); /* FIXME duplicate packet */
*pp_block = NULL;
} }
tarkin_synthesis_packetin( p_dec->tarkin_stream, &oggpacket ); if( tarkin_synthesis_frameout( p_sys->tarkin_stream,
&rgb, 0, &p_sys->tarkdate ) == 0 )
while( tarkin_synthesis_frameout( p_dec->tarkin_stream,
&rgb, 0, &p_dec->tarkdate ) == 0 )
{ {
int i_width, i_height, i_chroma, i_stride;
picture_t *p_pic;
msg_Err( p_dec, "Tarkin frame decoded" );
i_width = p_dec->tarkin_stream->layer->desc.width; i_width = p_sys->tarkin_stream->layer->desc.width;
i_height = p_dec->tarkin_stream->layer->desc.height; i_height = p_sys->tarkin_stream->layer->desc.height;
switch( p_dec->tarkin_stream->layer->desc.format )
switch( p_sys->tarkin_stream->layer->desc.format )
{ {
case TARKIN_RGB24: case TARKIN_RGB24:
/*i_chroma = VLC_FOURCC('R','G','B','A');*/
i_chroma = VLC_FOURCC('R','V','2','4'); i_chroma = VLC_FOURCC('R','V','2','4');
i_stride = i_width * 3; i_stride = i_width * 3;
break; break;
...@@ -249,88 +249,53 @@ static void DecodePacket( dec_thread_t *p_dec ) ...@@ -249,88 +249,53 @@ static void DecodePacket( dec_thread_t *p_dec )
i_stride = i_width * 4; i_stride = i_width * 4;
break; break;
default: default:
i_chroma = VLC_FOURCC('Y','V','1','2'); i_chroma = VLC_FOURCC('I','4','2','0');
i_stride = i_width; i_stride = i_width;
break; break;
} }
i_aspect = VOUT_ASPECT_FACTOR * i_width / i_height;
p_dec->p_vout = vout_Request( p_dec->p_fifo, p_dec->p_vout, /* Set output properties */
i_width, i_height, i_chroma, i_aspect ); p_dec->fmt_out.video.i_width = i_width;
p_dec->fmt_out.video.i_height = i_height;
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR * i_width / i_height;
p_dec->fmt_out.i_codec = i_chroma;
/* Get a new picture */ /* Get a new picture */
while( !(p_pic = vout_CreatePicture( p_dec->p_vout, 0, 0, 0 ) ) ) if( (p_pic = p_dec->pf_vout_buffer_new( p_dec )) )
{
if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
{ {
return;
}
msleep( VOUT_OUTMEM_SLEEP );
}
if( !p_pic )
break;
tarkin_CopyPicture( p_dec, p_pic, rgb, i_stride ); tarkin_CopyPicture( p_dec, p_pic, rgb, i_stride );
tarkin_synthesis_freeframe( p_dec->tarkin_stream, rgb ); tarkin_synthesis_freeframe( p_sys->tarkin_stream, rgb );
vout_DatePicture( p_dec->p_vout, p_pic, mdate()+DEFAULT_PTS_DELAY/*i_pts*/ ); p_pic->date = mdate() + DEFAULT_PTS_DELAY/*i_pts*/;
vout_DisplayPicture( p_dec->p_vout, p_pic );
return p_pic;
}
} }
}
/*****************************************************************************
* GetOggPacket: get the following tarkin packet from the stream and send back
* the result in an ogg packet (for easy decoding by libtarkin).
*****************************************************************************
* Returns VLC_EGENERIC in case of eof.
*****************************************************************************/
static int GetOggPacket( dec_thread_t *p_dec, ogg_packet *p_oggpacket,
mtime_t *p_pts )
{
if( p_dec->p_pes ) input_DeletePES( p_dec->p_fifo->p_packets_mgt,
p_dec->p_pes );
input_ExtractPES( p_dec->p_fifo, &p_dec->p_pes );
if( !p_dec->p_pes ) return VLC_EGENERIC;
p_oggpacket->packet = p_dec->p_pes->p_first->p_payload_start;
p_oggpacket->bytes = p_dec->p_pes->i_pes_size;
p_oggpacket->granulepos = p_dec->p_pes->i_dts;
p_oggpacket->b_o_s = 0;
p_oggpacket->e_o_s = 0;
p_oggpacket->packetno = 0;
*p_pts = p_dec->p_pes->i_pts;
return VLC_SUCCESS; return NULL;
} }
/***************************************************************************** /*****************************************************************************
* CloseDecoder: tarkin decoder destruction * CloseDecoder: tarkin decoder destruction
*****************************************************************************/ *****************************************************************************/
static void CloseDecoder( dec_thread_t * p_dec ) static void CloseDecoder( vlc_object_t *p_this )
{ {
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
if( p_dec ) tarkin_stream_destroy( p_sys->tarkin_stream );
{
if( p_dec->p_pes )
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_dec->p_pes );
vout_Request( p_dec->p_fifo, p_dec->p_vout, 0, 0, 0, 0 );
if( p_dec->tarkin_stream ) free( p_sys );
tarkin_stream_destroy( p_dec->tarkin_stream );
free( p_dec );
}
} }
/***************************************************************************** /*****************************************************************************
* tarkin_CopyPicture: copy a picture from tarkin internal buffers to a * tarkin_CopyPicture: copy a picture from tarkin internal buffers to a
* picture_t structure. * picture_t structure.
*****************************************************************************/ *****************************************************************************/
static void tarkin_CopyPicture( dec_thread_t *p_dec, picture_t *p_pic, static void tarkin_CopyPicture( decoder_t *p_dec, picture_t *p_pic,
uint8_t *p_src, int i_pitch ) uint8_t *p_src, int i_pitch )
{ {
int i_plane, i_line, i_src_stride, i_dst_stride; int i_plane, i_line, i_src_stride, i_dst_stride;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment