Commit c556378f authored by Gildas Bazin's avatar Gildas Bazin

* src/video_output/vout_pictures.c, include/video_output.h: added a vout_InitPicture() function that initializes a picture_t structure based on the given chroma and sizes.
* modules/encoder/ffmpeg/video.c: misc improvements. Should also be able to handle more input chroma format.
* modules/codec/rawvideo.c: a few fixes.
* modules/access/v4l/v4l.c: misc improvments and cleanup. Should be able to handle more source chroma formats. On the fly video encoding is also working perfectly now.
parent 15fb1485
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* thread, and destroy a previously opened video output thread. * thread, and destroy a previously opened video output thread.
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * Copyright (C) 1999, 2000 VideoLAN
* $Id: video_output.h,v 1.93 2003/03/24 23:50:46 gbazin Exp $ * $Id: video_output.h,v 1.94 2003/04/27 23:16:35 gbazin Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr> * Samuel Hocevar <sam@via.ecp.fr>
...@@ -155,6 +155,7 @@ VLC_EXPORT( int, vout_VarCallback, ( vlc_object_t *, const char *, vlc_value_t, ...@@ -155,6 +155,7 @@ VLC_EXPORT( int, vout_VarCallback, ( vlc_object_t *, const char *, vlc_value_t,
VLC_EXPORT( int, vout_ChromaCmp, ( uint32_t, uint32_t ) ); VLC_EXPORT( int, vout_ChromaCmp, ( uint32_t, uint32_t ) );
VLC_EXPORT( picture_t *, vout_CreatePicture, ( vout_thread_t *, vlc_bool_t, vlc_bool_t, vlc_bool_t ) ); VLC_EXPORT( picture_t *, vout_CreatePicture, ( vout_thread_t *, vlc_bool_t, vlc_bool_t, vlc_bool_t ) );
VLC_EXPORT( void, vout_InitPicture, ( vlc_object_t *, picture_t *, int, int, uint32_t ) );
VLC_EXPORT( void, vout_AllocatePicture,( vout_thread_t *, picture_t *, int, int, uint32_t ) ); VLC_EXPORT( void, vout_AllocatePicture,( vout_thread_t *, picture_t *, int, int, uint32_t ) );
VLC_EXPORT( void, vout_DestroyPicture, ( vout_thread_t *, picture_t * ) ); VLC_EXPORT( void, vout_DestroyPicture, ( vout_thread_t *, picture_t * ) );
VLC_EXPORT( void, vout_DisplayPicture, ( vout_thread_t *, picture_t * ) ); VLC_EXPORT( void, vout_DisplayPicture, ( vout_thread_t *, picture_t * ) );
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* rawvideo.c: Pseudo audio decoder; for raw video data * rawvideo.c: Pseudo audio decoder; for raw video data
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: rawvideo.c,v 1.3 2003/04/27 17:53:20 gbazin Exp $ * $Id: rawvideo.c,v 1.4 2003/04/27 23:16:35 gbazin Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -161,7 +161,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo ) ...@@ -161,7 +161,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
*****************************************************************************/ *****************************************************************************/
static int InitThread( vdec_thread_t * p_vdec ) static int InitThread( vdec_thread_t * p_vdec )
{ {
picture_t *p_pic; picture_t pic;
int i; int i;
#define bih ((BITMAPINFOHEADER*)p_vdec->p_fifo->p_bitmapinfoheader) #define bih ((BITMAPINFOHEADER*)p_vdec->p_fifo->p_bitmapinfoheader)
...@@ -187,27 +187,19 @@ static int InitThread( vdec_thread_t * p_vdec ) ...@@ -187,27 +187,19 @@ static int InitThread( vdec_thread_t * p_vdec )
if( p_vdec->p_vout == NULL ) if( p_vdec->p_vout == NULL )
{ {
msg_Err( p_vdec->p_fifo, "failled created vout" ); msg_Err( p_vdec->p_fifo, "failed created vout" );
return( VLC_EGENERIC );
}
/* Get a 1 picture to be able to compute p_vdec->i_raw_size */
p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 );
if( p_pic == NULL )
{
msg_Err( p_vdec->p_fifo, "failled to get a vout picture" );
return( VLC_EGENERIC ); return( VLC_EGENERIC );
} }
/* Find out p_vdec->i_raw_size */
vout_InitPicture( VLC_OBJECT(p_vdec->p_fifo), &pic,
bih->biWidth, bih->biHeight, p_vdec->p_fifo->i_fourcc );
p_vdec->i_raw_size = 0; p_vdec->i_raw_size = 0;
for( i = 0; i < p_pic->i_planes; i++ ) for( i = 0; i < pic.i_planes; i++ )
{ {
p_vdec->i_raw_size += p_pic->p[i].i_lines * p_pic->p[i].i_visible_pitch p_vdec->i_raw_size += pic.p[i].i_lines * pic.p[i].i_visible_pitch;
* p_pic->p[i].i_pixel_pitch;
} }
vout_DestroyPicture( p_vdec->p_vout, p_pic );
return( VLC_SUCCESS ); return( VLC_SUCCESS );
#undef bih #undef bih
} }
...@@ -284,8 +276,9 @@ static void DecodeThread( vdec_thread_t *p_vdec ) ...@@ -284,8 +276,9 @@ static void DecodeThread( vdec_thread_t *p_vdec )
if( i_size < p_vdec->i_raw_size ) if( i_size < p_vdec->i_raw_size )
{ {
msg_Warn( p_vdec->p_fifo, "invalid frame size (%d < %d)", i_size, p_vdec->i_raw_size ); msg_Warn( p_vdec->p_fifo, "invalid frame size (%d < %d)",
input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes ); i_size, p_vdec->i_raw_size );
//input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
return; return;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* encoder.c : audio/video encoder using ffmpeg library * encoder.c : audio/video encoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: encoder.c,v 1.3 2003/04/26 14:54:49 gbazin Exp $ * $Id: encoder.c,v 1.4 2003/04/27 23:16:35 gbazin Exp $
* *
* Authors: Laurent Aimar * Authors: Laurent Aimar
* *
...@@ -48,19 +48,18 @@ void E_( CloseEncoderAudio )( vlc_object_t * ); ...@@ -48,19 +48,18 @@ void E_( CloseEncoderAudio )( vlc_object_t * );
*****************************************************************************/ *****************************************************************************/
vlc_module_begin(); vlc_module_begin();
set_description( _("ffmpeg encoder") ); set_description( _("ffmpeg video encoder") );
add_shortcut( "ffmpeg" ); add_shortcut( "ffmpeg" );
set_capability( "video encoder", 100 );
set_callbacks( E_( OpenEncoderVideo ), E_( CloseEncoderVideo ) );
add_category_hint( "video setting", NULL, VLC_TRUE );
add_integer( "encoder-ffmpeg-video-bitrate", 1000, NULL, "bitrate (kb/s)", "bitrate (kb/s)", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-max-key-interval", 10, NULL, "max key interval", "maximum value of frames between two keyframes", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-min-quant", 2, NULL, "min quantizer", "range 1-31", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-max-quant", 31, NULL, "max quantizer", "range 1-31", VLC_TRUE );
add_submodule(); add_submodule();
set_capability( "video encoder", 100 ); set_description( _("ffmpeg audio encoder") );
set_callbacks( E_( OpenEncoderVideo ), E_( CloseEncoderVideo ) );
add_category_hint( "video setting", NULL, VLC_TRUE );
add_integer( "encoder-ffmpeg-video-bitrate", 1000, NULL, "bitrate (kb/s)", "bitrate (kb/s)", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-max-key-interval", 10, NULL, "max key interval", "maximum value of frames between two keyframes", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-min-quant", 2, NULL, "min quantizer", "range 1-31", VLC_TRUE );
add_integer( "encoder-ffmpeg-video-max-quant", 31, NULL, "max quantizer", "range 1-31", VLC_TRUE );
add_submodule();
set_capability( "audio encoder", 50 ); set_capability( "audio encoder", 50 );
set_callbacks( E_( OpenEncoderAudio ), E_( CloseEncoderAudio ) ); set_callbacks( E_( OpenEncoderAudio ), E_( CloseEncoderAudio ) );
add_category_hint( "audio setting", NULL, VLC_TRUE ); add_category_hint( "audio setting", NULL, VLC_TRUE );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* video.c : video encoder using ffmpeg library * video.c : video encoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: video.c,v 1.3 2003/04/26 14:54:49 gbazin Exp $ * $Id: video.c,v 1.4 2003/04/27 23:16:35 gbazin Exp $
* *
* Authors: Laurent Aimar * Authors: Laurent Aimar
* *
...@@ -49,7 +49,7 @@ void E_( CloseEncoderVideo )( vlc_object_t * ); ...@@ -49,7 +49,7 @@ void E_( CloseEncoderVideo )( vlc_object_t * );
*****************************************************************************/ *****************************************************************************/
static int Init ( video_encoder_t *p_encoder ); static int Init ( video_encoder_t *p_encoder );
static int Encode ( video_encoder_t *p_encoder, static int Encode ( video_encoder_t *p_encoder,
picture_t *p_pic, void *p_data, size_t *pi_data ); picture_t *p_pic, void *p_data, size_t *pi_data );
static void End ( video_encoder_t *p_encoder ); static void End ( video_encoder_t *p_encoder );
/***************************************************************************** /*****************************************************************************
...@@ -70,7 +70,7 @@ struct encoder_sys_t ...@@ -70,7 +70,7 @@ struct encoder_sys_t
***************************************************************************** *****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
int E_( OpenEncoderVideo ) ( vlc_object_t *p_this ) int E_( OpenEncoderVideo ) ( vlc_object_t *p_this )
{ {
video_encoder_t *p_encoder = (video_encoder_t*)p_this; video_encoder_t *p_encoder = (video_encoder_t*)p_this;
...@@ -91,16 +91,27 @@ int E_( OpenEncoderVideo ) ( vlc_object_t *p_this ) ...@@ -91,16 +91,27 @@ int E_( OpenEncoderVideo ) ( vlc_object_t *p_this )
avcodec_register_all(); avcodec_register_all();
/* *** fix parameters *** */ /* *** fix parameters *** */
/* FIXME be clever, some codec support additional chroma */
if( p_encoder->i_chroma != VLC_FOURCC( 'I', '4', '2', '0' ) )
switch( p_encoder->i_chroma ) switch( p_encoder->i_chroma )
{ {
case VLC_FOURCC( 'I', '4', '2', '0' ): /* Planar YUV formats */
case VLC_FOURCC( 'I', '4', '2', '2' ): case VLC_FOURCC('I','4','4','4'):
case VLC_FOURCC( 'Y', 'U', 'Y', '2' ): case VLC_FOURCC('I','4','2','2'):
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
case VLC_FOURCC('I','4','1','1'):
case VLC_FOURCC('I','4','1','0'):
/* Packed YUV formats */
case VLC_FOURCC('Y','U','Y','2'):
case VLC_FOURCC('U','Y','V','Y'):
/* Packed RGB formats */
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'):
case VLC_FOURCC('R','G','B','2'):
break; break;
default: default:
p_encoder->i_chroma = VLC_FOURCC( 'I', '4', '2', '0' );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
#if 0 #if 0
...@@ -161,7 +172,8 @@ static int Init ( video_encoder_t *p_encoder ) ...@@ -161,7 +172,8 @@ static int Init ( video_encoder_t *p_encoder )
} }
if( ( p_sys->p_codec = avcodec_find_encoder( i_codec ) ) == NULL ) if( ( p_sys->p_codec = avcodec_find_encoder( i_codec ) ) == NULL )
{ {
msg_Err( p_encoder, "cannot find encoder for %s", p_encoder->p_sys->psz_codec ); msg_Err( p_encoder, "cannot find encoder for %s",
p_encoder->p_sys->psz_codec );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -185,7 +197,8 @@ static int Init ( video_encoder_t *p_encoder ) ...@@ -185,7 +197,8 @@ static int Init ( video_encoder_t *p_encoder )
if( avcodec_open( p_context, p_encoder->p_sys->p_codec ) < 0 ) if( avcodec_open( p_context, p_encoder->p_sys->p_codec ) < 0 )
{ {
msg_Err( p_encoder, "failed to open %s codec", p_encoder->p_sys->psz_codec ); msg_Err( p_encoder, "failed to open %s codec",
p_encoder->p_sys->psz_codec );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -193,15 +206,59 @@ static int Init ( video_encoder_t *p_encoder ) ...@@ -193,15 +206,59 @@ static int Init ( video_encoder_t *p_encoder )
switch( p_encoder->i_chroma ) switch( p_encoder->i_chroma )
{ {
case VLC_FOURCC( 'I', '4', '2', '0' ): /* Planar YUV formats */
p_frame->pict_type = PIX_FMT_YUV420P; case VLC_FOURCC('I','4','4','4'):
p_frame->pict_type = PIX_FMT_YUV444P;
break; break;
case VLC_FOURCC( 'I', '4', '2', '2' ):
case VLC_FOURCC('I','4','2','2'):
p_frame->pict_type = PIX_FMT_YUV422P; p_frame->pict_type = PIX_FMT_YUV422P;
break; break;
case VLC_FOURCC( 'Y', 'U', 'Y', '2' ):
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
p_frame->pict_type = PIX_FMT_YUV420P;
break;
case VLC_FOURCC('I','4','1','1'):
p_frame->pict_type = PIX_FMT_YUV411P;
break;
case VLC_FOURCC('I','4','1','0'):
p_frame->pict_type = PIX_FMT_YUV410P;
break;
/* Packed YUV formats */
case VLC_FOURCC('Y','U','Y','2'):
case VLC_FOURCC('U','Y','V','Y'):
p_frame->pict_type = PIX_FMT_YUV422; p_frame->pict_type = PIX_FMT_YUV422;
break; break;
/* Packed RGB formats */
case VLC_FOURCC('R','V','3','2'):
p_frame->pict_type = PIX_FMT_RGBA32;
break;
case VLC_FOURCC('R','V','2','4'):
p_frame->pict_type = PIX_FMT_RGB24;
//p_frame->pict_type = PIX_FMT_BGR24;
break;
case VLC_FOURCC('R','V','1','6'):
p_frame->pict_type = PIX_FMT_RGB565;
break;
case VLC_FOURCC('R','V','1','5'):
p_frame->pict_type = PIX_FMT_RGB555;
break;
case VLC_FOURCC('R','G','B','2'):
p_frame->pict_type = PIX_FMT_GRAY8;
break;
default: default:
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -217,14 +274,14 @@ static int Init ( video_encoder_t *p_encoder ) ...@@ -217,14 +274,14 @@ static int Init ( video_encoder_t *p_encoder )
***************************************************************************** *****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
static int Encode ( video_encoder_t *p_encoder, static int Encode( video_encoder_t *p_encoder,
picture_t *p_pic, void *p_data, size_t *pi_data ) picture_t *p_pic, void *p_data, size_t *pi_data )
{ {
#define p_frame p_encoder->p_sys->p_frame #define p_frame p_encoder->p_sys->p_frame
#define p_context p_encoder->p_sys->p_context #define p_context p_encoder->p_sys->p_context
int i; int i;
for( i = 0; i < 3; i++ ) for( i = 0; i < p_pic->i_planes; i++ )
{ {
p_frame->linesize[i] = p_pic->p[i].i_pitch; p_frame->linesize[i] = p_pic->p[i].i_pitch;
p_frame->data[i] = p_pic->p[i].p_pixels; p_frame->data[i] = p_pic->p[i].p_pixels;
...@@ -241,7 +298,7 @@ static int Encode ( video_encoder_t *p_encoder, ...@@ -241,7 +298,7 @@ static int Encode ( video_encoder_t *p_encoder,
***************************************************************************** *****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
static void End ( video_encoder_t *p_encoder ) static void End( video_encoder_t *p_encoder )
{ {
avcodec_close( p_encoder->p_sys->p_context ); avcodec_close( p_encoder->p_sys->p_context );
free( p_encoder->p_sys->p_context ); free( p_encoder->p_sys->p_context );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vout_pictures.c : picture management functions * vout_pictures.c : picture management functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2000 VideoLAN * Copyright (C) 2000 VideoLAN
* $Id: vout_pictures.c,v 1.38 2003/04/27 17:53:21 gbazin Exp $ * $Id: vout_pictures.c,v 1.39 2003/04/27 23:16:35 gbazin Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -438,6 +438,44 @@ void vout_AllocatePicture( vout_thread_t *p_vout, picture_t *p_pic, ...@@ -438,6 +438,44 @@ void vout_AllocatePicture( vout_thread_t *p_vout, picture_t *p_pic,
{ {
int i_bytes, i_index; int i_bytes, i_index;
vout_InitPicture( VLC_OBJECT(p_vout), p_pic, i_width, i_height, i_chroma );
/* Calculate how big the new image should be */
for( i_bytes = 0, i_index = 0; i_index < p_pic->i_planes; i_index++ )
{
i_bytes += p_pic->p[ i_index ].i_lines * p_pic->p[ i_index ].i_pitch;
}
p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
if( p_pic->p_data == NULL )
{
p_pic->i_planes = 0;
return;
}
/* Fill the p_pixels field for each plane */
p_pic->p[ 0 ].p_pixels = p_pic->p_data;
for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
{
p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels
+ p_pic->p[i_index-1].i_lines
* p_pic->p[i_index-1].i_pitch;
}
}
/*****************************************************************************
* vout_InitPicture: initialise the picture_t fields given chroma/size.
*****************************************************************************
* This function initializes most of the picture_t fields given a chroma and
* size. It makes the assumption that stride == width.
*****************************************************************************/
void vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
int i_width, int i_height, vlc_fourcc_t i_chroma )
{
int i_index;
/* Store default values */ /* Store default values */
for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ ) for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
{ {
...@@ -588,35 +626,12 @@ void vout_AllocatePicture( vout_thread_t *p_vout, picture_t *p_pic, ...@@ -588,35 +626,12 @@ void vout_AllocatePicture( vout_thread_t *p_vout, picture_t *p_pic,
break; break;
default: default:
msg_Err( p_vout, "unknown chroma type 0x%.8x (%4.4s)", msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
i_chroma, (char*)&i_chroma ); i_chroma, (char*)&i_chroma );
p_pic->i_planes = 0; p_pic->i_planes = 0;
return; return;
} }
/* Calculate how big the new image should be */
for( i_bytes = 0, i_index = 0; i_index < p_pic->i_planes; i_index++ )
{
i_bytes += p_pic->p[ i_index ].i_lines * p_pic->p[ i_index ].i_pitch;
}
p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
if( p_pic->p_data == NULL )
{
p_pic->i_planes = 0;
return;
}
/* Fill the p_pixels field for each plane */
p_pic->p[ 0 ].p_pixels = p_pic->p_data;
for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
{
p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels
+ p_pic->p[i_index-1].i_lines
* p_pic->p[i_index-1].i_pitch;
}
} }
/***************************************************************************** /*****************************************************************************
......
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