CSharpRTMP.Core.Protocols.Rtmp.BaseRTMPAppProtocolHandler.ProcessInvokeCreateStreamResult C# (CSharp) Method

ProcessInvokeCreateStreamResult() private method

private ProcessInvokeCreateStreamResult ( BaseRTMPProtocol pFrom, AmfMessage request, AmfMessage response ) : bool
pFrom BaseRTMPProtocol
request AmfMessage
response AmfMessage
return bool
        private bool ProcessInvokeCreateStreamResult(BaseRTMPProtocol pFrom,AmfMessage request, AmfMessage response)
        {
            //1. Do we need to push/pull a stream?
            if ((!NeedsToPullExternalStream(pFrom))
                    && (!NeedsToPushLocalStream(pFrom)))
            {
                Logger.WARN("Default implementation of ProcessInvokeCreateStreamResult: Request:\n{0}\nResponse:\n{1}",
                        request.ToString(),
                        response.ToString());

                return true;
            }

            //2. Test and see if this connection is an outbound RTMP connection
            //and get a pointer to it
            if (pFrom.Type != ProtocolTypes.PT_OUTBOUND_RTMP)
            {
                Logger.FATAL("This is not an outbound connection");
                return false;
            }
            var pProtocol = (OutboundRTMPProtocol)pFrom;

            //3. Test the response
            if (response.InvokeFunction != Defines.RM_INVOKE_FUNCTION_RESULT || response.InvokeParam[1] != VariantType.Numberic)
            {
                Logger.FATAL("createStream failed:\n{0}", response.ToString());
                return false;
            }

            //4. Get the assigned stream ID
            uint rtmpStreamId = response.InvokeParam[1];

            //5. Create the neutral stream
            var pStream = pProtocol.CreateNeutralStream(ref rtmpStreamId);
            if (pStream == null)
            {
                Logger.FATAL("Unable to create neutral stream");
                return false;
            }


            //6. Get our hands on streaming parameters
            var path = NeedsToPullExternalStream(pFrom) ? "externalStreamConfig" : "localStreamConfig";
            var parameters = pFrom.CustomParameters["customParameters"][path];

            //7. Create publish/play request
            AmfMessage publishPlayRequest;
            if (NeedsToPullExternalStream(pFrom))
            {
                publishPlayRequest = StreamMessageFactory.GetInvokePlay(3, rtmpStreamId,
                        parameters["localStreamName"], -2, -1);
            }
            else
            {
                string targetStreamType = parameters["targetStreamType"];

                if ((targetStreamType != "live")
                        && (targetStreamType != "record")
                        && (targetStreamType != "append"))
                {
                    targetStreamType = "live";
                }
                publishPlayRequest = StreamMessageFactory.GetInvokePublish(3, rtmpStreamId,
                        parameters["targetStreamName"], targetStreamType);
            }

            //8. Send it
            if (!SendRTMPMessage(pFrom, publishPlayRequest, true))
            {
                Logger.FATAL("Unable to send request:\n{0}", publishPlayRequest.ToString());
                return false;
            }

            //9. Done
            return true;
        }