File: amf_helper.c

package info (click to toggle)
vlc 3.0.21-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212,728 kB
  • sloc: ansic: 441,379; cpp: 110,628; objc: 36,394; sh: 6,946; makefile: 6,593; javascript: 4,902; xml: 1,611; asm: 1,355; yacc: 640; python: 555; lex: 88; perl: 77; sed: 16
file content (69 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: LGPL-2.1-or-later

// amf_helper.c: AMD Advanced Media Framework helper
// Copyright © 2024 VideoLabs, VLC authors and VideoLAN

// Authors: Steve Lhomme <robux4@videolabs.io>

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

#include "amf_helper.h"

#include <vlc_common.h>

int vlc_AMFCreateContext(struct vlc_amf_context *c)
{
#ifdef _WIN32
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
    HMODULE hLib = LoadLibraryA(AMF_DLL_NAMEA);
    if (hLib == NULL)
        return (-ENOTSUP);

    c->Version = 0;
    AMF_RESULT res;
    AMFQueryVersion_Fn queryVersion = (AMFQueryVersion_Fn)GetProcAddress(hLib, AMF_QUERY_VERSION_FUNCTION_NAME);
    if (unlikely(queryVersion == NULL))
        goto error;
    res = queryVersion(&c->Version);
    if (unlikely(res != AMF_OK))
        goto error;

    c->pFactory = NULL;
    c->Context = NULL;

    AMFInit_Fn init = (AMFInit_Fn)GetProcAddress(hLib, AMF_INIT_FUNCTION_NAME);
    res = init(AMF_FULL_VERSION, &c->pFactory);
    if (unlikely(res != AMF_OK))
        goto error;

    res = c->pFactory->pVtbl->CreateContext(c->pFactory, &c->Context);
    if (res != AMF_OK || c->Context == NULL)
        goto error;

    c->Private = hLib;
    return VLC_SUCCESS;

error:
    FreeLibrary(hLib);
    return (-ENOTSUP);

# else // !WINAPI_PARTITION_DESKTOP
    // we can't load external DLLs in UWP
    return (-ENOTSUP);
# endif // !WINAPI_PARTITION_DESKTOP

#else
    return NULL; // TODO
#endif
}

void vlc_AMFReleaseContext(struct vlc_amf_context *c)
{
    c->Context->pVtbl->Terminate(c->Context);
    c->Context->pVtbl->Release(c->Context);
#ifdef _WIN32
    FreeLibrary(c->Private);
#endif
}