Example #1
0
        public FFmpegCodec(FFmpegFuncs ffmpeg, AVCodec *codec)
        {
            this.ffmpeg = ffmpeg;

            Pointer = codec;
            SupportedHwDeviceTypes = new Lazy <IReadOnlyList <AVHWDeviceType> >(() =>
            {
                var list = new List <AVHWDeviceType>();

                int i = 0;

                while (true)
                {
                    var hwCfg = ffmpeg.avcodec_get_hw_config(codec, i);
                    if (hwCfg == null)
                    {
                        break;
                    }

                    list.Add(hwCfg->device_type);

                    i++;
                }

                return(list);
            });
        }
Example #2
0
        /// <summary>
        /// Creates a new video decoder that decodes the given video stream.
        /// </summary>
        /// <param name="videoStream">The stream that should be decoded.</param>
        public VideoDecoder(Stream videoStream)
        {
            ffmpeg = CreateFuncs();

            this.videoStream = videoStream;
            if (!videoStream.CanRead)
            {
                throw new InvalidOperationException($"The given stream does not support reading. A stream used for a {nameof(VideoDecoder)} must support reading.");
            }

            State             = DecoderState.Ready;
            decodedFrames     = new ConcurrentQueue <DecodedFrame>();
            decoderCommands   = new ConcurrentQueue <Action>();
            availableTextures = new ConcurrentQueue <Texture>(); // TODO: use "real" object pool when there's some public pool supporting disposables
            handle            = new ObjectHandle <VideoDecoder>(this, GCHandleType.Normal);

            TargetHardwareVideoDecoders.BindValueChanged(e =>
            {
                // ignore if decoding wasn't initialized yet.
                if (formatContext == null)
                {
                    return;
                }

                decoderCommands.Enqueue(recreateCodecContext);
            });
        }
Example #3
0
        /// <summary>
        /// Creates a new video decoder that decodes the given video stream.
        /// </summary>
        /// <param name="videoStream">The stream that should be decoded.</param>
        public VideoDecoder(Stream videoStream)
        {
            ffmpeg = CreateFuncs();

            this.videoStream = videoStream;
            if (!videoStream.CanRead)
            {
                throw new InvalidOperationException($"The given stream does not support reading. A stream used for a {nameof(VideoDecoder)} must support reading.");
            }

            State             = DecoderState.Ready;
            decodedFrames     = new ConcurrentQueue <DecodedFrame>();
            decoderCommands   = new ConcurrentQueue <Action>();
            availableTextures = new ConcurrentQueue <Texture>(); // TODO: use "real" object pool when there's some public pool supporting disposables
            handle            = new ObjectHandle <VideoDecoder>(this, GCHandleType.Normal);
        }