Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            VideoCache vc = null;
            vc = new VideoCache(openFileDialog1.FileName);
            vc.FrameLoaded += new Action<VideoCache, int>(vc_FrameLoaded);
            backgroundWorker1.RunWorkerAsync(vc);
            string abs_path=textBox3.Text;

            rs.addCache(abs_path, vc);
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            VideoCache vc = null;

            vc              = new VideoCache(openFileDialog1.FileName);
            vc.FrameLoaded += new Action <VideoCache, int>(vc_FrameLoaded);
            backgroundWorker1.RunWorkerAsync(vc);
            string abs_path = textBox3.Text;

            rs.addCache(abs_path, vc);
        }
Esempio n. 3
0
 public void addCache(string abs_path, VideoCache vc)
 {
     if (vcs.ContainsKey(abs_path))
     {
         vcs[abs_path] = vc;
     }
     else
     {
         vcs.Add(abs_path, vc);
     }
 }
Esempio n. 4
0
        public bool readPreviousTag(Stream stream)
        {
            var p = stream.Position;
            //Debug.WriteLine("readPreviousTag:{0}({0:X})+4+11=>{1}({1:X})", p,p+11+4);
            var    PreviousTagSize = stream.ReadUInt32();      //4    倒置读取位置
            FlvTag flvTag          = FlvTag.createTag(stream); //11   头部

            if (flvTag == null)
            {
                return(false);
            }
            var data = flvTag.LoadTagData(stream);

            //媒体数据
            if (flvTag is ScriptDataTag)
            {
                MediaData = flvTag as ScriptDataTag;
                return(true);
            }

            //音频头帧
            if (flvTag is AudioTag)
            {
                var tag = flvTag as AudioTag;
                if (FirstAudio == null)
                {
                    FirstAudio = tag as AudioTag;
                    return(true);
                }
                AudioCache.Enqueue(tag);
            }

            //视频头帧
            if (flvTag is VideoTag)
            {
                var tag = flvTag as VideoTag;
                if (FirstVideo == null)
                {
                    FirstVideo = flvTag as VideoTag;
                    return(true);
                }

                VideoCache.Enqueue(tag);
            }

            return(true);
        }
Esempio n. 5
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            VideoCache vc = (VideoCache)e.UserState;

            label1.Text = string.Format("已載入{0}影格", vc.frames.Count);
        }
Esempio n. 6
0
 void vc_FrameLoaded(VideoCache arg1, int arg2)
 {
     backgroundWorker1.ReportProgress(50, arg1);
 }
Esempio n. 7
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            VideoCache vc = (VideoCache)e.Argument;

            vc.startLoad();
        }
Esempio n. 8
0
 public RTPPlayer(string host, int port, VideoCache vc)
 {
     us      = new UdpSender(host, port);
     this.vc = vc;
 }
Esempio n. 9
0
        bool Reload(double time)
        {
            Stream m = null;
            int    i = 0;

            try {
                for (i = 0; i < times.Count; i++)
                {
                    if (times[i] >= time)
                    {
                        m          = this.CreateStream();
                        m.Position = kfs[i] - 4;
                        newFrame   = true;
                        break;
                    }
                }
            }
            catch (Exception e) {
                m = null;
            }
            if (m != null)
            {
                VideoCache.Clear();
                AudioCache.Clear();
                var dm = MainStream;
                if (dm != null)
                {
                    Task.Run(async() => {
                        await Task.Delay(1000);
                        dm.Dispose();
                    });
                }
                MainStream = m;;
                Debug.WriteLine(time + "==>  TIMER:" + times[i] + "    KFS:{0}({0:X})", kfs[i]);
            }
            if (!running)
            {
                running = true;
                Debug.WriteLine("==running:true==");
                Task.Run(async() => {
                    try {
                        while (true)
                        {
                            if (VideoCache.Count > 1024 || AudioCache.Count > 1024)
                            {
                                await Task.Delay(500);
                                //Debug.WriteLine("@@@ WAIT:RUNNING:" + VideoCache.Count + "|" + AudioCache.Count + " @@@");
                                continue;
                            }/*
                              * if (MainStream != m && MainStream != null) {
                              * m = MainStream;
                              * Debug.WriteLine("==running:update==");
                              * }*/
                            if (!this.readPreviousTag(MainStream))
                            {
                                break;
                            }
                        }
                        Debug.WriteLine("==running:false==");
                        Debug.WriteLine("END:" + MainStream.Position + "/" + MainStream.Length);
                        running = false;
                    }
                    catch (Exception ERR) {
                        Debug.WriteLine("==running:catch==");
                        running = false;
                        await Task.Delay(3000);
                        Debug.WriteLine(ERR);
                        Reload(time);
                        //throw;
                    }
                });
            }
            return(m != null);
        }
Esempio n. 10
0
 public void addCache(string abs_path, VideoCache vc)
 {
     if (vcs.ContainsKey(abs_path))
         vcs[abs_path] = vc;
     else
         vcs.Add(abs_path, vc);
 }
Esempio n. 11
0
 public RTPPlayer(string host, int port, VideoCache vc)
 {
     us = new UdpSender(host, port);
     this.vc = vc;
 }
Esempio n. 12
0
 void vc_FrameLoaded(VideoCache arg1, int arg2)
 {
     backgroundWorker1.ReportProgress(50, arg1);
 }
Esempio n. 13
0
        bool Reload(double time)
        {
            Stream m = null;

            try {
                for (int i = 0; i < times.Count; i++)
                {
                    if (times[i] >= time)
                    {
                        m = this.CreateStream();
                        //Debug.WriteLine("====Reload:"+i+"=====:" );
                        Debug.WriteLine(time + "==>  TIMER:" + times[i] + "    KFS:{0}({0:X})", kfs[i]);
                        m.Position = kfs[i] - 4;
                        VideoCache.Clear();
                        AudioCache.Clear();
                        break;
                    }
                }
            }
            catch (Exception e) {
                m = null;
                Debug.WriteLine(e);
            }
            if (m == null)
            {
                return(false);
            }
            else
            {
                MainStream = m;
            }

            if (!running)
            {
                running = true;
                Debug.WriteLine("==running:true==");
                Task.Run(async() => {
                    try {
                        while (true)
                        {
                            if (VideoCache.Count > 1024 || AudioCache.Count > 1024)
                            {
                                await Task.Delay(500);
                                //Debug.WriteLine("@@@ WAIT:RUNNING:" + VideoCache.Count + "|" + AudioCache.Count + " @@@");
                                continue;
                            }
                            if (!this.readPreviousTag(MainStream))
                            {
                                break;
                            }
                        }
                        Debug.WriteLine("==running:false==");
                        running = false;
                    }
                    catch (Exception ERR) {
                        Debug.WriteLine("==running:false==");
                        running = false;
                        Debug.WriteLine(ERR);
                        Reload(time + 5);
                        //throw;
                    }
                });
            }

            return(true);
        }