/*
* 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
{
///
/// MediaFormat is a base class for media formats.
///
/// 3
public abstract class MediaFormat
{
///
/// Initializes a new instance of the ContainerMediaFormat class with a type.
///
/// A type for the format.
internal MediaFormat(MediaFormatType type)
{
Type = type;
}
///
/// Gets the type of the current format.
///
/// 3
public MediaFormatType Type { get; }
///
/// Creates a media format from a native handle.
///
/// A native handle.
/// An object of one of the subclasses of .
internal static MediaFormat FromHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentException("The handle value is invalid.", nameof(handle));
}
int ret = Interop.MediaFormat.GetType(handle, out var type);
if (ret != (int)ErrorCode.InvalidOperation)
{
MultimediaDebug.AssertNoError(ret);
switch (type)
{
case MediaFormatType.Container:
return new ContainerMediaFormat(handle);
case MediaFormatType.Video:
return new VideoMediaFormat(handle);
case MediaFormatType.Audio:
return new AudioMediaFormat(handle);
case MediaFormatType.Text:
return new TextMediaFormat(handle);
}
}
throw new ArgumentException("looks like handle is corrupted.");
}
///
/// Creates a native media format from this object.
///
/// A converted native handle.
/// The returned handle must be destroyed using .
internal IntPtr AsNativeHandle()
{
int ret = Interop.MediaFormat.Create(out var handle);
MultimediaDebug.AssertNoError(ret);
AsNativeHandle(handle);
return handle;
}
internal static void ReleaseNativeHandle(IntPtr handle)
{
Interop.MediaFormat.Unref(handle);
}
///
/// Fills out properties of a native media format with the current media format object.
///
/// A native handle to be written.
internal abstract void AsNativeHandle(IntPtr handle);
}
}