Skip to content

Commit

Permalink
feat(UI): Add option to show the video codec name (#7747)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 12, 2024
1 parent 60429e9 commit 075c3fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
6 changes: 5 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ shaka.extern.UIVolumeBarColors;
* defaultVrProjectionMode: string,
* setupMediaSession: boolean,
* preferVideoFullScreenInVisionOS: boolean,
* showAudioCodec: boolean
* showAudioCodec: boolean,
* showVideoCodec: boolean
* }}
*
* @property {!Array.<string>} controlPanelElements
Expand Down Expand Up @@ -265,6 +266,9 @@ shaka.extern.UIVolumeBarColors;
* @property {boolean} showAudioCodec
* Show the audio codec if the language has more than one audio codec.
* Defaults to true.
* @property {boolean} showVideoCodec
* Show the video codec if the resolution has more than one video codec.
* Defaults to true.
* @exportDoc
*/
shaka.extern.UIConfiguration;
Expand Down
44 changes: 40 additions & 4 deletions ui/resolution_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ goog.require('shaka.ui.Utils');
goog.require('shaka.util.Dom');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.Functional');
goog.require('shaka.util.MimeUtils');
goog.requireType('shaka.ui.Controls');


Expand Down Expand Up @@ -125,23 +126,35 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
tracks = tracks.filter((track, idx) => {
// Keep the first one with the same height and framerate or bandwidth.
const otherIdx = tracks.findIndex((t) => {
return t.height == track.height &&
let ret = t.height == track.height &&
t.videoBandwidth == track.videoBandwidth &&
t.frameRate == track.frameRate &&
t.hdr == track.hdr &&
t.videoLayout == track.videoLayout;
if (ret && this.controls.getConfig().showVideoCodec &&
t.videoCodec && track.videoCodec) {
ret = shaka.util.MimeUtils.getNormalizedCodec(t.videoCodec) ==
shaka.util.MimeUtils.getNormalizedCodec(track.videoCodec);
}
return ret;
});
return otherIdx == idx;
});
} else {
tracks = tracks.filter((track, idx) => {
// Keep the first one with the same height and framerate or bandwidth.
const otherIdx = tracks.findIndex((t) => {
return t.height == track.height &&
let ret = t.height == track.height &&
t.bandwidth == track.bandwidth &&
t.frameRate == track.frameRate &&
t.hdr == track.hdr &&
t.videoLayout == track.videoLayout;
if (ret && this.controls.getConfig().showVideoCodec &&
t.videoCodec && track.videoCodec) {
ret = shaka.util.MimeUtils.getNormalizedCodec(t.videoCodec) ==
shaka.util.MimeUtils.getNormalizedCodec(track.videoCodec);
}
return ret;
});
return otherIdx == idx;
});
Expand Down Expand Up @@ -284,8 +297,31 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
return otherTrack != track && otherTrack.height == track.height;
});
if (hasDuplicateResolution) {
const bandwidth = track.videoBandwidth || track.bandwidth;
text += ' (' + Math.round(bandwidth / 1000) + ' kbits/s)';
const hasDuplicateBandwidth = tracks.some((otherTrack) => {
return otherTrack != track && otherTrack.height == track.height &&
(otherTrack.videoBandwidth || otherTrack.bandwidth) ==
(track.videoBandwidth || track.bandwidth);
});
if (!hasDuplicateBandwidth) {
const bandwidth = track.videoBandwidth || track.bandwidth;
text += ' (' + Math.round(bandwidth / 1000) + ' kbits/s)';
}

if (this.controls.getConfig().showVideoCodec) {
const getVideoCodecName = (videoCodec) => {
let name = '';
if (videoCodec) {
const codec = shaka.util.MimeUtils.getNormalizedCodec(videoCodec);
if (codec.startsWith('dovi-')) {
name = 'Dolby Vision';
} else {
name = codec.toUpperCase();
}
}
return name ? ' ' + name : name;
};
text += getVideoCodecName(track.videoCodec);
}
}
return text;
}
Expand Down
1 change: 1 addition & 0 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ shaka.ui.Overlay = class {
setupMediaSession: true,
preferVideoFullScreenInVisionOS: false,
showAudioCodec: true,
showVideoCodec: true,
};

// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit 075c3fd

Please sign in to comment.