bool InboundRTMPSDiscriminatorProtocol::BindSSL(IOBuffer &buffer) { //1. Create the RTMP protocol BaseProtocol *pRTMP = new InboundRTMPProtocol(); if (!pRTMP->Initialize(GetCustomParameters())) { FATAL("Unable to create RTMP protocol"); pRTMP->EnqueueForDelete(); return false; } //2. Destroy the link BaseProtocol *pFar = _pFarProtocol; pFar->ResetNearProtocol(); ResetFarProtocol(); //3. Create the new links pFar->SetNearProtocol(pRTMP); pRTMP->SetFarProtocol(pFar); //4. Set the application pRTMP->SetApplication(GetApplication()); //5. Enqueue for delete this protocol EnqueueForDelete(); //6. Process the data if (!pRTMP->SignalInputData(buffer)) { FATAL("Unable to process data"); pRTMP->EnqueueForDelete(); } return true; }
BaseProtocol *InboundHTTP4RTMP::Bind(string sid) { BaseProtocol *pResult = NULL; if (_pNearProtocol == NULL) { //14. This might be a new connection. Do we have that sid generated? if (!MAP_HAS1(_generatedSids, sid)) { FATAL("Invalid sid: %s", STR(sid)); return false; } //15. See if we have to generate a new connection or we just pick up //a disconnected one if (MAP_HAS1(_protocolsBySid, sid)) { pResult = ProtocolManager::GetProtocol(_protocolsBySid[sid]); } else { pResult = new InboundRTMPProtocol(); pResult->Initialize(GetCustomParameters()); pResult->SetApplication(GetApplication()); _protocolsBySid[sid] = pResult->GetId(); SetNearProtocol(pResult); pResult->SetFarProtocol(this); } } else { pResult = _pNearProtocol; } return pResult; }
BaseProtocol *ProtocolFactory::SpawnProtocol(uint64_t type, Variant ¶meters) { BaseProtocol *pResult = NULL; switch (type) { #ifdef HAS_MS_TIMER case PT_FINE_TIMER: pResult = new FineTimer(); break; #endif /* HAS_MS_TIMER */ case PT_INBOUND_MASTER_M3U8: pResult = new MasterM3U8Protocol(); break; case PT_INBOUND_CHILD_M3U8: pResult = new ChildM3U8Protocol(); break; case PT_INBOUND_KEY: pResult = new InboundKeyProtocol(); break; case PT_HTTP_BUFF: pResult = new HTTPBufferProtocol(); break; case PT_INBOUND_AES: pResult = new InboundAESProtocol(); break; default: FATAL("Spawning protocol %s not yet implemented", STR(tagToString(type))); break; } if (pResult != NULL) { if (!pResult->Initialize(parameters)) { FATAL("Unable to initialize protocol %s", STR(tagToString(type))); delete pResult; pResult = NULL; } } return pResult; }
BaseProtocol *DefaultProtocolFactory::SpawnProtocol(uint64_t type, Variant ¶meters) { BaseProtocol *pResult = NULL; switch (type) { case PT_TCP: pResult = new TCPProtocol(); break; case PT_UDP: pResult = new UDPProtocol(); break; case PT_INBOUND_SSL: pResult = new InboundSSLProtocol(); break; case PT_OUTBOUND_SSL: pResult = new OutboundSSLProtocol(); break; #ifdef HAS_PROTOCOL_DNS case PT_INBOUND_DNS: pResult = new InboundDNSResolverProtocol(); break; case PT_OUTBOUND_DNS: pResult = new OutboundDNSResolverProtocol(); break; #endif /* HAS_PROTOCOL_DNS */ #ifdef HAS_PROTOCOL_RTMP case PT_INBOUND_RTMP: pResult = new InboundRTMPProtocol(); break; case PT_INBOUND_RTMPS_DISC: pResult = new InboundRTMPSDiscriminatorProtocol(); break; case PT_OUTBOUND_RTMP: pResult = new OutboundRTMPProtocol(); break; #ifdef HAS_PROTOCOL_HTTP case PT_INBOUND_HTTP_FOR_RTMP: pResult = new InboundHTTP4RTMP(); break; #endif /* HAS_PROTOCOL_HTTP */ #endif /* HAS_PROTOCOL_RTMP */ #ifdef HAS_PROTOCOL_TS case PT_INBOUND_TS: pResult = new InboundTSProtocol(); break; #endif /* HAS_PROTOCOL_TS */ #ifdef HAS_PROTOCOL_HTTP case PT_INBOUND_HTTP: pResult = new InboundHTTPProtocol(); break; case PT_OUTBOUND_HTTP: pResult = new OutboundHTTPProtocol(); break; #endif /* HAS_PROTOCOL_HTTP */ #ifdef HAS_PROTOCOL_LIVEFLV case PT_INBOUND_LIVE_FLV: pResult = new InboundLiveFLVProtocol(); break; #endif /* HAS_PROTOCOL_LIVEFLV */ #ifdef HAS_PROTOCOL_VAR case PT_XML_VAR: pResult = new XmlVariantProtocol(); break; case PT_BIN_VAR: pResult = new BinVariantProtocol(); break; case PT_JSON_VAR: pResult = new JsonVariantProtocol(); break; #endif /* HAS_PROTOCOL_VAR */ #ifdef HAS_PROTOCOL_RTP case PT_RTSP: pResult = new RTSPProtocol(); break; case PT_RTCP: pResult = new RTCPProtocol(); break; case PT_INBOUND_RTP: pResult = new InboundRTPProtocol(); break; case PT_RTP_NAT_TRAVERSAL: pResult = new NATTraversalProtocol(); break; #endif /* HAS_PROTOCOL_RTP */ #ifdef HAS_PROTOCOL_CLI case PT_INBOUND_JSONCLI: pResult = new InboundJSONCLIProtocol(); break; case PT_HTTP_4_CLI: pResult = new HTTP4CLIProtocol(); break; #endif /* HAS_PROTOCOL_CLI */ #ifdef HAS_PROTOCOL_MMS case PT_OUTBOUND_MMS: pResult = new MMSProtocol(); break; #endif /* HAS_PROTOCOL_MMS */ #ifdef HAS_PROTOCOL_RAWHTTPSTREAM case PT_INBOUND_RAW_HTTP_STREAM: pResult = new InboundRawHTTPStreamProtocol(); break; #endif /* HAS_PROTOCOL_RAWHTTPSTREAM */ default: FATAL("Spawning protocol %s not yet implemented", STR(tagToString(type))); break; } if (pResult != NULL) { if (!pResult->Initialize(parameters)) { FATAL("Unable to initialize protocol %s", STR(tagToString(type))); delete pResult; pResult = NULL; } } return pResult; }