/*
* 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 text media format. This class cannot be inherited.
///
/// 3
public sealed class TextMediaFormat : MediaFormat
{
///
/// Initializes a new instance of the TextMediaFormat class with the specified mime type
/// and text type.
///
/// The mime type of the format.
/// The text type of the format.
///
/// or is invalid (i.e. undefined value).
///
/// 3
public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType)
: base(MediaFormatType.Text)
{
ValidationUtil.ValidateEnum(typeof(MediaFormatTextMimeType), mimeType, nameof(mimeType));
ValidationUtil.ValidateEnum(typeof(MediaFormatTextType), textType, nameof(textType));
MimeType = mimeType;
TextType = textType;
}
///
/// Initializes a new instance of the TextMediaFormat class from a native handle.
///
/// A native handle.
internal TextMediaFormat(IntPtr handle)
: base(MediaFormatType.Text)
{
Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
int ret = Interop.MediaFormat.GetTextInfo(handle, out var mimeType, out var textType);
MultimediaDebug.AssertNoError(ret);
Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType),
"Invalid text mime type!");
Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType),
"Invalid text type!");
MimeType = mimeType;
TextType = textType;
}
internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Text);
int ret = Interop.MediaFormat.SetTextMimeType(handle, MimeType);
MultimediaDebug.AssertNoError(ret);
ret = Interop.MediaFormat.SetTextType(handle, TextType);
MultimediaDebug.AssertNoError(ret);
}
///
/// Gets the mime type of the current format.
///
/// 3
public MediaFormatTextMimeType MimeType { get; }
///
/// Gets the text type of the current format.
///
/// 3
public MediaFormatTextType TextType { get; }
///
/// Returns a string that represents the current object.
///
/// A string that represents the current object.
/// 3
public override string ToString()
=> $"MimeType={ MimeType.ToString() }, TextType={ TextType.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 TextMediaFormat;
if (rhs == null)
{
return false;
}
return MimeType == rhs.MimeType && TextType == rhs.TextType;
}
///
/// Gets the hash code for this instance of .
///
/// The hash code for this instance of .
/// 3
public override int GetHashCode() => new { MimeType, TextType }.GetHashCode();
}
}