X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Ftheora.c;h=3c033f49c455bcc8bf3af3a2c2014f2d5d1e2c2d;hb=a1603d9e69629a8168f5babce3388307bb677341;hp=5f4814dadf8552ad120a45cc4f60d77c8cab286b;hpb=da112653fba3486db43b96075eaa7801b3229b32;p=vlc diff --git a/modules/codec/theora.c b/modules/codec/theora.c index 5f4814dadf..3c033f49c4 100644 --- a/modules/codec/theora.c +++ b/modules/codec/theora.c @@ -1,24 +1,24 @@ /***************************************************************************** * theora.c: theora decoder module making use of libtheora. ***************************************************************************** - * Copyright (C) 1999-2012 the VideoLAN team + * Copyright (C) 1999-2012 VLC authors and VideoLAN * $Id$ * * Authors: Gildas Bazin * - * 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 + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser 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. + * You should have received a copy of the GNU Lesser 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. *****************************************************************************/ /***************************************************************************** @@ -105,6 +105,8 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict ); "Enforce a quality between 1 (low) and 10 (high), instead " \ "of specifying a particular bitrate. This will produce a VBR stream." ) +#define ENC_POSTPROCESS_TEXT N_("Post processing quality") + vlc_module_begin () set_category( CAT_INPUT ) set_subcategory( SUBCAT_INPUT_VCODEC ) @@ -113,6 +115,8 @@ vlc_module_begin () set_capability( "decoder", 100 ) set_callbacks( OpenDecoder, CloseDecoder ) add_shortcut( "theora" ) +# define DEC_CFG_PREFIX "theora-" + add_integer( DEC_CFG_PREFIX "postproc", -1, ENC_POSTPROCESS_TEXT, NULL, true ) add_submodule () set_description( N_("Theora video packetizer") ) @@ -219,7 +223,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { if( ProcessHeaders( p_dec ) ) { - block_Release( *pp_block ); + block_Release( p_block ); return NULL; } p_sys->b_has_headers = true; @@ -236,6 +240,7 @@ static int ProcessHeaders( decoder_t *p_dec ) decoder_sys_t *p_sys = p_dec->p_sys; ogg_packet oggpacket; th_setup_info *ts = NULL; /* theora setup information */ + int i_max_pp, i_pp; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; @@ -244,7 +249,7 @@ static int ProcessHeaders( decoder_t *p_dec ) p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) ) return VLC_EGENERIC; if( i_count < 3 ) - goto error; + return VLC_EGENERIC; oggpacket.granulepos = -1; oggpacket.e_o_s = 0; @@ -374,6 +379,21 @@ static int ProcessHeaders( decoder_t *p_dec ) msg_Err( p_dec, "Could not allocate Theora decoder" ); goto error; } + + i_pp = var_InheritInteger( p_dec, DEC_CFG_PREFIX "postproc" ); + if ( i_pp >= 0 && !th_decode_ctl( p_sys->tcx, + TH_DECCTL_GET_PPLEVEL_MAX, &i_max_pp, sizeof(int) ) ) + { + i_pp = __MIN( i_pp, i_max_pp ); + if ( th_decode_ctl( p_sys->tcx, TH_DECCTL_SET_PPLEVEL, + &i_pp, sizeof(int) ) ) + msg_Err( p_dec, "Failed to set post processing level to %d", + i_pp ); + else + msg_Dbg( p_dec, "Set post processing level to %d / %d", + i_pp, i_max_pp ); + } + } else { @@ -384,15 +404,11 @@ static int ProcessHeaders( decoder_t *p_dec ) p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } - for( unsigned i = 0; i < i_count; i++ ) - free( pp_data[i] ); /* Clean up the decoder setup info... we're done with it */ th_setup_free( ts ); return VLC_SUCCESS; error: - for( unsigned i = 0; i < i_count; i++ ) - free( pp_data[i] ); /* Clean up the decoder setup info... we're done with it */ th_setup_free( ts ); return VLC_EGENERIC; @@ -413,6 +429,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket, /* Don't send the the first packet after a discontinuity to * theora_decode, otherwise we get purple/green display artifacts * appearing in the video output */ + block_Release(p_block); return NULL; } @@ -436,12 +453,11 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket, else { p_buf = DecodePacket( p_dec, p_oggpacket ); - if( p_block ) - block_Release( p_block ); + block_Release( p_block ); } /* Date management */ - p_sys->i_pts += ( INT64_C(1000000) * p_sys->ti.fps_denominator / + p_sys->i_pts += ( CLOCK_FREQ * p_sys->ti.fps_denominator / p_sys->ti.fps_numerator ); /* 1 frame per packet */ return p_buf; @@ -659,8 +675,8 @@ static int OpenEncoder( vlc_object_t *p_this ) th_info_init( &p_sys->ti ); - p_sys->ti.frame_width = p_enc->fmt_in.video.i_width; - p_sys->ti.frame_height = p_enc->fmt_in.video.i_height; + p_sys->ti.frame_width = p_enc->fmt_in.video.i_visible_width; + p_sys->ti.frame_height = p_enc->fmt_in.video.i_visible_height; if( p_sys->ti.frame_width % 16 || p_sys->ti.frame_height % 16 ) { @@ -670,12 +686,12 @@ static int OpenEncoder( vlc_object_t *p_this ) p_sys->ti.frame_height = (p_sys->ti.frame_height + 15) >> 4 << 4; msg_Dbg( p_enc, "padding video from %dx%d to %dx%d", - p_enc->fmt_in.video.i_width, p_enc->fmt_in.video.i_height, + p_enc->fmt_in.video.i_visible_width, p_enc->fmt_in.video.i_visible_height, p_sys->ti.frame_width, p_sys->ti.frame_height ); } - p_sys->ti.pic_width = p_enc->fmt_in.video.i_width; - p_sys->ti.pic_height = p_enc->fmt_in.video.i_height; + p_sys->ti.pic_width = p_enc->fmt_in.video.i_visible_width; + p_sys->ti.pic_height = p_enc->fmt_in.video.i_visible_height; p_sys->ti.pic_x = 0 /*frame_x_offset*/; p_sys->ti.pic_y = 0 /*frame_y_offset*/; @@ -710,7 +726,7 @@ static int OpenEncoder( vlc_object_t *p_this ) } p_sys->ti.target_bitrate = p_enc->fmt_out.i_bitrate; - p_sys->ti.quality = ((float)i_quality) * 6.3; + p_sys->ti.quality = ((float)i_quality) * 6.3f; p_sys->tcx = th_encode_alloc( &p_sys->ti ); @@ -850,7 +866,7 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict ) th_encode_packetout( p_sys->tcx, 0, &oggpacket ); /* Ogg packet to block */ - p_block = block_New( p_enc, oggpacket.bytes ); + p_block = block_Alloc( oggpacket.bytes ); memcpy( p_block->p_buffer, oggpacket.packet, oggpacket.bytes ); p_block->i_dts = p_block->i_pts = p_pict->date;