[xiph-commits] r7250 - in trunk/py-ogg2: . src
arc at dactyl.lonelymoon.com
arc
Wed Jul 21 14:42:27 PDT 2004
Author: arc
Date: Wed Jul 21 14:42:27 2004
New Revision: 7250
Added:
trunk/py-ogg2/src/module.c
trunk/py-ogg2/src/module.h
trunk/py-ogg2/src/packbuff.c
trunk/py-ogg2/src/packbuff.h
trunk/py-ogg2/src/packet.c
trunk/py-ogg2/src/packet.h
trunk/py-ogg2/src/page.c
trunk/py-ogg2/src/page.h
trunk/py-ogg2/src/stream.c
trunk/py-ogg2/src/stream.h
trunk/py-ogg2/src/sync.c
trunk/py-ogg2/src/sync.h
Removed:
trunk/py-ogg2/src/_ogg2module.c
trunk/py-ogg2/src/_ogg2module.h
trunk/py-ogg2/src/pyoggpackbuff.c
trunk/py-ogg2/src/pyoggpackbuff.h
trunk/py-ogg2/src/pyoggpacket.c
trunk/py-ogg2/src/pyoggpacket.h
trunk/py-ogg2/src/pyoggpage.c
trunk/py-ogg2/src/pyoggpage.h
trunk/py-ogg2/src/pyoggstreamstate.c
trunk/py-ogg2/src/pyoggstreamstate.h
trunk/py-ogg2/src/pyoggsyncstate.c
trunk/py-ogg2/src/pyoggsyncstate.h
Modified:
trunk/py-ogg2/setup.py
Log:
Huge cleanup.. shorter filenames, no more pysrc or __init__.py needed,
just one file needs to be installed now. Much easier to maintain..
Modified: trunk/py-ogg2/setup.py
===================================================================
--- trunk/py-ogg2/setup.py 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/setup.py 2004-07-21 21:42:26 UTC (rev 7250)
@@ -40,13 +40,13 @@
ogg_lib_dir = data['ogg_lib_dir']
ogg_libs = string.split(data['ogg_libs'])
-_ogg2module = Extension(name='ogg2',
+ogg2module = Extension(name='ogg2',
sources=['src/module.c',
'src/packet.c',
- 'src/streamstate.c',
+ 'src/stream.c',
'src/page.c',
'src/packbuff.c',
- 'src/syncstate.c',
+ 'src/sync.c',
'src/general.c'],
define_macros = [('VERSION_MAJOR', VERSION_MAJOR),
('VERSION_MINOR', VERSION_MINOR),
@@ -64,7 +64,7 @@
url = "NONEYET",
headers = [],
- packages = ['ogg2'],
- package_dir = {'ogg2' : 'pysrc'},
- ext_package = 'ogg2',
- ext_modules = [_ogg2module] )
+# packages = ['ogg2'],
+# package_dir = {'ogg2' : 'pysrc'},
+ ext_package = '',
+ ext_modules = [ogg2module] )
Deleted: trunk/py-ogg2/src/_ogg2module.c
===================================================================
--- trunk/py-ogg2/src/_ogg2module.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/_ogg2module.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,60 +0,0 @@
-#include <ogg2/ogg.h>
-
-#include "general.h"
-#include "_ogg2module.h"
-
-#include "pyoggstreamstate.h"
-#include "pyoggsyncstate.h"
-#include "pyoggpacket.h"
-#include "pyoggpackbuff.h"
-#include "pyoggpage.h"
-
-static PyMethodDef Ogg_methods[] = {
- {"OggPackBuff", PyOggPackBuffer_New,
- METH_VARARGS, PyOggPackBuffer_Doc},
- {"OggPackBuffB", PyOggPackBuffer_NewB,
- METH_VARARGS, PyOggPackBuffer_Doc},
- {"OggStreamState", PyOggStreamState_New,
- METH_VARARGS, PyOggStreamState_Doc},
- {"OggSyncState", PyOggSyncState_New,
- METH_VARARGS, PyOggSyncState_Doc},
- {NULL, NULL}
-};
-
-static char docstring[] = "";
-
-void
-initogg2(void)
-{
- PyObject *module, *dict, *Py_module_info;
-
- PyOggPackBuffer_Type.ob_type = &PyType_Type;
- PyOggPacket_Type.ob_type = &PyType_Type;
- PyOggPage_Type.ob_type = &PyType_Type;
- PyOggStreamState_Type.ob_type = &PyType_Type;
- PyOggSyncState_Type.ob_type = &PyType_Type;
-
- module = Py_InitModule("ogg2", Ogg_methods);
- dict = PyModule_GetDict(module);
-
- PyOgg_Error = PyErr_NewException("ogg2.OggError", NULL, NULL);
- PyDict_SetItemString(dict, "OggError", PyOgg_Error);
- Py_INCREF(PyOgg_Error);
-
- PyOggPage_Error = PyErr_NewException("ogg2.OggPageError", PyOgg_Error, NULL);
- PyDict_SetItemString(dict, "OggPageError", PyOggPage_Error);
- Py_INCREF(PyOggPage_Error);
-
- PyOggPacket_Error = PyErr_NewException("ogg2.OggPacketError", PyOgg_Error, NULL);
- PyDict_SetItemString(dict, "OggPacketError", PyOggPacket_Error);
- Py_INCREF(PyOggPacket_Error);
-
- PyModule_AddStringConstant(module, "__doc__", docstring);
- PyModule_AddStringConstant(module, "__version__", "2.0-pre_20040721");
-
- PyModule_AddIntConstant(module, "Ogg_Cont", OGG_CONT);
- PyModule_AddIntConstant(module, "Ogg_Discont", OGG_DISCONT);
-
- if (PyErr_Occurred())
- PyErr_SetString(PyExc_ImportError, "ogg2: init failed");
-}
Deleted: trunk/py-ogg2/src/_ogg2module.h
===================================================================
--- trunk/py-ogg2/src/_ogg2module.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/_ogg2module.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,16 +0,0 @@
-#ifndef __OGG2MODULE_H__
-#define __OGG2MODULE_H__
-
-#include <Python.h>
-
-PyObject *PyOgg_Error;
-PyObject *PyOggPage_Error;
-PyObject *PyOggPacket_Error;
-
-/* Object docstrings */
-
-extern char PyOggStreamState_Doc[];
-extern char PyOggPackBuffer_Doc[];
-extern char PyOggSyncState_Doc[];
-
-#endif /* __OGG2MODULE_H__ */
Copied: trunk/py-ogg2/src/module.c (from rev 7248, trunk/py-ogg2/src/_ogg2module.c)
===================================================================
--- trunk/py-ogg2/src/_ogg2module.c 2004-07-21 21:20:18 UTC (rev 7248)
+++ trunk/py-ogg2/src/module.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,60 @@
+#include <ogg2/ogg.h>
+
+#include "general.h"
+#include "module.h"
+
+#include "stream.h"
+#include "sync.h"
+#include "packet.h"
+#include "packbuff.h"
+#include "page.h"
+
+static PyMethodDef Ogg_methods[] = {
+ {"OggPackBuff", PyOggPackBuffer_New,
+ METH_VARARGS, PyOggPackBuffer_Doc},
+ {"OggPackBuffB", PyOggPackBuffer_NewB,
+ METH_VARARGS, PyOggPackBuffer_Doc},
+ {"OggStreamState", PyOggStreamState_New,
+ METH_VARARGS, PyOggStreamState_Doc},
+ {"OggSyncState", PyOggSyncState_New,
+ METH_VARARGS, PyOggSyncState_Doc},
+ {NULL, NULL}
+};
+
+static char docstring[] = "";
+
+void
+initogg2(void)
+{
+ PyObject *module, *dict, *Py_module_info;
+
+ PyOggPackBuffer_Type.ob_type = &PyType_Type;
+ PyOggPacket_Type.ob_type = &PyType_Type;
+ PyOggPage_Type.ob_type = &PyType_Type;
+ PyOggStreamState_Type.ob_type = &PyType_Type;
+ PyOggSyncState_Type.ob_type = &PyType_Type;
+
+ module = Py_InitModule("ogg2", Ogg_methods);
+ dict = PyModule_GetDict(module);
+
+ PyOgg_Error = PyErr_NewException("ogg2.OggError", NULL, NULL);
+ PyDict_SetItemString(dict, "OggError", PyOgg_Error);
+ Py_INCREF(PyOgg_Error);
+
+ PyOggPage_Error = PyErr_NewException("ogg2.OggPageError", PyOgg_Error, NULL);
+ PyDict_SetItemString(dict, "OggPageError", PyOggPage_Error);
+ Py_INCREF(PyOggPage_Error);
+
+ PyOggPacket_Error = PyErr_NewException("ogg2.OggPacketError", PyOgg_Error, NULL);
+ PyDict_SetItemString(dict, "OggPacketError", PyOggPacket_Error);
+ Py_INCREF(PyOggPacket_Error);
+
+ PyModule_AddStringConstant(module, "__doc__", docstring);
+ PyModule_AddStringConstant(module, "__version__", "2.0-pre_20040721");
+
+ PyModule_AddIntConstant(module, "Ogg_Cont", OGG_CONT);
+ PyModule_AddIntConstant(module, "Ogg_Discont", OGG_DISCONT);
+
+ if (PyErr_Occurred())
+ PyErr_SetString(PyExc_ImportError, "ogg2: init failed");
+}
Copied: trunk/py-ogg2/src/module.h (from rev 7192, trunk/py-ogg2/src/_ogg2module.h)
Copied: trunk/py-ogg2/src/packbuff.c (from rev 7192, trunk/py-ogg2/src/pyoggpackbuff.c)
===================================================================
--- trunk/py-ogg2/src/pyoggpackbuff.c 2004-07-20 16:10:06 UTC (rev 7192)
+++ trunk/py-ogg2/src/packbuff.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,387 @@
+#include "packbuff.h"
+#include "packet.h"
+#include "general.h"
+#include "module.h"
+
+/************************************************************
+ OggPackBuffer Object
+************************************************************/
+
+char PyOggPackBuffer_Doc[] = "";
+
+static void PyOggPackBuffer_Dealloc(PyObject *);
+static PyObject* PyOggPackBuffer_Getattr(PyObject *, char *);
+static PyObject *PyOggPackBuffer_Repr(PyObject *self);
+
+FDEF(PyOggPackBuffer_Bytes) "Return the number of bytes in the buffer";
+FDEF(PyOggPackBuffer_Bits) "Return the number of bits in the buffer";
+
+FDEF(PyOggPackBuffer_Read) "Return the value of n bits";
+FDEF(PyOggPackBuffer_Look) "Return the value of n bits without advancing pointer";
+FDEF(PyOggPackBuffer_Adv) "Advance the read location by n bits";
+
+FDEF(PyOggPackBuffer_Reset) "Clears and resets the packet buffer";
+FDEF(PyOggPackBuffer_Packetout) "Export the OggPacket built by the buffer";
+FDEF(PyOggPackBuffer_Write) "Write bits to the buffer.\n\n\
+The first parameter is an integer from which the bits will be extracted.\n\
+The second parameter is the number of bits to write (defaults to 1)";
+
+PyTypeObject PyOggPackBuffer_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "Oggpack_Buffer",
+ sizeof(PyOggPackBufferObject),
+ 0,
+
+ /* Standard Methods */
+ /* (destructor) */ PyOggPackBuffer_Dealloc,
+ /* (printfunc) */ 0,
+ /* (getattrfunc) */ PyOggPackBuffer_Getattr,
+ /* (setattrfunc) */ 0,
+ /* (cmpfunc) */ 0,
+ /* (reprfunc) */ PyOggPackBuffer_Repr,
+
+ /* Type Categories */
+ 0, /* as number */
+ 0, /* as sequence */
+ 0, /* as mapping */
+ 0, /* hash */
+ 0, /* binary */
+ 0, /* repr */
+ 0, /* getattro */
+ 0, /* setattro */
+ 0, /* as buffer */
+ 0, /* tp_flags */
+ PyOggPackBuffer_Doc
+};
+
+static PyMethodDef PyOggPackBuffer_Read_Methods[] = {
+ {"bytes", PyOggPackBuffer_Bytes,
+ METH_VARARGS, PyOggPackBuffer_Bytes_Doc},
+ {"bits", PyOggPackBuffer_Bits,
+ METH_VARARGS, PyOggPackBuffer_Bits_Doc},
+ {"look", PyOggPackBuffer_Look,
+ METH_VARARGS, PyOggPackBuffer_Look_Doc},
+ {"read", PyOggPackBuffer_Read,
+ METH_VARARGS, PyOggPackBuffer_Read_Doc},
+ {"adv", PyOggPackBuffer_Adv,
+ METH_VARARGS, PyOggPackBuffer_Adv_Doc},
+ {NULL, NULL}
+};
+
+static PyMethodDef PyOggPackBuffer_Write_Methods[] = {
+ {"bytes", PyOggPackBuffer_Bytes,
+ METH_VARARGS, PyOggPackBuffer_Bytes_Doc},
+ {"bits", PyOggPackBuffer_Bits,
+ METH_VARARGS, PyOggPackBuffer_Bits_Doc},
+ {"reset", PyOggPackBuffer_Reset,
+ METH_VARARGS, PyOggPackBuffer_Reset_Doc},
+ {"write", PyOggPackBuffer_Write,
+ METH_VARARGS, PyOggPackBuffer_Write_Doc},
+ {"packetout", PyOggPackBuffer_Packetout,
+ METH_VARARGS, PyOggPackBuffer_Packetout_Doc},
+ {NULL, NULL}
+};
+
+
+PyObject *
+PyOggPackBuffer_New(PyObject *self, PyObject *args)
+{
+ PyOggPacketObject *packetobj;
+ PyOggPackBufferObject *ret;
+
+ packetobj = NULL;
+
+ if ( !PyArg_ParseTuple(args, "|O!", &PyOggPacket_Type,
+ (PyObject *) &packetobj) ) return NULL;
+
+ ret = (PyOggPackBufferObject *) PyObject_NEW(PyOggPackBufferObject,
+ &PyOggPackBuffer_Type);
+ if (ret == NULL) return NULL;
+ ret->msb_flag = 0;
+ PyOggPackBuffer_AsOggPackBuffer(ret) = PyMem_Malloc(oggpack_buffersize());
+
+ if ( packetobj ) {
+ ret->write_flag = 0;
+ ret->packetobj = packetobj; /* Must keep packet around for now! */
+ Py_INCREF(((PyOggPackBufferObject *) ret)->packetobj);
+ oggpack_readinit(PyOggPackBuffer_AsOggPackBuffer(ret),
+ PyOggPacket_AsOggPacket(packetobj)->packet);
+ return (PyObject *)ret;
+ }
+ ret->write_flag = 1;
+ oggpack_writeinit(PyOggPackBuffer_AsOggPackBuffer(ret),
+ ogg_buffer_create());
+ return (PyObject *)ret;
+}
+
+
+PyObject *
+PyOggPackBuffer_NewB(PyObject *self, PyObject *args)
+{
+ PyOggPacketObject *packetobj;
+ PyOggPackBufferObject *ret;
+
+ packetobj = NULL;
+
+ if ( !PyArg_ParseTuple(args, "|O!", &PyOggPacket_Type,
+ (PyObject *) &packetobj) ) return NULL;
+
+ ret = (PyOggPackBufferObject *) PyObject_NEW(PyOggPackBufferObject,
+ &PyOggPackBuffer_Type);
+ if (ret == NULL) return NULL;
+ ret->msb_flag = 1;
+ PyOggPackBuffer_AsOggPackBuffer(ret) = PyMem_Malloc(oggpack_buffersize());
+
+ if ( packetobj ) {
+ ret->write_flag = 0;
+ ret->packetobj = packetobj; /* Must keep packet around for now! */
+ Py_INCREF(((PyOggPackBufferObject *) ret)->packetobj);
+ oggpack_readinit(PyOggPackBuffer_AsOggPackBuffer(ret),
+ PyOggPacket_AsOggPacket(packetobj)->packet);
+ return (PyObject *)ret;
+ }
+ ret->write_flag = 1;
+ oggpack_writeinit(PyOggPackBuffer_AsOggPackBuffer(ret),
+ ogg_buffer_create());
+ return (PyObject *)ret;
+}
+
+
+static void
+PyOggPackBuffer_Dealloc(PyObject *self)
+{
+ if ( ((PyOggPackBufferObject *) self)->write_flag ) {
+ if ( ((PyOggPackBufferObject *) self)->write_flag == 1 ) {
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+ }
+ }
+ else /* Release the packet being read */
+ Py_DECREF(((PyOggPackBufferObject *) self)->packetobj);
+ PyMem_Free(PyOggPackBuffer_AsOggPackBuffer(self));
+ PyObject_DEL(self);
+}
+
+static PyObject*
+PyOggPackBuffer_Getattr(PyObject *self, char *name)
+{
+ if ( !((PyOggPackBufferObject *) self)->write_flag )
+ return Py_FindMethod(PyOggPackBuffer_Read_Methods, self, name);
+ else {
+ if ( ((PyOggPackBufferObject *) self)->write_flag == 2) {
+ PyErr_SetString(PyExc_ValueError, "DEAD BUFFER!");
+ return NULL;
+ }
+ return Py_FindMethod(PyOggPackBuffer_Write_Methods, self, name);
+ }
+}
+
+
+static PyObject *
+PyOggPackBuffer_Bytes(PyObject *self, PyObject *args)
+{
+ long ret;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ ret = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+ return PyLong_FromLong(ret);
+}
+
+static PyObject *
+PyOggPackBuffer_Bits(PyObject *self, PyObject *args)
+{
+ long ret;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_bits(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ ret = oggpack_bits(PyOggPackBuffer_AsOggPackBuffer(self));
+ return PyLong_FromLong(ret);
+}
+
+
+static PyObject *
+PyOggPackBuffer_Reset(PyObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Look(PyObject *self, PyObject *args)
+{
+ int bits = 1;
+ long num;
+ long ret;
+ if (!PyArg_ParseTuple(args, "l", &bits))
+ return NULL;
+
+ if ( bits == 1 ) {
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_look1(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ ret = oggpack_look1(PyOggPackBuffer_AsOggPackBuffer(self));
+ return PyLong_FromLong(ret);
+ }
+
+ if (bits > 32) {
+ PyErr_SetString(PyExc_ValueError, "Cannot look at more than 32 bits");
+ return NULL;
+ }
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_look(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
+ else
+ ret = oggpack_look(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
+ if ( ret == 0 )
+ return PyLong_FromLong(num);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Read(PyObject *self, PyObject *args)
+{
+ int bits = 1;
+ long num;
+ long ret;
+
+ if (!PyArg_ParseTuple(args, "|i", &bits))
+ return NULL;
+
+ if ( bits == 1 ) {
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_read1(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ ret = oggpack_read1(PyOggPackBuffer_AsOggPackBuffer(self));
+ return PyInt_FromLong(ret);
+ }
+
+ if (bits > 32) {
+ PyErr_SetString(PyExc_ValueError, "Cannot read more than 32 bits");
+ return NULL;
+ }
+
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ ret = oggpackB_read(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
+ else
+ ret = oggpack_read(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
+ if ( ret == 0 )
+ return PyInt_FromLong(num);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Adv(PyObject *self, PyObject *args)
+{
+ int bits = 1;
+
+ if (!PyArg_ParseTuple(args, "|i", &bits))
+ return NULL;
+
+ if ( bits == 1 )
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ oggpackB_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ oggpack_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
+ else
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ oggpackB_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);
+ else
+ oggpack_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Write(PyObject *self, PyObject *args)
+{
+ long val;
+ int bits = 32;
+
+ if (!PyArg_ParseTuple(args, "l|l", &val, &bits))
+ return NULL;
+
+ if (bits > 32) {
+ PyErr_SetString(PyExc_ValueError, "Cannot write more than 32 bits");
+ return NULL;
+ }
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag )
+ oggpackB_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);
+ else
+ oggpack_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Packetout(PyObject *self, PyObject *args)
+{
+ ogg_packet *op;
+ PyOggPacketObject *packetobj;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ packetobj = PyOggPacket_Alloc();
+ op = packetobj->packet;
+
+ if ( ((PyOggPackBufferObject *) self)->msb_flag ) {
+ op->packet = oggpackB_writebuffer(PyOggPackBuffer_AsOggPackBuffer(self));
+ op->bytes = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+ } else {
+ op->packet = oggpackB_writebuffer(PyOggPackBuffer_AsOggPackBuffer(self));
+ op->bytes = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+ }
+ op->b_o_s = 0;
+ op->e_o_s = 0;
+ op->granulepos = 0;
+ op->packetno = 0;
+
+ ((PyOggPackBufferObject *) self)->write_flag = 2;
+ return (PyObject *) packetobj;
+}
+
+
+static PyObject *
+PyOggPackBuffer_Repr(PyObject *self)
+{
+ oggpack_buffer *ob = PyOggPackBuffer_AsOggPackBuffer(self);
+ char buf[256];
+
+ if ( ((PyOggPackBufferObject *) self)->write_flag == 2 ) {
+ PyErr_SetString(PyExc_ValueError, "DEAD BUFFER!");
+ return NULL;
+ }
+ sprintf(buf, "<OggPackBuff at %p>", self);
+ return PyString_FromString(buf);
+}
+
Copied: trunk/py-ogg2/src/packbuff.h (from rev 7192, trunk/py-ogg2/src/pyoggpackbuff.h)
===================================================================
--- trunk/py-ogg2/src/pyoggpackbuff.h 2004-07-20 16:10:06 UTC (rev 7192)
+++ trunk/py-ogg2/src/packbuff.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,21 @@
+#ifndef PYOGGPACKBUFF_H
+#define PYOGGPACKBUFF_H
+
+#include "packet.h"
+
+typedef struct {
+ PyObject_HEAD
+ int msb_flag; /* 0 = LSb (standard), 1 = MSb */
+ int write_flag; /* 0 = read, 1 = write, 2 = dead write */
+ oggpack_buffer *buffer;
+ PyOggPacketObject *packetobj; /* temporary workaround */
+} PyOggPackBufferObject;
+
+#define PyOggPackBuffer_AsOggPackBuffer(x) ( ((PyOggPackBufferObject *) (x))->buffer )
+
+extern PyTypeObject PyOggPackBuffer_Type;
+
+PyObject *PyOggPackBuffer_New(PyObject *, PyObject *);
+PyObject *PyOggPackBuffer_NewB(PyObject *, PyObject *);
+
+#endif
Copied: trunk/py-ogg2/src/packet.c (from rev 7192, trunk/py-ogg2/src/pyoggpacket.c)
===================================================================
--- trunk/py-ogg2/src/pyoggpacket.c 2004-07-20 16:10:06 UTC (rev 7192)
+++ trunk/py-ogg2/src/packet.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,188 @@
+#include "packet.h"
+#include "general.h"
+#include "module.h"
+
+/************************************************************
+ OggPacket Object
+ ************************************************************/
+
+char PyOggPacket_Doc[] = "";
+
+static void PyOggPacket_Dealloc(PyObject *);
+static PyObject* PyOggPacket_Getattr(PyObject *, char *);
+static int PyOggPacket_Setattr(PyObject *, char *, PyObject *);
+static PyObject *PyOggPacket_Repr(PyObject *self);
+static int PyOggPacket_Size(PyObject *self);
+
+PySequenceMethods PyOggPacket_SeqMethods = {
+ PyOggPacket_Size, /* (length) */
+ 0, /* (concat) */
+ 0, /* (repeat) */
+ 0, /* (item) */
+ 0, /* (slice) */
+ 0, /* (ass_item) */
+ 0, /* (ass_slice) */
+ 0, /* (contains) */
+ 0, /* (inplace_concat) */
+ 0, /* (inplace_repeat) */
+};
+
+PyTypeObject PyOggPacket_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "OggPacket",
+ sizeof(PyOggPacketObject),
+ 0,
+
+ /* Standard Methods */
+ PyOggPacket_Dealloc, /* (destructor) */
+ 0, /* (printfunc) */
+ PyOggPacket_Getattr, /* (getattrfunc) */
+ PyOggPacket_Setattr, /* (setattrfunc) */
+ 0, /* (cmpfunc) */
+ PyOggPacket_Repr, /* (reprfunc) */
+
+ /* Type Categories */
+ 0, /* as number */
+ &PyOggPacket_SeqMethods, /* as sequence */
+ 0, /* as mapping */
+ 0, /* hash */
+ 0, /* binary */
+ 0, /* repr */
+ 0, /* getattro */
+ 0, /* setattro */
+ 0, /* as buffer */
+ 0, /* tp_flags */
+ PyOggPacket_Doc
+};
+
+static PyMethodDef PyOggPacket_methods[] = {
+ {"bos", NULL, NULL},
+ {"eos", NULL, NULL},
+ {"granulepos", NULL, NULL},
+ {"packetno", NULL, NULL},
+ {NULL, NULL}
+};
+
+PyOggPacketObject *
+PyOggPacket_Alloc()
+{
+ ogg_packet *packet;
+ PyOggPacketObject *ret;
+
+ ret = (PyOggPacketObject *) PyObject_NEW(PyOggPacketObject,
+ &PyOggPacket_Type);
+ if (ret == NULL)
+ return NULL;
+
+ ret->valid_flag = 1;
+
+ ret->packet = PyMem_New(ogg_packet, 1);
+ if (ret->packet == NULL) {
+ PyObject_Del(ret);
+ return NULL;
+ }
+ memset(ret->packet, 0, sizeof(ogg_packet));
+ return ret;
+}
+
+
+static void
+PyOggPacket_Dealloc(PyObject *self)
+{
+ ogg_packet_release(PyOggPacket_AsOggPacket(self));
+ PyMem_Del(PyOggPacket_AsOggPacket(self));
+ PyObject_DEL(self);
+}
+
+static int
+PyOggPacket_Size(PyObject *self) {
+
+ if (((PyOggPacketObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
+ return -1;
+ }
+
+ return PyOggPacket_AsOggPacket(self)->bytes;
+}
+
+static PyObject*
+PyOggPacket_Getattr(PyObject *self, char *name)
+{
+ if (((PyOggPacketObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
+ return NULL;
+ }
+
+ if (strcmp(name, "bos") == 0)
+ return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->b_o_s);
+ if (strcmp(name, "eos") == 0)
+ return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->e_o_s);
+ if (strcmp(name, "granulepos") == 0)
+ return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->granulepos);
+ if (strcmp(name, "packetno") == 0)
+ return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->packetno);
+ return Py_FindMethod(PyOggPacket_methods, self, name);
+}
+
+static int
+PyOggPacket_Setattr(PyObject *self, char *name, PyObject *value)
+{
+ if (((PyOggPacketObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
+ return -1;
+ }
+ if (strcmp(name, "bos") == 0) {
+ ogg_int32_t v;
+ if (!arg_to_int32(value, &v))
+ return -1;
+ PyOggPacket_AsOggPacket(self)->b_o_s = v;
+ return 0;
+ }
+ if (strcmp(name, "eos") == 0) {
+ ogg_int32_t v;
+ if (!arg_to_int32(value, &v))
+ return -1;
+ PyOggPacket_AsOggPacket(self)->e_o_s = v;
+ return 0;
+ }
+ if (strcmp(name, "granulepos") == 0) {
+ ogg_int64_t v;
+ if (!arg_to_int64(value, &v))
+ return -1;
+ PyOggPacket_AsOggPacket(self)->granulepos = v;
+ return 0;
+ }
+ if (strcmp(name, "packetno") == 0) {
+ ogg_int64_t v;
+ if (!arg_to_int64(value, &v))
+ return -1;
+ PyOggPacket_AsOggPacket(self)->packetno = v;
+ return 0;
+ }
+
+ return -1;
+}
+
+static PyObject *
+PyOggPacket_Repr(PyObject *self)
+{
+ char buf[256];
+ char *bos;
+ char *eos;
+
+ if (((PyOggPacketObject *) self)->valid_flag == 0) {
+ sprintf(buf, "<OggPacket that has been passed back to libogg2>");
+ return PyString_FromString(buf);
+ }
+
+ bos = PyOggPacket_AsOggPacket(self)->b_o_s ? "BOS, " : "";
+ eos = PyOggPacket_AsOggPacket(self)->e_o_s ? "EOS, " : "";
+ sprintf(buf, "<OggPacket, %s%spacketno = %lld, granulepos = %lld,"
+ " length = %ld at %p (%p)>", bos, eos,
+ PyOggPacket_AsOggPacket(self)->packetno,
+ PyOggPacket_AsOggPacket(self)->granulepos,
+ PyOggPacket_AsOggPacket(self)->bytes, self,
+ PyOggPacket_AsOggPacket(self)->packet);
+ return PyString_FromString(buf);
+}
Copied: trunk/py-ogg2/src/packet.h (from rev 7192, trunk/py-ogg2/src/pyoggpacket.h)
Copied: trunk/py-ogg2/src/page.c (from rev 7192, trunk/py-ogg2/src/pyoggpage.c)
===================================================================
--- trunk/py-ogg2/src/pyoggpage.c 2004-07-20 16:10:06 UTC (rev 7192)
+++ trunk/py-ogg2/src/page.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,292 @@
+#include "general.h"
+#include "module.h"
+#include "page.h"
+
+/*****************************************************************
+ OggPage Object
+ *****************************************************************/
+
+
+char PyOggPage_Doc[] = "This is an Ogg Page.";
+
+static void PyOggPage_Dealloc(PyObject *);
+static PyObject* PyOggPage_Getattr(PyObject *, char *);
+static int PyOggPage_Setattr(PyObject *self, char *name, PyObject *value);
+static PyObject *PyOggPage_Repr(PyObject *self);
+static int PyOggPage_Size(PyObject *self);
+
+PySequenceMethods PyOggPage_SeqMethods = {
+ PyOggPage_Size, /* (length) */
+ 0, /* (concat) */
+ 0, /* (repeat) */
+ 0, /* (item) */
+ 0, /* (slice) */
+ 0, /* (ass_item) */
+ 0, /* (ass_slice) */
+ 0, /* (contains) */
+ 0, /* (inplace_concat) */
+ 0, /* (inplace_repeat) */
+};
+
+PyTypeObject PyOggPage_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "OggPage",
+ sizeof(PyOggPageObject),
+ 0,
+
+ /* Standard Methods */
+ PyOggPage_Dealloc, /* (destructor) */
+ 0, /* (printfunc) */
+ PyOggPage_Getattr, /* (getattrfunc) */
+ 0, /* (setattrfunc) */ /* disabled PyOggPage_Setattr, */
+ 0, /* (cmpfunc) */
+ PyOggPage_Repr, /* (reprfunc) */
+
+ /* Type Categories */
+ 0, /* as number */
+ &PyOggPage_SeqMethods,/* as sequence */
+ 0, /* as mapping */
+ 0, /* hash */
+ 0, /* binary */
+ 0, /* repr */
+ 0, /* getattro */
+ 0, /* setattro */
+ 0, /* as buffer */
+ 0, /* tp_flags */
+ PyOggPage_Doc
+};
+
+static PyMethodDef PyOggPage_methods[] = {
+ {"bos", NULL, NULL, NULL},
+ {"continued", NULL, NULL, NULL},
+ {"eos", NULL, NULL, NULL},
+ {"granulepos", NULL, NULL, NULL},
+ {"packets", NULL, NULL, NULL},
+ {"pageno", NULL, NULL, NULL},
+ {"serialno", NULL, NULL, NULL},
+ {"version", NULL, NULL, NULL},
+ {NULL, NULL}
+};
+
+PyOggPageObject *
+PyOggPage_Alloc() {
+ ogg_page *page;
+ PyOggPageObject *ret;
+
+ ret = (PyOggPageObject *) PyObject_NEW(PyOggPageObject, &PyOggPage_Type);
+ if (ret == NULL)
+ return NULL;
+
+ ret->valid_flag = 1;
+ page = PyMem_New(ogg_page, 1);
+ if (page == NULL) {
+ PyObject_Del(ret);
+ return NULL;
+ }
+ memset(page, 0, sizeof(*page));
+
+ ret->page = page;
+ return ret;
+}
+
+static void
+PyOggPage_Dealloc(PyObject *self) {
+ ogg_page_release(PyOggPage_AsOggPage(self));
+ PyMem_Del(PyOggPage_AsOggPage(self));
+ PyObject_Del(self);
+}
+
+
+static int
+PyOggPage_Size(PyObject *self) {
+
+ if (((PyOggPageObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+ return -1;
+ }
+
+ return PyOggPage_AsOggPage(self)->header_len +
+ PyOggPage_AsOggPage(self)->body_len;
+}
+
+static PyObject*
+PyOggPage_Getattr(PyObject *self, char *name) {
+ ogg_page *page;
+
+ if (((PyOggPageObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+ return NULL;
+ }
+
+ page = PyOggPage_AsOggPage(self);
+
+ if (strcmp(name, "bos") == 0)
+ return Py_TrueFalse(ogg_page_bos(page));
+ if (strcmp(name, "continued") == 0)
+ return Py_TrueFalse(ogg_page_continued(page));
+ if (strcmp(name, "eos") == 0)
+ return Py_TrueFalse(ogg_page_eos(page));
+ if (strcmp(name, "granulepos") == 0)
+ return PyLong_FromLongLong(ogg_page_granulepos(page));
+ if (strcmp(name, "packets") == 0)
+ return PyInt_FromLong(ogg_page_packets(page));
+ if (strcmp(name, "pageno") == 0)
+ return PyInt_FromLong(ogg_page_pageno(page));
+ if (strcmp(name, "serialno") == 0)
+ return PyInt_FromLong(ogg_page_serialno(page));
+ if (strcmp(name, "version") == 0)
+ return PyInt_FromLong(ogg_page_version(page));
+ return Py_FindMethod(PyOggPage_methods, self, name);
+}
+
+/* These are all horribly broken. Needs to be upgraded for libogg2. */
+
+static int
+PyOggPage_Setattr(PyObject *self, char *name, PyObject *value)
+{
+ char *head = (char *) PyOggPage_AsOggPage(self)->header;
+
+ if (strcmp(name, "bos") == 0) {
+ ogg_int64_t v;
+
+ if (!arg_to_int64(value, &v))
+ return -1;
+ if (!v) {
+ if (head[5] & 0x02) {
+ head[5] = head[5] & 0xFD;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ } else {
+ if (!(head[5] & 0x02)) {
+ head[5] = head[5] | 0x02;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ }
+ return 0;
+ }
+
+ if (strcmp(name, "continued") == 0) {
+ ogg_int64_t v;
+
+ if (!arg_to_int64(value, &v))
+ return -1;
+ if (!v) {
+ if (head[5] & 0x01) {
+ head[5] = head[5] & 0xFE;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ } else {
+ if (!(head[5] & 0x01)) {
+ head[5] = head[5] | 0x01;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ }
+ return 0;
+ }
+
+ if (strcmp(name, "eos") == 0) {
+ ogg_int64_t v;
+
+ if (!arg_to_int64(value, &v))
+ return -1;
+ if (!v) {
+ if (head[5] & 0x04) {
+ head[5] = head[5] & 0xFB;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ } else {
+ if (!(head[5] & 0x04)) {
+ head[5] = head[5] | 0x04;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ }
+ }
+ return 0;
+ }
+
+ if (strcmp(name, "granulepos") == 0) {
+ int i;
+ ogg_int64_t v;
+ if (!arg_to_int64(value, &v))
+ return -1;
+ for (i=6; i<14; i++) {
+ head[i] = v & 0xff;
+ v >>= 8;
+ }
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ return 0;
+ }
+
+ if (strcmp(name, "pageno") == 0) {
+ int i;
+ ogg_int32_t v;
+ if (!arg_to_int32(value, &v))
+ return -1;
+ for (i=18; i<22; i++) {
+ head[i] = v & 0xff;
+ v >>= 8;
+ }
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ return 0;
+ }
+
+ if (strcmp(name, "serialno") == 0) {
+ int i;
+ ogg_int32_t v;
+ if (!arg_to_int32(value, &v))
+ return -1;
+ for (i=14; i<18; i++) {
+ head[i] = v & 0xff;
+ v >>= 8;
+ }
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ return 0;
+ }
+
+ if (strcmp(name, "version") == 0) {
+ int i;
+ ogg_int32_t v;
+ if (!arg_to_int32(value, &v))
+ return -1;
+ if ( v<0 | v>255 ) {
+ PyErr_SetString(PyExc_ValueError, "version must be between 0 and 255");
+ return -1;
+ }
+ head[4] = v;
+ ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+ return 0;
+ }
+ PyErr_SetString(PyExc_AttributeError, "OggPage object has no such attribute");
+ return -1;
+}
+
+static PyObject *
+PyOggPage_Repr(PyObject *self)
+{
+ char buf[256];
+ char *bos;
+ char *eos;
+ char *cont;
+
+ if (((PyOggPageObject *) self)->valid_flag == 0) {
+ sprintf(buf, "<OggPage that has been passed back to libogg2>");
+ return PyString_FromString(buf);
+ }
+
+ bos = ogg_page_bos(PyOggPage_AsOggPage(self)) ? "BOS, " : "";
+ eos = ogg_page_eos(PyOggPage_AsOggPage(self)) ? "EOS, " : "";
+ cont = ogg_page_continued(PyOggPage_AsOggPage(self)) ? "CONT, " : "";
+ sprintf(buf, "<OggPage, %s%s%spageno = %ld, granulepos = %lld,"
+ " packets = %d, serialno = %d, version = %d,"
+ " head length = %ld, body length = %ld, at %p (%p)>",
+ cont, bos, eos, ogg_page_pageno(PyOggPage_AsOggPage(self)),
+ ogg_page_granulepos(PyOggPage_AsOggPage(self)),
+ ogg_page_packets(PyOggPage_AsOggPage(self)),
+ ogg_page_serialno(PyOggPage_AsOggPage(self)),
+ ogg_page_version(PyOggPage_AsOggPage(self)),
+ PyOggPage_AsOggPage(self)->header_len,
+ PyOggPage_AsOggPage(self)->body_len,
+ self, PyOggPage_AsOggPage(self));
+
+ return PyString_FromString(buf);
+}
Copied: trunk/py-ogg2/src/page.h (from rev 7192, trunk/py-ogg2/src/pyoggpage.h)
Deleted: trunk/py-ogg2/src/pyoggpackbuff.c
===================================================================
--- trunk/py-ogg2/src/pyoggpackbuff.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpackbuff.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,387 +0,0 @@
-#include "pyoggpackbuff.h"
-#include "pyoggpacket.h"
-#include "general.h"
-#include "_ogg2module.h"
-
-/************************************************************
- OggPackBuffer Object
-************************************************************/
-
-char PyOggPackBuffer_Doc[] = "";
-
-static void PyOggPackBuffer_Dealloc(PyObject *);
-static PyObject* PyOggPackBuffer_Getattr(PyObject *, char *);
-static PyObject *PyOggPackBuffer_Repr(PyObject *self);
-
-FDEF(PyOggPackBuffer_Bytes) "Return the number of bytes in the buffer";
-FDEF(PyOggPackBuffer_Bits) "Return the number of bits in the buffer";
-
-FDEF(PyOggPackBuffer_Read) "Return the value of n bits";
-FDEF(PyOggPackBuffer_Look) "Return the value of n bits without advancing pointer";
-FDEF(PyOggPackBuffer_Adv) "Advance the read location by n bits";
-
-FDEF(PyOggPackBuffer_Reset) "Clears and resets the packet buffer";
-FDEF(PyOggPackBuffer_Packetout) "Export the OggPacket built by the buffer";
-FDEF(PyOggPackBuffer_Write) "Write bits to the buffer.\n\n\
-The first parameter is an integer from which the bits will be extracted.\n\
-The second parameter is the number of bits to write (defaults to 1)";
-
-PyTypeObject PyOggPackBuffer_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
- "Oggpack_Buffer",
- sizeof(PyOggPackBufferObject),
- 0,
-
- /* Standard Methods */
- /* (destructor) */ PyOggPackBuffer_Dealloc,
- /* (printfunc) */ 0,
- /* (getattrfunc) */ PyOggPackBuffer_Getattr,
- /* (setattrfunc) */ 0,
- /* (cmpfunc) */ 0,
- /* (reprfunc) */ PyOggPackBuffer_Repr,
-
- /* Type Categories */
- 0, /* as number */
- 0, /* as sequence */
- 0, /* as mapping */
- 0, /* hash */
- 0, /* binary */
- 0, /* repr */
- 0, /* getattro */
- 0, /* setattro */
- 0, /* as buffer */
- 0, /* tp_flags */
- PyOggPackBuffer_Doc
-};
-
-static PyMethodDef PyOggPackBuffer_Read_Methods[] = {
- {"bytes", PyOggPackBuffer_Bytes,
- METH_VARARGS, PyOggPackBuffer_Bytes_Doc},
- {"bits", PyOggPackBuffer_Bits,
- METH_VARARGS, PyOggPackBuffer_Bits_Doc},
- {"look", PyOggPackBuffer_Look,
- METH_VARARGS, PyOggPackBuffer_Look_Doc},
- {"read", PyOggPackBuffer_Read,
- METH_VARARGS, PyOggPackBuffer_Read_Doc},
- {"adv", PyOggPackBuffer_Adv,
- METH_VARARGS, PyOggPackBuffer_Adv_Doc},
- {NULL, NULL}
-};
-
-static PyMethodDef PyOggPackBuffer_Write_Methods[] = {
- {"bytes", PyOggPackBuffer_Bytes,
- METH_VARARGS, PyOggPackBuffer_Bytes_Doc},
- {"bits", PyOggPackBuffer_Bits,
- METH_VARARGS, PyOggPackBuffer_Bits_Doc},
- {"reset", PyOggPackBuffer_Reset,
- METH_VARARGS, PyOggPackBuffer_Reset_Doc},
- {"write", PyOggPackBuffer_Write,
- METH_VARARGS, PyOggPackBuffer_Write_Doc},
- {"packetout", PyOggPackBuffer_Packetout,
- METH_VARARGS, PyOggPackBuffer_Packetout_Doc},
- {NULL, NULL}
-};
-
-
-PyObject *
-PyOggPackBuffer_New(PyObject *self, PyObject *args)
-{
- PyOggPacketObject *packetobj;
- PyOggPackBufferObject *ret;
-
- packetobj = NULL;
-
- if ( !PyArg_ParseTuple(args, "|O!", &PyOggPacket_Type,
- (PyObject *) &packetobj) ) return NULL;
-
- ret = (PyOggPackBufferObject *) PyObject_NEW(PyOggPackBufferObject,
- &PyOggPackBuffer_Type);
- if (ret == NULL) return NULL;
- ret->msb_flag = 0;
- PyOggPackBuffer_AsOggPackBuffer(ret) = PyMem_Malloc(oggpack_buffersize());
-
- if ( packetobj ) {
- ret->write_flag = 0;
- ret->packetobj = packetobj; /* Must keep packet around for now! */
- Py_INCREF(((PyOggPackBufferObject *) ret)->packetobj);
- oggpack_readinit(PyOggPackBuffer_AsOggPackBuffer(ret),
- PyOggPacket_AsOggPacket(packetobj)->packet);
- return (PyObject *)ret;
- }
- ret->write_flag = 1;
- oggpack_writeinit(PyOggPackBuffer_AsOggPackBuffer(ret),
- ogg_buffer_create());
- return (PyObject *)ret;
-}
-
-
-PyObject *
-PyOggPackBuffer_NewB(PyObject *self, PyObject *args)
-{
- PyOggPacketObject *packetobj;
- PyOggPackBufferObject *ret;
-
- packetobj = NULL;
-
- if ( !PyArg_ParseTuple(args, "|O!", &PyOggPacket_Type,
- (PyObject *) &packetobj) ) return NULL;
-
- ret = (PyOggPackBufferObject *) PyObject_NEW(PyOggPackBufferObject,
- &PyOggPackBuffer_Type);
- if (ret == NULL) return NULL;
- ret->msb_flag = 1;
- PyOggPackBuffer_AsOggPackBuffer(ret) = PyMem_Malloc(oggpack_buffersize());
-
- if ( packetobj ) {
- ret->write_flag = 0;
- ret->packetobj = packetobj; /* Must keep packet around for now! */
- Py_INCREF(((PyOggPackBufferObject *) ret)->packetobj);
- oggpack_readinit(PyOggPackBuffer_AsOggPackBuffer(ret),
- PyOggPacket_AsOggPacket(packetobj)->packet);
- return (PyObject *)ret;
- }
- ret->write_flag = 1;
- oggpack_writeinit(PyOggPackBuffer_AsOggPackBuffer(ret),
- ogg_buffer_create());
- return (PyObject *)ret;
-}
-
-
-static void
-PyOggPackBuffer_Dealloc(PyObject *self)
-{
- if ( ((PyOggPackBufferObject *) self)->write_flag ) {
- if ( ((PyOggPackBufferObject *) self)->write_flag == 1 ) {
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
- }
- }
- else /* Release the packet being read */
- Py_DECREF(((PyOggPackBufferObject *) self)->packetobj);
- PyMem_Free(PyOggPackBuffer_AsOggPackBuffer(self));
- PyObject_DEL(self);
-}
-
-static PyObject*
-PyOggPackBuffer_Getattr(PyObject *self, char *name)
-{
- if ( !((PyOggPackBufferObject *) self)->write_flag )
- return Py_FindMethod(PyOggPackBuffer_Read_Methods, self, name);
- else {
- if ( ((PyOggPackBufferObject *) self)->write_flag == 2) {
- PyErr_SetString(PyExc_ValueError, "DEAD BUFFER!");
- return NULL;
- }
- return Py_FindMethod(PyOggPackBuffer_Write_Methods, self, name);
- }
-}
-
-
-static PyObject *
-PyOggPackBuffer_Bytes(PyObject *self, PyObject *args)
-{
- long ret;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- ret = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
- return PyLong_FromLong(ret);
-}
-
-static PyObject *
-PyOggPackBuffer_Bits(PyObject *self, PyObject *args)
-{
- long ret;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_bits(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- ret = oggpack_bits(PyOggPackBuffer_AsOggPackBuffer(self));
- return PyLong_FromLong(ret);
-}
-
-
-static PyObject *
-PyOggPackBuffer_Reset(PyObject *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Look(PyObject *self, PyObject *args)
-{
- int bits = 1;
- long num;
- long ret;
- if (!PyArg_ParseTuple(args, "l", &bits))
- return NULL;
-
- if ( bits == 1 ) {
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_look1(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- ret = oggpack_look1(PyOggPackBuffer_AsOggPackBuffer(self));
- return PyLong_FromLong(ret);
- }
-
- if (bits > 32) {
- PyErr_SetString(PyExc_ValueError, "Cannot look at more than 32 bits");
- return NULL;
- }
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_look(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
- else
- ret = oggpack_look(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
- if ( ret == 0 )
- return PyLong_FromLong(num);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Read(PyObject *self, PyObject *args)
-{
- int bits = 1;
- long num;
- long ret;
-
- if (!PyArg_ParseTuple(args, "|i", &bits))
- return NULL;
-
- if ( bits == 1 ) {
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_read1(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- ret = oggpack_read1(PyOggPackBuffer_AsOggPackBuffer(self));
- return PyInt_FromLong(ret);
- }
-
- if (bits > 32) {
- PyErr_SetString(PyExc_ValueError, "Cannot read more than 32 bits");
- return NULL;
- }
-
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- ret = oggpackB_read(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
- else
- ret = oggpack_read(PyOggPackBuffer_AsOggPackBuffer(self), bits, &num);
- if ( ret == 0 )
- return PyInt_FromLong(num);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Adv(PyObject *self, PyObject *args)
-{
- int bits = 1;
-
- if (!PyArg_ParseTuple(args, "|i", &bits))
- return NULL;
-
- if ( bits == 1 )
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- oggpackB_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- oggpack_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
- else
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- oggpackB_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);
- else
- oggpack_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Write(PyObject *self, PyObject *args)
-{
- long val;
- int bits = 32;
-
- if (!PyArg_ParseTuple(args, "l|l", &val, &bits))
- return NULL;
-
- if (bits > 32) {
- PyErr_SetString(PyExc_ValueError, "Cannot write more than 32 bits");
- return NULL;
- }
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag )
- oggpackB_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);
- else
- oggpack_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Packetout(PyObject *self, PyObject *args)
-{
- ogg_packet *op;
- PyOggPacketObject *packetobj;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- packetobj = PyOggPacket_Alloc();
- op = packetobj->packet;
-
- if ( ((PyOggPackBufferObject *) self)->msb_flag ) {
- op->packet = oggpackB_writebuffer(PyOggPackBuffer_AsOggPackBuffer(self));
- op->bytes = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
- } else {
- op->packet = oggpackB_writebuffer(PyOggPackBuffer_AsOggPackBuffer(self));
- op->bytes = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
- }
- op->b_o_s = 0;
- op->e_o_s = 0;
- op->granulepos = 0;
- op->packetno = 0;
-
- ((PyOggPackBufferObject *) self)->write_flag = 2;
- return (PyObject *) packetobj;
-}
-
-
-static PyObject *
-PyOggPackBuffer_Repr(PyObject *self)
-{
- oggpack_buffer *ob = PyOggPackBuffer_AsOggPackBuffer(self);
- char buf[256];
-
- if ( ((PyOggPackBufferObject *) self)->write_flag == 2 ) {
- PyErr_SetString(PyExc_ValueError, "DEAD BUFFER!");
- return NULL;
- }
- sprintf(buf, "<OggPackBuff at %p>", self);
- return PyString_FromString(buf);
-}
-
Deleted: trunk/py-ogg2/src/pyoggpackbuff.h
===================================================================
--- trunk/py-ogg2/src/pyoggpackbuff.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpackbuff.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,21 +0,0 @@
-#ifndef PYOGGPACKBUFF_H
-#define PYOGGPACKBUFF_H
-
-#include "pyoggpacket.h"
-
-typedef struct {
- PyObject_HEAD
- int msb_flag; /* 0 = LSb (standard), 1 = MSb */
- int write_flag; /* 0 = read, 1 = write, 2 = dead write */
- oggpack_buffer *buffer;
- PyOggPacketObject *packetobj; /* temporary workaround */
-} PyOggPackBufferObject;
-
-#define PyOggPackBuffer_AsOggPackBuffer(x) ( ((PyOggPackBufferObject *) (x))->buffer )
-
-extern PyTypeObject PyOggPackBuffer_Type;
-
-PyObject *PyOggPackBuffer_New(PyObject *, PyObject *);
-PyObject *PyOggPackBuffer_NewB(PyObject *, PyObject *);
-
-#endif
Deleted: trunk/py-ogg2/src/pyoggpacket.c
===================================================================
--- trunk/py-ogg2/src/pyoggpacket.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpacket.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,188 +0,0 @@
-#include "pyoggpacket.h"
-#include "general.h"
-#include "_ogg2module.h"
-
-/************************************************************
- OggPacket Object
- ************************************************************/
-
-char PyOggPacket_Doc[] = "";
-
-static void PyOggPacket_Dealloc(PyObject *);
-static PyObject* PyOggPacket_Getattr(PyObject *, char *);
-static int PyOggPacket_Setattr(PyObject *, char *, PyObject *);
-static PyObject *PyOggPacket_Repr(PyObject *self);
-static int PyOggPacket_Size(PyObject *self);
-
-PySequenceMethods PyOggPacket_SeqMethods = {
- PyOggPacket_Size, /* (length) */
- 0, /* (concat) */
- 0, /* (repeat) */
- 0, /* (item) */
- 0, /* (slice) */
- 0, /* (ass_item) */
- 0, /* (ass_slice) */
- 0, /* (contains) */
- 0, /* (inplace_concat) */
- 0, /* (inplace_repeat) */
-};
-
-PyTypeObject PyOggPacket_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
- "OggPacket",
- sizeof(PyOggPacketObject),
- 0,
-
- /* Standard Methods */
- PyOggPacket_Dealloc, /* (destructor) */
- 0, /* (printfunc) */
- PyOggPacket_Getattr, /* (getattrfunc) */
- PyOggPacket_Setattr, /* (setattrfunc) */
- 0, /* (cmpfunc) */
- PyOggPacket_Repr, /* (reprfunc) */
-
- /* Type Categories */
- 0, /* as number */
- &PyOggPacket_SeqMethods, /* as sequence */
- 0, /* as mapping */
- 0, /* hash */
- 0, /* binary */
- 0, /* repr */
- 0, /* getattro */
- 0, /* setattro */
- 0, /* as buffer */
- 0, /* tp_flags */
- PyOggPacket_Doc
-};
-
-static PyMethodDef PyOggPacket_methods[] = {
- {"bos", NULL, NULL},
- {"eos", NULL, NULL},
- {"granulepos", NULL, NULL},
- {"packetno", NULL, NULL},
- {NULL, NULL}
-};
-
-PyOggPacketObject *
-PyOggPacket_Alloc()
-{
- ogg_packet *packet;
- PyOggPacketObject *ret;
-
- ret = (PyOggPacketObject *) PyObject_NEW(PyOggPacketObject,
- &PyOggPacket_Type);
- if (ret == NULL)
- return NULL;
-
- ret->valid_flag = 1;
-
- ret->packet = PyMem_New(ogg_packet, 1);
- if (ret->packet == NULL) {
- PyObject_Del(ret);
- return NULL;
- }
- memset(ret->packet, 0, sizeof(ogg_packet));
- return ret;
-}
-
-
-static void
-PyOggPacket_Dealloc(PyObject *self)
-{
- ogg_packet_release(PyOggPacket_AsOggPacket(self));
- PyMem_Del(PyOggPacket_AsOggPacket(self));
- PyObject_DEL(self);
-}
-
-static int
-PyOggPacket_Size(PyObject *self) {
-
- if (((PyOggPacketObject *) self)->valid_flag == 0) {
- PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
- return -1;
- }
-
- return PyOggPacket_AsOggPacket(self)->bytes;
-}
-
-static PyObject*
-PyOggPacket_Getattr(PyObject *self, char *name)
-{
- if (((PyOggPacketObject *) self)->valid_flag == 0) {
- PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
- return NULL;
- }
-
- if (strcmp(name, "bos") == 0)
- return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->b_o_s);
- if (strcmp(name, "eos") == 0)
- return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->e_o_s);
- if (strcmp(name, "granulepos") == 0)
- return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->granulepos);
- if (strcmp(name, "packetno") == 0)
- return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->packetno);
- return Py_FindMethod(PyOggPacket_methods, self, name);
-}
-
-static int
-PyOggPacket_Setattr(PyObject *self, char *name, PyObject *value)
-{
- if (((PyOggPacketObject *) self)->valid_flag == 0) {
- PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
- return -1;
- }
- if (strcmp(name, "bos") == 0) {
- ogg_int32_t v;
- if (!arg_to_int32(value, &v))
- return -1;
- PyOggPacket_AsOggPacket(self)->b_o_s = v;
- return 0;
- }
- if (strcmp(name, "eos") == 0) {
- ogg_int32_t v;
- if (!arg_to_int32(value, &v))
- return -1;
- PyOggPacket_AsOggPacket(self)->e_o_s = v;
- return 0;
- }
- if (strcmp(name, "granulepos") == 0) {
- ogg_int64_t v;
- if (!arg_to_int64(value, &v))
- return -1;
- PyOggPacket_AsOggPacket(self)->granulepos = v;
- return 0;
- }
- if (strcmp(name, "packetno") == 0) {
- ogg_int64_t v;
- if (!arg_to_int64(value, &v))
- return -1;
- PyOggPacket_AsOggPacket(self)->packetno = v;
- return 0;
- }
-
- return -1;
-}
-
-static PyObject *
-PyOggPacket_Repr(PyObject *self)
-{
- char buf[256];
- char *bos;
- char *eos;
-
- if (((PyOggPacketObject *) self)->valid_flag == 0) {
- sprintf(buf, "<OggPacket that has been passed back to libogg2>");
- return PyString_FromString(buf);
- }
-
- bos = PyOggPacket_AsOggPacket(self)->b_o_s ? "BOS, " : "";
- eos = PyOggPacket_AsOggPacket(self)->e_o_s ? "EOS, " : "";
- sprintf(buf, "<OggPacket, %s%spacketno = %lld, granulepos = %lld,"
- " length = %ld at %p (%p)>", bos, eos,
- PyOggPacket_AsOggPacket(self)->packetno,
- PyOggPacket_AsOggPacket(self)->granulepos,
- PyOggPacket_AsOggPacket(self)->bytes, self,
- PyOggPacket_AsOggPacket(self)->packet);
- return PyString_FromString(buf);
-}
Deleted: trunk/py-ogg2/src/pyoggpacket.h
===================================================================
--- trunk/py-ogg2/src/pyoggpacket.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpacket.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,18 +0,0 @@
-#ifndef PYOGGPACKET_H
-#define PYOGGPACKET_H
-
-#include "general.h"
-
-typedef struct {
- PyObject_HEAD
- int valid_flag;
- ogg_packet *packet;
-} PyOggPacketObject;
-
-extern PyTypeObject PyOggPacket_Type;
-
-#define PyOggPacket_AsOggPacket(x) ( ((PyOggPacketObject *) (x))->packet )
-
-PyOggPacketObject *PyOggPacket_Alloc(void);
-
-#endif /* PYOGGPACKET_H */
Deleted: trunk/py-ogg2/src/pyoggpage.c
===================================================================
--- trunk/py-ogg2/src/pyoggpage.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpage.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,292 +0,0 @@
-#include "general.h"
-#include "_ogg2module.h"
-#include "pyoggpage.h"
-
-/*****************************************************************
- OggPage Object
- *****************************************************************/
-
-
-char PyOggPage_Doc[] = "This is an Ogg Page.";
-
-static void PyOggPage_Dealloc(PyObject *);
-static PyObject* PyOggPage_Getattr(PyObject *, char *);
-static int PyOggPage_Setattr(PyObject *self, char *name, PyObject *value);
-static PyObject *PyOggPage_Repr(PyObject *self);
-static int PyOggPage_Size(PyObject *self);
-
-PySequenceMethods PyOggPage_SeqMethods = {
- PyOggPage_Size, /* (length) */
- 0, /* (concat) */
- 0, /* (repeat) */
- 0, /* (item) */
- 0, /* (slice) */
- 0, /* (ass_item) */
- 0, /* (ass_slice) */
- 0, /* (contains) */
- 0, /* (inplace_concat) */
- 0, /* (inplace_repeat) */
-};
-
-PyTypeObject PyOggPage_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
- "OggPage",
- sizeof(PyOggPageObject),
- 0,
-
- /* Standard Methods */
- PyOggPage_Dealloc, /* (destructor) */
- 0, /* (printfunc) */
- PyOggPage_Getattr, /* (getattrfunc) */
- 0, /* (setattrfunc) */ /* disabled PyOggPage_Setattr, */
- 0, /* (cmpfunc) */
- PyOggPage_Repr, /* (reprfunc) */
-
- /* Type Categories */
- 0, /* as number */
- &PyOggPage_SeqMethods,/* as sequence */
- 0, /* as mapping */
- 0, /* hash */
- 0, /* binary */
- 0, /* repr */
- 0, /* getattro */
- 0, /* setattro */
- 0, /* as buffer */
- 0, /* tp_flags */
- PyOggPage_Doc
-};
-
-static PyMethodDef PyOggPage_methods[] = {
- {"bos", NULL, NULL, NULL},
- {"continued", NULL, NULL, NULL},
- {"eos", NULL, NULL, NULL},
- {"granulepos", NULL, NULL, NULL},
- {"packets", NULL, NULL, NULL},
- {"pageno", NULL, NULL, NULL},
- {"serialno", NULL, NULL, NULL},
- {"version", NULL, NULL, NULL},
- {NULL, NULL}
-};
-
-PyOggPageObject *
-PyOggPage_Alloc() {
- ogg_page *page;
- PyOggPageObject *ret;
-
- ret = (PyOggPageObject *) PyObject_NEW(PyOggPageObject, &PyOggPage_Type);
- if (ret == NULL)
- return NULL;
-
- ret->valid_flag = 1;
- page = PyMem_New(ogg_page, 1);
- if (page == NULL) {
- PyObject_Del(ret);
- return NULL;
- }
- memset(page, 0, sizeof(*page));
-
- ret->page = page;
- return ret;
-}
-
-static void
-PyOggPage_Dealloc(PyObject *self) {
- ogg_page_release(PyOggPage_AsOggPage(self));
- PyMem_Del(PyOggPage_AsOggPage(self));
- PyObject_Del(self);
-}
-
-
-static int
-PyOggPage_Size(PyObject *self) {
-
- if (((PyOggPageObject *) self)->valid_flag == 0) {
- PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
- return -1;
- }
-
- return PyOggPage_AsOggPage(self)->header_len +
- PyOggPage_AsOggPage(self)->body_len;
-}
-
-static PyObject*
-PyOggPage_Getattr(PyObject *self, char *name) {
- ogg_page *page;
-
- if (((PyOggPageObject *) self)->valid_flag == 0) {
- PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
- return NULL;
- }
-
- page = PyOggPage_AsOggPage(self);
-
- if (strcmp(name, "bos") == 0)
- return Py_TrueFalse(ogg_page_bos(page));
- if (strcmp(name, "continued") == 0)
- return Py_TrueFalse(ogg_page_continued(page));
- if (strcmp(name, "eos") == 0)
- return Py_TrueFalse(ogg_page_eos(page));
- if (strcmp(name, "granulepos") == 0)
- return PyLong_FromLongLong(ogg_page_granulepos(page));
- if (strcmp(name, "packets") == 0)
- return PyInt_FromLong(ogg_page_packets(page));
- if (strcmp(name, "pageno") == 0)
- return PyInt_FromLong(ogg_page_pageno(page));
- if (strcmp(name, "serialno") == 0)
- return PyInt_FromLong(ogg_page_serialno(page));
- if (strcmp(name, "version") == 0)
- return PyInt_FromLong(ogg_page_version(page));
- return Py_FindMethod(PyOggPage_methods, self, name);
-}
-
-/* These are all horribly broken. Needs to be upgraded for libogg2. */
-
-static int
-PyOggPage_Setattr(PyObject *self, char *name, PyObject *value)
-{
- char *head = (char *) PyOggPage_AsOggPage(self)->header;
-
- if (strcmp(name, "bos") == 0) {
- ogg_int64_t v;
-
- if (!arg_to_int64(value, &v))
- return -1;
- if (!v) {
- if (head[5] & 0x02) {
- head[5] = head[5] & 0xFD;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- } else {
- if (!(head[5] & 0x02)) {
- head[5] = head[5] | 0x02;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- }
- return 0;
- }
-
- if (strcmp(name, "continued") == 0) {
- ogg_int64_t v;
-
- if (!arg_to_int64(value, &v))
- return -1;
- if (!v) {
- if (head[5] & 0x01) {
- head[5] = head[5] & 0xFE;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- } else {
- if (!(head[5] & 0x01)) {
- head[5] = head[5] | 0x01;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- }
- return 0;
- }
-
- if (strcmp(name, "eos") == 0) {
- ogg_int64_t v;
-
- if (!arg_to_int64(value, &v))
- return -1;
- if (!v) {
- if (head[5] & 0x04) {
- head[5] = head[5] & 0xFB;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- } else {
- if (!(head[5] & 0x04)) {
- head[5] = head[5] | 0x04;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- }
- }
- return 0;
- }
-
- if (strcmp(name, "granulepos") == 0) {
- int i;
- ogg_int64_t v;
- if (!arg_to_int64(value, &v))
- return -1;
- for (i=6; i<14; i++) {
- head[i] = v & 0xff;
- v >>= 8;
- }
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- return 0;
- }
-
- if (strcmp(name, "pageno") == 0) {
- int i;
- ogg_int32_t v;
- if (!arg_to_int32(value, &v))
- return -1;
- for (i=18; i<22; i++) {
- head[i] = v & 0xff;
- v >>= 8;
- }
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- return 0;
- }
-
- if (strcmp(name, "serialno") == 0) {
- int i;
- ogg_int32_t v;
- if (!arg_to_int32(value, &v))
- return -1;
- for (i=14; i<18; i++) {
- head[i] = v & 0xff;
- v >>= 8;
- }
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- return 0;
- }
-
- if (strcmp(name, "version") == 0) {
- int i;
- ogg_int32_t v;
- if (!arg_to_int32(value, &v))
- return -1;
- if ( v<0 | v>255 ) {
- PyErr_SetString(PyExc_ValueError, "version must be between 0 and 255");
- return -1;
- }
- head[4] = v;
- ogg_page_checksum_set(PyOggPage_AsOggPage(self));
- return 0;
- }
- PyErr_SetString(PyExc_AttributeError, "OggPage object has no such attribute");
- return -1;
-}
-
-static PyObject *
-PyOggPage_Repr(PyObject *self)
-{
- char buf[256];
- char *bos;
- char *eos;
- char *cont;
-
- if (((PyOggPageObject *) self)->valid_flag == 0) {
- sprintf(buf, "<OggPage that has been passed back to libogg2>");
- return PyString_FromString(buf);
- }
-
- bos = ogg_page_bos(PyOggPage_AsOggPage(self)) ? "BOS, " : "";
- eos = ogg_page_eos(PyOggPage_AsOggPage(self)) ? "EOS, " : "";
- cont = ogg_page_continued(PyOggPage_AsOggPage(self)) ? "CONT, " : "";
- sprintf(buf, "<OggPage, %s%s%spageno = %ld, granulepos = %lld,"
- " packets = %d, serialno = %d, version = %d,"
- " head length = %ld, body length = %ld, at %p (%p)>",
- cont, bos, eos, ogg_page_pageno(PyOggPage_AsOggPage(self)),
- ogg_page_granulepos(PyOggPage_AsOggPage(self)),
- ogg_page_packets(PyOggPage_AsOggPage(self)),
- ogg_page_serialno(PyOggPage_AsOggPage(self)),
- ogg_page_version(PyOggPage_AsOggPage(self)),
- PyOggPage_AsOggPage(self)->header_len,
- PyOggPage_AsOggPage(self)->body_len,
- self, PyOggPage_AsOggPage(self));
-
- return PyString_FromString(buf);
-}
Deleted: trunk/py-ogg2/src/pyoggpage.h
===================================================================
--- trunk/py-ogg2/src/pyoggpage.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggpage.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,18 +0,0 @@
-#ifndef PYOGG2PAGE_H
-#define PYOGG2PAGE_H
-
-#include "general.h"
-
-typedef struct {
- PyObject_HEAD
- int valid_flag;
- ogg_page *page;
-} PyOggPageObject;
-
-#define PyOggPage_AsOggPage(x) ( ((PyOggPageObject *) (x))->page )
-
-extern PyTypeObject PyOggPage_Type;
-
-PyOggPageObject *PyOggPage_Alloc(void);
-
-#endif
Deleted: trunk/py-ogg2/src/pyoggstreamstate.c
===================================================================
--- trunk/py-ogg2/src/pyoggstreamstate.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggstreamstate.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,367 +0,0 @@
-#include "_ogg2module.h"
-#include "pyoggstreamstate.h"
-#include "pyoggpacket.h"
-#include "pyoggpage.h"
-#include "general.h"
-
-/*****************************************************************
- OggStreamState Object
- *****************************************************************/
-
-
-char PyOggStreamState_Doc[] = "";
-
-static void PyOggStreamState_Dealloc(PyObject *);
-static PyObject* PyOggStreamState_Getattr(PyObject *, char *);
-static PyObject *PyOggStreamState_Repr(PyObject *self);
-
-FDEF(PyOggStreamState_Packetin) "Add a packet to the stream.";
-FDEF(PyOggStreamState_Pageout) "Extract and return an OggPage.";
-FDEF(PyOggStreamState_Flush) "Produce an ogg page suitable for writing to output.";
-FDEF(PyOggStreamState_Pagein) "Write a page to the stream";
-FDEF(PyOggStreamState_Packetout) "Extract a packet from the stream";
-FDEF(PyOggStreamState_Packetpeek) "Extract a packet from the stream";
-FDEF(PyOggStreamState_Reset) "Reset the stream state";
-FDEF(PyOggStreamState_Eos) "Return whether the end of the stream is reached.";
-FDEF(PyOggStreamState_Setmode) "Set stream mode for (dis)continuous.";
-
-PyTypeObject PyOggStreamState_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
- "OggStreamState",
- sizeof(PyOggStreamStateObject),
- 0,
-
- /* Standard Methods */
- /* (destructor) */ PyOggStreamState_Dealloc,
- /* (printfunc) */ 0,
- /* (getattrfunc) */ PyOggStreamState_Getattr,
- /* (setattrfunc) */ 0,
- /* (cmpfunc) */ 0,
- /* (reprfunc) */ PyOggStreamState_Repr,
-
- /* Type Categories */
- 0, /* as number */
- 0, /* as sequence */
- 0, /* as mapping */
- 0, /* hash */
- 0, /* binary */
- 0, /* repr */
- 0, /* getattro */
- 0, /* setattro */
- 0, /* as buffer */
- 0, /* tp_flags */
- PyOggStreamState_Doc
-};
-
-static PyMethodDef PyOggStreamState_methods[] = {
- {"packetin", PyOggStreamState_Packetin,
- METH_VARARGS, PyOggStreamState_Packetin_Doc},
- {"pageout", PyOggStreamState_Pageout,
- METH_VARARGS, PyOggStreamState_Pageout_Doc},
- {"flush", PyOggStreamState_Flush,
- METH_VARARGS, PyOggStreamState_Flush_Doc},
- {"pagein", PyOggStreamState_Pagein,
- METH_VARARGS, PyOggStreamState_Pagein_Doc},
- {"packetout", PyOggStreamState_Packetout,
- METH_VARARGS, PyOggStreamState_Packetout_Doc},
- {"packetpeek", PyOggStreamState_Packetpeek,
- METH_VARARGS, PyOggStreamState_Packetpeek_Doc},
- {"reset", PyOggStreamState_Reset,
- METH_VARARGS, PyOggStreamState_Reset_Doc},
- {"eos", PyOggStreamState_Eos,
- METH_VARARGS, PyOggStreamState_Eos_Doc},
- {"setmode", PyOggStreamState_Setmode,
- METH_VARARGS, PyOggStreamState_Setmode_Doc},
- {NULL, NULL}
-};
-
-static void
-PyOggStreamState_Dealloc(PyObject *self)
-{
- ogg_stream_destroy(PyOggStreamState_AsOggStreamState(self));
- PyObject_DEL(self);
-}
-
-static PyObject*
-PyOggStreamState_Getattr(PyObject *self, char *name)
-{
- return Py_FindMethod(PyOggStreamState_methods, self, name);
-}
-
-PyObject *
-PyOggStreamState_FromSerialno(int serialno)
-{
- PyOggStreamStateObject *ret = PyObject_NEW(PyOggStreamStateObject,
- &PyOggStreamState_Type);
- if (ret == NULL)
- return NULL;
-
- ret->stream = ogg_stream_create(serialno);
- if (ret->stream == NULL) {
- PyObject_DEL(ret);
- return NULL;
- }
- return (PyObject *) ret;
-}
-
-PyObject *
-PyOggStreamState_New(PyObject *self, PyObject *args)
-{
- int serialno;
-
- if (!PyArg_ParseTuple(args, "i", &serialno))
- return NULL;
- return PyOggStreamState_FromSerialno(serialno);
-}
-
-static PyObject *
-PyOggStreamState_Packetin(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPacketObject *packet;
-
- if (!PyArg_ParseTuple(args, "O!", &PyOggPacket_Type,
- (PyObject *) &packet))
- return NULL;
-
- if ( packet->valid_flag == 0 ) {
- PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
- return NULL;
- }
-
- ret = ogg_stream_packetin(PyOggStreamState_AsOggStreamState(self),
- PyOggPacket_AsOggPacket(packet));
- if (ret == OGG_SUCCESS) {
- Py_INCREF(Py_None);
- packet->valid_flag = 0;
- return Py_None;
- }
- if (ret == OGG_EEOS) {
- PyErr_SetString(PyOgg_Error, "EOS has been set on this stream");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "error in ogg_stream_packetin");
- return NULL;
-}
-
-
-static PyObject *
-PyOggStreamState_Pageout(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPageObject *pageobj;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- pageobj = PyOggPage_Alloc();
- if ( !pageobj ) {
- PyErr_SetString(PyOgg_Error, "Out of Memory.");
- return NULL;
- }
- ret = ogg_stream_pageout(PyOggStreamState_AsOggStreamState(self),
- PyOggPage_AsOggPage(pageobj));
- if ( ret == 1 ) return (PyObject *) pageobj;
- Py_DECREF(pageobj);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggStreamState_Flush(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPageObject *pageobj;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- pageobj = PyOggPage_Alloc();
- if ( !pageobj ) {
- PyErr_SetString(PyOgg_Error, "Out of Memory.");
- return NULL;
- }
- ret = ogg_stream_flush(PyOggStreamState_AsOggStreamState(self),
- PyOggPage_AsOggPage(pageobj));
- if ( ret == 1 ) return (PyObject *) pageobj;
- Py_DECREF(pageobj);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject *
-PyOggStreamState_Pagein(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPageObject *page;
-
- if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
- (PyObject *) &page))
- return NULL;
-
- if ( page->valid_flag == 0 ) {
- PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
- return NULL;
- }
-
- ret = ogg_stream_pagein(PyOggStreamState_AsOggStreamState(self),
- PyOggPage_AsOggPage(page));
- if (ret == OGG_SUCCESS) {
- Py_INCREF(Py_None);
- page->valid_flag = 0;
- return Py_None;
- }
- if (ret == OGG_ESERIAL) {
- PyErr_SetString(PyOgg_Error, "Page serial does not match stream.");
- return NULL;
- }
- if (ret == OGG_EVERSION) {
- PyErr_SetString(PyOgg_Error, "Unknown Ogg page version.");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_pagein.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggStreamState_Packetout(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPacketObject *packetobj;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- packetobj = PyOggPacket_Alloc();
- if ( !packetobj ) {
- PyErr_SetString(PyOgg_Error, "Out of Memory.");
- return NULL;
- }
-
- ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self),
- PyOggPacket_AsOggPacket(packetobj));
- if (ret == 1) return (PyObject *) packetobj;
- Py_DECREF(packetobj);
-
- if (ret == 0) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
- return NULL;
- }
- if (ret == OGG_SPAN) {
- PyErr_SetString(PyOgg_Error, "Stream spans ??.");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggStreamState_Packetpeek(PyObject *self, PyObject *args)
-{
- int ret;
- ogg_packet *packet;
-
- ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self), packet);
- if (ret == 1) {
- Py_INCREF(Py_True);
- return Py_True;
- }
- if (ret == 0) {
- Py_INCREF(Py_False);
- return Py_False;
- }
- if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
- return NULL;
- }
- if (ret == OGG_SPAN) {
- PyErr_SetString(PyOgg_Error, "Stream spans ??.");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggStreamState_Reset(PyObject *self, PyObject *args)
-{
- int ret;
- int serialno = -1;
-
- if (!PyArg_ParseTuple(args, "|i", &serialno))
- return NULL;
-
- if ( serialno == -1 )
- ret = ogg_stream_reset(PyOggStreamState_AsOggStreamState(self));
- else
- ret = ogg_stream_reset_serialno(PyOggStreamState_AsOggStreamState(self),serialno);
-
- if ( ret == OGG_SUCCESS ) {
- Py_INCREF(Py_None);
- return Py_None;
- } else {
- PyErr_SetString(PyOgg_Error, "Unknown error while resetting stream");
- return NULL;
- }
-}
-
-
-static PyObject*
-PyOggStreamState_Eos(PyObject *self, PyObject *args)
-{
- int eos;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- eos = ogg_stream_eos(PyOggStreamState_AsOggStreamState(self));
- if ( eos == 0 ) {
- Py_INCREF(Py_False);
- return Py_False;
- }
- Py_INCREF(Py_True);
- return Py_True;
-}
-
-static PyObject*
-PyOggStreamState_Setmode(PyObject *self, PyObject *args)
-{
- int mode;
- int ret;
-
- if (!PyArg_ParseTuple(args, "i", &mode))
- return NULL;
-
- ret = ogg_stream_setmode(PyOggStreamState_AsOggStreamState(self), mode);
-
- if ( ret == OGG_SUCCESS ) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- if ( ret == OGG_EMODE ) {
- PyErr_SetString(PyOgg_Error, "Cannot set this stream mode at this time.");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "Unknown error while setting stream mode");
- return NULL;
-}
-
-
-static PyObject *
-PyOggStreamState_Repr(PyObject *self)
-{
- char buf[256];
-
- sprintf(buf, "<OggStreamState at %p>", self);
- return PyString_FromString(buf);
-}
Deleted: trunk/py-ogg2/src/pyoggstreamstate.h
===================================================================
--- trunk/py-ogg2/src/pyoggstreamstate.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggstreamstate.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,18 +0,0 @@
-#ifndef PYOGGSTREAMSTATE_H
-#define PYOGGSTREAMSTATE_H
-
-#include "general.h"
-
-typedef struct {
- PyObject_HEAD
- ogg_stream_state *stream;
-} PyOggStreamStateObject;
-
-extern PyTypeObject PyOggStreamState_Type;
-
-#define PyOggStreamState_AsOggStreamState(x) (((PyOggStreamStateObject *) (x))->stream)
-
-PyObject *PyOggStreamState_FromSerialno(int);
-PyObject *PyOggStreamState_New(PyObject *, PyObject *);
-
-#endif
Deleted: trunk/py-ogg2/src/pyoggsyncstate.c
===================================================================
--- trunk/py-ogg2/src/pyoggsyncstate.c 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggsyncstate.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,292 +0,0 @@
-#include "pyoggsyncstate.h"
-#include "pyoggpage.h"
-#include "general.h"
-#include "_ogg2module.h"
-
-/*****************************************************************
- OggSyncState Object
- *****************************************************************/
-
-char PyOggSyncState_Doc[] = "";
-
-static void PyOggSyncState_Dealloc(PyObject *);
-static PyObject* PyOggSyncState_Getattr(PyObject *, char *);
-
-FDEF(PyOggSyncState_Pagein) "Add an Ogg page to the sync state buffer.";
-FDEF(PyOggSyncState_Read) "Output bytes as a python buffer.";
-FDEF(PyOggSyncState_Output) "Write bytes to a file.";
-FDEF(PyOggSyncState_Reset) "Reset the PyOggSyncState object.";
-FDEF(PyOggSyncState_Write) "Append bytes from a string.";
-FDEF(PyOggSyncState_Input) "Append bytes from a file.";
-FDEF(PyOggSyncState_Pageout) "Add an Ogg page to the syn.";
-
-PyTypeObject PyOggSyncState_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
- "OggSyncState",
- sizeof(PyOggSyncStateObject),
- 0,
-
- /* Standard Methods */
- /* (destructor) */ PyOggSyncState_Dealloc,
- /* (printfunc) */ 0,
- /* (getattrfunc) */ PyOggSyncState_Getattr,
- /* (setattrfunc) */ 0,
- /* (cmpfunc) */ 0,
- /* (reprfunc) */ 0,
-
- /* Type Categories */
- 0, /* as number */
- 0, /* as sequence */
- 0, /* as mapping */
- 0, /* hash */
- 0, /* binary */
- 0, /* repr */
- 0, /* getattro */
- 0, /* setattro */
- 0, /* as buffer */
- 0, /* tp_flags */
- PyOggSyncState_Doc
-};
-
-static PyMethodDef PyOggSyncState_methods[] = {
- {"pagein", PyOggSyncState_Pagein,
- METH_VARARGS, PyOggSyncState_Pagein_Doc},
- {"read", PyOggSyncState_Read,
- METH_VARARGS, PyOggSyncState_Read_Doc},
- {"output", PyOggSyncState_Output,
- METH_VARARGS, PyOggSyncState_Output_Doc},
- {"reset", PyOggSyncState_Reset,
- METH_VARARGS, PyOggSyncState_Reset_Doc},
- {"write", PyOggSyncState_Write,
- METH_VARARGS, PyOggSyncState_Write_Doc},
- {"input", PyOggSyncState_Input,
- METH_VARARGS, PyOggSyncState_Input_Doc},
- {"pageout", PyOggSyncState_Pageout,
- METH_VARARGS, PyOggSyncState_Pageout_Doc},
- {NULL, NULL}
-};
-
-PyObject *
-PyOggSyncState_New(PyObject *self, PyObject *args)
-{
- PyOggSyncStateObject *ret;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
- ret = PyObject_NEW(PyOggSyncStateObject, &PyOggSyncState_Type);
-
- if (ret == NULL)
- return NULL;
-
- ret->sync = ogg_sync_create();
- return (PyObject *) ret;
-}
-
-
-static void
-PyOggSyncState_Dealloc(PyObject *self)
-{
- ogg_sync_destroy(PyOggSyncState_AsOggSyncState(self));
- PyObject_DEL(self);
-}
-
-
-/* This should be changed to return pointer, size, etc */
-static PyObject*
-PyOggSyncState_Getattr(PyObject *self, char *name)
-{
- return Py_FindMethod(PyOggSyncState_methods, self, name);
-}
-
-
-static PyObject *
-PyOggSyncState_Pagein(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPageObject *page;
-
- if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
- (PyObject *) &page))
- return NULL;
-
- if ( page->valid_flag == 0 ) {
- PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
- return NULL;
- }
-
- ret = ogg_sync_pagein(PyOggSyncState_AsOggSyncState(self),
- PyOggPage_AsOggPage(page));
-
- if (ret == OGG_SUCCESS) {
- Py_INCREF(Py_None);
- page->valid_flag = 0;
- return Py_None;
- }
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_pagein.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggSyncState_Read(PyObject *self, PyObject *args)
-{
- int ret;
- int ask_bytes;
- int got_bytes;
- unsigned char *ogg_buffer;
- char *pybuffer;
- PyObject *pybufferobj;
-
- if (!PyArg_ParseTuple(args, "i", &ask_bytes))
- return NULL;
-
- got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
- &ogg_buffer);
- if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
-
-
- pybufferobj = PyBuffer_New(ask_bytes);
- PyObject_AsWriteBuffer(pybufferobj, (void **) &pybuffer, &got_bytes);
- if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
- if ( got_bytes == 0 ) return pybufferobj; /* If 0, return it now */
- memcpy(pybuffer, ogg_buffer, ask_bytes);
-
- ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
- if (ret == OGG_SUCCESS) return pybufferobj;
-
- Py_DECREF(pybufferobj);
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
- return NULL;
-}
-
-static PyObject *
-PyOggSyncState_Output(PyObject *self, PyObject *args)
-{
- int ret;
- int ask_bytes = -1;
- int got_bytes;
- unsigned char *ogg_buffer;
- FILE *fp;
- PyObject *pyfile;
-
- if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &ask_bytes))
- return NULL;
-
- if ( ask_bytes < 0 ) ask_bytes = 4096;
- fp = PyFile_AsFile(pyfile);
-
- got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
- &ogg_buffer);
-
- if ( got_bytes == 0 ) return PyInt_FromLong(0);
- if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
- fwrite(ogg_buffer, 1, ask_bytes, fp);
-
- ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
- if (ret == OGG_SUCCESS) return PyInt_FromLong(ask_bytes);
-
- PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggSyncState_Reset(PyObject *self, PyObject *args)
-{
- int ret;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- ret = ogg_sync_reset(PyOggSyncState_AsOggSyncState(self));
- if (ret == OGG_SUCCESS) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_reset.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggSyncState_Write(PyObject *self, PyObject *args)
-{
- int ret;
- char *bytes;
- int byte_count;
- char *ogg_buffer;
-
- if (!PyArg_ParseTuple(args, "s#", &bytes, &byte_count))
- return NULL;
-
- ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self),
- byte_count);
- memcpy(ogg_buffer, bytes, byte_count);
- ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self), byte_count);
- if (ret == OGG_SUCCESS) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggSyncState_Input(PyObject *self, PyObject *args)
-{
- int ret;
- int bytes = 4096;
- char *ogg_buffer;
- PyObject *pyfile;
- FILE *fp;
-
- if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &bytes))
- return NULL;
-
- fp = PyFile_AsFile(pyfile);
-
- ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self),
- bytes);
- bytes = fread(ogg_buffer, 1, bytes, fp);
- ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self),
- bytes);
- if ( ret == OGG_SUCCESS ) {
- return PyLong_FromLong(bytes);
- }
- PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
- return NULL;
-}
-
-
-static PyObject *
-PyOggSyncState_Pageout(PyObject *self, PyObject *args)
-{
- int ret;
- PyOggPageObject *pageobj;
-
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
-
- pageobj = PyOggPage_Alloc();
- if ( !pageobj ) {
- PyErr_SetString(PyOgg_Error, "Out of Memory.");
- return NULL;
- }
- ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self),
- PyOggPage_AsOggPage(pageobj));
-
- if ( ret == 1 ) return (PyObject *) pageobj;
- Py_DECREF(pageobj);
- if ( ret == 0 ) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
- return NULL;
- }
- PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_pageout.");
- return NULL;
-}
Deleted: trunk/py-ogg2/src/pyoggsyncstate.h
===================================================================
--- trunk/py-ogg2/src/pyoggsyncstate.h 2004-07-21 21:39:07 UTC (rev 7249)
+++ trunk/py-ogg2/src/pyoggsyncstate.h 2004-07-21 21:42:26 UTC (rev 7250)
@@ -1,17 +0,0 @@
-#ifndef PYOGGSYNCSTATE_H
-#define PYOGGSYNCSTATE_H
-
-#include "general.h"
-
-typedef struct {
- PyObject_HEAD
- ogg_sync_state *sync;
-} PyOggSyncStateObject;
-
-#define PyOggSyncState_AsOggSyncState(x) (((PyOggSyncStateObject *) (x))->sync)
-
-extern PyTypeObject PyOggSyncState_Type;
-
-PyObject *PyOggSyncState_New(PyObject *, PyObject *);
-
-#endif
Copied: trunk/py-ogg2/src/stream.c (from rev 7233, trunk/py-ogg2/src/pyoggstreamstate.c)
===================================================================
--- trunk/py-ogg2/src/pyoggstreamstate.c 2004-07-21 18:55:43 UTC (rev 7233)
+++ trunk/py-ogg2/src/stream.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,367 @@
+#include "module.h"
+#include "stream.h"
+#include "packet.h"
+#include "page.h"
+#include "general.h"
+
+/*****************************************************************
+ OggStreamState Object
+ *****************************************************************/
+
+
+char PyOggStreamState_Doc[] = "";
+
+static void PyOggStreamState_Dealloc(PyObject *);
+static PyObject* PyOggStreamState_Getattr(PyObject *, char *);
+static PyObject *PyOggStreamState_Repr(PyObject *self);
+
+FDEF(PyOggStreamState_Packetin) "Add a packet to the stream.";
+FDEF(PyOggStreamState_Pageout) "Extract and return an OggPage.";
+FDEF(PyOggStreamState_Flush) "Produce an ogg page suitable for writing to output.";
+FDEF(PyOggStreamState_Pagein) "Write a page to the stream";
+FDEF(PyOggStreamState_Packetout) "Extract a packet from the stream";
+FDEF(PyOggStreamState_Packetpeek) "Extract a packet from the stream";
+FDEF(PyOggStreamState_Reset) "Reset the stream state";
+FDEF(PyOggStreamState_Eos) "Return whether the end of the stream is reached.";
+FDEF(PyOggStreamState_Setmode) "Set stream mode for (dis)continuous.";
+
+PyTypeObject PyOggStreamState_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "OggStreamState",
+ sizeof(PyOggStreamStateObject),
+ 0,
+
+ /* Standard Methods */
+ /* (destructor) */ PyOggStreamState_Dealloc,
+ /* (printfunc) */ 0,
+ /* (getattrfunc) */ PyOggStreamState_Getattr,
+ /* (setattrfunc) */ 0,
+ /* (cmpfunc) */ 0,
+ /* (reprfunc) */ PyOggStreamState_Repr,
+
+ /* Type Categories */
+ 0, /* as number */
+ 0, /* as sequence */
+ 0, /* as mapping */
+ 0, /* hash */
+ 0, /* binary */
+ 0, /* repr */
+ 0, /* getattro */
+ 0, /* setattro */
+ 0, /* as buffer */
+ 0, /* tp_flags */
+ PyOggStreamState_Doc
+};
+
+static PyMethodDef PyOggStreamState_methods[] = {
+ {"packetin", PyOggStreamState_Packetin,
+ METH_VARARGS, PyOggStreamState_Packetin_Doc},
+ {"pageout", PyOggStreamState_Pageout,
+ METH_VARARGS, PyOggStreamState_Pageout_Doc},
+ {"flush", PyOggStreamState_Flush,
+ METH_VARARGS, PyOggStreamState_Flush_Doc},
+ {"pagein", PyOggStreamState_Pagein,
+ METH_VARARGS, PyOggStreamState_Pagein_Doc},
+ {"packetout", PyOggStreamState_Packetout,
+ METH_VARARGS, PyOggStreamState_Packetout_Doc},
+ {"packetpeek", PyOggStreamState_Packetpeek,
+ METH_VARARGS, PyOggStreamState_Packetpeek_Doc},
+ {"reset", PyOggStreamState_Reset,
+ METH_VARARGS, PyOggStreamState_Reset_Doc},
+ {"eos", PyOggStreamState_Eos,
+ METH_VARARGS, PyOggStreamState_Eos_Doc},
+ {"setmode", PyOggStreamState_Setmode,
+ METH_VARARGS, PyOggStreamState_Setmode_Doc},
+ {NULL, NULL}
+};
+
+static void
+PyOggStreamState_Dealloc(PyObject *self)
+{
+ ogg_stream_destroy(PyOggStreamState_AsOggStreamState(self));
+ PyObject_DEL(self);
+}
+
+static PyObject*
+PyOggStreamState_Getattr(PyObject *self, char *name)
+{
+ return Py_FindMethod(PyOggStreamState_methods, self, name);
+}
+
+PyObject *
+PyOggStreamState_FromSerialno(int serialno)
+{
+ PyOggStreamStateObject *ret = PyObject_NEW(PyOggStreamStateObject,
+ &PyOggStreamState_Type);
+ if (ret == NULL)
+ return NULL;
+
+ ret->stream = ogg_stream_create(serialno);
+ if (ret->stream == NULL) {
+ PyObject_DEL(ret);
+ return NULL;
+ }
+ return (PyObject *) ret;
+}
+
+PyObject *
+PyOggStreamState_New(PyObject *self, PyObject *args)
+{
+ int serialno;
+
+ if (!PyArg_ParseTuple(args, "i", &serialno))
+ return NULL;
+ return PyOggStreamState_FromSerialno(serialno);
+}
+
+static PyObject *
+PyOggStreamState_Packetin(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPacketObject *packet;
+
+ if (!PyArg_ParseTuple(args, "O!", &PyOggPacket_Type,
+ (PyObject *) &packet))
+ return NULL;
+
+ if ( packet->valid_flag == 0 ) {
+ PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
+ return NULL;
+ }
+
+ ret = ogg_stream_packetin(PyOggStreamState_AsOggStreamState(self),
+ PyOggPacket_AsOggPacket(packet));
+ if (ret == OGG_SUCCESS) {
+ Py_INCREF(Py_None);
+ packet->valid_flag = 0;
+ return Py_None;
+ }
+ if (ret == OGG_EEOS) {
+ PyErr_SetString(PyOgg_Error, "EOS has been set on this stream");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "error in ogg_stream_packetin");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggStreamState_Pageout(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPageObject *pageobj;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ pageobj = PyOggPage_Alloc();
+ if ( !pageobj ) {
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
+ return NULL;
+ }
+ ret = ogg_stream_pageout(PyOggStreamState_AsOggStreamState(self),
+ PyOggPage_AsOggPage(pageobj));
+ if ( ret == 1 ) return (PyObject *) pageobj;
+ Py_DECREF(pageobj);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggStreamState_Flush(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPageObject *pageobj;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ pageobj = PyOggPage_Alloc();
+ if ( !pageobj ) {
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
+ return NULL;
+ }
+ ret = ogg_stream_flush(PyOggStreamState_AsOggStreamState(self),
+ PyOggPage_AsOggPage(pageobj));
+ if ( ret == 1 ) return (PyObject *) pageobj;
+ Py_DECREF(pageobj);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject *
+PyOggStreamState_Pagein(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPageObject *page;
+
+ if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
+ (PyObject *) &page))
+ return NULL;
+
+ if ( page->valid_flag == 0 ) {
+ PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+ return NULL;
+ }
+
+ ret = ogg_stream_pagein(PyOggStreamState_AsOggStreamState(self),
+ PyOggPage_AsOggPage(page));
+ if (ret == OGG_SUCCESS) {
+ Py_INCREF(Py_None);
+ page->valid_flag = 0;
+ return Py_None;
+ }
+ if (ret == OGG_ESERIAL) {
+ PyErr_SetString(PyOgg_Error, "Page serial does not match stream.");
+ return NULL;
+ }
+ if (ret == OGG_EVERSION) {
+ PyErr_SetString(PyOgg_Error, "Unknown Ogg page version.");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_pagein.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggStreamState_Packetout(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPacketObject *packetobj;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ packetobj = PyOggPacket_Alloc();
+ if ( !packetobj ) {
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
+ return NULL;
+ }
+
+ ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self),
+ PyOggPacket_AsOggPacket(packetobj));
+ if (ret == 1) return (PyObject *) packetobj;
+ Py_DECREF(packetobj);
+
+ if (ret == 0) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if (ret == OGG_HOLE ) {
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
+ return NULL;
+ }
+ if (ret == OGG_SPAN) {
+ PyErr_SetString(PyOgg_Error, "Stream spans ??.");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggStreamState_Packetpeek(PyObject *self, PyObject *args)
+{
+ int ret;
+ ogg_packet *packet;
+
+ ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self), packet);
+ if (ret == 1) {
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
+ if (ret == 0) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ if (ret == OGG_HOLE ) {
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
+ return NULL;
+ }
+ if (ret == OGG_SPAN) {
+ PyErr_SetString(PyOgg_Error, "Stream spans ??.");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggStreamState_Reset(PyObject *self, PyObject *args)
+{
+ int ret;
+ int serialno = -1;
+
+ if (!PyArg_ParseTuple(args, "|i", &serialno))
+ return NULL;
+
+ if ( serialno == -1 )
+ ret = ogg_stream_reset(PyOggStreamState_AsOggStreamState(self));
+ else
+ ret = ogg_stream_reset_serialno(PyOggStreamState_AsOggStreamState(self),serialno);
+
+ if ( ret == OGG_SUCCESS ) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ } else {
+ PyErr_SetString(PyOgg_Error, "Unknown error while resetting stream");
+ return NULL;
+ }
+}
+
+
+static PyObject*
+PyOggStreamState_Eos(PyObject *self, PyObject *args)
+{
+ int eos;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ eos = ogg_stream_eos(PyOggStreamState_AsOggStreamState(self));
+ if ( eos == 0 ) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ Py_INCREF(Py_True);
+ return Py_True;
+}
+
+static PyObject*
+PyOggStreamState_Setmode(PyObject *self, PyObject *args)
+{
+ int mode;
+ int ret;
+
+ if (!PyArg_ParseTuple(args, "i", &mode))
+ return NULL;
+
+ ret = ogg_stream_setmode(PyOggStreamState_AsOggStreamState(self), mode);
+
+ if ( ret == OGG_SUCCESS ) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if ( ret == OGG_EMODE ) {
+ PyErr_SetString(PyOgg_Error, "Cannot set this stream mode at this time.");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown error while setting stream mode");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggStreamState_Repr(PyObject *self)
+{
+ char buf[256];
+
+ sprintf(buf, "<OggStreamState at %p>", self);
+ return PyString_FromString(buf);
+}
Copied: trunk/py-ogg2/src/stream.h (from rev 7192, trunk/py-ogg2/src/pyoggstreamstate.h)
Copied: trunk/py-ogg2/src/sync.c (from rev 7192, trunk/py-ogg2/src/pyoggsyncstate.c)
===================================================================
--- trunk/py-ogg2/src/pyoggsyncstate.c 2004-07-20 16:10:06 UTC (rev 7192)
+++ trunk/py-ogg2/src/sync.c 2004-07-21 21:42:26 UTC (rev 7250)
@@ -0,0 +1,292 @@
+#include "sync.h"
+#include "page.h"
+#include "general.h"
+#include "module.h"
+
+/*****************************************************************
+ OggSyncState Object
+ *****************************************************************/
+
+char PyOggSyncState_Doc[] = "";
+
+static void PyOggSyncState_Dealloc(PyObject *);
+static PyObject* PyOggSyncState_Getattr(PyObject *, char *);
+
+FDEF(PyOggSyncState_Pagein) "Add an Ogg page to the sync state buffer.";
+FDEF(PyOggSyncState_Read) "Output bytes as a python buffer.";
+FDEF(PyOggSyncState_Output) "Write bytes to a file.";
+FDEF(PyOggSyncState_Reset) "Reset the PyOggSyncState object.";
+FDEF(PyOggSyncState_Write) "Append bytes from a string.";
+FDEF(PyOggSyncState_Input) "Append bytes from a file.";
+FDEF(PyOggSyncState_Pageout) "Add an Ogg page to the syn.";
+
+PyTypeObject PyOggSyncState_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "OggSyncState",
+ sizeof(PyOggSyncStateObject),
+ 0,
+
+ /* Standard Methods */
+ /* (destructor) */ PyOggSyncState_Dealloc,
+ /* (printfunc) */ 0,
+ /* (getattrfunc) */ PyOggSyncState_Getattr,
+ /* (setattrfunc) */ 0,
+ /* (cmpfunc) */ 0,
+ /* (reprfunc) */ 0,
+
+ /* Type Categories */
+ 0, /* as number */
+ 0, /* as sequence */
+ 0, /* as mapping */
+ 0, /* hash */
+ 0, /* binary */
+ 0, /* repr */
+ 0, /* getattro */
+ 0, /* setattro */
+ 0, /* as buffer */
+ 0, /* tp_flags */
+ PyOggSyncState_Doc
+};
+
+static PyMethodDef PyOggSyncState_methods[] = {
+ {"pagein", PyOggSyncState_Pagein,
+ METH_VARARGS, PyOggSyncState_Pagein_Doc},
+ {"read", PyOggSyncState_Read,
+ METH_VARARGS, PyOggSyncState_Read_Doc},
+ {"output", PyOggSyncState_Output,
+ METH_VARARGS, PyOggSyncState_Output_Doc},
+ {"reset", PyOggSyncState_Reset,
+ METH_VARARGS, PyOggSyncState_Reset_Doc},
+ {"write", PyOggSyncState_Write,
+ METH_VARARGS, PyOggSyncState_Write_Doc},
+ {"input", PyOggSyncState_Input,
+ METH_VARARGS, PyOggSyncState_Input_Doc},
+ {"pageout", PyOggSyncState_Pageout,
+ METH_VARARGS, PyOggSyncState_Pageout_Doc},
+ {NULL, NULL}
+};
+
+PyObject *
+PyOggSyncState_New(PyObject *self, PyObject *args)
+{
+ PyOggSyncStateObject *ret;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ ret = PyObject_NEW(PyOggSyncStateObject, &PyOggSyncState_Type);
+
+ if (ret == NULL)
+ return NULL;
+
+ ret->sync = ogg_sync_create();
+ return (PyObject *) ret;
+}
+
+
+static void
+PyOggSyncState_Dealloc(PyObject *self)
+{
+ ogg_sync_destroy(PyOggSyncState_AsOggSyncState(self));
+ PyObject_DEL(self);
+}
+
+
+/* This should be changed to return pointer, size, etc */
+static PyObject*
+PyOggSyncState_Getattr(PyObject *self, char *name)
+{
+ return Py_FindMethod(PyOggSyncState_methods, self, name);
+}
+
+
+static PyObject *
+PyOggSyncState_Pagein(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPageObject *page;
+
+ if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
+ (PyObject *) &page))
+ return NULL;
+
+ if ( page->valid_flag == 0 ) {
+ PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+ return NULL;
+ }
+
+ ret = ogg_sync_pagein(PyOggSyncState_AsOggSyncState(self),
+ PyOggPage_AsOggPage(page));
+
+ if (ret == OGG_SUCCESS) {
+ Py_INCREF(Py_None);
+ page->valid_flag = 0;
+ return Py_None;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_pagein.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggSyncState_Read(PyObject *self, PyObject *args)
+{
+ int ret;
+ int ask_bytes;
+ int got_bytes;
+ unsigned char *ogg_buffer;
+ char *pybuffer;
+ PyObject *pybufferobj;
+
+ if (!PyArg_ParseTuple(args, "i", &ask_bytes))
+ return NULL;
+
+ got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
+ &ogg_buffer);
+ if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
+
+
+ pybufferobj = PyBuffer_New(ask_bytes);
+ PyObject_AsWriteBuffer(pybufferobj, (void **) &pybuffer, &got_bytes);
+ if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
+ if ( got_bytes == 0 ) return pybufferobj; /* If 0, return it now */
+ memcpy(pybuffer, ogg_buffer, ask_bytes);
+
+ ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
+ if (ret == OGG_SUCCESS) return pybufferobj;
+
+ Py_DECREF(pybufferobj);
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
+ return NULL;
+}
+
+static PyObject *
+PyOggSyncState_Output(PyObject *self, PyObject *args)
+{
+ int ret;
+ int ask_bytes = -1;
+ int got_bytes;
+ unsigned char *ogg_buffer;
+ FILE *fp;
+ PyObject *pyfile;
+
+ if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &ask_bytes))
+ return NULL;
+
+ if ( ask_bytes < 0 ) ask_bytes = 4096;
+ fp = PyFile_AsFile(pyfile);
+
+ got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
+ &ogg_buffer);
+
+ if ( got_bytes == 0 ) return PyInt_FromLong(0);
+ if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
+ fwrite(ogg_buffer, 1, ask_bytes, fp);
+
+ ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
+ if (ret == OGG_SUCCESS) return PyInt_FromLong(ask_bytes);
+
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggSyncState_Reset(PyObject *self, PyObject *args)
+{
+ int ret;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ ret = ogg_sync_reset(PyOggSyncState_AsOggSyncState(self));
+ if (ret == OGG_SUCCESS) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_reset.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggSyncState_Write(PyObject *self, PyObject *args)
+{
+ int ret;
+ char *bytes;
+ int byte_count;
+ char *ogg_buffer;
+
+ if (!PyArg_ParseTuple(args, "s#", &bytes, &byte_count))
+ return NULL;
+
+ ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self),
+ byte_count);
+ memcpy(ogg_buffer, bytes, byte_count);
+ ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self), byte_count);
+ if (ret == OGG_SUCCESS) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggSyncState_Input(PyObject *self, PyObject *args)
+{
+ int ret;
+ int bytes = 4096;
+ char *ogg_buffer;
+ PyObject *pyfile;
+ FILE *fp;
+
+ if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &bytes))
+ return NULL;
+
+ fp = PyFile_AsFile(pyfile);
+
+ ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self),
+ bytes);
+ bytes = fread(ogg_buffer, 1, bytes, fp);
+ ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self),
+ bytes);
+ if ( ret == OGG_SUCCESS ) {
+ return PyLong_FromLong(bytes);
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
+ return NULL;
+}
+
+
+static PyObject *
+PyOggSyncState_Pageout(PyObject *self, PyObject *args)
+{
+ int ret;
+ PyOggPageObject *pageobj;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ pageobj = PyOggPage_Alloc();
+ if ( !pageobj ) {
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
+ return NULL;
+ }
+ ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self),
+ PyOggPage_AsOggPage(pageobj));
+
+ if ( ret == 1 ) return (PyObject *) pageobj;
+ Py_DECREF(pageobj);
+ if ( ret == 0 ) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if (ret == OGG_HOLE ) {
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
+ return NULL;
+ }
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_pageout.");
+ return NULL;
+}
Copied: trunk/py-ogg2/src/sync.h (from rev 7192, trunk/py-ogg2/src/pyoggsyncstate.h)
More information about the commits
mailing list