From e5277510c22f30c604e1fb420f88f78dbf118959 Mon Sep 17 00:00:00 2001 From: acgnhik Date: Sat, 2 Jul 2022 23:03:08 +0800 Subject: [PATCH] refactor: workaround for negative timestamp --- src/blrec/core/operators/exception_handler.py | 1 + src/blrec/flv/format.py | 3 +++ src/blrec/flv/operators/dump.py | 3 --- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/blrec/core/operators/exception_handler.py b/src/blrec/core/operators/exception_handler.py index 033f53a..b5b2644 100644 --- a/src/blrec/core/operators/exception_handler.py +++ b/src/blrec/core/operators/exception_handler.py @@ -28,6 +28,7 @@ class ExceptionHandler(AsyncCooperationMixin): scheduler: Optional[abc.SchedulerBase] = None, ) -> abc.DisposableBase: def on_error(exc: Exception) -> None: + logger.exception(repr(exc)) self._submit_exception(exc) try: raise exc diff --git a/src/blrec/flv/format.py b/src/blrec/flv/format.py index e455d1a..37abc59 100644 --- a/src/blrec/flv/format.py +++ b/src/blrec/flv/format.py @@ -197,6 +197,9 @@ class FlvDumper: self._writer.write_ui32(size) def dump_tag(self, tag: FlvTag) -> None: + if tag.timestamp < 0: + raise FlvDataError(f'Incorrect timestamp: {tag.timestamp}', tag) + self.dump_flv_tag_header(tag) if tag.is_audio_tag(): diff --git a/src/blrec/flv/operators/dump.py b/src/blrec/flv/operators/dump.py index 86d34cc..42b3d29 100644 --- a/src/blrec/flv/operators/dump.py +++ b/src/blrec/flv/operators/dump.py @@ -90,9 +90,6 @@ class Dumper: self._timestamp_updates.on_next(0) else: if self._flv_writer is not None: - # XXX: negative timestamp will cause - # `struct.error: ubyte format requires 0 <= number <= 255` - assert item.timestamp >= 0, item size = self._flv_writer.write_tag(item) self._size_updates.on_next(size) self._timestamp_updates.on_next(item.timestamp)