Пример #1
0
            private static IntPtr GetExtra(IntPtr handle)
            {
                int ret = Native.GetExtra(handle, out var value);

                MultimediaDebug.AssertNoError(ret);

                return(value);
            }
Пример #2
0
        /// <summary>
        /// Releases the resources used by the <see cref="MediaPacket"/> object.
        /// </summary>
        /// <param name="disposing">
        /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        /// <since_tizen> 3 </since_tizen>
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (_handle != IntPtr.Zero)
            {
                Native.Destroy(_handle);
                _handle = IntPtr.Zero;
            }

            _isDisposed = true;
        }
Пример #3
0
        /// <summary>
        /// Retrieves video planes of the current packet.
        /// </summary>
        /// <returns>The <see cref="MediaPacketVideoPlane"/>s allocated to the current MediaPacket.</returns>
        private MediaPacketVideoPlane[] GetVideoPlanes()
        {
            Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetNumberOfVideoPlanes(_handle, out var numberOfPlanes);

            MultimediaDebug.AssertNoError(ret);

            MediaPacketVideoPlane[] planes = new MediaPacketVideoPlane[numberOfPlanes];

            for (int i = 0; i < numberOfPlanes; ++i)
            {
                planes[i] = new MediaPacketVideoPlane(this, i);
            }

            return(planes);
        }
Пример #4
0
        /// <summary>
        /// Retrieves the buffer of the current packet.
        /// </summary>
        /// <returns>The <see cref="IMediaBuffer"/> allocated to the current MediaPacket.</returns>
        private IMediaBuffer GetBuffer()
        {
            Debug.Assert(!IsDisposed, "Packet is already disposed!");

            Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetBufferData(_handle, out var dataHandle);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!");

            ret = Native.GetAllocatedBufferSize(_handle, out var size);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(size >= 0, "size must not be negative!");

            return(new DependentMediaBuffer(this, dataHandle, size));
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the MediaPacket class from a native handle.
        /// </summary>
        /// <param name="handle">The native handle to be used.</param>
        internal MediaPacket(IntPtr handle)
        {
            _handle = handle;

            int ret = Native.GetFormat(handle, out IntPtr formatHandle);

            MultimediaDebug.AssertNoError(ret);

            try
            {
                if (formatHandle != IntPtr.Zero)
                {
                    _format = MediaFormat.FromHandle(formatHandle);
                }
            }
            finally
            {
                NativeFormat.Unref(formatHandle);
            }
        }
Пример #6
0
        /// <summary>
        /// Allocates internal buffer.
        /// </summary>
        /// <exception cref="InvalidOperationException">Operation failed.</exception>
        private void Alloc()
        {
            ErrorCode ret = (ErrorCode)Native.Alloc(_handle);

            if (ret == ErrorCode.None)
            {
                return;
            }

            _handle = IntPtr.Zero;

            switch (ret)
            {
            case ErrorCode.OutOfMemory:
                throw new OutOfMemoryException("Failed to allocate buffer for the packet.");

            default:
                throw new InvalidOperationException("Failed to create a packet.");
            }
        }
Пример #7
0
        /// <summary>
        /// Creates and initializes a native handle for the current object.
        /// </summary>
        /// <param name="format">The format to be set to the media format.</param>
        /// <exception cref="InvalidOperationException">Operation failed.</exception>
        private void Initialize(MediaFormat format)
        {
            if (format.Type == MediaFormatType.Container)
            {
                throw new ArgumentException("Container format can't be used to create a new packet.",
                                            nameof(format));
            }

            IntPtr formatHandle = IntPtr.Zero;

            try
            {
                formatHandle = format.AsNativeHandle();

                int ret = Native.Create(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle);
                MultimediaDebug.AssertNoError(ret);

                Debug.Assert(_handle != IntPtr.Zero, "Created handle must not be null");

                Alloc();
            }
            catch (Exception)
            {
                if (_handle != IntPtr.Zero)
                {
                    Native.Destroy(_handle);
                    _handle = IntPtr.Zero;
                }

                throw;
            }
            finally
            {
                if (formatHandle != IntPtr.Zero)
                {
                    NativeFormat.Unref(formatHandle);
                }
            }
        }
Пример #8
0
        internal MediaPacketVideoPlane(MediaPacket packet, int index)
        {
            Debug.Assert(packet != null, "The packet is null!");
            Debug.Assert(!packet.IsDisposed, "Packet is already disposed!");
            Debug.Assert(index >= 0, "Video plane index must not be negative!");

            _packet = packet;

            int ret = Native.GetVideoStrideWidth(packet.GetHandle(), index, out _strideWidth);

            MultimediaDebug.AssertNoError(ret);

            ret = Native.GetVideoStrideHeight(packet.GetHandle(), index, out _strideHeight);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(_strideWidth >= 0 && _strideHeight >= 0, "size must not be negative!");

            ret = Native.GetVideoPlaneData(packet.GetHandle(), index, out var dataHandle);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!");

            _buffer = new DependentMediaBuffer(packet, dataHandle, _strideWidth * _strideHeight);
        }
Пример #9
0
            private void SetExtra(IntPtr ptr)
            {
                int ret = Native.SetExtra(_packet._handle, ptr);

                MultimediaDebug.AssertNoError(ret);
            }