2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Diagnostics;
19 using Tizen.Internals.Errors;
21 namespace Tizen.Multimedia
24 /// MediaFormat is a base class for media formats.
26 public abstract class MediaFormat
29 /// Initializes a new instance of the ContainerMediaFormat class with a type.
31 /// <param name="type">A type for the format.</param>
32 internal MediaFormat(MediaFormatType type)
38 /// Gets the type of the current format.
40 public MediaFormatType Type
46 /// Creates a media format from a native handle.
48 /// <param name="handle">A native handle.</param>
49 /// <returns>An object of one of the subclasses of <see cref="MediaFormat"/>.</returns>
50 internal static MediaFormat FromHandle(IntPtr handle)
52 if (handle == IntPtr.Zero)
54 throw new ArgumentException("The handle value is invalid.");
58 int ret = Interop.MediaFormat.GetType(handle, out type);
60 if (ret != (int)ErrorCode.InvalidOperation)
62 MultimediaDebug.AssertNoError(ret);
64 switch ((MediaFormatType)type)
66 case MediaFormatType.Container:
67 return new ContainerMediaFormat(handle);
69 case MediaFormatType.Video:
70 return new VideoMediaFormat(handle);
72 case MediaFormatType.Audio:
73 return new AudioMediaFormat(handle);
75 case MediaFormatType.Text:
76 return new TextMediaFormat(handle);
80 throw new ArgumentException("looks like handle is corrupted.");
84 /// Creates a native media format from this object.
86 /// <returns>A converted native handle.</returns>
87 /// <remarks>The returned handle must be destroyed using <see cref="Interop.MediaFormat.Unref(IntPtr)"/>.</remarks>
88 internal IntPtr AsNativeHandle()
91 int ret = Interop.MediaFormat.Create(out handle);
93 MultimediaDebug.AssertNoError(ret);
95 AsNativeHandle(handle);
100 internal static void ReleaseNativeHandle(IntPtr handle)
102 Interop.MediaFormat.Unref(handle);
106 /// Fills out properties of a native media format with the current media format object.
108 /// <param name="handle">A native handle to be written.</param>
109 internal abstract void AsNativeHandle(IntPtr handle);