[NUI][API10] Create Context/CookieManager when WebView is created.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / MediaTool / MediaPacketVideoPlane.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
17 using System;
18 using System.Diagnostics;
19 using Native = Tizen.Multimedia.Interop.MediaPacket;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Represents a video plane for the <see cref="MediaPacket"/>.
25     /// This class is used if and only if the format of the packet is the raw video.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class MediaPacketVideoPlane
29     {
30         private readonly MediaPacket _packet;
31         private readonly int _strideWidth;
32         private readonly int _strideHeight;
33         private readonly IMediaBuffer _buffer;
34
35         internal MediaPacketVideoPlane(MediaPacket packet, int index)
36         {
37             Debug.Assert(packet != null, "The packet is null!");
38             Debug.Assert(!packet.IsDisposed, "Packet is already disposed!");
39             Debug.Assert(index >= 0, "Video plane index must not be negative!");
40
41             _packet = packet;
42
43             int ret = Native.GetVideoStrideWidth(packet.GetHandle(), index, out _strideWidth);
44             MultimediaDebug.AssertNoError(ret);
45
46             ret = Native.GetVideoStrideHeight(packet.GetHandle(), index, out _strideHeight);
47             MultimediaDebug.AssertNoError(ret);
48
49             Debug.Assert(_strideWidth >= 0 && _strideHeight >= 0, "size must not be negative!");
50
51             ret = Native.GetVideoPlaneData(packet.GetHandle(), index, out var dataHandle);
52             MultimediaDebug.AssertNoError(ret);
53
54             Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!");
55
56             _buffer = new DependentMediaBuffer(packet, dataHandle, _strideWidth * _strideHeight);
57         }
58
59         /// <summary>
60         /// Gets the buffer of the current video plane.
61         /// </summary>
62         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
63         /// <since_tizen> 3 </since_tizen>
64         public IMediaBuffer Buffer
65         {
66             get
67             {
68                 _packet.EnsureReadableState();
69                 return _buffer;
70             }
71         }
72
73         /// <summary>
74         /// Gets the stride width of the current video plane.
75         /// </summary>
76         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
77         /// <since_tizen> 3 </since_tizen>
78         public int StrideWidth
79         {
80             get
81             {
82                 _packet.EnsureReadableState();
83                 return _strideWidth;
84             }
85         }
86
87         /// <summary>
88         /// Gets the stride height of the current video plane.
89         /// </summary>
90         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
91         /// <since_tizen> 3 </since_tizen>
92         public int StrideHeight
93         {
94             get
95             {
96                 _packet.EnsureReadableState();
97                 return _strideHeight;
98             }
99         }
100     }
101 }