va.c 2.78 KB
Newer Older
1 2 3 4 5 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
/*****************************************************************************
 * va.c: Video Acceleration API for avcodec
 *****************************************************************************
 * Copyright (C) 2011, M2X BV
 * $Id$
 *
 * Authors: Jean-Paul Saman
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_fourcc.h>
#include <assert.h>

#ifdef HAVE_LIBAVCODEC_AVCODEC_H
#   include <libavcodec/avcodec.h>
#else
#   include <avcodec.h>
#endif

#include "avcodec.h"
#ifdef HAVE_AVCODEC_VAAPI
#  include <vlc_xlib.h>
#  include <libavcodec/vaapi.h>
#  include <va/va.h>
#  include <va/va_x11.h>
#endif
#include "va.h"
46
#include "vaapi.h"
47 48 49 50

#ifdef HAVE_AVCODEC_VAAPI

/* Global VAAPI connection state */
51
static vlc_va_conn_t vlc_va_conn = { NULL, 0, 0, 0, 0 };
52

53
/* */
54
vlc_va_conn_t *vlc_va_get_conn( void )
55 56 57 58
{
    return (vlc_va_conn_t *) &vlc_va_conn;
}

59
vlc_va_conn_t *vlc_va_Initialize( const char *display_name )
60 61
{
    /* connect global to caller */
62 63
    vlc_va_conn_t *conn = vlc_va_get_conn();
    assert(conn);
64 65 66
    if (conn->i_ref_count > 0)
    {
        conn->i_ref_count++;
67
        return conn;
68
    }
69

70 71 72 73 74 75 76 77 78 79 80
    /* Create a VA display */
    conn->p_display_x11 = XOpenDisplay(display_name);
    if( !conn->p_display_x11 )
        goto error;

    conn->p_display = vaGetDisplay(conn->p_display_x11);
    if( !conn->p_display )
        goto error;

    if( vaInitialize(conn->p_display, &conn->i_version_major, &conn->i_version_minor) )
        goto error;
81

82
    conn->i_ref_count++;
83
    return conn;
84 85

error:
86
    return NULL;
87 88
}

89 90
void vlc_va_Terminate( vlc_va_conn_t *conn )
{
91
    assert(conn);
92

93
    conn->i_ref_count--;
94 95
    if (conn->i_ref_count > 0)
        return;
96

97 98 99 100
    if( conn->p_display )
        vaTerminate( conn->p_display );
    if( conn->p_display_x11 )
        XCloseDisplay( conn->p_display_x11 );
101

102 103 104 105 106 107
    /* Reset values */
    conn->p_display = 0;
    conn->p_display_x11 = NULL;
    conn->i_version_major = conn->i_version_minor = 0;
    conn->i_ref_count = 0;
    conn = NULL;
108 109
}

110
#endif