// ----------------------------------------------------------------------- // // Photon Voice API Framework for Photon - Copyright (C) 2017 Exit Games GmbH // // // Photon data streaming support. // // developer@photonengine.com // ---------------------------------------------------------------------------- using System.Collections.Generic; namespace Photon.Voice { /// Describes stream properties. public struct VoiceInfo { /// /// Create stream info for an Opus audio stream. /// /// Audio sampling rate. /// Number of channels. /// Uncompressed frame (audio packet) size in microseconds. /// Stream bitrate (in bits/second). /// Optional user data. Should be serializable by Photon. /// VoiceInfo instance. static public VoiceInfo CreateAudioOpus(POpusCodec.Enums.SamplingRate samplingRate, int channels, OpusCodec.FrameDuration frameDurationUs, int bitrate, object userdata = null) { return new VoiceInfo() { Codec = Codec.AudioOpus, SamplingRate = (int)samplingRate, Channels = channels, FrameDurationUs = (int)frameDurationUs, Bitrate = bitrate, UserData = userdata }; } /// /// Create stream info for an audio stream. /// /// Audio codec. /// Audio sampling rate. /// Number of channels. /// Uncompressed frame (audio packet) size in microseconds. /// Optional user data. Should be serializable by Photon. /// VoiceInfo instance. static public VoiceInfo CreateAudio(Codec codec, int samplingRate, int channels, int frameDurationUs, object userdata = null) { return new VoiceInfo() { Codec = codec, SamplingRate = (int)samplingRate, Channels = channels, FrameDurationUs = (int)frameDurationUs, UserData = userdata }; } #if PHOTON_VOICE_VIDEO_ENABLE /// /// Create stream info for a video stream. /// /// Video codec. /// Stream bitrate. /// Streamed video width. If 0, width and height of video source used (no rescaling). /// Streamed video height. If -1, aspect ratio preserved during rescaling. /// Streamed video frames per second. /// Keyframes interval in frames./// /// Optional user data. Should be serializable by Photon. /// VoiceInfo instance. static public VoiceInfo CreateVideo(Codec codec, int bitrate, int width, int heigth, int fps, int keyFrameInt, object userdata = null) { return new VoiceInfo() { Codec = codec, Bitrate = bitrate, Width = width, Height = heigth, FPS = fps, KeyFrameInt = keyFrameInt, UserData = userdata, }; } #endif public override string ToString() { return "c=" + Codec + " f=" + SamplingRate + " ch=" + Channels + " d=" + FrameDurationUs + " s=" + FrameSize + " b=" + Bitrate + " w=" + Width + " h=" + Height + " fps=" + FPS + " kfi=" + KeyFrameInt + " ud=" + UserData; } public Codec Codec { get; set; } /// Audio sampling rate (frequency, in Hz). public int SamplingRate { get; set; } /// Number of channels. public int Channels { get; set; } /// Uncompressed frame (audio packet) size in microseconds. public int FrameDurationUs { get; set; } /// Target bitrate (in bits/second). public int Bitrate { get; set; } /// Video width. public int Width { get; set; } /// Video height public int Height { get; set; } /// Video frames per second public int FPS { get; set; } /// Video keyframe interval in frames public int KeyFrameInt { get; set; } /// Optional user data. Should be serializable by Photon. public object UserData { get; set; } /// Uncompressed frame (data packet) size in samples. public int FrameDurationSamples { get { return (int)(this.SamplingRate * (long)this.FrameDurationUs / 1000000); } } /// Uncompressed frame (data packet) array size. public int FrameSize { get { return this.FrameDurationSamples * this.Channels; } } } /// Information about a remote voice (incoming stream). public class RemoteVoiceInfo { internal RemoteVoiceInfo(int channelId, int playerId, byte voiceId, VoiceInfo info) { this.ChannelId = channelId; this.PlayerId = playerId; this.VoiceId = voiceId; this.Info = info; } /// Remote voice info. public VoiceInfo Info { get; private set; } /// ID of channel used for transmission. public int ChannelId { get; private set; } /// Player ID of voice owner. public int PlayerId { get; private set; } /// Voice ID (unique in the room). public byte VoiceId { get; private set; } } }