Beispiel #1
0
        /// <inheritdoc />
        protected override unsafe void Dispose(bool ADisposing)
        {
            switch (Mode)
            {
            case StreamOpenMode.Input:
                AVFormatContext.CloseInput(ref Ref);
                break;

            case StreamOpenMode.Output:
                // Close output AVIOContext first.
                Ref <Unsafe.AVIOContext> pb = Ref.Ptr->pb;
                Ref.Ptr->pb = null;
                AVIO.Close(ref pb);

                AVFormatContext.Free(ref Ref);
                break;

            case StreamOpenMode.Closed:
                AVFormatContext.Free(ref Ref);
                break;
            }

            Mode = StreamOpenMode.Closed;
            base.Dispose(ADisposing);
        }
Beispiel #2
0
        /// <summary>
        /// Open the output context.
        /// </summary>
        /// <param name="AUrl">The output URL.</param>
        /// <param name="AMuxer">The <see cref="Muxer"/>.</param>
        /// <param name="AOptions">The options <see cref="Dictionary"/>.</param>
        /// <exception cref="ObjectDisposedException">This instance is disposed.</exception>
        /// <exception cref="InvalidOperationException">Stream is already open.</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="AUrl"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="AMuxer"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="FFmpegError">Error opening context.</exception>
        public unsafe void Open(
            string AUrl,
            Muxer AMuxer,
            [CanBeNull] Dictionary AOptions = null
            )
        {
            ThrowIfDisposed();

            if (Mode != StreamOpenMode.Closed)
            {
                throw new InvalidOperationException("Stream is already open.");
            }

            if (AUrl == null)
            {
                throw new ArgumentNullException(nameof(AUrl));
            }
            if (AMuxer == null)
            {
                throw new ArgumentNullException(nameof(AMuxer));
            }

            Ref <Unsafe.AVIOContext> pb = Ref.Ptr->pb;

            Ref <Unsafe.AVDictionary> opt = null;

            if (AOptions != null)
            {
                opt = AOptions.Ref;
            }

            try
            {
                AVIO.Open(ref pb, AUrl, AVIOOpenFlags.AVIO_FLAG_WRITE, null, ref opt);
                Ref.Ptr->pb = pb;
            }
            finally
            {
                if (AOptions != null)
                {
                    // Options were provided, update them.
                    AOptions.Ref = opt;
                }
                else
                {
                    // Options are unwanted, free them.
                    AVDictionary.Free(ref opt);
                }
            }

            Ref.Ptr->oformat = AMuxer.Ref;
            Mode             = StreamOpenMode.Output;
            State            = OutputState.Opened;
        }