/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Diagnostics; using Tizen.Internals.Errors; namespace Tizen.Multimedia { /// /// Represents a video media format. This class cannot be inherited. /// /// 3 public sealed class VideoMediaFormat : MediaFormat { private const int DefaultFrameRate = 0; private const int DefaultBitRate = 0; private const int DefaultMaxBps = 0; /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, width, and height. /// /// The mime type of the format. /// The width value of the format. /// The height value of the format /// is invalid (i.e. undefined value). /// or is less than zero. /// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height) : this(mimeType, width, height, DefaultFrameRate) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type and size. /// /// The mime type of the format. /// The size of the format. /// is invalid (i.e. undefined value). /// The width or the height of is less than zero. /// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size) : this(mimeType, size, DefaultFrameRate) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// width, height, and frame rate. /// /// The mime type of the format. /// The width value of the format. /// The height value of the format /// The frame rate of the format. /// is invalid (i.e. undefined value). /// /// , , or is less than zero. /// /// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, int frameRate) : this(mimeType, width, height, frameRate, DefaultBitRate) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// width, height, and frame rate. /// /// The mime type of the format. /// The video size of the format. /// The frame rate of the format. /// is invalid (i.e. undefined value). /// /// The width or the height of is less than zero.
/// -or-
/// is less than zero. ///
/// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, int frameRate) : this(mimeType, size, frameRate, DefaultBitRate) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// width, height, frame rate, and bit rate. /// /// The mime type of the format. /// The width value of the format. /// The height value of the format /// The frame rate of the format. /// The bit rate of the format. /// is invalid (i.e. undefined value). /// /// , , , or is less than zero. /// /// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, int frameRate, int bitRate) : this(mimeType, width, height, frameRate, bitRate, DefaultMaxBps) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// size, frame rate, and bit rate. /// /// The mime type of the format. /// The size of the format. /// The frame rate of the format. /// The bit rate of the format. /// is invalid (i.e. undefined value). /// /// The width or the height of is less than zero.
/// -or-
/// is less than zero.
/// -or-
/// is less than zero. ///
/// 3 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, int frameRate, int bitRate) : this (mimeType, size, frameRate, bitRate, DefaultMaxBps) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// width, height, frame rate, bit rate and max bps. /// /// The mime type of the format. /// The width value of the format. /// The height value of the format /// The frame rate of the format. /// The bit rate of the format. /// The max bps of the format. /// is invalid (i.e. undefined value). /// /// , ,
/// -or-
/// , or , or is less than zero. ///
/// 6 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, int frameRate, int bitRate, int maxBps) : this(mimeType, new Size(width, height), frameRate, bitRate, maxBps) { } /// /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, /// size, frame rate, bit rate and max bps. /// /// The mime type of the format. /// The size of the format. /// The frame rate of the format. /// The bit rate of the format. /// The max bps of the format. /// is invalid (i.e. undefined value). /// /// The width or the height of is less than zero.
/// -or-
/// is less than zero.
/// -or-
/// is less than zero. /// -or-
/// is less than zero. ///
/// 6 public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, int frameRate, int bitRate, int maxBps) : base(MediaFormatType.Video) { ValidationUtil.ValidateEnum(typeof(MediaFormatVideoMimeType), mimeType, nameof(mimeType)); if (size.Width < 0) { throw new ArgumentOutOfRangeException(nameof(size), size.Width, "Size.Width value can't be less than zero."); } if (size.Height < 0) { throw new ArgumentOutOfRangeException(nameof(size), size.Height, "Size.Height value can't be less than zero."); } if (frameRate < 0) { throw new ArgumentOutOfRangeException(nameof(frameRate), frameRate, "Frame rate can't be less than zero."); } if (bitRate < 0) { throw new ArgumentOutOfRangeException(nameof(bitRate), bitRate, "Bit rate value can't be less than zero."); } if (maxBps < 0) { throw new ArgumentOutOfRangeException(nameof(maxBps), maxBps, "Max bps value can't be less than zero."); } MimeType = mimeType; Size = size; FrameRate = frameRate; BitRate = bitRate; MaxBps = maxBps; } /// /// Initializes a new instance of the VideoMediaForma class from a native handle. /// /// A native handle. internal VideoMediaFormat(IntPtr handle) : base(MediaFormatType.Video) { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); int ret = Interop.MediaFormat.GetVideoInfo(handle, out var mimeType, out var width, out var height, out var bitRate, out var maxBps); MultimediaDebug.AssertNoError(ret); Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType), "Invalid video mime type!"); ret = Interop.MediaFormat.GetVideoFrameRate(handle, out var frameRate); MultimediaDebug.AssertNoError(ret); MimeType = mimeType; Size = new Size(width, height); FrameRate = frameRate; BitRate = bitRate; MaxBps = maxBps; } internal override void AsNativeHandle(IntPtr handle) { Debug.Assert(Type == MediaFormatType.Video); int ret = Interop.MediaFormat.SetVideoMimeType(handle, MimeType); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoWidth(handle, Size.Width); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoHeight(handle, Size.Height); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoAverageBps(handle, BitRate); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoFrameRate(handle, FrameRate); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoMaxBps(handle, MaxBps); MultimediaDebug.AssertNoError(ret); } /// /// Gets the mime type of the current format. /// /// 3 public MediaFormatVideoMimeType MimeType { get; } /// /// Gets the size of the current format. /// /// 3 public Size Size { get; } /// /// Gets the frame rate value of the current format. /// /// 3 public int FrameRate { get; } /// /// Gets the bit rate value of the current format. /// /// 3 public int BitRate { get; } /// /// Gets the max bps value of the current format. /// /// 6 public int MaxBps { get; } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. /// 3 public override string ToString() => $@"MimeType={ MimeType.ToString() }, Size=({ Size.ToString() }), FrameRate= { FrameRate.ToString() }, BitRate={ BitRate.ToString() }, MaxBps = { MaxBps.ToString() }"; /// /// Compares an object to an instance of for equality. /// /// A to compare. /// true if the formats are equal; otherwise, false. /// 3 public override bool Equals(object obj) { var rhs = obj as VideoMediaFormat; if (rhs == null) { return false; } return MimeType == rhs.MimeType && Size == rhs.Size && FrameRate == rhs.FrameRate && BitRate == rhs.BitRate && MaxBps == rhs.MaxBps; } /// /// Gets the hash code for this instance of . /// /// The hash code for this instance of . /// 3 public override int GetHashCode() => new { MimeType, Size, FrameRate, BitRate, MaxBps }.GetHashCode(); } }