Search in sources :

Example 1 with AdaptationSet

use of com.att.aro.core.videoanalysis.parsers.dashif.AdaptationSet in project VideoOptimzer by attdevsupport.

the class ManifestBuilderDASH method processDashIF.

public void processDashIF(Manifest newManifest, XmlManifestHelper manifestView, String key) {
    // DASH-IF parser implementation
    switchManifestCollection(newManifest, key, manifest.getRequestTime());
    newManifest.setVideoType(VideoType.DASH_IF);
    MPD mpd = (MPD) manifestView.getManifest();
    DashIFParser dashIFParser = new DashIFParser(VideoType.DASH, mpd, newManifest, manifestCollection, childManifest);
    List<AdaptationSet> adaptationList = dashIFParser.getAdaptationSet();
    if (adaptationList != null) {
        int audioQualityId = 0;
        int videoQualityId = 0;
        for (AdaptationSet adaptation : adaptationList) {
            ContentType contentType = manifest.matchContentType(adaptation.getContentType());
            // Sort the representations by bandwidth to assign incremental quality id
            List<Representation> sortedRepresentations = adaptation.getRepresentations().stream().sorted(new Comparator<Representation>() {

                @Override
                public int compare(Representation o1, Representation o2) {
                    if (o1 == null || o2 == null) {
                        return 0;
                    }
                    return o1.getBandwidth().compareTo(o2.getBandwidth());
                }
            }).collect(Collectors.toList());
            for (Representation representation : sortedRepresentations) {
                if (representation.getSegmentBase() != null) {
                    if (representation.getSegmentBase().getTimescale() != null) {
                        // TODO: Setting timescale value for manifest is overwritten every time a child manifest is created for individual representation. \
                        // Timescale should be set on the Child Manifest level. Revisit this some time later.
                        manifest.setTimeScale(representation.getSegmentBase().getTimescale().doubleValue());
                    }
                    // Generate child manifests for each individual representation
                    childManifest = createChildManifest(newManifest, "", representation.getBaseURL());
                    if (ContentType.AUDIO.equals(contentType)) {
                        childManifest.setQuality(++audioQualityId);
                        if (adaptation.getContentType().equals("audio")) {
                            if (representation.getAudioChannelConfiguration() != null) {
                                childManifest.setChannels(representation.getAudioChannelConfiguration().getValue());
                            } else if (adaptation.getAudioChannelConfiguration() != null) {
                                childManifest.setChannels(adaptation.getAudioChannelConfiguration().getValue());
                            }
                        }
                    } else if (ContentType.VIDEO.equals(contentType)) {
                        childManifest.setQuality(++videoQualityId);
                    }
                    childManifest.setBandwidth(representation.getBandwidth());
                    childManifest.setCodecs(representation.getCodecs() != null ? representation.getCodecs() : adaptation.getCodecs());
                    childManifest.setVideo(ContentType.VIDEO.equals(contentType));
                    childManifest.setContentType(contentType);
                    if (representation.getHeight() != null) {
                        childManifest.setPixelHeight(representation.getHeight());
                    }
                    if (representation.getWidth() != null) {
                        childManifest.setPixelWidth(representation.getWidth());
                    }
                    if (representation.getAudioChannelConfiguration() != null) {
                        childManifest.setChannels(representation.getAudioChannelConfiguration().getValue());
                    }
                    // Set first segment info to the child manifest
                    SegmentInfo segmentInfo = new SegmentInfo();
                    segmentInfo.setDuration(0);
                    segmentInfo.setStartTime(0);
                    segmentInfo.setSegmentID(0);
                    segmentInfo.setContentType(contentType);
                    segmentInfo.setVideo(childManifest.isVideo());
                    segmentInfo.setQuality(String.valueOf(childManifest.getQuality()));
                    // Add chunk size for the first initializing segment
                    int chunkSize = 0;
                    if (representation.getSegmentBase().getIndexRange() != null) {
                        chunkSize += calcSizeFromSegmentElement(representation.getSegmentBase().getIndexRange(), false);
                    }
                    if (representation.getSegmentBase().getInitialization() != null) {
                        chunkSize += calcSizeFromSegmentElement(representation.getSegmentBase().getInitialization().getRange(), false);
                    }
                    segmentInfo.setSize(chunkSize);
                    // Add segment to child manifest segment list
                    childManifest.addSegment("0-" + String.valueOf(chunkSize != 0 ? chunkSize - 1 : 0), segmentInfo);
                    masterManifest.getSegUrlMatchDef().add(defineUrlMatching(childManifest.getUriName()));
                    manifestCollection.addToSegmentChildManifestTrie(childManifest.getUriName(), childManifest);
                    addToSegmentManifestCollectionMap(childManifest.getUriName());
                } else if (representation.getSegmentList() != null || representation.getSegmentTemplate() != null) {
                    // TODO: Implement Segment List or Template parser
                    LOG.warn("MPD: Represenation segment base is null but segment list or template is not null!");
                }
            }
        }
    }
}
Also used : MPD(com.att.aro.core.videoanalysis.parsers.dashif.MPD) DashIFParser(com.att.aro.core.videoanalysis.parsers.DashIFParser) ContentType(com.att.aro.core.videoanalysis.pojo.Manifest.ContentType) AdaptationSet(com.att.aro.core.videoanalysis.parsers.dashif.AdaptationSet) Representation(com.att.aro.core.videoanalysis.parsers.dashif.Representation) Comparator(java.util.Comparator)

Aggregations

DashIFParser (com.att.aro.core.videoanalysis.parsers.DashIFParser)1 AdaptationSet (com.att.aro.core.videoanalysis.parsers.dashif.AdaptationSet)1 MPD (com.att.aro.core.videoanalysis.parsers.dashif.MPD)1 Representation (com.att.aro.core.videoanalysis.parsers.dashif.Representation)1 ContentType (com.att.aro.core.videoanalysis.pojo.Manifest.ContentType)1 Comparator (java.util.Comparator)1