int NdnRtcNamespace::trimDataTypeComponent(const ndn::Name &prefix, Name &trimmedPrefix) { trimmedPrefix = prefix; if (getPacketNumber(prefix) == -1) return -1; int p = -1; if (isParitySegmentPrefix(prefix)) { p = findComponent(prefix, NameComponentFrameSegmentParity); } else { p = findComponent(prefix, NameComponentFrameSegmentData); } if (p > 0) { trimmedPrefix = prefix.getSubName(0, p); } return p; }
int NdnRtcNamespace::trimSegmentNumber(const ndn::Name &prefix, Name &trimmedPrefix) { trimmedPrefix = prefix; if (getSegmentNumber(prefix) == -1) return -1; int p = -1; if (isDeltaFramesPrefix(prefix)) { p = findComponent(prefix, NameComponentStreamFramesDelta); } else if (isKeyFramePrefix(prefix)) { p = findComponent(prefix, NameComponentStreamFramesKey); } if (p > 0 && p+3 < prefix.size()) { p += 3; trimmedPrefix = prefix.getSubName(0, p); } return p; }
void VideoStreamImpl::publishManifest(ndn::Name dataName, PublishedDataPtrVector &segments) { Manifest m(segments); dataName.append(NameComponents::NameComponentManifest).appendVersion(0); PublishedDataPtrVector ss = metadataPublisher_->publish(dataName, m); LogDebugC << (busyPublishing_ == 1 ? "⤷" : "↓") << " published manifest ☆ (" << dataName.getSubName(-5, 5) << ")x" << ss.size() << std::endl; }
void SyncLogicHandler::processUpdateFromSync(const ndn::Name& updateName, uint64_t seqNo, Nlsr& pnlsr) { string chkString("LSA"); int32_t lasPosition = util::getNameComponentPosition(updateName, chkString); if (lasPosition >= 0) { ndn::Name routerName = updateName.getSubName(lasPosition + 1); processRoutingUpdateFromSync(routerName, seqNo, pnlsr); return; } }
bool NameComponents::extractInfo(const ndn::Name& name, NamespaceInfo& info) { bool goodName = false; static Name ndnrtcSubName(NameComponents::NameComponentApp); Name subName; int i; for (i = name.size()-2; i > 0 && !goodName; --i) { subName = name.getSubName(i); goodName = ndnrtcSubName.match(subName); } if (goodName) { info.basePrefix_ = name.getSubName(0, i+1); if ((goodName = subName[1].isVersion())) { info.apiVersion_ = subName[1].toVersion(); if (subName.size() > 2 && (goodName = (subName[2] == Name::Component(NameComponents::NameComponentAudio) || subName[2] == Name::Component(NameComponents::NameComponentVideo))) ) { info.streamType_ = (subName[2] == Name::Component(NameComponents::NameComponentAudio) ? MediaStreamParams::MediaStreamType::MediaStreamTypeAudio : MediaStreamParams::MediaStreamType::MediaStreamTypeVideo ); if (info.streamType_ == MediaStreamParams::MediaStreamType::MediaStreamTypeAudio) return extractAudioStreamInfo(subName.getSubName(3), info); else return extractVideoStreamInfo(subName.getSubName(3), info); } } } return false; }
bool NdnRtcNamespace::trimmedLookupPrefix(const ndn::Name &prefix, ndn::Name &trimmedPrefix) { trimmedPrefix = prefix; bool res = false; std::string prefixString = prefix.toUri(); int n1 = prefixString.find(NameComponentUserStreams); int n2 = prefixString.find(NameComponentStreamFrames); int n3 = prefixString.find(NameComponentStreamFramesKey); int n4 = prefixString.find(NameComponentStreamFramesDelta); if (!(n1 == n2 == n3 == n4) && n1 >= 0 && n1 < n2 && (n2 < n3 || n2 < n4)) { int p1 = prefixString.find(NameComponentFrameSegmentData); int p2 = prefixString.find(NameComponentFrameSegmentParity); if (!(p1 == p2)) { int p = -1; if (p1 == std::string::npos) p = findComponent(prefix, NameComponentFrameSegmentParity); else p = findComponent(prefix, NameComponentFrameSegmentData); trimmedPrefix = prefix.getSubName(0, p); } res = true; } return res; }
int NdnRtcNamespace::trimPacketNumber(const ndn::Name &prefix, Name &trimmedPrefix) { trimmedPrefix = prefix; int p = -1; if (isDeltaFramesPrefix(prefix)) { p = findComponent(prefix, NameComponentStreamFramesDelta); } else if (isKeyFramePrefix(prefix)) { p = findComponent(prefix, NameComponentStreamFramesKey); } if (p > 0) { p += 1; trimmedPrefix = prefix.getSubName(0, p); } return p; }
bool extractAudioStreamInfo(const ndn::Name& name, NamespaceInfo& info) { if (name.size() == 1) { info.streamName_ = name[0].toEscapedString(); return true; } if (name.size() == 2 && name[1].isTimestamp()) { info.streamName_ = name[0].toEscapedString(); info.streamTimestamp_ = name[1].toTimestamp(); return true; } if (name.size() < 2) return false; int idx = 0; info.streamName_ = name[idx++].toEscapedString(); info.isMeta_ = (name[idx++] == Name::Component(NameComponents::NameComponentMeta)); if (info.isMeta_) { info.segmentClass_ = SegmentClass::Meta; if (name.size() < idx+1) return false; info.threadName_ = ""; return extractMeta(name.getSubName(idx), info);; } else { info.class_ = SampleClass::Unknown; info.segmentClass_ = SegmentClass::Unknown; info.streamTimestamp_ = name[idx-1].toTimestamp(); info.threadName_ = name[idx++].toEscapedString(); if (name.size() == 3) { info.hasSeqNo_ = false; return true; } info.isMeta_ = (name[idx] == Name::Component(NameComponents::NameComponentMeta)); if (info.isMeta_) { info.segmentClass_ = SegmentClass::Meta; if (name.size() > idx+1 && extractMeta(name.getSubName(idx+1), info)) return true; return false; } info.isDelta_ = true; info.class_ = SampleClass::Delta; try { if (name.size() > 3) info.sampleNo_ = (PacketNumber)name[idx++].toSequenceNumber(); info.hasSeqNo_ = true; if (name.size() > idx) { if (name[idx] == Name::Component(NameComponents::NameComponentManifest)) info.segmentClass_ = SegmentClass::Manifest; else { info.hasSegNo_ = true; info.segmentClass_ = SegmentClass::Data; info.segNo_ = name[idx].toSegment(); } return true; } else { info.hasSegNo_ = false; return true; } } catch (std::runtime_error& e) { return false; } } return false; }
bool extractVideoStreamInfo(const ndn::Name& name, NamespaceInfo& info) { if (name.size() == 1) { info.streamName_ = name[0].toEscapedString(); return true; } if (name.size() == 2 && name[1].isTimestamp()) { info.streamName_ = name[0].toEscapedString(); info.streamTimestamp_ = name[1].toTimestamp(); return true; } if (name.size() < 3) return false; int idx = 0; info.streamName_ = name[idx++].toEscapedString(); info.isMeta_ = (name[idx++] == Name::Component(NameComponents::NameComponentMeta)); if (info.isMeta_) { // example: name == camera/_meta/%FD%05/%00%00 info.segmentClass_ = SegmentClass::Meta; info.threadName_ = ""; return extractMeta(name.getSubName(idx), info); } else { // example: name == camera/%FC%00%00%01c_%27%DE%D6/hi/d/%FE%07/%00%00 info.class_ = SampleClass::Unknown; info.segmentClass_ = SegmentClass::Unknown; info.streamTimestamp_ = name[idx-1].toTimestamp(); info.threadName_ = name[idx++].toEscapedString(); if (name.size() <= idx) return true; info.isMeta_ = (name[idx++] == Name::Component(NameComponents::NameComponentMeta)); if (info.isMeta_) { // example: camera/%FC%00%00%01c_%27%DE%D6/hi/_meta/%FD%05/%00%00 info.segmentClass_ = SegmentClass::Meta; if(name.size() > idx-1 && extractMeta(name.getSubName(idx), info)) return true; return false; } if (name[idx-1] == Name::Component(NameComponents::NameComponentDelta) || name[idx-1] == Name::Component(NameComponents::NameComponentKey)) { info.isDelta_ = (name[idx-1] == Name::Component(NameComponents::NameComponentDelta)); info.class_ = (info.isDelta_ ? SampleClass::Delta : SampleClass::Key); try{ if (name.size() > idx) info.sampleNo_ = (PacketNumber)name[idx++].toSequenceNumber(); else { info.hasSeqNo_ = false; return true; } info.hasSeqNo_ = true; if (name.size() > idx) { info.isParity_ = (name[idx] == Name::Component(NameComponents::NameComponentParity)); info.hasSegNo_ = true; if (info.isParity_ && name.size() > idx+1) { info.segmentClass_ = SegmentClass::Parity; info.segNo_ = name[idx+1].toSegment(); return true; } else { if (info.isParity_) return false; else { if (name[idx] == Name::Component(NameComponents::NameComponentManifest)) info.segmentClass_ = SegmentClass::Manifest; else { info.segmentClass_ = SegmentClass::Data; info.segNo_ = name[idx].toSegment(); } } return true; } } else { info.segmentClass_ = SegmentClass::Unknown; info.hasSegNo_ = false; return true; } } catch (std::runtime_error& e) { return false; } } } return false; }