|
From: oyster <lep...@gm...> - 2007-12-13 11:17:13
|
currently, some function in ming needs a FILE pointer, which is hard
for script languae(for example python) to use.
I found that there is something like
[C code]
/* added by David McNab <da...@re...> */
/* required so that python can pass in file descriptors instead of
FILE* streams */
SWFSound
newSWFSoundFromFileno(int fd, byte flags)
{
FILE *fp = fdopen(fd, "r");
return newSWFSound(fp, flags);
}
[/code]
so, my question is:
1. why not offer a peer function which only needs fielname, but act as
those needs a FILE pointer. Yes, there are some in the src, but not
all.
I have tested, but only get error message(see below), so can anyone check it?
2. or, in ming sourcecode, to offer a function, which takes the
filename then return a FILE pointer, then we don't have to modify the
ming heavily
[C code]
FILE *name2file(const char *filename)
{
return fopen(filename, "rb");
}
int closeit(FILE *f)
{
return fclose(f);
}
[/C code]
I have compiled ming-0.4.0.beta5 on win2k with mingw. Most of the test
runs ok, but after running test01.exe and test02.exe under
ming-0.4.0.beta5\test\Movie\setSoundStream\, there no flash file is
created, and there is no error message
When I translate the above C code to python with
[python]
f=open('some.flv', 'rb')
newSWFSoundStreamFromFileno(f.fileno())
[/python]
I get
[msg]
stream = newSWFSoundStreamFromFileno(fFile.fileno())
WindowsError: exception: access violation reading 0x00000034]
[/msg]
btw, I am program python-ming interface via ctypes
[python]
import os, sys
def setpath():
u=os.path.realpath(__file__)
u=os.path.split(u)[0]
u=os.path.normpath(u)
if ' ' in u:
u='"%s"' % u
if os.environ.has_key('PATH'):
os.environ['PATH']='%s;%s' % (u, os.environ['PATH'])
else:
os.environ['PATH']=u
setpath()
NULL=0
from ctypes import *
################for name2file#####################
class _FILE(Structure):
pass
FILE_PTR = POINTER(_FILE)
_name2file = CDLL('name2file.dll')
name2file = _name2file.name2file
name2file.restype = FILE_PTR
name2file.argtypes = [c_char_p]
closeit = _name2file.closeit
closeit.restype = c_int
closeit.argtypes = [FILE_PTR]
#############for ming################################
class SWFMovie_s(Structure):
pass
SWFMovie_s._fields_ = [
]
SWFMovie = POINTER(SWFMovie_s)
class SWFSoundStream_s(Structure):
pass
SWFSoundStream = POINTER(SWFSoundStream_s)
SWFSoundStream_s._fields_ = [
]
ming = CDLL('libming-0.dll')
newSWFMovieWithVersion = ming.newSWFMovieWithVersion
newSWFMovieWithVersion.restype = SWFMovie
newSWFMovieWithVersion.argtypes = [c_int]
newSWFSoundStream = ming.newSWFSoundStream
newSWFSoundStream.restype = SWFSoundStream
newSWFSoundStream.argtypes = [POINTER(_FILE)]
newSWFSoundStreamFromFileno = ming.newSWFSoundStreamFromFileno
newSWFSoundStreamFromFileno.restype = SWFSoundStream
newSWFSoundStreamFromFileno.argtypes = [c_int]
SWFMovie_setSoundStream = ming.SWFMovie_setSoundStream
SWFMovie_setSoundStream.restype = None
SWFMovie_setSoundStream.argtypes = [SWFMovie, SWFSoundStream]
SWFMovie_nextFrame = ming.SWFMovie_nextFrame
SWFMovie_nextFrame.restype = None
SWFMovie_nextFrame.argtypes = [SWFMovie]
SWFMovie_save = ming.SWFMovie_save
SWFMovie_save.restype = c_int
SWFMovie_save.argtypes = [SWFMovie, c_char_p]
def main():
m = newSWFMovieWithVersion(7);
if 0:
fFile = name2file('../test/Media/video02.flv')
print fFile
stream = newSWFSoundStream(fFile)
else:
fFile = open('../test/Media/video02.flv')
stream = newSWFSoundStreamFromFileno(fFile.fileno())
SWFMovie_setSoundStream(m, stream)
for i in range(200):
SWFMovie_nextFrame(m)
SWFMovie_save(m, "test02.swf")
main()
[/python]
|