Variant SDP::GetVideoTrack(uint32_t index, string uri) { //1. Find the track Variant track = GetTrack(index, "video"); if (track == V_NULL) { FATAL("Video track index %u not found", index); return Variant(); } //2. Prepare the info Variant result; SDP_VIDEO_SERVER_IP(result) = (*this)[SDP_SESSION][SDP_O]["address"]; string control = track[SDP_A].GetValue("control", false); if (control.find("rtsp") == 0) SDP_VIDEO_CONTROL_URI(result) = control; else SDP_VIDEO_CONTROL_URI(result) = uri + "/" + control; SDP_VIDEO_CODEC(result) = track[SDP_A].GetValue("rtpmap", false)["encodingName"]; if ((uint64_t) SDP_VIDEO_CODEC(result) != CODEC_VIDEO_AVC) { FATAL("The only supported video codec is h264"); return Variant(); } SDP_VIDEO_CODEC_H264_SPS(result) = track[SDP_A] .GetValue("fmtp", false) .GetValue("sprop-parameter-sets", false)["SPS"]; SDP_VIDEO_CODEC_H264_PPS(result) = track[SDP_A] .GetValue("fmtp", false) .GetValue("sprop-parameter-sets", false)["PPS"]; SDP_TRACK_GLOBAL_INDEX(result) = SDP_TRACK_GLOBAL_INDEX(track); SDP_TRACK_IS_AUDIO(result) = (bool)false; //3. Done return result; }
Variant SDP::GetVideoTrack(uint32_t index, string contentBase) { //1. Find the track Variant track = GetTrack(index, "video"); if (track == V_NULL) { FATAL("Video track index %u not found", index); return Variant(); } //2. Prepare the info Variant result; SDP_VIDEO_SERVER_IP(result) = (*this)[SDP_SESSION][SDP_O]["address"]; string control = track[SDP_A].GetValue("control", false); if (control.find("rtsp") == 0) { SDP_VIDEO_CONTROL_URI(result) = control; } else { if ((contentBase != "") && (contentBase[contentBase.size() - 1] != '/')) { contentBase += "/"; } SDP_VIDEO_CONTROL_URI(result) = contentBase + control; } SDP_VIDEO_CODEC(result) = track[SDP_A].GetValue("rtpmap", false)["encodingName"]; if ((uint64_t) SDP_VIDEO_CODEC(result) != CODEC_VIDEO_H264) { FATAL("The only supported video codec is h264"); return Variant(); } SDP_VIDEO_CODEC_H264_SPS(result) = track[SDP_A] .GetValue("fmtp", false) .GetValue("sprop-parameter-sets", false)["SPS"]; SDP_VIDEO_CODEC_H264_PPS(result) = track[SDP_A] .GetValue("fmtp", false) .GetValue("sprop-parameter-sets", false)["PPS"]; SDP_TRACK_GLOBAL_INDEX(result) = SDP_TRACK_GLOBAL_INDEX(track); SDP_TRACK_IS_AUDIO(result) = (bool)false; 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; }