[xiph-cvs] cvs commit: ogg-python2/src _ogg2module.c pyoggpacket.c pyoggpacket.h pyoggpage.c pyoggpage.h pyoggstreamstate.c pyoggsyncstate.c

Arc arc at xiph.org
Sat Nov 29 10:49:20 PST 2003



arc         03/11/29 13:49:20

  Modified:    include/pyogg pyogg2.h
               src      _ogg2module.c pyoggpacket.c pyoggpacket.h
                        pyoggpage.c pyoggpage.h pyoggstreamstate.c
                        pyoggsyncstate.c
  Log:
  PyOggPage works now except for access to it's header/body

Revision  Changes    Path
1.2       +1 -1      ogg-python2/include/pyogg/pyogg2.h

Index: pyogg2.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/include/pyogg/pyogg2.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyogg2.h	29 Nov 2003 14:50:58 -0000	1.1
+++ pyogg2.h	29 Nov 2003 18:49:19 -0000	1.2
@@ -15,7 +15,7 @@
   PyTypeObject *PyOggPacket_Type;
   PyTypeObject *PyOggStreamState_Type;
   PyObject *PyOggError;
-  PyObject *(*PyOggPacket_From_Packet)(ogg_packet *packet);
+/*  PyOggPacketObject *(*PyOggPacket_Alloc)(); */
   int (*arg_to_int64)(PyObject *longobj, ogg_int64_t *val);
 } ogg2_module_info;
 

<p><p>1.2       +3 -1      ogg-python2/src/_ogg2module.c

Index: _ogg2module.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/_ogg2module.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- _ogg2module.c	29 Nov 2003 09:21:57 -0000	1.1
+++ _ogg2module.c	29 Nov 2003 18:49:20 -0000	1.2
@@ -23,13 +23,15 @@
 
 static char docstring[] = "";
 
+/* 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_FromPacket,
+/*  PyOggPacket_Alloc, */
   arg_to_int64,
 };
 

<p><p>1.2       +15 -6     ogg-python2/src/pyoggpacket.c

Index: pyoggpacket.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpacket.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggpacket.c	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggpacket.c	29 Nov 2003 18:49:20 -0000	1.2
@@ -51,18 +51,27 @@
   {NULL, NULL}
 };
 
-PyObject *
-PyOggPacket_FromPacket(ogg_packet *packet)
+PyOggPacketObject * 
+PyOggPacket_Alloc() 
 {
-  PyOggPacketObject *ret = (PyOggPacketObject *) PyObject_NEW(PyOggPacketObject, 
-				                  &PyOggPacket_Type);
+  ogg_packet *packet;
+  PyOggPacketObject *ret;
+
+  ret = (PyOggPacketObject *) PyObject_NEW(PyOggPacketObject,
+                                           &PyOggPacket_Type);
   if (ret == NULL)
     return NULL;
 
-  ret->packet = packet;
-  return (PyObject *)ret;
+  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)
 {

<p><p>1.2       +2 -2      ogg-python2/src/pyoggpacket.h

Index: pyoggpacket.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpacket.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggpacket.h	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggpacket.h	29 Nov 2003 18:49:20 -0000	1.2
@@ -8,8 +8,8 @@
 
 extern PyTypeObject PyOggPacket_Type;
 
-#define PyOggPacket_AsOggPacket(x) (((PyOggPacketObject *) (x))->packet)
+#define PyOggPacket_AsOggPacket(x) ( ((PyOggPacketObject *) (x))->packet )
 
-PyObject *PyOggPacket_FromPacket(ogg_packet *);
+PyOggPacketObject *PyOggPacket_Alloc(void);
 
 #endif /* PYOGGPACKET_H */

<p><p>1.2       +24 -15    ogg-python2/src/pyoggpage.c

Index: pyoggpage.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpage.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggpage.c	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggpage.c	29 Nov 2003 18:49:20 -0000	1.2
@@ -61,25 +61,34 @@
   {NULL, NULL}
 };
 
-static void 
-PyOggPage_Dealloc(PyObject *self) {
-  ogg_page_release(PyOggPage_AsOggPage(self));
-  PyObject_Del(self);
-}
-
-
-PyObject *
-PyOggPage_FromOggPage(ogg_page *page) {
-  PyOggPageObject *ret = (PyOggPageObject *) PyObject_NEW(PyOggPageObject, 
-                                                          &PyOggPage_Type);
+PyOggPageObject *
+PyOggPage_Alloc() {
+  ogg_page *page;
+  PyOggPageObject *ret;
 
+  ret = (PyOggPageObject *) PyObject_NEW(PyOggPageObject, &PyOggPage_Type);
   if (ret == NULL)
     return NULL;
 
+  page = PyMem_New(ogg_page, 1);
+  if (page == NULL) {
+    PyObject_Del(ret);
+    return NULL;
+  }
+  memset(page, 0, sizeof(*page));
+
   ret->page = page;
-  return (PyObject *) ret;
+  return ret;
 }
 
+static void 
+PyOggPage_Dealloc(PyObject *self) {
+  ogg_page_release(PyOggPage_AsOggPage(self));
+  PyMem_Del(PyOggPage_AsOggPage(self));
+  PyObject_Del(self);
+}
+
+
 static PyObject *
 PyOggPage_Size(PyObject *self, PyObject *args) {
   int size;
@@ -267,16 +276,16 @@
   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, " : "";
-
   sprintf(buf, "<OggPage, %s%s%spageno = %ld, granulepos = %lld,"
           " packets = %d, serialno = %d, version = %d," 
-          " head length = %ld, body length = %ld at %p>",
+          " head length = %ld, body length = %ld, at %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)->body_len,
+          PyOggPage_AsOggPage(self)); 
   return PyString_FromString(buf);
 }

<p><p>1.2       +1 -1      ogg-python2/src/pyoggpage.h

Index: pyoggpage.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpage.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggpage.h	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggpage.h	29 Nov 2003 18:49:20 -0000	1.2
@@ -12,6 +12,6 @@
 
 extern PyTypeObject PyOggPage_Type;
 
-PyObject *PyOggPage_FromOggPage(ogg_page *page);
+PyOggPageObject *PyOggPage_Alloc(void);
 
 #endif

<p><p>1.2       +32 -11    ogg-python2/src/pyoggstreamstate.c

Index: pyoggstreamstate.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggstreamstate.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggstreamstate.c	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggstreamstate.c	29 Nov 2003 18:49:20 -0000	1.2
@@ -140,13 +140,20 @@
 PyOggStreamState_Pageout(PyObject *self, PyObject *args)
 {
   int ret;
-  ogg_page *page;
+  PyOggPageObject *pageobj;
   
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
-  ret = ogg_stream_pageout(PyOggStreamState_AsOggStreamState(self), page);
-  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
+  pageobj = PyOggPage_Alloc();
+  if ( !pageobj ) {
+    PyErr_SetString(PyOggError, "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;
 }
@@ -156,14 +163,20 @@
 PyOggStreamState_Flush(PyObject *self, PyObject *args)
 {
   int ret;
-  ogg_page *page;
+  PyOggPageObject *pageobj;
   
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
-  
-  ret = ogg_stream_flush(PyOggStreamState_AsOggStreamState(self), page);
-  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
-  
+
+  pageobj = PyOggPage_Alloc();
+  if ( !pageobj ) {
+    PyErr_SetString(PyOggError, "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;
 }
@@ -202,13 +215,21 @@
 PyOggStreamState_Packetout(PyObject *self, PyObject *args)
 {
   int ret;
-  ogg_packet *packet;
+  PyOggPacketObject *packetobj;
   
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
-  ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self), packet);
-  if (ret == 1) return PyOggPacket_FromPacket(packet);
+  packetobj = PyOggPacket_Alloc();
+  if ( !packetobj ) {
+    PyErr_SetString(PyOggError, "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);

<p><p>1.2       +10 -4     ogg-python2/src/pyoggsyncstate.c

Index: pyoggsyncstate.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggsyncstate.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pyoggsyncstate.c	29 Nov 2003 09:21:57 -0000	1.1
+++ pyoggsyncstate.c	29 Nov 2003 18:49:20 -0000	1.2
@@ -253,15 +253,21 @@
 PyOggSyncState_Pageout(PyObject *self, PyObject *args) 
 {
   int ret;
-  ogg_page *page;
+  PyOggPageObject *pageobj;
 
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
-  page = NULL;
-  ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self), page);
+  pageobj = PyOggPage_Alloc();
+  if ( !pageobj ) {
+    PyErr_SetString(PyOggError, "Out of Memory.");
+    return NULL;
+  }
+  ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self),
+                         PyOggPage_AsOggPage(pageobj));
 
-  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
+  if ( ret == 1 ) return (PyObject *) pageobj;
+  Py_DECREF(pageobj);
   if ( ret == 0 ) {
     Py_INCREF(Py_None);
     return Py_None;

<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