Commit f2c55479 authored by Gildas Bazin's avatar Gildas Bazin

* modules/codec/ffmpeg/video_filter.c, include/vlc_filter.h:

  - chroma + resizing video filter (using the filter_t architecture).
* modules/codec/ffmpeg/*:
  - cleanup + small updates.
* modules/codec/speex.c, theora.c, vorbis.c:
  - got rid of pf_header() in the encoder.
  - store the headers in fmt_out.p_extra (this will break the ogg muxer for now).
* modules/codec/libmpeg2.c, modules/codec/ffmpeg/video.c:
  - added a p_dec->b_pace_control field to signal if the decoder is allowed to drop frames.
* modules/stream_out/transcode.c:
  - heavy cleanup.
  - re-use video decoder modules and got rid of the duplicated ffmpeg video decoder.
  - use video filters for chroma conversion and resizing.
  (a few things are broken now like deinterlacing but I'll repair them asap).
parent 881b68a0
...@@ -46,20 +46,23 @@ struct decoder_t ...@@ -46,20 +46,23 @@ struct decoder_t
module_t * p_module; module_t * p_module;
decoder_sys_t * p_sys; decoder_sys_t * p_sys;
picture_t * ( * pf_decode_video )( decoder_t *, block_t ** );
aout_buffer_t * ( * pf_decode_audio )( decoder_t *, block_t ** );
subpicture_t * ( * pf_decode_sub) ( decoder_t *, block_t ** );
block_t * ( * pf_packetize ) ( decoder_t *, block_t ** );
/* Some decoders only accept packetized data (ie. not truncated) */
vlc_bool_t b_need_packetized;
/* Input format ie from demuxer (XXX: a lot of field could be invalid) */ /* Input format ie from demuxer (XXX: a lot of field could be invalid) */
es_format_t fmt_in; es_format_t fmt_in;
/* Output format of decoder/packetizer */ /* Output format of decoder/packetizer */
es_format_t fmt_out; es_format_t fmt_out;
/* Some decoders only accept packetized data (ie. not truncated) */
vlc_bool_t b_need_packetized;
/* Tell the decoder if it is allowed to drop frames */
vlc_bool_t b_pace_control;
picture_t * ( * pf_decode_video )( decoder_t *, block_t ** );
aout_buffer_t * ( * pf_decode_audio )( decoder_t *, block_t ** );
subpicture_t * ( * pf_decode_sub) ( decoder_t *, block_t ** );
block_t * ( * pf_packetize ) ( decoder_t *, block_t ** );
/* /*
* Buffers allocation * Buffers allocation
*/ */
...@@ -102,17 +105,16 @@ struct encoder_t ...@@ -102,17 +105,16 @@ struct encoder_t
module_t * p_module; module_t * p_module;
encoder_sys_t * p_sys; encoder_sys_t * p_sys;
block_t * ( * pf_header )( encoder_t * );
block_t * ( * pf_encode_video )( encoder_t *, picture_t * );
block_t * ( * pf_encode_audio )( encoder_t *, aout_buffer_t * );
block_t * ( * pf_encode_sub )( encoder_t *, subpicture_t * );
/* Properties of the input data fed to the encoder */ /* Properties of the input data fed to the encoder */
es_format_t fmt_in; es_format_t fmt_in;
/* Properties of the output of the encoder */ /* Properties of the output of the encoder */
es_format_t fmt_out; es_format_t fmt_out;
block_t * ( * pf_encode_video )( encoder_t *, picture_t * );
block_t * ( * pf_encode_audio )( encoder_t *, aout_buffer_t * );
block_t * ( * pf_encode_sub )( encoder_t *, subpicture_t * );
/* Common encoder options */ /* Common encoder options */
int i_threads; /* Number of threads to use during encoding */ int i_threads; /* Number of threads to use during encoding */
int i_iframes; /* One I frame per i_iframes */ int i_iframes; /* One I frame per i_iframes */
......
...@@ -45,6 +45,12 @@ struct filter_t ...@@ -45,6 +45,12 @@ struct filter_t
module_t * p_module; module_t * p_module;
filter_sys_t * p_sys; filter_sys_t * p_sys;
/* Input format */
es_format_t fmt_in;
/* Output format of filter */
es_format_t fmt_out;
void ( * pf_video_blend ) ( filter_t *, picture_t *, void ( * pf_video_blend ) ( filter_t *, picture_t *,
picture_t *, picture_t *, picture_t *, picture_t *,
int, int ); int, int );
...@@ -52,12 +58,6 @@ struct filter_t ...@@ -52,12 +58,6 @@ struct filter_t
subpicture_t * ( *pf_render_string ) ( filter_t *, block_t * ); subpicture_t * ( *pf_render_string ) ( filter_t *, block_t * );
/* Input format */
es_format_t fmt_in;
/* Output format of filter */
es_format_t fmt_out;
/* /*
* Buffers allocation * Buffers allocation
*/ */
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#define VLC_OBJECT_ACCESS (-19) #define VLC_OBJECT_ACCESS (-19)
#define VLC_OBJECT_STREAM (-20) #define VLC_OBJECT_STREAM (-20)
#define VLC_OBJECT_OPENGL (-21) #define VLC_OBJECT_OPENGL (-21)
#define VLC_OBJECT_FILTER (-22)
#define VLC_OBJECT_GENERIC (-666) #define VLC_OBJECT_GENERIC (-666)
......
...@@ -106,6 +106,9 @@ struct picture_t ...@@ -106,6 +106,9 @@ struct picture_t
/** Private data - the video output plugin might want to put stuff here to /** Private data - the video output plugin might want to put stuff here to
* keep track of the picture */ * keep track of the picture */
picture_sys_t * p_sys; picture_sys_t * p_sys;
/** This way the picture_Release can be overloaded */
void (*pf_release)( picture_t * );
}; };
/** /**
......
...@@ -3,6 +3,7 @@ SOURCES_ffmpeg = \ ...@@ -3,6 +3,7 @@ SOURCES_ffmpeg = \
ffmpeg.h \ ffmpeg.h \
video.c \ video.c \
audio.c \ audio.c \
video_filter.c \
chroma.c \ chroma.c \
encoder.c \ encoder.c \
postprocess.c \ postprocess.c \
...@@ -14,6 +15,7 @@ SOURCES_ffmpegaltivec = \ ...@@ -14,6 +15,7 @@ SOURCES_ffmpegaltivec = \
ffmpeg.h \ ffmpeg.h \
video.c \ video.c \
audio.c \ audio.c \
video_filter.c \
chroma.c \ chroma.c \
encoder.c \ encoder.c \
postprocess.c \ postprocess.c \
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id$ * $Id$
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -72,67 +72,8 @@ int E_(OpenChroma)( vlc_object_t *p_this ) ...@@ -72,67 +72,8 @@ int E_(OpenChroma)( vlc_object_t *p_this )
i_vlc_chroma[1] = p_vout->output.i_chroma; i_vlc_chroma[1] = p_vout->output.i_chroma;
for( i = 0; i < 2; i++ ) for( i = 0; i < 2; i++ )
{ {
switch( i_vlc_chroma[i] ) i_ffmpeg_chroma[i] = E_(GetFfmpegChroma)( i_vlc_chroma[i] );
{ if( i_ffmpeg_chroma[i] < 0 ) return VLC_EGENERIC;
/* Planar YUV formats */
case VLC_FOURCC('I','4','4','4'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV444P;
break;
case VLC_FOURCC('I','4','2','2'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV422P;
break;
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV420P;
break;
case VLC_FOURCC('I','4','1','1'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV411P;
break;
case VLC_FOURCC('I','4','1','0'):
case VLC_FOURCC('Y','V','U','9'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV410P;
break;
/* Packed YUV formats */
case VLC_FOURCC('Y','U','Y','2'):
case VLC_FOURCC('U','Y','V','Y'):
i_ffmpeg_chroma[i] = PIX_FMT_YUV422;
break;
/* Packed RGB formats */
case VLC_FOURCC('R','V','3','2'):
i_ffmpeg_chroma[i] = PIX_FMT_RGBA32;
break;
case VLC_FOURCC('R','V','2','4'):
i_ffmpeg_chroma[i] = PIX_FMT_RGB24;
//i_ffmpeg_chroma[i] = PIX_FMT_BGR24;
break;
case VLC_FOURCC('R','V','1','6'):
i_ffmpeg_chroma[i] = PIX_FMT_RGB565;
break;
case VLC_FOURCC('R','V','1','5'):
i_ffmpeg_chroma[i] = PIX_FMT_RGB555;
break;
case VLC_FOURCC('R','G','B','2'):
i_ffmpeg_chroma[i] = PIX_FMT_GRAY8;
break;
default:
return VLC_EGENERIC;
break;
}
} }
p_vout->chroma.pf_convert = ChromaConversion; p_vout->chroma.pf_convert = ChromaConversion;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* $Id$ * $Id$
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com> * Gildas Bazin <gbazin@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -160,9 +160,15 @@ vlc_module_begin(); ...@@ -160,9 +160,15 @@ vlc_module_begin();
/* demux submodule */ /* demux submodule */
add_submodule(); add_submodule();
set_description( _("ffmpeg demuxer" ) ); set_description( _("ffmpeg demuxer" ) );
set_capability( "demux2", 1 ); set_capability( "demux2", 2 );
set_callbacks( E_(OpenDemux), E_(CloseDemux) ); set_callbacks( E_(OpenDemux), E_(CloseDemux) );
/* video filter submodule */
add_submodule();
set_capability( "video filter2", 50 );
set_callbacks( E_(OpenFilter), E_(CloseFilter) );
set_description( _("ffmpeg video filter") );
var_Create( p_module->p_libvlc, "avcodec", VLC_VAR_MUTEX ); var_Create( p_module->p_libvlc, "avcodec", VLC_VAR_MUTEX );
vlc_module_end(); vlc_module_end();
...@@ -283,33 +289,6 @@ static void CloseDecoder( vlc_object_t *p_this ) ...@@ -283,33 +289,6 @@ static void CloseDecoder( vlc_object_t *p_this )
/***************************************************************************** /*****************************************************************************
* local Functions * local Functions
*****************************************************************************/ *****************************************************************************/
int E_(GetFfmpegChroma)( vlc_fourcc_t i_chroma )
{
switch( i_chroma )
{
case VLC_FOURCC( 'I', '4', '2', '0' ):
return PIX_FMT_YUV420P;
case VLC_FOURCC( 'I', '4', '2', '2' ):
return PIX_FMT_YUV422P;
case VLC_FOURCC( 'I', '4', '4', '4' ):
return PIX_FMT_YUV444P;
case VLC_FOURCC( 'R', 'V', '1', '5' ):
return PIX_FMT_RGB555;
case VLC_FOURCC( 'R', 'V', '1', '6' ):
return PIX_FMT_RGB565;
case VLC_FOURCC( 'R', 'V', '2', '4' ):
return PIX_FMT_RGB24;
case VLC_FOURCC( 'R', 'V', '3', '2' ):
return PIX_FMT_RGBA32;
case VLC_FOURCC( 'G', 'R', 'E', 'Y' ):
return PIX_FMT_GRAY8;
case VLC_FOURCC( 'Y', 'U', 'Y', '2' ):
return PIX_FMT_YUV422;
default:
return -1;
}
}
void E_(InitLibavcodec)( vlc_object_t *p_object ) void E_(InitLibavcodec)( vlc_object_t *p_object )
{ {
static int b_ffmpeginit = 0; static int b_ffmpeginit = 0;
...@@ -336,7 +315,67 @@ void E_(InitLibavcodec)( vlc_object_t *p_object ) ...@@ -336,7 +315,67 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
} }
/*****************************************************************************
* Chroma fourcc -> ffmpeg_id mapping
*****************************************************************************/
static struct
{
vlc_fourcc_t i_chroma;
int i_chroma_id;
} chroma_table[] =
{
/* Planar YUV formats */
{ VLC_FOURCC('I','4','4','4'), PIX_FMT_YUV444P },
{ VLC_FOURCC('I','4','2','2'), PIX_FMT_YUV422P },
{ VLC_FOURCC('I','4','2','0'), PIX_FMT_YUV420P },
{ VLC_FOURCC('Y','V','1','2'), PIX_FMT_YUV420P },
{ VLC_FOURCC('I','Y','U','V'), PIX_FMT_YUV420P },
{ VLC_FOURCC('I','4','1','1'), PIX_FMT_YUV411P },
{ VLC_FOURCC('I','4','1','0'), PIX_FMT_YUV410P },
{ VLC_FOURCC('Y','V','U','9'), PIX_FMT_YUV410P },
/* Packed YUV formats */
{ VLC_FOURCC('Y','U','Y','2'), PIX_FMT_YUV422 },
{ VLC_FOURCC('U','Y','V','Y'), PIX_FMT_YUV422 },
/* Packed RGB formats */
{ VLC_FOURCC('R','V','1','5'), PIX_FMT_RGB555 },
{ VLC_FOURCC('R','V','1','6'), PIX_FMT_RGB565 },
{ VLC_FOURCC('R','V','2','4'), PIX_FMT_RGB24 },
{ VLC_FOURCC('R','V','3','2'), PIX_FMT_RGBA32 },
{ VLC_FOURCC('G','R','E','Y'), PIX_FMT_GRAY8 },
{0}
};
int E_(GetFfmpegChroma)( vlc_fourcc_t i_chroma )
{
int i;
for( i = 0; chroma_table[i].i_chroma != 0; i++ )
{
if( chroma_table[i].i_chroma == i_chroma )
return chroma_table[i].i_chroma_id;
}
return -1;
}
vlc_fourcc_t E_(GetVlcChroma)( int i_ffmpeg_chroma )
{
int i;
for( i = 0; chroma_table[i].i_chroma != 0; i++ )
{
if( chroma_table[i].i_chroma_id == i_ffmpeg_chroma )
return chroma_table[i].i_chroma;
}
return 0;
}
/*****************************************************************************
* Codec fourcc -> ffmpeg_id mapping
*****************************************************************************/
static struct static struct
{ {
vlc_fourcc_t i_fourcc; vlc_fourcc_t i_fourcc;
......
...@@ -38,6 +38,7 @@ void E_(InitLibavcodec)( vlc_object_t * ); ...@@ -38,6 +38,7 @@ void E_(InitLibavcodec)( vlc_object_t * );
int E_(GetFfmpegCodec) ( vlc_fourcc_t, int *, int *, char ** ); int E_(GetFfmpegCodec) ( vlc_fourcc_t, int *, int *, char ** );
int E_(GetVlcFourcc) ( int, int *, vlc_fourcc_t *, char ** ); int E_(GetVlcFourcc) ( int, int *, vlc_fourcc_t *, char ** );
int E_(GetFfmpegChroma)( vlc_fourcc_t ); int E_(GetFfmpegChroma)( vlc_fourcc_t );
vlc_fourcc_t E_(GetVlcChroma)( int );
/* Video decoder module */ /* Video decoder module */
int E_( InitVideoDec )( decoder_t *, AVCodecContext *, AVCodec *, int E_( InitVideoDec )( decoder_t *, AVCodecContext *, AVCodec *,
...@@ -67,6 +68,10 @@ void E_(CloseAudioEncoder)( vlc_object_t * ); ...@@ -67,6 +68,10 @@ void E_(CloseAudioEncoder)( vlc_object_t * );
int E_(OpenDemux) ( vlc_object_t * ); int E_(OpenDemux) ( vlc_object_t * );
void E_(CloseDemux)( vlc_object_t * ); void E_(CloseDemux)( vlc_object_t * );
/* Video filter module */
int E_(OpenFilter)( vlc_object_t * );
void E_(CloseFilter)( vlc_object_t * );
/* Postprocessing module */ /* Postprocessing module */
void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * ); void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * );
int E_(InitPostproc)( decoder_t *, void *, int, int, int ); int E_(InitPostproc)( decoder_t *, void *, int, int, int );
......
...@@ -428,7 +428,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block ) ...@@ -428,7 +428,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
return NULL; return NULL;
} }
if( p_sys->i_late_frames > 0 && if( !p_dec->b_pace_control && p_sys->i_late_frames > 0 &&
mdate() - p_sys->i_late_frames_start > I64C(5000000) ) mdate() - p_sys->i_late_frames_start > I64C(5000000) )
{ {
if( p_sys->i_pts ) if( p_sys->i_pts )
...@@ -453,7 +453,8 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block ) ...@@ -453,7 +453,8 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
/* TODO implement it in a better way */ /* TODO implement it in a better way */
/* A good idea could be to decode all I pictures and see for the other */ /* A good idea could be to decode all I pictures and see for the other */
if( p_sys->b_hurry_up && p_sys->i_late_frames > 4 ) if( !p_dec->b_pace_control &&
p_sys->b_hurry_up && p_sys->i_late_frames > 4 )
{ {
b_drawpicture = 0; b_drawpicture = 0;
if( p_sys->i_late_frames < 8 ) if( p_sys->i_late_frames < 8 )
...@@ -622,6 +623,13 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block ) ...@@ -622,6 +623,13 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
p_sys->b_first_frame = VLC_FALSE; p_sys->b_first_frame = VLC_FALSE;
p_pic->b_force = VLC_TRUE; p_pic->b_force = VLC_TRUE;
} }
p_pic->i_nb_fields = p_sys->p_ff_pic->repeat_pict;
#if LIBAVCODEC_BUILD >= 4685
p_pic->b_progressive = !p_sys->p_ff_pic->interlaced_frame;
p_pic->b_top_field_first = p_sys->p_ff_pic->top_field_first;
#endif
return p_pic; return p_pic;
} }
else else
......
/*****************************************************************************
* video filter: video filter doing chroma conversion and resizing
* using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: chroma.c 7834 2004-05-30 16:57:55Z sigmunau $
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/decoder.h>
#include "vlc_filter.h"
/* ffmpeg header */
#ifdef HAVE_FFMPEG_AVCODEC_H
# include <ffmpeg/avcodec.h>
#else
# include <avcodec.h>
#endif
#include "ffmpeg.h"
void E_(InitLibavcodec) ( vlc_object_t *p_object );
static picture_t *Process( filter_t *p_filter, picture_t *p_pic );
/*****************************************************************************
* filter_sys_t : filter descriptor
*****************************************************************************/
struct filter_sys_t
{
vlc_bool_t b_resize;
vlc_bool_t b_convert;
es_format_t fmt_in;
int i_src_ffmpeg_chroma;
es_format_t fmt_out;
int i_dst_ffmpeg_chroma;
AVPicture tmp_pic;
ImgReSampleContext *p_rsc;
};
/*****************************************************************************
* OpenFilter: probe the filter and return score
*****************************************************************************/
int E_(OpenFilter)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys;
vlc_bool_t b_convert, b_resize;
ImgReSampleContext *p_rsc;
/* Check if we can handle that formats */
if( E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ) < 0 ||
E_(GetFfmpegChroma)( p_filter->fmt_out.video.i_chroma ) < 0 )
{
return VLC_EGENERIC;
}
b_resize =
p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ||
p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height;
b_convert =
p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma;
if( !b_resize && !b_convert )
{
/* Nothing to do */
return VLC_EGENERIC;
}
p_rsc = img_resample_init( p_filter->fmt_out.video.i_width,
p_filter->fmt_out.video.i_height,
p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height );
if( !p_rsc )
{
msg_Err( p_filter, "img_resample_init failed" );
return VLC_EGENERIC;
}
/* Allocate the memory needed to store the decoder's structure */
if( ( p_filter->p_sys = p_sys =
(filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
{
msg_Err( p_filter, "out of memory" );
return VLC_EGENERIC;
}
/* Misc init */
p_sys->b_resize = b_resize;
p_sys->b_convert = b_convert;
p_sys->p_rsc = p_rsc;
p_sys->i_src_ffmpeg_chroma =
E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma );
p_sys->i_dst_ffmpeg_chroma =
E_(GetFfmpegChroma)( p_filter->fmt_out.video.i_chroma );
p_sys->fmt_in = p_filter->fmt_in;
p_sys->fmt_out = p_filter->fmt_out;
p_filter->pf_video_filter = Process;
avpicture_alloc( &p_sys->tmp_pic, p_sys->i_dst_ffmpeg_chroma,
p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height );
msg_Dbg( p_filter, "input: %ix%i %4.4s -> %ix%i %4.4s",
p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height,
(char *)&p_filter->fmt_in.video.i_chroma,
p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height,
(char *)&p_filter->fmt_out.video.i_chroma );
/* libavcodec needs to be initialized for some chroma conversions */
E_(InitLibavcodec)(p_this);
return VLC_SUCCESS;
}
/*****************************************************************************
* CloseFilter: clean up the filter
*****************************************************************************/
void E_(CloseFilter)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
if( p_sys->p_rsc ) img_resample_close( p_sys->p_rsc );
avpicture_free( &p_sys->tmp_pic );
free( p_sys );
}
/*****************************************************************************
* Do the processing here
*****************************************************************************/
static picture_t *Process( filter_t *p_filter, picture_t *p_pic )
{
filter_sys_t *p_sys = p_filter->p_sys;
AVPicture src_pic, dest_pic, inter_pic;
picture_t *p_pic_dst;
vlc_bool_t b_resize = p_sys->b_resize;
int i;
/* Request output picture */
p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
if( !p_pic_dst )
{
msg_Warn( p_filter, "can't get output picture" );
return NULL;
}
/* Prepare the AVPictures for the conversion */
for( i = 0; i < p_pic->i_planes; i++ )
{
src_pic.data[i] = p_pic->p[i].p_pixels;
src_pic.linesize[i] = p_pic->p[i].i_pitch;
}
for( i = 0; i < p_pic_dst->i_planes; i++ )
{
dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
}
/* Special cases */
if( p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','1','2') ||
p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','U','9') )
{
/* Invert U and V */
src_pic.data[1] = p_pic->p[2].p_pixels;
src_pic.data[2] = p_pic->p[1].p_pixels;
}
if( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','1','2') ||
p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','U','9') )
{
/* Invert U and V */
dest_pic.data[1] = p_pic_dst->p[2].p_pixels;
dest_pic.data[2] = p_pic_dst->p[1].p_pixels;
}
#if 0
if( p_sys->b_resize &&
p_filter->fmt_in.video.i_width * p_filter->fmt_in.video.i_height >
p_filter->fmt_out.video.i_width * p_filter->fmt_out.video.i_height )
{
img_resample( p_sys->p_rsc, &dest_pic, &p_sys->tmp_pic );
b_resize = 0;
}
#endif
if( p_sys->b_convert )
{
if( p_sys->b_resize ) inter_pic = p_sys->tmp_pic;
else inter_pic = dest_pic;
img_convert( &inter_pic, p_sys->i_dst_ffmpeg_chroma,
&src_pic, p_sys->i_src_ffmpeg_chroma,
p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height );
src_pic = inter_pic;
}
if( p_sys->b_resize && p_sys->p_rsc )
{
img_resample( p_sys->p_rsc, &dest_pic, &src_pic );
}
p_pic_dst->date = p_pic->date;
p_pic_dst->b_force = p_pic->b_force;
p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
p_pic_dst->b_progressive = p_pic->b_progressive;
p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
p_pic->pf_release( p_pic );
return p_pic_dst;
}
...@@ -430,7 +430,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -430,7 +430,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->p_info->current_picture->nb_fields, i_pts, i_dts, p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
p_sys->i_current_rate ); p_sys->i_current_rate );
if ( !(p_sys->b_slice_i if( !p_dec->b_pace_control &&
!(p_sys->b_slice_i
&& ((p_sys->p_info->current_picture->flags && ((p_sys->p_info->current_picture->flags
& PIC_MASK_CODING_TYPE) == P_CODING_TYPE)) & PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
&& !vout_SynchroChoose( p_sys->p_synchro, && !vout_SynchroChoose( p_sys->p_synchro,
......
...@@ -92,7 +92,6 @@ static void ParseSpeexComments( decoder_t *, ogg_packet * ); ...@@ -92,7 +92,6 @@ static void ParseSpeexComments( decoder_t *, ogg_packet * );
static int OpenEncoder ( vlc_object_t * ); static int OpenEncoder ( vlc_object_t * );
static void CloseEncoder ( vlc_object_t * ); static void CloseEncoder ( vlc_object_t * );
static block_t *Headers ( encoder_t * );
static block_t *Encode ( encoder_t *, aout_buffer_t * ); static block_t *Encode ( encoder_t *, aout_buffer_t * );
/***************************************************************************** /*****************************************************************************
...@@ -517,8 +516,6 @@ struct encoder_sys_t ...@@ -517,8 +516,6 @@ struct encoder_sys_t
/* /*
* Input properties * Input properties
*/ */
int i_headers;
char *p_buffer; char *p_buffer;
char p_buffer_out[MAX_FRAME_BYTES]; char p_buffer_out[MAX_FRAME_BYTES];
...@@ -551,7 +548,10 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -551,7 +548,10 @@ static int OpenEncoder( vlc_object_t *p_this )
encoder_t *p_enc = (encoder_t *)p_this; encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys; encoder_sys_t *p_sys;
const SpeexMode *p_speex_mode = &speex_nb_mode; const SpeexMode *p_speex_mode = &speex_nb_mode;
int i_quality; int i_quality, i;
char *pp_header[2];
int pi_header[2];
uint8_t *p_extra;
if( p_enc->fmt_out.i_codec != VLC_FOURCC('s','p','x',' ') && if( p_enc->fmt_out.i_codec != VLC_FOURCC('s','p','x',' ') &&
!p_enc->b_force ) !p_enc->b_force )
...@@ -566,7 +566,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -566,7 +566,6 @@ static int OpenEncoder( vlc_object_t *p_this )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_enc->p_sys = p_sys; p_enc->p_sys = p_sys;
p_enc->pf_header = Headers;
p_enc->pf_encode_audio = Encode; p_enc->pf_encode_audio = Encode;
p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE; p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
p_enc->fmt_out.i_codec = VLC_FOURCC('s','p','x',' '); p_enc->fmt_out.i_codec = VLC_FOURCC('s','p','x',' ');
...@@ -590,7 +589,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -590,7 +589,6 @@ static int OpenEncoder( vlc_object_t *p_this )
p_sys->i_frames_in_packet = 0; p_sys->i_frames_in_packet = 0;
p_sys->i_samples_delay = 0; p_sys->i_samples_delay = 0;
p_sys->i_headers = 0;
p_sys->i_pts = 0; p_sys->i_pts = 0;
speex_encoder_ctl( p_sys->p_state, SPEEX_GET_FRAME_SIZE, speex_encoder_ctl( p_sys->p_state, SPEEX_GET_FRAME_SIZE,
...@@ -600,6 +598,22 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -600,6 +598,22 @@ static int OpenEncoder( vlc_object_t *p_this )
sizeof(int16_t) * p_enc->fmt_in.audio.i_channels; sizeof(int16_t) * p_enc->fmt_in.audio.i_channels;
p_sys->p_buffer = malloc( p_sys->i_frame_size ); p_sys->p_buffer = malloc( p_sys->i_frame_size );
/* Create and store headers */
pp_header[0] = speex_header_to_packet( &p_sys->header, &pi_header[0] );
pp_header[1] = "ENCODER=VLC media player";
pi_header[1] = sizeof("ENCODER=VLC media player");
p_enc->fmt_out.i_extra = 1 + 3 * 2 + pi_header[0] + pi_header[1];
p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
*(p_extra++) = 2; /* number of headers */
for( i = 0; i < 2; i++ )
{
*(p_extra++) = pi_header[i] >> 8;
*(p_extra++) = pi_header[i] & 0xFF;
memcpy( p_extra, pp_header[i], pi_header[i] );
p_extra += pi_header[i];
}
msg_Dbg( p_enc, "encoding: frame size:%d, channels:%d, samplerate:%d", msg_Dbg( p_enc, "encoding: frame size:%d, channels:%d, samplerate:%d",
p_sys->i_frame_size, p_enc->fmt_in.audio.i_channels, p_sys->i_frame_size, p_enc->fmt_in.audio.i_channels,
p_enc->fmt_in.audio.i_rate ); p_enc->fmt_in.audio.i_rate );
...@@ -607,42 +621,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -607,42 +621,6 @@ static int OpenEncoder( vlc_object_t *p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/****************************************************************************
* Headers: spits out the headers
****************************************************************************
* This function spits out ogg packets.
****************************************************************************/
static block_t *Headers( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_block, *p_chain = NULL;
/* Create speex headers */
if( !p_sys->i_headers )
{
char *p_buffer;
int i_buffer;
/* Main header */
p_buffer = speex_header_to_packet( &p_sys->header, &i_buffer );
p_block = block_New( p_enc, i_buffer );
memcpy( p_block->p_buffer, p_buffer, i_buffer );
p_block->i_dts = p_block->i_pts = p_block->i_length = 0;
block_ChainAppend( &p_chain, p_block );
/* Comment */
p_block = block_New( p_enc, sizeof("ENCODER=VLC media player") );
memcpy( p_block->p_buffer, "ENCODER=VLC media player",
p_block->i_buffer );
p_block->i_dts = p_block->i_pts = p_block->i_length = 0;
block_ChainAppend( &p_chain, p_block );
p_sys->i_headers = 2;
}
return p_chain;
}
/**************************************************************************** /****************************************************************************
* Encode: the whole thing * Encode: the whole thing
**************************************************************************** ****************************************************************************
......
...@@ -76,7 +76,6 @@ static void theora_CopyPicture( decoder_t *, picture_t *, yuv_buffer * ); ...@@ -76,7 +76,6 @@ static void theora_CopyPicture( decoder_t *, picture_t *, yuv_buffer * );
static int OpenEncoder( vlc_object_t *p_this ); static int OpenEncoder( vlc_object_t *p_this );
static void CloseEncoder( vlc_object_t *p_this ); static void CloseEncoder( vlc_object_t *p_this );
static block_t *Headers( encoder_t *p_enc );
static block_t *Encode( encoder_t *p_enc, picture_t *p_pict ); static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
/***************************************************************************** /*****************************************************************************
...@@ -460,8 +459,10 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -460,8 +459,10 @@ static int OpenEncoder( vlc_object_t *p_this )
{ {
encoder_t *p_enc = (encoder_t *)p_this; encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys; encoder_sys_t *p_sys = p_enc->p_sys;
ogg_packet header[3];
uint8_t *p_extra;
vlc_value_t val; vlc_value_t val;
int i_quality; int i_quality, i;
if( p_enc->fmt_out.i_codec != VLC_FOURCC('t','h','e','o') && if( p_enc->fmt_out.i_codec != VLC_FOURCC('t','h','e','o') &&
!p_enc->b_force ) !p_enc->b_force )
...@@ -486,7 +487,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -486,7 +487,6 @@ static int OpenEncoder( vlc_object_t *p_this )
} }
p_enc->p_sys = p_sys; p_enc->p_sys = p_sys;
p_enc->pf_header = Headers;
p_enc->pf_encode_video = Encode; p_enc->pf_encode_video = Encode;
p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0'); p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
p_enc->fmt_out.i_codec = VLC_FOURCC('t','h','e','o'); p_enc->fmt_out.i_codec = VLC_FOURCC('t','h','e','o');
...@@ -548,54 +548,23 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -548,54 +548,23 @@ static int OpenEncoder( vlc_object_t *p_this )
theora_info_clear( &p_sys->ti ); theora_info_clear( &p_sys->ti );
theora_comment_init( &p_sys->tc ); theora_comment_init( &p_sys->tc );
p_sys->b_headers = VLC_FALSE; /* Create and store headers */
theora_encode_header( &p_sys->td, &header[0] );
return VLC_SUCCESS; theora_encode_comment( &p_sys->tc, &header[1] );
} theora_encode_tables( &p_sys->td, &header[2] );
p_enc->fmt_out.i_extra = 1 + 3 * 2 + header[0].bytes +
/**************************************************************************** header[1].bytes + header[2].bytes;
* Encode: the whole thing p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
**************************************************************************** *(p_extra++) = 3; /* number of headers */
* This function spits out ogg packets.
****************************************************************************/
static block_t *Headers( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_chain = NULL;
/* Create theora headers */
if( !p_sys->b_headers )
{
ogg_packet oggpackets;
int i;
block_t *p_block;
/* Ogg packet to block */
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
switch( i ) *(p_extra++) = header[i].bytes >> 8;
{ *(p_extra++) = header[i].bytes & 0xFF;
case 0: memcpy( p_extra, header[i].packet, header[i].bytes );
theora_encode_header( &p_sys->td, &oggpackets ); p_extra += header[i].bytes;
break;
case 1:
theora_encode_comment( &p_sys->tc, &oggpackets );
break;
case 2:
theora_encode_tables( &p_sys->td, &oggpackets );
break;
}
p_block = block_New( p_enc, oggpackets.bytes );
memcpy( p_block->p_buffer, oggpackets.packet, oggpackets.bytes );
p_block->i_dts = p_block->i_pts = p_block->i_length = 0;
block_ChainAppend( &p_chain, p_block );
} }
p_sys->b_headers = VLC_TRUE; return VLC_SUCCESS;
}
return p_chain;
} }
/**************************************************************************** /****************************************************************************
......
...@@ -120,7 +120,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -120,7 +120,6 @@ static int OpenEncoder( vlc_object_t *p_this )
} }
p_enc->p_sys = p_sys; p_enc->p_sys = p_sys;
p_enc->pf_header = NULL;
p_enc->pf_encode_audio = Encode; p_enc->pf_encode_audio = Encode;
p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE; p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
p_enc->fmt_out.i_codec = VLC_FOURCC('m','p','g','a'); p_enc->fmt_out.i_codec = VLC_FOURCC('m','p','g','a');
......
...@@ -117,7 +117,6 @@ static void Interleave ( float *, const float **, int, int ); ...@@ -117,7 +117,6 @@ static void Interleave ( float *, const float **, int, int );
#ifndef MODULE_NAME_IS_tremor #ifndef MODULE_NAME_IS_tremor
static int OpenEncoder ( vlc_object_t * ); static int OpenEncoder ( vlc_object_t * );
static void CloseEncoder ( vlc_object_t * ); static void CloseEncoder ( vlc_object_t * );
static block_t *Headers ( encoder_t * );
static block_t *Encode ( encoder_t *, aout_buffer_t * ); static block_t *Encode ( encoder_t *, aout_buffer_t * );
#endif #endif
...@@ -549,15 +548,10 @@ static void CloseDecoder( vlc_object_t *p_this ) ...@@ -549,15 +548,10 @@ static void CloseDecoder( vlc_object_t *p_this )
#if defined(HAVE_VORBIS_VORBISENC_H) && !defined(MODULE_NAME_IS_tremor) #if defined(HAVE_VORBIS_VORBISENC_H) && !defined(MODULE_NAME_IS_tremor)
/***************************************************************************** /*****************************************************************************
* encoder_sys_t : theora encoder descriptor * encoder_sys_t : vorbis encoder descriptor
*****************************************************************************/ *****************************************************************************/
struct encoder_sys_t struct encoder_sys_t
{ {
/*
* Input properties
*/
int i_headers;
/* /*
* Vorbis properties * Vorbis properties
*/ */
...@@ -586,8 +580,10 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -586,8 +580,10 @@ static int OpenEncoder( vlc_object_t *p_this )
{ {
encoder_t *p_enc = (encoder_t *)p_this; encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys; encoder_sys_t *p_sys;
int i_quality, i_min_bitrate, i_max_bitrate; int i_quality, i_min_bitrate, i_max_bitrate, i;
ogg_packet header[3];
vlc_value_t val; vlc_value_t val;
uint8_t *p_extra;
if( p_enc->fmt_out.i_codec != VLC_FOURCC('v','o','r','b') && if( p_enc->fmt_out.i_codec != VLC_FOURCC('v','o','r','b') &&
!p_enc->b_force ) !p_enc->b_force )
...@@ -603,7 +599,6 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -603,7 +599,6 @@ static int OpenEncoder( vlc_object_t *p_this )
} }
p_enc->p_sys = p_sys; p_enc->p_sys = p_sys;
p_enc->pf_header = Headers;
p_enc->pf_encode_audio = Encode; p_enc->pf_encode_audio = Encode;
p_enc->fmt_in.i_codec = VLC_FOURCC('f','l','3','2'); p_enc->fmt_in.i_codec = VLC_FOURCC('f','l','3','2');
p_enc->fmt_out.i_codec = VLC_FOURCC('v','o','r','b'); p_enc->fmt_out.i_codec = VLC_FOURCC('v','o','r','b');
...@@ -671,54 +666,35 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -671,54 +666,35 @@ static int OpenEncoder( vlc_object_t *p_this )
vorbis_encode_setup_init( &p_sys->vi ); vorbis_encode_setup_init( &p_sys->vi );
/* add a comment */ /* Add a comment */
vorbis_comment_init( &p_sys->vc); vorbis_comment_init( &p_sys->vc);
vorbis_comment_add_tag( &p_sys->vc, "ENCODER", "VLC media player"); vorbis_comment_add_tag( &p_sys->vc, "ENCODER", "VLC media player");
/* set up the analysis state and auxiliary encoding storage */ /* Set up the analysis state and auxiliary encoding storage */
vorbis_analysis_init( &p_sys->vd, &p_sys->vi ); vorbis_analysis_init( &p_sys->vd, &p_sys->vi );
vorbis_block_init( &p_sys->vd, &p_sys->vb ); vorbis_block_init( &p_sys->vd, &p_sys->vb );
p_sys->i_channels = p_enc->fmt_in.audio.i_channels; /* Create and store headers */
p_sys->i_last_block_size = 0;
p_sys->i_samples_delay = 0;
p_sys->i_headers = 0;
p_sys->i_pts = 0;
return VLC_SUCCESS;
}
/****************************************************************************
* Encode: the whole thing
****************************************************************************
* This function spits out ogg packets.
****************************************************************************/
static block_t *Headers( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_block, *p_chain = NULL;
/* Create theora headers */
if( !p_sys->i_headers )
{
ogg_packet header[3];
int i;
vorbis_analysis_headerout( &p_sys->vd, &p_sys->vc, vorbis_analysis_headerout( &p_sys->vd, &p_sys->vc,
&header[0], &header[1], &header[2]); &header[0], &header[1], &header[2]);
p_enc->fmt_out.i_extra = 1 + 3 * 2 + header[0].bytes +
header[1].bytes + header[2].bytes;
p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
*(p_extra++) = 3; /* number of headers */
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
p_block = block_New( p_enc, header[i].bytes ); *(p_extra++) = header[i].bytes >> 8;
memcpy( p_block->p_buffer, header[i].packet, header[i].bytes ); *(p_extra++) = header[i].bytes & 0xFF;
memcpy( p_extra, header[i].packet, header[i].bytes );
p_block->i_dts = p_block->i_pts = p_block->i_length = 0; p_extra += header[i].bytes;
block_ChainAppend( &p_chain, p_block );
}
p_sys->i_headers = 3;
} }
return p_chain; p_sys->i_channels = p_enc->fmt_in.audio.i_channels;
p_sys->i_last_block_size = 0;
p_sys->i_samples_delay = 0;
p_sys->i_pts = 0;
return VLC_SUCCESS;
} }
/**************************************************************************** /****************************************************************************
...@@ -791,7 +767,7 @@ static block_t *Encode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) ...@@ -791,7 +767,7 @@ static block_t *Encode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
} }
/***************************************************************************** /*****************************************************************************
* CloseEncoder: theora encoder destruction * CloseEncoder: vorbis encoder destruction
*****************************************************************************/ *****************************************************************************/
static void CloseEncoder( vlc_object_t *p_this ) static void CloseEncoder( vlc_object_t *p_this )
{ {
......
This diff is collapsed.
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "vlc_playlist.h" #include "vlc_playlist.h"
#include "vlc_interface.h" #include "vlc_interface.h"
#include "vlc_codec.h" #include "vlc_codec.h"
#include "vlc_filter.h"
#include "vlc_httpd.h" #include "vlc_httpd.h"
#include "vlc_vlm.h" #include "vlc_vlm.h"
...@@ -149,6 +150,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type ) ...@@ -149,6 +150,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
i_size = sizeof(encoder_t); i_size = sizeof(encoder_t);
psz_type = "encoder"; psz_type = "encoder";
break; break;
case VLC_OBJECT_FILTER:
i_size = sizeof(filter_t);
psz_type = "filter";
break;
case VLC_OBJECT_VOUT: case VLC_OBJECT_VOUT:
i_size = sizeof(vout_thread_t); i_size = sizeof(vout_thread_t);
psz_type = "video output"; psz_type = "video output";
...@@ -194,12 +199,7 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type ) ...@@ -194,12 +199,7 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
else else
{ {
p_new = malloc( i_size ); p_new = malloc( i_size );
if( !p_new ) return NULL;
if( !p_new )
{
return NULL;
}
memset( p_new, 0, i_size ); memset( p_new, 0, i_size );
} }
......
This diff is collapsed.
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