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 /// <since_tizen> 3 </since_tizen>
27 public abstract class MediaFormat
30 /// Initializes a new instance of the ContainerMediaFormat class with a type.
32 /// <param name="type">A type for the format.</param>
33 internal MediaFormat(MediaFormatType type)
39 /// Gets the type of the current format.
41 /// <since_tizen> 3 </since_tizen>
42 public MediaFormatType Type { get; }
45 /// Creates a media format from a native handle.
47 /// <param name="handle">A native handle.</param>
48 /// <returns>An object of one of the subclasses of <see cref="MediaFormat"/>.</returns>
49 internal static MediaFormat FromHandle(IntPtr handle)
51 if (handle == IntPtr.Zero)
53 throw new ArgumentException("The handle value is invalid.", nameof(handle));
56 int ret = Interop.MediaFormat.GetType(handle, out var type);
58 if (ret != (int)ErrorCode.InvalidOperation)
60 MultimediaDebug.AssertNoError(ret);
64 case MediaFormatType.Container:
65 return new ContainerMediaFormat(handle);
67 case MediaFormatType.Video:
68 return new VideoMediaFormat(handle);
70 case MediaFormatType.Audio:
71 return new AudioMediaFormat(handle);
73 case MediaFormatType.Text:
74 return new TextMediaFormat(handle);
78 throw new ArgumentException("looks like handle is corrupted.");
82 /// Creates a native media format from this object.
84 /// <returns>A converted native handle.</returns>
85 /// <remarks>The returned handle must be destroyed using <see cref="Interop.MediaFormat.Unref(IntPtr)"/>.</remarks>
86 internal IntPtr AsNativeHandle()
88 int ret = Interop.MediaFormat.Create(out var handle);
90 MultimediaDebug.AssertNoError(ret);
92 AsNativeHandle(handle);
97 internal static void ReleaseNativeHandle(IntPtr handle)
99 Interop.MediaFormat.Unref(handle);
103 /// Fills out properties of a native media format with the current media format object.
105 /// <param name="handle">A native handle to be written.</param>
106 internal abstract void AsNativeHandle(IntPtr handle);