⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mosaic_bridge.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * mosaic_bridge.c: ***************************************************************************** * Copyright (C) 2004-2005 VideoLAN * $Id: mosaic_bridge.c 11088 2005-05-20 18:16:33Z massiot $ * * Authors: Antoine Cellerier <dionoea@videolan.org> *          Christophe Massiot <massiot@via.ecp.fr> * * 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 <errno.h>                                                 /* ENOMEM */#include <stdlib.h>                                                /* free() */#include <string.h>                                            /* strerror() */#include <vlc/vlc.h>#include <vlc/sout.h>#include <vlc/decoder.h>#include "vlc_image.h"#include "../video_filter/mosaic.h"/***************************************************************************** * Local structures *****************************************************************************/struct sout_stream_sys_t{    bridged_es_t *p_es;    vlc_mutex_t *p_lock;    decoder_t       *p_decoder;    image_handler_t *p_image; /* filter for resizing */    int i_height, i_width;    char *psz_id;    vlc_bool_t b_inited;};#define PICTURE_RING_SIZE 64struct decoder_owner_sys_t{    picture_t *pp_pics[PICTURE_RING_SIZE];};typedef void (* pf_release_t)( picture_t * );static void ReleasePicture( picture_t *p_pic ){    p_pic->i_refcount--;    if ( p_pic->i_refcount <= 0 )    {        if ( p_pic->p_sys != NULL )        {            pf_release_t pf_release = (pf_release_t)p_pic->p_sys;            p_pic->p_sys = NULL;            pf_release( p_pic );        }        else        {            if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );            if( p_pic ) free( p_pic );        }    }}/***************************************************************************** * Local prototypes *****************************************************************************/static int  Open    ( vlc_object_t * );static void Close   ( vlc_object_t * );static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );static int               Del ( sout_stream_t *, sout_stream_id_t * );static int               Send( sout_stream_t *, sout_stream_id_t *, block_t * );static void video_del_buffer( decoder_t *, picture_t * );static picture_t *video_new_buffer( decoder_t * );static void video_link_picture_decoder( decoder_t *, picture_t * );static void video_unlink_picture_decoder( decoder_t *, picture_t * );/***************************************************************************** * Module descriptor *****************************************************************************/#define ID_TEXT N_("ID")#define ID_LONGTEXT N_( \    "Specify an identifier string for this subpicture" )#define WIDTH_TEXT N_("Video width")#define WIDTH_LONGTEXT N_( \    "Allows you to specify the output video width." )#define HEIGHT_TEXT N_("Video height")#define HEIGHT_LONGTEXT N_( \    "Allows you to specify the output video height." )#define SOUT_CFG_PREFIX "sout-mosaic-bridge-"vlc_module_begin();    set_shortname( _( "Mosaic bridge" ) );    set_description(_("Mosaic bridge stream output") );    set_capability( "sout stream", 0 );    add_shortcut( "mosaic-bridge" );    add_string( SOUT_CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,                VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,                 WIDTH_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,                 HEIGHT_LONGTEXT, VLC_TRUE );    set_callbacks( Open, Close );    var_Create( p_module->p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );vlc_module_end();static const char *ppsz_sout_options[] = {    "id", "width", "height", NULL};/***************************************************************************** * Open *****************************************************************************/static int Open( vlc_object_t *p_this ){    sout_stream_t     *p_stream = (sout_stream_t *)p_this;    sout_stream_sys_t *p_sys;    libvlc_t *p_libvlc = p_this->p_libvlc;    vlc_value_t val;    sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,                   p_stream->p_cfg );    p_sys          = malloc( sizeof( sout_stream_sys_t ) );    p_stream->p_sys = p_sys;    p_sys->b_inited = VLC_FALSE;    var_Get( p_libvlc, "mosaic-lock", &val );    p_sys->p_lock = val.p_address;    var_Get( p_stream, SOUT_CFG_PREFIX "id", &val );    p_sys->psz_id = val.psz_string;    var_Get( p_stream, SOUT_CFG_PREFIX "height", &val );    p_sys->i_height = val.i_int;     var_Get( p_stream, SOUT_CFG_PREFIX "width", &val );    p_sys->i_width = val.i_int;     if ( p_sys->i_height || p_sys->i_width )    {        p_sys->p_image = image_HandlerCreate( p_stream );    }    p_stream->pf_add    = Add;    p_stream->pf_del    = Del;    p_stream->pf_send   = Send;    p_stream->p_sout->i_out_pace_nocontrol++;    return VLC_SUCCESS;}/***************************************************************************** * Close *****************************************************************************/static void Close( vlc_object_t * p_this ){    sout_stream_t     *p_stream = (sout_stream_t*)p_this;    sout_stream_sys_t *p_sys = p_stream->p_sys;    p_stream->p_sout->i_out_pace_nocontrol--;    if ( p_sys->psz_id )        free( p_sys->psz_id );    free( p_sys );}static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ){    sout_stream_sys_t *p_sys = p_stream->p_sys;    bridge_t *p_bridge;    bridged_es_t *p_es;    int i;    if ( p_sys->b_inited )    {        return NULL;    }    /* Create decoder object */    p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );    vlc_object_attach( p_sys->p_decoder, p_stream );    p_sys->p_decoder->p_module = NULL;    p_sys->p_decoder->fmt_in = *p_fmt;    p_sys->p_decoder->b_pace_control = VLC_FALSE;    p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;    p_sys->p_decoder->fmt_out.i_extra = 0;    p_sys->p_decoder->fmt_out.p_extra = 0;    p_sys->p_decoder->pf_decode_video = 0;    p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer;    p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer;    p_sys->p_decoder->pf_picture_link    = video_link_picture_decoder;    p_sys->p_decoder->pf_picture_unlink  = video_unlink_picture_decoder;    p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );    for( i = 0; i < PICTURE_RING_SIZE; i++ )        p_sys->p_decoder->p_owner->pp_pics[i] = 0;    //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;    p_sys->p_decoder->p_module =        module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );    if( !p_sys->p_decoder->p_module )    {        msg_Err( p_stream, "cannot find decoder" );        vlc_object_detach( p_sys->p_decoder );        vlc_object_destroy( p_sys->p_decoder );        return NULL;    }    p_sys->b_inited = VLC_TRUE;    vlc_mutex_lock( p_sys->p_lock );    p_bridge = GetBridge( p_stream );    if ( p_bridge == NULL )    {        libvlc_t *p_libvlc = p_stream->p_libvlc;        vlc_value_t val;        p_bridge = malloc( sizeof( bridge_t ) );        var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );        val.p_address = p_bridge;        var_Set( p_libvlc, "mosaic-struct", val );        p_bridge->i_es_num = 0;        p_bridge->pp_es = NULL;    }    for ( i = 0; i < p_bridge->i_es_num; i++ )    {        if ( p_bridge->pp_es[i]->b_empty )            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -