2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Diagnostics;
19 using System.Runtime.InteropServices;
20 using static Interop.Camera;
22 namespace Tizen.Multimedia
25 /// The class containing preview image data.
27 public class PreviewFrame
29 internal PreviewFrame(IntPtr ptr)
31 var unmanagedStruct = Marshal.PtrToStructure<CameraPreviewDataStruct>(ptr);
33 Format = unmanagedStruct.Format;
34 Resolution = new Size(unmanagedStruct.Width, unmanagedStruct.Height);
35 TimeStamp = unmanagedStruct.TimeStamp;
36 PlaneType = GetPlaneType(unmanagedStruct);
37 Plane = ConvertPlane(unmanagedStruct);
40 private static IPreviewPlane ConvertPlane(CameraPreviewDataStruct unmanagedStruct)
42 if (unmanagedStruct.NumOfPlanes == 1)
44 if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
46 return new EncodedPlane(unmanagedStruct.Plane.EncodedPlane);
50 return new SinglePlane(unmanagedStruct.Plane.SinglePlane);
53 else if (unmanagedStruct.NumOfPlanes == 2)
55 return new DoublePlane(unmanagedStruct.Plane.DoublePlane);
57 else if (unmanagedStruct.NumOfPlanes == 3)
59 return new TriplePlane(unmanagedStruct.Plane.TriplePlane);
62 Debug.Fail("Unknown preview data!");
66 private static PlaneType GetPlaneType(CameraPreviewDataStruct unmanagedStruct)
68 if (unmanagedStruct.NumOfPlanes == 1)
70 if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
72 return PlaneType.EncodedPlane;
76 return PlaneType.SinglePlane;
79 else if (unmanagedStruct.NumOfPlanes == 2)
81 return PlaneType.DoublePlane;
84 return PlaneType.TriplePlane;
88 /// The pixel format of the image.
90 /// <since_tizen> 3 </since_tizen>
91 public CameraPixelFormat Format { get; }
94 /// The resolution of the preview image.
96 /// <since_tizen> 3 </since_tizen>
97 public Size Resolution { get; }
100 /// The timestamp of preview frame.
102 /// <since_tizen> 3 </since_tizen>
103 public uint TimeStamp { get; }
106 /// The type of preview plane. <see cref="Tizen.Multimedia.PlaneType"/>
108 /// <since_tizen> 3 </since_tizen>
109 public PlaneType PlaneType { get; }
112 /// The buffer including preview frame.
114 /// <since_tizen> 3 </since_tizen>
115 public IPreviewPlane Plane { get; }