pyremoteplay.receiver package

Module contents

AV Receivers for pyremoteplay.

class pyremoteplay.receiver.AVReceiver

Bases: ABC

Base Class for AV Receiver. Abstract. Must use subclass for session.

This class exposes the audio/video stream of the Remote Play Session. The handle_video and handle_audio methods need to be reimplemented. Re-implementing this class provides custom handling of audio and video frames.

AV_CODEC_OPTIONS_H264 = {'preset': 'ultrafast', 'tune': 'zerolatency'}
AV_CODEC_OPTIONS_HEVC = {'preset': 'ultrafast', 'tune': 'zerolatency'}
static audio_frame(buf, codec_ctx, resampler=None)

Return decoded audio frame.

Return type

AudioFrame

static video_frame(buf, codec_ctx, video_format='rgb24')

Decode H264 Frame to raw image. Return AV Frame.

Parameters
  • buf (bytes) – Raw Video Packet representing one video frame

  • codec_ctx (CodecContext) – av codec context for decoding

  • video_format – Format to output frames as.

Return type

VideoFrame

static video_codec(codec_name)

Return Video Codec Context.

Return type

CodecContext

static audio_codec(codec_name='opus')

Return Audio Codec Context.

Return type

CodecContext

static audio_resampler(audio_format='s16', channels=2, rate=48000)

Return Audio Resampler.

Return type

AudioResampler

decode_video_frame(buf)

Return decoded Video Frame.

Return type

VideoFrame

decode_audio_frame(buf)

Return decoded Audio Frame.

Return type

AudioFrame

handle_video_data(buf)

Handle video data.

handle_audio_data(buf)

Handle audio data.

handle_video(frame)

Handle video frame. Re-implementation required.

This method is called as soon as a video frame is decoded. This method should define what should happen when this frame is received. For example the frame can be stored, sent somewhere, processed further, etc.

handle_audio(frame)

Handle audio frame. Re-implementation required.

This method is called as soon as an audio frame is decoded. This method should define what should happen when this frame is received. For example the frame can be stored, sent somewhere, processed further, etc.

get_video_frame()

Return Video Frame. Re-implementation optional.

This method is a placeholder for retrieving a frame from a collection.

Return type

VideoFrame

get_audio_frame()

Return Audio Frame. Re-implementation optional.

This method is a placeholder for retrieving a frame from a collection.

Return type

AudioFrame

close()

Close Receiver.

property video_format

Return Video Format Name.

property video_decoder: CodecContext

Return Video Codec Context.

Return type

CodecContext

property audio_decoder: CodecContext

Return Audio Codec Context.

Return type

CodecContext

property audio_config: dict

Return Audio config.

Return type

dict

class pyremoteplay.receiver.QueueReceiver(max_frames=10, max_video_frames=-1, max_audio_frames=-1)

Bases: AVReceiver

Receiver which stores decoded frames in queues. New Frames are added to the end of queue. When queue is full the oldest frame is removed.

Parameters
  • max_frames – Maximum number of frames to be stored. Will be at least 1.

  • max_video_frames – Maximum video frames that can be stored. If <= 0, max_frames will be used.

  • max_audio_frames – Maximum audio frames that can be stored. If <= 0, max_frames will be used.

close()

Close Receiver.

get_video_frame()

Return oldest Video Frame from queue.

Return type

VideoFrame

get_audio_frame()

Return oldest Audio Frame from queue.

Return type

AudioFrame

get_latest_video_frame()

Return latest Video Frame from queue.

Return type

VideoFrame

get_latest_audio_frame()

Return latest Audio Frame from queue.

Return type

AudioFrame

handle_video(frame)

Handle video frame. Add to queue.

handle_audio(frame)

Handle Audio Frame. Add to queue.

property video_frames: list[av.VideoFrame]

Return Latest Video Frames.

property audio_frames: list[av.AudioFrame]

Return Latest Audio Frames.