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

📄 rss.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * rss.c : rss/atom feed display video plugin for vlc ***************************************************************************** * Copyright (C) 2003-2006 the VideoLAN team * $Id: rss.c 18287 2006-12-06 10:41:07Z md $ * * Authors: Antoine Cellerier <dionoea -at- videolan -dot- 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. *****************************************************************************//***************************************************************************** * Atom : http://www.ietf.org/rfc/rfc4287.txt * RSS : http://www.rssboard.org/rss-specification *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>                                      /* malloc(), free() */#include <string.h>#include <vlc/vlc.h>#include <vlc/vout.h>#include "vlc_filter.h"#include "vlc_block.h"#include "vlc_osd.h"#include "vlc_block.h"#include "vlc_stream.h"#include "vlc_xml.h"#include "charset.h"#include "vlc_image.h"/***************************************************************************** * Local prototypes *****************************************************************************/static int  CreateFilter ( vlc_object_t * );static void DestroyFilter( vlc_object_t * );static subpicture_t *Filter( filter_t *, mtime_t );static int FetchRSS( filter_t * );static void FreeRSS( filter_t * );static int pi_color_values[] = { 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,               0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,               0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,               0x00000080, 0x000000FF, 0x0000FFFF};static char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),               N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),               N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),               N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),               N_("Aqua") };/***************************************************************************** * filter_sys_t: rss filter descriptor *****************************************************************************/struct rss_item_t{    char *psz_title;    char *psz_description;    char *psz_link;};struct rss_feed_t{    char *psz_title;    char *psz_description;    char *psz_link;    char *psz_image;    picture_t *p_pic;    int i_items;    struct rss_item_t *p_items;};struct filter_sys_t{    vlc_mutex_t lock;    vlc_mutex_t *p_lock;    int i_xoff, i_yoff;  /* offsets for the display string in the video window */    int i_pos; /* permit relative positioning (top, bottom, left, right, center) */    int i_speed;    int i_length;    char *psz_marquee;    /* marquee string */    text_style_t *p_style; /* font control */    mtime_t last_date;    char *psz_urls;    int i_feeds;    struct rss_feed_t *p_feeds;    int i_ttl;    time_t t_last_update;    vlc_bool_t b_images;    int i_cur_feed;    int i_cur_item;    int i_cur_char;};#define MSG_TEXT N_("Feed URLs")#define MSG_LONGTEXT N_("RSS/Atom feed '|' (pipe) seperated URLs.")#define SPEED_TEXT N_("Speed of feeds")#define SPEED_LONGTEXT N_("Speed of the RSS/Atom feeds (bigger is slower).")#define LENGTH_TEXT N_("Max length")#define LENGTH_LONGTEXT N_("Maximum number of characters displayed on the " \                "screen." )#define TTL_TEXT N_("Refresh time")#define TTL_LONGTEXT N_("Number of seconds between each forced refresh " \        "of the feeds. 0 means that the feeds are never updated." )#define IMAGE_TEXT N_("Feed images")#define IMAGE_LONGTEXT N_("Display feed images if available.")#define POSX_TEXT N_("X offset")#define POSX_LONGTEXT N_("X offset, from the left screen edge." )#define POSY_TEXT N_("Y offset")#define POSY_LONGTEXT N_("Y offset, down from the top." )#define OPACITY_TEXT N_("Opacity")#define OPACITY_LONGTEXT N_("Opacity (inverse of transparency) of " \    "overlay text. 0 = transparent, 255 = totally opaque." )#define SIZE_TEXT N_("Font size, pixels")#define SIZE_LONGTEXT N_("Font size, in pixels. Default is -1 (use default " \    "font size)." )#define COLOR_TEXT N_("Color")#define COLOR_LONGTEXT N_("Color of the text that will be rendered on "\    "the video. This must be an hexadecimal (like HTML colors). The first two "\    "chars are for red, then green, then blue. #000000 = black, #FF0000 = red,"\    " #00FF00 = green, #FFFF00 = yellow (red + green), #FFFFFF = white" )#define POS_TEXT N_("Text position")#define POS_LONGTEXT N_( \  "You can enforce the text position on the video " \  "(0=center, 1=left, 2=right, 4=top, 8=bottom; you can " \  "also use combinations of these values, eg 6 = top-right).")static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };static char *ppsz_pos_descriptions[] =     { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),     N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin();    set_capability( "sub filter", 0 );    set_shortname( "RSS / Atom" );    set_callbacks( CreateFilter, DestroyFilter );    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_SUBPIC );    add_string( "rss-urls", "rss", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );    set_section( N_("Position"), NULL );    add_integer( "rss-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );    add_integer( "rss-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );    add_integer( "rss-position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );        change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );    set_section( N_("Font"), NULL );    /* 5 sets the default to top [1] left [4] */    add_integer_with_range( "rss-opacity", 255, 0, 255, NULL,        OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );    add_integer( "rss-color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT,                  VLC_FALSE );        change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );    add_integer( "rss-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );    set_section( N_("Misc"), NULL );    add_integer( "rss-speed", 100000, NULL, SPEED_TEXT, SPEED_LONGTEXT,                 VLC_FALSE );    add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,                 VLC_FALSE );    add_integer( "rss-ttl", 1800, NULL, TTL_TEXT, TTL_LONGTEXT, VLC_FALSE );    add_bool( "rss-images", 1, NULL, IMAGE_TEXT, IMAGE_LONGTEXT, VLC_FALSE );    set_description( _("RSS and Atom feed display") );    add_shortcut( "rss" );    add_shortcut( "atom" );vlc_module_end();/***************************************************************************** * CreateFilter: allocates RSS video filter *****************************************************************************/static int CreateFilter( vlc_object_t *p_this ){    filter_t *p_filter = (filter_t *)p_this;    filter_sys_t *p_sys;    int i_feed;    /* Allocate structure */    p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );    if( p_sys == NULL )    {        msg_Err( p_filter, "out of memory" );        return VLC_ENOMEM;    }    vlc_mutex_init( p_filter, &p_sys->lock );    vlc_mutex_lock( &p_sys->lock );    p_sys->psz_urls = var_CreateGetString( p_filter, "rss-urls" );    p_sys->i_cur_feed = 0;    p_sys->i_cur_item = 0;    p_sys->i_cur_char = 0;    p_sys->i_feeds = 0;    p_sys->p_feeds = NULL;    p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" );    p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" );    p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) );    p_sys->b_images = var_CreateGetBool( p_filter, "rss-images" );    p_sys->psz_marquee = (char *)malloc( p_sys->i_length );    p_sys->p_style = malloc( sizeof( text_style_t ));    memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ));    p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" );    p_sys->i_yoff = var_CreateGetInteger( p_filter, "rss-y" );    p_sys->i_pos = var_CreateGetInteger( p_filter, "rss-position" );    p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_filter, "rss-opacity" );    p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, "rss-color" );    p_sys->p_style->i_font_size = var_CreateGetInteger( p_filter, "rss-size" );    if( p_sys->b_images == VLC_TRUE && p_sys->p_style->i_font_size == -1 )    {        msg_Warn( p_filter, "rrs-size wasn't specified. Feed images will thus be displayed without being resized" );    }    if( FetchRSS( p_filter ) )    {        msg_Err( p_filter, "failed while fetching RSS ... too bad" );        vlc_mutex_unlock( &p_sys->lock );        return VLC_EGENERIC;    }    p_sys->t_last_update = time( NULL );    if( p_sys->i_feeds == 0 )    {        vlc_mutex_unlock( &p_sys->lock );        return VLC_EGENERIC;    }    for( i_feed=0; i_feed < p_sys->i_feeds; i_feed ++ )        if( p_sys->p_feeds[i_feed].i_items == 0 )        {            vlc_mutex_unlock( &p_sys->lock );            return VLC_EGENERIC;        }    /* Misc init */    p_filter->pf_sub_filter = Filter;    p_sys->last_date = (mtime_t)0;    vlc_mutex_unlock( &p_sys->lock );    return VLC_SUCCESS;}/***************************************************************************** * DestroyFilter: destroy RSS video filter *****************************************************************************/static void DestroyFilter( vlc_object_t *p_this ){    filter_t *p_filter = (filter_t *)p_this;    filter_sys_t *p_sys = p_filter->p_sys;    vlc_mutex_lock( &p_sys->lock );    if( p_sys->p_style ) free( p_sys->p_style );    if( p_sys->psz_marquee ) free( p_sys->psz_marquee );    free( p_sys->psz_urls );    FreeRSS( p_filter );    vlc_mutex_unlock( &p_sys->lock );    vlc_mutex_destroy( &p_sys->lock );    free( p_sys );    /* Delete the RSS variables */    var_Destroy( p_filter, "rss-urls" );    var_Destroy( p_filter, "rss-speed" );    var_Destroy( p_filter, "rss-length" );    var_Destroy( p_filter, "rss-ttl" );    var_Destroy( p_filter, "rss-images" );    var_Destroy( p_filter, "rss-x" );

⌨️ 快捷键说明

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