Exemple #1
0
//		byte[] decodedKeyframe;


        internal void SendUpdate(long elapsedTicks)
        {
            if (nextAudioTick <= elapsedTicks)
            {
                int    newaudiobytes;
                int    newvideobytes;
                byte[] newaudioframes;
                byte[] newvideoframes;
                int    newsampleRate;
                if (videoBuffer.GetNextSecond(out newaudioframes, out newaudiobytes, out newvideoframes, out newvideobytes, out newsampleRate))
                {
                    started         = true;
                    audiobytes      = newaudiobytes;
                    videobytes      = newvideobytes;
                    audioframes     = newaudioframes;
                    videoframes     = newvideoframes;
                    this.sampleRate = newsampleRate;
                    videoptr        = 0;
                    framecnt        = 0;
                    if (!first && nextAudioTick + Stopwatch.Frequency <= elapsedTicks)
                    {
                        nextAudioTick += Stopwatch.Frequency;
                    }
                    else
                    {
                        nextAudioTick = elapsedTicks + Stopwatch.Frequency;
                    }
                    nextVideoFrame = elapsedTicks;
                    if (audiobytes != 0)
                    {
                        foreach (var lcd in subscribers)
                        {
                            if (!LCDWriterCore.isLocalMuted || (MyAPIGateway.Session.OnlineMode != VRage.Game.MyOnlineModeEnum.OFFLINE && videoBuffer.steamid != MyAPIGateway.Multiplayer.MyId))
                            {
                                lcd.PlayAudio(audioframes, audiobytes, sampleRate);
                            }
                        }
                    }
                }
            }
            if (started && nextVideoFrame <= elapsedTicks)
            {
                if (videoframes == null || videoptr >= videobytes)
                {
                    return;                    //wait.
                }
                //int control = BitConverter.ToInt32(videoframes, videoptr);

                ushort stride    = BitConverter.ToUInt16(videoframes, videoptr + sizeof(int));
                ushort height    = BitConverter.ToUInt16(videoframes, videoptr + sizeof(int) + sizeof(ushort));
                ushort width     = BitConverter.ToUInt16(videoframes, videoptr + sizeof(int) + sizeof(ushort) * 2);
                ushort framerate = BitConverter.ToUInt16(videoframes, videoptr + sizeof(int) + sizeof(ushort) * 3);
                //int frameln = BitConverter.ToInt32(videoframes, videoptr + sizeof(int) + sizeof(ushort) * 4);
                LCDWriterCore.debugMonitor.VideoByteLength = videoframes.Length;
                LCDWriterCore.debugMonitor.VideoCharWidth  = width;
                LCDWriterCore.debugMonitor.VideoStride     = stride;
                LCDWriterCore.debugMonitor.VideoHeight     = height;
                LCDWriterCore.debugMonitor.FrameRate       = framerate;
                if (framerate == 0)
                {
                    return;
                }
                if (framerate > 60)
                {
                    framerate = 60;
                }
                nextVideoFrame += (tickspersecond / framerate);


                videoptr += sizeof(int) * 1 + sizeof(ushort) * 4;
                //string s_frame = getString(videoframes, videoptr, width, stride, height);
                var strings = getString(videoframes, videoptr, width, stride, height);
                foreach (var lcd in subscribers)
                {
                    //lcd.PrepareFrame(videoframes, videoptr, stride * height, stride, width, height);
                    //lcd.SetFontSize((float)width, (float)height);

                    lcd.PlayNextFrame(strings, videoptr, width, stride, height);
                }
                videoptr += stride * height;
                framecnt++;
            }
        }