use of com.att.aro.core.videoanalysis.pojo.ManifestCollection 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.ManifestCollection in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method getChildManifest.
/**
* Locate and return a ChildManifest.
*
* @param request
* @return segment number or -1 if not found
*/
public ChildManifest getChildManifest(HttpRequestResponseInfo request) {
ChildManifest childManifest;
ManifestCollection manifestCollection;
manifestCollection = findManifest(request);
childManifest = manifestCollection.getSegmentChildManifestTrie().get(buildKey(request));
if (childManifest == null) {
childManifest = manifestCollection.getSegmentChildManifestTrie().get(request.getObjUri().toString());
}
return childManifest;
}
use of com.att.aro.core.videoanalysis.pojo.ManifestCollection 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.ManifestCollection in project VideoOptimzer by attdevsupport.
the class ManifestBuilderDASH method getSegmentInfo.
/**
* Locate and return a segment number.
*
* @param request
* @return segment number or -1 if not found
*/
public SegmentInfo getSegmentInfo(HttpRequestResponseInfo request) {
ManifestCollection manifestCollection;
SegmentInfo segmentInfo = null;
String key = buildKey(request);
manifestCollection = findManifest(request);
if (manifestCollection != null) {
segmentInfo = manifestCollection.getSegmentTrie().get(key);
}
return segmentInfo;
}
use of com.att.aro.core.videoanalysis.pojo.ManifestCollection in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method switchManifestCollection.
/**
* Switch/Create a Manifest if there is no manifestCollection or key/timestamp for a manifest in manifestCollectionMap.
*
* @param tmpManifest
* @param key
* @param timestamp
*/
protected void switchManifestCollection(Manifest tmpManifest, String key, double timestamp) {
if (!manifestCollectionMap.containsKey(key)) {
manifestCollectionMap.put(key, new HashMap<Double, ManifestCollection>());
}
if ((manifestCollection = manifestCollectionMap.get(key).get(timestamp)) == null) {
tmpManifest.setManifestType(ManifestType.MASTER);
tmpManifest.setContentType(ContentType.UNKNOWN);
childManifest = null;
manifestCollection = new ManifestCollection();
manifestCollection.setManifest(tmpManifest);
masterManifest = tmpManifest;
manifestCollectionMap.get(key).put(timestamp, manifestCollection);
} else {
LOG.error(String.format("Two Manifests, same key, same timestamp : %s, %.3f\n", key, timestamp));
}
}
Aggregations