directx_va.h 4.22 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
/*****************************************************************************
 * directx_va.h: DirectX Generic Video Acceleration helpers
 *****************************************************************************
 * Copyright (C) 2009 Geoffroy Couprie
 * Copyright (C) 2009 Laurent Aimar
 * Copyright (C) 2015 Steve Lhomme
 * $Id$
 *
 * Authors: Geoffroy Couprie <geal@videolan.org>
 *          Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *          Steve Lhomme <robux4@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 *****************************************************************************/

#ifndef AVCODEC_DIRECTX_VA_H
#define AVCODEC_DIRECTX_VA_H

31
# if _WIN32_WINNT < _WIN32_WINNT_VISTA
32 33
/* d3d11 needs Vista support */
#  undef _WIN32_WINNT
34
#  define _WIN32_WINNT _WIN32_WINNT_VISTA
35 36 37 38 39 40 41 42
# endif

#include <vlc_common.h>

#include <libavcodec/avcodec.h>
#include "va.h"

#include <unknwn.h>
43
#include <stdatomic.h>
44 45

/* */
46
struct vlc_va_surface_t {
47
    atomic_uintptr_t     refcount;
48
    D3D_DecoderSurface *decoderSurface;
49
};
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

typedef struct input_list_t {
    void (*pf_release)(struct input_list_t *);
    GUID *list;
    unsigned count;
} input_list_t;

#define MAX_SURFACE_COUNT (64)
typedef struct
{
    int          codec_id;
    int          width;
    int          height;

    /* DLL */
    HINSTANCE             hdecoder_dll;
    const TCHAR           *psz_decoder_dll;

    /* Direct3D */
69
    D3D_Device            *d3ddev;
70 71 72

    /* Video service */
    GUID                   input;
73
    D3D_DecoderDevice      *d3ddec;
74 75

    /* Video decoder */
76
    D3D_DecoderType        *decoder;
77 78

    /* */
79
    unsigned     surface_count;
80 81 82
    int          surface_width;
    int          surface_height;

83
    vlc_va_surface_t     *surface[MAX_SURFACE_COUNT];
84
    D3D_DecoderSurface  *hw_surface[MAX_SURFACE_COUNT];
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    /**
     * Check that the decoder device is still available
     */
    int (*pf_check_device)(vlc_va_t *);

    int (*pf_create_device)(vlc_va_t *);
    void (*pf_destroy_device)(vlc_va_t *);

    int (*pf_create_device_manager)(vlc_va_t *);
    void (*pf_destroy_device_manager)(vlc_va_t *);

    int (*pf_create_video_service)(vlc_va_t *);
    void (*pf_destroy_video_service)(vlc_va_t *);

    /**
     * Read the list of possible input GUIDs
     */
    int (*pf_get_input_list)(vlc_va_t *, input_list_t *);
    /**
     * Find a suitable decoder configuration for the input and set the
     * internal state to use that output
     */
108
    int (*pf_setup_output)(vlc_va_t *, const GUID *input, const video_format_t *fmt);
109 110 111 112 113

    /**
     * Create the DirectX surfaces in hw_surface and the decoder in decoder
     */
    int (*pf_create_decoder_surfaces)(vlc_va_t *, int codec_id,
114 115
                                      const video_format_t *fmt,
                                      unsigned surface_count);
116
    /**
117
     * Destroy resources allocated with the surfaces and the associated decoder
118 119 120 121 122 123 124 125 126
     */
    void (*pf_destroy_surfaces)(vlc_va_t *);
    /**
     * Set the avcodec hw context after the decoder is created
     */
    void (*pf_setup_avcodec_ctx)(vlc_va_t *);

} directx_sys_t;

127
int directx_va_Open(vlc_va_t *, directx_sys_t *, AVCodecContext *ctx, const es_format_t *fmt, bool b_dll);
128
void directx_va_Close(vlc_va_t *, directx_sys_t *);
129
int directx_va_Setup(vlc_va_t *, directx_sys_t *, AVCodecContext *avctx);
130
vlc_va_surface_t *directx_va_Get(vlc_va_t *, directx_sys_t *);
131
void directx_va_AddRef(vlc_va_surface_t *surface);
132
void directx_va_Release(vlc_va_surface_t *surface);
133
char *directx_va_GetDecoderName(const GUID *guid);
134 135

#endif /* AVCODEC_DIRECTX_VA_H */