/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using static Interop.Camera;
namespace Tizen.Multimedia
{
///
/// The class containing the preview image data.
///
public class PreviewFrame
{
internal PreviewFrame(IntPtr ptr)
{
var unmanagedStruct = Marshal.PtrToStructure(ptr);
Format = unmanagedStruct.Format;
Resolution = new Size(unmanagedStruct.Width, unmanagedStruct.Height);
TimeStamp = unmanagedStruct.TimeStamp;
PlaneType = GetPlaneType(unmanagedStruct);
Plane = ConvertPlane(unmanagedStruct);
}
private static IPreviewPlane ConvertPlane(CameraPreviewDataStruct unmanagedStruct)
{
if (unmanagedStruct.NumOfPlanes == 1)
{
if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
{
return new EncodedPlane(unmanagedStruct.Plane.EncodedPlane);
}
else
{
return new SinglePlane(unmanagedStruct.Plane.SinglePlane);
}
}
else if (unmanagedStruct.NumOfPlanes == 2)
{
return new DoublePlane(unmanagedStruct.Plane.DoublePlane);
}
else if (unmanagedStruct.NumOfPlanes == 3)
{
return new TriplePlane(unmanagedStruct.Plane.TriplePlane);
}
Debug.Fail("Unknown preview data!");
return null;
}
private static PlaneType GetPlaneType(CameraPreviewDataStruct unmanagedStruct)
{
if (unmanagedStruct.NumOfPlanes == 1)
{
if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
{
return PlaneType.EncodedPlane;
}
else
{
return PlaneType.SinglePlane;
}
}
else if (unmanagedStruct.NumOfPlanes == 2)
{
return PlaneType.DoublePlane;
}
return PlaneType.TriplePlane;
}
///
/// The pixel format of the image.
///
/// 3
public CameraPixelFormat Format { get; }
///
/// The resolution of the preview image.
///
/// 3
public Size Resolution { get; }
///
/// The time stamp of the preview frame.
///
/// 3
public uint TimeStamp { get; }
///
/// The type of the preview plane.
///
/// 3
public PlaneType PlaneType { get; }
///
/// The buffer including the preview frame.
///
/// 3
public IPreviewPlane Plane { get; }
}
}