Esempio n. 1
0
        public void Init(Device device)
        {
            Utils.RegisterFFmpegBinaries();
            //av_log_set_level(AV_LOG_MAX_OFFSET);
            av_log_set_level(AV_LOG_WARNING);
            av_log_set_callback(Utils.ffmpegLogCallback);

            vDecoder = new Decoder(Type.Video, this);
            aDecoder = new Decoder(Type.Audio, this);
            sDecoder = new Decoder(Type.Subs, this);

            demuxer  = new Demuxer(Type.Video, this);
            aDemuxer = new Demuxer(Type.Audio, this);
            sDemuxer = new Demuxer(Type.Subs, this);

            va = new VideoAcceleration();
            if (opt.video.HWAcceleration)
            {
                va.Init(device);
            }
            this.device = device;

            status = Status.NOTSET;

            GCHandle decCtxHandle = GCHandle.Alloc(this);

            decCtxPtr = (IntPtr)decCtxHandle;
        }
Esempio n. 2
0
        public static void Fill(Demuxer demuxer)
        {
            Console.WriteLine($"[# Format] {Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->long_name)}/{Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->name)} | {Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->extensions)} | {new TimeSpan(demuxer.fmtCtx->start_time * 10)}/{new TimeSpan(demuxer.fmtCtx->duration * 10)}");

            demuxer.streams = new StreamInfo[demuxer.fmtCtx->nb_streams];
            for (int i = 0; i < demuxer.fmtCtx->nb_streams; i++)
            {
                demuxer.streams[i] = Get(demuxer.fmtCtx->streams[i]);
                if (demuxer.streams[i].DurationTicks <= 0)
                {
                    demuxer.streams[i].DurationTicks = demuxer.decCtx.demuxer.fmtCtx->duration * 10;
                }
                PrintDump(demuxer.streams[i]);
            }
        }
Esempio n. 3
0
        public void Close()
        {
            if (status == Status.NOTSET)
            {
                return;
            }
            if (decodeThread.IsAlive)
            {
                forcePause = true; Thread.Sleep(20); if (decodeThread.IsAlive)
                {
                    decodeThread.Abort();
                }
            }

            if (demuxer.enabledStreams.Contains(st->index))
            {
                st->discard = AVDiscard.AVDISCARD_ALL;
                demuxer.enabledStreams.Remove(st->index);
            }

            Flush();

            if (type == Type.Video)
            {
                av_buffer_unref(&codecCtx->hw_device_ctx);
                if (swsCtx != null)
                {
                    sws_freeContext(swsCtx); swsCtx = null;
                }
            }
            else if (type == Type.Audio)
            {
                //fixed (SwrContext** ptr = &swrCtx) swr_free(ptr);
            }

            avcodec_close(codecCtx);
            if (frame != null)
                fixed(AVFrame **ptr = &frame) av_frame_free(ptr);
            if (codecCtx != null)
                fixed(AVCodecContext **ptr = &codecCtx) avcodec_free_context(ptr);
            codecCtx = null;
            decodeARE.Reset();
            demuxer    = null;
            st         = null;
            info       = null;
            isEmbedded = false;
            status     = Status.NOTSET;
        }
Esempio n. 4
0
        public int Open(Demuxer demuxer, AVStream *st)
        {
            if (status != Status.NOTSET)
            {
                Close();
            }

            this.st      = st;
            this.demuxer = demuxer;
            isEmbedded   = demuxer.type == Type.Video ? true : false;
            info         = demuxer.streams[st->index];

            int ret = OpenCodec();

            if (ret < 0)
            {
                return(ret);
            }

            if (decodeThread == null || !decodeThread.IsAlive)
            {
                decodeThread = new Thread(() => Decode());
                decodeThread.IsBackground = true;
                decodeThread.Start();
                while (status != Status.READY)
                {
                    Thread.Sleep(5);
                }
            }
            else
            {
                status = Status.READY;
            }

            frame = av_frame_alloc();

            demuxer.enabledStreams.Add(st->index);
            st->discard = AVDiscard.AVDISCARD_DEFAULT;

            return(ret);
        }