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); }
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); }
public void addCache(string abs_path, VideoCache vc) { if (vcs.ContainsKey(abs_path)) { vcs[abs_path] = vc; } else { vcs.Add(abs_path, vc); } }
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); }
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { VideoCache vc = (VideoCache)e.UserState; label1.Text = string.Format("已載入{0}影格", vc.frames.Count); }
void vc_FrameLoaded(VideoCache arg1, int arg2) { backgroundWorker1.ReportProgress(50, arg1); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { VideoCache vc = (VideoCache)e.Argument; vc.startLoad(); }
public RTPPlayer(string host, int port, VideoCache vc) { us = new UdpSender(host, port); this.vc = vc; }
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); }
public void addCache(string abs_path, VideoCache vc) { if (vcs.ContainsKey(abs_path)) vcs[abs_path] = vc; else vcs.Add(abs_path, vc); }
public RTPPlayer(string host, int port, VideoCache vc) { us = new UdpSender(host, port); this.vc = vc; }
void vc_FrameLoaded(VideoCache arg1, int arg2) { backgroundWorker1.ReportProgress(50, arg1); }
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); }