Пример #1
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;
        }
Пример #2
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);
                }
            }
        }