示例#1
0
        /// <summary>
        /// Find streams from here.
        /// </summary>
        /// <param name="AOptions">The options <see cref="Dictionary"/>.</param>
        /// <exception cref="ObjectDisposedException">This instance is disposed.</exception>
        /// <exception cref="InvalidOperationException">Stream is closed.</exception>
        /// <exception cref="FFmpegError">Error finding stream info.</exception>
        public void FindStreamInfo([CanBeNull] Dictionary AOptions = null)
        {
            ThrowIfDisposed();

            if (Mode != StreamOpenMode.Input)
            {
                throw new InvalidOperationException("Stream is closed.");
            }

            Ref <Unsafe.AVDictionary> opt = null;

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

            try
            {
                AVFormatContext.FindStreamInfo(Ref, ref opt);
            }
            finally
            {
                if (AOptions != null)
                {
                    // Options were provided, update them.
                    AOptions.Ref = opt;
                }
                else
                {
                    // Options are unwanted, free them.
                    AVDictionary.Free(ref opt);
                }
            }
        }
示例#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;
        }
示例#3
0
        /// <summary>
        /// Open the input context.
        /// </summary>
        /// <param name="AUrl">The input URL.</param>
        /// <param name="ADemuxer">The <see cref="Demuxer"/>.</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="FFmpegError">Error opening context.</exception>
        public void Open(
            string AUrl,
            [CanBeNull] Demuxer ADemuxer    = null,
            [CanBeNull] Dictionary AOptions = null
            )
        {
            ThrowIfDisposed();

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

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

            Ref <Unsafe.AVDictionary> opt = null;

            // If options were provided, input them.
            if (AOptions != null)
            {
                opt = AOptions.Ref;
            }

            try
            {
                AVFormatContext.OpenInput(
                    ref Ref,
                    AUrl,
                    ADemuxer != null ? ADemuxer.Ref : null,
                    ref opt
                    );

                Mode = StreamOpenMode.Input;
            }
            finally
            {
                if (AOptions != null)
                {
                    // Options were provided, update them.
                    AOptions.Ref = opt;
                }
                else
                {
                    // Options are unwanted, free them.
                    AVDictionary.Free(ref opt);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Begin writing stream data.
        /// </summary>
        /// <param name="AOptions"></param>
        /// <exception cref="ObjectDisposedException">This instance is disposed.</exception>
        /// <exception cref="InvalidOperationException">
        /// Stream is not in the Opened state.
        /// </exception>
        /// <exception cref="FFmpegError">Error writing header.</exception>
        public void BeginData([CanBeNull] Dictionary AOptions = null)
        {
            ThrowIfDisposed();

            if (State != OutputState.Opened)
            {
                throw new InvalidOperationException("Stream is not in the Opened state.");
            }

            // TODO : Implement stream check.

            Ref <Unsafe.AVDictionary> opt = null;

            // If options were provided, input them.
            if (AOptions != null)
            {
                opt = AOptions.Ref;
            }

            try
            {
                AVFormatContext.WriteHeader(Ref, ref opt);
                State = OutputState.Ready;
            }
            finally
            {
                if (AOptions != null)
                {
                    // Options were provided, update them.
                    AOptions.Ref = opt;
                }
                else
                {
                    // Options are unwanted, free them.
                    AVDictionary.Free(ref opt);
                }
            }
        }