It doesn't do anything yet, except compile to Pyrex C code...

--HG--
extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%4022
issue20
tibs 2008-07-28 22:20:43 +00:00
rodzic c8e31f28d2
commit 0a3b3284ae
1 zmienionych plików z 59 dodań i 0 usunięć

59
es.pyx 100644
Wyświetl plik

@ -0,0 +1,59 @@
"""es.pyx -- Pyrex bindings for es.c
Whilst starting, "compile" with::
pyrexc es.pyx -o es.pyx.c
"""
# If we're going to use definitions like this in more than one pyx file, we'll
# need to define the shared types in a .pxd file and use cimport to import
# them.
cdef extern from "stdio.h":
ctypedef struct FILE:
int _fileno
cdef extern from 'es_defns.h':
# The reader for an ES file
struct elementary_stream:
pass
ctypedef elementary_stream ES
ctypedef elementary_stream *ES_p
# An actual ES unit
struct ES_unit:
pass
ctypedef ES_unit *ES_unit_p
cdef extern from 'es_fns.h':
int open_elementary_stream(char *filename, ES_p *es)
void free_elementary_stream(ES_p *es)
int find_and_build_next_ES_unit(ES_p es, ES_unit_p *unit)
void free_ES_unit(ES_unit_p *unit)
void report_ES_unit(FILE *stream, ES_unit_p unit)
# Is this the best thing to do?
class TSToolsException(Exception):
pass
cdef class ESStream:
"""A Python class representing an ES stream, readable from a file.
"""
cdef ES_p stream
# It appears to be recommended to make __cinit__ expand to take more
# arguments (if __init__ ever gains them), since both get the same
# things passed to them. Hmm, normally I'd trust myself, but let's
# try the recommended route
def __cinit__(self,filename,*args,**kwargs):
retval = open_elementary_stream(filename,&self.stream)
if retval != 0:
raise TSToolsException,'Error opening ES file %s'%filename
def __init__(self,filename):
# The __cinit__ method will already have *used* the filename,
# but it may be useful to remember it for later on
self.filename = filename
def __dealloc__(self):
free_elementary_stream(&self.stream)