Skip to content

Commit

Permalink
add code for allocating buffers (crashes!)
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@4330 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 13, 2013
1 parent 2efff8d commit 0b43f22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/xpra/codecs/nvenc/constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ NV_ENCODE_API_FUNCTION_LIST_VER
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER
NV_ENC_INITIALIZE_PARAMS_VER
NV_ENC_PRESET_CONFIG_VER
NV_ENC_CREATE_INPUT_BUFFER_VER
NV_ENC_CREATE_BITSTREAM_BUFFER_VER

NVENC_INFINITE_GOPLENGTH

Expand Down
29 changes: 29 additions & 0 deletions src/xpra/codecs/nvenc/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ def get_version():
def get_type():
return "nvenc"

def roundup(n, m):
return (n + m - 1) & ~(m - 1)

def statusInfo(ret):
if ret in STATUS_TXT:
Expand Down Expand Up @@ -700,9 +702,12 @@ cdef class Encoder:
cdef int height
cdef object src_format
cdef void *context
cdef void *inputBuffer
cdef void *bitstreamBuffer

def init_context(self, int width, int height, src_format, int quality, int speed, options): #@DuplicatedSignature
global functionList
log.info("init_context%s", (width, height, src_format, quality, speed, options))
self.width = width
self.height = height
self.src_format = src_format
Expand All @@ -716,6 +721,29 @@ cdef class Encoder:
params.encodeHeight = height
params.enableEncodeAsync = 0
raiseCuda(functionList.nvEncInitializeEncoder(self.context, &params))
log.info("encoder initialized")

#allocate input buffer:
cdef NV_ENC_CREATE_INPUT_BUFFER createInputBufferParams
memset(&createInputBufferParams, 0, sizeof(NV_ENC_CREATE_INPUT_BUFFER))
createInputBufferParams.version = NV_ENC_CREATE_INPUT_BUFFER_VER
createInputBufferParams.width = roundup(width, 32)
createInputBufferParams.height = roundup(height, 32)
createInputBufferParams.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_UNCACHED #NV_ENC_MEMORY_HEAP_AUTOSELECT
createInputBufferParams.bufferFmt = NV_ENC_BUFFER_FORMAT_YV12_PL
raiseCuda(functionList.nvEncCreateInputBuffer(self.context, &createInputBufferParams), "creating input buffer")
self.inputBuffer = createInputBufferParams.inputBuffer
log.info("inputBuffer=%s", hex(<long> self.inputBuffer))

#allocate output buffer:
cdef NV_ENC_CREATE_BITSTREAM_BUFFER createBitstreamBufferParams
memset(&createBitstreamBufferParams, 0, sizeof(NV_ENC_CREATE_BITSTREAM_BUFFER))
createBitstreamBufferParams.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER
createBitstreamBufferParams.size = 1024*1024
createBitstreamBufferParams.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED
raiseCuda(functionList.nvEncCreateBitstreamBuffer(self.context, &createBitstreamBufferParams), "creating output buffer")
self.bitstreamBuffer = createBitstreamBufferParams.bitstreamBuffer
log.info("bitstreamBuffer=%s", hex(<long> self.bitstreamBuffer))

def get_info(self):
cdef float pps
Expand Down Expand Up @@ -754,4 +782,5 @@ cdef class Encoder:
return {}

def compress_image(self, image, options={}):
assert self.context!=NULL, "context is not initialized"
return None

0 comments on commit 0b43f22

Please sign in to comment.