X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fcinepak.c;h=21f23a110ae86b71afdc9f375a166de91862ba36;hb=ce8975594a807902cc839211f9792a9598a7da0a;hp=4a3b8eed1c41e111fb1642f9266c15dca0bf2e93;hpb=1e9f16e284a4bb84ac446bf18e6b5581754fc6d3;p=vlc diff --git a/modules/codec/cinepak.c b/modules/codec/cinepak.c index 4a3b8eed1c..21f23a110a 100644 --- a/modules/codec/cinepak.c +++ b/modules/codec/cinepak.c @@ -2,7 +2,7 @@ * cinepak.c: cinepak video decoder ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: cinepak.c,v 1.3 2003/11/16 21:07:30 gbazin Exp $ + * $Id$ * * Authors: Laurent Aimar * @@ -24,24 +24,38 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include - #include #include #include -#include +/***************************************************************************** + * Module descriptor + *****************************************************************************/ +static int OpenDecoder ( vlc_object_t * ); +static void CloseDecoder( vlc_object_t * ); + +vlc_module_begin(); + set_description( _("Cinepak video decoder") ); + set_capability( "decoder", 100 ); + set_category( CAT_INPUT ); + set_subcategory( SUBCAT_INPUT_VCODEC ); + set_callbacks( OpenDecoder, CloseDecoder ); +vlc_module_end(); + + +/***************************************************************************** + * Local prototypes + *****************************************************************************/ #define CINEPAK_MAXSTRIP 32 -typedef struct cinepak_codebook_s +typedef struct { uint8_t i_y[4]; uint8_t i_u, i_v; } cinepak_codebook_t; -typedef struct cinepak_context_s +typedef struct { int b_grayscale; /* force to grayscale */ @@ -70,27 +84,13 @@ struct decoder_sys_t /* * Cinepak properties */ - cinepak_context_t *p_context; + cinepak_context_t context; }; -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -static int OpenDecoder( vlc_object_t * ); -static void CloseDecoder( vlc_object_t * ); static picture_t *DecodeBlock ( decoder_t *, block_t ** ); static int cinepak_decode_frame( cinepak_context_t *, int, uint8_t * ); -/***************************************************************************** - * Module descriptor - *****************************************************************************/ -vlc_module_begin(); - set_description( _("Cinepak video decoder") ); - set_capability( "decoder", 70 ); - set_callbacks( OpenDecoder, CloseDecoder ); -vlc_module_end(); - /***************************************************************************** * OpenDecoder: probe the decoder and return score ***************************************************************************** @@ -103,33 +103,23 @@ static int OpenDecoder( vlc_object_t *p_this ) decoder_sys_t *p_sys; vlc_value_t val; - switch( p_dec->fmt_in.i_codec ) + if( p_dec->fmt_in.i_codec != VLC_FOURCC('c','v','i','d') && + p_dec->fmt_in.i_codec != VLC_FOURCC('C','V','I','D') ) { - case VLC_FOURCC('c','v','i','d'): - case VLC_FOURCC('C','V','I','D'): - break; - - default: - return VLC_EGENERIC; + return VLC_EGENERIC; } /* 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 ) + if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL ) { msg_Err( p_dec, "out of memory" ); return VLC_EGENERIC; } - - if( !(p_sys->p_context = malloc( sizeof( cinepak_context_t ) ) ) ) - { - msg_Err( p_dec, "out of memory" ); - } - memset( p_sys->p_context, 0, sizeof( cinepak_context_t ) ); + memset( &p_sys->context, 0, sizeof( cinepak_context_t ) ); var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Get( p_dec, "grayscale", &val ); - p_sys->p_context->b_grayscale = val.b_bool; + p_sys->context.b_grayscale = val.b_bool; p_dec->pf_decode_video = DecodeBlock; @@ -151,11 +141,14 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) picture_t *p_pic; block_t *p_block; - if( !pp_block || !*pp_block ) return NULL; - + if( !pp_block || !*pp_block ) + { + return NULL; + } p_block = *pp_block; + *pp_block = NULL; - i_status = cinepak_decode_frame( p_sys->p_context, p_block->i_buffer, + i_status = cinepak_decode_frame( &p_sys->context, p_block->i_buffer, p_block->p_buffer ); if( i_status < 0 ) { @@ -165,43 +158,38 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) return NULL; } - p_dec->fmt_out.video.i_width = p_sys->p_context->i_width; - p_dec->fmt_out.video.i_height = p_sys->p_context->i_height; - p_dec->fmt_out.video.i_aspect = p_sys->p_context->i_width - * VOUT_ASPECT_FACTOR / p_sys->p_context->i_height; + p_dec->fmt_out.video.i_width = p_sys->context.i_width; + p_dec->fmt_out.video.i_height = p_sys->context.i_height; + p_dec->fmt_out.video.i_aspect = p_sys->context.i_width + * VOUT_ASPECT_FACTOR / p_sys->context.i_height; p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0'); /* Get a new picture */ - p_pic = p_dec->pf_vout_buffer_new( p_dec ); - - if( p_pic == NULL ) + if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) ) { - block_Release( p_block ); - return NULL; - } - - for( i_plane = 0; i_plane < 3; i_plane++ ) - { - int i_line, i_lines; + for( i_plane = 0; i_plane < 3; i_plane++ ) + { + int i_line, i_lines; - p_dst = p_pic->p[i_plane].p_pixels; - p_src = p_sys->p_context->p_pix[i_plane]; + p_dst = p_pic->p[i_plane].p_pixels; + p_src = p_sys->context.p_pix[i_plane]; - i_lines = __MIN( p_sys->p_context->i_lines[i_plane], - p_pic->p[i_plane].i_lines ); - for( i_line = 0; i_line < i_lines; i_line++ ) - { - memcpy( p_dst, p_src, - __MIN( p_pic->p[i_plane].i_pitch, - p_sys->p_context->i_stride[i_plane] ) ); - p_dst += p_pic->p[i_plane].i_pitch; - p_src += p_sys->p_context->i_stride[i_plane]; + i_lines = __MIN( p_sys->context.i_lines[i_plane], + p_pic->p[i_plane].i_visible_lines ); + for( i_line = 0; i_line < i_lines; i_line++ ) + { + memcpy( p_dst, p_src, + __MIN( p_pic->p[i_plane].i_pitch, + p_sys->context.i_stride[i_plane] ) ); + p_dst += p_pic->p[i_plane].i_pitch; + p_src += p_sys->context.i_stride[i_plane]; + } } + + p_pic->date = p_block->i_pts ? p_block->i_pts : p_block->i_dts; } - p_pic->date = p_block->i_pts; block_Release( p_block ); - return p_pic; } @@ -210,7 +198,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) *****************************************************************************/ static void CloseDecoder( 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 = p_dec->p_sys; int i; @@ -218,11 +206,9 @@ static void CloseDecoder( vlc_object_t *p_this ) for( i = 0; i < 3; i++ ) { - if( p_sys->p_context->p_pix[i] ) free( p_sys->p_context->p_pix[i] ); + if( p_sys->context.p_pix[i] ) free( p_sys->context.p_pix[i] ); } - free( p_sys->p_context ); - free( p_sys ); }