use of com.att.aro.core.videoanalysis.pojo.UrlMatchDef in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method findManifest.
/**
* @param request
* @return ManifestCollection, null if not found
*/
public ManifestCollection findManifest(HttpRequestResponseInfo request) {
LOG.debug(String.format("locating manifest for|<%s>|", request.getObjUri().toString()));
if (CollectionUtils.isEmpty(manifestCollectionMap)) {
return null;
}
// initial
manifestCollectionToBeReturned = null;
identifiedManifestRequestTime = 0;
byteRangeKey = "";
double manifestReqTime = 0;
double lastManifestReqTime = 0;
for (Map<Double, ManifestCollection> innerMap : manifestCollectionMap.values()) {
for (ManifestCollection manifestCollection : innerMap.values()) {
if (manifestCollection.getManifest().getRequestTime() < request.getTimeStamp()) {
manifestReqTime = manifestCollection.getManifest().getRequestTime();
if (lastManifestReqTime == 0 || lastManifestReqTime < manifestReqTime) {
for (UrlMatchDef urlMatchDef : manifestCollection.getManifest().getMasterManifest().getSegUrlMatchDef()) {
key = buildUriNameKey(urlMatchDef, request);
// VID-TODO find #EXT-X-MAP:URI="5b3733a4-e7db-4700-975b-4e842c158274/3cec-BUMPER/02/1200K/map.mp4"
key += "|" + formatTimeKey(manifestCollection.getManifest().getRequestTime());
if (!StringUtils.isEmpty(key)) {
if (locatePatKey(segmentManifestCollectionMap, key, request, urlMatchDef) != null) {
manifestCollectionToBeReturned = manifestCollection;
lastManifestReqTime = manifestReqTime;
return manifestCollectionToBeReturned;
}
}
}
}
}
}
}
for (UrlMatchDef urlMatchDef : masterManifest.getSegUrlMatchDef()) {
key = buildUriNameKey(urlMatchDef, request);
if (StringUtils.isEmpty(key) && segmentManifestCollectionMap.selectKey("#EXT-X-BYTERANGE:") != null) {
String[] range = stringParse.parse(request.getAllHeaders(), "Range: bytes=(\\d+)-(\\d+)");
if (range != null) {
// #EXT-X-BYTERANGE:207928@0 //
String segName = String.format("#EXT-X-BYTERANGE:%.0f@%s", StringParse.stringToDouble(range[1], 0D) + 1, range[0]);
key = segmentManifestCollectionMap.selectKey(segName);
if (key.startsWith(segName)) {
key = keyMatch(request, segName, urlMatchDef);
byteRangeKey = segName;
} else {
LOG.error(String.format("Bad key match <%s> %s<>", segName, key));
key = "";
}
}
}
String key1 = StringUtils.substringBefore(key, "|");
try {
List<Entry<String, String>> tempList = segmentManifestCollectionMap.entrySet().parallelStream().filter(segmentManifestCollectionMapEntry -> segmentManifestCollectionMapEntry.getKey().contains(key)).collect(Collectors.toList());
if (tempList.size() > 1) {
tempList.stream().forEach(x -> {
manifestCollectionMap.entrySet().stream().filter(y -> y.getKey().contains(x.getValue())).forEach(y -> {
y.getValue().entrySet().stream().forEach(z -> {
if (request.getTimeStamp() > z.getKey() && z.getKey() > identifiedManifestRequestTime) {
identifiedManifestRequestTime = z.getKey();
manifestCollectionToBeReturned = z.getValue();
}
});
});
});
} else if (tempList.size() == 1 && !manifestCollectionMap.isEmpty()) {
String key = tempList.get(0).getValue();
manifestCollectionMap.entrySet().stream().filter(f -> f.getKey().endsWith(key)).forEach(outerMap -> {
outerMap.getValue().entrySet().stream().filter(f -> f.getKey() <= request.getTimeStamp() && f.getValue().getSegmentChildManifestTrie().containsKey(key1)).forEach(innerMap -> {
manifestCollectionToBeReturned = innerMap.getValue();
});
});
if (manifestCollectionToBeReturned == null) {
manifestCollectionMap.entrySet().stream().filter(f -> f.getKey().endsWith(key)).forEach(outerMap -> {
outerMap.getValue().entrySet().stream().filter(f -> f.getKey() <= request.getTimeStamp()).forEach(innerMap -> {
manifestCollectionToBeReturned = innerMap.getValue();
});
});
}
}
} catch (Exception e) {
LOG.error("Failed to locate manifestCollection: ", e);
}
if (manifestCollectionToBeReturned != null) {
break;
}
}
return manifestCollectionToBeReturned;
}
use of com.att.aro.core.videoanalysis.pojo.UrlMatchDef in project VideoOptimzer by attdevsupport.
the class ManifestBuilderHLS method prefixParentUrlToSegmentUrl.
/**
* Try to build up absolute URI for segmentUrl using parent manifest URL address
* @param segmentUrl
* @param urlMatchDef
* @param childManifest
* @return
*/
private String prefixParentUrlToSegmentUrl(String segmentUrl, UrlMatchDef urlMatchDef, ChildManifest childManifest) {
// Build reference URL and URL match definition for the segment using corresponding child manifest
if (segmentUrl.length() > 0 && segmentUrl.charAt(0) != '/') {
if (UrlMatchType.COUNT.equals(urlMatchDef.getUrlMatchType())) {
UrlMatchDef segmentManifestUrlMatchDef = defineUrlMatching(childManifest.getUriName());
if (segmentManifestUrlMatchDef.getUrlMatchLen() != 0) {
urlMatchDef.setUrlMatchLen(urlMatchDef.getUrlMatchLen() + segmentManifestUrlMatchDef.getUrlMatchLen());
segmentUrl = StringUtils.substringBeforeLast(childManifest.getUriName(), "/") + "/" + segmentUrl;
}
}
}
return segmentUrl;
}
use of com.att.aro.core.videoanalysis.pojo.UrlMatchDef in project VideoOptimzer by attdevsupport.
the class VideoStreamConstructor method locateChildManifestAndSegmentInfo.
/**
* Locate ChildManifest using keys based on multiple storage strategies, depending on Manifest & Manifest usage
*
* @param request
* @param timeStamp
* @param manifestCollection
* @return
*/
public ChildManifest locateChildManifestAndSegmentInfo(HttpRequestResponseInfo request, byte[] content, Double timeStamp, ManifestCollection manifestCollection) {
childManifest = null;
segmentInfo = null;
for (UrlMatchDef urlMatchDef : manifestCollection.getManifest().getSegUrlMatchDef()) {
String key0 = manifestBuilder.locateKey(urlMatchDef, request);
String key = genKey(key0, request, urlMatchDef);
Double timeKey = timeStamp;
if ((childManifest = manifestCollection.getTimestampChildManifestMap().get(timeKey)) != null) {
LOG.debug("childManifest :" + childManifest.dumpManifest(600));
if ((segmentInfo = childManifest.getSegmentInfoTrie().get(key)) != null) {
return childManifest;
}
}
timeKey = request.getTimeStamp();
do {
if ((timeKey = manifestCollection.getTimestampChildManifestMap().lowerKey(timeKey)) != null) {
childManifest = manifestCollection.getTimestampChildManifestMap().get(timeKey);
}
} while (timeKey != null && (segmentInfo = childManifest.getSegmentInfoTrie().get(key)) == null);
if ((childManifest = manifestCollection.getSegmentChildManifestTrie().get(key0)) != null || (childManifest = manifestCollection.getChildManifest(key0)) != null) {
boolean encoded = childManifest.getSegmentInfoTrie().size() != 0 && VideoType.DASH_ENCODEDSEGMENTLIST.equals(childManifest.getManifest().getVideoType()) ? true : false;
String brKey = buildByteRangeKey(request, encoded);
if (brKey != null) {
// As part of standard dash implementation, we assume that the segment information exists in sidx box in the fragmented mp4 received in the response of the request.
if (content != null) {
populateSegmentInformation(request, content, childManifest);
}
if ((segmentInfo = childManifest.getSegmentInfoTrie().get(brKey.toLowerCase())) == null) {
segmentInfo = childManifest.getSegmentInfoTrie().get(brKey.toUpperCase());
}
}
if (segmentInfo == null) {
if ((segmentInfo = childManifest.getSegmentInfoTrie().get(key)) == null) {
if (!encoded && brKey != null) {
Map.Entry<String, SegmentInfo> entry = childManifest.getSegmentInfoTrie().select(brKey);
if (entry.getKey().split("-")[1].equals(brKey.split("-")[1])) {
segmentInfo = entry.getValue();
}
} else {
segmentInfo = childManifest.getSegmentInfoTrie().get(key);
}
}
}
LOG.debug("childManifest: " + childManifest.getUriName() + ", URL match def: " + urlMatchDef);
if (segmentInfo != null) {
break;
}
} else if (timeStamp != null) {
childManifest = manifestCollection.getTimestampChildManifestMap().get(timeStamp);
if (childManifest == null || !childManifest.getSegmentInfoTrie().keySet().parallelStream().filter(segmentUriName -> {
return request.getObjUri().toString().contains(segmentUriName);
}).findFirst().isPresent()) {
childManifest = manifestCollection.getUriNameChildMap().entrySet().stream().filter(x -> {
return x.getValue().getSegmentInfoTrie().keySet().parallelStream().filter(segmentUriName -> {
return request.getObjUri().toString().contains(segmentUriName);
}).findFirst().isPresent();
}).findFirst().map(x -> x.getValue()).orElseGet(() -> null);
}
if (childManifest == null) {
LOG.debug("ChildManifest wasn't found for segment request: " + request.getObjUri() + ", URL match def: " + urlMatchDef);
nullSegmentInfo();
continue;
}
segmentInfo = null;
if ((segmentInfo = childManifest.getSegmentInfoTrie().get(key)) == null) {
childManifest.getSegmentInfoTrie().entrySet().stream().filter(segmentInfoEntry -> segmentInfoEntry.getKey().contains(key)).findFirst().map(segmentInfoEntry -> segmentInfo = segmentInfoEntry.getValue()).orElseGet(() -> nullSegmentInfo());
}
if (segmentInfo != null) {
break;
}
}
}
return childManifest;
}
use of com.att.aro.core.videoanalysis.pojo.UrlMatchDef in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method defineUrlMatching.
protected UrlMatchDef defineUrlMatching(String uriName) {
UrlMatchDef urlMatchDef = new UrlMatchDef();
if (uriName.startsWith("http")) {
urlMatchDef.setUrlMatchType(UrlMatchType.FULL);
} else {
String name = StringUtils.substringBeforeLast(uriName, ".");
int countSlash = StringUtils.countMatches(name, "/");
urlMatchDef.setUrlMatchLen(countSlash);
urlMatchDef.setUrlMatchType(UrlMatchType.COUNT);
urlMatchDef.setPrefix(uriName.startsWith("/"));
}
return urlMatchDef;
}
use of com.att.aro.core.videoanalysis.pojo.UrlMatchDef in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method locateChildManifest.
protected ChildManifest locateChildManifest(Manifest manifest) {
childManifest = null;
for (UrlMatchDef urlMatchDef : manifest.getMasterManifest().getSegUrlMatchDef()) {
referenceKey = Util.decodeUrlEncoding(buildUriNameKey(urlMatchDef, manifest.getRequest()));
if ((childManifest = manifestCollection.getUriNameChildMap().get(referenceKey)) == null) {
if (!CollectionUtils.isEmpty(manifestCollection.getUriNameChildMap())) {
childManifest = manifestCollection.getUriNameChildMap().entrySet().stream().filter(x -> x.getKey().contains(referenceKey)).findFirst().map(x -> x.getValue()).orElseGet(() -> null);
}
}
if (childManifest != null) {
break;
}
}
if (childManifest == null) {
// create an adhoc childManifest
childManifest = createChildManifest(manifest, "", referenceKey);
manifestCollection.addToTimestampChildManifestMap(manifest.getRequest().getTimeStamp(), childManifest);
childManifest.setVideo(false);
}
return childManifest;
}
Aggregations