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