Skip to content

Commit

Permalink
fix(image): Fix thumbnails issues (#3858)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván committed Jan 13, 2022
1 parent 9f3fb46 commit 087a9b4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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 @@ -1014,7 +1014,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;
if (reference) {
layout = reference.getTilesLayout() || layout;
Expand Down Expand Up @@ -1055,7 +1061,7 @@ shaka.util.StreamUtils = class {
channelsCount: null,
audioSamplingRate: null,
spatialAudio: false,
tilesLayout: stream.tilesLayout || null,
tilesLayout: layout || null,
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

0 comments on commit 087a9b4

Please sign in to comment.