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

Fix thumbnails issues #3858

Merged
merged 4 commits into from Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions externs/shaka/player.js
Expand Up @@ -1207,6 +1207,8 @@ shaka.extern.LanguageRole;

/**
* @typedef {{
* imageHeight: number,
* imageWidth: number,
* height: number,
* positionX: number,
* positionY: number,
Expand All @@ -1216,6 +1218,12 @@ shaka.extern.LanguageRole;
* width: number
* }}
*
* @property {number} imageHeight
* The image height in px. The image height could be different to height if
* the layout is different to 1x1.
* @property {number} imageWidth
* The image width in px. The image width could be different to width if
* the layout is different to 1x1.
* @property {number} height
* The thumbnail height in px.
* @property {number} positionX
Expand Down
2 changes: 2 additions & 0 deletions lib/player.js
Expand Up @@ -3637,6 +3637,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
positionY = Math.floor(thumbnailPosition / columns) * height;
}
return {
imageHeight: fullImageHeight,
imageWidth: fullImageWidth,
height: height,
positionX: positionX,
positionY: positionY,
Expand Down
10 changes: 8 additions & 2 deletions lib/util/stream_utils.js
Expand Up @@ -994,7 +994,13 @@ shaka.util.StreamUtils = class {

// The stream width and height represent the size of the entire thumbnail
// sheet, so divide by the layout.
const reference = stream.segmentIndex.get(0);
let reference = null;
// Note: segmentIndex is built by default for HLS, but not for DASH, but
// in DASH this information comes at the stream level and not at the
// segment level.
if (stream.segmentIndex) {
reference = stream.segmentIndex.get(0);
}
let layout = stream.tilesLayout;
theodab marked this conversation as resolved.
Show resolved Hide resolved
if (reference) {
layout = reference.getTilesLayout() || layout;
Expand Down Expand Up @@ -1035,7 +1041,7 @@ shaka.util.StreamUtils = class {
channelsCount: null,
audioSamplingRate: null,
spatialAudio: false,
tilesLayout: stream.tilesLayout || null,
tilesLayout: layout,
audioBandwidth: null,
videoBandwidth: null,
originalVideoId: null,
Expand Down
8 changes: 8 additions & 0 deletions test/player_unit.js
Expand Up @@ -3544,24 +3544,32 @@ describe('Player', () => {
const thumbnail2 = await player.getThumbnails(5, 21);
const thumbnail5 = await player.getThumbnails(5, 51);
expect(thumbnail0).toEqual(jasmine.objectContaining({
imageHeight: 150,
imageWidth: 200,
positionX: 0,
positionY: 0,
width: 100,
height: 50,
}));
expect(thumbnail1).toEqual(jasmine.objectContaining({
imageHeight: 150,
imageWidth: 200,
positionX: 100,
positionY: 0,
width: 100,
height: 50,
}));
expect(thumbnail2).toEqual(jasmine.objectContaining({
imageHeight: 150,
imageWidth: 200,
positionX: 0,
positionY: 50,
width: 100,
height: 50,
}));
expect(thumbnail5).toEqual(jasmine.objectContaining({
imageHeight: 150,
imageWidth: 200,
positionX: 100,
positionY: 100,
width: 100,
Expand Down