Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 0801e41

Browse files
committed
Initial commit
0 parents  commit 0801e41

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: build
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest, macos-latest]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.8
17+
- name: Build codecs
18+
env:
19+
CIBW_BEFORE_BUILD: scripts/build-codecs /tmp/vendor
20+
CIBW_BUILD: cp38-*
21+
CIBW_TEST_COMMAND: python -c "import dummy"
22+
run: |
23+
pip install cibuildwheel
24+
cibuildwheel --output-dir output
25+
rm -f output/*.whl
26+
shell: bash
27+
- name: Upload codecs
28+
uses: actions/upload-artifact@v1
29+
with:
30+
name: output
31+
path: output/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.egg-info
2+
*.pyc
3+
*.so

scripts/build-codecs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
3+
set -xe
4+
5+
if [ -z "$1" ]; then
6+
echo "Usage: $0 <prefix>"
7+
exit 1
8+
fi
9+
10+
destdir=$1
11+
12+
builddir=`pwd`/build
13+
sourcedir=`pwd`/source
14+
15+
for d in $builddir $destdir; do
16+
if [ -e $d ]; then
17+
rm -rf $d
18+
fi
19+
done
20+
21+
extract() {
22+
path=$builddir/$1
23+
url=$2
24+
tarball=$sourcedir/`echo $url | sed -e 's/.*\///'`
25+
26+
if [ ! -e $tarball ]; then
27+
curl -L -o $tarball $url
28+
fi
29+
30+
mkdir $path
31+
tar xf $tarball -C $path --strip-components 1
32+
}
33+
34+
if [ "`uname`" = "Linux" ]; then
35+
outputdir=/output
36+
outputfile=$outputdir/codecs-manylinux_$(uname -m).tar.bz2
37+
elif [ "`uname`" = "Darwin" ]; then
38+
outputdir=`pwd`/output
39+
outputfile=$outputdir/codecs-macosx_$(uname -m).tar.bz2
40+
else
41+
echo "Unknown platform"
42+
exit 1
43+
fi
44+
45+
mkdir -p $outputdir
46+
if [ ! -e $outputfile ]; then
47+
mkdir $builddir
48+
mkdir -p $sourcedir
49+
cd $builddir
50+
51+
# build vpx
52+
extract vpx https://github.com/webmproject/libvpx/archive/v1.8.2.tar.gz
53+
cd vpx
54+
./configure --prefix=$destdir --disable-examples --disable-tools --disable-unit-tests --enable-pic
55+
make -j
56+
make install
57+
cd ..
58+
59+
# build opus
60+
extract opus https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
61+
cd opus
62+
./configure --prefix=$destdir --disable-shared --enable-static --with-pic
63+
make -j
64+
make install
65+
cd ..
66+
67+
tar cjvf $outputfile -C $destdir include lib
68+
fi

setup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import setuptools
2+
import sys
3+
4+
if sys.platform == "win32":
5+
include_dirs = ["C:\\cibw\\vendor\\include"]
6+
library_dirs = ["C:\\cibw\\vendor\\lib"]
7+
else:
8+
include_dirs = ["/tmp/vendor/include"]
9+
library_dirs = ["/tmp/vendor/lib"]
10+
11+
setuptools.setup(
12+
name="dummy",
13+
package_dir={"": "src"},
14+
packages=["dummy"],
15+
ext_modules=[
16+
setuptools.Extension(
17+
"dummy.binding",
18+
include_dirs=include_dirs,
19+
library_dirs=library_dirs,
20+
libraries=["opus", "vpx",],
21+
sources=["src/dummy/binding.c"],
22+
),
23+
],
24+
)

src/dummy/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .binding import test
2+
3+
test()

src/dummy/binding.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <stdio.h>
2+
#include <Python.h>
3+
4+
#include <opus/opus.h>
5+
6+
#include <vpx/vpx_decoder.h>
7+
#include <vpx/vp8dx.h>
8+
9+
10+
#define MODULE_NAME "dummy.binding"
11+
12+
static PyObject*
13+
test(PyObject *args)
14+
{
15+
OpusDecoder *opus_decoder;
16+
int opus_error;
17+
vpx_codec_ctx_t vpx_decoder;
18+
vpx_codec_err_t vpx_error;
19+
20+
// check opus
21+
opus_decoder = opus_decoder_create(48000, 2, &opus_error);
22+
if (opus_error != OPUS_OK) {
23+
PyErr_SetString(PyExc_RuntimeError, "opus_decoder_create failed");
24+
return NULL;
25+
}
26+
opus_decoder_destroy(opus_decoder);
27+
28+
// check vpx
29+
vpx_error = vpx_codec_dec_init(&vpx_decoder, vpx_codec_vp8_dx(), NULL, 0);
30+
if (vpx_error != VPX_CODEC_OK) {
31+
PyErr_SetString(PyExc_RuntimeError, "vpx_codec_dec_init failed");
32+
return NULL;
33+
}
34+
vpx_codec_destroy(&vpx_decoder);
35+
36+
fprintf(stderr, "Codecs are OK\n");
37+
38+
Py_RETURN_NONE;
39+
}
40+
41+
static PyMethodDef module_methods[] = {
42+
{"test", (PyCFunction)test, METH_NOARGS, ""},
43+
{NULL}
44+
};
45+
46+
static struct PyModuleDef moduledef = {
47+
PyModuleDef_HEAD_INIT,
48+
MODULE_NAME, /* m_name */
49+
"Dummy bindings for opus and vpx.", /* m_doc */
50+
-1, /* m_size */
51+
module_methods, /* m_methods */
52+
NULL, /* m_reload */
53+
NULL, /* m_traverse */
54+
NULL, /* m_clear */
55+
NULL, /* m_free */
56+
};
57+
58+
PyMODINIT_FUNC
59+
PyInit_binding(void)
60+
{
61+
PyObject* m;
62+
63+
m = PyModule_Create(&moduledef);
64+
if (m == NULL)
65+
return NULL;
66+
67+
return m;
68+
}

0 commit comments

Comments
 (0)