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.
17 using System.Diagnostics;
18 using Tizen.Internals.Errors;
20 namespace Tizen.Multimedia
23 /// Represents a text media format. This class cannot be inherited.
25 public sealed class TextMediaFormat : MediaFormat
28 /// Initializes a new instance of the TextMediaFormat class with the specified mime type
31 /// <param name="mimeType">The mime type of the format.</param>
32 /// <param name="textType">The text type of the format.</param>
33 /// <exception cref="ArgumentException">
34 /// <paramref name="mimeType"/> or <paramref name="textType"/> is invalid (i.e. undefined value).
36 public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType)
37 : base(MediaFormatType.Text)
39 if (!Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType))
41 throw new ArgumentException($"Invalid mime type value : { (int)mimeType }");
43 if (!Enum.IsDefined(typeof(MediaFormatTextType), textType))
45 throw new ArgumentException($"Invalid text type value : { (int)textType }");
52 /// Initializes a new instance of the TextMediaFormat class from a native handle.
54 /// <param name="handle">A native handle.</param>
55 internal TextMediaFormat(IntPtr handle)
56 : base(MediaFormatType.Text)
58 Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
60 MediaFormatTextMimeType mimeType;
61 MediaFormatTextType textType;
63 GetInfo(handle, out mimeType, out textType);
70 /// Retrieves text properties of the media format from a native handle.
72 /// <param name="handle">A native handle that the properties are retrieved from.</param>
73 /// <param name="mimeType">An out parameter for the mime type.</param>
74 /// <param name="textType">An out parameter for the text type.</param>
75 private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType,
76 out MediaFormatTextType textType)
78 int mimeTypeValue = 0;
79 int textTypeValue = 0;
81 int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue);
83 MultimediaDebug.AssertNoError(ret);
85 mimeType = (MediaFormatTextMimeType)mimeTypeValue;
86 textType = (MediaFormatTextType)textTypeValue;
88 Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType),
89 "Invalid text mime type!");
90 Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType),
91 "Invalid text type!");
94 internal override void AsNativeHandle(IntPtr handle)
96 Debug.Assert(Type == MediaFormatType.Text);
98 int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType);
99 MultimediaDebug.AssertNoError(ret);
101 ret = Interop.MediaFormat.SetTextType(handle, (int)TextType);
102 MultimediaDebug.AssertNoError(ret);
106 /// Gets the mime type of the current format.
108 public MediaFormatTextMimeType MimeType { get; }
111 /// Gets the text type of the current format.
113 public MediaFormatTextType TextType { get; }
115 public override string ToString()
117 return $"MimeType={ MimeType.ToString() }, TextType={ TextType.ToString() }";
120 public override bool Equals(object obj)
122 var rhs = obj as TextMediaFormat;
128 return MimeType == rhs.MimeType && TextType == rhs.TextType;
131 public override int GetHashCode()
133 return new { MimeType, TextType }.GetHashCode();