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
module_t * p_module;
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) */
es_format_t fmt_in;
/* Output format of decoder/packetizer */
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
*/
......@@ -102,17 +105,16 @@ struct encoder_t
module_t * p_module;
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 */
es_format_t fmt_in;
/* Properties of the output of the encoder */
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 */
int i_threads; /* Number of threads to use during encoding */
int i_iframes; /* One I frame per i_iframes */
......
......@@ -45,6 +45,12 @@ struct filter_t
module_t * p_module;
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 *,
picture_t *, picture_t *,
int, int );
......@@ -52,12 +58,6 @@ struct filter_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
*/
......
......@@ -53,6 +53,7 @@
#define VLC_OBJECT_ACCESS (-19)
#define VLC_OBJECT_STREAM (-20)
#define VLC_OBJECT_OPENGL (-21)
#define VLC_OBJECT_FILTER (-22)
#define VLC_OBJECT_GENERIC (-666)
......
......@@ -106,6 +106,9 @@ struct picture_t
/** Private data - the video output plugin might want to put stuff here to
* keep track of the picture */
picture_sys_t * p_sys;
/** This way the picture_Release can be overloaded */
void (*pf_release)( picture_t * );
};
/**
......
......@@ -3,6 +3,7 @@ SOURCES_ffmpeg = \
ffmpeg.h \
video.c \
audio.c \
video_filter.c \
chroma.c \
encoder.c \
postprocess.c \
......@@ -14,6 +15,7 @@ SOURCES_ffmpegaltivec = \
ffmpeg.h \
video.c \
audio.c \
video_filter.c \
chroma.c \
encoder.c \
postprocess.c \
......
......@@ -4,7 +4,7 @@
* Copyright (C) 1999-2001 VideoLAN
* $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
* 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 )
i_vlc_chroma[1] = p_vout->output.i_chroma;
for( i = 0; i < 2; i++ )
{
switch( i_vlc_chroma[i] )
{
/* 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;
}
i_ffmpeg_chroma[i] = E_(GetFfmpegChroma)( i_vlc_chroma[i] );
if( i_ffmpeg_chroma[i] < 0 ) return VLC_EGENERIC;
}
p_vout->chroma.pf_convert = ChromaConversion;
......
......@@ -5,7 +5,7 @@
* $Id$
*
* 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
* it under the terms of the GNU General Public License as published by
......@@ -160,9 +160,15 @@ vlc_module_begin();
/* demux submodule */
add_submodule();
set_description( _("ffmpeg demuxer" ) );
set_capability( "demux2", 1 );
set_capability( "demux2", 2 );
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 );
vlc_module_end();
......@@ -283,33 +289,6 @@ static void CloseDecoder( vlc_object_t *p_this )
/*****************************************************************************
* 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 )
{
static int b_ffmpeginit = 0;
......@@ -336,7 +315,67 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
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
{
vlc_fourcc_t i_fourcc;
......
......@@ -38,6 +38,7 @@ void E_(InitLibavcodec)( vlc_object_t * );
int E_(GetFfmpegCodec) ( vlc_fourcc_t, int *, int *, char ** );
int E_(GetVlcFourcc) ( int, int *, vlc_fourcc_t *, char ** );
int E_(GetFfmpegChroma)( vlc_fourcc_t );
vlc_fourcc_t E_(GetVlcChroma)( int );
/* Video decoder module */
int E_( InitVideoDec )( decoder_t *, AVCodecContext *, AVCodec *,
......@@ -67,6 +68,10 @@ void E_(CloseAudioEncoder)( vlc_object_t * );
int E_(OpenDemux) ( 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 */
void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * );
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 )
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) )
{
if( p_sys->i_pts )
......@@ -453,7 +453,8 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
/* TODO implement it in a better way */
/* 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;
if( p_sys->i_late_frames < 8 )
......@@ -622,6 +623,13 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
p_sys->b_first_frame = VLC_FALSE;
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;
}
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 )
p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
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
& PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
&& !vout_SynchroChoose( p_sys->p_synchro,
......
......@@ -92,7 +92,6 @@ static void ParseSpeexComments( decoder_t *, ogg_packet * );
static int OpenEncoder ( vlc_object_t * );
static void CloseEncoder ( vlc_object_t * );
static block_t *Headers ( encoder_t * );
static block_t *Encode ( encoder_t *, aout_buffer_t * );
/*****************************************************************************
......@@ -517,8 +516,6 @@ struct encoder_sys_t
/*
* Input properties
*/
int i_headers;
char *p_buffer;
char p_buffer_out[MAX_FRAME_BYTES];
......@@ -551,7 +548,10 @@ static int OpenEncoder( vlc_object_t *p_this )
encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
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',' ') &&
!p_enc->b_force )
......@@ -566,7 +566,6 @@ static int OpenEncoder( vlc_object_t *p_this )
return VLC_EGENERIC;
}
p_enc->p_sys = p_sys;
p_enc->pf_header = Headers;
p_enc->pf_encode_audio = Encode;
p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
p_enc->fmt_out.i_codec = VLC_FOURCC('s','p','x',' ');
......@@ -590,7 +589,6 @@ static int OpenEncoder( vlc_object_t *p_this )
p_sys->i_frames_in_packet = 0;
p_sys->i_samples_delay = 0;
p_sys->i_headers = 0;
p_sys->i_pts = 0;
speex_encoder_ctl( p_sys->p_state, SPEEX_GET_FRAME_SIZE,
......@@ -600,6 +598,22 @@ static int OpenEncoder( vlc_object_t *p_this )
sizeof(int16_t) * p_enc->fmt_in.audio.i_channels;
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",
p_sys->i_frame_size, p_enc->fmt_in.audio.i_channels,
p_enc->fmt_in.audio.i_rate );
......@@ -607,42 +621,6 @@ static int OpenEncoder( vlc_object_t *p_this )
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 */