protected bool AllocateBuffers(uint width, uint height)
        {
            // Allocate exactly 3 buffers to use as the capture destination while streaming.
            // These buffers are passed to the SDK.
            for (uint i = 0; i < 3; ++i)
            {
                IntPtr    buffer = IntPtr.Zero;
                ErrorCode ret    = m_Stream.AllocateFrameBuffer(width * height * 4, out buffer);
                if (Error.Failed(ret))
                {
                    string err = Error.GetString(ret);
                    ReportError(string.Format("Error while allocating frame buffer: {0}", err));
                    return(false);
                }

                m_CaptureBuffers.Add(buffer);
                m_FreeBufferList.Add(buffer);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Begins the ingest testing.
        /// </summary>
        public void Start()
        {
            // can only run it once per instance
            if (m_TestState != TestState.Uninitalized)
            {
                return;
            }

            m_CurrentServerIndex = 0;
            m_CancelTest         = false;
            m_SkipServer         = false;

            m_PreviousStatCallbacks = m_Stream.StatCallbacks;
            m_Stream.StatCallbacks  = this;

            m_PreviousStreamCallbacks = m_Stream.StreamCallbacks;
            m_Stream.StreamCallbacks  = this;

            m_IngestTestVideoParams                        = new VideoParams();
            m_IngestTestVideoParams.TargetFps              = Twitch.Broadcast.Constants.TTV_MAX_FPS;
            m_IngestTestVideoParams.MaxKbps                = Twitch.Broadcast.Constants.TTV_MAX_BITRATE;
            m_IngestTestVideoParams.OutputWidth            = 1280;
            m_IngestTestVideoParams.OutputHeight           = 720;
            m_IngestTestVideoParams.PixelFormat            = PixelFormat.TTV_PF_BGRA;
            m_IngestTestVideoParams.DisableAdaptiveBitrate = true;
            m_IngestTestVideoParams.VerticalFlip           = false;

            m_Stream.GetDefaultParams(m_IngestTestVideoParams);

            m_IngestTestAudioParams = new AudioParams();
            m_IngestTestAudioParams.AudioEnabled = false;

            m_IngestBuffers = new List <UIntPtr>();

            // allocate some buffers
            int numFrames = 3;

            for (int i = 0; i < numFrames; ++i)
            {
                UIntPtr buffer = UIntPtr.Zero;
                uint    size   = m_IngestTestVideoParams.OutputWidth * m_IngestTestVideoParams.OutputHeight * 4;

                m_Stream.AllocateFrameBuffer(size, out buffer);

                if (buffer == UIntPtr.Zero)
                {
                    Cleanup();
                    SetTestState(TestState.Failed);
                    return;
                }

                m_Stream.RandomizeFrameBuffer(buffer, size);

                m_IngestBuffers.Add(buffer);
            }

            SetTestState(TestState.Starting);

            m_Timer.Reset();
            m_Timer.Start();
        }