@ -29,12 +29,13 @@
# include "avcodec.h"
# include "bytestream.h"
# include "internal.h"
# include "zlib_wrapper.h"
# include <zlib.h>
typedef struct WCMVContext {
int bpp ;
z_stream zstream ;
FFZStream zstream ;
AVFrame * prev_frame ;
uint8_t block_data [ 65536 * 8 ] ;
} WCMVContext ;
@ -44,12 +45,13 @@ static int decode_frame(AVCodecContext *avctx,
AVPacket * avpkt )
{
WCMVContext * s = avctx - > priv_data ;
z_stream * const zstream = & s - > zstream . zstream ;
AVFrame * frame = data ;
int skip , blocks , zret , ret , intra = 0 , flags = 0 , bpp = s - > bpp ;
GetByteContext gb ;
uint8_t * dst ;
ret = inflateReset ( & s - > zstream ) ;
ret = inflateReset ( zstream ) ;
if ( ret ! = Z_OK ) {
av_log ( avctx , AV_LOG_ERROR , " Inflate reset error: %d \n " , ret ) ;
return AVERROR_EXTERNAL ;
@ -78,19 +80,19 @@ static int decode_frame(AVCodecContext *avctx,
if ( size > avpkt - > size - skip )
return AVERROR_INVALIDDATA ;
s - > zstream . next_in = avpkt - > data + skip ;
s - > zstream . avail_in = size ;
s - > zstream . next_out = s - > block_data ;
s - > zstream . avail_out = sizeof ( s - > block_data ) ;
z stream - > next_in = avpkt - > data + skip ;
z stream - > avail_in = size ;
z stream - > next_out = s - > block_data ;
z stream - > avail_out = sizeof ( s - > block_data ) ;
zret = inflate ( & s - > zstream , Z_FINISH ) ;
zret = inflate ( zstream , Z_FINISH ) ;
if ( zret ! = Z_STREAM_END ) {
av_log ( avctx , AV_LOG_ERROR ,
" Inflate failed with return code: %d. \n " , zret ) ;
return AVERROR_INVALIDDATA ;
}
ret = inflateReset ( & s - > zstream ) ;
ret = inflateReset ( zstream ) ;
if ( ret ! = Z_OK ) {
av_log ( avctx , AV_LOG_ERROR , " Inflate reset error: %d \n " , ret ) ;
return AVERROR_EXTERNAL ;
@ -119,8 +121,8 @@ static int decode_frame(AVCodecContext *avctx,
skip = bytestream2_tell ( & gb ) ;
s - > zstream . next_in = avpkt - > data + skip ;
s - > zstream . avail_in = avpkt - > size - skip ;
z stream - > next_in = avpkt - > data + skip ;
z stream - > avail_in = avpkt - > size - skip ;
bytestream2_init ( & gb , s - > block_data , blocks * 8 ) ;
} else if ( blocks ) {
@ -148,8 +150,8 @@ static int decode_frame(AVCodecContext *avctx,
skip = bytestream2_tell ( & gb ) ;
s - > zstream . next_in = avpkt - > data + skip ;
s - > zstream . avail_in = avpkt - > size - skip ;
z stream - > next_in = avpkt - > data + skip ;
z stream - > avail_in = avpkt - > size - skip ;
bytestream2_seek ( & gb , 2 , SEEK_SET ) ;
}
@ -182,10 +184,10 @@ static int decode_frame(AVCodecContext *avctx,
dst = s - > prev_frame - > data [ 0 ] + ( avctx - > height - y - 1 ) * s - > prev_frame - > linesize [ 0 ] + x * bpp ;
for ( int i = 0 ; i < h ; i + + ) {
s - > zstream . next_out = dst ;
s - > zstream . avail_out = w * bpp ;
z stream - > next_out = dst ;
z stream - > avail_out = w * bpp ;
zret = inflate ( & s - > zstream , Z_SYNC_FLUSH ) ;
zret = inflate ( zstream , Z_SYNC_FLUSH ) ;
if ( zret ! = Z_OK & & zret ! = Z_STREAM_END ) {
av_log ( avctx , AV_LOG_ERROR ,
" Inflate failed with return code: %d. \n " , zret ) ;
@ -210,7 +212,6 @@ static int decode_frame(AVCodecContext *avctx,
static av_cold int decode_init ( AVCodecContext * avctx )
{
WCMVContext * s = avctx - > priv_data ;
int zret ;
switch ( avctx - > bits_per_coded_sample ) {
case 16 : avctx - > pix_fmt = AV_PIX_FMT_RGB565LE ; break ;
@ -223,20 +224,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
s - > bpp = avctx - > bits_per_coded_sample > > 3 ;
s - > zstream . zalloc = Z_NULL ;
s - > zstream . zfree = Z_NULL ;
s - > zstream . opaque = Z_NULL ;
zret = inflateInit ( & s - > zstream ) ;
if ( zret ! = Z_OK ) {
av_log ( avctx , AV_LOG_ERROR , " Inflate init error: %d \n " , zret ) ;
return AVERROR_EXTERNAL ;
}
s - > prev_frame = av_frame_alloc ( ) ;
if ( ! s - > prev_frame )
return AVERROR ( ENOMEM ) ;
return 0 ;
return ff_inflate_init ( & s - > zstream , avctx ) ;
}
static av_cold int decode_close ( AVCodecContext * avctx )
@ -244,7 +236,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
WCMVContext * s = avctx - > priv_data ;
av_frame_free ( & s - > prev_frame ) ;
inflateE nd( & s - > zstream ) ;
ff_inflate_e nd( & s - > zstream ) ;
return 0 ;
}