[xiph-commits] r7449 - trunk/vorbisfile-python

jack at motherfish-iii.xiph.org jack
Thu Aug 5 19:06:45 PDT 2004


Author: jack
Date: Thu Aug  5 19:06:45 2004
New Revision: 7449

Added:
trunk/vorbisfile-python/vorbisfile.py
Modified:
trunk/vorbisfile-python/vorbisfile.c
Log:
First stab at class wrapper for _vorbisfile.


Modified: trunk/vorbisfile-python/vorbisfile.c
===================================================================
--- trunk/vorbisfile-python/vorbisfile.c	2004-08-01 16:46:41 UTC (rev 7448)
+++ trunk/vorbisfile-python/vorbisfile.c	2004-08-02 04:54:20 UTC (rev 7449)
@@ -143,7 +143,7 @@
Py_INCREF(file);
ret = ov_open_callbacks((void *)file, vf, NULL, 0, callbacks);
if (ret != 0) {
-	/* FIXME: implement error handling */
+	/* FIXME: handle open failures more gracefully */
PyErr_SetString(PyExc_StandardError, "ov_open failed");
PyMem_Free((void *)vf);
return NULL;
@@ -933,69 +933,69 @@

static PyMethodDef vorbisfileMethods[] = {
{"ov_open", ov_open_py, METH_VARARGS,
-     "Open an Ogg Vorbis file"},
+     "Opens a Vorbis file"},
{"ov_test", ov_test_py, METH_VARARGS,
-     "Test an Ogg Vorbis file"},
+     "Tests if a file is a Vorbis file"},
{"ov_test_open", ov_test_open_py, METH_VARARGS,
-     "Open an Ogg Vorbis file after testing"},
+     "Opens a Vorbis file after testing"},
{"ov_clear", ov_clear_py, METH_VARARGS,
-     "Clear a vorbisfile object"},
+     "Clears a vorbisfile object"},
{"ov_bitrate", ov_bitrate_py, METH_VARARGS,
-     "Return bitrate of chain(s)"},
+     "Returns bitrate of chain(s)"},
{"ov_bitrate_instant", ov_bitrate_instant_py, METH_VARARGS,
-     "Return instantaneous bitrate"},
+     "Returns instantaneous bitrate"},
{"ov_streams", ov_streams_py, METH_VARARGS,
-     "Return number of chains"},
+     "Returns number of chains"},
{"ov_seekable", ov_seekable_py, METH_VARARGS,
-     "Return whether stream is seekable"},
+     "Returns whether stream is seekable"},
{"ov_serialnumber", ov_serialnumber_py, METH_VARARGS,
-     "Return link's serial number"},
+     "Returns a link's serial number"},
{"ov_raw_total", ov_raw_total_py, METH_VARARGS,
-     "return something"},
+     "Returns total raw compressed length of bitstream"},
{"ov_pcm_total", ov_pcm_total_py, METH_VARARGS,
-     "return something"},
+     "Returns total number of PCM samples"},
{"ov_time_total", ov_time_total_py, METH_VARARGS,
-     "return something"},
+     "Returns total length of bitstream in seconds"},
{"ov_raw_seek", ov_raw_seek_py, METH_VARARGS,
-     "return something"},
+     "Seeks to an offset relative to compressed data"},
{"ov_pcm_seek", ov_pcm_seek_py, METH_VARARGS,
-     "return something"},
+     "Seeks to a sample offset of the PCM data"},
{"ov_pcm_seek_page", ov_pcm_seek_page_py, METH_VARARGS,
-     "return something"},
+     "Seeks to page near sample offset"},
{"ov_time_seek", ov_time_seek_py, METH_VARARGS,
-     "return something"},
+     "Seeks to sample at time"},
{"ov_time_seek_page", ov_time_seek_page_py, METH_VARARGS,
-     "return something"},
+     "Seeks to page near sample at time"},
{"ov_raw_seek_lap", ov_raw_seek_lap_py, METH_VARARGS,
-     "return something"},
+     "Seeks something (FIXME)"},
{"ov_pcm_seek_lap", ov_pcm_seek_lap_py, METH_VARARGS,
-     "return something"},
+     "Seeks something (FIXME)"},
{"ov_pcm_seek_page_lap", ov_pcm_seek_page_lap_py, METH_VARARGS,
-     "return somethings"},
+     "Seeks something (FIXME)"},
{"ov_time_seek_lap", ov_time_seek_lap_py, METH_VARARGS,
-     "return something"},
+     "Seeks something (FIXME)"},
{"ov_time_seek_page_lap", ov_time_seek_page_lap_py, METH_VARARGS,
-     "return something"},
+     "Seeks something (FIXME)"},
{"ov_raw_tell", ov_raw_tell_py, METH_VARARGS,
-     "return something"},
+     "Returns the current stream offset"},
{"ov_pcm_tell", ov_pcm_tell_py, METH_VARARGS,
-     "return something"},
+     "Returns PCM offset of next sample to be read"},
{"ov_time_tell", ov_time_tell_py, METH_VARARGS,
-     "return something"},
+     "Returns time offset of next sample to be read"},
{"ov_info", ov_info_py, METH_VARARGS,
-     "return something"},
+     "Returns the vorbis_info object for the current chain"},
{"ov_comment", ov_comment_py, METH_VARARGS,
-     "return something"},
+     "Returns the vorbis_comment object for the current chain"},
{"ov_read_float", ov_read_float_py, METH_VARARGS,
-     "return something"},
+     "Returns array of decoded float data"},
{"ov_read", ov_read_py, METH_VARARGS,
-     "return something"},
+     "Returns array of decoded sample data"},
{"ov_crosslap", ov_crosslap_py, METH_VARARGS,
-     "return something"},
+     "Crosses something (FIXME)"},
{"ov_halfrate", ov_halfrate_py, METH_VARARGS,
-     "return something"},
+     "Does something (FIXME)"},
{"ov_halfrate_p", ov_halfrate_p_py, METH_VARARGS,
-     "return something"},
+     "Does something (FIXME)"},
{NULL, NULL, 0, NULL}
};


Added: trunk/vorbisfile-python/vorbisfile.py
===================================================================
--- trunk/vorbisfile-python/vorbisfile.py	2004-08-01 16:46:41 UTC (rev 7448)
+++ trunk/vorbisfile-python/vorbisfile.py	2004-08-02 04:54:20 UTC (rev 7449)
@@ -0,0 +1,53 @@
+import types
+from _vorbisfile import *
+
+class VorbisFile(object):
+    def __init__(self):
+        self.vf = None
+        self.testing = 0
+
+    def open(self, file=None):
+        if not self.testing and not file:
+            raise StandardException, "Expected a file object or "\
+                  "string, or test mode."
+        elif self.testing:
+            ret = ov_test_open(self.vf)
+            # FIXME: check return value
+        else:
+            if type(file) == types.StringType:
+                self.vf = ov_open(open(file))
+            else:
+                self.vf = ov_open(file)
+
+        return self.vf != None
+
+    def test(self, file):
+        self.testing = 1
+
+        if type(file) == types.StringType:
+            self.vf = ov_test(open(file))
+        else:
+            self.vf = ov_test(file)
+
+        return self.vf != None
+
+    def clear(self):
+        return ov_clear(self.vf)
+
+    def bitrate(self, link=-1):
+        return ov_bitrate(self.vf, link)
+
+    def bitrate_instant(self):
+        return ov_bitrate_instant(self.vf)
+
+    def links(self):
+        return ov_streams(self.vf)
+
+    def seekable(self):
+        return ov_seekable(self.vf)
+
+    def serialnumber(self, link=-1):
+        return ov_serialnumber(self.vf, link)
+
+    def raw_length(self, link=-1):
+        return ov_raw_total(self.vf, link)



More information about the commits mailing list