mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2024-12-21 20:29:21 +00:00
Allow player to exit cleanly
- can't emit Terminate opcode in the middle of the bytestream - pad the TCP stream to next 2k boundary when emitting terminate opcode, since the player will block until receiving this much data.
This commit is contained in:
parent
8ffc8efaac
commit
531a6ae345
@ -29,12 +29,12 @@ def main(args):
|
|||||||
m = movie.Movie(
|
m = movie.Movie(
|
||||||
filename,
|
filename,
|
||||||
every_n_video_frames=args.every_n_video_frames,
|
every_n_video_frames=args.every_n_video_frames,
|
||||||
audio_normalization=args.audio_normalization)
|
audio_normalization=args.audio_normalization,
|
||||||
|
max_bytes_out = 1024. * 1024 * args.max_output_mb
|
||||||
|
)
|
||||||
|
|
||||||
print("Input frame rate = %f" % m.video.input_frame_rate)
|
print("Input frame rate = %f" % m.video.input_frame_rate)
|
||||||
|
|
||||||
max_bytes_out = 1024. * 1024 * args.max_output_mb
|
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
out_filename = args.output
|
out_filename = args.output
|
||||||
else:
|
else:
|
||||||
@ -45,11 +45,6 @@ def main(args):
|
|||||||
for bytes_out, b in enumerate(m.emit_stream(m.encode())):
|
for bytes_out, b in enumerate(m.emit_stream(m.encode())):
|
||||||
out.write(bytearray([b]))
|
out.write(bytearray([b]))
|
||||||
|
|
||||||
if max_bytes_out and bytes_out >= max_bytes_out:
|
|
||||||
break
|
|
||||||
|
|
||||||
out.write(bytes(m.done()))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(parser.parse_args())
|
main(parser.parse_args())
|
||||||
|
@ -12,9 +12,13 @@ class Movie:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self, filename: str,
|
self, filename: str,
|
||||||
every_n_video_frames: int = 1,
|
every_n_video_frames: int = 1,
|
||||||
audio_normalization: float = None):
|
audio_normalization: float = None,
|
||||||
|
max_bytes_out: int = None
|
||||||
|
):
|
||||||
self.filename = filename # type: str
|
self.filename = filename # type: str
|
||||||
self.every_n_video_frames = every_n_video_frames # type: int
|
self.every_n_video_frames = every_n_video_frames # type: int
|
||||||
|
self.max_bytes_out = max_bytes_out # type: int
|
||||||
|
|
||||||
self.audio = audio.Audio(
|
self.audio = audio.Audio(
|
||||||
filename, normalization=audio_normalization) # type: audio.Audio
|
filename, normalization=audio_normalization) # type: audio.Audio
|
||||||
self.video = video.Video(filename) # type: video.Video
|
self.video = video.Video(filename) # type: video.Video
|
||||||
@ -75,6 +79,9 @@ class Movie:
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for op in ops:
|
for op in ops:
|
||||||
|
if self.stream_pos >= self.max_bytes_out:
|
||||||
|
yield from self.done()
|
||||||
|
return
|
||||||
# Keep track of where we are in TCP client socket buffer
|
# Keep track of where we are in TCP client socket buffer
|
||||||
socket_pos = self.stream_pos % 2048
|
socket_pos = self.stream_pos % 2048
|
||||||
if socket_pos >= 2044:
|
if socket_pos >= 2044:
|
||||||
@ -88,3 +95,7 @@ class Movie:
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
yield from self._emit_bytes(opcodes.Terminate())
|
yield from self._emit_bytes(opcodes.Terminate())
|
||||||
|
|
||||||
|
# Player expects to fill 2K TCP buffer so pad it out
|
||||||
|
for _ in range(2048 - (self.stream_pos % 2048)):
|
||||||
|
yield 0x00
|
||||||
|
Loading…
Reference in New Issue
Block a user