mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-24 17:35:10 +03:00
54ff2d8f28
This pertains to #2648 (although this is a new feature, not a replacement) and #1404. A CEA-708 decoder that follows the CEA-708-E standard, decodes closed caption data from User Data Registered by Rec. ITU-T T.35 SEI messages, and returns them as cues in Shaka's internal cue format. Furthermore, this pull request fixes and cements some of the logic surrounding CEA-608 and CEA-708 tag parsing on the Dash Manifest Parser. Format: Similar to the CEA-608 decoder, cues are emitted in Shaka's internal format (lib/text/cue.js). This decoder makes use of nested cues. The top level cue is always a blank cue with no text, and each nested cue inside it contains text, as well as a specific style, or linebreak cues to facilitate line breaks. This also allows for inline style (color, italics, underline) changes. Details: - ASCII (G0), Latin-1 (G1), and CEA-708 specific charsets (G2 and G3) all supported. - Underlines, colors, and Italics supported, set as a property on each nested cue. - Positioning of text is supported. (Exception: In CEA-708 the default positioning is left, in this decoder it is centered.) - Positioning of windows not supported, but relevant fields that could be used to support this are extracted and left as a TODO.
121 lines
3.0 KiB
JavaScript
121 lines
3.0 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.util.MimeUtils');
|
|
|
|
|
|
/**
|
|
* @summary A set of utility functions for dealing with MIME types.
|
|
*/
|
|
shaka.util.MimeUtils = class {
|
|
/**
|
|
* Takes a MIME type and optional codecs string and produces the full MIME
|
|
* type.
|
|
*
|
|
* @param {string} mimeType
|
|
* @param {string=} codecs
|
|
* @return {string}
|
|
*/
|
|
static getFullType(mimeType, codecs) {
|
|
let fullMimeType = mimeType;
|
|
if (codecs) {
|
|
fullMimeType += '; codecs="' + codecs + '"';
|
|
}
|
|
return fullMimeType;
|
|
}
|
|
|
|
/**
|
|
* Takes a Stream object and produces an extended MIME type with information
|
|
* beyond the container and codec type, when available.
|
|
*
|
|
* @param {shaka.extern.Stream} stream
|
|
* @return {string}
|
|
*/
|
|
static getExtendedType(stream) {
|
|
const components = [stream.mimeType];
|
|
|
|
const extendedMimeParams = shaka.util.MimeUtils.EXTENDED_MIME_PARAMETERS_;
|
|
extendedMimeParams.forEach((mimeKey, streamKey) => {
|
|
const value = stream[streamKey];
|
|
if (value) {
|
|
components.push(mimeKey + '="' + value + '"');
|
|
}
|
|
});
|
|
|
|
return components.join(';');
|
|
}
|
|
|
|
/**
|
|
* Split a list of codecs encoded in a string into a list of codecs.
|
|
* @param {string} codecs
|
|
* @return {!Array.<string>}
|
|
*/
|
|
static splitCodecs(codecs) {
|
|
return codecs.split(',');
|
|
}
|
|
|
|
/**
|
|
* Get the base codec from a codec string.
|
|
*
|
|
* @param {string} codecString
|
|
* @return {string}
|
|
*/
|
|
static getCodecBase(codecString) {
|
|
const parts = shaka.util.MimeUtils.getCodecParts_(codecString);
|
|
return parts[0];
|
|
}
|
|
|
|
/**
|
|
* Get the base and profile of a codec string. Where [0] will be the codec
|
|
* base and [1] will be the profile.
|
|
* @param {string} codecString
|
|
* @return {!Array.<string>}
|
|
* @private
|
|
*/
|
|
static getCodecParts_(codecString) {
|
|
const parts = codecString.split('.');
|
|
|
|
const base = parts[0];
|
|
|
|
parts.pop();
|
|
const profile = parts.join('.');
|
|
|
|
// Make sure that we always return a "base" and "profile".
|
|
return [base, profile];
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* A map from Stream object keys to MIME type parameters. These should be
|
|
* ignored by platforms that do not recognize them.
|
|
*
|
|
* This initial set of parameters are all recognized by Chromecast.
|
|
*
|
|
* @const {!Map.<string, string>}
|
|
* @private
|
|
*/
|
|
shaka.util.MimeUtils.EXTENDED_MIME_PARAMETERS_ = new Map()
|
|
.set('codecs', 'codecs')
|
|
.set('frameRate', 'framerate') // Ours is camelCase, theirs is lowercase.
|
|
.set('bandwidth', 'bitrate') // They are in the same units: bits/sec.
|
|
.set('width', 'width')
|
|
.set('height', 'height')
|
|
.set('channelsCount', 'channels');
|
|
|
|
|
|
/**
|
|
* A mimetype created for CEA-608 closed captions.
|
|
* @const {string}
|
|
*/
|
|
shaka.util.MimeUtils.CEA608_CLOSED_CAPTION_MIMETYPE = 'application/cea-608';
|
|
|
|
/**
|
|
* A mimetype created for CEA-708 closed captions.
|
|
* @const {string}
|
|
*/
|
|
shaka.util.MimeUtils.CEA708_CLOSED_CAPTION_MIMETYPE = 'application/cea-708';
|