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.Runtime.InteropServices;
19 using static Interop.MediaVision;
21 namespace Tizen.Multimedia
24 /// This class represents media vision source. An instance of this class has to be created \n
25 /// to keep information on image or video frame data as raw buffer. It can be created based on \n
26 /// the media data stored in memory or using the BaseMediaPacket class. \n
27 /// It provides a set of getters which allow to retrieve such image parameters as its size or colorspace (see Colorspace enumeration).
29 public class MediaVisionSource : IDisposable
31 internal IntPtr _sourceHandle = IntPtr.Zero;
32 private bool _disposed = false;
35 /// The media vision source constructor
38 /// MediaVisionSource source = new MediaVisionSource();
40 public MediaVisionSource()
42 int ret = Interop.MediaVision.MediaSource.Create(out _sourceHandle);
43 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to create media vision source.");
47 /// Destructor of the MediaVisionSource class.
55 /// Gets buffer of the media source.
66 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.MediaSource.GetBuffer(_sourceHandle, out byteStrPtr, out byteStrSize);
67 if (ret != MediaVisionError.None)
69 Log.Error(MediaVisionLog.Tag, "[{0}] : Failed to get buffer data", ret.ToString());
73 byte[] byteStr = new byte[byteStrSize];
76 Marshal.Copy(byteStrPtr, byteStr, 0, byteStrSize);
84 /// Gets height of the media source.
94 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.MediaSource.GetHeight(_sourceHandle, out height);
95 if (ret != MediaVisionError.None)
97 Log.Error(MediaVisionLog.Tag, "[{0}] : Failed to get height", ret.ToString());
105 /// Gets width of the media source.
115 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.MediaSource.GetWidth(_sourceHandle, out width);
116 if (ret != MediaVisionError.None)
118 Log.Error(MediaVisionLog.Tag, "[{0}] : Failed to get width", ret.ToString());
126 /// Gets colorspace of the media source.
131 public Colorspace Colorspace
135 Colorspace colorspace = Colorspace.Invalid;
136 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.MediaSource.GetColorspace(_sourceHandle, out colorspace);
137 if (ret != MediaVisionError.None)
139 Log.Error(MediaVisionLog.Tag, "[{0}] : Failed to get colorspace", ret.ToString());
147 /// Fills the media source based on the media packet.
149 /// <param name="mediaPacket">The media packet from which the source will be filled</param>
153 /*public void FillMediaPacket(BaseMediaPacket mediaPacket)
155 int ret = Interop.MediaVision.MediaSource.FillBuffer(out _sourceHandle, mediaPacket._mediaPacketHandle);
156 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to fill media packet");
160 /// Fills the media source based on the buffer and metadata.
162 /// <param name="buffer">The buffer of image data</param>
163 /// <param name="width">The width of image data</param>
164 /// <param name="height">The height of image data</param>
165 /// <param name="colorspace">The image colorspace</param>
166 /// <seealso cref="Clear()"/>
170 public void FillBuffer(byte[] buffer, uint width, uint height, Colorspace colorspace)
172 int ret = Interop.MediaVision.MediaSource.FillBuffer(_sourceHandle, buffer, buffer.Length, width, height, colorspace);
173 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to fill buffer");
177 /// Clears the buffer of the media source.
179 /// <seealso cref="FillBuffer()"/>
185 int ret = Interop.MediaVision.MediaSource.Clear(_sourceHandle);
186 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to clear media source buffer");
189 public void Dispose()
192 GC.SuppressFinalize(this);
195 protected virtual void Dispose(bool disposing)
204 // Free managed objects
207 Interop.MediaVision.MediaSource.Destroy(_sourceHandle);