bool HTTP4CLIProtocol::SignalInputData(IOBuffer &buffer) { //1. Get the HTTP protocol. We are sure is a PT_INBOUND_HTTP //because we return true inside AllowFarProtocol only when type == PT_INBOUND_HTTP InboundHTTPProtocol *pHTTP = (InboundHTTPProtocol *) GetFarProtocol(); //2. Get the request headers Variant headers = pHTTP->GetHeaders(); //3. Populate the input buffer for the next protocol in the stack (PT_INBOUND_JSONCLI) //with the data we just found out inside the headers URI uri; string dummy = "http://localhost" + (string) headers[HTTP_FIRST_LINE][HTTP_URL]; FINEST("dummy: %s",STR(dummy)); if (!URI::FromString(dummy, false, uri)) { FATAL("Invalid request"); return false; } string fullCommand=uri.document; fullCommand+=" "; if(uri.parameters.size()!=0){ fullCommand+=unb64(MAP_VAL(uri.parameters.begin())); } fullCommand+="\n"; _localInputBuffer.ReadFromString(fullCommand); //4. Call the next protocol with the new buffer return GetNearProtocol()->SignalInputData(_localInputBuffer); }
bool InboundConnectivity::Initialize() { //1. get the application BaseClientApplication *pApplication = _pRTSP->GetApplication(); if (pApplication == NULL) { FATAL("RTSP protocol not yet assigned to an application"); return false; } //2. Compute the bandwidthHint uint32_t bandwidth = 0; if (_videoTrack != V_NULL) { bandwidth += (uint32_t) SDP_TRACK_BANDWIDTH(_videoTrack); } if (_audioTrack != V_NULL) { bandwidth += (uint32_t) SDP_TRACK_BANDWIDTH(_audioTrack); } if (bandwidth == 0) { bandwidth = _bandwidthHint; } //5. Create the in stream if (_streamName == "") _streamName = format("rtsp_%u", _pRTSP->GetId()); if (!pApplication->StreamNameAvailable(_streamName, _pRTSP)) { FATAL("Stream name %s already taken", STR(_streamName)); return false; } _pInStream = new InNetRTPStream(_pRTSP, pApplication->GetStreamsManager(), _streamName, _videoTrack != V_NULL ? unb64((string) SDP_VIDEO_CODEC_H264_SPS(_videoTrack)) : "", _videoTrack != V_NULL ? unb64((string) SDP_VIDEO_CODEC_H264_PPS(_videoTrack)) : "", _audioTrack != V_NULL ? unhex(SDP_AUDIO_CODEC_SETUP(_audioTrack)) : "", bandwidth, _rtcpDetectionInterval); //6. override the width/height with the values in session (if any) Variant &session = _pRTSP->GetCustomParameters(); if ((session.HasKeyChain(_V_NUMERIC, true, 3, "customParameters", "externalStreamConfig", "width")) && (session.HasKeyChain(_V_NUMERIC, true, 3, "customParameters", "externalStreamConfig", "height"))) { StreamCapabilities *pCap = _pInStream->GetCapabilities(); if (pCap->videoCodecId == CODEC_VIDEO_AVC) { pCap->avc._widthOverride = (uint32_t) session["customParameters"]["externalStreamConfig"]["width"]; pCap->avc._heightOverride = (uint32_t) session["customParameters"]["externalStreamConfig"]["height"]; } } // pCap->avc._widthOverride=session["width"]; // pCap->avc._widthOverride=session[""]; //6. make the stream known to inbound RTP protocols //and plug in the connectivity if (_pRTPVideo != NULL) { _pRTPVideo->SetStream(_pInStream, false); _pRTPVideo->SetInbboundConnectivity(this); _pRTCPVideo->SetInbboundConnectivity(this, false); } if (_pRTPAudio != NULL) { _pRTPAudio->SetStream(_pInStream, true); _pRTPAudio->SetInbboundConnectivity(this); _pRTCPAudio->SetInbboundConnectivity(this, true); } //7. Pickup all outbound waiting streams map<uint32_t, BaseOutStream *> subscribedOutStreams = pApplication->GetStreamsManager()->GetWaitingSubscribers( _streamName, _pInStream->GetType(), true); //FINEST("subscribedOutStreams count: %"PRIz"u", subscribedOutStreams.size()); //8. Bind the waiting subscribers FOR_MAP(subscribedOutStreams, uint32_t, BaseOutStream *, i) { BaseOutStream *pBaseOutStream = MAP_VAL(i); pBaseOutStream->Link(_pInStream); }
void CommonTestsSuite::test_unb64() { TS_ASSERT(unb64("dGhpcyBpcyBhIHRlc3Qx") == "this is a test1"); TS_ASSERT(unb64("dGhpcyBpcyBhIHRlc3Q=") == "this is a test"); TS_ASSERT(unb64("dGhpcyBpcyBhIHRlcw==") == "this is a tes"); TS_ASSERT(unb64("") == ""); }
string unb64(string source) { return unb64((uint8_t *) STR(source), source.length()); }