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

/*****************************************************************************
 * Preamble
 *****************************************************************************/

29
#include <vlc/vlc.h>
zorglub's avatar
zorglub committed
30 31
#include <vlc_vout.h>
#include <vlc_osd.h>
32 33
#include "vout_pictures.h"

34 35 36
/**
 * Display a picture
 *
gbazin's avatar
 
gbazin committed
37 38
 * Remove the reservation flag of a picture, which will cause it to be ready
 * for display. The picture won't be displayed until vout_DatePicture has been
Sam Hocevar's avatar
 
Sam Hocevar committed
39
 * called.
40
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
41
void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
42 43
{
    vlc_mutex_lock( &p_vout->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
44
    switch( p_pic->i_status )
Sam Hocevar's avatar
 
Sam Hocevar committed
45 46
    {
    case RESERVED_PICTURE:
Sam Hocevar's avatar
 
Sam Hocevar committed
47
        p_pic->i_status = RESERVED_DISP_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
48 49
        break;
    case RESERVED_DATED_PICTURE:
Sam Hocevar's avatar
 
Sam Hocevar committed
50
        p_pic->i_status = READY_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
51 52
        break;
    default:
53 54
        msg_Err( p_vout, "picture to display %p has invalid status %d",
                         p_pic, p_pic->i_status );
Sam Hocevar's avatar
 
Sam Hocevar committed
55 56 57 58 59 60
        break;
    }

    vlc_mutex_unlock( &p_vout->picture_lock );
}

61 62 63
/**
 * Date a picture
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
64 65 66
 * Remove the reservation flag of a picture, which will cause it to be ready
 * for display. The picture won't be displayed until vout_DisplayPicture has
 * been called.
67 68 69 70
 * \param p_vout The vout in question
 * \param p_pic The picture to date
 * \param date The date to display the picture
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
71
void vout_DatePicture( vout_thread_t *p_vout,
Sam Hocevar's avatar
 
Sam Hocevar committed
72
                       picture_t *p_pic, mtime_t date )
Sam Hocevar's avatar
 
Sam Hocevar committed
73 74
{
    vlc_mutex_lock( &p_vout->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
75 76
    p_pic->date = date;
    switch( p_pic->i_status )
Sam Hocevar's avatar
 
Sam Hocevar committed
77 78
    {
    case RESERVED_PICTURE:
Sam Hocevar's avatar
 
Sam Hocevar committed
79
        p_pic->i_status = RESERVED_DATED_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
80 81
        break;
    case RESERVED_DISP_PICTURE:
Sam Hocevar's avatar
 
Sam Hocevar committed
82
        p_pic->i_status = READY_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
83 84
        break;
    default:
85 86
        msg_Err( p_vout, "picture to date %p has invalid status %d",
                         p_pic, p_pic->i_status );
Sam Hocevar's avatar
 
Sam Hocevar committed
87 88 89 90 91 92
        break;
    }

    vlc_mutex_unlock( &p_vout->picture_lock );
}

93 94 95
/**
 * Allocate a picture in the video output heap.
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
96 97
 * This function creates a reserved image in the video output heap.
 * A null pointer is returned if the function fails. This method provides an
gbazin's avatar
 
gbazin committed
98 99 100
 * already allocated zone of memory in the picture data fields.
 * It needs locking since several pictures can be created by several producers
 * threads.
101
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
102
picture_t *vout_CreatePicture( vout_thread_t *p_vout,
103 104
                               vlc_bool_t b_progressive,
                               vlc_bool_t b_top_field_first,
105
                               unsigned int i_nb_fields )
Sam Hocevar's avatar
 
Sam Hocevar committed
106
{
Sam Hocevar's avatar
 
Sam Hocevar committed
107 108 109
    int         i_pic;                                      /* picture index */
    picture_t * p_pic;
    picture_t * p_freepic = NULL;                      /* first free picture */
Sam Hocevar's avatar
 
Sam Hocevar committed
110 111 112 113 114

    /* Get lock */
    vlc_mutex_lock( &p_vout->picture_lock );

    /*
gbazin's avatar
 
gbazin committed
115
     * Look for an empty place in the picture heap.
Sam Hocevar's avatar
 
Sam Hocevar committed
116
     */
gbazin's avatar
 
gbazin committed
117
    for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
Sam Hocevar's avatar
 
Sam Hocevar committed
118
    {
gbazin's avatar
 
gbazin committed
119 120
        p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
                                 % I_RENDERPICTURES];
Sam Hocevar's avatar
 
Sam Hocevar committed
121

Sam Hocevar's avatar
 
Sam Hocevar committed
122
        switch( p_pic->i_status )
Sam Hocevar's avatar
 
Sam Hocevar committed
123
        {
Sam Hocevar's avatar
 
Sam Hocevar committed
124 125 126 127
            case DESTROYED_PICTURE:
                /* Memory will not be reallocated, and function can end
                 * immediately - this is the best possible case, since no
                 * memory allocation needs to be done */
Sam Hocevar's avatar
 
Sam Hocevar committed
128 129
                p_pic->i_status   = RESERVED_PICTURE;
                p_pic->i_refcount = 0;
130
                p_pic->b_force    = 0;
Sam Hocevar's avatar
 
Sam Hocevar committed
131

Sam Hocevar's avatar
 
Sam Hocevar committed
132
                p_pic->b_progressive        = b_progressive;
133
                p_pic->i_nb_fields          = i_nb_fields;
Sam Hocevar's avatar
 
Sam Hocevar committed
134
                p_pic->b_top_field_first    = b_top_field_first;
Sam Hocevar's avatar
 
Sam Hocevar committed
135

Sam Hocevar's avatar
 
Sam Hocevar committed
136
                p_vout->i_heap_size++;
gbazin's avatar
 
gbazin committed
137 138 139
                p_vout->render.i_last_used_pic =
                    ( p_vout->render.i_last_used_pic + i_pic + 1 )
                    % I_RENDERPICTURES;
Sam Hocevar's avatar
 
Sam Hocevar committed
140
                vlc_mutex_unlock( &p_vout->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
141
                return( p_pic );
Sam Hocevar's avatar
 
Sam Hocevar committed
142

Sam Hocevar's avatar
 
Sam Hocevar committed
143
            case FREE_PICTURE:
Sam Hocevar's avatar
 
Sam Hocevar committed
144
                /* Picture is empty and ready for allocation */
gbazin's avatar
 
gbazin committed
145 146 147
                p_vout->render.i_last_used_pic =
                    ( p_vout->render.i_last_used_pic + i_pic + 1 )
                    % I_RENDERPICTURES;
Sam Hocevar's avatar
 
Sam Hocevar committed
148
                p_freepic = p_pic;
Sam Hocevar's avatar
 
Sam Hocevar committed
149 150 151 152 153
                break;

            default:
                break;
        }
Sam Hocevar's avatar
 
Sam Hocevar committed
154 155 156 157 158
    }

    /*
     * Prepare picture
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
159
    if( p_freepic != NULL )
Sam Hocevar's avatar
 
Sam Hocevar committed
160
    {
gbazin's avatar
 
gbazin committed
161 162
        vout_AllocatePicture( VLC_OBJECT(p_vout),
                              p_freepic, p_vout->render.i_chroma,
Sam Hocevar's avatar
 
Sam Hocevar committed
163
                              p_vout->render.i_width, p_vout->render.i_height,
gbazin's avatar
 
gbazin committed
164
                              p_vout->render.i_aspect );
Sam Hocevar's avatar
 
Sam Hocevar committed
165

Sam Hocevar's avatar
 
Sam Hocevar committed
166
        if( p_freepic->i_planes )
Sam Hocevar's avatar
 
Sam Hocevar committed
167 168
        {
            /* Copy picture information, set some default values */
Sam Hocevar's avatar
 
Sam Hocevar committed
169 170
            p_freepic->i_status   = RESERVED_PICTURE;
            p_freepic->i_type     = MEMORY_PICTURE;
171
            p_freepic->b_slow     = 0;
Sam Hocevar's avatar
 
Sam Hocevar committed
172

Sam Hocevar's avatar
 
Sam Hocevar committed
173
            p_freepic->i_refcount = 0;
174
            p_freepic->b_force = 0;
Sam Hocevar's avatar
 
Sam Hocevar committed
175

Sam Hocevar's avatar
 
Sam Hocevar committed
176
            p_freepic->b_progressive        = b_progressive;
177
            p_freepic->i_nb_fields          = i_nb_fields;
Sam Hocevar's avatar
 
Sam Hocevar committed
178
            p_freepic->b_top_field_first    = b_top_field_first;
Sam Hocevar's avatar
 
Sam Hocevar committed
179

Sam Hocevar's avatar
 
Sam Hocevar committed
180
            p_freepic->i_matrix_coefficients = 1;
Sam Hocevar's avatar
 
Sam Hocevar committed
181

Sam Hocevar's avatar
 
Sam Hocevar committed
182
            p_vout->i_heap_size++;
Sam Hocevar's avatar
 
Sam Hocevar committed
183 184 185 186
        }
        else
        {
            /* Memory allocation failed : set picture as empty */
Sam Hocevar's avatar
 
Sam Hocevar committed
187 188
            p_freepic->i_status = FREE_PICTURE;
            p_freepic = NULL;
Sam Hocevar's avatar
 
Sam Hocevar committed
189

190
            msg_Err( p_vout, "picture allocation failed" );
Sam Hocevar's avatar
 
Sam Hocevar committed
191 192 193 194
        }

        vlc_mutex_unlock( &p_vout->picture_lock );

Sam Hocevar's avatar
 
Sam Hocevar committed
195
        return( p_freepic );
Sam Hocevar's avatar
 
Sam Hocevar committed
196 197 198 199 200 201 202 203 204
    }

    /* No free or destroyed picture could be found, but the decoder
     * will try again in a while. */
    vlc_mutex_unlock( &p_vout->picture_lock );

    return( NULL );
}

205 206 207
/**
 * Remove a permanent or reserved picture from the heap
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
208 209 210
 * This function frees a previously reserved picture or a permanent
 * picture. It is meant to be used when the construction of a picture aborted.
 * Note that the picture will be destroyed even if it is linked !
211
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
212
void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
213 214 215 216 217
{
    vlc_mutex_lock( &p_vout->picture_lock );

#ifdef DEBUG
    /* Check if picture status is valid */
Sam Hocevar's avatar
 
Sam Hocevar committed
218 219 220
    if( (p_pic->i_status != RESERVED_PICTURE) &&
        (p_pic->i_status != RESERVED_DATED_PICTURE) &&
        (p_pic->i_status != RESERVED_DISP_PICTURE) )
Sam Hocevar's avatar
 
Sam Hocevar committed
221
    {
222 223
        msg_Err( p_vout, "picture to destroy %p has invalid status %d",
                         p_pic, p_pic->i_status );
Sam Hocevar's avatar
 
Sam Hocevar committed
224 225 226
    }
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
227
    p_pic->i_status = DESTROYED_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
228
    p_vout->i_heap_size--;
Sam Hocevar's avatar
 
Sam Hocevar committed
229 230 231 232

    vlc_mutex_unlock( &p_vout->picture_lock );
}

233 234 235
/**
 * Increment reference counter of a picture
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
236 237
 * This function increments the reference counter of a picture in the video
 * heap. It needs a lock since several producer threads can access the picture.
238
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
239
void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
240 241
{
    vlc_mutex_lock( &p_vout->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
242
    p_pic->i_refcount++;
Sam Hocevar's avatar
 
Sam Hocevar committed
243 244 245
    vlc_mutex_unlock( &p_vout->picture_lock );
}

246 247 248
/**
 * Decrement reference counter of a picture
 *
gbazin's avatar
 
gbazin committed
249
 * This function decrement the reference counter of a picture in the video heap
250
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
251
void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
252 253
{
    vlc_mutex_lock( &p_vout->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
254
    p_pic->i_refcount--;
Sam Hocevar's avatar
 
Sam Hocevar committed
255

Sam Hocevar's avatar
 
Sam Hocevar committed
256 257
    if( ( p_pic->i_refcount == 0 ) &&
        ( p_pic->i_status == DISPLAYED_PICTURE ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
258
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
259
        p_pic->i_status = DESTROYED_PICTURE;
Sam Hocevar's avatar
 
Sam Hocevar committed
260
        p_vout->i_heap_size--;
Sam Hocevar's avatar
 
Sam Hocevar committed
261 262 263 264 265
    }

    vlc_mutex_unlock( &p_vout->picture_lock );
}

266 267 268
/**
 * Render a picture
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
269 270 271
 * This function chooses whether the current picture needs to be copied
 * before rendering, does the subpicture magic, and tells the video output
 * thread which direct buffer needs to be displayed.
272
 */
Sam Hocevar's avatar
 
Sam Hocevar committed
273
picture_t * vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
Sam Hocevar's avatar
 
Sam Hocevar committed
274 275
                                                       subpicture_t *p_subpic )
{
276 277
    int i_scale_width, i_scale_height;

Sam Hocevar's avatar
 
Sam Hocevar committed
278
    if( p_pic == NULL )
Sam Hocevar's avatar
 
Sam Hocevar committed
279 280 281 282 283
    {
        /* XXX: subtitles */
        return NULL;
    }

284 285 286 287
    i_scale_width = p_vout->fmt_out.i_visible_width * 1000 /
        p_vout->fmt_in.i_visible_width;
    i_scale_height = p_vout->fmt_out.i_visible_height * 1000 /
        p_vout->fmt_in.i_visible_height;
288

Sam Hocevar's avatar
 
Sam Hocevar committed
289
    if( p_pic->i_type == DIRECT_PICTURE )
Sam Hocevar's avatar
 
Sam Hocevar committed
290
    {
291 292
        if( !p_vout->render.b_allow_modify_pics || p_pic->i_refcount ||
            p_pic->b_force )
Sam Hocevar's avatar
 
Sam Hocevar committed
293 294 295 296 297 298 299 300 301
        {
            /* Picture is in a direct buffer and is still in use,
             * we need to copy it to another direct buffer before
             * displaying it if there are subtitles. */
            if( p_subpic != NULL )
            {
                /* We have subtitles. First copy the picture to
                 * the spare direct buffer, then render the
                 * subtitles. */
302
                vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
Sam Hocevar's avatar
 
Sam Hocevar committed
303

304
                spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
305 306
                                       PP_OUTPUTPICTURE[0], p_pic, p_subpic,
                                       i_scale_width, i_scale_height );
Sam Hocevar's avatar
 
Sam Hocevar committed
307

Sam Hocevar's avatar
 
Sam Hocevar committed
308
                return PP_OUTPUTPICTURE[0];
Sam Hocevar's avatar
 
Sam Hocevar committed
309 310 311 312 313
            }

            /* No subtitles, picture is in a directbuffer so
             * we can display it directly even if it is still
             * in use. */
Sam Hocevar's avatar
 
Sam Hocevar committed
314
            return p_pic;
Sam Hocevar's avatar
 
Sam Hocevar committed
315 316 317 318 319
        }

        /* Picture is in a direct buffer but isn't used by the
         * decoder. We can safely render subtitles on it and
         * display it. */
320 321
        spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out, p_pic, p_pic,
                               p_subpic, i_scale_width, i_scale_height );
Sam Hocevar's avatar
 
Sam Hocevar committed
322

Sam Hocevar's avatar
 
Sam Hocevar committed
323
        return p_pic;
Sam Hocevar's avatar
 
Sam Hocevar committed
324 325 326 327
    }

    /* Not a direct buffer. We either need to copy it to a direct buffer,
     * or render it if the chroma isn't the same. */
Sam Hocevar's avatar
 
Sam Hocevar committed
328
    if( p_vout->b_direct )
Sam Hocevar's avatar
 
Sam Hocevar committed
329 330 331 332
    {
        /* Picture is not in a direct buffer, but is exactly the
         * same size as the direct buffers. A memcpy() is enough,
         * then render the subtitles. */
gbazin's avatar
 
gbazin committed
333 334 335 336 337

        if( PP_OUTPUTPICTURE[0]->pf_lock )
            if( PP_OUTPUTPICTURE[0]->pf_lock( p_vout, PP_OUTPUTPICTURE[0] ) )
                return NULL;

338
        vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
339 340 341
        spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
                               PP_OUTPUTPICTURE[0], p_pic,
                               p_subpic, i_scale_width, i_scale_height );
Sam Hocevar's avatar
 
Sam Hocevar committed
342

gbazin's avatar
 
gbazin committed
343 344 345
        if( PP_OUTPUTPICTURE[0]->pf_unlock )
            PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );

Sam Hocevar's avatar
 
Sam Hocevar committed
346
        return PP_OUTPUTPICTURE[0];
Sam Hocevar's avatar
 
Sam Hocevar committed
347 348 349 350
    }

    /* Picture is not in a direct buffer, and needs to be converted to
     * another size/chroma. Then the subtitles need to be rendered as
Sam Hocevar's avatar
 
Sam Hocevar committed
351
     * well. This usually means software YUV, or hardware YUV with a
Sam Hocevar's avatar
 
Sam Hocevar committed
352 353
     * different chroma. */

354 355 356 357 358 359 360 361 362
    if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
    {
        /* The picture buffer is in slow memory. We'll use
         * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
         * one for subpictures rendering. */
        picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
        if( p_tmp_pic->i_status == FREE_PICTURE )
        {
            vout_AllocatePicture( VLC_OBJECT(p_vout),
363 364 365 366
                                  p_tmp_pic, p_vout->fmt_out.i_chroma,
                                  p_vout->fmt_out.i_width,
                                  p_vout->fmt_out.i_height,
                                  p_vout->fmt_out.i_aspect );
367 368
            p_tmp_pic->i_type = MEMORY_PICTURE;
            p_tmp_pic->i_status = RESERVED_PICTURE;
369 370
            /* some modules (such as blend)  needs to know the extra information in picture heap */
            p_tmp_pic->p_heap = &p_vout->output;
371 372 373 374
        }

        /* Convert image to the first direct buffer */
        p_vout->chroma.pf_convert( p_vout, p_pic, p_tmp_pic );
gbazin's avatar
 
gbazin committed
375

376
        /* Render subpictures on the first direct buffer */
377
        spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out, p_tmp_pic,
378 379
                               p_tmp_pic, p_subpic,
                               i_scale_width, i_scale_height );
Sam Hocevar's avatar
 
Sam Hocevar committed
380

381 382 383 384
        if( p_vout->p_picture[0].pf_lock )
            if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
                return NULL;

385
        vout_CopyPicture( p_vout, &p_vout->p_picture[0], p_tmp_pic );
386 387 388 389 390 391 392 393 394 395 396
    }
    else
    {
        if( p_vout->p_picture[0].pf_lock )
            if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
                return NULL;

        /* Convert image to the first direct buffer */
        p_vout->chroma.pf_convert( p_vout, p_pic, &p_vout->p_picture[0] );

        /* Render subpictures on the first direct buffer */
397 398 399
        spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
                               &p_vout->p_picture[0], &p_vout->p_picture[0],
                               p_subpic, i_scale_width, i_scale_height );
400
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
401

gbazin's avatar
 
gbazin committed
402 403 404
    if( p_vout->p_picture[0].pf_unlock )
        p_vout->p_picture[0].pf_unlock( p_vout, &p_vout->p_picture[0] );

Sam Hocevar's avatar
 
Sam Hocevar committed
405 406 407
    return &p_vout->p_picture[0];
}

408 409 410
/**
 * Calculate image window coordinates
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
411 412
 * This function will be accessed by plugins. It calculates the relative
 * position of the output window and the image window.
413
 */
414 415 416 417
void vout_PlacePicture( vout_thread_t *p_vout,
                        unsigned int i_width, unsigned int i_height,
                        unsigned int *pi_x, unsigned int *pi_y,
                        unsigned int *pi_width, unsigned int *pi_height )
Sam Hocevar's avatar
 
Sam Hocevar committed
418
{
gbazin's avatar
 
gbazin committed
419
    if( (i_width <= 0) || (i_height <=0) )
gbazin's avatar
 
gbazin committed
420 421
    {
        *pi_width = *pi_height = *pi_x = *pi_y = 0;
gbazin's avatar
 
gbazin committed
422
        return;
gbazin's avatar
 
gbazin committed
423
    }
gbazin's avatar
 
gbazin committed
424

Sam Hocevar's avatar
 
Sam Hocevar committed
425 426 427 428 429 430 431
    if( p_vout->b_scale )
    {
        *pi_width = i_width;
        *pi_height = i_height;
    }
    else
    {
432 433
        *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
        *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
Sam Hocevar's avatar
 
Sam Hocevar committed
434 435
    }

436
    if( p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
437 438
        *pi_height / p_vout->fmt_in.i_visible_height /
        p_vout->fmt_in.i_sar_den > *pi_width )
Sam Hocevar's avatar
 
Sam Hocevar committed
439
    {
440
        *pi_height = p_vout->fmt_in.i_visible_height *
441
            (int64_t)p_vout->fmt_in.i_sar_den * *pi_width /
442
            p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
Sam Hocevar's avatar
 
Sam Hocevar committed
443 444 445
    }
    else
    {
446
        *pi_width = p_vout->fmt_in.i_visible_width *
447
            (int64_t)p_vout->fmt_in.i_sar_num * *pi_height /
448
            p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
Sam Hocevar's avatar
 
Sam Hocevar committed
449 450
    }

gbazin's avatar
 
gbazin committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
    switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
    {
    case VOUT_ALIGN_LEFT:
        *pi_x = 0;
        break;
    case VOUT_ALIGN_RIGHT:
        *pi_x = i_width - *pi_width;
        break;
    default:
        *pi_x = ( i_width - *pi_width ) / 2;
    }

    switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
    {
    case VOUT_ALIGN_TOP:
        *pi_y = 0;
        break;
    case VOUT_ALIGN_BOTTOM:
        *pi_y = i_height - *pi_height;
        break;
    default:
        *pi_y = ( i_height - *pi_height ) / 2;
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
474 475
}

476 477 478
/**
 * Allocate a new picture in the heap.
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
479 480 481
 * This function allocates a fake direct buffer in memory, which can be
 * used exactly like a video buffer. The video output thread then manages
 * how it gets displayed.
482
 */
483 484 485
int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
                            vlc_fourcc_t i_chroma,
                            int i_width, int i_height, int i_aspect )
Sam Hocevar's avatar
 
Sam Hocevar committed
486
{
487 488 489 490 491
    int i_bytes, i_index, i_width_aligned, i_height_aligned;

    /* Make sure the real dimensions are a multiple of 16 */
    i_width_aligned = (i_width + 15) >> 4 << 4;
    i_height_aligned = (i_height + 15) >> 4 << 4;
Sam Hocevar's avatar
 
Sam Hocevar committed
492

493 494 495 496 497 498
    if( vout_InitPicture( p_this, p_pic, i_chroma,
                          i_width, i_height, i_aspect ) != VLC_SUCCESS )
    {
        p_pic->i_planes = 0;
        return VLC_EGENERIC;
    }
gbazin's avatar
 
gbazin committed
499 500

    /* Calculate how big the new image should be */
gbazin's avatar
 
gbazin committed
501
    i_bytes = p_pic->format.i_bits_per_pixel *
502
        i_width_aligned * i_height_aligned / 8;
gbazin's avatar
 
gbazin committed
503 504 505 506 507 508

    p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );

    if( p_pic->p_data == NULL )
    {
        p_pic->i_planes = 0;
509
        return VLC_EGENERIC;
gbazin's avatar
 
gbazin committed
510 511 512 513 514 515 516
    }

    /* Fill the p_pixels field for each plane */
    p_pic->p[ 0 ].p_pixels = p_pic->p_data;

    for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
    {
517 518
        p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
            p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
gbazin's avatar
 
gbazin committed
519
    }
520 521

    return VLC_SUCCESS;
gbazin's avatar
 
gbazin committed
522 523
}

524 525 526
/**
 * Initialise the video format fields given chroma/size.
 *
gbazin's avatar
 
gbazin committed
527 528
 * This function initializes all the video_frame_format_t fields given the
 * static properties of a picture (chroma and size).
529 530 531 532 533 534
 * \param p_format Pointer to the format structure to initialize
 * \param i_chroma Chroma to set
 * \param i_width Width to set
 * \param i_height Height to set
 * \param i_aspect Aspect ratio
 */
gbazin's avatar
 
gbazin committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
                      int i_width, int i_height, int i_aspect )
{
    p_format->i_chroma   = i_chroma;
    p_format->i_width    = p_format->i_visible_width  = i_width;
    p_format->i_height   = p_format->i_visible_height = i_height;
    p_format->i_x_offset = p_format->i_y_offset = 0;
    p_format->i_aspect   = i_aspect;

#if 0
    /* Assume we have square pixels */
    if( i_width && i_height )
        p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
    else
        p_format->i_aspect = 0;
#endif

    switch( i_chroma )
    {
554 555 556
        case FOURCC_YUVA:
            p_format->i_bits_per_pixel = 32;
            break;
gbazin's avatar
 
gbazin committed
557
        case FOURCC_I444:
558
        case FOURCC_J444:
gbazin's avatar
 
gbazin committed
559 560 561 562
            p_format->i_bits_per_pixel = 24;
            break;
        case FOURCC_I422:
        case FOURCC_YUY2:
563
        case FOURCC_UYVY:
564
        case FOURCC_J422:
gbazin's avatar
 
gbazin committed
565 566 567 568 569
            p_format->i_bits_per_pixel = 16;
            break;
        case FOURCC_I411:
        case FOURCC_YV12:
        case FOURCC_I420:
570
        case FOURCC_J420:
gbazin's avatar
 
gbazin committed
571 572 573 574
        case FOURCC_IYUV:
            p_format->i_bits_per_pixel = 12;
            break;
        case FOURCC_I410:
575
        case FOURCC_YVU9:
gbazin's avatar
 
gbazin committed
576 577 578 579 580
            p_format->i_bits_per_pixel = 9;
            break;
        case FOURCC_Y211:
            p_format->i_bits_per_pixel = 8;
            break;
581 582 583 584
        case FOURCC_YUVP:
            p_format->i_bits_per_pixel = 8;
            break;

gbazin's avatar
 
gbazin committed
585
        case FOURCC_RV32:
586
        case FOURCC_RGBA:
gbazin's avatar
 
gbazin committed
587 588 589 590 591 592 593 594 595 596 597 598
            p_format->i_bits_per_pixel = 32;
            break;
        case FOURCC_RV24:
            p_format->i_bits_per_pixel = 24;
            break;
        case FOURCC_RV15:
        case FOURCC_RV16:
            p_format->i_bits_per_pixel = 16;
            break;
        case FOURCC_RGB2:
            p_format->i_bits_per_pixel = 8;
            break;
599 600 601 602 603

        case FOURCC_GREY:
            p_format->i_bits_per_pixel = 8;
            break;

gbazin's avatar
 
gbazin committed
604 605 606 607 608 609
        default:
            p_format->i_bits_per_pixel = 0;
            break;
    }
}

610 611 612
/**
 * Initialise the picture_t fields given chroma/size.
 *
gbazin's avatar
 
gbazin committed
613 614
 * This function initializes most of the picture_t fields given a chroma and
 * size. It makes the assumption that stride == width.
615 616 617 618 619 620 621
 * \param p_this The calling object
 * \param p_pic Pointer to the picture to initialize
 * \param i_chroma The chroma fourcc to set
 * \param i_width The width of the picture
 * \param i_height The height of the picture
 * \param i_aspect The aspect ratio of the picture
 */
622 623 624
int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
                        vlc_fourcc_t i_chroma,
                        int i_width, int i_height, int i_aspect )
gbazin's avatar
 
gbazin committed
625
{
626
    int i_index, i_width_aligned, i_height_aligned;
gbazin's avatar
 
gbazin committed
627

Sam Hocevar's avatar
 
Sam Hocevar committed
628 629 630 631
    /* Store default values */
    for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
    {
        p_pic->p[i_index].p_pixels = NULL;
632
        p_pic->p[i_index].i_pixel_pitch = 1;
Sam Hocevar's avatar
 
Sam Hocevar committed
633 634
    }

635 636 637 638 639
    p_pic->pf_release = 0;
    p_pic->pf_lock = 0;
    p_pic->pf_unlock = 0;
    p_pic->i_refcount = 0;

gbazin's avatar
 
gbazin committed
640 641
    vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );

642 643 644 645
    /* Make sure the real dimensions are a multiple of 16 */
    i_width_aligned = (i_width + 15) >> 4 << 4;
    i_height_aligned = (i_height + 15) >> 4 << 4;

Sam Hocevar's avatar
 
Sam Hocevar committed
646
    /* Calculate coordinates */
Sam Hocevar's avatar
 
Sam Hocevar committed
647
    switch( i_chroma )
Sam Hocevar's avatar
 
Sam Hocevar committed
648
    {
gbazin's avatar
 
gbazin committed
649
        case FOURCC_I411:
650 651
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
652 653
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
654 655
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height;
656 657
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
658 659
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height;
660 661
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
gbazin's avatar
 
gbazin committed
662 663 664
            p_pic->i_planes = 3;
            break;

665
        case FOURCC_I410:
666
        case FOURCC_YVU9:
667 668
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
669 670
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
671 672
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
673 674
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
675 676
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
677 678
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
679 680 681
            p_pic->i_planes = 3;
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
682
        case FOURCC_YV12:
Sam Hocevar's avatar
 
Sam Hocevar committed
683 684
        case FOURCC_I420:
        case FOURCC_IYUV:
685
        case FOURCC_J420:
686 687
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
688 689
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
690 691
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
692 693
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
694 695
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
696 697
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
Sam Hocevar's avatar
 
Sam Hocevar committed
698
            p_pic->i_planes = 3;
Sam Hocevar's avatar
 
Sam Hocevar committed
699 700
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
701
        case FOURCC_I422:
702
        case FOURCC_J422:
703 704
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
705 706
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
707 708
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height;
709 710
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
711 712
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height;
713 714
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
Sam Hocevar's avatar
 
Sam Hocevar committed
715
            p_pic->i_planes = 3;
Sam Hocevar's avatar
 
Sam Hocevar committed
716 717
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
718
        case FOURCC_I444:
719
        case FOURCC_J444:
720 721
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
722 723
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
724 725
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height;
726 727
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
728 729
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height;
730 731
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
Sam Hocevar's avatar
 
Sam Hocevar committed
732 733 734
            p_pic->i_planes = 3;
            break;

735
        case FOURCC_YUVA:
736 737
            p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
738 739
            p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
740 741
            p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ U_PLANE ].i_visible_lines = i_height;
742 743
            p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
744 745
            p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ V_PLANE ].i_visible_lines = i_height;
746 747
            p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
748 749
            p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
            p_pic->p[ A_PLANE ].i_visible_lines = i_height;
750 751
            p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
            p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
752 753 754 755
            p_pic->i_planes = 4;
            break;

        case FOURCC_YUVP:
756 757
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
758 759
            p_pic->p->i_pitch = i_width_aligned;
            p_pic->p->i_visible_pitch = i_width;
760 761 762 763
            p_pic->p->i_pixel_pitch = 8;
            p_pic->i_planes = 1;
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
764
        case FOURCC_Y211:
765 766
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
767 768
            p_pic->p->i_pitch = i_width_aligned;
            p_pic->p->i_visible_pitch = i_width;
769
            p_pic->p->i_pixel_pitch = 4;
Sam Hocevar's avatar
 
Sam Hocevar committed
770 771 772
            p_pic->i_planes = 1;
            break;

773
        case FOURCC_UYVY:
774
        case FOURCC_YUY2:
775 776
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
777 778
            p_pic->p->i_pitch = i_width_aligned * 2;
            p_pic->p->i_visible_pitch = i_width * 2;
779
            p_pic->p->i_pixel_pitch = 4;
780 781 782
            p_pic->i_planes = 1;
            break;

783
        case FOURCC_RGB2:
784 785
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
786 787
            p_pic->p->i_pitch = i_width_aligned;
            p_pic->p->i_visible_pitch = i_width;
788 789 790 791
            p_pic->p->i_pixel_pitch = 1;
            p_pic->i_planes = 1;
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
792
        case FOURCC_RV15:
793 794
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
795 796
            p_pic->p->i_pitch = i_width_aligned * 2;
            p_pic->p->i_visible_pitch = i_width * 2;
797
            p_pic->p->i_pixel_pitch = 2;
Sam Hocevar's avatar
 
Sam Hocevar committed
798 799 800 801
            p_pic->i_planes = 1;
            break;

        case FOURCC_RV16:
802 803
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
804 805
            p_pic->p->i_pitch = i_width_aligned * 2;
            p_pic->p->i_visible_pitch = i_width * 2;
806
            p_pic->p->i_pixel_pitch = 2;
Sam Hocevar's avatar
 
Sam Hocevar committed
807
            p_pic->i_planes = 1;
Sam Hocevar's avatar
 
Sam Hocevar committed
808 809
            break;

gbazin's avatar
 
gbazin committed
810
        case FOURCC_RV24:
811 812
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
813 814
            p_pic->p->i_pitch = i_width_aligned * 3;
            p_pic->p->i_visible_pitch = i_width * 3;
gbazin's avatar
 
gbazin committed
815 816 817 818
            p_pic->p->i_pixel_pitch = 3;
            p_pic->i_planes = 1;
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
819
        case FOURCC_RV32:
820
        case FOURCC_RGBA:
821 822
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
823 824
            p_pic->p->i_pitch = i_width_aligned * 4;
            p_pic->p->i_visible_pitch = i_width * 4;
825
            p_pic->p->i_pixel_pitch = 4;
Sam Hocevar's avatar
 
Sam Hocevar committed
826 827 828
            p_pic->i_planes = 1;
            break;

829 830 831 832 833 834 835 836 837
        case FOURCC_GREY:
            p_pic->p->i_lines = i_height_aligned;
            p_pic->p->i_visible_lines = i_height;
            p_pic->p->i_pitch = i_width_aligned;
            p_pic->p->i_visible_pitch = i_width;
            p_pic->p->i_pixel_pitch = 1;
            p_pic->i_planes = 1;
            break;

Sam Hocevar's avatar
 
Sam Hocevar committed
838
        default:
gbazin's avatar
 
gbazin committed
839
            msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
840
                             i_chroma, (char*)&i_chroma );
Sam Hocevar's avatar
 
Sam Hocevar committed
841
            p_pic->i_planes = 0;
842
            return VLC_EGENERIC;
Sam Hocevar's avatar
 
Sam Hocevar committed
843
    }
844 845

    return VLC_SUCCESS;
Sam Hocevar's avatar
 
Sam Hocevar committed
846 847
}

848 849 850
/**
 * Compare two chroma values
 *
851
 * This function returns 1 if the two fourcc values given as argument are
gbazin's avatar
 
gbazin committed
852
 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
853
 */
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
{
    /* If they are the same, they are the same ! */
    if( i_chroma == i_amorhc )
    {
        return 1;
    }

    /* Check for equivalence classes */
    switch( i_chroma )
    {
        case FOURCC_I420:
        case FOURCC_IYUV:
        case FOURCC_YV12:
            switch( i_amorhc )
            {
                case FOURCC_I420:
                case FOURCC_IYUV:
                case FOURCC_YV12:
                    return 1;

                default:
                    return 0;
            }

        case FOURCC_UYVY:
        case FOURCC_UYNV:
        case FOURCC_Y422:
            switch( i_amorhc )
            {
                case FOURCC_UYVY:
                case FOURCC_UYNV:
                case FOURCC_Y422:
                    return 1;

                default:
                    return 0;
            }

        case FOURCC_YUY2:
        case FOURCC_YUNV:
            switch( i_amorhc )
            {
                case FOURCC_YUY2:
                case FOURCC_YUNV:
                    return 1;

                default:
                    return 0;
            }

        default:
            return 0;
    }
}

910
/*****************************************************************************
911
 * vout_CopyPicture: copy a picture to another one
912 913 914
 *****************************************************************************
 * This function takes advantage of the image format, and reduces the
 * number of calls to memcpy() to the minimum. Source and destination
915
 * images must have same width (hence i_visible_pitch), height, and chroma.
916
 *****************************************************************************/