Commit 26adc5a8 authored by Antoine Cellerier's avatar Antoine Cellerier

rss.c: add suport for feed images (default enabled).

tested with 
./vlc --sub-filter rss --rss-urls "http://www.lefigaro.fr/rss/figaro_une.xml|http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml" --rss-length 40 --rss-size 15 --rss-images --rss-speed 1000 <video>
parent 4bf6d519
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "vlc_xml.h" #include "vlc_xml.h"
#include "charset.h" #include "charset.h"
#include "vlc_image.h"
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -75,6 +77,8 @@ struct rss_feed_t ...@@ -75,6 +77,8 @@ struct rss_feed_t
char *psz_title; char *psz_title;
char *psz_description; char *psz_description;
char *psz_link; char *psz_link;
char *psz_image;
picture_t *p_pic;
int i_items; int i_items;
struct rss_item_t *p_items; struct rss_item_t *p_items;
...@@ -102,6 +106,7 @@ struct filter_sys_t ...@@ -102,6 +106,7 @@ struct filter_sys_t
int i_ttl; int i_ttl;
time_t t_last_update; time_t t_last_update;
vlc_bool_t b_images;
int i_cur_feed; int i_cur_feed;
int i_cur_item; int i_cur_item;
...@@ -116,7 +121,8 @@ struct filter_sys_t ...@@ -116,7 +121,8 @@ struct filter_sys_t
#define LENGTH_LONGTEXT N_("RSS feed max number of chars displayed") #define LENGTH_LONGTEXT N_("RSS feed max number of chars displayed")
#define TTL_TEXT N_("Number of seconds between each forced refresh of the feeds") #define TTL_TEXT N_("Number of seconds between each forced refresh of the feeds")
#define TTL_LONGTEXT N_("Number of seconds between each forced refresh of the feeds. If 0, the feeds will never be updated.") #define TTL_LONGTEXT N_("Number of seconds between each forced refresh of the feeds. If 0, the feeds will never be updated.")
#define IMAGE_TEXT N_("Display feed images if available")
#define IMAGE_LONGTEXT N_("Display feed images if available")
#define POSX_TEXT N_("X offset, from left") #define POSX_TEXT N_("X offset, from left")
#define POSX_LONGTEXT N_("X offset, from the left screen edge" ) #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
...@@ -177,6 +183,7 @@ vlc_module_begin(); ...@@ -177,6 +183,7 @@ vlc_module_begin();
add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT, add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,
VLC_FALSE ); VLC_FALSE );
add_integer( "rss-ttl", 1800, NULL, TTL_TEXT, TTL_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 feed display") ); set_description( _("RSS feed display") );
add_shortcut( "rss" ); add_shortcut( "rss" );
...@@ -211,6 +218,7 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -211,6 +218,7 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" ); p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" );
p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" ); p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" );
p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) ); 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->psz_marquee = (char *)malloc( p_sys->i_length );
p_sys->p_style = malloc( sizeof( text_style_t )); p_sys->p_style = malloc( sizeof( text_style_t ));
...@@ -223,6 +231,11 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -223,6 +231,11 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, "rss-color" ); 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" ); 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 ) ) if( FetchRSS( p_filter ) )
{ {
msg_Err( p_filter, "failed while fetching RSS ... too bad" ); msg_Err( p_filter, "failed while fetching RSS ... too bad" );
...@@ -274,6 +287,7 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -274,6 +287,7 @@ static void DestroyFilter( vlc_object_t *p_this )
var_Destroy( p_filter, "rss-speed" ); var_Destroy( p_filter, "rss-speed" );
var_Destroy( p_filter, "rss-length" ); var_Destroy( p_filter, "rss-length" );
var_Destroy( p_filter, "rss-ttl" ); var_Destroy( p_filter, "rss-ttl" );
var_Destroy( p_filter, "rss-images" );
var_Destroy( p_filter, "rss-x" ); var_Destroy( p_filter, "rss-x" );
var_Destroy( p_filter, "rss-y" ); var_Destroy( p_filter, "rss-y" );
var_Destroy( p_filter, "rss-position" ); var_Destroy( p_filter, "rss-position" );
...@@ -291,10 +305,14 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -291,10 +305,14 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
{ {
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
subpicture_t *p_spu; subpicture_t *p_spu;
video_format_t fmt; video_format_t fmt = {0};
subpicture_region_t *p_region;
int i_feed, i_item; int i_feed, i_item;
struct rss_feed_t *p_feed;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( p_sys->last_date if( p_sys->last_date
...@@ -341,13 +359,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -341,13 +359,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
return NULL; return NULL;
} }
memset( &fmt, 0, sizeof(video_format_t) );
fmt.i_chroma = VLC_FOURCC('T','E','X','T'); fmt.i_chroma = VLC_FOURCC('T','E','X','T');
fmt.i_aspect = 0;
fmt.i_width = 0;
fmt.i_height = 0;
fmt.i_x_offset = 0;
fmt.i_y_offset = 0;
p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt ); p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
if( !p_spu->p_region ) if( !p_spu->p_region )
{ {
...@@ -360,10 +373,22 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -360,10 +373,22 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
be p_sys->i_length characters long. */ be p_sys->i_length characters long. */
i_item = p_sys->i_cur_item; i_item = p_sys->i_cur_item;
i_feed = p_sys->i_cur_feed; i_feed = p_sys->i_cur_feed;
p_feed = &p_sys->p_feeds[p_sys->i_cur_feed];
if( p_feed->p_pic )
{
/* Don't display the feed's title if we have an image */
snprintf( p_sys->psz_marquee, p_sys->i_length, "%s",
p_sys->p_feeds[i_feed].p_items[i_item].psz_title
+p_sys->i_cur_char );
}
else
{
snprintf( p_sys->psz_marquee, p_sys->i_length, "%s : %s", snprintf( p_sys->psz_marquee, p_sys->i_length, "%s : %s",
p_sys->p_feeds[i_feed].psz_title, p_sys->p_feeds[i_feed].psz_title,
p_sys->p_feeds[i_feed].p_items[i_item].psz_title p_sys->p_feeds[i_feed].p_items[i_item].psz_title
+p_sys->i_cur_char ); +p_sys->i_cur_char );
}
while( strlen( p_sys->psz_marquee ) < (unsigned int)p_sys->i_length ) while( strlen( p_sys->psz_marquee ) < (unsigned int)p_sys->i_length )
{ {
...@@ -374,6 +399,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -374,6 +399,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
" - %s", " - %s",
p_sys->p_feeds[i_feed].p_items[i_item].psz_title ); p_sys->p_feeds[i_feed].p_items[i_item].psz_title );
} }
/* Calls to snprintf might split multibyte UTF8 chars ... /* Calls to snprintf might split multibyte UTF8 chars ...
* which freetype doesn't like. */ * which freetype doesn't like. */
{ {
...@@ -410,9 +436,39 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -410,9 +436,39 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
p_spu->i_y = p_sys->i_yoff; p_spu->i_y = p_sys->i_yoff;
p_spu->b_absolute = VLC_TRUE; p_spu->b_absolute = VLC_TRUE;
} }
p_spu->i_height = 1; p_spu->i_height = 1;
p_spu->p_region->p_style = p_sys->p_style; p_spu->p_region->p_style = p_sys->p_style;
if( p_feed->p_pic )
{
/* Display the feed's image */
picture_t *p_pic = p_feed->p_pic;
video_format_t fmt_out = {0};
fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
fmt_out.i_aspect = VOUT_ASPECT_FACTOR;
fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
fmt_out.i_width =
fmt_out.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
fmt_out.i_height =
fmt_out.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
p_region = p_spu->pf_create_region( VLC_OBJECT( p_filter ), &fmt_out );
if( !p_region )
{
msg_Err( p_filter, "cannot allocate SPU region" );
}
else
{
vout_CopyPicture( p_filter, &p_region->picture, p_pic );
p_spu->p_region->p_next = p_region;
}
/* Offset text to display right next to the image */
p_spu->p_region->i_x = p_pic->p[Y_PLANE].i_visible_pitch;
}
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return p_spu; return p_spu;
} }
...@@ -424,6 +480,54 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -424,6 +480,54 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
* functions * functions
***************************************************************************/ ***************************************************************************/
/****************************************************************************
* download and resize image located at psz_url
***************************************************************************/
picture_t *LoadImage( filter_t *p_filter, const char *psz_url )
{
filter_sys_t *p_sys = p_filter->p_sys;
video_format_t fmt_in={0}, fmt_out={0};
picture_t *p_orig, *p_pic=NULL;
image_handler_t *p_handler = image_HandlerCreate( p_filter );
char *psz_local;
psz_local = ToLocale( psz_url );
fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
p_orig = image_ReadUrl( p_handler, psz_local, &fmt_in, &fmt_out );
LocaleFree( psz_local );
if( !p_orig )
{
msg_Warn( p_filter, "Unable to read image %s", psz_url );
}
else if( p_sys->p_style->i_font_size > 0 )
{
fmt_in.i_chroma = VLC_FOURCC('Y','U','V','A');
fmt_in.i_height = p_orig->p[Y_PLANE].i_visible_lines;
fmt_in.i_width = p_orig->p[Y_PLANE].i_visible_pitch;
fmt_out.i_width = p_orig->p[Y_PLANE].i_visible_pitch
*p_sys->p_style->i_font_size/p_orig->p[Y_PLANE].i_visible_lines;
fmt_out.i_height = p_sys->p_style->i_font_size;
p_pic = image_Convert( p_handler, p_orig, &fmt_in, &fmt_out );
p_orig->pf_release( p_orig );
if( !p_pic )
{
msg_Warn( p_filter, "Error while converting %s", psz_url );
}
}
else
{
p_pic = p_orig;
}
image_HandlerDelete( p_handler );
return p_pic;
}
/**************************************************************************** /****************************************************************************
* remove all ' ' '\t' '\n' '\r' characters from the begining and end of the * remove all ' ' '\t' '\n' '\r' characters from the begining and end of the
...@@ -470,7 +574,8 @@ static int FetchRSS( filter_t *p_filter) ...@@ -470,7 +574,8 @@ static int FetchRSS( filter_t *p_filter)
int i_feed; int i_feed;
int i_item; int i_item;
int i_is_item; vlc_bool_t b_is_item;
vlc_bool_t b_is_image;
int i_int; int i_int;
FreeRSS( p_filter ); FreeRSS( p_filter );
...@@ -504,6 +609,8 @@ static int FetchRSS( filter_t *p_filter) ...@@ -504,6 +609,8 @@ static int FetchRSS( filter_t *p_filter)
p_feed->psz_title = NULL; p_feed->psz_title = NULL;
p_feed->psz_description = NULL; p_feed->psz_description = NULL;
p_feed->psz_link = NULL; p_feed->psz_link = NULL;
p_feed->psz_image = NULL;
p_feed->p_pic = NULL;
p_feed->i_items = 0; p_feed->i_items = 0;
p_feed->p_items = NULL; p_feed->p_items = NULL;
...@@ -524,7 +631,8 @@ static int FetchRSS( filter_t *p_filter) ...@@ -524,7 +631,8 @@ static int FetchRSS( filter_t *p_filter)
} }
i_item = 0; i_item = 0;
i_is_item = VLC_FALSE; b_is_item = VLC_FALSE;
b_is_image = VLC_FALSE;
while( xml_ReaderRead( p_xml_reader ) == 1 ) while( xml_ReaderRead( p_xml_reader ) == 1 )
{ {
...@@ -550,7 +658,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -550,7 +658,7 @@ static int FetchRSS( filter_t *p_filter)
# endif # endif
if( !strcmp( psz_eltname, "item" ) ) if( !strcmp( psz_eltname, "item" ) )
{ {
i_is_item = VLC_TRUE; b_is_item = VLC_TRUE;
p_feed->i_items++; p_feed->i_items++;
p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) ); p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) );
p_feed->p_items[p_feed->i_items-1].psz_title = NULL; p_feed->p_items[p_feed->i_items-1].psz_title = NULL;
...@@ -558,6 +666,10 @@ static int FetchRSS( filter_t *p_filter) ...@@ -558,6 +666,10 @@ static int FetchRSS( filter_t *p_filter)
= NULL; = NULL;
p_feed->p_items[p_feed->i_items-1].psz_link = NULL; p_feed->p_items[p_feed->i_items-1].psz_link = NULL;
} }
else if( !strcmp( psz_eltname, "image" ) )
{
b_is_image = VLC_TRUE;
}
break; break;
case XML_READER_ENDELEM: case XML_READER_ENDELEM:
...@@ -576,9 +688,13 @@ static int FetchRSS( filter_t *p_filter) ...@@ -576,9 +688,13 @@ static int FetchRSS( filter_t *p_filter)
# endif # endif
if( !strcmp( psz_eltname, "item" ) ) if( !strcmp( psz_eltname, "item" ) )
{ {
i_is_item = VLC_FALSE; b_is_item = VLC_FALSE;
i_item++; i_item++;
} }
else if( !strcmp( psz_eltname, "image" ) )
{
b_is_image = VLC_FALSE;
}
free( psz_eltname ); free( psz_eltname );
psz_eltname = NULL; psz_eltname = NULL;
break; break;
...@@ -598,19 +714,36 @@ static int FetchRSS( filter_t *p_filter) ...@@ -598,19 +714,36 @@ static int FetchRSS( filter_t *p_filter)
# ifdef RSS_DEBUG # ifdef RSS_DEBUG
msg_Dbg( p_filter, " text : <%s>", psz_eltvalue ); msg_Dbg( p_filter, " text : <%s>", psz_eltvalue );
# endif # endif
if( i_is_item == VLC_FALSE ) if( b_is_item == VLC_TRUE )
{ {
struct rss_item_t *p_item;
p_item = p_feed->p_items+i_item;
if( !strcmp( psz_eltname, "title" ) ) if( !strcmp( psz_eltname, "title" ) )
{ {
p_feed->psz_title = psz_eltvalue; p_item->psz_title = psz_eltvalue;
} }
else if( !strcmp( psz_eltname, "link" ) ) else if( !strcmp( psz_eltname, "link" ) )
{ {
p_feed->psz_link = psz_eltvalue; p_item->psz_link = psz_eltvalue;
} }
else if( !strcmp( psz_eltname, "description" ) ) else if( !strcmp( psz_eltname, "description" ) )
{ {
p_feed->psz_description = psz_eltvalue; p_item->psz_description = psz_eltvalue;
}
else
{
free( psz_eltvalue );
psz_eltvalue = NULL;
}
}
else if( b_is_image == VLC_TRUE )
{
if( !strcmp( psz_eltname, "url" ) )
{
p_feed->psz_image = psz_eltvalue;
if( p_sys->b_images == VLC_TRUE )
p_feed->p_pic = LoadImage( p_filter,
p_feed->psz_image );
} }
else else
{ {
...@@ -620,19 +753,17 @@ static int FetchRSS( filter_t *p_filter) ...@@ -620,19 +753,17 @@ static int FetchRSS( filter_t *p_filter)
} }
else else
{ {
struct rss_item_t *p_item;
p_item = p_feed->p_items+i_item;
if( !strcmp( psz_eltname, "title" ) ) if( !strcmp( psz_eltname, "title" ) )
{ {
p_item->psz_title = psz_eltvalue; p_feed->psz_title = psz_eltvalue;
} }
else if( !strcmp( psz_eltname, "link" ) ) else if( !strcmp( psz_eltname, "link" ) )
{ {
p_item->psz_link = psz_eltvalue; p_feed->psz_link = psz_eltvalue;
} }
else if( !strcmp( psz_eltname, "description" ) ) else if( !strcmp( psz_eltname, "description" ) )
{ {
p_item->psz_description = psz_eltvalue; p_feed->psz_description = psz_eltvalue;
} }
else else
{ {
...@@ -681,6 +812,9 @@ static void FreeRSS( filter_t *p_filter) ...@@ -681,6 +812,9 @@ static void FreeRSS( filter_t *p_filter)
free( p_feed->psz_title); free( p_feed->psz_title);
free( p_feed->psz_link ); free( p_feed->psz_link );
free( p_feed->psz_description ); free( p_feed->psz_description );
free( p_feed->psz_image );
if( p_feed->p_pic != NULL )
p_feed->p_pic->pf_release( p_feed->p_pic );
} }
free( p_sys->p_feeds ); free( p_sys->p_feeds );
p_sys->i_feeds = 0; p_sys->i_feeds = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment