use of com.att.aro.core.videoanalysis.pojo.ChildManifest in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method createChildManifest.
protected ChildManifest createChildManifest(Manifest manifest, String parameters, String childUriName) {
childUriName = Util.decodeUrlEncoding(childUriName);
ChildManifest childManifest = new ChildManifest();
childManifest.setManifest(manifest);
childManifest.setUriName(childUriName);
childManifest.setManifestCollectionParent(manifestCollection);
manifest.getSegUrlMatchDef().add(defineUrlMatching(childUriName));
manifestCollection.addToUriNameChildMap(childUriName, childManifest);
return childManifest;
}
use of com.att.aro.core.videoanalysis.pojo.ChildManifest 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.ChildManifest in project VideoOptimzer by attdevsupport.
the class ManifestBuilderHLS method createChildManifest.
@Override
protected ChildManifest createChildManifest(Manifest manifest, String parameters, String childUriName) {
try {
childUriName = Util.decodeUrlEncoding(childUriName);
} catch (Exception e1) {
LOG.error("failed to decode childUriName:", e1);
}
ChildManifest childManifest = new ChildManifest();
childManifest.setManifestCollectionParent(manifestCollection);
childManifest.setManifest(manifest);
childManifest.setUriName(childUriName);
if (StringUtils.isNotEmpty(parameters)) {
Double bandwidth = StringParse.findLabeledDoubleFromString("BANDWIDTH=", parameters);
if (bandwidth != null) {
manifestCollection.addToBandwidthMap(bandwidth, childManifest);
childManifest.setBandwidth(bandwidth);
}
String resolution = StringParse.findLabeledDataFromString("RESOLUTION=", ",", parameters);
if (StringUtils.isNotEmpty(resolution)) {
String[] resolutionNumbers = resolution.split("[Xx]");
if (resolutionNumbers.length == 2) {
try {
childManifest.setPixelWidth(Integer.valueOf(resolutionNumbers[0]));
childManifest.setPixelHeight(Integer.valueOf(resolutionNumbers[1]));
} catch (NumberFormatException e) {
LOG.debug(String.format("failed to parse \"%s\" or \"%s\"", resolutionNumbers[0], resolutionNumbers[1]));
childManifest.setPixelWidth(0);
childManifest.setPixelHeight(0);
}
childManifest.setVideo(true);
childManifest.setContentType(ContentType.VIDEO);
}
}
String codecs = StringParse.findLabeledDataFromString("CODECS=", "\"", parameters);
childManifest.setCodecs(codecs);
if (codecs.contains(",")) {
childManifest.setVideo(true);
childManifest.setContentType(ContentType.MUXED);
} else if (codecs.contains("v")) {
childManifest.setVideo(true);
childManifest.setContentType(ContentType.VIDEO);
} else if (codecs.contains("a")) {
childManifest.setVideo(false);
childManifest.setContentType(ContentType.AUDIO);
}
}
childUriName = StringUtils.substringBefore(childUriName, "?");
manifestCollection.addToUriNameChildMap(childUriName, childManifest);
return childManifest;
}
use of com.att.aro.core.videoanalysis.pojo.ChildManifest 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.ChildManifest in project VideoOptimzer by attdevsupport.
the class VideoStreamConstructor method extractVideo.
public void extractVideo(StreamingVideoData streamingVideoData, HttpRequestResponseInfo request, Double timeStamp) {
CRC32 crc32 = new CRC32();
ChildManifest childManifest = null;
byte[] content = extractContent(request, StreamContentType.VIDEO);
if (content == null) {
return;
}
LOG.debug(String.format(">>Segment request, packetID: %d, len:%d, name:%s, TS:%.3f, URL:%s", request.getAssocReqResp().getFirstDataPacket().getPacketId(), content.length, request.getFileName(), request.getTimeStamp(), request.getObjUri()));
this.streamingVideoData = streamingVideoData;
childManifest = matchSegment(streamingVideoData, request, timeStamp, content);
if (childManifest == null) {
return;
}
String name = manifestBuilder.buildSegmentName(request, extractExtensionFromRequest(request));
crc32.update(content);
updateVideoNameSize();
byte[] thumbnail = null;
if (segmentInfo.getSegmentID() == 0 && childManifest.getManifest().isVideoFormat(VideoFormat.MPEG4)) {
childManifest.setMoovContent(content);
segmentInfo.setDuration(0);
}
if (segmentInfo.getDuration() > 0) {
double bitRate = content.length * 8 / segmentInfo.getDuration();
segmentInfo.setBitrate(bitRate / 1000);
}
VideoEvent videoEvent = new // imageArray
VideoEvent(// imageArray
thumbnail, // Manifest
manifestCollection.getManifest(), // segmentID, quality, duration
segmentInfo, // PixelHeight
childManifest, // segmentSize
content.length, // response
request.getAssocReqResp(), // crc32Value
crc32.getValue());
videoStream.addVideoEvent(videoEvent);
String fullPathName = buildPath(streamingVideoData, request, segmentInfo.getSegmentID(), segmentInfo.getQuality(), name);
int pos1 = fullPathName.lastIndexOf(Util.FILE_SEPARATOR) + 1;
int pos2 = fullPathName.substring(pos1).indexOf('_');
fullPathName = String.format("%s%09.0f%s", fullPathName.substring(0, pos1), videoEvent.getEndTS() * 1000, fullPathName.substring(pos1 + pos2));
savePayload(content, fullPathName);
videoEvent.setSegmentPathName(fullPathName);
String tempClippingFullPath = buildSegmentFullPathName(streamingVideoData, request);
if (videoEvent.isNormalSegment() && createClipping(segmentInfo, childManifest, content, tempClippingFullPath)) {
ffmpegRunner.addJob(videoEvent, tempClippingFullPath);
}
videoEvent.isDefaultThumbnail();
}
Aggregations