Release 4.0.0-preview1-00201
[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     public sealed class ContainerMediaFormat : MediaFormat
26     {
27         /// <summary>
28         /// Initializes a new instance of the ContainerMediaFormat class.
29         /// </summary>
30         /// <param name="mimeType">The mime type of the container format.</param>
31         /// <exception cref="ArgumentException"><paramref name="mimeType"/> is invalid (i.e. undefined value).</exception>
32         public ContainerMediaFormat(MediaFormatContainerMimeType mimeType)
33             : base(MediaFormatType.Container)
34         {
35             if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType))
36             {
37                 throw new ArgumentException($"Invalid mime type value : { (int)mimeType }");
38             }
39             MimeType = mimeType;
40         }
41
42         /// <summary>
43         /// Initializes a new instance of the ContainerMediaFormat class from a native handle.
44         /// </summary>
45         /// <param name="handle">A native media format handle.</param>
46         internal ContainerMediaFormat(IntPtr handle)
47             : base(MediaFormatType.Container)
48         {
49             Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");
50
51             int mimeType = 0;
52
53             int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType);
54
55             MultimediaDebug.AssertNoError(ret);
56
57             Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType),
58                 "Invalid container mime type!");
59
60             MimeType = (MediaFormatContainerMimeType)mimeType;
61         }
62
63         /// <summary>
64         /// Gets the mime type of the current format.
65         /// </summary>
66         public MediaFormatContainerMimeType MimeType
67         {
68             get;
69         }
70
71         internal override void AsNativeHandle(IntPtr handle)
72         {
73             Debug.Assert(Type == MediaFormatType.Container);
74
75             int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)MimeType);
76
77             MultimediaDebug.AssertNoError(ret);
78         }
79
80         public override string ToString()
81         {
82             return $"MimeType={ MimeType.ToString() }";
83         }
84
85         public override bool Equals(object obj)
86         {
87             var rhs = obj as ContainerMediaFormat;
88             if (rhs == null)
89             {
90                 return false;
91             }
92
93             return MimeType == rhs.MimeType;
94         }
95
96         public override int GetHashCode()
97         {
98             return (int)MimeType;
99         }
100     }
101 }