Search in sources :

Example 1 with MPDEncodedSegment

use of com.att.aro.core.videoanalysis.parsers.encodedsegment.MPDEncodedSegment in project VideoOptimzer by attdevsupport.

the class ManifestBuilderDASH method processEncodedSegment.

public void processEncodedSegment(Manifest newManifest, XmlManifestHelper manifestView, String key) {
    // DASH-VOD EncodedSegmentList
    switchManifestCollection(newManifest, key, manifest.getRequestTime());
    newManifest.setVideoType(VideoType.DASH_ENCODEDSEGMENTLIST);
    MPDEncodedSegment mpdEncodedSegment = (MPDEncodedSegment) manifestView.getManifest();
    DashEncodedSegmentParser dashEncodedSegmentParser = new DashEncodedSegmentParser(mpdEncodedSegment, newManifest, manifestCollection, childManifest);
    List<AdaptationSetESL> adaptationSetList = dashEncodedSegmentParser.getAdaptationSet();
    String[] encodedSegmentDurationList = null;
    Double segmentTimeScale = null;
    /* 
		 * Sort Adaptations by minBandwidth, for the purpose of assigning track numbers.
		 * Video tracks will start with track 0
		 * Audio tracks will start with track 0, also
		 */
    SortedMap<Double, AdaptationSetESL> sortedAdaptationSet;
    Map<String, SortedMap<Double, AdaptationSetESL>> sortedAdaptationSets = new HashMap<>();
    Map<String, Integer> trackMap = new HashMap<>();
    Integer track;
    Double bandWidth;
    for (AdaptationSetESL adaptation : adaptationSetList) {
        List<RepresentationESL> representation = adaptation.getRepresentation();
        if (sortedAdaptationSets.containsKey(adaptation.getContentType())) {
            sortedAdaptationSet = sortedAdaptationSets.get(adaptation.getContentType());
        } else {
            sortedAdaptationSet = new TreeMap<>();
            sortedAdaptationSets.put(adaptation.getContentType(), sortedAdaptationSet);
            trackMap.put(createKey(adaptation), 0);
        }
        if ((bandWidth = adaptation.getMinBandwidth()) == null || bandWidth == 0) {
            bandWidth = Double.MAX_VALUE;
            for (RepresentationESL repSet : representation) {
                if (repSet.getBandwidth() == null) {
                    bandWidth = 1.0;
                    break;
                }
                if (repSet.getBandwidth() < bandWidth) {
                    bandWidth = repSet.getBandwidth();
                }
            }
        }
        sortedAdaptationSet.put(bandWidth, adaptation);
    }
    for (SortedMap<Double, AdaptationSetESL> sortedMap : sortedAdaptationSets.values()) {
        for (AdaptationSetESL adaptation : sortedMap.values()) {
            ContentType contentType = manifest.matchContentType(adaptation.getContentType());
            if (adaptation.getEncodedSegmentDurations() != null && adaptation.getEncodedSegmentDurations().getEncodedSegmentDurationList() != null) {
                segmentTimeScale = StringParse.stringToDouble(adaptation.getEncodedSegmentDurations().getTimescale(), 1);
                encodedSegmentDurationList = adaptation.getEncodedSegmentDurations().getEncodedSegmentDurationList().split(";");
            }
            track = trackMap.get(createKey(adaptation));
            SortedMap<Double, RepresentationESL> sortedRepresentationESL = sortRepresentationByBandwidth(adaptation.getRepresentation());
            for (RepresentationESL representation : sortedRepresentationESL.values()) {
                if (representation.getEncodedSegment() != null) {
                    track++;
                    manifest.setTimeScale(StringParse.stringToDouble(representation.getEncodedSegment().getTimescale(), 1));
                    LOG.debug(String.format("representation.getBandwidth() %d:%s", track, representation.getBandwidth()));
                    generateChildManifestFromEncodedSegmentList(newManifest, contentType, track, representation, encodedSegmentDurationList, segmentTimeScale);
                    if (representation.getRepresentationACC() != null) {
                        // audio
                        childManifest.setChannels(representation.getRepresentationACC().getValue());
                    }
                    addToSegmentManifestCollectionMap(childManifest.getUriName());
                }
            }
            trackMap.put(createKey(adaptation), track);
        }
    }
}
Also used : ContentType(com.att.aro.core.videoanalysis.pojo.Manifest.ContentType) HashMap(java.util.HashMap) DashEncodedSegmentParser(com.att.aro.core.videoanalysis.parsers.DashEncodedSegmentParser) MPDEncodedSegment(com.att.aro.core.videoanalysis.parsers.encodedsegment.MPDEncodedSegment) RepresentationESL(com.att.aro.core.videoanalysis.parsers.encodedsegment.RepresentationESL) SortedMap(java.util.SortedMap) AdaptationSetESL(com.att.aro.core.videoanalysis.parsers.encodedsegment.AdaptationSetESL)

Example 2 with MPDEncodedSegment

use of com.att.aro.core.videoanalysis.parsers.encodedsegment.MPDEncodedSegment in project VideoOptimzer by attdevsupport.

the class XmlManifestHelper method xml2EncodedSegmentList.

/**
 * Load Amazon manifest into an MPDAmz object
 *
 * @param xmlByte
 * @return an MPDAmz object
 */
private MPDEncodedSegment xml2EncodedSegmentList(ByteArrayInputStream xmlByte) {
    JAXBContext context;
    Unmarshaller unMarshaller;
    MPDEncodedSegment mpdOutput = new MPDEncodedSegment();
    try {
        context = JAXBContext.newInstance(MPDEncodedSegment.class);
        unMarshaller = context.createUnmarshaller();
        mpdOutput = (MPDEncodedSegment) unMarshaller.unmarshal(xmlByte);
        if (mpdOutput.getPeriod().isEmpty()) {
            LOG.error("MPD NULL");
        }
    } catch (JAXBException e) {
        LOG.error("JAXBException", e);
    } catch (Exception ex) {
        LOG.error("JaxB parse Exception", ex);
    }
    return mpdOutput;
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) MPDEncodedSegment(com.att.aro.core.videoanalysis.parsers.encodedsegment.MPDEncodedSegment) JAXBException(javax.xml.bind.JAXBException)

Aggregations

MPDEncodedSegment (com.att.aro.core.videoanalysis.parsers.encodedsegment.MPDEncodedSegment)2 DashEncodedSegmentParser (com.att.aro.core.videoanalysis.parsers.DashEncodedSegmentParser)1 AdaptationSetESL (com.att.aro.core.videoanalysis.parsers.encodedsegment.AdaptationSetESL)1 RepresentationESL (com.att.aro.core.videoanalysis.parsers.encodedsegment.RepresentationESL)1 ContentType (com.att.aro.core.videoanalysis.pojo.Manifest.ContentType)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1