Ejemplo n.º 1
0
        public static void Fill(Demuxer demuxer)
        {
            DemuxerInfo di = new DemuxerInfo();

            di.Name       = Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->name);
            di.LongName   = Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->long_name);
            di.Extensions = Utils.BytePtrToStringUTF8(demuxer.fmtCtx->iformat->extensions);
            di.StartTime  = demuxer.fmtCtx->start_time * 10;
            di.Duration   = demuxer.fmtCtx->duration * 10;

            demuxer.info = di;
            StreamInfo.Fill(demuxer);

            //for (int i=0; i<demuxer.fmtCtx->nb_streams; i++)
            //{
            //    switch (demuxer.fmtCtx->streams[i]->codecpar->codec_type)
            //    {
            //        case AVMEDIA_TYPE_AUDIO:
            //            demuxer.AudioStreams.Add(new EmbeddedAudioStream(demuxer.fmtCtx->streams[i]));
            //            if (demuxer.fmtCtx->streams[i]->duration <= 0) demuxer.AudioStreams[demuxer.AudioStreams.Count-1].Duration = demuxer.decCtx.demuxer.info.Duration;
            //            break;

            //        case AVMEDIA_TYPE_VIDEO:
            //            demuxer.VideoStreams.Add(new EmbeddedVideoStream(demuxer.fmtCtx->streams[i]));
            //            if (demuxer.fmtCtx->streams[i]->duration <= 0) demuxer.VideoStreams[demuxer.VideoStreams.Count-1].Duration = demuxer.decCtx.demuxer.info.Duration;
            //            break;

            //        case AVMEDIA_TYPE_SUBTITLE:
            //            demuxer.SubtitleStreams.Add(new EmbeddedSubtitleStream(demuxer.fmtCtx->streams[i]));
            //            if (demuxer.fmtCtx->streams[i]->duration <= 0) demuxer.SubtitleStreams[demuxer.SubtitleStreams.Count-1].Duration = demuxer.decCtx.demuxer.info.Duration;
            //            break;
            //    }
            //}
        }
Ejemplo n.º 2
0
        public void Init(Renderer renderer, Config cfg)
        {
            this.renderer = renderer;
            this.cfg      = cfg;
            status        = Status.None;

            Master.RegisterFFmpeg();

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

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

            va = new VideoAcceleration();
            if (cfg.decoder.HWAcceleration)
            {
                va.Init(renderer.device);
            }

            GCHandle decCtxHandle = GCHandle.Alloc(this);

            decCtxPtr = (IntPtr)decCtxHandle;
        }
Ejemplo n.º 3
0
 public static void Fill(Demuxer demuxer)
 {
     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].Duration <= 0)
         {
             demuxer.streams[i].Duration = demuxer.decCtx.demuxer.fmtCtx->duration * 10;
         }
     }
 }
Ejemplo n.º 4
0
        public void Close()
        {
            if (decodeThread != null && decodeThread.IsAlive)
            {
                stopThread = true;
                decodeARE.Set();
                Utils.EnsureThreadDone(decodeThread);
                stopThread = false;
            }

            if (status == Status.None)
            {
                return;
            }

            if (demuxer.enabledStreams.Contains(st->index))
            {
                Log($"Closing StreamIndex #{st->index}");
                st->discard = AVDiscard.AVDISCARD_ALL;
                demuxer.enabledStreams.Remove(st->index);
            }

            Flush();

            if (type == MediaType.Video)
            {
                av_buffer_unref(&codecCtx->hw_device_ctx);
                if (swsCtx != null)
                {
                    sws_freeContext(swsCtx); swsCtx = null;
                }
            }
            //else if (type == MediaType.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.None;
        }
Ejemplo n.º 5
0
        public int Open(Demuxer demuxer, AVStream *st)
        {
            Log($"Opening StreamIndex #{st->index}");
            if (status != Status.None)
            {
                Close();
            }

            this.st      = st;
            this.demuxer = demuxer;
            isEmbedded   = demuxer.type == MediaType.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.Name = $"{type} Decoder"; decodeThread.IsBackground = true; decodeThread.Start();
                while (status != Status.Paused)
                {
                    Thread.Sleep(5);
                }
            }
            else
            {
                status = Status.Paused;
            }

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

            return(ret);
        }
Ejemplo n.º 6
0
        public static string GetDumpAll(Demuxer demuxer)
        {
            var dump = demuxer.info.ToString() + "\r\n";

            foreach (var stream in demuxer.streams)
            {
                dump += stream.ToString() + "\r\n";
            }

            return(dump.Trim());

            //var dump = demuxer.info.ToString() + "\r\n";

            //foreach(var stream in demuxer.VideoStreams)
            //    dump += stream.GetDump() + "\r\n";

            //foreach(var stream in demuxer.AudioStreams)
            //    dump += stream.GetDump() + "\r\n";

            //foreach(var stream in demuxer.SubtitleStreams)
            //    dump += stream.GetDump() + "\r\n";

            //return dump.Trim();
        }
Ejemplo n.º 7
0
 public static string GetDump(Demuxer demuxer)
 {
     return(demuxer.info.ToString());
 }