0
저는 Cython에 익숙해지기 시작했습니다. C++ 라이브러리에서 파이썬 메소드 및 클래스로 일부 클래스를 래핑하려고합니다. 필자가 실제로 이해하지 못하는 것은이 확장 모듈을 파이썬 세계에 전달하는 방법입니다. 여기 파이썬에 파이썬 확장 모듈을 전달하는 Cython이 to_py_call_code 에러를 던졌습니다.
는 C++ 클래스와 메소드 노출을 시도 내pyx
파일에서 코드입니다 :
# distutils: language = c++
# distutils: sources = Demuxer.cpp, SharedUtil.cpp, ffmpeg_tpl.c, tpl.c
# distutils: libraries = spam eggs
# distutils: include_dirs = /opt/food/include
from cython.operator cimport dereference as deref
cdef extern from "Demuxer.h":
cdef cppclass DemuxPkt:
int streamID
int tb_num
int tb_den
bint splitPoint
int ts
int duration
unsigned char* data
DemuxPkt()
int initDemuxWithFileImpl(char*)
int getNextChunkImpl(DemuxPkt*)
을 그리고 다음은 파이썬 세계로 포장하려고 코드입니다
cdef class Demuxer:
def __cinit__(self, fname, stream=None, length=None):
#if stream is not None and length is not None:
# initDemuxWithFileImpl(stream, length)
#else:
initDemuxWithFileImpl(fname)
cpdef getNextChunk(self):
cdef DemuxPacket _dpkt = DemuxPacket()
getNextChunkImpl(_dpkt._thisptr) # Is this correct??
return _dpkt
cdef class DemuxPacket(object):
"""A packet of encoded data
"""
cdef DemuxPkt* _thisptr
def __cinit__(self, flag):
#if flag is _cinit_bypass_sentinel:
# return
self._thisptr = new DemuxPkt()
if self._thisptr == NULL:
raise MemoryError()
def __dealloc__(self):
if self._thisptr != NULL:
del self._thisptr
def __call__(self):
return deref(self._thisptr)()
cpdef long getMillisecondsTs(self):
return (self._thisptr.ts*self._thisptr.tb_num)/(self._thisptr.tb_den/1000)
cpdef long getMillisecondsDuration(self):
return (self._thisptr.duration*self.struct.tb_num)/(self._thisptr.tb_den/1000)
그러나 cython을 실행하면 다음과 같은 오류가 나타납니다.
나는 메시지에 대해 전혀 몰라서 앞으로 나아갈 방법을 모른다. Cython의 버전은 우분투 14.0.4에서 0.25.2입니다.
의견을 보내주십시오.
미리 감사드립니다.