vout_subpictures.c 57.2 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1 2 3
/*****************************************************************************
 * vout_subpictures.c : subpicture management functions
 *****************************************************************************
4
 * Copyright (C) 2000-2007 the VideoLAN team
5
 * $Id$
Sam Hocevar's avatar
 
Sam Hocevar committed
6 7 8
 *
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
9
 *          Gildas Bazin <gbazin@videolan.org>
Sam Hocevar's avatar
 
Sam Hocevar committed
10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Sam Hocevar's avatar
 
Sam Hocevar committed
24 25 26 27 28
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
Clément Stenac's avatar
Clément Stenac committed
34 35 36 37
#include <vlc_vout.h>
#include <vlc_block.h>
#include <vlc_filter.h>
#include <vlc_osd.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
38
#include "../libvlc.h"
39

40
#include <assert.h>
41
#include <limits.h>
42

43 44 45
/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
46 47 48 49 50
#define VLC_FOURCC_YUVP VLC_FOURCC('Y','U','V','P')
#define VLC_FOURCC_YUVA VLC_FOURCC('Y','U','V','A')
#define VLC_FOURCC_RGBA VLC_FOURCC('R','G','B','A')
#define VLC_FOURCC_TEXT VLC_FOURCC('T','E','X','T')

Laurent Aimar's avatar
Laurent Aimar committed
51
/* */
52 53 54 55 56 57 58 59 60 61 62 63
typedef struct
{
    subpicture_t *p_subpicture;
    bool          b_reject;
} spu_heap_entry_t;

typedef struct
{
    spu_heap_entry_t p_entry[VOUT_MAX_SUBPICTURES];

} spu_heap_t;

Laurent Aimar's avatar
Laurent Aimar committed
64 65 66 67 68 69
static void SpuHeapInit( spu_heap_t * );
static int  SpuHeapPush( spu_heap_t *, subpicture_t * );
static void SpuHeapDeleteAt( spu_heap_t *, int i_index );
static int  SpuHeapDeleteSubpicture( spu_heap_t *, subpicture_t * );
static void SpuHeapClean( spu_heap_t *p_heap );

70 71
struct spu_private_t
{
72 73 74 75
    vlc_mutex_t lock;   /* lock to protect all followings fields */

    spu_heap_t heap;

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    int i_channel;             /**< number of subpicture channels registered */
    filter_t *p_blend;                            /**< alpha blending module */
    filter_t *p_text;                              /**< text renderer module */
    filter_t *p_scale_yuvp;                     /**< scaling module for YUVP */
    filter_t *p_scale;                    /**< scaling module (all but YUVP) */
    bool b_force_crop;                     /**< force cropping of subpicture */
    int i_crop_x, i_crop_y, i_crop_width, i_crop_height;       /**< cropping */

    int i_margin;                        /**< force position of a subpicture */
    bool b_force_palette;             /**< force palette of subpicture */
    uint8_t palette[4][4];                               /**< forced palette */

    /* Supciture filters */
    filter_chain_t *p_chain;
};

92 93 94 95 96 97
/* */
struct subpicture_region_private_t
{
    video_format_t fmt;
    picture_t      *p_picture;
};
Laurent Aimar's avatar
Laurent Aimar committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
static subpicture_region_private_t *SpuRegionPrivateNew( video_format_t * );
static void SpuRegionPrivateDelete( subpicture_region_private_t * );

/* */
typedef struct
{
    int w;
    int h;
} spu_scale_t;
static spu_scale_t spu_scale_create( int w, int h );
static spu_scale_t spu_scale_unit(void );
static spu_scale_t spu_scale_createq( int wn, int wd, int hn, int hd );
static int spu_scale_w( int v, const spu_scale_t s );
static int spu_scale_h( int v, const spu_scale_t s );
static int spu_invscale_w( int v, const spu_scale_t s );
static int spu_invscale_h( int v, const spu_scale_t s );

typedef struct
{
    int i_x;
    int i_y;
    int i_width;
    int i_height;

    spu_scale_t scale;
} spu_area_t;

static spu_area_t spu_area_create( int x, int y, int w, int h, spu_scale_t );
static spu_area_t spu_area_scaled( spu_area_t );
static spu_area_t spu_area_unscaled( spu_area_t, spu_scale_t );
static bool spu_area_overlap( spu_area_t, spu_area_t );

130

131 132 133
/* Subpicture rendered flag
 * FIXME ? it could be moved to private ? */
#define SUBPICTURE_RENDERED  (0x1000)
Laurent Aimar's avatar
Laurent Aimar committed
134
#if SUBPICTURE_RENDERED < SUBPICTURE_ALIGN_MASK
135 136 137
#   error SUBPICTURE_RENDERED too low
#endif

Laurent Aimar's avatar
Laurent Aimar committed
138 139
#define SCALE_UNIT (1000)

140
static void SubpictureChain( subpicture_t **pp_head, subpicture_t *p_subpic );
Laurent Aimar's avatar
Laurent Aimar committed
141 142 143 144 145 146 147 148
static int SubpictureCmp( const void *s0, const void *s1 );

static void SpuRenderRegion( spu_t *,
                             picture_t *p_pic_dst, spu_area_t *,
                             subpicture_t *, subpicture_region_t *,
                             const spu_scale_t scale_size,
                             const video_format_t *p_fmt,
                             const spu_area_t *p_subtitle_area, int i_subtitle_area );
149

150 151 152
static void UpdateSPU   ( spu_t *, vlc_object_t * );
static int  CropCallback( vlc_object_t *, char const *,
                          vlc_value_t, vlc_value_t, void * );
153

154
static int SpuControl( spu_t *, int, va_list );
155

156 157 158
static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked );

/* Buffer allocation for SPU filter (blend, scale, ...) */
159 160
static subpicture_t *spu_new_buffer( filter_t * );
static void spu_del_buffer( filter_t *, subpicture_t * );
161 162
static picture_t *spu_new_video_buffer( filter_t * );
static void spu_del_video_buffer( filter_t *, picture_t * );
163

164
static int spu_ParseChain( spu_t * );
165 166

/* Buffer aloccation fir SUB filter */
167 168 169
static int SubFilterCallback( vlc_object_t *, char const *,
                              vlc_value_t, vlc_value_t, void * );

170 171
static int SubFilterAllocationInit( filter_t *, void * );
static void SubFilterAllocationClean( filter_t * );
172

173
/* */
Laurent Aimar's avatar
Laurent Aimar committed
174 175 176
static void SpuRenderCreateAndLoadText( spu_t * );
static void SpuRenderCreateAndLoadScale( spu_t * );
static void SpuRenderCreateBlend( spu_t *, vlc_fourcc_t i_chroma, int i_aspect );
177
static void FilterRelease( filter_t *p_filter );
178

Laurent Aimar's avatar
Laurent Aimar committed
179 180 181
/*****************************************************************************
 * Public API
 *****************************************************************************/
182
/**
183
 * Creates the subpicture unit
184
 *
185
 * \param p_this the parent object which creates the subpicture unit
186
 */
187
spu_t *__spu_Create( vlc_object_t *p_this )
188
{
189 190 191 192 193 194 195 196 197 198 199 200 201 202
    spu_t *p_spu;
    spu_private_t *p_sys;
    
    p_spu = vlc_custom_create( p_this, sizeof(spu_t) + sizeof(spu_private_t),
                               VLC_OBJECT_GENERIC, "subpicture" );

    if( !p_spu )
        return NULL;

    /* Initialize spu fields */
    p_spu->pf_control = SpuControl;
    p_spu->p = p_sys = (spu_private_t*)&p_spu[1];

    /* Initialize private fields */
203 204 205 206
    vlc_mutex_init( &p_sys->lock );

    SpuHeapInit( &p_sys->heap );

207 208 209 210
    p_sys->p_blend = NULL;
    p_sys->p_text = NULL;
    p_sys->p_scale = NULL;
    p_sys->p_scale_yuvp = NULL;
211 212

    /* Register the default subpicture channel */
213
    p_sys->i_channel = 2;
214 215 216

    vlc_object_attach( p_spu, p_this );

217
    p_sys->p_chain = filter_chain_New( p_spu, "sub filter", false,
218 219
                                       SubFilterAllocationInit,
                                       SubFilterAllocationClean,
220
                                       p_spu );
221 222 223 224 225

    /* Load text and scale module */
    SpuRenderCreateAndLoadText( p_spu );
    SpuRenderCreateAndLoadScale( p_spu );

226 227 228 229 230 231 232 233 234 235
    return p_spu;
}

/**
 * Initialise the subpicture unit
 *
 * \param p_spu the subpicture unit object
 */
int spu_Init( spu_t *p_spu )
{
236
    spu_private_t *p_sys = p_spu->p;
237

238
    /* If the user requested a sub margin, we force the position. */
239
    p_sys->i_margin = var_CreateGetInteger( p_spu, "sub-margin" );
240 241

    var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
242 243 244 245
    var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );

    spu_ParseChain( p_spu );

246
    return VLC_SUCCESS;
247
}
Antoine Cellerier's avatar
 
Antoine Cellerier committed
248

249 250
int spu_ParseChain( spu_t *p_spu )
{
251
    char *psz_parser = var_GetString( p_spu, "sub-filter" );
252 253 254
    int i_ret;

    if( !psz_parser )
255
        return VLC_EGENERIC;
256 257

    i_ret = filter_chain_AppendFromString( p_spu->p->p_chain, psz_parser );
258

259
    free( psz_parser );
260 261

    return i_ret;
262 263 264
}

/**
265
 * Destroy the subpicture unit
266
 *
267
 * \param p_this the parent object which destroys the subpicture unit
268
 */
269
void spu_Destroy( spu_t *p_spu )
270
{
271
    spu_private_t *p_sys = p_spu->p;
272

273 274 275 276 277
    if( p_sys->p_blend )
        FilterRelease( p_sys->p_blend );

    if( p_sys->p_text )
        FilterRelease( p_sys->p_text );
278

279 280
    if( p_sys->p_scale_yuvp )
        FilterRelease( p_sys->p_scale_yuvp );
281

282 283
    if( p_sys->p_scale )
        FilterRelease( p_sys->p_scale );
284

285
    filter_chain_Delete( p_sys->p_chain );
286

287 288 289 290
    /* Destroy all remaining subpictures */
    SpuHeapClean( &p_sys->heap );

    vlc_mutex_destroy( &p_sys->lock );
291

292
    vlc_object_release( p_spu );
293 294
}

295 296 297
/**
 * Attach/Detach the SPU from any input
 *
298
 * \param p_this the object in which to destroy the subpicture unit
299 300
 * \param b_attach to select attach or detach
 */
301
void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
302 303 304
{
    vlc_object_t *p_input;

305
    p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
306 307 308
    if( !p_input ) return;

    if( b_attach )
309
    {
310 311
        UpdateSPU( p_spu, VLC_OBJECT(p_input) );
        var_AddCallback( p_input, "highlight", CropCallback, p_spu );
312 313 314 315 316
        vlc_object_release( p_input );
    }
    else
    {
        /* Delete callback */
317
        var_DelCallback( p_input, "highlight", CropCallback, p_spu );
318 319 320 321
        vlc_object_release( p_input );
    }
}

322
/**
323
 * Display a subpicture
324
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
325 326
 * Remove the reservation flag of a subpicture, which will cause it to be
 * ready for display.
327
 * \param p_spu the subpicture unit object
328 329
 * \param p_subpic the subpicture to display
 */
330
void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
Sam Hocevar's avatar
 
Sam Hocevar committed
331
{
332
    spu_private_t *p_sys = p_spu->p;
Sam Hocevar's avatar
 
Sam Hocevar committed
333

334
    /* DEFAULT_CHAN always reset itself */
335
    if( p_subpic->i_channel == DEFAULT_CHAN )
336 337 338 339 340 341 342 343 344
        SpuClearChannel( p_spu, DEFAULT_CHAN, false );

    /* p_private is for spu only and cannot be non NULL here */
    for( subpicture_region_t *r = p_subpic->p_region; r != NULL; r = r->p_next )
        assert( r->p_private == NULL );

    /* */
    vlc_mutex_lock( &p_sys->lock );
    if( SpuHeapPush( &p_sys->heap, p_subpic ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
345
    {
346 347 348 349
        vlc_mutex_unlock( &p_sys->lock );
        msg_Err( p_spu, "subpicture heap full" );
        subpicture_Delete( p_subpic );
        return;
Sam Hocevar's avatar
 
Sam Hocevar committed
350
    }
351
    vlc_mutex_unlock( &p_sys->lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
352 353
}

Laurent Aimar's avatar
Laurent Aimar committed
354 355 356 357 358 359 360
/**
 * This function renders all sub picture units in the list.
 */
void spu_RenderSubpictures( spu_t *p_spu,
                            picture_t *p_pic_dst, const video_format_t *p_fmt_dst,
                            subpicture_t *p_subpic_list,
                            const video_format_t *p_fmt_src )
361
{
Laurent Aimar's avatar
Laurent Aimar committed
362
    spu_private_t *p_sys = p_spu->p;
363

Laurent Aimar's avatar
Laurent Aimar committed
364 365 366
    const int i_source_video_width  = p_fmt_src->i_width;
    const int i_source_video_height = p_fmt_src->i_height;
    const mtime_t i_current_date = mdate();
367

Laurent Aimar's avatar
Laurent Aimar committed
368 369
    unsigned int i_subpicture;
    subpicture_t *pp_subpicture[VOUT_MAX_SUBPICTURES];
370

Laurent Aimar's avatar
Laurent Aimar committed
371 372 373 374
    unsigned int i_subtitle_region_count;
    spu_area_t p_subtitle_area_buffer[VOUT_MAX_SUBPICTURES];
    spu_area_t *p_subtitle_area;
    int i_subtitle_area;
375

Laurent Aimar's avatar
Laurent Aimar committed
376
    vlc_mutex_lock( &p_sys->lock );
377

Laurent Aimar's avatar
Laurent Aimar committed
378 379 380 381 382 383 384 385 386 387
    /* Preprocess subpictures */
    i_subpicture = 0;
    i_subtitle_region_count = 0;
    for( subpicture_t * p_subpic = p_subpic_list;
            p_subpic != NULL;
                p_subpic = p_subpic->p_next )
    {
        /* */
        if( p_subpic->pf_pre_render )
            p_subpic->pf_pre_render( p_spu, p_subpic, p_fmt_dst );
388

Laurent Aimar's avatar
Laurent Aimar committed
389 390 391 392 393 394 395
        if( p_subpic->pf_update_regions )
        {
            video_format_t fmt_org = *p_fmt_dst;
            fmt_org.i_width =
            fmt_org.i_visible_width = i_source_video_width;
            fmt_org.i_height =
            fmt_org.i_visible_height = i_source_video_height;
396

Laurent Aimar's avatar
Laurent Aimar committed
397 398
            p_subpic->pf_update_regions( p_spu, p_subpic, &fmt_org, i_current_date );
        }
399

Laurent Aimar's avatar
Laurent Aimar committed
400 401 402 403 404 405
        /* */
        if( p_subpic->b_subtitle )
        {
            for( subpicture_region_t *r = p_subpic->p_region; r != NULL; r = r->p_next )
                i_subtitle_region_count++;
        }
406

Laurent Aimar's avatar
Laurent Aimar committed
407 408 409
        /* */
        pp_subpicture[i_subpicture++] = p_subpic;
    }
410

Laurent Aimar's avatar
Laurent Aimar committed
411 412
    /* Be sure we have at least 1 picture to process */
    if( i_subpicture <= 0 )
413
    {
Laurent Aimar's avatar
Laurent Aimar committed
414 415
        vlc_mutex_unlock( &p_sys->lock );
        return;
416 417
    }

Laurent Aimar's avatar
Laurent Aimar committed
418 419 420
    /* Now order subpicture array
     * XXX The order is *really* important for overlap subtitles positionning */
    qsort( pp_subpicture, i_subpicture, sizeof(*pp_subpicture), SubpictureCmp );
Laurent Aimar's avatar
Laurent Aimar committed
421

Laurent Aimar's avatar
Laurent Aimar committed
422 423 424 425 426
    /* Allocate area array for subtitle overlap */
    i_subtitle_area = 0;
    p_subtitle_area = p_subtitle_area_buffer;
    if( i_subtitle_region_count > sizeof(p_subtitle_area_buffer)/sizeof(*p_subtitle_area_buffer) )
        p_subtitle_area = calloc( i_subtitle_region_count, sizeof(*p_subtitle_area) );
427

Laurent Aimar's avatar
Laurent Aimar committed
428 429 430
    /* Create the blending module */
    if( !p_sys->p_blend )
        SpuRenderCreateBlend( p_spu, p_fmt_dst->i_chroma, p_fmt_dst->i_aspect );
431

Laurent Aimar's avatar
Laurent Aimar committed
432 433 434 435 436
    /* Process all subpictures and regions (in the right order) */
    for( unsigned int i_index = 0; i_index < i_subpicture; i_index++ )
    {
        subpicture_t *p_subpic = pp_subpicture[i_index];
        subpicture_region_t *p_region;
437

Laurent Aimar's avatar
Laurent Aimar committed
438 439
        if( !p_subpic->p_region )
            continue;
440

Laurent Aimar's avatar
Laurent Aimar committed
441 442 443 444 445 446 447 448 449
        /* FIXME when possible use a better rendering size than source size
         * (max of display size and source size for example) FIXME */
        int i_render_width  = p_subpic->i_original_picture_width;
        int i_render_height = p_subpic->i_original_picture_height;
        if( !i_render_width || !i_render_height )
        {
            if( i_render_width != 0 || i_render_height != 0 )
                msg_Err( p_spu, "unsupported original picture size %dx%d",
                         i_render_width, i_render_height );
450

Laurent Aimar's avatar
Laurent Aimar committed
451 452 453
            p_subpic->i_original_picture_width  = i_render_width = i_source_video_width;
            p_subpic->i_original_picture_height = i_render_height = i_source_video_height;
        }
454

Laurent Aimar's avatar
Laurent Aimar committed
455 456 457 458
        if( p_sys->p_text )
        {
            p_sys->p_text->fmt_out.video.i_width          =
            p_sys->p_text->fmt_out.video.i_visible_width  = i_render_width;
459

Laurent Aimar's avatar
Laurent Aimar committed
460 461 462
            p_sys->p_text->fmt_out.video.i_height         =
            p_sys->p_text->fmt_out.video.i_visible_height = i_render_height;
        }
463

Laurent Aimar's avatar
Laurent Aimar committed
464 465 466
        /* Compute scaling from picture to source size */
        spu_scale_t scale = spu_scale_createq( i_source_video_width,  i_render_width,
                                               i_source_video_height, i_render_height );
467

Laurent Aimar's avatar
Laurent Aimar committed
468 469 470
        /* Update scaling from source size to display size(p_fmt_dst) */
        scale.w = scale.w * p_fmt_dst->i_width  / i_source_video_width;
        scale.h = scale.h * p_fmt_dst->i_height / i_source_video_height;
471

Laurent Aimar's avatar
Laurent Aimar committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
        /* Set default subpicture aspect ratio
         * FIXME if we only handle 1 aspect ratio per picture, why is it set per
         * region ? */
        p_region = p_subpic->p_region;
        if( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den )
        {
            if( p_region->fmt.i_aspect != 0 )
            {
                p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
                p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
            }
            else
            {
                p_region->fmt.i_sar_den = p_fmt_dst->i_sar_den;
                p_region->fmt.i_sar_num = p_fmt_dst->i_sar_num;
            }
        }
489

Laurent Aimar's avatar
Laurent Aimar committed
490 491 492 493 494 495 496 497 498
        /* Take care of the aspect ratio */
        if( p_region->fmt.i_sar_num * p_fmt_dst->i_sar_den !=
            p_region->fmt.i_sar_den * p_fmt_dst->i_sar_num )
        {
            /* FIXME FIXME what about region->i_x/i_y ? */
            scale.w = scale.w *
                (int64_t)p_region->fmt.i_sar_num * p_fmt_dst->i_sar_den /
                p_region->fmt.i_sar_den / p_fmt_dst->i_sar_num;
        }
499

Laurent Aimar's avatar
Laurent Aimar committed
500 501 502 503 504 505 506
        /* Render all regions
         * We always transform non absolute subtitle into absolute one on the
         * first rendering to allow good subtitle overlap support.
         */
        for( p_region = p_subpic->p_region; p_region != NULL; p_region = p_region->p_next )
        {
            spu_area_t area;
507

Laurent Aimar's avatar
Laurent Aimar committed
508 509 510
            /* Check scale validity */
            if( scale.w <= 0 || scale.h <= 0 )
                continue;
511

Laurent Aimar's avatar
Laurent Aimar committed
512 513 514 515
            /* */
            SpuRenderRegion( p_spu, p_pic_dst, &area,
                             p_subpic, p_region, scale, p_fmt_dst,
                             p_subtitle_area, i_subtitle_area );
516

Laurent Aimar's avatar
Laurent Aimar committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
            if( p_subpic->b_subtitle )
            {
                area = spu_area_unscaled( area, scale );
                if( !p_subpic->b_absolute && area.i_width > 0 && area.i_height > 0 )
                {
                    p_region->i_x = area.i_x;
                    p_region->i_y = area.i_y;
                }
                if( p_subtitle_area )
                    p_subtitle_area[i_subtitle_area++] = area;
            }
        }
        if( p_subpic->b_subtitle )
            p_subpic->b_absolute = true;
    }
532

Laurent Aimar's avatar
Laurent Aimar committed
533 534 535
    /* */
    if( p_subtitle_area != p_subtitle_area_buffer )
        free( p_subtitle_area );
536

Laurent Aimar's avatar
Laurent Aimar committed
537
    vlc_mutex_unlock( &p_sys->lock );
538 539
}

Laurent Aimar's avatar
Laurent Aimar committed
540 541 542 543 544 545 546 547 548 549 550 551
/*****************************************************************************
 * spu_SortSubpictures: find the subpictures to display
 *****************************************************************************
 * This function parses all subpictures and decides which ones need to be
 * displayed. If no picture has been selected, display_date will depend on
 * the subpicture.
 * We also check for ephemer DVD subpictures (subpictures that have
 * to be removed if a newer one is available), which makes it a lot
 * more difficult to guess if a subpicture has to be rendered or not.
 *****************************************************************************/
subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
                                   bool b_paused, bool b_subtitle_only )
Laurent Aimar's avatar
Laurent Aimar committed
552
{
Laurent Aimar's avatar
Laurent Aimar committed
553 554 555
    spu_private_t *p_sys = p_spu->p;
    int i_channel;
    subpicture_t *p_subpic = NULL;
556

Laurent Aimar's avatar
Laurent Aimar committed
557 558
    /* Run subpicture filters */
    filter_chain_SubFilter( p_sys->p_chain, display_date );
Laurent Aimar's avatar
Laurent Aimar committed
559

Laurent Aimar's avatar
Laurent Aimar committed
560
    vlc_mutex_lock( &p_sys->lock );
Laurent Aimar's avatar
Laurent Aimar committed
561

Laurent Aimar's avatar
Laurent Aimar committed
562 563 564
    /* We get an easily parsable chained list of subpictures which
     * ends with NULL since p_subpic was initialized to NULL. */
    for( i_channel = 0; i_channel < p_sys->i_channel; i_channel++ )
Laurent Aimar's avatar
Laurent Aimar committed
565
    {
Laurent Aimar's avatar
Laurent Aimar committed
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
        subpicture_t *p_ephemer = NULL;
        mtime_t      ephemer_date = 0;
        int i_index;

        for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
        {
            spu_heap_entry_t *p_entry = &p_sys->heap.p_entry[i_index];
            subpicture_t *p_current = p_entry->p_subpicture;

            if( !p_current || p_entry->b_reject )
            {
                if( p_entry->b_reject )
                    SpuHeapDeleteAt( &p_sys->heap, i_index );
                continue;
            }

            if( p_current->i_channel != i_channel ||
                ( b_subtitle_only && !p_current->b_subtitle ) )
            {
                continue;
            }
            if( display_date &&
                display_date < p_current->i_start )
            {
                /* Too early, come back next monday */
                continue;
            }

            if( p_current->i_start > ephemer_date )
                ephemer_date = p_current->i_start;

            if( display_date > p_current->i_stop &&
                ( !p_current->b_ephemer || p_current->i_stop > p_current->i_start ) &&
                !( p_current->b_subtitle && b_paused ) ) /* XXX Assume that subtitle are pausable */
            {
                SpuHeapDeleteAt( &p_sys->heap, i_index );
            }
            else if( p_current->b_ephemer )
            {
                SubpictureChain( &p_ephemer, p_current );
            }
            else
            {
                SubpictureChain( &p_subpic, p_current );
            }
        }

        /* If we found ephemer subpictures, check if they have to be
         * displayed or destroyed */
        while( p_ephemer != NULL )
        {
            subpicture_t *p_tmp = p_ephemer;
            p_ephemer = p_ephemer->p_next;

            if( p_tmp->i_start < ephemer_date )
            {
                SpuHeapDeleteSubpicture( &p_sys->heap, p_tmp );
            }
            else
            {
                SubpictureChain( &p_subpic, p_tmp );
            }
        }
Laurent Aimar's avatar
Laurent Aimar committed
629
    }
Laurent Aimar's avatar
Laurent Aimar committed
630
    vlc_mutex_unlock( &p_sys->lock );
Laurent Aimar's avatar
Laurent Aimar committed
631

Laurent Aimar's avatar
Laurent Aimar committed
632
    return p_subpic;
Laurent Aimar's avatar
Laurent Aimar committed
633 634
}

Laurent Aimar's avatar
Laurent Aimar committed
635 636 637
/*****************************************************************************
 * subpicture_t allocation
 *****************************************************************************/
638
subpicture_t *subpicture_New( void )
639
{
Laurent Aimar's avatar
Laurent Aimar committed
640 641 642
    subpicture_t *p_subpic = calloc( 1, sizeof(*p_subpic) );
    if( !p_subpic )
        return NULL;
643

Laurent Aimar's avatar
Laurent Aimar committed
644 645 646 647 648 649 650 651 652 653 654
    p_subpic->i_order    = 0;
    p_subpic->b_absolute = true;
    p_subpic->b_fade     = false;
    p_subpic->b_subtitle = false;
    p_subpic->i_alpha    = 0xFF;
    p_subpic->p_region   = NULL;
    p_subpic->pf_render  = NULL;
    p_subpic->pf_destroy = NULL;
    p_subpic->p_sys      = NULL;

    return p_subpic;
655
}
Laurent Aimar's avatar
Laurent Aimar committed
656

657
void subpicture_Delete( subpicture_t *p_subpic )
658
{
Laurent Aimar's avatar
Laurent Aimar committed
659 660 661 662 663 664 665 666
    subpicture_region_ChainDelete( p_subpic->p_region );
    p_subpic->p_region = NULL;

    if( p_subpic->pf_destroy )
    {
        p_subpic->pf_destroy( p_subpic );
    }
    free( p_subpic );
667
}
Laurent Aimar's avatar
Laurent Aimar committed
668 669

static void SubpictureChain( subpicture_t **pp_head, subpicture_t *p_subpic )
670
{
Laurent Aimar's avatar
Laurent Aimar committed
671 672 673
    p_subpic->p_next = *pp_head;

    *pp_head = p_subpic;
674
}
Laurent Aimar's avatar
Laurent Aimar committed
675 676 677 678 679

/*****************************************************************************
 * subpicture_region_t allocation
 *****************************************************************************/
subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
680
{
Laurent Aimar's avatar
Laurent Aimar committed
681 682 683
    subpicture_region_t *p_region = calloc( 1, sizeof(*p_region ) );
    if( !p_region )
        return NULL;
684

Laurent Aimar's avatar
Laurent Aimar committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698
    p_region->fmt = *p_fmt;
    p_region->fmt.p_palette = NULL;
    if( p_fmt->i_chroma == VLC_FOURCC_YUVP )
    {
        p_region->fmt.p_palette = calloc( 1, sizeof(*p_region->fmt.p_palette) );
        if( p_fmt->p_palette )
            *p_region->fmt.p_palette = *p_fmt->p_palette;
    }
    p_region->i_alpha = 0xff;
    p_region->p_next = NULL;
    p_region->p_private = NULL;
    p_region->psz_text = NULL;
    p_region->p_style = NULL;
    p_region->p_picture = NULL;
699

Laurent Aimar's avatar
Laurent Aimar committed
700 701
    if( p_fmt->i_chroma == VLC_FOURCC_TEXT )
        return p_region;
702

Laurent Aimar's avatar
Laurent Aimar committed
703 704 705 706 707 708 709 710
    p_region->p_picture = picture_New( p_fmt->i_chroma, p_fmt->i_width, p_fmt->i_height,
                                       p_fmt->i_aspect );
    if( !p_region->p_picture )
    {
        free( p_fmt->p_palette );
        free( p_region );
        return NULL;
    }
711

Laurent Aimar's avatar
Laurent Aimar committed
712
    return p_region;
713
}
Laurent Aimar's avatar
Laurent Aimar committed
714 715 716

/* */
void subpicture_region_Delete( subpicture_region_t *p_region )
717
{
Laurent Aimar's avatar
Laurent Aimar committed
718 719
    if( !p_region )
        return;
720

Laurent Aimar's avatar
Laurent Aimar committed
721 722
    if( p_region->p_private )
        SpuRegionPrivateDelete( p_region->p_private );
723

Laurent Aimar's avatar
Laurent Aimar committed
724 725
    if( p_region->p_picture )
        picture_Release( p_region->p_picture );
726

Laurent Aimar's avatar
Laurent Aimar committed
727 728 729 730 731 732
    free( p_region->fmt.p_palette );

    free( p_region->psz_text );
    free( p_region->psz_html );
    //free( p_region->p_style ); FIXME --fenrir plugin does not allocate the memory for it. I think it might lead to segfault, video renderer can live longer than the decoder
    free( p_region );
733 734
}

Laurent Aimar's avatar
Laurent Aimar committed
735 736 737 738 739 740
/* */
void subpicture_region_ChainDelete( subpicture_region_t *p_head )
{
    while( p_head )
    {
        subpicture_region_t *p_next = p_head->p_next;
741

Laurent Aimar's avatar
Laurent Aimar committed
742
        subpicture_region_Delete( p_head );
743

Laurent Aimar's avatar
Laurent Aimar committed
744 745
        p_head = p_next;
    }
746 747 748 749
}



Laurent Aimar's avatar
Laurent Aimar committed
750 751 752 753
/*****************************************************************************
 * heap managment
 *****************************************************************************/
static void SpuHeapInit( spu_heap_t *p_heap )
754
{
Laurent Aimar's avatar
Laurent Aimar committed
755 756 757
    for( int i = 0; i < VOUT_MAX_SUBPICTURES; i++ )
    {
        spu_heap_entry_t *e = &p_heap->p_entry[i];
758

Laurent Aimar's avatar
Laurent Aimar committed
759 760 761 762
        e->p_subpicture = NULL;
        e->b_reject = false;
    }
}
763

Laurent Aimar's avatar
Laurent Aimar committed
764 765 766
static int SpuHeapPush( spu_heap_t *p_heap, subpicture_t *p_subpic )
{
    for( int i = 0; i < VOUT_MAX_SUBPICTURES; i++ )
767
    {
Laurent Aimar's avatar
Laurent Aimar committed
768
        spu_heap_entry_t *e = &p_heap->p_entry[i];
769

Laurent Aimar's avatar
Laurent Aimar committed
770 771
        if( e->p_subpicture )
            continue;
772

Laurent Aimar's avatar
Laurent Aimar committed
773 774 775 776 777 778
        e->p_subpicture = p_subpic;
        e->b_reject = false;
        return VLC_SUCCESS;
    }
    return VLC_EGENERIC;
}
779

Laurent Aimar's avatar
Laurent Aimar committed
780 781 782
static void SpuHeapDeleteAt( spu_heap_t *p_heap, int i_index )
{
    spu_heap_entry_t *e = &p_heap->p_entry[i_index];
783

Laurent Aimar's avatar
Laurent Aimar committed
784 785
    if( e->p_subpicture )
        subpicture_Delete( e->p_subpicture );
786

Laurent Aimar's avatar
Laurent Aimar committed
787 788
    e->p_subpicture = NULL;
}
789

Laurent Aimar's avatar
Laurent Aimar committed
790
static int SpuHeapDeleteSubpicture( spu_heap_t *p_heap, subpicture_t *p_subpic )
Laurent Aimar's avatar
Laurent Aimar committed
791
{
Laurent Aimar's avatar
Laurent Aimar committed
792
    for( int i = 0; i < VOUT_MAX_SUBPICTURES; i++ )
Laurent Aimar's avatar
Laurent Aimar committed
793
    {
Laurent Aimar's avatar
Laurent Aimar committed
794
        spu_heap_entry_t *e = &p_heap->p_entry[i];
Laurent Aimar's avatar
Laurent Aimar committed
795

Laurent Aimar's avatar
Laurent Aimar committed
796 797 798 799 800
        if( e->p_subpicture != p_subpic )
            continue;

        SpuHeapDeleteAt( p_heap, i );
        return VLC_SUCCESS;
Laurent Aimar's avatar
Laurent Aimar committed
801
    }
Laurent Aimar's avatar
Laurent Aimar committed
802 803
    return VLC_EGENERIC;
}
Laurent Aimar's avatar
Laurent Aimar committed
804

Laurent Aimar's avatar
Laurent Aimar committed
805 806 807
static void SpuHeapClean( spu_heap_t *p_heap )
{
    for( int i = 0; i < VOUT_MAX_SUBPICTURES; i++ )
Laurent Aimar's avatar
Laurent Aimar committed
808
    {
Laurent Aimar's avatar
Laurent Aimar committed
809 810 811
        spu_heap_entry_t *e = &p_heap->p_entry[i];
        if( e->p_subpicture )
            subpicture_Delete( e->p_subpicture );
Laurent Aimar's avatar
Laurent Aimar committed
812
    }
Laurent Aimar's avatar
Laurent Aimar committed
813
}
814

Laurent Aimar's avatar
Laurent Aimar committed
815 816 817
static subpicture_region_private_t *SpuRegionPrivateNew( video_format_t *p_fmt )
{
    subpicture_region_private_t *p_private = malloc( sizeof(*p_private) );
818

Laurent Aimar's avatar
Laurent Aimar committed
819 820
    if( !p_private )
        return NULL;
821

Laurent Aimar's avatar
Laurent Aimar committed
822 823 824 825 826 827 828 829
    p_private->fmt = *p_fmt;
    if( p_fmt->p_palette )
    {
        p_private->fmt.p_palette = malloc( sizeof(*p_private->fmt.p_palette) );
        if( p_private->fmt.p_palette )
            *p_private->fmt.p_palette = *p_fmt->p_palette;
    }
    p_private->p_picture = NULL;
Laurent Aimar's avatar
Laurent Aimar committed
830

Laurent Aimar's avatar
Laurent Aimar committed
831 832 833 834 835 836 837 838
    return p_private;
}
static void SpuRegionPrivateDelete( subpicture_region_private_t *p_private )
{
    if( p_private->p_picture )
        picture_Release( p_private->p_picture );
    free( p_private->fmt.p_palette );
    free( p_private );
Laurent Aimar's avatar
Laurent Aimar committed
839 840
}

Laurent Aimar's avatar
Laurent Aimar committed
841
static void FilterRelease( filter_t *p_filter )
842
{
Laurent Aimar's avatar
Laurent Aimar committed
843 844
    if( p_filter->p_module )
        module_unneed( p_filter, p_filter->p_module );
845

Laurent Aimar's avatar
Laurent Aimar committed
846 847
    vlc_object_detach( p_filter );
    vlc_object_release( p_filter );
848 849
}

Laurent Aimar's avatar
Laurent Aimar committed
850
static void SpuRenderCreateBlend( spu_t *p_spu, vlc_fourcc_t i_chroma, int i_aspect )
Laurent Aimar's avatar
Laurent Aimar committed
851
{
Laurent Aimar's avatar
Laurent Aimar committed
852
    filter_t *p_blend;
853

Laurent Aimar's avatar
Laurent Aimar committed
854
    assert( !p_spu->p->p_blend );
Laurent Aimar's avatar
Laurent Aimar committed
855

Laurent Aimar's avatar
Laurent Aimar committed
856 857 858 859 860
    p_spu->p->p_blend =
    p_blend        = vlc_custom_create( p_spu, sizeof(filter_t),
                                        VLC_OBJECT_GENERIC, "blend" );
    if( !p_blend )
        return;
861

Laurent Aimar's avatar
Laurent Aimar committed
862
    es_format_Init( &p_blend->fmt_in, VIDEO_ES, 0 );
863

Laurent Aimar's avatar
Laurent Aimar committed
864 865 866 867 868
    es_format_Init( &p_blend->fmt_out, VIDEO_ES, 0 );
    p_blend->fmt_out.video.i_x_offset = 0;
    p_blend->fmt_out.video.i_y_offset = 0;
    p_blend->fmt_out.video.i_chroma = i_chroma;
    p_blend->fmt_out.video.i_aspect = i_aspect;
Laurent Aimar's avatar
Laurent Aimar committed
869

Laurent Aimar's avatar
Laurent Aimar committed
870 871 872
    /* The blend module will be loaded when needed with the real
    * input format */
    p_blend->p_module = NULL;
Laurent Aimar's avatar
Laurent Aimar committed
873

Laurent Aimar's avatar
Laurent Aimar committed
874 875 876 877 878 879 880
    /* */
    vlc_object_attach( p_blend, p_spu );
}
static void SpuRenderUpdateBlend( spu_t *p_spu, int i_out_width, int i_out_height,
                                  const video_format_t *p_in_fmt )
{
    filter_t *p_blend = p_spu->p->p_blend;
881

Laurent Aimar's avatar
Laurent Aimar committed
882
    assert( p_blend );
883

Laurent Aimar's avatar
Laurent Aimar committed
884 885
    /* */
    if( p_blend->p_module && p_blend->fmt_in.video.i_chroma != p_in_fmt->i_chroma )
886
    {
Laurent Aimar's avatar
Laurent Aimar committed
887 888 889 890
        /* The chroma is not the same, we need to reload the blend module
         * XXX to match the old behaviour just test !p_blend->fmt_in.video.i_chroma */
        module_unneed( p_blend, p_blend->p_module );
        p_blend->p_module = NULL;
891
    }
892

893
    /* */
Laurent Aimar's avatar
Laurent Aimar committed
894
    p_blend->fmt_in.video = *p_in_fmt;
895

Laurent Aimar's avatar
Laurent Aimar committed
896 897 898 899 900
    /* */
    p_blend->fmt_out.video.i_width =
    p_blend->fmt_out.video.i_visible_width = i_out_width;
    p_blend->fmt_out.video.i_height =
    p_blend->fmt_out.video.i_visible_height = i_out_height;
Laurent Aimar's avatar
Laurent Aimar committed
901

902
    /* */
Laurent Aimar's avatar
Laurent Aimar committed
903 904 905 906 907 908
    if( !p_blend->p_module )
        p_blend->p_module = module_need( p_blend, "video blending", 0, 0 );
}
static void SpuRenderCreateAndLoadText( spu_t *p_spu )
{
    filter_t *p_text;
909

Laurent Aimar's avatar
Laurent Aimar committed
910
    assert( !p_spu->p->p_text );
911

Laurent Aimar's avatar
Laurent Aimar committed
912 913 914 915 916
    p_spu->p->p_text =
    p_text        = vlc_custom_create( p_spu, sizeof(filter_t),
                                       VLC_OBJECT_GENERIC, "spu text" );
    if( !p_text )
        return;
Laurent Aimar's avatar
Laurent Aimar committed
917

Laurent Aimar's avatar
Laurent Aimar committed
918
    es_format_Init( &p_text->fmt_in, VIDEO_ES, 0 );
919

Laurent Aimar's avatar
Laurent Aimar committed
920 921 922 923 924
    es_format_Init( &p_text->fmt_out, VIDEO_ES, 0 );
    p_text->fmt_out.video.i_width =
    p_text->fmt_out.video.i_visible_width = 32;
    p_text->fmt_out.video.i_height =
    p_text->fmt_out.video.i_visible_height = 32;
925

Laurent Aimar's avatar
Laurent Aimar committed
926 927
    p_text->pf_sub_buffer_new = spu_new_buffer;
    p_text->pf_sub_buffer_del = spu_del_buffer;
928

Laurent Aimar's avatar
Laurent Aimar committed
929
    vlc_object_attach( p_text, p_spu );
Laurent Aimar's avatar
Laurent Aimar committed
930

Laurent Aimar's avatar
Laurent Aimar committed
931 932 933 934 935 936 937 938 939
    /* FIXME TOCHECK shouldn't module_need( , , psz_modulename, false ) do the
     * same than these 2 calls ? */
    char *psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
    if( psz_modulename && *psz_modulename )
    {
        p_text->p_module = module_need( p_text, "text renderer",
                                        psz_modulename, true );
    }
    free( psz_modulename );
940

Laurent Aimar's avatar
Laurent Aimar committed
941 942
    if( !p_text->p_module )
        p_text->p_module = module_need( p_text, "text renderer", NULL, false );
943

Laurent Aimar's avatar
Laurent Aimar committed
944 945 946 947 948 949
    /* Create a few variables used for enhanced text rendering */
    var_Create( p_text, "spu-duration", VLC_VAR_TIME );
    var_Create( p_text, "spu-elapsed", VLC_VAR_TIME );
    var_Create( p_text, "text-rerender", VLC_VAR_BOOL );
    var_Create( p_text, "scale", VLC_VAR_INTEGER );
}
950

Laurent Aimar's avatar
Laurent Aimar committed
951 952 953 954 955
static filter_t *CreateAndLoadScale( vlc_object_t *p_obj,
                                     vlc_fourcc_t i_src_chroma, vlc_fourcc_t i_dst_chroma,
                                     bool b_resize )
{
    filter_t *p_scale;
956

Laurent Aimar's avatar
Laurent Aimar committed
957 958 959 960
    p_scale = vlc_custom_create( p_obj, sizeof(filter_t),
                                 VLC_OBJECT_GENERIC, "scale" );
    if( !p_scale )
        return NULL;
961

Laurent Aimar's avatar
Laurent Aimar committed
962 963 964 965
    es_format_Init( &p_scale->fmt_in, VIDEO_ES, 0 );
    p_scale->fmt_in.video.i_chroma = i_src_chroma;
    p_scale->fmt_in.video.i_width =
    p_scale->fmt_in.video.i_height = 32;
Laurent Aimar's avatar
Laurent Aimar committed
966

Laurent Aimar's avatar
Laurent Aimar committed
967 968 969 970
    es_format_Init( &p_scale->fmt_out, VIDEO_ES, 0 );
    p_scale->fmt_out.video.i_chroma = i_dst_chroma;
    p_scale->fmt_out.video.i_width =
    p_scale->fmt_out.video.i_height = b_resize ? 16 : 32;
Laurent Aimar's avatar
Laurent Aimar committed
971

Laurent Aimar's avatar
Laurent Aimar committed
972 973
    p_scale->pf_vout_buffer_new = spu_new_video_buffer;
    p_scale->pf_vout_buffer_del = spu_del_video_buffer;
Laurent Aimar's avatar
Laurent Aimar committed
974

Laurent Aimar's avatar
Laurent Aimar committed
975 976
    vlc_object_attach( p_scale, p_obj );
    p_scale->p_module = module_need( p_scale, "video filter2", 0, 0 );
Laurent Aimar's avatar
Laurent Aimar committed
977

Laurent Aimar's avatar
Laurent Aimar committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
    return p_scale;
}
static void SpuRenderCreateAndLoadScale( spu_t *p_spu )
{
    assert( !p_spu->p->p_scale );
    assert( !p_spu->p->p_scale_yuvp );
    /* XXX p_spu->p_scale is used for all conversion/scaling except yuvp to
     * yuva/rgba */
    p_spu->p->p_scale = CreateAndLoadScale( VLC_OBJECT(p_spu),
                                            VLC_FOURCC_YUVA, VLC_FOURCC_YUVA, true );
    /* This one is used for YUVP to YUVA/RGBA without scaling
     * FIXME rename it */
    p_spu->p->p_scale_yuvp = CreateAndLoadScale( VLC_OBJECT(p_spu),
                                                 VLC_FOURCC_YUVP, VLC_FOURCC_YUVA, false );
}
Laurent Aimar's avatar
Laurent Aimar committed
993

Laurent Aimar's avatar
Laurent Aimar committed
994 995 996 997 998
static void SpuRenderText( spu_t *p_spu, bool *pb_rerender_text,
                           subpicture_t *p_subpic, subpicture_region_t *p_region,
                           int i_min_scale_ratio )
{
    filter_t *p_text = p_spu->p->p_text;
Laurent Aimar's avatar
Laurent Aimar committed
999

Laurent Aimar's avatar
Laurent Aimar committed
1000
    assert( p_region->fmt.i_chroma == VLC_FOURCC_TEXT );
Laurent Aimar's avatar
Laurent Aimar committed
1001

Laurent Aimar's avatar
Laurent Aimar committed
1002 1003
    if( !p_text || !p_text->p_module )
        goto exit;
Laurent Aimar's avatar
Laurent Aimar committed
1004

Laurent Aimar's avatar
Laurent Aimar committed
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    /* Setup 3 variables which can be used to render
     * time-dependent text (and effects). The first indicates
     * the total amount of time the text will be on screen,
     * the second the amount of time it has already been on
     * screen (can be a negative value as text is layed out
     * before it is rendered) and the third is a feedback
     * variable from the renderer - if the renderer sets it
     * then this particular text is time-dependent, eg. the
     * visual progress bar inside the text in karaoke and the
     * text needs to be rendered multiple times in order for
     * the effect to work - we therefore need to return the
     * region to its original state at the end of the loop,
     * instead of leaving it in YUVA or YUVP.
     * Any renderer which is unaware of how to render
     * time-dependent text can happily ignore the variables
     * and render the text the same as usual - it should at
     * least show up on screen, but the effect won't change
     * the text over time.
     */
    var_SetTime( p_text, "spu-duration", p_subpic->i_stop - p_subpic->i_start );
    var_SetTime( p_text, "spu-elapsed", mdate() - p_subpic->i_start );
    var_SetBool( p_text, "text-rerender", false );
    var_SetInteger( p_text, "scale", i_min_scale_ratio );
Laurent Aimar's avatar
Laurent Aimar committed
1028

Laurent Aimar's avatar
Laurent Aimar committed
1029
    if( p_text->pf_render_html && p_region->psz_html )
Laurent Aimar's avatar
Laurent Aimar committed
1030
    {
Laurent Aimar's avatar
Laurent Aimar committed
1031
        p_text->pf_render_html( p_text, p_region, p_region );
Laurent Aimar's avatar
Laurent Aimar committed
1032
    }
Laurent Aimar's avatar
Laurent Aimar committed
1033
    else if( p_text->pf_render_text )