# flake8: noqa
from construct import *
from xbox.nano.enum import RtpPayloadType, ChannelControlPayloadType, ChannelClass
from xbox.sg.utils.struct import XStruct
from xbox.sg.utils.adapters import XSwitch, XEnum, XInject, PrefixedBytes


channel_control_handshake = XStruct(
    'type' / XEnum(Int8ul, ChannelControlPayloadType),
    'connection_id' / Int16ul
)


channel_control = XStruct(
    'type' / XEnum(Int32ul, ChannelControlPayloadType),
    'name' / If(
        this.type == ChannelControlPayloadType.ChannelCreate,
        XEnum(PascalString(Int16ul, 'utf8'), ChannelClass)
    ),
    'flags' / XSwitch(
        this.type, {
            # Flags: For control channel, second Int16ul is protocol version. First doesnt seem to do anything
            ChannelControlPayloadType.ChannelCreate: Int32ul,
            ChannelControlPayloadType.ChannelOpen: PrefixedBytes(Int32ul),
            # Might be reason?
            ChannelControlPayloadType.ChannelClose: Int32ul
        }
    )
)

Esempio n. 2
0
# flake8: noqa
from construct import *
from xbox.sg.utils.struct import XStruct
from xbox.sg.utils.adapters import XEnum, PrefixedBytes
from xbox.nano.enum import AudioCodec
from xbox.nano.adapters import ReferenceTimestampAdapter

fmt = XStruct(
    'channels' / Int32ul,
    'sample_rate' / Int32ul,
    'codec' / XEnum(Int32ul, AudioCodec),
    'pcm' / If(
        this.codec == AudioCodec.PCM,
        Struct(
            'bit_depth' / Int32ul,
            'type' / Int32ul  # float or integer
        )))

server_handshake = XStruct('protocol_version' / Int32ul,
                           'reference_timestamp' / ReferenceTimestampAdapter(),
                           'formats' / PrefixedArray(Int32ul, fmt))

client_handshake = XStruct('initial_frame_id' / Int32ul,
                           'requested_format' / fmt)

control = XStruct('flags' /
                  BitStruct(Padding(1), 'reinitialize' / Default(Flag, False),
                            Padding(1), 'start_stream' / Default(Flag, False),
                            'stop_stream' / Default(Flag, False), Padding(27)))

data = XStruct('flags' / Int32ul, 'frame_id' / Int32ul, 'timestamp' / Int64ul,
# flake8: noqa
"""
Construct containers for message header and payloads
"""
from construct import *
from xbox.sg import enum
from xbox.sg.enum import PacketType, MessageType
from xbox.sg.utils.struct import XStruct
from xbox.sg.utils.adapters import CryptoTunnel, UUIDAdapter, JsonAdapter, XSwitch, XEnum, SGString, PrefixedBytes

header = XStruct(
    'pkt_type' / Default(XEnum(Int16ub, PacketType), PacketType.Message),
    'protected_payload_length' / Default(Int16ub, 0),
    'sequence_number' / Int32ub, 'target_participant_id' / Int32ub,
    'source_participant_id' / Int32ub,
    'flags' / BitStruct('version' / Default(BitsInteger(2), 2),
                        'need_ack' / Flag, 'is_fragment' / Flag,
                        'msg_type' / XEnum(BitsInteger(12), MessageType)),
    'channel_id' / Int64ub)

fragment = XStruct('sequence_begin' / Int32ub, 'sequence_end' / Int32ub,
                   'data' / SGString())

acknowledge = XStruct('low_watermark' / Int32ub,
                      'processed_list' / PrefixedArray(Int32ub, Int32ub),
                      'rejected_list' / PrefixedArray(Int32ub, Int32ub))

json = XStruct('text' / JsonAdapter(SGString()))

local_join = XStruct(
    'device_type' / XEnum(Int16ub, enum.ClientType), 'native_width' / Int16ub,
Esempio n. 4
0
# flake8: noqa
from construct import *
from xbox.nano.enum import VideoCodec
from xbox.sg.utils.struct import XStruct
from xbox.sg.utils.adapters import XEnum, PrefixedBytes

fmt = XStruct(
    'fps' / Int32ul, 'width' / Int32ul, 'height' / Int32ul,
    'codec' / XEnum(Int32ul, VideoCodec), 'rgb' / If(
        this.codec == VideoCodec.RGB,
        Struct('bpp' / Int32ul, 'bytes' / Int32ul, 'red_mask' / Int64ul,
               'green_mask' / Int64ul, 'blue_mask' / Int64ul)))

server_handshake = XStruct('protocol_version' / Int32ul, 'width' / Int32ul,
                           'height' / Int32ul, 'fps' / Int32ul,
                           'reference_timestamp' / Int64ul,
                           'formats' / PrefixedArray(Int32ul, fmt))

client_handshake = XStruct('initial_frame_id' / Int32ul,
                           'requested_format' / fmt)

control = XStruct(
    'flags' / BitStruct(
        Padding(2),
        'request_keyframe' / Default(Flag, False),
        'start_stream' / Default(Flag, False),
        'stop_stream' / Default(Flag, False),
        'queue_depth' / Default(Flag, False),
        'lost_frames' / Default(Flag, False),
        'last_displayed_frame' / Default(Flag, False),
        Padding(24),
Construct containers for simple-message header and payloads
"""
from construct import *
from xbox.sg import enum
from xbox.sg.enum import PacketType
from xbox.sg.utils.struct import XStruct
from xbox.sg.utils.adapters import CryptoTunnel, XSwitch, XEnum, CertificateAdapter, UUIDAdapter, SGString, FieldIn

pkt_types = [
    PacketType.PowerOnRequest, PacketType.DiscoveryRequest,
    PacketType.DiscoveryResponse, PacketType.ConnectRequest,
    PacketType.ConnectResponse
]

header = XStruct(
    'pkt_type' / XEnum(Int16ub, PacketType),
    'unprotected_payload_length' / Default(Int16ub, 0),
    'protected_payload_length' / If(
        FieldIn('pkt_type',
                [PacketType.ConnectRequest, PacketType.ConnectResponse]),
        Default(Int16ub, 0)), 'version' / Default(Int16ub, 2))

power_on_request = XStruct('liveid' / SGString())

discovery_request = XStruct('flags' / Int32ub,
                            'client_type' / XEnum(Int16ub, enum.ClientType),
                            'minimum_version' / Int16ub,
                            'maximum_version' / Int16ub)

discovery_response = XStruct('flags' / XEnum(Int32ub, enum.PrimaryDeviceFlag),
                             'type' / XEnum(Int16ub, enum.ClientType),