📄 dirac.c
字号:
/***************************************************************************** * dirac.c: Dirac decoder/encoder module making use of libdirac. * (http://www.bbc.co.uk/rd/projects/dirac/index.shtml) ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN * $Id: dirac.c 10101 2005-03-02 16:47:31Z robux4 $ * * 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/sout.h>#include <libdirac_decoder/dirac_parser.h>#include <libdirac_encoder/dirac_encoder.h>/***************************************************************************** * decoder_sys_t : theora decoder descriptor *****************************************************************************/struct decoder_sys_t{ /* * Dirac properties */ dirac_decoder_t *p_dirac;};/***************************************************************************** * Local prototypes *****************************************************************************/static int OpenDecoder ( vlc_object_t * );static void CloseDecoder ( vlc_object_t * );static picture_t *DecodeBlock ( decoder_t *p_dec, block_t **pp_block );static int OpenEncoder( vlc_object_t *p_this );static void CloseEncoder( vlc_object_t *p_this );static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );#define ENC_CFG_PREFIX "sout-dirac-"static const char *ppsz_enc_options[] = { "quality", NULL};/***************************************************************************** * Module descriptor *****************************************************************************/#define ENC_QUALITY_TEXT N_("Encoding quality")#define ENC_QUALITY_LONGTEXT N_( \ "Allows you to specify a quality between 1.0 (low) and 10.0 (high)." )vlc_module_begin(); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_VCODEC ); set_description( _("Dirac video decoder") ); set_capability( "decoder", 100 ); set_callbacks( OpenDecoder, CloseDecoder ); add_shortcut( "dirac" ); add_submodule(); set_description( _("Dirac video encoder") ); set_capability( "encoder", 100 ); set_callbacks( OpenEncoder, CloseEncoder ); add_shortcut( "dirac" ); add_float( ENC_CFG_PREFIX "quality", 7.0, NULL, ENC_QUALITY_TEXT, ENC_QUALITY_LONGTEXT, VLC_FALSE );vlc_module_end();/***************************************************************************** * OpenDecoder: probe the decoder and return score *****************************************************************************/static int OpenDecoder( vlc_object_t *p_this ){ decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; dirac_decoder_t *p_dirac; if( p_dec->fmt_in.i_codec != VLC_FOURCC('d','r','a','c') ) { return VLC_EGENERIC; } /* Initialise the dirac decoder */ if( !(p_dirac = dirac_decoder_init(0)) ) return VLC_EGENERIC; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) { msg_Err( p_dec, "out of memory" ); return VLC_EGENERIC; } p_sys->p_dirac = p_dirac; /* Set output properties */ p_dec->fmt_out.i_cat = VIDEO_ES; p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0'); /* Set callbacks */ p_dec->pf_decode_video = DecodeBlock; return VLC_SUCCESS;}static void FreeFrameBuffer( dirac_decoder_t *p_dirac ){ if( p_dirac->fbuf ) { int i; for( i = 0; i < 3; i++ ) { if( p_dirac->fbuf->buf[i] ) free( p_dirac->fbuf->buf[i] ); p_dirac->fbuf->buf[i] = 0; } }}/***************************************************************************** * GetNewPicture: Get a new picture from the vout and copy the decoder output *****************************************************************************/static picture_t *GetNewPicture( decoder_t *p_dec ){ decoder_sys_t *p_sys = p_dec->p_sys; picture_t *p_pic; int i_plane; p_dec->fmt_out.i_codec = p_sys->p_dirac->seq_params.chroma == format411 ? VLC_FOURCC('I','4','1','1') : p_sys->p_dirac->seq_params.chroma == format420 ? VLC_FOURCC('I','4','2','0') : p_sys->p_dirac->seq_params.chroma == format422 ? VLC_FOURCC('I','4','2','2') : 0; p_dec->fmt_out.video.i_visible_width = p_dec->fmt_out.video.i_width = p_sys->p_dirac->seq_params.width; p_dec->fmt_out.video.i_visible_height = p_dec->fmt_out.video.i_height = p_sys->p_dirac->seq_params.height; p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * 4 / 3; p_dec->fmt_out.video.i_frame_rate = p_sys->p_dirac->seq_params.frame_rate.numerator; p_dec->fmt_out.video.i_frame_rate_base = p_sys->p_dirac->seq_params.frame_rate.denominator; /* Get a new picture */ p_pic = p_dec->pf_vout_buffer_new( p_dec ); if( p_pic == NULL ) return NULL; p_pic->b_progressive = !p_sys->p_dirac->seq_params.interlace; p_pic->b_top_field_first = p_sys->p_dirac->seq_params.topfieldfirst; p_pic->i_nb_fields = 2; /* Copy picture stride by stride */ for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) { int i_line, i_width, i_dst_stride; uint8_t *p_src = p_sys->p_dirac->fbuf->buf[i_plane]; uint8_t *p_dst = p_pic->p[i_plane].p_pixels; i_width = p_pic->p[i_plane].i_visible_pitch; i_dst_stride = p_pic->p[i_plane].i_pitch; for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ ) { p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width ); p_src += i_width; p_dst += i_dst_stride; } } return p_pic;}/***************************************************************************** * CloseDecoder: decoder destruction *****************************************************************************/static void CloseDecoder( vlc_object_t *p_this ){ decoder_t *p_dec = (decoder_t *)p_this; decoder_sys_t *p_sys = p_dec->p_sys; FreeFrameBuffer( p_sys->p_dirac ); dirac_decoder_close( p_sys->p_dirac ); free( p_sys );}/**************************************************************************** * DecodeBlock: the whole thing **************************************************************************** * This function must be fed with complete frames. ****************************************************************************/static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ){ decoder_sys_t *p_sys = p_dec->p_sys; dirac_decoder_state_t state; picture_t *p_pic; block_t *p_block; if( !pp_block || !*pp_block ) return NULL; p_block = *pp_block; while( 1 ) { state = dirac_parse( p_sys->p_dirac ); switch( state ) { case STATE_BUFFER: if( !p_block->i_buffer ) { block_Release( p_block ); return NULL; } msg_Dbg( p_dec, "STATE_BUFFER" ); dirac_buffer( p_sys->p_dirac, p_block->p_buffer, p_block->p_buffer + p_block->i_buffer ); p_block->i_buffer = 0; break; case STATE_SEQUENCE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -