private void SetMediaStreamInfo(StreamType streamType, MediaFormat mediaFormat) { if (mediaFormat == null) { Log.Error(PlayerLog.Tag, "invalid media format"); return; } IntPtr ptr = IntPtr.Zero; try { ptr = mediaFormat.AsNativeHandle(); NativePlayer.SetMediaStreamInfo(_player.Handle, (int)streamType, ptr). ThrowIfFailed("Failed to set the media stream info"); } finally { MediaFormat.ReleaseNativeHandle(ptr); } }
/// <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); } } }
/// <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("Creating a packet for container is not supported."); } IntPtr formatHandle = IntPtr.Zero; try { formatHandle = format.AsNativeHandle(); int ret = Interop.MediaPacket.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) { Interop.MediaPacket.Destroy(_handle); _handle = IntPtr.Zero; } throw; } finally { if (formatHandle != IntPtr.Zero) { Interop.MediaFormat.Unref(formatHandle); } } }