1 #include "_oggmodule.h"
2 #include "pyoggstreamstate.h"
3 #include "pyoggpacket.h"
7 /*****************************************************************
9 *****************************************************************/
12 char py_ogg_stream_state_doc
[] = "";
14 static void py_ogg_stream_state_dealloc(PyObject
*);
15 static PyObject
* py_ogg_stream_state_getattr(PyObject
*, char *);
16 static PyObject
*py_ogg_stream_repr(PyObject
*self
);
18 FDEF(ogg_stream_packetin
) "Add a packet to the stream.";
19 FDEF(ogg_stream_clear
) "Clear the contents of the stream state.";
20 FDEF(ogg_stream_flush
) "Produce an ogg page suitable for writing to output.";
21 FDEF(ogg_stream_eos
) "Return whether the end of the stream is reached.";
22 FDEF(ogg_stream_pageout
) "Extract and return an OggPage.";
23 FDEF(ogg_stream_reset
) "Reset the stream state";
24 FDEF(ogg_stream_pagein
) "Write a page to the stream";
25 FDEF(ogg_stream_packetout
) "Extract a packet from the stream";
27 PyTypeObject py_ogg_stream_state_type
= {
28 PyObject_HEAD_INIT(NULL
)
31 sizeof(py_ogg_stream_state
),
34 /* Standard Methods */
35 /* (destructor) */ py_ogg_stream_state_dealloc
,
37 /* (getattrfunc) */ py_ogg_stream_state_getattr
,
38 /* (setattrfunc) */ 0,
40 /* (reprfunc) */ py_ogg_stream_repr
,
53 py_ogg_stream_state_doc
56 static PyMethodDef py_ogg_stream_state_methods
[] = {
57 {"clear", py_ogg_stream_clear
,
58 METH_VARARGS
, py_ogg_stream_clear_doc
},
59 {"flush", py_ogg_stream_flush
,
60 METH_VARARGS
, py_ogg_stream_flush_doc
},
61 {"eos", py_ogg_stream_eos
,
62 METH_VARARGS
, py_ogg_stream_eos_doc
},
63 {"packetin", py_ogg_stream_packetin
,
64 METH_VARARGS
, py_ogg_stream_packetin_doc
},
65 {"pageout", py_ogg_stream_pageout
,
66 METH_VARARGS
, py_ogg_stream_pageout_doc
},
67 {"pagein", py_ogg_stream_pagein
,
68 METH_VARARGS
, py_ogg_stream_pagein_doc
},
69 {"packetout", py_ogg_stream_packetout
,
70 METH_VARARGS
, py_ogg_stream_packetout_doc
},
71 {"reset", py_ogg_stream_reset
,
72 METH_VARARGS
, py_ogg_stream_reset_doc
},
77 py_ogg_stream_state_dealloc(PyObject
*self
)
79 ogg_stream_clear(PY_OGG_STREAM(self
));
84 py_ogg_stream_state_getattr(PyObject
*self
, char *name
)
86 return Py_FindMethod(py_ogg_stream_state_methods
, self
, name
);
90 py_ogg_stream_state_from_serialno(int serialno
)
92 py_ogg_stream_state
*ret
= PyObject_NEW(py_ogg_stream_state
,
93 &py_ogg_stream_state_type
);
98 ogg_stream_init(&ret
->os
, serialno
);
99 return (PyObject
*) ret
;
103 py_ogg_stream_state_new(PyObject
*self
, PyObject
*args
)
106 if (!PyArg_ParseTuple(args
, "i", &serialno
))
108 return py_ogg_stream_state_from_serialno(serialno
);
112 py_ogg_stream_clear(PyObject
*self
, PyObject
*args
)
114 if (!PyArg_ParseTuple(args
, ""))
116 ogg_stream_clear(PY_OGG_STREAM(self
));
122 py_ogg_stream_packetin(PyObject
*self
, PyObject
*args
)
124 py_ogg_packet
*packetobj
;
126 if (!PyArg_ParseTuple(args
, "O!", &py_ogg_packet_type
,
127 (PyObject
*) &packetobj
))
130 if (ogg_stream_packetin(PY_OGG_STREAM(self
), &packetobj
->op
)) {
131 /* currently this can't happen */
132 PyErr_SetString(Py_OggError
, "error in ogg_stream_packetin");
141 py_ogg_stream_flush(PyObject
*self
, PyObject
*args
)
146 if (!PyArg_ParseTuple(args
, ""))
148 res
= ogg_stream_flush(PY_OGG_STREAM(self
), &op
);
153 return py_ogg_page_from_page(&op
);
156 /* TODO: You can't keep a page between calls to flush or pageout!! */
159 py_ogg_stream_pageout(PyObject
*self
, PyObject
*args
)
164 if (!PyArg_ParseTuple(args
, ""))
166 res
= ogg_stream_pageout(PY_OGG_STREAM(self
), &op
);
171 return py_ogg_page_from_page(&op
);
175 py_ogg_stream_eos(PyObject
*self
, PyObject
*args
)
177 int eos
= ogg_stream_eos(PY_OGG_STREAM(self
));
178 if (!PyArg_ParseTuple(args
, ""))
180 return PyInt_FromLong(eos
);
184 py_ogg_stream_reset(PyObject
*self
, PyObject
*args
)
186 if (!PyArg_ParseTuple(args
, ""))
188 if (ogg_stream_reset(PY_OGG_STREAM(self
))) {
189 PyErr_SetString(Py_OggError
, "Error resetting stream");
198 py_ogg_stream_pagein(PyObject
*self
, PyObject
*args
)
200 py_ogg_page
*pageobj
;
202 if (!PyArg_ParseTuple(args
, "O!", &py_ogg_page_type
,
203 (PyObject
*) &pageobj
))
206 if (ogg_stream_pagein(PY_OGG_STREAM(self
), &pageobj
->op
)) {
207 PyErr_SetString(Py_OggError
, "error in ogg_stream_pagein (bad page?)");
216 py_ogg_stream_packetout(PyObject
*self
, PyObject
*args
)
221 if (!PyArg_ParseTuple(args
, ""))
223 res
= ogg_stream_packetout(PY_OGG_STREAM(self
), &op
);
227 } else if (res
== -1) {
228 PyErr_SetString(Py_OggError
, "lost sync");
231 return py_ogg_packet_from_packet(&op
);
235 py_ogg_stream_repr(PyObject
*self
)
237 ogg_stream_state
*os
= PY_OGG_STREAM(self
);
239 char *bos
= os
->b_o_s
? "BOS " : "";
240 char *eos
= os
->e_o_s
? "EOS " : "";
242 sprintf(buf
, "<OggStreamState, %s%spageno = %ld, packetno = %lld,"
243 " granulepos = %lld, serialno = %d, at %p>",
244 bos
, eos
, os
->pageno
, os
->packetno
, os
->granulepos
,
246 return PyString_FromString(buf
);