[xiph-cvs] cvs commit: ogg-python2/src _ogg2module.c pyoggpackbuff.c pyoggpackbuff.h

Arc arc at xiph.org
Mon Dec 1 00:34:12 PST 2003



arc         03/12/01 03:34:12

  Modified:    src      _ogg2module.c pyoggpackbuff.c pyoggpackbuff.h
  Log:
  Added oggpackB_* functions for MSb codecs

Revision  Changes    Path
1.4       +4 -2      ogg-python2/src/_ogg2module.c

Index: _ogg2module.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/_ogg2module.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- _ogg2module.c	30 Nov 2003 21:03:34 -0000	1.3
+++ _ogg2module.c	1 Dec 2003 08:34:11 -0000	1.4
@@ -12,10 +12,12 @@
 #include "pyoggpage.h"
 
 static PyMethodDef Ogg_methods[] = {
-  {"OggStreamState", PyOggStreamState_New, 
-   METH_VARARGS, PyOggStreamState_Doc},
   {"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}

<p><p>1.4       +92 -16    ogg-python2/src/pyoggpackbuff.c

Index: pyoggpackbuff.c
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpackbuff.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyoggpackbuff.c	1 Dec 2003 06:49:56 -0000	1.3
+++ pyoggpackbuff.c	1 Dec 2003 08:34:11 -0000	1.4
@@ -98,6 +98,39 @@
   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 ) { 
@@ -120,7 +153,10 @@
 {
   if ( ((PyOggPackBufferObject *) self)->write_flag ) { 
     if ( ((PyOggPackBufferObject *) self)->write_flag == 1 ) {
-      oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+      if ( ((PyOggPackBufferObject *) self)->msb_flag )
+        oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+      else 
+        oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
     }
   }
   else  /* Release the packet being read */
@@ -152,7 +188,10 @@
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
-  ret = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+  if ( ((PyOggPackBufferObject *) self)->msb_flag )
+    ret = oggpackB_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+  else
+    ret = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
   return PyLong_FromLong(ret);
 }
 
@@ -164,7 +203,10 @@
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
-  ret = oggpack_bits(PyOggPackBuffer_AsOggPackBuffer(self));
+  if ( ((PyOggPackBufferObject *) self)->msb_flag )
+    ret = oggpackB_bits(PyOggPackBuffer_AsOggPackBuffer(self));
+  else
+    ret = oggpack_bits(PyOggPackBuffer_AsOggPackBuffer(self));
   return PyLong_FromLong(ret);
 }
 
@@ -175,7 +217,10 @@
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
     
-  oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+  if ( ((PyOggPackBufferObject *) self)->msb_flag )
+    oggpackB_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
+  else
+    oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
   Py_INCREF(Py_None);
   return Py_None;
 }
@@ -185,12 +230,16 @@
 PyOggPackBuffer_Look(PyObject *self, PyObject *args) 
 {
   int bits = 1;
+  long num;
   long ret;
   if (!PyArg_ParseTuple(args, "l", &bits))
     return NULL;
 
   if ( bits == 1 ) {
-    ret = oggpack_look1(PyOggPackBuffer_AsOggPackBuffer(self));
+    if ( ((PyOggPackBufferObject *) self)->msb_flag )
+      ret = oggpackB_look1(PyOggPackBuffer_AsOggPackBuffer(self));
+    else
+      ret = oggpack_look1(PyOggPackBuffer_AsOggPackBuffer(self));
     return PyLong_FromLong(ret);
   }
   
@@ -199,8 +248,12 @@
     return NULL;
   }
 
-  if ( oggpack_look(PyOggPackBuffer_AsOggPackBuffer(self), bits, &ret) == 0 )
-    return PyLong_FromLong(ret);
+  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;
 }
@@ -210,13 +263,17 @@
 PyOggPackBuffer_Read(PyObject *self, PyObject *args) 
 {
   int bits = 1;
+  long num;
   long ret;
   
   if (!PyArg_ParseTuple(args, "|i", &bits))
     return NULL;
   
   if ( bits == 1 ) {
-    ret = oggpack_read1(PyOggPackBuffer_AsOggPackBuffer(self));
+    if ( ((PyOggPackBufferObject *) self)->msb_flag )
+      ret = oggpackB_read1(PyOggPackBuffer_AsOggPackBuffer(self));
+    else
+      ret = oggpack_read1(PyOggPackBuffer_AsOggPackBuffer(self));
     return PyInt_FromLong(ret);
   }
   
@@ -225,8 +282,13 @@
     return NULL;
   } 
 
-  if ( oggpack_read(PyOggPackBuffer_AsOggPackBuffer(self), bits, &ret) == 0 )
-    return PyInt_FromLong(ret);
+
+  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;
 }
@@ -241,9 +303,15 @@
     return NULL;
 
   if ( bits == 1 ) 
-    oggpack_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
+    if ( ((PyOggPackBufferObject *) self)->msb_flag )
+      oggpackB_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
+    else
+      oggpack_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
   else 
-    oggpack_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);
+    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;
@@ -263,8 +331,11 @@
     PyErr_SetString(PyExc_ValueError, "Cannot write more than 32 bits");
     return NULL;
   }
-
-  oggpack_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);
+    
+  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;
@@ -283,8 +354,13 @@
   packetobj = PyOggPacket_Alloc();
   op = packetobj->packet;
 
-  op->packet = oggpack_writebuffer(PyOggPackBuffer_AsOggPackBuffer(self));
-  op->bytes = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
+  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;

<p><p>1.3       +2 -0      ogg-python2/src/pyoggpackbuff.h

Index: pyoggpackbuff.h
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/src/pyoggpackbuff.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- pyoggpackbuff.h	1 Dec 2003 06:49:56 -0000	1.2
+++ pyoggpackbuff.h	1 Dec 2003 08:34:11 -0000	1.3
@@ -6,6 +6,7 @@
 
 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 */
@@ -16,5 +17,6 @@
 extern PyTypeObject PyOggPackBuffer_Type;
 
 PyObject *PyOggPackBuffer_New(PyObject *, PyObject *);
+PyObject *PyOggPackBuffer_NewB(PyObject *, PyObject *);
 
 #endif

<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