Release 4.0.0-preview1-00201
[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     public class MediaPacketVideoPlane
27     {
28         private readonly MediaPacket _packet;
29         private readonly int _strideWidth;
30         private readonly int _strideHeight;
31         private readonly MediaPacketBuffer _buffer;
32
33         internal MediaPacketVideoPlane(MediaPacket packet, int index)
34         {
35             Debug.Assert(packet != null, "The packet is null!");
36             Debug.Assert(!packet.IsDisposed, "Packet is already disposed!");
37             Debug.Assert(index >= 0, "Video plane index must not be negative!");
38
39             _packet = packet;
40
41             int ret = Interop.MediaPacket.GetVideoStrideWidth(packet.GetHandle(), index, out _strideWidth);
42             MultimediaDebug.AssertNoError(ret);
43
44             ret = Interop.MediaPacket.GetVideoStrideWidth(packet.GetHandle(), index, out _strideHeight);
45             MultimediaDebug.AssertNoError(ret);
46
47             IntPtr dataHandle;
48             ret = Interop.MediaPacket.GetVideoPlaneData(packet.GetHandle(), index, out dataHandle);
49             MultimediaDebug.AssertNoError(ret);
50
51             _buffer = new MediaPacketBuffer(packet, dataHandle, _strideWidth * _strideHeight);
52         }
53
54         /// <summary>
55         /// Gets the buffer of the current video plane.
56         /// </summary>
57         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
58         public MediaPacketBuffer Buffer
59         {
60             get
61             {
62                 _packet.EnsureReadableState();
63                 return _buffer;
64             }
65         }
66
67         /// <summary>
68         /// Gets the stride width of the current video plane.
69         /// </summary>
70         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
71         public int StrideWidth
72         {
73             get
74             {
75                 _packet.EnsureReadableState();
76                 return _strideWidth;
77             }
78         }
79
80         /// <summary>
81         /// Gets the stride height of the current video plane.
82         /// </summary>
83         /// <exception cref="ObjectDisposedException">The MediaPacket that owns the current buffer has already been disposed of.</exception>
84         public int StrideHeight
85         {
86             get
87             {
88                 _packet.EnsureReadableState();
89                 return _strideHeight;
90             }
91         }
92     }
93 }