using System; namespace UMP { public class PlayerOptionsIPhone : PlayerOptions { private const string PLAYER_TYPE_KEY = ":player-type"; private const string FLIP_VERTICALLY = ":flip-vertically"; private const string VIDEOTOOLBOX_KEY = ":videotoolbox"; private const string VIDEOTOOLBOX_FRAME_WIDTH_KEY = ":videotoolbox-max-frame-width"; private const string VIDEOTOOLBOX_ASYNC_KEY = ":videotoolbox-async"; private const string VIDEOTOOLBOX_WAIT_ASYNC_KEY = ":videotoolbox-wait-async"; private const string PACKET_BUFFERING_KEY = ":packet-buffering"; private const string MAX_BUFFER_SIZE_KEY = ":max-buffer-size"; private const string MIN_FRAMES_KEY = ":min-frames"; private const string INFBUF_KEY = ":infbuf"; private const string FRAMEDROP_KEY = ":framedrop"; private const string MAX_FPS_KEY = ":max-fps"; private const string PLAY_IN_BACKGROUND_KEY = ":play-in-background"; private const string RTSP_OVER_TCP_KEY = ":rtsp-tcp"; private const int DEFAULT_VIDEOTOOLBOX_FRAME_WIDTH_VALUE = 4096; private const int DEFAULT_MAX_BUFFER_SIZE_VALUE = 15 * 1024 * 1024; private const int DEFAULT_MIN_FRAMES_VALUE = 50000; private const int DEFAULT_FRAMEDROP_VALUE = 0; private const int DEFAULT_MAX_FPS_VALUE = 31; public enum PlayerTypes { Native = 1, FFmpeg = 2 } public PlayerOptionsIPhone(string[] options) : base(options) { PlayerType = PlayerTypes.FFmpeg; FlipVertically = true; VideoToolbox = true; VideoToolboxFrameWidth = DEFAULT_VIDEOTOOLBOX_FRAME_WIDTH_VALUE; VideoToolboxAsync = false; VideoToolboxWaitAsync = true; PlayInBackground = false; UseTCP = false; PacketBuffering = true; MaxBufferSize = DEFAULT_MAX_BUFFER_SIZE_VALUE; MinFrames = DEFAULT_MIN_FRAMES_VALUE; Infbuf = false; Framedrop = DEFAULT_FRAMEDROP_VALUE; MaxFps = DEFAULT_MAX_FPS_VALUE; } /// /// This allows to choose the usable player. /// public PlayerTypes PlayerType { get { return (PlayerTypes)GetValue(PLAYER_TYPE_KEY); } set { var settings = UMPSettings.Instance; var playerTypes = Enum.GetValues(typeof(PlayerTypes)); var result = PlayerTypes.Native; foreach (var type in playerTypes) { var playerType = (PlayerTypes)type; if ((settings.PlayersIPhone & playerType) == playerType) { result = playerType; if (result == value) break; } } SetValue(PLAYER_TYPE_KEY, ((int)result).ToString()); } } /// /// Flip video frame vertically when we get it from native library (CPU usage cost). /// public bool FlipVertically { get { return GetValue(FLIP_VERTICALLY); } set { if (value) SetValue(FLIP_VERTICALLY, string.Empty); else RemoveOption(FLIP_VERTICALLY); } } /// /// Enable/Disable low-level framework that provides direct access to hardware encoders and decoders. /// public bool VideoToolbox { get { return GetValue(VIDEOTOOLBOX_KEY); } set { if (value) SetValue(VIDEOTOOLBOX_KEY, string.Empty); else RemoveOption(VIDEOTOOLBOX_KEY); } } /// /// Max width of output frame. /// public int VideoToolboxFrameWidth { get { return GetValue(VIDEOTOOLBOX_FRAME_WIDTH_KEY); } set { SetValue(VIDEOTOOLBOX_FRAME_WIDTH_KEY, value.ToString()); } } /// /// Enable VideoToolbox asynchronous decompression. /// public bool VideoToolboxAsync { get { return GetValue(VIDEOTOOLBOX_ASYNC_KEY); } set { if (VideoToolbox && value) SetValue(VIDEOTOOLBOX_ASYNC_KEY, string.Empty); else RemoveOption(VIDEOTOOLBOX_ASYNC_KEY); } } /// /// Wait for asynchronous frames. /// public bool VideoToolboxWaitAsync { get { return GetValue(VIDEOTOOLBOX_WAIT_ASYNC_KEY); } set { if (VideoToolboxAsync && value) SetValue(VIDEOTOOLBOX_WAIT_ASYNC_KEY, string.Empty); else RemoveOption(VIDEOTOOLBOX_WAIT_ASYNC_KEY); } } /// /// Continue play video when application in background. /// public bool PlayInBackground { get { return GetValue(PLAY_IN_BACKGROUND_KEY); } set { if (value) SetValue(PLAY_IN_BACKGROUND_KEY, string.Empty); else RemoveOption(PLAY_IN_BACKGROUND_KEY); } } /// /// Use RTP over RTSP (TCP) (default disabled). /// public bool UseTCP { get { return GetValue(RTSP_OVER_TCP_KEY); } set { if (value) SetValue(RTSP_OVER_TCP_KEY, string.Empty); else RemoveOption(RTSP_OVER_TCP_KEY); } } /// /// Pause output until enough packets have been read after stalling. /// public bool PacketBuffering { get { return GetValue(PACKET_BUFFERING_KEY); } set { if (value) SetValue(PACKET_BUFFERING_KEY, string.Empty); else RemoveOption(PACKET_BUFFERING_KEY); } } /// /// Max buffer size should be pre-read (in bytes). /// public int MaxBufferSize { get { return GetValue(MAX_BUFFER_SIZE_KEY); } set { SetValue(MAX_BUFFER_SIZE_KEY, value.ToString()); } } /// /// Minimal frames to stop pre-reading. /// public int MinFrames { get { return GetValue(MIN_FRAMES_KEY); } set { SetValue(MIN_FRAMES_KEY, value.ToString()); } } /// /// Don't limit the input buffer size (useful with realtime streams). /// public bool Infbuf { get { return GetValue(INFBUF_KEY); } set { if (value) SetValue(INFBUF_KEY, string.Empty); else RemoveOption(INFBUF_KEY); } } /// /// Drop frames when cpu is too slow. /// public int Framedrop { get { return GetValue(FRAMEDROP_KEY); } set { SetValue(FRAMEDROP_KEY, value.ToString()); } } /// /// Drop frames in video whose fps is greater than MaxFps. /// public int MaxFps { get { return GetValue(MAX_FPS_KEY); } set { SetValue(MAX_FPS_KEY, value.ToString()); } } } }