Search in sources :

Example 1 with Manifest

use of com.att.aro.core.videoanalysis.pojo.Manifest in project VideoOptimzer by attdevsupport.

the class ManifestBuilder method create.

/**
 * <pre>
 * Create a Manifest object from byte[] data.
 *  if manifest is a master, a new ManifestCollection will be created to hold the masterManifest
 *  if manifest is a "child" it will be attached to it's master
 *
 * @param request - object
 * @param data - byte[]
 * @param videoPath
 * @return manifest, that was just created, master or child
 */
public Manifest create(HttpRequestResponseInfo request, byte[] data, String videoPath) {
    crc32 = new CRC32();
    manifest = new Manifest();
    manifest.setRequest(request);
    manifest.setVideoName(StringUtils.substringBefore(request.getObjNameWithoutParams(), ";"));
    manifest.setUri(request.getObjUri());
    manifest.setUriStr(request.getObjUri().toString());
    manifest.setSession(request.getAssocReqResp().getSession());
    manifest.setVideoPath(videoPath);
    manifest.setContent(data);
    crc32.update(data);
    manifest.setChecksumCRC32(crc32.getValue());
    manifest.setRequestTime(request.getTimeStamp());
    manifest.setEndTime(request.getAssocReqResp().getLastDataPacket().getTimeStamp());
    parseManifestData(manifest, data);
    return manifest;
}
Also used : CRC32(java.util.zip.CRC32) Manifest(com.att.aro.core.videoanalysis.pojo.Manifest) ChildManifest(com.att.aro.core.videoanalysis.pojo.ChildManifest)

Example 2 with Manifest

use of com.att.aro.core.videoanalysis.pojo.Manifest 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;
}
Also used : UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef) StringUtils(org.apache.commons.lang.StringUtils) VideoFormat(com.att.aro.core.videoanalysis.pojo.VideoFormat) PatriciaTrie(org.apache.commons.collections4.trie.PatriciaTrie) HashMap(java.util.HashMap) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) Logger(org.apache.log4j.Logger) ManifestCollection(com.att.aro.core.videoanalysis.pojo.ManifestCollection) Manifest(com.att.aro.core.videoanalysis.pojo.Manifest) Map(java.util.Map) IStringParse(com.att.aro.core.util.IStringParse) UrlMatchType(com.att.aro.core.videoanalysis.pojo.UrlMatchDef.UrlMatchType) StringParse(com.att.aro.core.util.StringParse) Iterator(java.util.Iterator) Util(com.att.aro.core.util.Util) NonNull(lombok.NonNull) Set(java.util.Set) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef) ContentType(com.att.aro.core.videoanalysis.pojo.Manifest.ContentType) Entry(java.util.Map.Entry) AROConfig(com.att.aro.core.AROConfig) Data(lombok.Data) CRC32(java.util.zip.CRC32) ChildManifest(com.att.aro.core.videoanalysis.pojo.ChildManifest) Pattern(java.util.regex.Pattern) LogManager(org.apache.log4j.LogManager) ManifestType(com.att.aro.core.videoanalysis.pojo.Manifest.ManifestType) ManifestCollection(com.att.aro.core.videoanalysis.pojo.ManifestCollection) Entry(java.util.Map.Entry)

Example 3 with Manifest

use of com.att.aro.core.videoanalysis.pojo.Manifest 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;
}
Also used : UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef) StringUtils(org.apache.commons.lang.StringUtils) VideoFormat(com.att.aro.core.videoanalysis.pojo.VideoFormat) SortedSet(java.util.SortedSet) IFileManager(com.att.aro.core.fileio.IFileManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Random(java.util.Random) FFmpegRunner(com.att.aro.core.videoanalysis.videoframe.FFmpegRunner) Logger(org.apache.log4j.Logger) ManifestBuilderHLS(com.att.aro.core.videoanalysis.impl.ManifestBuilderHLS) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) IStringParse(com.att.aro.core.util.IStringParse) VideoType(com.att.aro.core.videoanalysis.pojo.VideoEvent.VideoType) Path(java.nio.file.Path) HttpDirection(com.att.aro.core.packetanalysis.pojo.HttpDirection) NonNull(lombok.NonNull) Box(org.mp4parser.Box) VideoStream(com.att.aro.core.videoanalysis.pojo.VideoStream) IsoFile(org.mp4parser.IsoFile) IHttpRequestResponseHelper(com.att.aro.core.packetanalysis.IHttpRequestResponseHelper) ChildManifest(com.att.aro.core.videoanalysis.pojo.ChildManifest) Pattern(java.util.regex.Pattern) ManifestType(com.att.aro.core.videoanalysis.pojo.Manifest.ManifestType) SortedMap(java.util.SortedMap) Getter(lombok.Getter) HashMap(java.util.HashMap) ManifestBuilderDASH(com.att.aro.core.videoanalysis.impl.ManifestBuilderDASH) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) ManifestCollection(com.att.aro.core.videoanalysis.pojo.ManifestCollection) Manifest(com.att.aro.core.videoanalysis.pojo.Manifest) StringParse(com.att.aro.core.util.StringParse) Files(java.nio.file.Files) Util(com.att.aro.core.util.Util) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) ManifestBuilder(com.att.aro.core.videoanalysis.impl.ManifestBuilder) VideoEvent(com.att.aro.core.videoanalysis.pojo.VideoEvent) StreamingVideoData(com.att.aro.core.videoanalysis.pojo.StreamingVideoData) IExternalProcessRunner(com.att.aro.core.commandline.IExternalProcessRunner) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef) CRC32(java.util.zip.CRC32) SegmentInfo(com.att.aro.core.videoanalysis.impl.SegmentInfo) LogManager(org.apache.log4j.LogManager) SegmentIndexBox(org.mp4parser.boxes.iso14496.part12.SegmentIndexBox) SegmentInfo(com.att.aro.core.videoanalysis.impl.SegmentInfo) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 4 with Manifest

use of com.att.aro.core.videoanalysis.pojo.Manifest in project VideoOptimzer by attdevsupport.

the class VideoStartUpDelayImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    BPResultType bpResultType = BPResultType.SELF_TEST;
    result = new VideoStartUpDelayResult();
    init(result);
    warningValue = videoPref.getVideoUsagePreference().getStartUpDelayWarnVal();
    if ((streamingVideoData = tracedata.getStreamingVideoData()) != null && (videoStreamCollection = streamingVideoData.getVideoStreamMap()) != null && MapUtils.isNotEmpty(videoStreamCollection)) {
        selectedManifestCount = streamingVideoData.getSelectedManifestCount();
        hasSelectedManifest = (selectedManifestCount > 0);
        invalidCount = streamingVideoData.getInvalidManifestCount();
        // default startup delay
        startupDelay = videoPref.getVideoUsagePreference().getStartupDelay();
        startupDelaySet = false;
        bpResultType = BPResultType.CONFIG_REQUIRED;
        result.setResultExcelText(BPResultType.CONFIG_REQUIRED.getDescription());
        if (selectedManifestCount == 0) {
            if (invalidCount == videoStreamCollection.size()) {
                result.setResultText(invalidManifestsFound);
            } else if (invalidCount > 0) {
                result.setResultText(noManifestsSelectedMixed);
            } else {
                if (videoStreamCollection.size() > 0 && MapUtils.isEmpty(streamingVideoData.getStreamingVideoCompiled().getChunkPlayTimeList())) {
                    result.setResultText(startUpDelayNotSet);
                } else {
                    result.setResultText(noManifestsSelected);
                }
            }
        } else if (MapUtils.isEmpty(streamingVideoData.getStreamingVideoCompiled().getChunkPlayTimeList())) {
            result.setResultText(startUpDelayNotSet);
        } else if (selectedManifestCount > 1) {
            result.setResultText(multipleManifestsSelected);
        } else if (hasSelectedManifest) {
            startupDelaySet = true;
            for (VideoStream videoStream : videoStreamCollection.values()) {
                if (videoStream.isSelected() && MapUtils.isNotEmpty(videoStream.getVideoEventMap()) && videoStream.getManifest().getStartupVideoEvent() != null) {
                    Manifest manifest = videoStream.getManifest();
                    manifestRequestTime = manifest.getRequestTime();
                    // - tracedata.getTraceresult().getPcapTimeOffset();
                    manifestDeliveredTime = manifest.getEndTime() - manifestRequestTime;
                    startupDelay = manifest.getStartupDelay() - manifestRequestTime;
                    playDelay = manifest.getStartupDelay() - manifestRequestTime;
                    LOG.info(String.format("startup segment = %s", manifest.getStartupVideoEvent()));
                    LOG.info(String.format("segment startupDelay = %.03f", startupDelay));
                    LOG.info(String.format("videoStream request to segment_plays = %.03f", manifest.getStartupVideoEvent().getPlayTime() - manifestRequestTime));
                    LOG.info(String.format("segment_plays = %.03f", manifest.getStartupVideoEvent().getPlayTime()));
                    List<VideoStartup> compApps = new ArrayList<>();
                    compApps.add(new VideoStartup("RefApp 1", 0.914, 3.423));
                    compApps.add(new VideoStartup("RefApp 2", 3.27, 8.400));
                    compApps.add(new VideoStartup("RefApp 3", 2.409, 3.969));
                    VideoStartup testedApp = new VideoStartup("Tested", manifestDeliveredTime, playDelay);
                    compApps.add(testedApp);
                    result.setResults(compApps);
                    bpResultType = Util.checkPassFailorWarning(startupDelay, warningValue);
                    if (bpResultType.equals(BPResultType.PASS)) {
                        result.setResultText(MessageFormat.format(textResultPass, startupDelay, startupDelay == 1 ? "" : "s"));
                        result.setResultExcelText(BPResultType.PASS.getDescription());
                    } else {
                        result.setResultText(MessageFormat.format(textResults, String.format("%.03f", startupDelay), startupDelay == 1 ? "" : "s", String.format("%.04f", warningValue), warningValue == 1 ? "" : "s"));
                        result.setResultExcelText(MessageFormat.format(textExcelResults, bpResultType.getDescription(), String.format("%.03f", startupDelay)));
                    }
                    break;
                }
            }
        } else {
            bpResultType = BPResultType.CONFIG_REQUIRED;
            result.setResultText(novalidManifestsFound);
            result.setResultExcelText(BPResultType.CONFIG_REQUIRED.getDescription());
        }
        result.setStartUpDelay(startupDelay);
    } else {
        // No Data
        result.setResultText(noData);
        bpResultType = BPResultType.NO_DATA;
        result.setResultExcelText(BPResultType.NO_DATA.getDescription());
    }
    result.setResultType(bpResultType);
    return result;
}
Also used : VideoStartup(com.att.aro.core.videoanalysis.pojo.VideoStartup) BPResultType(com.att.aro.core.bestpractice.pojo.BPResultType) VideoStream(com.att.aro.core.videoanalysis.pojo.VideoStream) ArrayList(java.util.ArrayList) List(java.util.List) Manifest(com.att.aro.core.videoanalysis.pojo.Manifest) VideoStartUpDelayResult(com.att.aro.core.bestpractice.pojo.VideoStartUpDelayResult)

Example 5 with Manifest

use of com.att.aro.core.videoanalysis.pojo.Manifest in project VideoOptimzer by attdevsupport.

the class VideoTrafficInferencer method createManifest.

private Manifest createManifest(String manifestName, ManifestType manifestType, ContentType contentType) {
    Manifest manifestMaster = new Manifest();
    manifestMaster.setVideoName(manifestName);
    manifestMaster.setManifestType(manifestType);
    manifestMaster.setContentType(contentType);
    return manifestMaster;
}
Also used : Manifest(com.att.aro.core.videoanalysis.pojo.Manifest) VideoManifest(com.att.aro.core.video.pojo.VideoManifest) ChildManifest(com.att.aro.core.videoanalysis.pojo.ChildManifest)

Aggregations

Manifest (com.att.aro.core.videoanalysis.pojo.Manifest)8 ChildManifest (com.att.aro.core.videoanalysis.pojo.ChildManifest)7 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)3 Util (com.att.aro.core.util.Util)3 ManifestType (com.att.aro.core.videoanalysis.pojo.Manifest.ManifestType)3 UrlMatchDef (com.att.aro.core.videoanalysis.pojo.UrlMatchDef)3 VideoStream (com.att.aro.core.videoanalysis.pojo.VideoStream)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CRC32 (java.util.zip.CRC32)3 IFileManager (com.att.aro.core.fileio.IFileManager)2 HttpDirection (com.att.aro.core.packetanalysis.pojo.HttpDirection)2 IStringParse (com.att.aro.core.util.IStringParse)2 StringParse (com.att.aro.core.util.StringParse)2 VideoManifest (com.att.aro.core.video.pojo.VideoManifest)2 ManifestBuilderDASH (com.att.aro.core.videoanalysis.impl.ManifestBuilderDASH)2 ContentType (com.att.aro.core.videoanalysis.pojo.Manifest.ContentType)2 ManifestCollection (com.att.aro.core.videoanalysis.pojo.ManifestCollection)2 StreamingVideoData (com.att.aro.core.videoanalysis.pojo.StreamingVideoData)2 VideoEvent (com.att.aro.core.videoanalysis.pojo.VideoEvent)2