Exemple #1
0
 public void Close()
 {
     BSPDAbort();
     if (mThread != null)
     {
         mThread.Abort();
     }
     lock (mctxlocker)
     {
         BSPDClose(mBSPDCtx);
     }
     MediaStateChage?.Invoke(BSPDMediaState.close);
 }
Exemple #2
0
        private void DataThread()
        {
            bool          op        = true;
            BSPDMediaData mediaData = null;

            byte[] ydata, udata, vdata;

            var file = System.IO.File.Open("e:/test.pcm", System.IO.FileMode.OpenOrCreate);

            BSPDContext bSPD = (BSPDContext)Marshal.PtrToStructure(mBSPDCtx, typeof(BSPDContext));

            GC.SuppressFinalize(bSPD);
            ydata = new byte[bSPD.ysize];
            udata = new byte[bSPD.ysize / 4];
            vdata = new byte[bSPD.ysize / 4];
            int w = 0, h = 0;

            BSPDGetDecWH(mBSPDCtx, ref w, ref h);
            DecW = w;
            DecH = h;
            long apts = 0, vpts = 0, aduration = 0, vduration = 0;

            MediaStateChage?.Invoke(BSPDMediaState.buffering);
            while (true)
            {
                //var idex= StaticCache.PushIndex();
                //if (idex == -1)
                //{
                //    Thread.Sleep(10);
                //    continue;
                //}

                //if (mediaData== null)
                //{
                //    StaticCache.mediaQueue[idex] = new BSPDMediaData();
                //    StaticCache.mediaQueue[idex].YData = new byte[ydata.Length];
                //    StaticCache.mediaQueue[idex].VData = new byte[vdata.Length];
                //    StaticCache.mediaQueue[idex].UData = new byte[udata.Length];
                //}


                if (op)
                {
                    int flt = 0;
                    lock (mctxlocker)
                    {
                        //if(0 != BSPDGetYUVWithTime(mBSPDCtx, ydata, udata, vdata, ref vpts, ref apts, ref vduration, ref aduration))
                        //{
                        //    MediaStateChage?.Invoke(BSPDMediaState.error);
                        //}
                        flt = BSPDGetRawDataWithTime(mBSPDCtx, ydata, udata, vdata, ref vpts, ref vduration);
                        if (flt == 2)
                        {
                            int num = GetInt32(udata);
                            // Console.WriteLine("audio pts:" + vpts + " dur:" + vduration);
                            // file.Write(ydata, 0, num);
                            continue;
                        }
                        else if (flt == 1)
                        {
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (flt == 1)
                    {
                        mediaData       = new BSPDMediaData();
                        mediaData.YData = new byte[ydata.Length];
                        mediaData.VData = new byte[vdata.Length];
                        mediaData.UData = new byte[udata.Length];
                        Array.Copy(ydata, mediaData.YData, ydata.Length);
                        Array.Copy(udata, mediaData.UData, udata.Length);
                        Array.Copy(vdata, mediaData.VData, vdata.Length);
                        mediaData.vpts      = vpts;
                        mediaData.vdur      = vduration;
                        mediaData.MediaType = BSPDMediaDataType.Video;
                    }
                    //Array.Copy(ydata, StaticCache.mediaQueue[idex].YData, ydata.Length);
                    //Array.Copy(vdata, StaticCache.mediaQueue[idex].VData, vdata.Length);
                    //Array.Copy(udata, StaticCache.mediaQueue[idex].UData, udata.Length);
                    //StaticCache.mediaQueue[idex].vpts = vpts;
                    //StaticCache.mediaQueue[idex].vdur = vduration;
                    //StaticCache.mediaQueue[idex].MediaType = BSPDMediaDataType.Video;
                }
                else
                {
                    Thread.Sleep(10);
                }
                op = mediaCache.Push(mediaData);
                // op = StaticCache.Push();
                //op = bSPDCache.Push(mediaData);
            }
        }
Exemple #3
0
        public void CheckUpdate()
        {
            curtime = GetTimeStamp();

            if (bSPDCache != null && nextData == null)
            {
                //idex = StaticCache.PopIndex();
                //if (idex!=-1)
                //{
                //    nextData = StaticCache.mediaQueue[idex];
                //    StaticCache.Pop();
                //}
                //else
                //{
                //    nextData = null;
                ////}
                //if (tcontrol.DelayTime>500)
                //{
                //    mediaCache.TrySkipFrame(-1);
                //}
                nextData = mediaCache.Pop();
//                nextData = bSPDCache.Pop(BSPDMediaDataType.Video);
            }
            if (preData == null && nextData != null)
            {
                if (RBaseTime == 0)
                {
                    RBaseTime = curtime;
                }
                preData = nextData;
                pretime = curtime;
                MediaStateChage?.Invoke(BSPDMediaState.open);
                Update();
                if (tc == null)
                {
                    tc = new BSPDTimeControl();
                    tc.InitClock(preData, preData);
                }
                tcontrol.SetInitTime(preData.vpts);
            }
            else
            {
                if (nextData != null)
                {
                    var vt = nextData.vpts - preData.vpts;
                    var rt = curtime - pretime;
                    // Console.WriteLine((curtime + vPaseTime - RBaseTime));
                    vt = nextData.vpts - VBaseTime;
                    rt = curtime - RBaseTime;
                    int fl = tc.CheckUpdate(nextData);
                    if (fl == 1)
                    {
                        preData = nextData;
                        Update();
                    }
                    if (fl < 0)
                    {
                        nextData = null;
                        while (fl < -1 && mediaCache.queue.Count > 2)
                        {
                            mediaCache.Pop();
                            fl++;
                        }
                    }
                    //if (vt<rt)
                    //{
                    //    //Console.WriteLine("VT:" + nextData.vpts);
                    //    // Console.WriteLine("RT:" + rt);
                    //    preData = nextData;
                    //    pretime = curtime;
                    //    Update();
                    //}
                }
            }
        }