[xiph-cvs] cvs commit: ogg-python2/src _ogg2module.c _ogg2module.h general.c general.h pyoggpackbuff.h pyoggpacket.c pyoggpacket.h pyoggpage.c pyoggpage.h pyoggstreamstate.c pyoggstreamstate.h pyoggsyncstate.c pyoggsyncstate.h
Arc
arc at xiph.org
Mon Feb 23 22:31:50 PST 2004
arc 04/02/24 01:31:50
Modified: . setup.py
examples writ_encoder.py
src _ogg2module.c _ogg2module.h general.c general.h
pyoggpackbuff.h pyoggpacket.c pyoggpacket.h
pyoggpage.c pyoggpage.h pyoggstreamstate.c
pyoggstreamstate.h pyoggsyncstate.c
pyoggsyncstate.h
Removed: include/pyogg pyogg2.h
Log:
This is a massive cleanup and bugfix.
Trying to use OggPage and OggPacket objects after they've been passed
back to libogg2 now raises a proper Python error instead of a segfault.
I also removed some inter-module stuff since this module will never need
them. We will use a universal multi-codec library, such as OggFile,
instead of individual Python modules for each codec.
Lastly, there's some older work on the example writ encoder that's
getting updated with this commit.
Revision Changes Path
1.3 +3 -3 ogg-python2/setup.py
Index: setup.py
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/setup.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- setup.py 30 Nov 2003 21:03:34 -0000 1.2
+++ setup.py 24 Feb 2004 06:31:48 -0000 1.3
@@ -59,11 +59,11 @@
setup ( name = "pyogg",
version = pyogg_version,
description = "A wrapper for the Ogg libraries.",
- author = "Arc",
- author_email = "arc at indymedia.org",
+ author = "Arc Riley",
+ author_email = "arc at xiph.org",
url = "NONEYET",
- headers = ['include/pyogg/pyogg2.h'],
+ headers = [],
packages = ['ogg2'],
package_dir = {'ogg2' : 'pysrc'},
ext_package = 'ogg2',
<p><p>1.2 +90 -54 ogg-python2/examples/writ_encoder.py
Index: writ_encoder.py
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/examples/writ_encoder.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- writ_encoder.py 1 Dec 2003 07:21:05 -0000 1.1
+++ writ_encoder.py 24 Feb 2004 06:31:49 -0000 1.2
@@ -1,6 +1,6 @@
'''
function: Ogg Writ reference encoder
- last mod: $Id: writ_encoder.py,v 1.1 2003/12/01 07:21:05 arc Exp $
+ last mod: $Id: writ_encoder.py,v 1.2 2004/02/24 06:31:49 arc Exp $
This is an example for how py-ogg2 can be used to rapidly design a new
Ogg codec or test an existing codec's specifications for accuracy.
@@ -9,6 +9,7 @@
import ogg2
import struct
+import random
class BitPacker :
def __init__(self) :
@@ -48,7 +49,48 @@
return self.pb.packetout()
def reset(self) :
- return self.pb.reset()
+ self.pb = ogg2.OggPackBuff()
+ # return self.pb.reset()
+
+class OggStream :
+ def __init__(self) :
+ self.os = ogg2.OggStreamState(random.randrange(2**24))
+ self.oy = ogg2.OggSyncState()
+ self.fd = open('test.writ.ogg','w')
+ self.pn = 0
+
+ def packetin(self, packet, granulepos=0) :
+ packet.packetno = self.pn
+ packet.granulepos = granulepos
+ if self.pn == 0 :
+ packet.bos = 1
+ else :
+ self.os.packetin(self.packet)
+ if self.pn != 2 :
+ print "Flushing: %d" % (self.packet.packetno)
+ self.flush()
+ else :
+ print "Skipping: %d" % (self.packet.packetno)
+ self.packet = packet
+ self.pn = self.pn + 1
+
+ def flush(self) :
+ page = self.os.flush()
+ if page != None :
+ self.oy.pagein(page)
+ output = '.'
+ while len(output)!= 0 :
+ output = self.oy.read(4096)
+ print type(output), len(output)
+ self.fd.write(output)
+ else : print 'None!'
+
+ def close(self) :
+ self.packet.eos = 1
+ self.os.packetin(self.packet)
+ self.flush()
+ self.fd.close()
+
def ilog(num) :
for x in range(17) :
@@ -57,83 +99,77 @@
return 0
-serialno = 5
gnum = 1
gden = 1
+
+langs=(('en','English'),('es','Spanish'))
+
+# winds: location_x, location_y, width, height, alignment_x, alignment_y
sclx = 4000
scly = 270
bitx = ilog(sclx)
bity = ilog(scly)
totl = (bitx*2)+(bity*2)+4
bitp = ((((totl-1)/8)+1)*8)-totl
+winds=((1,2,3,1,3,3),(5,6,7,1,3,3))
-langs=(('en','English'),('es','Spanish'))
-
-texts=((05,10,1,2,3,1,3,3, ( u'Hello World!' ,
- u'Hola, Mundo!' ) ),
- (12,15,5,6,7,1,3,3, ( u'It\'s a beautiful day to be born.' ,
- u'Es un d\N{LATIN SMALL LETTER I WITH ACUTE}'+\
- u'a hermoso para que se llevar'+\
- u'\N{LATIN SMALL LETTER A WITH ACUTE}.' ) ) )
+# texts: start, duration, lang(s), wind
+texts=((05,10, ( u'Hello World!' ,
+ u'Hola, Mundo!' ), 0),
+ (12,15, ( u'It\'s a beautiful day to be born.' ,
+ u'Es un d\N{LATIN SMALL LETTER I WITH ACUTE}'+\
+ u'a hermoso para que se llevar'+\
+ u'\N{LATIN SMALL LETTER A WITH ACUTE}.' ), 1) )
bp = BitPacker()
-os=ogg2.OggStreamState(5)
-oy=ogg2.OggSyncState()
-fd=open('test.writ.ogg','w')
-
+os = OggStream()
-# Start with Header
-bp.write(0,8) # header packet
+# Start with Header 0
+bp.write(0,8) # header packet 0
bp.write(1953067639,32) # "writ"
bp.write(0,8) # version = 0
+bp.write(2,8) # subversion = 0
bp.write(gnum,32) # granulerate_numerator
bp.write(gden,32) # granulerate_denominator
-bp.write(sclx,16) # location_scale_x
-bp.write(scly,16) # location_scale_y
+os.packetin(bp.export())
+bp.reset()
+
+# Start with Header 1
+bp.write(1,8) # header packet 1
+bp.write(1953067639,32) # "writ"
bp.write(len(langs)-1,8) # num_languages
for lang in langs:
bp.uniwrite(lang[0]) # lang_name length, string
bp.uniwrite(lang[1]) # lang_desc length, string
+os.packetin(bp.export())
+bp.reset()
-packet = bp.export()
-packet.bos = 1
-os.packetin(packet)
-page=os.flush()
-pn=1
-oy.pagein(page)
-
-bp = BitPacker()
-# bp.reset()
-
+# Start with Header 1
+bp.write(2,8) # header packet 2
+bp.write(1953067639,32) # "writ"
+bp.write(sclx,16) # location_scale_x
+bp.write(scly,16) # location_scale_y
+bp.write(len(winds),8) # num_windows
+for win in winds:
+ bp.write(win[0],bitx) # location_x
+ bp.write(win[1],bity) # location_x
+ bp.write(win[2],bitx) # location_width
+ bp.write(win[3],bity) # location_height
+ bp.write(win[4],2) # alignment_x
+ bp.write(win[5],2) # alignment_y
+os.packetin(bp.export())
+bp.reset()
+
for text in texts: # - Each Phrase -
bp.write(255,8) # data packet
bp.write(text[0],64) # granule_start
bp.write(text[1],32) # granule_duration
- bp.write(text[2],bitx) # location_x
- bp.write(text[3],bity) # location_y
- bp.write(text[4],bitx) # location_width
- bp.write(text[5],bity) # location_height
- bp.write(text[6],2) # alignment_x
- bp.write(text[7],2) # alignment_y
- bp.write(0,bitp) # byte padding
for lang in range(len(langs)):
- bp.uniwrite(text[8][lang]) # text length, string
+ bp.uniwrite(text[2][lang]) # text length, string
+ if len(winds) > 1 : # only if we need to specify
+ bp.write(text[3],8) # window_id
+ os.packetin(bp.export(), text[0])
+ bp.reset()
- packet = bp.export()
- packet.packetno = pn
- packet.granulepos = text[0]+text[1]
- os.packetin(packet)
- pn=pn+1
- page=os.pageout()
- if page != None :
- oy.pagein(page)
- oy.output(fd)
- bp = BitPacker()
- #bp.reset()
-
-page=os.flush()
-if page != None :
- oy.pagein(page)
- while oy.output(fd) :
- pass
+os.close()
<p><p>1.5 +13 -21 ogg-python2/src/_ogg2module.c
Index: _ogg2module.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/_ogg2module.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- _ogg2module.c 1 Dec 2003 08:34:11 -0000 1.4
+++ _ogg2module.c 24 Feb 2004 06:31:49 -0000 1.5
@@ -1,7 +1,5 @@
#include <ogg2/ogg.h>
-#include <pyogg/pyogg2.h>
-
#include "general.h"
#include "_ogg2module.h"
@@ -27,22 +25,12 @@
/* This stuff is useful to py-ogg2 submodules */
-static ogg2_module_info mi = {
- VERSION_MINOR,
- VERSION_MAJOR,
- &PyOggPacket_Type,
- &PyOggStreamState_Type,
- NULL, /* Will be PyOggError */
-/* PyOggPacket_Alloc, */
- arg_to_int64,
-};
-
void
init_ogg2(void)
{
PyObject *module, *dict, *Py_module_info;
-/* PyOggPackBuffer_Type.ob_type = &PyType_Type; */
+ PyOggPackBuffer_Type.ob_type = &PyType_Type;
PyOggPacket_Type.ob_type = &PyType_Type;
PyOggPage_Type.ob_type = &PyType_Type;
PyOggStreamState_Type.ob_type = &PyType_Type;
@@ -51,16 +39,20 @@
module = Py_InitModule("_ogg2", Ogg_methods);
dict = PyModule_GetDict(module);
- PyOggError = PyErr_NewException("ogg2.OggError", NULL, NULL);
- PyDict_SetItemString(dict, "OggError", PyOggError);
-
- mi.PyOggError = PyOggError;
-
- Py_module_info = PyCObject_FromVoidPtr(&mi, NULL);
- PyDict_SetItemString(dict, "_moduleinfo", Py_module_info);
+ 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);
PyDict_SetItemString(dict, "__doc__", PyString_FromString(docstring));
- PyDict_SetItemString(dict, "__version__", PyString_FromString("2.0"));
+ PyDict_SetItemString(dict, "__version__", PyString_FromString("2.0-pre_20040224"));
if (PyErr_Occurred())
PyErr_SetString(PyExc_ImportError, "_ogg2: init failed");
<p><p>1.2 +3 -1 ogg-python2/src/_ogg2module.h
Index: _ogg2module.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/_ogg2module.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- _ogg2module.h 29 Nov 2003 09:21:57 -0000 1.1
+++ _ogg2module.h 24 Feb 2004 06:31:50 -0000 1.2
@@ -3,7 +3,9 @@
#include <Python.h>
-PyObject *PyOggError;
+PyObject *PyOgg_Error;
+PyObject *PyOggPage_Error;
+PyObject *PyOggPacket_Error;
/* Object docstrings */
<p><p>1.3 +0 -1 ogg-python2/src/general.c
Index: general.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/general.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- general.c 30 Nov 2003 06:32:08 -0000 1.2
+++ general.c 24 Feb 2004 06:31:50 -0000 1.3
@@ -1,5 +1,4 @@
#include "general.h"
-#include <pyogg/pyogg2.h>
/* Simple function to turn an object into an ogg_int64_t. Returns 0 on
* an error. Does not DECREF the argument */
<p><p>1.2 +12 -0 ogg-python2/src/general.h
Index: general.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/general.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- general.h 29 Nov 2003 09:21:57 -0000 1.1
+++ general.h 24 Feb 2004 06:31:50 -0000 1.2
@@ -1,6 +1,9 @@
#ifndef __GENERAL_H__
#define __GENERAL_H__
+#include <Python.h>
+#include <ogg2/ogg.h>
+
#define MSG_SIZE 256
#define KEY_SIZE 1024
@@ -9,4 +12,13 @@
#define FDEF(x) static PyObject *##x(PyObject *self, PyObject *args); \
static char x##_Doc[] =
+int arg_to_int64(PyObject *longobj, ogg_int64_t *val);
+int arg_to_int32(PyObject *intobj, ogg_int32_t *val);
+
+PyObject * Py_TrueFalse(int value);
+
+/* This is temporary, until libogg2 is more complete */
+ogg_buffer_state *ogg_buffer_create(void);
+
+
#endif /* __GENERAL_H__ */
<p><p>1.4 +0 -1 ogg-python2/src/pyoggpackbuff.h
Index: pyoggpackbuff.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpackbuff.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyoggpackbuff.h 1 Dec 2003 08:34:11 -0000 1.3
+++ pyoggpackbuff.h 24 Feb 2004 06:31:50 -0000 1.4
@@ -1,7 +1,6 @@
#ifndef PYOGGPACKBUFF_H
#define PYOGGPACKBUFF_H
-#include <pyogg/pyogg2.h>
#include "pyoggpacket.h"
typedef struct {
<p><p>1.4 +60 -25 ogg-python2/src/pyoggpacket.c
Index: pyoggpacket.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpacket.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyoggpacket.c 1 Dec 2003 06:49:56 -0000 1.3
+++ pyoggpacket.c 24 Feb 2004 06:31:50 -0000 1.4
@@ -1,6 +1,6 @@
-#include <pyogg/pyogg2.h>
#include "pyoggpacket.h"
#include "general.h"
+#include "_ogg2module.h"
/************************************************************
OggPacket Object
@@ -12,6 +12,20 @@
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)
@@ -21,29 +35,28 @@
0,
/* Standard Methods */
- /* (destructor) */ PyOggPacket_Dealloc,
- /* (printfunc) */ 0,
- /* (getattrfunc) */ PyOggPacket_Getattr,
- /* (setattrfunc) */ PyOggPacket_Setattr,
- /* (cmpfunc) */ 0,
- /* (reprfunc) */ PyOggPacket_Repr,
+ PyOggPacket_Dealloc, /* (destructor) */
+ 0, /* (printfunc) */
+ PyOggPacket_Getattr, /* (getattrfunc) */
+ PyOggPacket_Setattr, /* (setattrfunc) */
+ 0, /* (cmpfunc) */
+ PyOggPacket_Repr, /* (reprfunc) */
/* 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 */
+ 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[] = {
- {"data", NULL, NULL},
{"bos", NULL, NULL},
{"eos", NULL, NULL},
{"granulepos", NULL, NULL},
@@ -62,6 +75,8 @@
if (ret == NULL)
return NULL;
+ ret->valid_flag = 1;
+
ret->packet = PyMem_New(ogg_packet, 1);
if (ret->packet == NULL) {
PyObject_Del(ret);
@@ -80,12 +95,25 @@
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 (strcmp(name, "data") == 0)
- return PyString_FromStringAndSize((char *) PyOggPacket_AsOggPacket(self)->packet,
- PyOggPacket_AsOggPacket(self)->bytes);
+ 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)
@@ -100,8 +128,8 @@
static int
PyOggPacket_Setattr(PyObject *self, char *name, PyObject *value)
{
- if (strcmp(name, "data") == 0) {
- PyErr_SetString(PyExc_AttributeError, "Function not written yet");
+ if (((PyOggPacketObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPacket_Error, "this packet is no longer usable.");
return -1;
}
if (strcmp(name, "bos") == 0) {
@@ -140,9 +168,16 @@
PyOggPacket_Repr(PyObject *self)
{
char buf[256];
- char *bos = PyOggPacket_AsOggPacket(self)->b_o_s ? "BOS, " : "";
- char *eos = PyOggPacket_AsOggPacket(self)->e_o_s ? "EOS, " : "";
+ 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,
<p><p>1.3 +3 -0 ogg-python2/src/pyoggpacket.h
Index: pyoggpacket.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpacket.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- pyoggpacket.h 29 Nov 2003 18:49:20 -0000 1.2
+++ pyoggpacket.h 24 Feb 2004 06:31:50 -0000 1.3
@@ -1,8 +1,11 @@
#ifndef PYOGGPACKET_H
#define PYOGGPACKET_H
+#include "general.h"
+
typedef struct {
PyObject_HEAD
+ int valid_flag;
ogg_packet *packet;
} PyOggPacketObject;
<p><p>1.4 +59 -29 ogg-python2/src/pyoggpage.c
Index: pyoggpage.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpage.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyoggpage.c 30 Nov 2003 06:33:11 -0000 1.3
+++ pyoggpage.c 24 Feb 2004 06:31:50 -0000 1.4
@@ -13,7 +13,20 @@
static PyObject* PyOggPage_Getattr(PyObject *, char *);
static int PyOggPage_Setattr(PyObject *self, char *name, PyObject *value);
static PyObject *PyOggPage_Repr(PyObject *self);
-static PyObject *PyOggPage_Size(PyObject *self, PyObject *args);
+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)
@@ -23,29 +36,28 @@
0,
/* Standard Methods */
- /* (destructor) */ PyOggPage_Dealloc,
- /* (printfunc) */ 0,
- /* (getattrfunc) */ PyOggPage_Getattr,
- /* (setattrfunc) */ PyOggPage_Setattr,
- /* (cmpfunc) */ 0,
- /* (reprfunc) */ PyOggPage_Repr,
+ PyOggPage_Dealloc, /* (destructor) */
+ 0, /* (printfunc) */
+ PyOggPage_Getattr, /* (getattrfunc) */
+ 0, /* (setattrfunc) */ /* disabled PyOggPage_Setattr, */
+ 0, /* (cmpfunc) */
+ PyOggPage_Repr, /* (reprfunc) */
/* 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 */
+ 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[] = {
- {"__len__", PyOggPage_Size, METH_VARARGS, NULL},
{"bos", NULL, NULL, NULL},
{"continued", NULL, NULL, NULL},
{"eos", NULL, NULL, NULL},
@@ -66,6 +78,7 @@
if (ret == NULL)
return NULL;
+ ret->valid_flag = 1;
page = PyMem_New(ogg_page, 1);
if (page == NULL) {
PyObject_Del(ret);
@@ -85,21 +98,28 @@
}
-static PyObject *
-PyOggPage_Size(PyObject *self, PyObject *args) {
- int size;
+static int
+PyOggPage_Size(PyObject *self) {
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
+ if (((PyOggPageObject *) self)->valid_flag == 0) {
+ PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+ return -1;
+ }
- size = PyOggPage_AsOggPage(self)->header_len +
+ return PyOggPage_AsOggPage(self)->header_len +
PyOggPage_AsOggPage(self)->body_len;
- return PyInt_FromLong(size);
}
static PyObject*
PyOggPage_Getattr(PyObject *self, char *name) {
- ogg_page *page = PyOggPage_AsOggPage(self);
+ 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));
@@ -244,9 +264,18 @@
PyOggPage_Repr(PyObject *self)
{
char buf[256];
- char *bos = ogg_page_bos(PyOggPage_AsOggPage(self)) ? "BOS, " : "";
- char *eos = ogg_page_eos(PyOggPage_AsOggPage(self)) ? "EOS, " : "";
- char *cont = ogg_page_continued(PyOggPage_AsOggPage(self)) ? "CONT, " : "";
+ 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)>",
@@ -258,5 +287,6 @@
PyOggPage_AsOggPage(self)->header_len,
PyOggPage_AsOggPage(self)->body_len,
self, PyOggPage_AsOggPage(self));
+
return PyString_FromString(buf);
}
<p><p>1.3 +2 -1 ogg-python2/src/pyoggpage.h
Index: pyoggpage.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpage.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- pyoggpage.h 29 Nov 2003 18:49:20 -0000 1.2
+++ pyoggpage.h 24 Feb 2004 06:31:50 -0000 1.3
@@ -1,10 +1,11 @@
#ifndef PYOGG2PAGE_H
#define PYOGG2PAGE_H
-#include <pyogg/pyogg2.h>
+#include "general.h"
typedef struct {
PyObject_HEAD
+ int valid_flag;
ogg_page *page;
} PyOggPageObject;
<p><p>1.4 +28 -16 ogg-python2/src/pyoggstreamstate.c
Index: pyoggstreamstate.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggstreamstate.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyoggstreamstate.c 30 Nov 2003 06:33:11 -0000 1.3
+++ pyoggstreamstate.c 24 Feb 2004 06:31:50 -0000 1.4
@@ -121,17 +121,23 @@
(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(PyOggError, "EOS has been set on this stream");
+ PyErr_SetString(PyOgg_Error, "EOS has been set on this stream");
return NULL;
}
- PyErr_SetString(PyOggError, "error in ogg_stream_packetin");
+ PyErr_SetString(PyOgg_Error, "error in ogg_stream_packetin");
return NULL;
}
@@ -147,7 +153,7 @@
pageobj = PyOggPage_Alloc();
if ( !pageobj ) {
- PyErr_SetString(PyOggError, "Out of Memory.");
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
return NULL;
}
ret = ogg_stream_pageout(PyOggStreamState_AsOggStreamState(self),
@@ -170,7 +176,7 @@
pageobj = PyOggPage_Alloc();
if ( !pageobj ) {
- PyErr_SetString(PyOggError, "Out of Memory.");
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
return NULL;
}
ret = ogg_stream_flush(PyOggStreamState_AsOggStreamState(self),
@@ -191,22 +197,28 @@
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(PyOggError, "Page serial does not match stream.");
+ PyErr_SetString(PyOgg_Error, "Page serial does not match stream.");
return NULL;
}
if (ret == OGG_EVERSION) {
- PyErr_SetString(PyOggError, "Unknown Ogg page version.");
+ PyErr_SetString(PyOgg_Error, "Unknown Ogg page version.");
return NULL;
}
- PyErr_SetString(PyOggError, "Unknown return from ogg_stream_pagein.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_pagein.");
return NULL;
}
@@ -222,7 +234,7 @@
packetobj = PyOggPacket_Alloc();
if ( !packetobj ) {
- PyErr_SetString(PyOggError, "Out of Memory.");
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
return NULL;
}
@@ -236,14 +248,14 @@
return Py_None;
}
if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
return NULL;
}
if (ret == OGG_SPAN) {
- PyErr_SetString(PyOggError, "Stream spans ??.");
+ PyErr_SetString(PyOgg_Error, "Stream spans ??.");
return NULL;
}
- PyErr_SetString(PyOggError, "Unknown return from ogg_stream_packetout.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
return NULL;
}
@@ -264,14 +276,14 @@
return Py_False;
}
if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
return NULL;
}
if (ret == OGG_SPAN) {
- PyErr_SetString(PyOggError, "Stream spans ??.");
+ PyErr_SetString(PyOgg_Error, "Stream spans ??.");
return NULL;
}
- PyErr_SetString(PyOggError, "Unknown return from ogg_stream_packetout.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_stream_packetout.");
return NULL;
}
@@ -294,7 +306,7 @@
Py_INCREF(Py_None);
return Py_None;
} else {
- PyErr_SetString(PyOggError, "Unknown error while resetting stream");
+ PyErr_SetString(PyOgg_Error, "Unknown error while resetting stream");
return NULL;
}
}
<p><p>1.2 +1 -1 ogg-python2/src/pyoggstreamstate.h
Index: pyoggstreamstate.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggstreamstate.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggstreamstate.h 29 Nov 2003 09:21:57 -0000 1.1
+++ pyoggstreamstate.h 24 Feb 2004 06:31:50 -0000 1.2
@@ -1,7 +1,7 @@
#ifndef PYOGGSTREAMSTATE_H
#define PYOGGSTREAMSTATE_H
-#include <pyogg/pyogg2.h>
+#include "general.h"
typedef struct {
PyObject_HEAD
<p><p>1.5 +15 -9 ogg-python2/src/pyoggsyncstate.c
Index: pyoggsyncstate.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggsyncstate.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- pyoggsyncstate.c 6 Dec 2003 16:39:48 -0000 1.4
+++ pyoggsyncstate.c 24 Feb 2004 06:31:50 -0000 1.5
@@ -109,15 +109,21 @@
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(PyOggError, "Unknown return from ogg_sync_pagein.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_pagein.");
return NULL;
}
@@ -150,7 +156,7 @@
if (ret == OGG_SUCCESS) return pybufferobj;
Py_DECREF(pybufferobj);
- PyErr_SetString(PyOggError, "Unknown return from ogg_sync_read.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
return NULL;
}
@@ -180,7 +186,7 @@
ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
if (ret == OGG_SUCCESS) return PyInt_FromLong(ask_bytes);
- PyErr_SetString(PyOggError, "Unknown return from ogg_sync_read.");
+ PyErr_SetString(PyOgg_Error, "Unknown return from ogg_sync_read.");
return NULL;
}
@@ -198,7 +204,7 @@
Py_INCREF(Py_None);
return Py_None;
}
- PyErr_SetString(PyOggError, "Unknown error from ogg_sync_reset.");
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_reset.");
return NULL;
}
@@ -222,7 +228,7 @@
Py_INCREF(Py_None);
return Py_None;
}
- PyErr_SetString(PyOggError, "Unknown error from ogg_sync_wrote.");
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
return NULL;
}
@@ -249,7 +255,7 @@
if ( ret == OGG_SUCCESS ) {
return PyLong_FromLong(bytes);
}
- PyErr_SetString(PyOggError, "Unknown error from ogg_sync_wrote.");
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_wrote.");
return NULL;
}
@@ -265,7 +271,7 @@
pageobj = PyOggPage_Alloc();
if ( !pageobj ) {
- PyErr_SetString(PyOggError, "Out of Memory.");
+ PyErr_SetString(PyOgg_Error, "Out of Memory.");
return NULL;
}
ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self),
@@ -278,9 +284,9 @@
return Py_None;
}
if (ret == OGG_HOLE ) {
- PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
+ PyErr_SetString(PyOgg_Error, "Hole in data, stream is desynced.");
return NULL;
}
- PyErr_SetString(PyOggError, "Unknown error from ogg_sync_pageout.");
+ PyErr_SetString(PyOgg_Error, "Unknown error from ogg_sync_pageout.");
return NULL;
}
<p><p>1.2 +1 -1 ogg-python2/src/pyoggsyncstate.h
Index: pyoggsyncstate.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggsyncstate.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggsyncstate.h 29 Nov 2003 09:21:57 -0000 1.1
+++ pyoggsyncstate.h 24 Feb 2004 06:31:50 -0000 1.2
@@ -1,7 +1,7 @@
#ifndef PYOGGSYNCSTATE_H
#define PYOGGSYNCSTATE_H
-#include <pyogg/pyogg2.h>
+#include "general.h"
typedef struct {
PyObject_HEAD
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list