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 /// mimeType or textType is invalid(i.e. undefined value).</exception>
35 public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType)
36 : base(MediaFormatType.Text)
38 if (!Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType))
40 throw new ArgumentException($"Invalid mime type value : { (int)mimeType }");
42 if (!Enum.IsDefined(typeof(MediaFormatTextType), textType))
44 throw new ArgumentException($"Invalid text type value : { (int)textType }");
51 /// Initializes a new instance of the TextMediaFormat class from a native handle.
53 /// <param name="handle">A native handle.</param>
54 internal TextMediaFormat(IntPtr handle)
55 : base(MediaFormatType.Text)
57 Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
59 MediaFormatTextMimeType mimeType;
60 MediaFormatTextType textType;
62 GetInfo(handle, out mimeType, out textType);
69 /// Retrieves text properties of media format from a native handle.
71 /// <param name="handle">A native handle that properties are retrieved from.</param>
72 /// <param name="mimeType">An out parameter for mime type.</param>
73 /// <param name="textType">An out parameter for text type.</param>
74 private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType,
75 out MediaFormatTextType textType)
77 int mimeTypeValue = 0;
78 int textTypeValue = 0;
80 int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue);
82 MultimediaDebug.AssertNoError(ret);
84 mimeType = (MediaFormatTextMimeType)mimeTypeValue;
85 textType = (MediaFormatTextType)textTypeValue;
87 Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType),
88 "Invalid text mime type!");
89 Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType),
90 "Invalid text type!");
93 internal override void AsNativeHandle(IntPtr handle)
95 Debug.Assert(Type == MediaFormatType.Text);
97 int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType);
98 MultimediaDebug.AssertNoError(ret);
100 ret = Interop.MediaFormat.SetTextType(handle, (int)TextType);
101 MultimediaDebug.AssertNoError(ret);
105 /// Gets the mime type of the current format.
107 public MediaFormatTextMimeType MimeType { get; }
110 /// Gets the text type of the current format.
112 public MediaFormatTextType TextType { get; }
114 public override string ToString()
116 return $"MimeType={ MimeType.ToString() }, TextType={ TextType.ToString() }";
119 public override bool Equals(object obj)
121 var rhs = obj as TextMediaFormat;
127 return MimeType == rhs.MimeType && TextType == rhs.TextType;
130 public override int GetHashCode()
132 return new { MimeType, TextType }.GetHashCode();