Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for segments in Period and Representation. #19

Merged
merged 9 commits into from
Feb 26, 2018

Conversation

ishita12
Copy link
Contributor

No description provided.

@forbesjo forbesjo self-assigned this Feb 14, 2018
package.json Outdated
@@ -86,6 +87,7 @@
"version": "5.0.0"
},
"dependencies": {
"deepmerge": "^2.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should update the shallowMerge function to be a deepMerge and remove this dependency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that we should make video.js a dependency so that we can use videojs.mergeOptions? Its excessive to make that whole project a dependency just for a merge, but as long as this is being used in another project that is using videojs, rollup or other bundlers should be able to handle and remove the redundancy? I'm not sure what best practices are for this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building with video.js's mergeOptions it seems like the rollup did not remove the unnecessary code and mpd-parser.js shot up to 680KB. I think it would be better to write a simple deep merge function instead.

@@ -2,27 +2,25 @@ import { shallowMerge } from './utils/object';
import { segmentsFromTemplate } from './segment/segmentTemplate';
import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';

// import merge from 'deepmerge';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to remove this comment

const adaptationSets = findChildren(period, 'AdaptationSet');
const periodInfo = getSegmentInformation(period);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this periodSegmentInfo

@@ -178,9 +181,10 @@ export const toRepresentations =
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
const representations = findChildren(adaptationSet, 'Representation');
const periodAdaptationSetInfo = merge(periodInfo, segmentInfo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this adaptationSetSegmentInfo

const repBaseUrlElements = findChildren(representation, 'BaseURL');
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation));
const segmentInfoFromRepresenation = getSegmentInformation(representation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this representationSegmentInfo


return repBaseUrls.map(baseUrl => {
return {
segmentInfo,
segmentInfo: segmentRepresentationInfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo) (using the naming from my other suggestions) and then you don't need the segmentRepresentationInfo variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will make that change

package.json Outdated
@@ -86,6 +87,7 @@
"version": "5.0.0"
},
"dependencies": {
"deepmerge": "^2.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that we should make video.js a dependency so that we can use videojs.mergeOptions? Its excessive to make that whole project a dependency just for a merge, but as long as this is being used in another project that is using videojs, rollup or other bundlers should be able to handle and remove the redundancy? I'm not sure what best practices are for this case.

return segmentsFromTemplate(
shallowMerge(segmentInfo.template, attributes),
segmentInfo.timeline
if (segmentInfo.list) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reasoning for switching the order of list and template here? I think either order should be fine, just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just checking for the SegmentList output.

@@ -197,6 +198,7 @@ QUnit.test('end to end - basic', function(assert) {
height="404"
id="test"
width="720">
<SegmentTemplate></SegmentTemplate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added?

@@ -272,6 +274,7 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
height="404"
id="test"
width="720">
<SegmentTemplate></SegmentTemplate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this one added as well?

startWithSAP: '1'

},
segments: undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be undefined, it should have a segment list built from the segment information provided in the adaptation set

assert.deepEqual(actual, expected);
});

QUnit.test(' End to End test for checking support of segments in period ', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test is checking for support for segment information in the period, we should have the mpd not have any segment information contained in the adaptation set or representation to show that we can build a segment list when the segment info is just in the period

segmentInfo: {
base: undefined,
list: undefined,
template: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be undefined, should have used template from containing adaptation set

segmentInfo: {
base: undefined,
list: undefined,
template: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be undefined, should have used template from containing adaptation set


// Test for only periodAdaptationSetInfo

QUnit.test(' End to End test for returning period information', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is nearly identical to the one above it . Is it testing something specifically different?

height= "404"
id= "test"
width= "720" >
<SegmentBase></SegmentBase>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this line

assert.deepEqual(actual, expected);
});

QUnit.test(' Test for checking presence of atmost one segment at each level', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is a bit misleading maybe something along the lines of "uses only one set of segment information when multiple are present" and then add a code comment saying that although the spec states that at each level at most one shall be present, we still handle the case to prevent throwing errors

<Representation audioSamplingRate="48000" bandwidth="63000" codecs="mp4a.40.2" id="63000"></Representation>
<Representation audioSamplingRate="48000" bandwidth="125000" codecs="mp4a.40.2" id="125000"></Representation>
<Representation audioSamplingRate="48000" bandwidth="63000" codecs="mp4a.40.2" id="63000">
<SegmentTemplate></SegmentTemplate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these <segment*> tags added to these mpd manifests shouldn't be necessary to add

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to test your use case within an actual manifest, you could create a fresh one, and add that and the accompanying json to index.test.js.


return repBaseUrls.map(baseUrl => {
return {
segmentInfo: segmentRepresentationInfo,
segmentInfo: {
list: adaptationSetSegmentInfo.list && representationSegmentInfo.list ? merge(adaptationSetSegmentInfo.list, representationSegmentInfo.list) : adaptationSetSegmentInfo.list && !representationSegmentInfo.list ? adaptationSetSegmentInfo.list : !adaptationSetSegmentInfo.list && representationSegmentInfo.list ? representationSegmentInfo.list : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nightmare to read. I think its best we try to come at this with a different approach.

The main issue with the merge is that if the second object in the merge has a property that is undefined, it overwrites that property with undefined, so removing those properties from the object before we even get to merging should solve the issue without needing all this complex logic.

I think that we should return to what you had before this commit of just merging the full segment info objects instead of merging these properties individually.

Then, to fix the issue of a property being undefined, in getSegmentInformation, before returning the segment info object, save it to a variable and then delete properties that are undefined

const segmentInfo = {
  template,
  timeline: ...
  ....
};

Object.keys(segmentInfo).forEach(key => {
  if (!segmentInfo[key]) {
    delete segmentInfo[key];
  }
});

return segmentInfo;

@@ -181,10 +185,15 @@ export const toRepresentations =
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
const representations = findChildren(adaptationSet, 'Representation');
const periodAdaptationSetInfo = merge(periodInfo, segmentInfo);
const adaptationSetSegmentInfo = {
list: periodSegmentInfo.list && segmentInfo.list ? merge(periodSegmentInfo.list, segmentInfo.list) : periodSegmentInfo.list && !segmentInfo.list ? periodSegmentInfo.list : !periodSegmentInfo.list && segmentInfo.list ? segmentInfo.list : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same strategy as my other comment here

@@ -210,10 +221,12 @@ export const toRepresentations =
*/
export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodIndex) => {
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL'));
const periodAttributes = shallowMerge({ periodIndex }, mpdAttributes);
const periodAtt = getAttributes(period);
const periodAttributes = shallowMerge(periodAtt, { periodIndex }, mpdAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets switch the order of the arguments here to be mpdAttributes, periodAtt, { periodIndex }. Off the top of my head I'm not sure if there are any overlapping attributes between the mpd or period, but to be on the safe side, switching those around will make sure any overlapping attributes get overwritten correctly from the period.

import { parseDuration } from './utils/time';
import { findChildren, getContent } from './utils/xml';
import resolveUrl from './utils/resolveUrl';
import errors from './errors';
import merge from 'deepmerge';
// import merge from 'deepmerge';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this comment

@@ -1,10 +1,11 @@
import { flatten } from './utils/list';
import { shallowMerge, getAttributes } from './utils/object';
import { getAttributes } from './utils/object';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can import merge along with getAttributes here

import { parseDuration } from './utils/time';
import { findChildren, getContent } from './utils/xml';
import resolveUrl from './utils/resolveUrl';
import errors from './errors';
import merge from 'deepmerge';
// import merge from 'deepmerge';
import { merge } from './utils/object';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this line

@@ -2,27 +2,25 @@ import { shallowMerge } from './utils/object';
import { segmentsFromTemplate } from './segment/segmentTemplate';
import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';

// import merge from 'deepmerge';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to remove this comment

export const shallowMerge = (...objects) => {
export const merge = (...objects) => {

const isObject = (obj) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can be defined outside of merge

export const merge = (...objects) => {

const isObject = (obj) => {
return obj && typeof obj === 'object';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets be explicit and use !!obj

const isObject = (obj) => {
return obj && typeof obj === 'object';
};

return objects.reduce((x, y) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to update this to use more descriptive names for readability. maybe result for x and source for y

Copy link
Contributor

@mjneil mjneil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tested

@@ -8,25 +8,25 @@ import QUnit from 'qunit';

QUnit.module('utils');

QUnit.module('shallowMerge');
QUnit.module('merge');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a test or two for the new merge functionality

@forbesjo forbesjo merged commit 7ee6470 into videojs:master Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants