示例#1
0
 public bool Push(BSPDMediaData data)
 {
     if (data.MediaType == BSPDMediaDataType.Audio)
     {
         lock (alock)
         {
             if (AQueue.Count < 10)
             {
                 AQueue.Enqueue(data);
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     else
     {
         lock (vlock)
         {
             if (VQueue.Count < 10)
             {
                 VQueue.Enqueue(data);
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
 }
示例#2
0
        public void InitClock(BSPDMediaData adata, BSPDMediaData vdata)
        {
            long time = GetTimeStamp();

            realTimeClock.SetClock(time);
            realTimeClock.UpDateClock(time);
            videoClock.SetClock(vdata.vpts, vdata.vdur, vdata.vpts);
            // audioClock.SetClock(adata.vpts, adata.vdur, adata.vpts);
        }
示例#3
0
 public void UpdateMediaClock(BSPDMediaData data, long time)
 {
     if (data.MediaType == BSPDMediaDataType.Audio)
     {
         audioClock.Update(data.vpts, data.vdur, time);
     }
     else
     {
         videoClock.Update(data.vpts, data.vdur, time);
     }
 }
示例#4
0
 public void Update()
 {
     tcontrol.CheckUpdate(preData);
     //Console.WriteLine(preData.vpts);
     //if (VBaseTime ==-1)
     //{
     //  vPaseTime =  VBaseTime = preData.vpts;
     //}
     //vPaseTime += preData.vdur;
     //Console.WriteLine("DUR:" + preData.vdur);
     nextData = null;
 }
示例#5
0
        public bool Push(BSPDMediaData data)
        {
            lock (qlock)
            {
                if (queue.Count < 30)
                {
                    queue.Enqueue(data);
                    return(true);
                }
            }

            return(false);
        }
示例#6
0
        public void CheckUpdate(BSPDMediaData data)
        {
            videoCurTime = data.vpts;
            realCurTime  = GetTimeStamp();

            if (videoCurTime - videoPreTime < realCurTime - realPreTime)
            {
                //update
                ResetPreTime();
                Console.WriteLine("UPDATE");
            }

            DelayTime = (realCurTime - realInitTime) - (videoCurTime - videoInitTime);
            Console.WriteLine("DELAY:" + DelayTime);
        }
示例#7
0
        public long GetMediaDur(BSPDMediaData data)
        {
            long st = 0;

            if (data.MediaType == BSPDMediaDataType.Audio)
            {
                st = audioClock.StartTime;
            }
            else
            {
                st = videoClock.StartTime;
            }
            long rt = data.vpts - st + data.vdur;

            return(rt);
        }
示例#8
0
        public int CheckUpdate(BSPDMediaData data)
        {
            long time = GetTimeStamp();

            long delay    = time - realTimeClock.LastUpdate;
            long mediadur = GetMediaDur(data);
            long rtdur    = GetRealTimeDurWithoutLag();
            long diff     = mediadur - rtdur - delay;

            CalculateAVGTime();
            realTimeClock.UpDateClock(time);

            if (diff < -RenderAvgtime)
            {
                Console.WriteLine("drop data:" + data.MediaType + " diff:" + diff);
                int rt = 0;
                if (-diff > RenderAvgtime + data.vdur)
                {
                    rt = (int)(-diff) / (int)data.vdur;
                }
                else
                {
                    rt = (int)(RenderAvgtime) / (int)data.vdur;
                }
                rt++;
                Console.WriteLine("drop data:" + data.MediaType + " rt:" + rt);
                return(-rt);
            }
            diff = mediadur - rtdur - delay - RenderAvgtime;
            if (diff > 0)
            {
                Console.WriteLine("NotNeed Update diff :" + diff);
                return(0);
            }
            else
            {
                UpdateMediaClock(data, time);
                Console.WriteLine("update");
                return(1);
            }
        }
示例#9
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);
            }
        }
示例#10
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();
                    //}
                }
            }
        }