Search in sources :

Example 1 with ChildManifest

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

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

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

Example 4 with 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;
}
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 5 with 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();
}
Also used : CRC32(java.util.zip.CRC32) ChildManifest(com.att.aro.core.videoanalysis.pojo.ChildManifest) VideoEvent(com.att.aro.core.videoanalysis.pojo.VideoEvent)

Aggregations

ChildManifest (com.att.aro.core.videoanalysis.pojo.ChildManifest)7 VideoEvent (com.att.aro.core.videoanalysis.pojo.VideoEvent)3 IFileManager (com.att.aro.core.fileio.IFileManager)2 HttpDirection (com.att.aro.core.packetanalysis.pojo.HttpDirection)2 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)2 Util (com.att.aro.core.util.Util)2 ManifestBuilderDASH (com.att.aro.core.videoanalysis.impl.ManifestBuilderDASH)2 Manifest (com.att.aro.core.videoanalysis.pojo.Manifest)2 ManifestType (com.att.aro.core.videoanalysis.pojo.Manifest.ManifestType)2 ManifestCollection (com.att.aro.core.videoanalysis.pojo.ManifestCollection)2 StreamingVideoData (com.att.aro.core.videoanalysis.pojo.StreamingVideoData)2 VideoStream (com.att.aro.core.videoanalysis.pojo.VideoStream)2 File (java.io.File)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2