Example #1
0
Variant SDP::GetAudioTrack(uint32_t index, string uri) {
	//1. Find the track
	Variant track = GetTrack(index, "audio");
	if (track == V_NULL) {
		FATAL("Audio track index %u not found", index);
		return Variant();
	}

	//2. Prepare the info
	Variant result;
	SDP_AUDIO_SERVER_IP(result) = (*this)[SDP_SESSION][SDP_O]["address"];
	string control = track[SDP_A].GetValue("control", false);
	if (control.find("rtsp") == 0)
		SDP_AUDIO_CONTROL_URI(result) = control;
	else
		SDP_AUDIO_CONTROL_URI(result) = uri + "/" + control;
	SDP_AUDIO_CODEC(result) = track[SDP_A].GetValue("rtpmap", false)["encodingName"];
	if ((uint64_t) SDP_AUDIO_CODEC(result) != CODEC_AUDIO_AAC) {
		FATAL("The only supported audio codec is aac");
		return Variant();
	}

	SDP_AUDIO_CODEC_SETUP(result) = track[SDP_A]
			.GetValue("fmtp", false)
			.GetValue("config", false);
	SDP_TRACK_GLOBAL_INDEX(result) = SDP_TRACK_GLOBAL_INDEX(track);
	SDP_TRACK_IS_AUDIO(result) = (bool)true;

	//3. Done
	return result;
}
Example #2
0
Variant SDP::GetAudioTrack(uint32_t index, string contentBase) {
	//1. Find the track
	Variant track = GetTrack(index, "audio");
	if (track == V_NULL) {
		FATAL("Audio track index %u not found", index);
		return Variant();
	}

	//2. Prepare the info
	Variant result;
	SDP_AUDIO_SERVER_IP(result) = (*this)[SDP_SESSION][SDP_O]["address"];
	string control = track[SDP_A].GetValue("control", false);
	if (control.find("rtsp") == 0) {
		SDP_AUDIO_CONTROL_URI(result) = control;
	} else {
		if ((contentBase != "") && (contentBase[contentBase.size() - 1] != '/')) {
			contentBase += "/";
		}
		SDP_AUDIO_CONTROL_URI(result) = contentBase + control;
	}
	SDP_AUDIO_CODEC(result) = track[SDP_A].GetValue("rtpmap", false)["encodingName"];
	if ((uint64_t) SDP_AUDIO_CODEC(result) != CODEC_AUDIO_AAC) {
		FATAL("The only supported audio codec is aac");
		return Variant();
	}

	SDP_AUDIO_CODEC_SETUP(result) = track[SDP_A]
			.GetValue("fmtp", false)
			.GetValue("config", false);
	SDP_AUDIO_TRANSPORT(result) = track[SDP_A].GetValue("rtpmap", false)["encodingNameString"];
	SDP_TRACK_GLOBAL_INDEX(result) = SDP_TRACK_GLOBAL_INDEX(track);
	SDP_TRACK_IS_AUDIO(result) = (bool)true;
	if (track.HasKeyChain(V_UINT32, false, 1, SDP_B))
		SDP_TRACK_BANDWIDTH(result) = track[SDP_B];
	else
		SDP_TRACK_BANDWIDTH(result) = (uint32_t) 0;

	SDP_TRACK_CLOCKRATE(result) = track[SDP_A].GetValue("rtpmap", false)["clockRate"];
	//3. Done
	return result;
}
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);
    }