Skip to content

Commit

Permalink
Make SegmentReference comparison more general
Browse files Browse the repository at this point in the history
There were fields in SegmentReference which were not being examined
when instances are compared by jasmine.  Now, the comparison is more
general and will continue to work when we change the structure.

This relates to the issues below because the next changes for those
issues will change the fields in SegmentReference.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: Ib7cd3d3cadeb0e58efd70964c082219b1c097fad
  • Loading branch information
joeyparrish committed Dec 19, 2019
1 parent 52aa032 commit 4923622
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
12 changes: 4 additions & 8 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,13 @@ describe('HlsParser live', () => {
const expectedRef = ManifestParser.makeReference(
'test:/main.mp4', 0, segmentDataStartTime,
segmentDataStartTime + 2);
// In live content, we do not set presentationTimeOffset.
expectedRef.presentationTimeOffset = 0;

const manifest = await parser.start('test:/master', playerInterface);
const video = manifest.periods[0].variants[0].video;
await video.createSegmentIndex();
ManifestParser.verifySegmentIndex(video, [expectedRef]);

// In live content, we do not set presentationTimeOffset.
const ref = video.segmentIndex.get(0);
expect(ref.presentationTimeOffset).toBe(0);
});

it('gets start time on update without segment request', async () => {
Expand Down Expand Up @@ -625,15 +623,13 @@ describe('HlsParser live', () => {
const expectedRef = ManifestParser.makeReference(
'test:/main2.ts', 1, segmentDataStartTime,
segmentDataStartTime + 2);
// In live content, we do not set presentationTimeOffset.
expectedRef.presentationTimeOffset = 0;

const manifest = await parser.start('test:/master', playerInterface);
const video = manifest.periods[0].variants[0].video;
await video.createSegmentIndex();
ManifestParser.verifySegmentIndex(video, [expectedRef]);

// In live content, we do not set presentationTimeOffset.
const ref = video.segmentIndex.get(1);
expect(ref.presentationTimeOffset).toBe(0);
});

it('gets start time of segments with byte range', async () => {
Expand Down
18 changes: 6 additions & 12 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,9 @@ describe('HlsParser', () => {
'' /* baseUri */,
expectedStartByte,
expectedEndByte);
// In VOD content, we set the presentationTimeOffset to align the
// content to presentation time 0.
expectedRef.presentationTimeOffset = segmentDataStartTime;

const manifest = await parser.start('test:/master', playerInterface);
const video = manifest.periods[0].variants[0].video;
Expand All @@ -2049,12 +2052,6 @@ describe('HlsParser', () => {
'test:/main.mp4',
expectedStartByte,
partialEndByte);

// In VOD content, we set the presentationTimeOffset to align the
// content to presentation time 0.
const position = video.segmentIndex.find(0);
const ref = video.segmentIndex.get(position);
expect(ref.presentationTimeOffset).toBe(segmentDataStartTime);
});

it('parses start time from ts segments', async () => {
Expand All @@ -2073,6 +2070,9 @@ describe('HlsParser', () => {
'' /* baseUri */,
expectedStartByte,
expectedEndByte);
// In VOD content, we set the presentationTimeOffset to align the
// content to presentation time 0.
expectedRef.presentationTimeOffset = segmentDataStartTime;

const manifest = await parser.start('test:/master', playerInterface);
const video = manifest.periods[0].variants[0].video;
Expand All @@ -2085,12 +2085,6 @@ describe('HlsParser', () => {
'test:/main.ts',
expectedStartByte,
partialEndByte);

// In VOD content, we set the presentationTimeOffset to align the
// content to presentation time 0.
const position = video.segmentIndex.find(0);
const ref = video.segmentIndex.get(position);
expect(ref.presentationTimeOffset).toBe(segmentDataStartTime);
});

// We want to make sure that we can interrupt the parser while it is getting
Expand Down
10 changes: 10 additions & 0 deletions test/test/externs/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,13 @@ jasmine.Ajax.RequestTracker.prototype.at = function(index) {};

/** @const {!jasmine.Ajax.RequestTracker} */
jasmine.Ajax.requests;

/** @const */
jasmine.matchersUtil = {};

/**
* @param {*} first
* @param {*} second
* @return {boolean}
*/
jasmine.matchersUtil.equals = function(first, second) {};
15 changes: 14 additions & 1 deletion test/test/util/manifest_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ shaka.test.ManifestParser = class {
static makeReference(uri, position, start, end, baseUri = '',
startByte = 0, endByte = null) {
const getUris = () => [baseUri + uri];

// If a test wants to verify these, they can be set explicitly after
// makeReference is called.
const initSegmentReference = /** @type {?} */({
asymmetricMatch: (value) => {
return value == null ||
value instanceof shaka.media.InitSegmentReference;
},
});

const presentationTimeOffset = /** @type {?} */(jasmine.any(Number));

return new shaka.media.SegmentReference(
position, start, end, getUris, startByte, endByte,
/* initSegmentReference */ null, /* presentationTimeOffset */ 0);
initSegmentReference,
presentationTimeOffset);
}
};
22 changes: 11 additions & 11 deletions test/test/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ shaka.test.Util = class {
!a.every((x, i) => { return x == b[i]; })) {
return false;
}

// Make shallow copies of each, without their getUris fields.
const trimmedFirst = Object.assign({}, /** @type {Object} */(first));
delete trimmedFirst.getUris;
const trimmedSecond = Object.assign({}, /** @type {Object} */(second));
delete trimmedSecond.getUris;

// Compare those using Jasmine's utility, which will compare the fields of
// an object and the items of an array.
return jasmine.matchersUtil.equals(trimmedFirst, trimmedSecond);
}
if (isSegment) {
return first.position == second.position &&
first.startTime == second.startTime &&
first.endTime == second.endTime &&
first.startByte == second.startByte &&
first.endByte == second.endByte;
}
if (isInit) {
return first.startByte == second.startByte &&
first.endByte == second.endByte;
}

return undefined;
}

Expand Down

0 comments on commit 4923622

Please sign in to comment.