[xiph-commits] r7297 - in trunk/py-ogg2: examples src

arc at dactyl.lonelymoon.com arc
Fri Jul 23 16:13:09 PDT 2004


Author: arc
Date: Fri Jul 23 16:13:09 2004
New Revision: 7297

Modified:
trunk/py-ogg2/examples/writ_encoder.py
trunk/py-ogg2/src/packet.c
trunk/py-ogg2/src/page.c
Log:
This takes care of several compiler warnings and brings py-ogg2 to sync
with libogg2, specifically, rewritting OggPage's setattr functions.

There seems to be a problem with OggSyncState that I have yet to
resolve.  I hope it's in py-ogg2 and not libogg2.  Apparently, the Sync
buffer believes that fewer bytes have been submitted than have actually
been.  This results, in my test scripts, in files being outputted that
are half the size as they should be.



Modified: trunk/py-ogg2/examples/writ_encoder.py
===================================================================
--- trunk/py-ogg2/examples/writ_encoder.py	2004-07-23 23:07:26 UTC (rev 7296)
+++ trunk/py-ogg2/examples/writ_encoder.py	2004-07-23 23:13:08 UTC (rev 7297)
@@ -1,5 +1,5 @@
'''
-  function: Ogg Writ reference encoder
+  function: Ogg Writ 1.2 reference encoder
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
@@ -69,10 +69,7 @@
packetno = self.packet.packetno
self.os.packetin(self.packet)
if self.pn != 2 :
-            print "Flushing: %d" % (packetno)
self.flush()
-         else :
-            print "Skipping: %d" % (packetno)
self.packet = packet
self.pn = self.pn + 1

@@ -83,9 +80,7 @@
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
@@ -129,8 +124,8 @@
# 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(1,8)				# version = 1
+bp.write(2,8)				# subversion = 2
bp.write(gnum,32)			# granulerate_numerator
bp.write(gden,32)			# granulerate_denominator
os.packetin(bp.export())

Modified: trunk/py-ogg2/src/packet.c
===================================================================
--- trunk/py-ogg2/src/packet.c	2004-07-23 23:07:26 UTC (rev 7296)
+++ trunk/py-ogg2/src/packet.c	2004-07-23 23:13:08 UTC (rev 7297)
@@ -57,10 +57,10 @@
};

static PyMethodDef PyOggPacket_methods[] = {
-  {"bos", NULL, NULL},
-  {"eos", NULL, NULL},
-  {"granulepos", NULL, NULL},
-  {"packetno", NULL, NULL},
+  {"bos", NULL},
+  {"eos", NULL},
+  {"granulepos", NULL},
+  {"packetno", NULL},
{NULL, NULL}
};


Modified: trunk/py-ogg2/src/page.c
===================================================================
--- trunk/py-ogg2/src/page.c	2004-07-23 23:07:26 UTC (rev 7296)
+++ trunk/py-ogg2/src/page.c	2004-07-23 23:13:08 UTC (rev 7297)
@@ -39,7 +39,7 @@
PyOggPage_Dealloc,	/* (destructor) */
0,			/* (printfunc) */
PyOggPage_Getattr,	/* (getattrfunc) */
-  0, 			/* (setattrfunc) */ /* disabled PyOggPage_Setattr, */
+  PyOggPage_Setattr, 	/* (setattrfunc) */
0, 			/* (cmpfunc) */
PyOggPage_Repr,	/* (reprfunc) */

@@ -58,14 +58,14 @@
};

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},
+  {"bos", NULL},
+  {"continued", NULL},
+  {"eos", NULL},
+  {"granulepos", NULL},
+  {"packets", NULL},
+  {"pageno", NULL},
+  {"serialno", NULL},
+  {"version", NULL},
{NULL, NULL}
};

@@ -140,122 +140,75 @@
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 (((PyOggPageObject *) self)->valid_flag == 0) {
+    PyErr_SetString(PyOggPage_Error, "this page is no longer usable.");
+    return -1;
+  }
if (strcmp(name, "bos") == 0) {
-    ogg_int64_t v;
-
-    if (!arg_to_int64(value, &v))
+    int v;
+    if (!arg_to_int32(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
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));
-      }
}
+    ogg_page_set_bos(PyOggPage_AsOggPage(self), v);
return 0;
}
-
if (strcmp(name, "continued") == 0) {
-    ogg_int64_t v;
-
-    if (!arg_to_int64(value, &v))
+    int v;
+    if (!arg_to_int32(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
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));
-      }
}
+    ogg_page_set_continued(PyOggPage_AsOggPage(self), v);
return 0;
}
-
if (strcmp(name, "eos") == 0) {
-    ogg_int64_t v;
-
-    if (!arg_to_int64(value, &v))
+    int v;
+    if (!arg_to_int32(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
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));
-      }
}
+    ogg_page_set_eos(PyOggPage_AsOggPage(self), v);
return 0;
}
-
if (strcmp(name, "granulepos") == 0) {
-    int i;
ogg_int64_t v;
-    if (!arg_to_int64(value, &v))
+    if (!arg_to_int64(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
return -1;
-    for (i=6; i<14; i++) {
-      head[i] = v & 0xff;
-      v >>= 8;
}
-    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+    ogg_page_set_granulepos(PyOggPage_AsOggPage(self), v);
return 0;
}
-
if (strcmp(name, "pageno") == 0) {
-    int i;
-    ogg_int32_t v;
-    if (!arg_to_int32(value, &v))
+    ogg_uint32_t v;
+    if (!arg_to_int32(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
return -1;
-    for (i=18; i<22; i++) {
-      head[i] = v & 0xff;
-      v >>= 8;
}
-    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+    ogg_page_set_pageno(PyOggPage_AsOggPage(self), v);
return 0;
}
-
if (strcmp(name, "serialno") == 0) {
-    int i;
-    ogg_int32_t v;
-    if (!arg_to_int32(value, &v))
+    ogg_uint32_t v;
+    if (!arg_to_int32(value, &v)) {
+      PyErr_SetString(PyExc_ValueError, "value must be type INT");
return -1;
-    for (i=14; i<18; i++) {
-      head[i] = v & 0xff;
-      v >>= 8;
}
-    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
+    ogg_page_set_serialno(PyOggPage_AsOggPage(self), v);
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_ValueError, "version is read-only");
+    return -1;
}
+  if (strcmp(name, "packets") == 0) {
+    PyErr_SetString(PyExc_ValueError, "packets is read-only, use OggStreamState");
+    return -1;
+  }
PyErr_SetString(PyExc_AttributeError, "OggPage object has no such attribute");
return -1;
}



More information about the commits mailing list