vpar_pool.h 4.98 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * vpar_pool.h : video parser/video decoders communication
 *****************************************************************************
 * Copyright (C) 1999, 2000 VideoLAN
Henri Fallon's avatar
 
Henri Fallon committed
5
 * $Id: vpar_pool.h,v 1.1 2001/11/13 12:09:18 henri Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
 *
 * Authors: Christophe Massiot <massiot@via.ecp.fr>
 *
 * 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * vdec_pool_t
 *****************************************************************************
 * This structure is used for the communication between the parser and the
 * decoders.
 *****************************************************************************/
typedef struct vdec_pool_s
{
    /* Locks */
    vlc_mutex_t         lock;                         /* Structure data lock */
    vlc_cond_t          wait_empty;      /* The parser blocks there when all
                                          * decoder threads are busy         */
    vlc_cond_t          wait_undecoded; /* The decoders block there when no
                                         * macroblock has been given by the
                                         * parser */

    /* Video decoder threads */
    struct vdec_thread_s ** pp_vdec;       /* Array of video decoder threads */
    int                 i_smp;     /* Number of symmetrical decoder threads,
                                    * hence size of the pp_vdec, p_macroblocks
                                    * and pp_new_macroblocks array */

    /* Macroblocks */
    macroblock_t *      p_macroblocks;

    /* Empty macroblocks */
    macroblock_t **     pp_empty_macroblocks;           /* Empty macroblocks */
    int                 i_index_empty;              /* Last empty macroblock */

    /* Undecoded macroblocks, read by the decoders */
    macroblock_t **     pp_new_macroblocks;         /* Undecoded macroblocks */
    int                 i_index_new;            /* Last undecoded macroblock */

    /* Undecoded macroblock, used when the parser and the decoder share the
     * same thread */
    macroblock_t        mb;
    struct vdec_thread_s * p_vdec;                     /* Fake video decoder */

    /* Pointers to usual pool functions */
    void             (* pf_wait_pool) ( struct vdec_pool_s * );
    macroblock_t *   (* pf_new_mb) ( struct vdec_pool_s * );
    void             (* pf_free_mb) ( struct vdec_pool_s *,
                                      struct macroblock_s * );
    void             (* pf_decode_mb) ( struct vdec_pool_s *,
                                        struct macroblock_s * );

    /* Pointer to the decoding function - used for B&W switching */
    void             (* pf_vdec_decode) ( struct vdec_thread_s *,
                                          struct macroblock_s * );
    boolean_t           b_bw;                      /* Current value for B&W */

    /* Access to the plug-ins needed by the video decoder thread */
76 77 78
    void ( * pf_idct_init )   ( void ** );
    void ( * ppppf_motion[2][2][4] ) ( yuv_data_t *, yuv_data_t *,
                                       int, int );
79 80

    struct vpar_thread_s * p_vpar;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
} vdec_pool_t;

/*****************************************************************************
 * Prototypes
 *****************************************************************************/
void vpar_InitPool( struct vpar_thread_s * );
void vpar_SpawnPool( struct vpar_thread_s * );
void vpar_EndPool( struct vpar_thread_s * );

/*****************************************************************************
 * vpar_GetMacroblock: In a vdec thread, get the next available macroblock
 *****************************************************************************/
static __inline__ macroblock_t * vpar_GetMacroblock( vdec_pool_t * p_pool,
                                                     boolean_t * pb_die )
{
    macroblock_t *  p_mb;

    vlc_mutex_lock( &p_pool->lock );
    while( p_pool->i_index_new == 0 && !*pb_die )
    {
        vlc_cond_wait( &p_pool->wait_undecoded, &p_pool->lock );
    }

    if( *pb_die )
    {
        vlc_mutex_unlock( &p_pool->lock );
        return( NULL );
    }

    p_mb = p_pool->pp_new_macroblocks[ --p_pool->i_index_new ];
    vlc_mutex_unlock( &p_pool->lock );
    return( p_mb );
}