bool StreamMonitor::Init(Variant &configuration) { if (configuration.HasKeyChain(V_STRING, false, 1, "monitorPath")) { _monitorPath = (string) configuration.GetValue("monitorPath", false); } if (configuration.HasKeyChain(V_STRING, false, 1, "speedPath")) { _speedPath = (string) configuration.GetValue("speedPath", false); } return OpenMonitorFile() && OpenSpeedFile(); }
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; if (track.HasKeyChain(V_UINT32, false, 1, SDP_B)) SDP_TRACK_BANDWIDTH(result) = track[SDP_B]; else SDP_TRACK_BANDWIDTH(result) = (uint32_t) 0; //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; }