Beispiel #1
0
        protected bool StartServerTest(IngestServer server)
        {
            // reset the test
            m_ServerTestSucceeded = true;
            m_TotalSent           = 0;
            m_RTMPState           = RTMPState.Idle;
            m_CurrentServer       = server;

            // start the stream asynchronously
            SetTestState(TestState.ConnectingToServer);
            m_WaitingForStartStopCallback = true;
            ErrorCode ret = m_Stream.Start(m_IngestTestVideoParams, m_IngestTestAudioParams, server, StartFlags.TTV_Start_BandwidthTest, k_AsyncStartStop);

            if (Error.Failed(ret))
            {
                m_ServerTestSucceeded = false;
                SetTestState(TestState.DoneTestingServer);
                return(false);
            }

            // the amount of data sent before the test of this server starts
            m_LastTotalSent = m_TotalSent;

            server.BitrateKbps = 0;
            m_BufferIndex      = 0;

            return(true);
        }
Beispiel #2
0
        protected void CleanupServerTest(IngestServer server)
        {
            m_WaitingForStartStopCallback = true;
            m_Stream.Stop(k_AsyncStartStop);

            m_Stream.PollStats();
        }
Beispiel #3
0
        protected void StopServerTest(IngestServer server)
        {
            if (m_WaitingForStartCallback)
            {
                // wait for the start callback and do the stop after that comes in
                m_SkipServer = true;
            }
            else if (m_Broadcasting)
            {
                m_WaitingForStopCallback = true;

                ErrorCode ec = m_Stream.Stop(true);
                if (Error.Failed(ec))
                {
                    // this should never happen so fake the callback to indicate it's stopped
                    (m_StreamCallbackListener as IBroadcastApiListener).StopCallback(ErrorCode.TTV_EC_SUCCESS);

                    System.Diagnostics.Debug.WriteLine("Stop failed: " + ec.ToString());
                }

                m_Stream.PollStats();
            }
            else
            {
                // simulate a stop callback
                (m_StreamCallbackListener as IBroadcastApiListener).StopCallback(ErrorCode.TTV_EC_SUCCESS);
            }
        }
Beispiel #4
0
        protected void Cleanup()
        {
            m_CurrentServer = null;

            // free the buffers
            if (m_IngestBuffers != null)
            {
                for (int i = 0; i < m_IngestBuffers.Count; ++i)
                {
                    m_Stream.FreeFrameBuffer(m_IngestBuffers[i]);
                }

                m_IngestBuffers = null;
            }

            if (m_Stream.StatCallbacks == this)
            {
                m_Stream.StatCallbacks  = m_PreviousStatCallbacks;
                m_PreviousStatCallbacks = null;
            }

            if (m_Stream.StreamCallbacks == this)
            {
                m_Stream.StreamCallbacks  = m_PreviousStreamCallbacks;
                m_PreviousStreamCallbacks = null;
            }
        }
Beispiel #5
0
        void IStreamCallbacks.GetIngestServersCallback(ErrorCode result, IngestList ingestList)
        {
            if (Error.Succeeded(result))
            {
                m_IngestList = ingestList;

                // assume we're going to use the default ingest server unless overidden by the client
                m_IngestServer = m_IngestList.DefaultServer;

                SetBroadcastState(BroadcastState.ReceivedIngestServers);

                try
                {
                    if (IngestListReceived != null)
                    {
                        IngestListReceived(ingestList);
                    }
                }
                catch (Exception x)
                {
                    ReportError(x.ToString());
                }
            }
            else
            {
                string err = Error.GetString(result);
                ReportError(string.Format("IngestListCallback got failure: {0}", err));

                // try again
                SetBroadcastState(BroadcastState.LoggedIn);
            }
        }
Beispiel #6
0
        protected bool UpdateServerTest(IngestServer server)
        {
            if (m_SkipServer || m_Timer.ElapsedMilliseconds >= m_TestDurationMilliseconds)
            {
                SetTestState(TestState.DoneTestingServer);
                return(true);
            }

            // not started yet
            if (m_WaitingForStartStopCallback)
            {
                return(true);
            }

            ErrorCode ret = m_Stream.SubmitVideoFrame(m_IngestBuffers[m_BufferIndex]);

            if (Error.Failed(ret))
            {
                m_ServerTestSucceeded = false;
                SetTestState(TestState.DoneTestingServer);
                return(false);
            }

            m_BufferIndex = (m_BufferIndex + 1) % m_IngestBuffers.Count;

            m_Stream.PollStats();

            // connected and sending video
            if (m_RTMPState == RTMPState.SendVideo)
            {
                SetTestState(TestState.TestingServer);

                long elapsed = m_Timer.ElapsedMilliseconds;
                if (elapsed > 0 && m_TotalSent > m_LastTotalSent)
                {
                    server.BitrateKbps = (float)(m_TotalSent * 8) / (float)(m_Timer.ElapsedMilliseconds);
                    m_LastTotalSent    = m_TotalSent;
                }
            }

            return(true);
        }
        protected void ReadIngestServerObject(LitJson.JsonReader reader, object context)
        {
            IngestListCallbackData data   = context as IngestListCallbackData;
            IngestServer           server = data.servers.Last();

            switch (reader.Token)
            {
            case LitJson.JsonToken.PropertyName:
            {
                string key = reader.Value.ToString();
                string val = JsonReadStringPropertyRHS(reader);
                switch (key)
                {
                case "Name":
                {
                    server.ServerName = val;
                    break;
                }

                case "Url":
                {
                    server.ServerUrl = val;
                    break;
                }

                case "Default":
                {
                    server.DefaultServer = val != "0" && val.ToLower() != "false";
                    break;
                }
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Updates the internal state of the tester.  This should be called as frequently as possible.
        /// </summary>
        public void Update()
        {
            if (this.IsDone || m_TestState == TestState.Uninitalized)
            {
                return;
            }

            // nothing to be done while waiting for a callback
            if (m_WaitingForStartCallback || m_WaitingForStopCallback)
            {
                return;
            }

            switch (m_TestState)
            {
                case TestState.Starting:
                case TestState.DoneTestingServer:
                {
                    // cleanup the previous server test
                    if (m_CurrentServer != null)
                    {
                        if (m_SkipServer || !m_ServerTestSucceeded)
                        {
                            m_CurrentServer.BitrateKbps = 0;
                        }

                        StopServerTest(m_CurrentServer);
                    }
                    // start the next test
                    else
                    {
                        m_Timer.Stop();
                        m_Timer.Reset();
                        m_SkipServer = false;
                        m_ServerTestSucceeded = true;

                        if (m_TestState != TestState.Starting)
                        {
                            m_CurrentServerIndex++;
                        }

                        // start the next server test
                        if (m_CurrentServerIndex < m_IngestList.Length)
                        {
                            m_CurrentServer = m_IngestList[m_CurrentServerIndex];
                            StartServerTest(m_CurrentServer);
                        }
                        // done testing all servers
                        else
                        {
                            SetTestState(TestState.Finished);
                        }
                    }

                    break;
                }
                case TestState.ConnectingToServer:
                case TestState.TestingServer:
                {
                    UpdateServerTest(m_CurrentServer);
                    break;
                }
                case TestState.Cancelling:
                {
                    SetTestState(TestState.Cancelled);
                    break;
                }
                default:
                {
                    break;
                }
            }

            UpdateProgress();

            // test finished
            if (m_TestState == TestState.Cancelled || m_TestState == TestState.Finished)
            {
                Cleanup();
            }
        }
        void IStreamCallbacks.GetIngestServersCallback(ErrorCode result, IngestList ingestList)
        {
            if (Error.Succeeded(result))
            {
                m_IngestList = ingestList;

                // assume we're going to use the default ingest server unless overidden by the client
                m_IngestServer = m_IngestList.DefaultServer;

                SetBroadcastState(BroadcastState.ReceivedIngestServers);

                try
                {
                    if (IngestListReceived != null)
                    {
                        IngestListReceived(ingestList);
                    }
                }
                catch (Exception x)
                {
                    ReportError(x.ToString());
                }
            }
            else
            {
                string err = Error.GetString(result);
                ReportError(string.Format("IngestListCallback got failure: {0}", err));

                // try again
                SetBroadcastState(BroadcastState.LoggedIn);
            }
        }
Beispiel #10
0
        protected bool UpdateServerTest(IngestServer server)
        {
            if (m_SkipServer || m_Timer.ElapsedMilliseconds >= m_TestDurationMilliseconds)
            {
                SetTestState(TestState.DoneTestingServer);
                return true;
            }

            // not started yet
            if (m_WaitingForStartStopCallback)
            {
                return true;
            }

            ErrorCode ret = m_Stream.SubmitVideoFrame(m_IngestBuffers[m_BufferIndex]);
            if (Error.Failed(ret))
            {
                m_ServerTestSucceeded = false;
                SetTestState(TestState.DoneTestingServer);
                return false;
            }

            m_BufferIndex = (m_BufferIndex + 1) % m_IngestBuffers.Count;

            m_Stream.PollStats();

            // connected and sending video
            if (m_RTMPState == RTMPState.SendVideo)
            {
                SetTestState(TestState.TestingServer);

                long elapsed = m_Timer.ElapsedMilliseconds;
                if (elapsed > 0 && m_TotalSent > m_LastTotalSent)
                {
                    server.BitrateKbps = (float)(m_TotalSent * 8) / (float)(m_Timer.ElapsedMilliseconds);
                    m_LastTotalSent = m_TotalSent;
                }
            }

            return true;
        }
Beispiel #11
0
 internal IngestTester(Stream stream, IngestServer[] ingestList)
 {
     m_Stream = stream;
     m_IngestList = ingestList;
 }
Beispiel #12
0
        protected bool StartServerTest(IngestServer server)
        {
            // reset the test
            m_ServerTestSucceeded = true;
            m_TotalSent = 0;
            m_RTMPState = RTMPState.Idle;
            m_CurrentServer = server;

            // start the stream asynchronously
            SetTestState(TestState.ConnectingToServer);
            m_WaitingForStartStopCallback = true;
            ErrorCode ret = m_Stream.Start(m_IngestTestVideoParams, m_IngestTestAudioParams, server, StartFlags.TTV_Start_BandwidthTest, k_AsyncStartStop);
            if (Error.Failed(ret))
            {
                m_ServerTestSucceeded = false;
                SetTestState(TestState.DoneTestingServer);
                return false;
            }

            // the amount of data sent before the test of this server starts
            m_LastTotalSent = m_TotalSent;

            server.BitrateKbps = 0;
            m_BufferIndex = 0;

            return true;
        }
Beispiel #13
0
        protected void CleanupServerTest(IngestServer server)
        {
            m_WaitingForStartStopCallback = true;
            m_Stream.Stop(k_AsyncStartStop);

            m_Stream.PollStats();
        }
Beispiel #14
0
        protected void Cleanup()
        {
            m_CurrentServer = null;

            // free the buffers
            if (m_IngestBuffers != null)
            {
                for (int i = 0; i < m_IngestBuffers.Count; ++i)
                {
                    m_Stream.FreeFrameBuffer(m_IngestBuffers[i]);
                }

                m_IngestBuffers = null;
            }

            if (m_Stream.StatCallbacks == this)
            {
                m_Stream.StatCallbacks = m_PreviousStatCallbacks;
                m_PreviousStatCallbacks = null;
            }

            if (m_Stream.StreamCallbacks == this)
            {
                m_Stream.StreamCallbacks = m_PreviousStreamCallbacks;
                m_PreviousStreamCallbacks = null;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Updates the internal state of the tester.  This should be called as frequently as possible.
        /// </summary>
        public void Update()
        {
            if (this.IsDone || m_TestState == TestState.Uninitalized)
            {
                return;
            }

            if (m_WaitingForStartStopCallback)
            {
                return;
            }

            if (m_CancelTest)
            {
                SetTestState(TestState.Cancelled);
            }

            switch (m_TestState)
            {
                case TestState.Starting:
                case TestState.DoneTestingServer:
                {
                    // cleanup the previous server test
                    if (m_CurrentServer != null)
                    {
                        if (m_SkipServer || !m_ServerTestSucceeded)
                        {
                            m_CurrentServer.BitrateKbps = 0;
                        }

                        CleanupServerTest(m_CurrentServer);
                        m_CurrentServer = null;
                    }
                    // wait for the stop to complete before starting the next server
                    else if (!m_WaitingForStartStopCallback &&
                             m_Timer.ElapsedMilliseconds >= m_DelayBetweenServerTestsMilliseconds)
                    {
                        m_Timer.Stop();

                        m_SkipServer = false;
                        m_ServerTestSucceeded = true;

                        if (m_TestState != TestState.Starting)
                        {
                            m_CurrentServerIndex++;
                        }

                        // start the next server test
                        if (m_CurrentServerIndex < m_IngestList.Length)
                        {
                            m_CurrentServer = m_IngestList[m_CurrentServerIndex];
                            StartServerTest(m_CurrentServer);
                        }
                        // done testing all servers
                        else
                        {
                            SetTestState(TestState.Finished);
                        }
                    }

                    break;
                }
                case TestState.ConnectingToServer:
                case TestState.TestingServer:
                {
                    UpdateServerTest(m_CurrentServer);
                    break;
                }
                default:
                {
                    break;
                }
            }

            UpdateProgress();

            // test finished
            if (m_TestState == TestState.Cancelled || m_TestState == TestState.Finished)
            {
                if (m_CurrentServer != null)
                {
                    if (m_TestState == TestState.Cancelled)
                    {
                        m_CurrentServer.BitrateKbps = 0;
                    }

                    CleanupServerTest(m_CurrentServer);
                    m_CurrentServer = null;
                }

                if (m_IngestBuffers != null)
                {
                    Cleanup();
                }
            }
        }
Beispiel #16
0
 internal IngestTester(BroadcastApi stream, IngestServer[] ingestList)
 {
     m_Stream = stream;
     m_IngestList = ingestList;
 }
Beispiel #17
0
        protected void StopServerTest(IngestServer server)
        {
            if (m_WaitingForStartCallback)
            {
                // wait for the start callback and do the stop after that comes in
                m_SkipServer = true;
            }
            else if (m_Broadcasting)
            {
                m_WaitingForStopCallback = true;

                ErrorCode ec = m_Stream.Stop(true);
                if (Error.Failed(ec))
                {
                    // this should never happen so fake the callback to indicate it's stopped
                    (m_StreamCallbackListener as IBroadcastApiListener).StopCallback(ErrorCode.TTV_EC_SUCCESS);

                    System.Diagnostics.Debug.WriteLine("Stop failed: " + ec.ToString());
                }

                m_Stream.PollStats();
            }
            else
            {
                // simulate a stop callback
                (m_StreamCallbackListener as IBroadcastApiListener).StopCallback(ErrorCode.TTV_EC_SUCCESS);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Updates the internal state of the tester.  This should be called as frequently as possible.
        /// </summary>
        public void Update()
        {
            if (this.IsDone || m_TestState == TestState.Uninitalized)
            {
                return;
            }

            // nothing to be done while waiting for a callback
            if (m_WaitingForStartCallback || m_WaitingForStopCallback)
            {
                return;
            }

            switch (m_TestState)
            {
            case TestState.Starting:
            case TestState.DoneTestingServer:
            {
                // cleanup the previous server test
                if (m_CurrentServer != null)
                {
                    if (m_SkipServer || !m_ServerTestSucceeded)
                    {
                        m_CurrentServer.BitrateKbps = 0;
                    }

                    StopServerTest(m_CurrentServer);
                }
                // start the next test
                else
                {
                    m_Timer.Stop();
                    m_Timer.Reset();
                    m_SkipServer          = false;
                    m_ServerTestSucceeded = true;

                    if (m_TestState != TestState.Starting)
                    {
                        m_CurrentServerIndex++;
                    }

                    // start the next server test
                    if (m_CurrentServerIndex < m_IngestList.Length)
                    {
                        m_CurrentServer = m_IngestList[m_CurrentServerIndex];
                        StartServerTest(m_CurrentServer);
                    }
                    // done testing all servers
                    else
                    {
                        SetTestState(TestState.Finished);
                    }
                }

                break;
            }

            case TestState.ConnectingToServer:
            case TestState.TestingServer:
            {
                UpdateServerTest(m_CurrentServer);
                break;
            }

            case TestState.Cancelling:
            {
                SetTestState(TestState.Cancelled);
                break;
            }

            default:
            {
                break;
            }
            }

            UpdateProgress();

            // test finished
            if (m_TestState == TestState.Cancelled || m_TestState == TestState.Finished)
            {
                Cleanup();
            }
        }
Beispiel #19
0
        /// <summary>
        /// Updates the internal state of the tester.  This should be called as frequently as possible.
        /// </summary>
        public void Update()
        {
            if (this.IsDone || m_TestState == TestState.Uninitalized)
            {
                return;
            }

            if (m_WaitingForStartStopCallback)
            {
                return;
            }

            if (m_CancelTest)
            {
                SetTestState(TestState.Cancelled);
            }

            switch (m_TestState)
            {
            case TestState.Starting:
            case TestState.DoneTestingServer:
            {
                // cleanup the previous server test
                if (m_CurrentServer != null)
                {
                    if (m_SkipServer || !m_ServerTestSucceeded)
                    {
                        m_CurrentServer.BitrateKbps = 0;
                    }

                    CleanupServerTest(m_CurrentServer);
                    m_CurrentServer = null;
                }
                // wait for the stop to complete before starting the next server
                else if (!m_WaitingForStartStopCallback &&
                         m_Timer.ElapsedMilliseconds >= m_DelayBetweenServerTestsMilliseconds)
                {
                    m_Timer.Stop();

                    m_SkipServer          = false;
                    m_ServerTestSucceeded = true;

                    if (m_TestState != TestState.Starting)
                    {
                        m_CurrentServerIndex++;
                    }

                    // start the next server test
                    if (m_CurrentServerIndex < m_IngestList.Length)
                    {
                        m_CurrentServer = m_IngestList[m_CurrentServerIndex];
                        StartServerTest(m_CurrentServer);
                    }
                    // done testing all servers
                    else
                    {
                        SetTestState(TestState.Finished);
                    }
                }

                break;
            }

            case TestState.ConnectingToServer:
            case TestState.TestingServer:
            {
                UpdateServerTest(m_CurrentServer);
                break;
            }

            default:
            {
                break;
            }
            }

            UpdateProgress();

            // test finished
            if (m_TestState == TestState.Cancelled || m_TestState == TestState.Finished)
            {
                if (m_CurrentServer != null)
                {
                    if (m_TestState == TestState.Cancelled)
                    {
                        m_CurrentServer.BitrateKbps = 0;
                    }

                    CleanupServerTest(m_CurrentServer);
                    m_CurrentServer = null;
                }

                if (m_IngestBuffers != null)
                {
                    Cleanup();
                }
            }
        }