[NUI][API10] Create Context/CookieManager when WebView is created.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / MediaTool / ContainerMediaFormat.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 using System;
17 using System.Diagnostics;
18 using Tizen.Internals.Errors;
19
20 namespace Tizen.Multimedia
21 {
22     /// <summary>
23     /// Represents a container media format. This class cannot be inherited.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public sealed class ContainerMediaFormat : MediaFormat
27     {
28         /// <summary>
29         /// Initializes a new instance of the ContainerMediaFormat class.
30         /// </summary>
31         /// <param name="mimeType">The mime type of the container format.</param>
32         /// <exception cref="ArgumentException"><paramref name="mimeType"/> is invalid (i.e. undefined value).</exception>
33         /// <since_tizen> 3 </since_tizen>
34         public ContainerMediaFormat(MediaFormatContainerMimeType mimeType)
35             : base(MediaFormatType.Container)
36         {
37             ValidationUtil.ValidateEnum(typeof(MediaFormatContainerMimeType), mimeType,
38                 nameof(mimeType));
39
40             MimeType = mimeType;
41         }
42
43         /// <summary>
44         /// Initializes a new instance of the ContainerMediaFormat class from a native handle.
45         /// </summary>
46         /// <param name="handle">A native media format handle.</param>
47         internal ContainerMediaFormat(IntPtr handle)
48             : base(MediaFormatType.Container)
49         {
50             Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
51
52             int ret = Interop.MediaFormat.GetContainerMimeType(handle, out var mimeType);
53
54             MultimediaDebug.AssertNoError(ret);
55
56             Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType),
57                 "Invalid container mime type!");
58
59             MimeType = mimeType;
60         }
61
62         /// <summary>
63         /// Gets the mime type of the current format.
64         /// </summary>
65         /// <since_tizen> 3 </since_tizen>
66         public MediaFormatContainerMimeType MimeType { get; }
67
68         internal override void AsNativeHandle(IntPtr handle)
69         {
70             Debug.Assert(Type == MediaFormatType.Container);
71
72             int ret = Interop.MediaFormat.SetContainerMimeType(handle, MimeType);
73
74             MultimediaDebug.AssertNoError(ret);
75         }
76
77         /// <summary>
78         /// Returns a string that represents the current object.
79         /// </summary>
80         /// <returns>A string that represents the current object.</returns>
81         /// <since_tizen> 3 </since_tizen>
82         public override string ToString() => $"MimeType={ MimeType.ToString() }";
83
84         /// <summary>
85         /// Compares an object to an instance of <see cref="ContainerMediaFormat"/> for equality.
86         /// </summary>
87         /// <param name="obj">A <see cref="Object"/> to compare.</param>
88         /// <returns>true if the formats are equal; otherwise, false.</returns>
89         /// <since_tizen> 3 </since_tizen>
90         public override bool Equals(object obj)
91         {
92             var rhs = obj as ContainerMediaFormat;
93             if (rhs == null)
94             {
95                 return false;
96             }
97
98             return MimeType == rhs.MimeType;
99         }
100
101         /// <summary>
102         /// Gets the hash code for this instance of <see cref="ContainerMediaFormat"/>.
103         /// </summary>
104         /// <returns>The hash code for this instance of <see cref="ContainerMediaFormat"/>.</returns>
105         /// <since_tizen> 3 </since_tizen>
106         public override int GetHashCode() => MimeType.GetHashCode();
107     }
108 }