File size: 1,688 Bytes
d82cf6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Wrapper for include/libswresample/swresample.h
"""
from ctypes import c_int, c_int64
from ctypes import c_uint8
from ctypes import c_void_p, POINTER, Structure

import pyglet.lib
from pyglet.util import debug_print
from . import compat

_debug = debug_print('debug_media')

swresample = pyglet.lib.load_library(
    'swresample',
    win32=('swresample-4', 'swresample-3'),
    darwin=('swresample.4', 'swresample.3')
)

swresample.swresample_version.restype = c_int

compat.set_version('swresample', swresample.swresample_version() >> 16)


SWR_CH_MAX = 32


class SwrContext(Structure):
    pass


swresample.swr_alloc_set_opts.restype = POINTER(SwrContext)
swresample.swr_alloc_set_opts.argtypes = [POINTER(SwrContext),
                                          c_int64, c_int, c_int, c_int64,
                                          c_int, c_int, c_int, c_void_p]
swresample.swr_init.restype = c_int
swresample.swr_init.argtypes = [POINTER(SwrContext)]
swresample.swr_free.argtypes = [POINTER(POINTER(SwrContext))]
swresample.swr_convert.restype = c_int
swresample.swr_convert.argtypes = [POINTER(SwrContext),
                                   POINTER(c_uint8) * SWR_CH_MAX,
                                   c_int,
                                   POINTER(POINTER(c_uint8)),
                                   c_int]
swresample.swr_set_compensation.restype = c_int
swresample.swr_set_compensation.argtypes = [POINTER(SwrContext),
                                            c_int, c_int]
swresample.swr_get_out_samples.restype = c_int
swresample.swr_get_out_samples.argtypes = [POINTER(SwrContext), c_int]

__all__ = [
    'swresample',
    'SWR_CH_MAX',
    'SwrContext'
]