/*
* 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 container media format. This class cannot be inherited.
///
/// 3
public sealed class ContainerMediaFormat : MediaFormat
{
///
/// Initializes a new instance of the ContainerMediaFormat class.
///
/// The mime type of the container format.
/// is invalid (i.e. undefined value).
/// 3
public ContainerMediaFormat(MediaFormatContainerMimeType mimeType)
: base(MediaFormatType.Container)
{
if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType))
{
throw new ArgumentException($"Invalid mime type value : { (int)mimeType }");
}
MimeType = mimeType;
}
///
/// Initializes a new instance of the ContainerMediaFormat class from a native handle.
///
/// A native media format handle.
internal ContainerMediaFormat(IntPtr handle)
: base(MediaFormatType.Container)
{
Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
int mimeType = 0;
int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType);
MultimediaDebug.AssertNoError(ret);
Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType),
"Invalid container mime type!");
MimeType = (MediaFormatContainerMimeType)mimeType;
}
///
/// Gets the mime type of the current format.
///
/// 3
public MediaFormatContainerMimeType MimeType { get; }
internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Container);
int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)MimeType);
MultimediaDebug.AssertNoError(ret);
}
///
/// Returns a string that represents the current object.
///
/// A string that represents the current object.
/// 3
public override string ToString() => $"MimeType={ MimeType.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 ContainerMediaFormat;
if (rhs == null)
{
return false;
}
return MimeType == rhs.MimeType;
}
///
/// Gets the hash code for this instance of .
///
/// The hash code for this instance of .
/// 3
public override int GetHashCode()
=> (int)MimeType;
}
}