~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to modules/gui/fbosd.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * fbosd.c : framebuffer osd plugin for vlc
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2007-2008, the VideoLAN team
5
 
 * $Id: 9af2a75873aeed672c3bc0508633a66fe3debeb3 $
 
5
 * $Id: d7845bfc4bee6db2f2666ae87930100f987c035c $
6
6
 *
7
7
 * Authors: Jean-Paul Saman
8
8
 * Copied from modules/video_output/fb.c by Samuel Hocevar <sam@zoy.org>
31
31
 
32
32
#include <vlc_common.h>
33
33
#include <vlc_plugin.h>
 
34
#include <vlc_fs.h>
34
35
 
35
 
#include <errno.h>
36
36
#include <stdlib.h>                                                /* free() */
37
37
#include <string.h>                                            /* strerror() */
38
38
#include <fcntl.h>                                                 /* open() */
234
234
    int             i_state;
235
235
 
236
236
    /* Font style */
237
 
    text_style_t    text_style;                              /* font control */
 
237
    text_style_t*   p_text_style;                            /* font control */
238
238
    char            *psz_string;
239
239
 
240
240
    /* Position */
310
310
    if( !p_intf->p_sys )
311
311
        return VLC_ENOMEM;
312
312
 
313
 
    p_sys->p_style = malloc( sizeof( text_style_t ) );
 
313
    p_sys->p_style = text_style_New();
314
314
    if( !p_sys->p_style )
315
315
    {
316
316
        free( p_intf->p_sys );
317
317
        return VLC_ENOMEM;
318
318
    }
319
 
    vlc_memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
320
319
 
321
320
    p_intf->pf_run = Run;
322
321
 
323
322
    p_sys->p_image = image_HandlerCreate( p_this );
324
323
    if( !p_sys->p_image )
325
324
    {
326
 
        free( p_sys->p_style );
 
325
        text_style_Delete( p_sys->p_style );
327
326
        free( p_sys );
328
327
        return VLC_ENOMEM;
329
328
    }
331
330
    p_sys->i_alpha = var_CreateGetIntegerCommand( p_intf, "fbosd-alpha" );
332
331
    var_AddCallback( p_intf, "fbosd-alpha", OverlayCallback, NULL );
333
332
 
 
333
    /* Use PAL by default */
 
334
    p_sys->i_width  = p_sys->fmt_out.i_width  = 704;
 
335
    p_sys->i_height = p_sys->fmt_out.i_height = 576;
 
336
 
334
337
    p_sys->i_aspect = -1;
335
338
    psz_aspect =
336
339
            var_CreateGetNonEmptyString( p_intf, "fbosd-aspect-ratio" );
343
346
            *psz_parser++ = '\0';
344
347
            p_sys->i_aspect = ( atoi( psz_aspect )
345
348
                              * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
346
 
            p_sys->fmt_out.i_aspect = p_sys->i_aspect;
 
349
            p_sys->fmt_out.i_sar_num = p_sys->i_aspect    * p_sys->i_height;
 
350
            p_sys->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR * p_sys->i_width;
347
351
        }
348
352
        msg_Dbg( p_intf, "using aspect ratio %d:%d",
349
353
                  atoi( psz_aspect ), atoi( psz_parser ) );
351
355
        free( psz_aspect );
352
356
    }
353
357
 
354
 
    /* Use PAL by default */
355
 
    p_sys->i_width  = p_sys->fmt_out.i_width  = 704;
356
 
    p_sys->i_height = p_sys->fmt_out.i_height = 576;
357
 
 
358
358
    psz_tmp = var_CreateGetNonEmptyStringCommand( p_intf, "fbosd-image" );
359
359
    var_AddCallback( p_intf, "fbosd-image", OverlayCallback, NULL );
360
360
    if( psz_tmp && *psz_tmp )
395
395
    var_AddCallback( p_intf, "fbosd-font-opacity", OverlayCallback, NULL );
396
396
 
397
397
    for( i = 0; i < FBOSD_RENDER_MAX; i++ )
398
 
    {
399
 
        vlc_memcpy( &p_sys->render[i].text_style, &default_text_style,
400
 
                    sizeof( text_style_t ) );
401
 
    }
 
398
        p_sys->render[i].p_text_style = text_style_New();
402
399
 
403
400
    p_sys->b_clear = var_CreateGetBoolCommand( p_intf, "fbosd-clear" );
404
401
    p_sys->b_render = var_CreateGetBoolCommand( p_intf, "fbosd-render" );
508
505
    {
509
506
        free( p_sys->render[i].psz_string );
510
507
        p_sys->render[i].i_state = FBOSD_STATE_FREE;
 
508
        text_style_Delete( p_sys->render[i].p_text_style );
511
509
    }
512
510
 
513
511
#if defined(FBOSD_BLENDING)
520
518
    if( p_sys->p_overlay )
521
519
        picture_Release( p_sys->p_overlay );
522
520
 
523
 
    free( p_sys->p_style );
 
521
    text_style_Delete( p_sys->p_style );
524
522
    free( p_sys );
525
523
}
526
524
 
534
532
    vlc_object_attach( p_intf->p_sys->p_blend, p_intf );
535
533
    p_intf->p_sys->p_blend->fmt_out.video.i_x_offset =
536
534
        p_intf->p_sys->p_blend->fmt_out.video.i_y_offset = 0;
537
 
    p_intf->p_sys->p_blend->fmt_out.video.i_aspect =
538
 
            p_intf->p_sys->fmt_out.i_aspect;
 
535
    p_intf->p_sys->p_blend->fmt_out.video.i_sar_num =
 
536
            p_intf->p_sys->fmt_out.i_sar_num;
 
537
    p_intf->p_sys->p_blend->fmt_out.video.i_sar_den =
 
538
            p_intf->p_sys->fmt_out.i_sar_den;
539
539
    p_intf->p_sys->p_blend->fmt_out.video.i_chroma =
540
540
            p_intf->p_sys->fmt_out.i_chroma;
541
 
    if( config_GetInt( p_intf, "freetype-yuvp" ) )
 
541
    if( var_InheritBool( p_intf, "freetype-yuvp" ) )
542
542
        p_intf->p_sys->p_blend->fmt_in.video.i_chroma =
543
 
                VLC_FOURCC('Y','U','V','P');
 
543
                VLC_CODEC_YUVP;
544
544
    else
545
545
        p_intf->p_sys->p_blend->fmt_in.video.i_chroma =
546
 
                VLC_FOURCC('Y','U','V','A');
 
546
                VLC_CODEC_YUVA;
547
547
 
548
548
    p_intf->p_sys->p_blend->p_module =
549
549
        module_need( p_intf->p_sys->p_blend, "video blending", NULL, false );
562
562
            module_unneed( p_intf->p_sys->p_blend,
563
563
                           p_intf->p_sys->p_blend->p_module );
564
564
 
565
 
        vlc_object_detach( p_intf->p_sys->p_blend );
566
565
        vlc_object_release( p_intf->p_sys->p_blend );
567
566
    }
568
567
}
613
612
            module_unneed( p_intf->p_sys->p_text,
614
613
                           p_intf->p_sys->p_text->p_module );
615
614
 
616
 
        vlc_object_detach( p_intf->p_sys->p_text );
617
615
        vlc_object_release( p_intf->p_sys->p_text );
618
616
    }
619
617
}
624
622
 *****************************************************************************/
625
623
static picture_t *AllocatePicture( video_format_t *p_fmt )
626
624
{
627
 
    picture_t *p_picture = picture_New( p_fmt->i_chroma,
628
 
                                        p_fmt->i_width, p_fmt->i_height,
629
 
                                        p_fmt->i_aspect );
 
625
    picture_t *p_picture = picture_NewFromFormat( p_fmt );
630
626
    if( !p_picture )
631
627
        return NULL;
632
628
 
633
629
    if( !p_fmt->p_palette &&
634
 
        ( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') ) )
 
630
        ( p_fmt->i_chroma == VLC_CODEC_YUVP ) )
635
631
    {
636
632
        p_fmt->p_palette = malloc( sizeof(video_palette_t) );
637
633
        if( !p_fmt->p_palette )
740
736
 
741
737
    switch( fmt.i_chroma )
742
738
    {
743
 
        case VLC_FOURCC('R','V','2','4'):
 
739
        case VLC_CODEC_RGB24:
744
740
            p_begin = (uint8_t *)(*p_pic)->p[Y_PLANE].p_pixels;
745
741
            p_end   = (uint8_t *)(*p_pic)->p[Y_PLANE].p_pixels +
746
742
                      ( fmt.i_height * (*p_pic)->p[Y_PLANE].i_pitch );
747
743
            i_skip = 3;
748
744
            break;
749
 
        case VLC_FOURCC('R','V','3','2'):
 
745
        case VLC_CODEC_RGB32:
750
746
            p_begin = (uint8_t *)(*p_pic)->p[Y_PLANE].p_pixels;
751
747
            p_end   = (uint8_t *)(*p_pic)->p[Y_PLANE].p_pixels +
752
748
                      ( fmt.i_height * (*p_pic)->p[Y_PLANE].i_pitch );
848
844
        video_format_t fmt;
849
845
 
850
846
        memset( &fmt, 0, sizeof(fmt) );
851
 
        fmt.i_chroma = VLC_FOURCC('T','E','X','T');
852
 
        fmt.i_aspect = 0;
 
847
        fmt.i_chroma = VLC_CODEC_TEXT;
853
848
        fmt.i_width  = fmt.i_visible_width = 0;
854
849
        fmt.i_height = fmt.i_visible_height = 0;
855
850
        fmt.i_x_offset = 0;
865
860
            subpicture_region_Delete( p_region );
866
861
            return NULL;
867
862
        }
868
 
        p_region->p_style = p_style;
 
863
        p_region->p_style = text_style_Duplicate( p_style );
869
864
        p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
870
865
 
871
866
        if( p_sys->p_text->pf_render_text )
963
958
    switch( p_sys->var_info.bits_per_pixel )
964
959
    {
965
960
    case 8: /* FIXME: set the palette */
966
 
        p_sys->fmt_out.i_chroma = VLC_FOURCC('R','G','B','2'); break;
 
961
        p_sys->fmt_out.i_chroma = VLC_CODEC_RGB8; break;
967
962
    case 15:
968
 
        p_sys->fmt_out.i_chroma = VLC_FOURCC('R','V','1','5'); break;
 
963
        p_sys->fmt_out.i_chroma = VLC_CODEC_RGB15; break;
969
964
    case 16:
970
 
        p_sys->fmt_out.i_chroma = VLC_FOURCC('R','V','1','6'); break;
 
965
        p_sys->fmt_out.i_chroma = VLC_CODEC_RGB16; break;
971
966
    case 24:
972
 
        p_sys->fmt_out.i_chroma = VLC_FOURCC('R','V','2','4'); break;
 
967
        p_sys->fmt_out.i_chroma = VLC_CODEC_RGB24; break;
973
968
    case 32:
974
 
        p_sys->fmt_out.i_chroma = VLC_FOURCC('R','V','3','2'); break;
 
969
        p_sys->fmt_out.i_chroma = VLC_CODEC_RGB32; break;
975
970
    default:
976
971
        msg_Err( p_intf, "unknown screen depth %i",
977
972
                 p_sys->var_info.bits_per_pixel );
985
980
    /* Assume we have square pixels */
986
981
    if( p_sys->i_aspect < 0 )
987
982
    {
988
 
        p_sys->fmt_out.i_aspect = ( p_sys->i_width
989
 
                                  * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
990
 
    }
991
 
    else p_sys->fmt_out.i_aspect = p_sys->i_aspect;
992
 
 
993
 
    p_sys->fmt_out.i_sar_num = p_sys->fmt_out.i_sar_den = 1;
 
983
        p_sys->fmt_out.i_sar_num = 1;
 
984
        p_sys->fmt_out.i_sar_den = 1;
 
985
    }
 
986
    else
 
987
    {
 
988
        p_sys->fmt_out.i_sar_num = p_sys->i_aspect    * p_sys->i_height;
 
989
        p_sys->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR * p_sys->i_width;
 
990
    }
994
991
 
995
992
    /* Allocate overlay buffer */
996
993
    p_sys->p_overlay = AllocatePicture( &p_sys->fmt_out );
1056
1053
    struct fb_fix_screeninfo    fix_info;     /* framebuffer fix information */
1057
1054
 
1058
1055
    /* Open framebuffer device */
1059
 
    if( !(psz_device = config_GetPsz( p_intf, "fbosd-dev" )) )
 
1056
    if( !(psz_device = var_InheritString( p_intf, "fbosd-dev" )) )
1060
1057
    {
1061
1058
        msg_Err( p_intf, "don't know which fb osd/overlay device to open" );
1062
1059
        return VLC_EGENERIC;
1063
1060
    }
1064
1061
 
1065
 
    p_sys->i_fd = open( psz_device, O_RDWR );
 
1062
    p_sys->i_fd = vlc_open( psz_device, O_RDWR );
1066
1063
    if( p_sys->i_fd == -1 )
1067
1064
    {
1068
 
        msg_Err( p_intf, "cannot open %s (%s)", psz_device, strerror(errno) );
 
1065
        msg_Err( p_intf, "cannot open %s (%m)", psz_device );
1069
1066
        free( psz_device );
1070
1067
        return VLC_EGENERIC;
1071
1068
    }
1074
1071
    /* Get framebuffer device information */
1075
1072
    if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
1076
1073
    {
1077
 
        msg_Err( p_intf, "cannot get fb info (%s)", strerror(errno) );
 
1074
        msg_Err( p_intf, "cannot get fb info (%m)" );
1078
1075
        close( p_sys->i_fd );
1079
1076
        return VLC_EGENERIC;
1080
1077
    }
1194
1191
#if defined(FBOSD_BLENDING)
1195
1192
        video_format_t fmt_in;
1196
1193
        memset( &fmt_in, 0, sizeof(video_format_t) );
1197
 
        p_text = RenderText( p_intf, render->psz_string, &render->text_style,
 
1194
        p_text = RenderText( p_intf, render->psz_string, render->p_text_style,
1198
1195
                             &fmt_in );
1199
1196
        if( p_text )
1200
1197
        {
1204
1201
            DeAllocatePicture( p_text, &fmt_in );
1205
1202
        }
1206
1203
#else
1207
 
        p_text = RenderText( p_intf, render->psz_string, &render->text_style,
 
1204
        p_text = RenderText( p_intf, render->psz_string, render->p_text_style,
1208
1205
                             &p_sys->fmt_out );
1209
1206
        if( p_text )
1210
1207
        {
1220
1217
{
1221
1218
    intf_sys_t *p_sys = p_intf->p_sys;
1222
1219
 
1223
 
    vlc_memcpy( &render->text_style, &default_text_style,
1224
 
                sizeof( text_style_t ) );
 
1220
    text_style_Delete( render->p_text_style );
 
1221
    render->p_text_style = text_style_New();
1225
1222
    free( render->psz_string );
1226
1223
    render->psz_string = NULL;
1227
1224
 
1399
1396
        }
1400
1397
        else if( !strncmp( psz_cmd, "fbosd-font-size", 15 ) )
1401
1398
        {
1402
 
            p_sys->render[i].text_style.i_font_size = newval.i_int;
 
1399
            p_sys->render[i].p_text_style->i_font_size = newval.i_int;
1403
1400
        }
1404
1401
        else if( !strncmp( psz_cmd, "fbosd-font-color", 16 ) )
1405
1402
        {
1406
 
            p_sys->render[i].text_style.i_font_color = newval.i_int;
 
1403
            p_sys->render[i].p_text_style->i_font_color = newval.i_int;
1407
1404
        }
1408
1405
        else if( !strncmp( psz_cmd, "fbosd-font-opacity", 18 ) )
1409
1406
        {
1410
 
            p_sys->render[i].text_style.i_font_alpha = 255 - newval.i_int;
 
1407
            p_sys->render[i].p_text_style->i_font_alpha = 255 - newval.i_int;
1411
1408
        }
1412
1409
        else if( !strncmp( psz_cmd, "fbosd-alpha", 11 ) )
1413
1410
        {