vout_pictures.c 3.12 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1
/*****************************************************************************
2
 * vout_pictures.c :
Sam Hocevar's avatar
 
Sam Hocevar committed
3
 *****************************************************************************
4
 * Copyright (C) 2009-2010 Laurent Aimar
5
 * $Id$
Sam Hocevar's avatar
 
Sam Hocevar committed
6
 *
7
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
Sam Hocevar's avatar
 
Sam Hocevar committed
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Sam Hocevar's avatar
 
Sam Hocevar committed
22 23 24 25 26 27
 *****************************************************************************/

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

28 29 30
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
31
#include <assert.h>
32

33
#include <vlc_common.h>
34
#include <libvlc.h>
zorglub's avatar
zorglub committed
35
#include <vlc_vout.h>
Laurent Aimar's avatar
Laurent Aimar committed
36
#include <vlc_picture_fifo.h>
37
#include <vlc_picture_pool.h>
38

39
#include "vout_internal.h"
40

41
/**
Laurent Aimar's avatar
Laurent Aimar committed
42 43
 * It retreives a picture from the vout or NULL if no pictures are
 * available yet.
44
 *
Laurent Aimar's avatar
Laurent Aimar committed
45
 * You MUST call vout_PutPicture or vout_ReleasePicture on it.
46
 *
Laurent Aimar's avatar
Laurent Aimar committed
47 48
 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
 * read-only reference.
49
 */
Laurent Aimar's avatar
Laurent Aimar committed
50
picture_t *vout_GetPicture( vout_thread_t *p_vout )
Sam Hocevar's avatar
 
Sam Hocevar committed
51 52
{
    /* Get lock */
53
    vlc_mutex_lock( &p_vout->p->picture_lock );
54 55 56
    picture_t *p_pic = picture_pool_Get(p_vout->p->decoder_pool);
    if (p_pic) {
        picture_Reset(p_pic);
57
        p_pic->p_next = NULL;
Sam Hocevar's avatar
 
Sam Hocevar committed
58
    }
59
    vlc_mutex_unlock( &p_vout->p->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
60

61
    return p_pic;
Sam Hocevar's avatar
 
Sam Hocevar committed
62 63
}

Laurent Aimar's avatar
Laurent Aimar committed
64 65 66 67 68 69 70 71 72
/**
 * It gives to the vout a picture to be displayed.
 *
 * The given picture MUST comes from vout_GetPicture.
 *
 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
 * read/used.
 */
void vout_PutPicture( vout_thread_t *p_vout, picture_t *p_pic )
73
{
74
    vlc_mutex_lock( &p_vout->p->picture_lock );
75

Laurent Aimar's avatar
Laurent Aimar committed
76 77
    p_pic->p_next = NULL;
    picture_fifo_Push(p_vout->p->decoder_fifo, p_pic);
78

79
    vlc_mutex_unlock( &p_vout->p->picture_lock );
80 81

    vout_control_Wake( &p_vout->p->control);
82 83
}

84
/**
Laurent Aimar's avatar
Laurent Aimar committed
85
 * It releases a picture retreived by vout_GetPicture.
86
 */
Laurent Aimar's avatar
Laurent Aimar committed
87
void vout_ReleasePicture( vout_thread_t *p_vout, picture_t *p_pic  )
Sam Hocevar's avatar
 
Sam Hocevar committed
88
{
89
    vlc_mutex_lock( &p_vout->p->picture_lock );
Laurent Aimar's avatar
Laurent Aimar committed
90 91 92

    picture_Release( p_pic );

93
    vlc_mutex_unlock( &p_vout->p->picture_lock );
94 95

    vout_control_Wake( &p_vout->p->control);
Sam Hocevar's avatar
 
Sam Hocevar committed
96 97
}

98
/**
Laurent Aimar's avatar
Laurent Aimar committed
99 100
 * It increment the reference counter of a picture retreived by
 * vout_GetPicture.
101
 */
Laurent Aimar's avatar
Laurent Aimar committed
102
void vout_HoldPicture( vout_thread_t *p_vout, picture_t *p_pic )
Sam Hocevar's avatar
 
Sam Hocevar committed
103
{
104
    vlc_mutex_lock( &p_vout->p->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
105

Laurent Aimar's avatar
Laurent Aimar committed
106 107
    picture_Hold( p_pic );

108
    vlc_mutex_unlock( &p_vout->p->picture_lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
109 110
}