Import py-vorbis, a set of Python bindings for the vorbis libraries.

With fixes from Debian's patchset for python-pyvorbis.

OK landry@
This commit is contained in:
dcoppa 2011-05-31 09:19:45 +00:00
parent 620481c51a
commit 7af88817c7
12 changed files with 541 additions and 0 deletions

50
audio/py-vorbis/Makefile Normal file
View File

@ -0,0 +1,50 @@
# $OpenBSD: Makefile,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
SHARED_ONLY = Yes
COMMENT = Python wrapper for the Vorbis libraries
MODPY_EGG_VERSION=1.4
DISTNAME = pyvorbis-${MODPY_EGG_VERSION}
PKGNAME = ${DISTNAME:S/py/py-/}
CATEGORIES = audio
HOMEPAGE = http://ekyo.nerim.net/software/pyogg/
# LGPL
PERMIT_PACKAGE_CDROM = Yes
PERMIT_PACKAGE_FTP = Yes
PERMIT_DISTFILES_CDROM =Yes
PERMIT_DISTFILES_FTP = Yes
MASTER_SITES = ${HOMEPAGE}
WANTLIB = ogg vorbis vorbisenc vorbisfile
MODULES = lang/python
BUILD_DEPENDS = audio/py-ogg
LIB_DEPENDS = audio/libogg \
audio/libvorbis
RUN_DEPENDS = ${BUILD_DEPENDS} \
audio/py-ao
NO_REGRESS = Yes
MODPY_ADJ_FILES = test/comment.py \
test/enc.py \
test/enc2.py \
test/ogg123.py \
test/short.py
EXAMPLESDIR = ${PREFIX}/share/examples/py-vorbis
do-configure:
@cd ${WRKSRC} && ${MODPY_BIN} ./config_unix.py --prefix ${PREFIX}
post-install:
${INSTALL_DATA_DIR} ${EXAMPLESDIR}
${INSTALL_DATA} ${WRKSRC}/test/*.py ${EXAMPLESDIR}
.include <bsd.port.mk>

5
audio/py-vorbis/distinfo Normal file
View File

@ -0,0 +1,5 @@
MD5 (pyvorbis-1.4.tar.gz) = tJIeeSwKdPdbnTBX3xDufA==
RMD160 (pyvorbis-1.4.tar.gz) = wukh9fbetOvj/zrIAX8PRMcztas=
SHA1 (pyvorbis-1.4.tar.gz) = 34P6gjGG1KG4WGA3yZXB1z65FyA=
SHA256 (pyvorbis-1.4.tar.gz) = pxVFQc6lgwT+/zB1IkPquGITHHWJ1ywgDIrXItO/Fkc=
SIZE (pyvorbis-1.4.tar.gz) = 39045

View File

@ -0,0 +1,23 @@
$OpenBSD: patch-setup_py,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Fix linking with vorbis libraries
--- setup.py.orig Tue Jun 1 17:58:01 2010
+++ setup.py Tue Jun 1 17:58:39 2010
@@ -43,7 +43,6 @@ data = get_setup()
vorbis_include_dir = data['vorbis_include_dir']
vorbis_lib_dir = data['vorbis_lib_dir']
-vorbis_libs = string.split(data['vorbis_libs'])
ogg_include_dir = data['ogg_include_dir']
ogg_lib_dir = data['ogg_lib_dir']
@@ -61,7 +60,7 @@ vorbismodule = Extension(name='vorbis',
ogg_include_dir],
library_dirs=[vorbis_lib_dir,
ogg_lib_dir],
- libraries=vorbis_libs)
+ libraries=['vorbis', 'vorbisfile', 'vorbisenc', 'ogg'])
setup ( name = "pyvorbis",
version = pyvorbis_version,

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-src_general_h,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Avoid unused symbol warnings from the static callbacks defined in
vorbisfile.h (see http://svn.xiph.org/trunk/vorbis/CHANGES)
--- src/general.h.orig Tue Jun 8 11:31:58 2010
+++ src/general.h Tue Jun 8 11:32:34 2010
@@ -7,6 +7,8 @@
#define MSG_SIZE 256
#define KEY_SIZE 1024
+#define OV_EXCLUDE_STATIC_CALLBACKS
+
#define PY_UNICODE (PY_VERSION_HEX >= 0x01060000)
ogg_int64_t arg_to_64(PyObject *longobj);

View File

@ -0,0 +1,177 @@
$OpenBSD: patch-src_pyvorbiscodec_c,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Fixes for python2.5 memory management
(from Debian's patchset for python-pyvorbis)
--- src/pyvorbiscodec.c.orig Tue May 13 10:17:13 2003
+++ src/pyvorbiscodec.c Fri May 27 10:36:17 2011
@@ -29,7 +29,6 @@ FDEF(dsp_write_wav) "Write audio data to the dsp devic
FDEF(dsp_close) "Signal that all audio data has been written to the object.";
FDEF(vorbis_bitrate_flushpacket) "";
-static void py_dsp_dealloc(PyObject *);
static PyObject *py_dsp_getattr(PyObject *, char*);
char py_dsp_doc[] = "";
@@ -82,14 +81,11 @@ static PyMethodDef DSP_methods[] = {
};
PyObject *
-py_dsp_from_dsp(vorbis_dsp_state *vd, PyObject *parent)
+py_dsp_alloc(PyObject *parent)
{
- py_dsp *ret = (py_dsp *) PyObject_NEW(py_dsp, &py_dsp_type);
-
+ py_dsp *ret = (py_dsp *) PyObject_New(py_dsp, &py_dsp_type);
if (ret == NULL)
return NULL;
-
- ret->vd = *vd;
ret->parent = parent;
Py_XINCREF(parent);
return (PyObject *) ret;
@@ -100,25 +96,23 @@ py_dsp_new(PyObject *self, PyObject *args)
{
py_vinfo* py_vi;
py_dsp *ret;
- vorbis_info *vi;
- vorbis_dsp_state vd;
if (!PyArg_ParseTuple(args, "O!", &py_vinfo_type, &py_vi))
return NULL;
- ret = (py_dsp *) PyObject_NEW(py_dsp, &py_dsp_type);
- ret->parent = NULL;
- vi = &py_vi->vi;
- vorbis_synthesis_init(&vd, vi);
- return py_dsp_from_dsp(&vd, (PyObject *) py_vi);
+ ret = (py_dsp *) py_dsp_alloc((PyObject*) py_vi);
+ if (ret == NULL)
+ return NULL;
+ vorbis_synthesis_init(&ret->vd, &py_vi->vi);
+ return (PyObject *) ret;
}
-static void
+void
py_dsp_dealloc(PyObject *self)
{
vorbis_dsp_clear(PY_DSP(self));
Py_XDECREF(((py_dsp *)self)->parent);
- PyMem_DEL(self);
+ PyObject_Del(self);
}
static PyObject*
@@ -127,21 +121,26 @@ py_dsp_getattr(PyObject *self, char *name)
return Py_FindMethod(DSP_methods, self, name);
}
+static void py_block_dealloc(PyObject *);
+PyObject * py_block_alloc(PyObject *parent);
+
static PyObject *
py_vorbis_analysis_blockout(PyObject *self, PyObject *args)
{
- vorbis_block vb;
- int ret;
py_dsp *dsp_self = (py_dsp *) self;
+ py_block* py_vb;
if (!PyArg_ParseTuple(args, ""))
return NULL;
- vorbis_block_init(&dsp_self->vd, &vb);
- ret = vorbis_analysis_blockout(&dsp_self->vd, &vb);
- if (ret == 1)
- return py_block_from_block(&vb, self);
+ py_vb = (py_block*) py_block_alloc(self);
+ if (py_vb == NULL)
+ return NULL;
+
+ if (vorbis_analysis_blockout(&dsp_self->vd, &py_vb->vb) == 1)
+ return (PyObject*) py_vb;
else {
+ py_block_dealloc((PyObject*) py_vb);
Py_INCREF(Py_None);
return Py_None;
}
@@ -207,16 +206,16 @@ py_vorbis_analysis_headerout(PyObject *self, PyObject
static PyObject *
py_vorbis_block_init(PyObject *self, PyObject *args)
{
- vorbis_block vb;
- py_dsp *dsp_self = (py_dsp *) self;
- PyObject *ret;
+ py_block *py_vb;
if (!PyArg_ParseTuple(args, ""))
return NULL;
- vorbis_block_init(&dsp_self->vd,&vb);
- ret = py_block_from_block(&vb, self);
- return ret;
+ py_vb = (py_block*) py_block_alloc(self);
+ if (py_vb == NULL)
+ return NULL;
+
+ return (PyObject*) py_vb;
}
/* Returns "len" if all arguments are strings of the same length,
@@ -397,7 +396,6 @@ py_vorbis_bitrate_flushpacket(PyObject *self, PyObject
/*********************************************************
VorbisBlock
*********************************************************/
-static void py_block_dealloc(PyObject *);
static PyObject *py_block_getattr(PyObject *, char*);
FDEF(vorbis_analysis) "Output an OggPage.";
@@ -442,12 +440,25 @@ static PyMethodDef Block_methods[] = {
{NULL, NULL}
};
+PyObject *
+py_block_alloc(PyObject *parent)
+{
+ py_block *ret = (py_block *) PyObject_New(py_block,
+ &py_block_type);
+ if (ret == NULL)
+ return NULL;
+ vorbis_block_init(PY_DSP(parent), PY_BLOCK(ret));
+ ret->parent = parent;
+ Py_XINCREF(parent);
+ return (PyObject *)ret;
+}
+
static void
py_block_dealloc(PyObject *self)
{
vorbis_block_clear(PY_BLOCK(self));
Py_XDECREF(((py_block *)self)->parent);
- PyMem_DEL(self);
+ PyObject_Del(self);
}
static PyObject*
@@ -488,20 +499,4 @@ py_vorbis_bitrate_addblock(PyObject *self, PyObject *a
Py_INCREF(Py_None);
return Py_None;
}
-
-PyObject *
-py_block_from_block(vorbis_block *vb, PyObject *parent)
-{
- py_block *ret = (py_block *) PyObject_NEW(py_block,
- &py_block_type);
- if (ret == NULL)
- return NULL;
-
- ret->vb = *vb;
- ret->parent = parent;
- Py_XINCREF(parent);
- return (PyObject *)ret;
-}
-
-

View File

@ -0,0 +1,18 @@
$OpenBSD: patch-src_pyvorbiscodec_h,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Fixes for python2.5 memory management
(from Debian's patchset for python-pyvorbis)
--- src/pyvorbiscodec.h.orig Mon Oct 7 01:04:59 2002
+++ src/pyvorbiscodec.h Tue Jun 8 08:21:46 2010
@@ -22,8 +22,8 @@ typedef struct {
extern PyTypeObject py_dsp_type;
extern PyTypeObject py_block_type;
-PyObject *py_dsp_from_dsp(vorbis_dsp_state *vd, PyObject *parent);
-PyObject *py_block_from_block(vorbis_block *vb, PyObject *parent);
+PyObject *py_dsp_alloc(PyObject *parent);
+void py_dsp_dealloc(PyObject *self);
#endif /* __VORBISCODEC_H__ */

View File

@ -0,0 +1,36 @@
$OpenBSD: patch-src_pyvorbisfile_c,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Fixes for python2.5 memory management
Fix redundant double free
(from Debian's patchset for python-pyvorbis)
--- src/pyvorbisfile.c.orig Fri Dec 19 08:11:02 2003
+++ src/pyvorbisfile.c Tue Jun 8 08:27:27 2010
@@ -171,10 +171,9 @@ py_file_new(PyObject *self, PyObject *args) /* change
ret = py_ov_open(newobj, args);
if (ret == NULL) {
- PyMem_DEL(newobj);
+ PyObject_Del(newobj);
return NULL;
- } else
- Py_DECREF(ret);
+ }
return (PyObject *) newobj;
}
@@ -190,12 +189,10 @@ py_ov_file_dealloc(PyObject *self)
/* If file was opened from a file object, decref it, so it can
close */
Py_DECREF(py_self->py_file);
- } else {
- /* Otherwise, we opened the file and should close it. */
- fclose(py_self->c_file);
}
- PyMem_DEL(self);
+ free(py_self->ovf);
+ PyObject_Del(self);
}
static PyObject *

View File

@ -0,0 +1,126 @@
$OpenBSD: patch-src_pyvorbisinfo_c,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Fixes for python2.5 memory management
(from Debian's patchset for python-pyvorbis)
--- src/pyvorbisinfo.c.orig Fri Dec 19 08:51:36 2003
+++ src/pyvorbisinfo.c Fri May 27 10:36:34 2011
@@ -72,7 +72,7 @@ PyObject*
py_info_new_from_vi(vorbis_info *vi)
{
py_vinfo *newobj;
- newobj = (py_vinfo *) PyObject_NEW(py_vinfo,
+ newobj = (py_vinfo *) PyObject_New(py_vinfo,
&py_vinfo_type);
newobj->vi = *vi;
return (PyObject *) newobj;
@@ -134,7 +134,7 @@ py_ov_info_clear(PyObject *self, PyObject *args)
static void
py_ov_info_dealloc(PyObject *self)
{
- PyMem_DEL(self);
+ PyObject_Del(self);
}
#define CMP_RET(x) \
@@ -225,17 +225,21 @@ static PyObject *
py_vorbis_analysis_init(PyObject *self, PyObject *args)
{
int res;
+ py_dsp *ret;
+ py_vinfo *py_vi = (py_vinfo *) self;
- py_vinfo *ovi_self = (py_vinfo *) self;
- vorbis_dsp_state vd;
-
if (!PyArg_ParseTuple(args, ""))
return NULL;
- if ((res = vorbis_analysis_init(&vd, &ovi_self->vi)))
- return v_error_from_code(res, "vorbis_analysis_init");
+ ret = (py_dsp *) py_dsp_alloc((PyObject*) py_vi);
+ if (ret == NULL)
+ return NULL;
- return py_dsp_from_dsp(&vd, self);
+ if ((res = vorbis_analysis_init(&ret->vd, &py_vi->vi))) {
+ py_dsp_dealloc((PyObject *) py_vi);
+ return v_error_from_code(res, "vorbis_analysis_init");
+ }
+ return (PyObject*) ret;
}
/*
@@ -300,7 +304,7 @@ static int py_comment_assign(py_vcomment *,
static PyObject *py_comment_subscript(py_vcomment *, PyObject *);
static PyMappingMethods py_vcomment_Mapping_Methods = {
- (inquiry) py_comment_length,
+ (lenfunc) py_comment_length,
(binaryfunc) py_comment_subscript,
(objobjargproc) py_comment_assign
};
@@ -360,7 +364,7 @@ py_comment_new_from_vc(vorbis_comment *vc, PyObject *p
{
py_vcomment *newobj;
- newobj = (py_vcomment *) PyObject_NEW(py_vcomment,
+ newobj = (py_vcomment *) PyObject_New(py_vcomment,
&py_vcomment_type);
newobj->vc = vc;
newobj->parent = parent;
@@ -373,7 +377,7 @@ static PyObject *
py_comment_new_empty(void)
{
py_vcomment *newobj;
- newobj = (py_vcomment *) PyObject_NEW(py_vcomment,
+ newobj = (py_vcomment *) PyObject_New(py_vcomment,
&py_vcomment_type);
if (!newobj)
return NULL;
@@ -418,7 +422,7 @@ py_vorbis_comment_dealloc(PyObject *self)
free(ovc_self->vc);
}
- PyMem_DEL(self);
+ PyObject_Del(self);
}
@@ -644,7 +648,8 @@ py_comment_keys(PyObject *self, PyObject *args)
static PyObject *
py_comment_items(PyObject *self, PyObject *args)
{
- int curitem, curpos, j;
+ Py_ssize_t curitem, curpos;
+ int j;
PyObject *key, *val, *curval, *tuple;
PyObject *retlist;
PyObject *dict;
@@ -682,7 +687,8 @@ py_comment_items(PyObject *self, PyObject *args)
static PyObject *
py_comment_values(PyObject *self, PyObject *args)
{
- int curitem, curpos, j;
+ Py_ssize_t curitem, curpos;
+ int j;
PyObject *key, *val, *curval;
PyObject *retlist;
PyObject *dict;
@@ -942,7 +948,7 @@ py_comment_new(PyObject *self, PyObject *args)
vcomment = create_comment_from_dict(dict);
if (!vcomment)
return NULL;
- pvc = (py_vcomment *) PyObject_NEW(py_vcomment,
+ pvc = (py_vcomment *) PyObject_New(py_vcomment,
&py_vcomment_type);
if (!pvc) {
vorbis_comment_clear(vcomment);
@@ -999,6 +1005,7 @@ py_comment_as_dict(PyObject *self, PyObject *args)
#if PY_UNICODE
item = PyUnicode_DecodeUTF8(val, vallen, NULL);
if (!item) {
+ PyErr_Clear();
/* To deal with non-UTF8 comments (against the standard) */
item = PyString_FromStringAndSize(val, vallen);
}

View File

@ -0,0 +1,65 @@
$OpenBSD: patch-test_ogg123_py,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
whrandom in python2.4 is deprecated, and in python2.5 is gone: use
the 'random' module which is a drop-in replacement
Use py-ao as backend
(from Debian's patchset for python-pyvorbis)
Use sndio as default libao backend
--- test/ogg123.py.orig Mon Oct 7 01:04:59 2002
+++ test/ogg123.py Tue Jun 8 08:24:59 2010
@@ -17,7 +17,7 @@ import sys
import string
import re
import os
-import whrandom
+import random
import time
import ogg.vorbis
@@ -98,7 +98,7 @@ class AOPlayer(Player):
def __init__(self, id=None):
import ao
if id is None:
- id = ao.driver_id('esd')
+ id = ao.driver_id('sndio')
self.dev = ao.AudioDevice(id)
def write(self, buff, bytes):
@@ -165,9 +165,10 @@ def main():
sys.exit(0)
elif arg == '-d' or arg == '--device':
+ import ao
try:
- driver_id = ao_get_driver_id(val)
- except aoError:
+ driver_id = ao.driver_id(val)
+ except ao.aoError:
sys.stderr.write('No such device %s\n' % val)
sys.exit(1)
@@ -188,7 +189,7 @@ def main():
verbose = 0
elif arg == '-z' or arg == '--shuffle':
- ri = whrandom.randrange
+ ri = random.randrange
for pos in range(len(args)):
newpos = ri(pos, len(args))
tmp = args[pos]
@@ -199,7 +200,12 @@ def main():
usage()
sys.exit(0)
- myplayer = choices[modchoice]() # Either AOPlayer or LADPlayer
+ if modchoice == 'ao' and driver_id:
+ playerargs = (driver_id,)
+ else:
+ playerargs = ()
+
+ myplayer = apply(choices[modchoice],playerargs) # Either AOPlayer or LADPlayer
if verbose:
print "Module choice: %s" % modchoice

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-test_short_py,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
Use sndio as default libao backend
--- test/short.py.orig Tue Jun 8 08:24:43 2010
+++ test/short.py Tue Jun 8 08:25:09 2010
@@ -6,7 +6,7 @@ import ogg.vorbis
import ao
filename = 'test.ogg'
-device = 'esd'
+device = 'sndio'
SIZE = 4096
vf = ogg.vorbis.VorbisFile(filename)

View File

@ -0,0 +1 @@
pyvorbis is a set of Python bindings for the vorbis libraries.

View File

@ -0,0 +1,9 @@
@comment $OpenBSD: PLIST,v 1.1.1.1 2011/05/31 09:19:45 dcoppa Exp $
lib/python${MODPY_VERSION}/site-packages/ogg/vorbis.so
lib/python${MODPY_VERSION}/site-packages/pyvorbis-${MODPY_EGG_VERSION}-py${MODPY_VERSION}.egg-info
share/examples/py-vorbis/
share/examples/py-vorbis/comment.py
share/examples/py-vorbis/enc.py
share/examples/py-vorbis/enc2.py
share/examples/py-vorbis/ogg123.py
share/examples/py-vorbis/short.py