Skip to content
Snippets Groups Projects
Commit da0bb451 authored by Sebastian's avatar Sebastian
Browse files

output libde265 warnings

parent 70249406
No related branches found
No related tags found
1 merge request!155Feature/python
Pipeline #15888 passed
......@@ -6,7 +6,7 @@ import struct
from enum import IntEnum
from collections import namedtuple
from . libde265 import Decoder
from . import libde265
try:
import cv2 as cv
......@@ -191,7 +191,6 @@ class FTLStream:
todo: fix endianess
'''
calibration = struct.unpack("@ddddIIdddd", p.data[:(4*8+2*4+4*8)])
self._calibration[sp.streamID] = _Camera._make(calibration)
......@@ -216,16 +215,25 @@ class FTLStream:
k = (sp.streamID, sp.channel)
if k not in self._decoders:
self._decoders[k] = Decoder(_definition_t[p.definition])
self._decoders[k] = libde265.Decoder(_definition_t[p.definition])
decoder = self._decoders[k]
decoder.push_data(p.data)
try:
decoder.decode()
except libde265.WaitingForInput:
pass
def _decode_hevc(self):
for stream, decoder in self._decoders.items():
try:
decoder.decode()
img = decoder.get_next_picture()
except libde265.WaitingForInput:
pass
img = decoder.get_next_picture()
if img is not None:
self._frames[stream] = _ycrcb2rgb(img)
......
......@@ -20,6 +20,8 @@ except ImportError:
# order: 0 nn, 1 bilinear, 3 bicubic
return (resize_skimage(img, size, order=3, mode="constant", cval=0) * 255).astype(np.uint8)
from warnings import warn
import ctypes
from enum import IntEnum
......@@ -35,7 +37,7 @@ if _threads is None:
# error codes copied from header (de265.h)
class libde265error(IntEnum):
class _libde265error(IntEnum):
DE265_OK = 0
DE265_ERROR_NO_SUCH_FILE=1
DE265_ERROR_COEFFICIENT_OUT_OF_IMAGE_BOUNDS=4
......@@ -86,6 +88,10 @@ libde265 = ctypes.cdll.LoadLibrary("libde265.so.0")
libde265.de265_get_error_text.argtypes = [ctypes.c_void_p]
libde265.de265_get_error_text.restype = ctypes.c_char_p
libde265.de265_get_warning.argtypes = [ctypes.c_void_p]
libde265.de265_get_warning.restype = ctypes.c_int
libde265.de265_get_version_number_major.restype = ctypes.c_uint32
libde265.de265_get_version_number_minor.restype = ctypes.c_uint32
......@@ -136,8 +142,6 @@ libde265.de265_get_image_plane.restype = ctypes.POINTER(ctypes.c_char)
libde265.de265_get_number_of_input_bytes_pending.argtypes = [ctypes.c_void_p]
libde265.de265_get_number_of_input_bytes_pending.restype = ctypes.c_int
import time
class libde265Error(Exception):
def __init__(self, code):
super(libde265Error, self).__init__(
......@@ -152,7 +156,10 @@ class Decoder:
self._more = ctypes.c_int()
self._out_stride = ctypes.c_int()
self._ctx = libde265.de265_new_decoder()
self._supress_warnings = False
err = libde265.de265_start_worker_threads(self._ctx, threads)
if err:
raise libde265Error(err)
......@@ -180,16 +187,27 @@ class Decoder:
return res
def _warning(self):
if self._supress_warnings:
return
code = libde265.de265_get_warning(self._ctx)
if code != _libde265error.DE265_OK:
msg = libde265.de265_get_error_text(code).decode("ascii")
warn(msg)
def decode(self):
err = libde265.de265_decode(self._ctx, self._more)
# should use custom
if err:
if err == libde265error.DE265_ERROR_WAITING_FOR_INPUT_DATA:
if err == _libde265error.DE265_ERROR_WAITING_FOR_INPUT_DATA:
raise WaitingForInput(err)
raise libde265Error(err)
self._warning()
return self._more.value != 0
def flush_data(self):
......@@ -234,6 +252,7 @@ class Decoder:
return None
res = self._copy_image(de265_image)
libde265.de265_release_next_picture(self._ctx)
return res
......@@ -248,6 +267,7 @@ class Decoder:
return None
res = self._copy_image(de265_image)
libde265.de265_release_next_picture(self._ctx)
return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment