📄 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 the VideoLAN team * $Id$ * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_codec.h>#include <vlc_sout.h>#include <vlc_vout.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 *const ppsz_enc_options[] = { "quality", NULL};/***************************************************************************** * Module descriptor *****************************************************************************/#define ENC_QUALITY_TEXT N_("Encoding quality")#define ENC_QUALITY_LONGTEXT N_( \ "Quality of the encoding between 1.0 (low) and 10.0 (high)." )vlc_module_begin(); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_VCODEC ); set_description( N_("Dirac video decoder") ); set_capability( "decoder", 100 ); set_callbacks( OpenDecoder, CloseDecoder ); add_shortcut( "dirac" ); add_submodule(); set_description( N_("Dirac video encoder") ); set_capability( "encoder", 100 ); set_callbacks( OpenEncoder, CloseEncoder ); add_float( ENC_CFG_PREFIX "quality", 7.0, NULL, ENC_QUALITY_TEXT, ENC_QUALITY_LONGTEXT, 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 ) return VLC_ENOMEM; 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++ ) { 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; switch( p_sys->p_dirac->src_params.chroma ) { case format420: p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0'); break; case format422: p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','2'); break; case format444: p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','4','4'); break; // XXX 0.6 ? default: p_dec->fmt_out.i_codec = 0; break; } p_dec->fmt_out.video.i_visible_width = p_dec->fmt_out.video.i_width = p_sys->p_dirac->src_params.width; p_dec->fmt_out.video.i_visible_height = p_dec->fmt_out.video.i_height = p_sys->p_dirac->src_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->src_params.frame_rate.numerator; p_dec->fmt_out.video.i_frame_rate_base = p_sys->p_dirac->src_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->src_params.source_sampling; p_pic->b_top_field_first = p_sys->p_dirac->src_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++ ) { vlc_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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -