X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Frawvideo.c;h=dbb8fdeae64d095f89a0f5823168979a2887bab9;hb=a0d319bab02f2f8109f005424ee0c9df767bdedd;hp=30e05b3f98426f207141ba2da621d5a4aa25548a;hpb=4e8ff11fa527bcfb49eb4e747fac40b7b249233e;p=vlc diff --git a/modules/codec/rawvideo.c b/modules/codec/rawvideo.c index 30e05b3f98..dbb8fdeae6 100644 --- a/modules/codec/rawvideo.c +++ b/modules/codec/rawvideo.c @@ -28,10 +28,9 @@ # include "config.h" #endif -#include +#include #include #include -#include /***************************************************************************** * decoder_sys_t : raw video decoder descriptor @@ -50,8 +49,7 @@ struct decoder_sys_t /* * Common properties */ - mtime_t i_pts; - + date_t pts; }; /**************************************************************************** @@ -69,18 +67,18 @@ static block_t *SendFrame ( decoder_t *, block_t * ); /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_description( N_("Pseudo raw video decoder") ); - set_capability( "decoder", 50 ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_VCODEC ); - set_callbacks( OpenDecoder, CloseDecoder ); - - add_submodule(); - set_description( N_("Pseudo raw video packetizer") ); - set_capability( "packetizer", 100 ); - set_callbacks( OpenPacketizer, CloseDecoder ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("Pseudo raw video decoder") ) + set_capability( "decoder", 50 ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_VCODEC ) + set_callbacks( OpenDecoder, CloseDecoder ) + + add_submodule () + set_description( N_("Pseudo raw video packetizer") ) + set_capability( "packetizer", 100 ) + set_callbacks( OpenPacketizer, CloseDecoder ) +vlc_module_end () /***************************************************************************** * OpenDecoder: probe the decoder and return score @@ -93,36 +91,32 @@ static int OpenDecoder( vlc_object_t *p_this ) switch( p_dec->fmt_in.i_codec ) { /* Planar YUV */ - case VLC_FOURCC('I','4','4','4'): - case VLC_FOURCC('I','4','2','2'): - case VLC_FOURCC('I','4','2','0'): - case VLC_FOURCC('Y','V','1','2'): - case VLC_FOURCC('I','Y','U','V'): - case VLC_FOURCC('I','4','1','1'): - case VLC_FOURCC('I','4','1','0'): - case VLC_FOURCC('Y','V','U','9'): - case VLC_FOURCC('Y','4','2','B'): - case VLC_FOURCC('Y','4','1','B'): + case VLC_CODEC_I444: + case VLC_CODEC_J444: + case VLC_CODEC_I422: + case VLC_CODEC_J422: + case VLC_CODEC_I420: + case VLC_CODEC_J420: + case VLC_CODEC_YV12: + case VLC_CODEC_YV9: + case VLC_CODEC_I411: + case VLC_CODEC_I410: + case VLC_CODEC_GREY: + case VLC_CODEC_YUVP: /* Packed YUV */ - case VLC_FOURCC('Y','U','Y','2'): - case VLC_FOURCC('Y','8','0','0'): - case VLC_FOURCC('U','Y','V','Y'): - case VLC_FOURCC('H','D','Y','C'): + case VLC_CODEC_YUYV: + case VLC_CODEC_YVYU: + case VLC_CODEC_UYVY: + case VLC_CODEC_VYUY: /* RGB */ - case VLC_FOURCC('R','V','3','2'): - case VLC_FOURCC('R','V','2','4'): - case VLC_FOURCC('R','V','1','6'): - case VLC_FOURCC('R','V','1','5'): - break; - case VLC_FOURCC('2','V','u','y'): - case VLC_FOURCC('2','v','u','y'): - case VLC_FOURCC('A','V','U','I'): - p_dec->fmt_in.i_codec = VLC_FOURCC('U','Y','V','Y'); - break; - case VLC_FOURCC('y','v','1','2'): - p_dec->fmt_in.i_codec = VLC_FOURCC('Y','V','1','2'); + case VLC_CODEC_RGB32: + case VLC_CODEC_RGB24: + case VLC_CODEC_RGB16: + case VLC_CODEC_RGB15: + case VLC_CODEC_RGB8: + case VLC_CODEC_RGBP: break; default: @@ -135,7 +129,6 @@ static int OpenDecoder( vlc_object_t *p_this ) return VLC_ENOMEM; /* Misc init */ p_dec->p_sys->b_packetizer = false; - p_sys->i_pts = 0; p_sys->b_invert = 0; if( (int)p_dec->fmt_in.video.i_height < 0 ) @@ -153,30 +146,39 @@ static int OpenDecoder( vlc_object_t *p_this ) return VLC_EGENERIC; } - /* Find out p_vdec->i_raw_size */ - vout_InitFormat( &p_dec->fmt_out.video, p_dec->fmt_in.i_codec, - p_dec->fmt_in.video.i_width, - p_dec->fmt_in.video.i_height, - p_dec->fmt_in.video.i_aspect ); - p_sys->i_raw_size = p_dec->fmt_out.video.i_bits_per_pixel * - p_dec->fmt_out.video.i_width * p_dec->fmt_out.video.i_height / 8; - - /* Set output properties */ - p_dec->fmt_out.i_cat = VIDEO_ES; - p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; - if( !p_dec->fmt_in.video.i_aspect ) + es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); + + date_Init( &p_sys->pts, p_dec->fmt_out.video.i_frame_rate, + p_dec->fmt_out.video.i_frame_rate_base ); + if( p_dec->fmt_out.video.i_frame_rate == 0 || + p_dec->fmt_out.video.i_frame_rate_base == 0) { - p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * - p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height; + msg_Warn( p_dec, "invalid frame rate %d/%d, using 25 fps instead", + p_dec->fmt_out.video.i_frame_rate, + p_dec->fmt_out.video.i_frame_rate_base); + date_Init( &p_sys->pts, 25, 1 ); } - else p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect; - if( p_dec->fmt_in.video.i_rmask ) - p_dec->fmt_out.video.i_rmask = p_dec->fmt_in.video.i_rmask; - if( p_dec->fmt_in.video.i_gmask ) - p_dec->fmt_out.video.i_gmask = p_dec->fmt_in.video.i_gmask; - if( p_dec->fmt_in.video.i_bmask ) - p_dec->fmt_out.video.i_bmask = p_dec->fmt_in.video.i_bmask; + /* Find out p_vdec->i_raw_size */ + video_format_Setup( &p_dec->fmt_out.video, p_dec->fmt_in.i_codec, + p_dec->fmt_in.video.i_width, + p_dec->fmt_in.video.i_height, + p_dec->fmt_in.video.i_sar_num, + p_dec->fmt_in.video.i_sar_den ); + picture_t picture; + picture_Setup( &picture, p_dec->fmt_out.i_codec, + p_dec->fmt_in.video.i_width, + p_dec->fmt_in.video.i_height, 0, 1 ); + p_sys->i_raw_size = 0; + for( int i = 0; i < picture.i_planes; i++ ) + p_sys->i_raw_size += picture.p[i].i_visible_pitch * + picture.p[i].i_visible_lines; + + if( !p_dec->fmt_in.video.i_sar_num || !p_dec->fmt_in.video.i_sar_den ) + { + p_dec->fmt_out.video.i_sar_num = 1; + p_dec->fmt_out.video.i_sar_den = 1; + } /* Set callbacks */ p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **)) @@ -213,23 +215,32 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) p_block = *pp_block; - if( !p_sys->i_pts && !p_block->i_pts && !p_block->i_dts ) + + if( p_block->i_pts <= VLC_TS_INVALID && p_block->i_dts <= VLC_TS_INVALID && + !date_Get( &p_sys->pts ) ) { /* We've just started the stream, wait for the first PTS. */ block_Release( p_block ); return NULL; } - /* Date management */ - if( p_block->i_pts > 0 || p_block->i_dts > 0 ) + /* Date management: If there is a pts avaliable, use that. */ + if( p_block->i_pts > VLC_TS_INVALID ) + { + date_Set( &p_sys->pts, p_block->i_pts ); + } + else if( p_block->i_dts > VLC_TS_INVALID ) { - if( p_block->i_pts > 0 ) p_sys->i_pts = p_block->i_pts; - else if( p_block->i_dts > 0 ) p_sys->i_pts = p_block->i_dts; + /* NB, davidf doesn't quite agree with this in general, it is ok + * for rawvideo since it is in order (ie pts=dts), however, it + * may not be ok for an out-of-order codec, so don't copy this + * without thinking */ + date_Set( &p_sys->pts, p_block->i_dts ); } if( p_block->i_buffer < p_sys->i_raw_size ) { - msg_Warn( p_dec, "invalid frame size (%d < %d)", + msg_Warn( p_dec, "invalid frame size (%zu < %zu)", p_block->i_buffer, p_sys->i_raw_size ); block_Release( p_block ); @@ -246,7 +257,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) } /* Date management: 1 frame per packet */ - p_sys->i_pts += ( INT64_C(1000000) * 1.0 / 25 /*FIXME*/ ); + date_Increment( &p_sys->pts, 1 ); *pp_block = NULL; return p_buf; @@ -257,29 +268,26 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) *****************************************************************************/ static void FillPicture( decoder_t *p_dec, block_t *p_block, picture_t *p_pic ) { - uint8_t *p_src, *p_dst; - int i_plane, i_line, i_width; + int i_plane; decoder_sys_t *p_sys = p_dec->p_sys; - - p_src = p_block->p_buffer; + uint8_t *p_src = p_block->p_buffer; for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) { - p_dst = p_pic->p[i_plane].p_pixels; - i_width = p_pic->p[i_plane].i_pitch; - - if( p_sys->b_invert ) - p_src += (i_width * (p_pic->p[i_plane].i_visible_lines - 1)); - - for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ ) - { - vlc_memcpy( p_dst, p_src, i_width ); - p_src += p_sys->b_invert ? -i_width : i_width; - p_dst += i_width; - } + int i_pitch = p_pic->p[i_plane].i_pitch; + int i_visible_pitch = p_pic->p[i_plane].i_visible_pitch; + int i_visible_lines = p_pic->p[i_plane].i_visible_lines; + uint8_t *p_dst = p_pic->p[i_plane].p_pixels; + uint8_t *p_dst_end = p_dst+i_pitch*i_visible_lines; if( p_sys->b_invert ) - p_src += (i_width * (p_pic->p[i_plane].i_visible_lines + 1)); + for( p_dst_end -= i_pitch; p_dst <= p_dst_end; + p_dst_end -= i_pitch, p_src += i_visible_pitch ) + vlc_memcpy( p_dst_end, p_src, i_visible_pitch ); + else + for( ; p_dst < p_dst_end; + p_dst += i_pitch, p_src += i_visible_pitch ) + vlc_memcpy( p_dst, p_src, i_visible_pitch ); } } @@ -292,7 +300,7 @@ static picture_t *DecodeFrame( decoder_t *p_dec, block_t *p_block ) picture_t *p_pic; /* Get a new picture */ - p_pic = p_dec->pf_vout_buffer_new( p_dec ); + p_pic = decoder_NewPicture( p_dec ); if( !p_pic ) { block_Release( p_block ); @@ -301,7 +309,18 @@ static picture_t *DecodeFrame( decoder_t *p_dec, block_t *p_block ) FillPicture( p_dec, p_block, p_pic ); - p_pic->date = p_sys->i_pts; + p_pic->date = date_Get( &p_sys->pts ); + if( p_block->i_flags & BLOCK_FLAG_INTERLACED_MASK ) + { + p_pic->b_progressive = false; + p_pic->i_nb_fields = 2; + if( p_block->i_flags & BLOCK_FLAG_TOP_FIELD_FIRST ) + p_pic->b_top_field_first = true; + else + p_pic->b_top_field_first = false; + } + else + p_pic->b_progressive = true; block_Release( p_block ); return p_pic; @@ -314,7 +333,7 @@ static block_t *SendFrame( decoder_t *p_dec, block_t *p_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - p_block->i_dts = p_block->i_pts = p_sys->i_pts; + p_block->i_dts = p_block->i_pts = date_Get( &p_sys->pts ); if( p_sys->b_invert ) { @@ -323,9 +342,9 @@ static block_t *SendFrame( decoder_t *p_dec, block_t *p_block ) int i, j; /* Fill in picture_t fields */ - vout_InitPicture( VLC_OBJECT(p_dec), &pic, p_dec->fmt_out.i_codec, - p_dec->fmt_out.video.i_width, - p_dec->fmt_out.video.i_height, VOUT_ASPECT_FACTOR ); + picture_Setup( &pic, p_dec->fmt_out.i_codec, + p_dec->fmt_out.video.i_width, + p_dec->fmt_out.video.i_height, 0, 1 ); if( !pic.i_planes ) {