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

📄 mosaic_bridge.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
    }    if ( i == p_bridge->i_es_num )    {        p_bridge->pp_es = realloc( p_bridge->pp_es,                                   (p_bridge->i_es_num + 1)                                     * sizeof(bridged_es_t *) );        p_bridge->i_es_num++;        p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );    }    p_sys->p_es = p_es = p_bridge->pp_es[i];    //p_es->fmt = *p_fmt;    p_es->psz_id = p_sys->psz_id;    p_es->p_picture = NULL;    p_es->pp_last = &p_es->p_picture;    p_es->b_empty = VLC_FALSE;    vlc_mutex_unlock( p_sys->p_lock );    msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );    return (sout_stream_id_t *)p_sys;}static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ){    sout_stream_sys_t *p_sys = p_stream->p_sys;    bridge_t *p_bridge;    bridged_es_t *p_es;    vlc_bool_t b_last_es = VLC_TRUE;    int i;    if ( !p_sys->b_inited )    {        return VLC_SUCCESS;    }    if ( p_sys->p_decoder )    {        if( p_sys->p_decoder->p_module )            module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );        vlc_object_detach( p_sys->p_decoder );        vlc_object_destroy( p_sys->p_decoder );    }    vlc_mutex_lock( p_sys->p_lock );    p_bridge = GetBridge( p_stream );    p_es = p_sys->p_es;    p_es->b_empty = VLC_TRUE;    while ( p_es->p_picture )    {        picture_t *p_next = p_es->p_picture->p_next;        p_es->p_picture->pf_release( p_es->p_picture );        p_es->p_picture = p_next;    }    for ( i = 0; i < p_bridge->i_es_num; i++ )    {        if ( !p_bridge->pp_es[i]->b_empty )        {            b_last_es = VLC_FALSE;            break;        }    }    if ( b_last_es )    {        libvlc_t *p_libvlc = p_stream->p_libvlc;        for ( i = 0; i < p_bridge->i_es_num; i++ )            free( p_bridge->pp_es[i] );        free( p_bridge->pp_es );        free( p_bridge );        var_Destroy( p_libvlc, "mosaic-struct" );    }    vlc_mutex_unlock( p_sys->p_lock );    if ( p_sys->i_height || p_sys->i_width )    {        image_HandlerDelete( p_sys->p_image );    }    p_sys->b_inited = VLC_FALSE;    return VLC_SUCCESS;}/***************************************************************************** * PushPicture : push a picture in the mosaic-struct structure *****************************************************************************/static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture ){    sout_stream_sys_t *p_sys = p_stream->p_sys;    bridged_es_t *p_es = p_sys->p_es;    vlc_mutex_lock( p_sys->p_lock );    *p_es->pp_last = p_picture;    p_picture->p_next = NULL;    p_es->pp_last = &p_picture->p_next;    vlc_mutex_unlock( p_sys->p_lock );}static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,                 block_t *p_buffer ){    sout_stream_sys_t *p_sys = p_stream->p_sys;    picture_t *p_pic;    if ( (sout_stream_sys_t *)id != p_sys )    {        block_ChainRelease( p_buffer );        return VLC_SUCCESS;    }    while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,                                                        &p_buffer )) )    {        picture_t *p_new_pic;        if ( p_sys->i_height || p_sys->i_width )        {            video_format_t fmt_out = {0}, fmt_in = {0};            fmt_in = p_sys->p_decoder->fmt_out.video;            fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');            fmt_out.i_width = p_sys->i_width;            fmt_out.i_height = p_sys->i_height;            fmt_out.i_visible_width = fmt_out.i_width;            fmt_out.i_visible_height = fmt_out.i_height;            p_new_pic = image_Convert( p_sys->p_image,                                       p_pic, &fmt_in, &fmt_out );            if ( p_new_pic == NULL )            {                msg_Err( p_stream, "image conversion failed" );                continue;            }        }        else        {            p_new_pic = (picture_t*)malloc( sizeof(picture_t) );            vout_AllocatePicture( p_stream, p_new_pic, p_pic->format.i_chroma,                                  p_pic->format.i_width, p_pic->format.i_height,                                  p_sys->p_decoder->fmt_out.video.i_aspect );            vout_CopyPicture( p_stream, p_new_pic, p_pic );        }        p_new_pic->i_refcount = 1;        p_new_pic->i_status = DESTROYED_PICTURE;        p_new_pic->i_type   = DIRECT_PICTURE;        p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;        p_new_pic->pf_release = ReleasePicture;        p_new_pic->date = p_pic->date;        p_pic->pf_release( p_pic );        PushPicture( p_stream, p_new_pic );    }    return VLC_SUCCESS;}struct picture_sys_t{    vlc_object_t *p_owner;};static void video_release_buffer( picture_t *p_pic ){    if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )    {        video_del_buffer( (decoder_t *)p_pic->p_sys->p_owner, p_pic );    }    else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;}static picture_t *video_new_buffer( decoder_t *p_dec ){    picture_t **pp_ring = p_dec->p_owner->pp_pics;    picture_t *p_pic;    int i;    /* Find an empty space in the picture ring buffer */    for( i = 0; i < PICTURE_RING_SIZE; i++ )    {        if( pp_ring[i] != 0 && pp_ring[i]->i_status == DESTROYED_PICTURE )        {            pp_ring[i]->i_status = RESERVED_PICTURE;            return pp_ring[i];        }    }    for( i = 0; i < PICTURE_RING_SIZE; i++ )    {        if( pp_ring[i] == 0 ) break;    }    if( i == PICTURE_RING_SIZE )    {        msg_Err( p_dec, "decoder/filter is leaking pictures, "                 "resetting its ring buffer" );        for( i = 0; i < PICTURE_RING_SIZE; i++ )        {            pp_ring[i]->pf_release( pp_ring[i] );        }        i = 0;    }    p_pic = malloc( sizeof(picture_t) );    p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;    vout_AllocatePicture( VLC_OBJECT(p_dec), p_pic,                          p_dec->fmt_out.video.i_chroma,                          p_dec->fmt_out.video.i_width,                          p_dec->fmt_out.video.i_height,                          p_dec->fmt_out.video.i_aspect );    if( !p_pic->i_planes )    {        free( p_pic );        return 0;    }    p_pic->pf_release = video_release_buffer;    p_pic->p_sys = malloc( sizeof(picture_sys_t) );    p_pic->p_sys->p_owner = VLC_OBJECT(p_dec);    p_pic->i_status = RESERVED_PICTURE;    pp_ring[i] = p_pic;    return p_pic;}static void video_del_buffer( decoder_t *p_this, picture_t *p_pic ){    p_pic->i_refcount = 0;    p_pic->i_status = DESTROYED_PICTURE;}static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic ){    p_pic->i_refcount++;}static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic ){    video_release_buffer( p_pic );}

⌨️ 快捷键说明

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