]> git.sesse.net Git - vlc/blob - modules/codec/avcodec/va.c
avcodec: do not overwrite libavcodec internal AVCodec data
[vlc] / modules / codec / avcodec / va.c
1 /*****************************************************************************
2  * va.c: hardware acceleration plugins for avcodec
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * Copyright (C) 2012-2013 RĂ©mi Denis-Courmont
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20  *****************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include <vlc_common.h>
27 #include <vlc_modules.h>
28 #include <libavcodec/avcodec.h>
29 #include "va.h"
30
31 static int vlc_va_Start(void *func, va_list ap)
32 {
33     vlc_va_t *va = va_arg(ap, vlc_va_t *);
34     AVCodecContext *ctx = va_arg(ap, AVCodecContext *);
35     const es_format_t *fmt = va_arg(ap, const es_format_t *);
36     int (*open)(vlc_va_t *, AVCodecContext *, const es_format_t *) = func;
37
38     return open(va, ctx, fmt);
39 }
40
41 static void vlc_va_Stop(void *func, va_list ap)
42 {
43     vlc_va_t *va = va_arg(ap, vlc_va_t *);
44     void (*close)(vlc_va_t *) = func;
45
46     close(va);
47 }
48
49 vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
50                      const es_format_t *fmt)
51 {
52     vlc_va_t *va = vlc_object_create(obj, sizeof (*va));
53     if (unlikely(va == NULL))
54         return NULL;
55
56     va->module = vlc_module_load(va, "hw decoder", "$avcodec-hw", true,
57                                  vlc_va_Start, va, avctx, fmt);
58     if (va->module == NULL)
59     {
60         vlc_object_release(va);
61         va = NULL;
62     }
63     return va;
64 }
65
66 void vlc_va_Delete(vlc_va_t *va)
67 {
68     vlc_module_unload(va->module, vlc_va_Stop, va);
69     vlc_object_release(va);
70 }