Search in sources :

Example 1 with UrlMatchDef

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;
}
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 2 with UrlMatchDef

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;
}
Also used : UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef)

Example 3 with UrlMatchDef

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;
}
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 UrlMatchDef

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;
}
Also used : UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef)

Example 5 with 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;
}
Also used : UrlMatchDef(com.att.aro.core.videoanalysis.pojo.UrlMatchDef)

Aggregations

UrlMatchDef (com.att.aro.core.videoanalysis.pojo.UrlMatchDef)7 ChildManifest (com.att.aro.core.videoanalysis.pojo.ChildManifest)3 Manifest (com.att.aro.core.videoanalysis.pojo.Manifest)3 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)2 IStringParse (com.att.aro.core.util.IStringParse)2 StringParse (com.att.aro.core.util.StringParse)2 Util (com.att.aro.core.util.Util)2 ContentType (com.att.aro.core.videoanalysis.pojo.Manifest.ContentType)2 ManifestType (com.att.aro.core.videoanalysis.pojo.Manifest.ManifestType)2 ManifestCollection (com.att.aro.core.videoanalysis.pojo.ManifestCollection)2 VideoFormat (com.att.aro.core.videoanalysis.pojo.VideoFormat)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Pattern (java.util.regex.Pattern)2 CRC32 (java.util.zip.CRC32)2 NonNull (lombok.NonNull)2 StringUtils (org.apache.commons.lang.StringUtils)2 LogManager (org.apache.log4j.LogManager)2 Logger (org.apache.log4j.Logger)2 AROConfig (com.att.aro.core.AROConfig)1