-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
CEA-708 Decoder (#2648) #2807
Merged
joeyparrish
merged 39 commits into
shaka-project:master
from
muhammadharis:cea708-decoder
Sep 10, 2020
Merged
CEA-708 Decoder (#2648) #2807
Changes from 31 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
a236a7c
Implemented CEA608 decoder (#2648)
muhammadharis b3ed9ae
removed unnecessary switch statement
muhammadharis da868ce
made all hex lowercase
muhammadharis e27c1e0
removed log
muhammadharis 047317c
linting
muhammadharis 18b1356
added annotations for constants
muhammadharis 352d058
commenting hotfixes
muhammadharis 1ebb6a9
moved comment
muhammadharis 9a9b65e
resolve conflicts
muhammadharis 0a4ae52
modularize design and add appropriate unit tests
muhammadharis 5302da8
color fix
muhammadharis 92da874
CEA-708 Decoder (#2648)
muhammadharis 4165bc7
resolve merge conflict
muhammadharis 10c0a5b
improve error handling and safety of 708 decoding
muhammadharis 4933c1a
made data flow more intuitive
muhammadharis 10381b9
Merge branch 'master' of https://github.com/google/shaka-player into …
muhammadharis adb467e
add impl for G2 and G3 groups, fix comments, enhance logic
muhammadharis 63973ee
add emit logic
muhammadharis c11c1ed
map 64 colors -> 8 colors to avoid unreadable text
muhammadharis 89d8913
moved shared constants into utils file
muhammadharis cc3b8b9
unit tests for window
muhammadharis de499a8
added unit tests for cea-708 logic
muhammadharis a4bbebf
remove extra file
muhammadharis d791022
further unit tests and removing logs
muhammadharis 7420ca9
minor bugfix in unit tests
muhammadharis 759961b
fix emit logic, and fix type errors in compiler
muhammadharis b3579a3
tighten types on unit tests
muhammadharis a3f323f
clean dash parsing of CEA-608 and CEA-708
muhammadharis e7b0cc7
typing fix compiler
muhammadharis f807210
remove logs
muhammadharis 6c3e5ef
renamed CeaDecoderUtils to CeaUtils
muhammadharis c514e7c
triple equals
muhammadharis 72378f0
fix merge conflict
muhammadharis a6544fe
address pull request review
muhammadharis bd0edf0
remove comments on language_utils
muhammadharis b72883f
address pr review
muhammadharis df901cb
typo fix and remove unnecessary comment
muhammadharis 0b4ed72
fix merge conflict
muhammadharis 0873830
Merge branch 'master' of https://github.com/google/shaka-player into …
muhammadharis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
*/ | ||
|
||
goog.provide('shaka.cea.Cea608Memory'); | ||
goog.provide('shaka.cea.Cea608Char'); | ||
|
||
goog.require('shaka.cea.CeaUtils'); | ||
goog.require('shaka.text.Cue'); | ||
|
||
|
||
|
@@ -21,7 +21,7 @@ shaka.cea.Cea608Memory = class { | |
constructor(fieldNum, channelNum) { | ||
/** | ||
* Buffer for storing decoded characters. | ||
* @private @const {!Array<!Array<!shaka.cea.Cea608Char>>} | ||
* @private @const {!Array<!Array<!shaka.cea.CeaUtils.StyledChar>>} | ||
*/ | ||
this.rows_ = []; | ||
|
||
|
@@ -62,12 +62,12 @@ shaka.cea.Cea608Memory = class { | |
/** | ||
* @private {!string} | ||
*/ | ||
this.textColor_ = shaka.cea.Cea608Memory.DEFAULT_TXT_COLOR; | ||
this.textColor_ = shaka.cea.CeaUtils.DEFAULT_TXT_COLOR; | ||
|
||
/** | ||
* @private {!string} | ||
*/ | ||
this.backgroundColor_ = shaka.cea.Cea608Memory.DEFAULT_BG_COLOR; | ||
this.backgroundColor_ = shaka.cea.CeaUtils.DEFAULT_BG_COLOR; | ||
|
||
this.reset(); | ||
} | ||
|
@@ -80,121 +80,10 @@ shaka.cea.Cea608Memory = class { | |
*/ | ||
forceEmit(startTime, endTime) { | ||
const stream = `CC${(this.fieldNum_<< 1) | this.channelNum_ +1}`; | ||
|
||
// Find the first and last row that contains characters. | ||
let firstNonEmptyRow = -1; | ||
let lastNonEmptyRow = -1; | ||
|
||
for (let i = 0; i < this.rows_.length; i++) { | ||
if (this.rows_[i].length) { | ||
firstNonEmptyRow = i; | ||
break; | ||
} | ||
} | ||
|
||
for (let i = this.rows_.length - 1; i >= 0; i--) { | ||
if (this.rows_[i].length) { | ||
lastNonEmptyRow = i; | ||
break; | ||
} | ||
} | ||
|
||
// Exit early if no non-empty row was found. | ||
if (firstNonEmptyRow === -1 || lastNonEmptyRow === -1) { | ||
return null; | ||
} | ||
|
||
// Keeps track of the current styles for a cue being emitted. | ||
let currentUnderline = false; | ||
let currentItalics = false; | ||
let currentTextColor = shaka.cea.Cea608Memory.DEFAULT_TXT_COLOR; | ||
let currentBackgroundColor = shaka.cea.Cea608Memory.DEFAULT_BG_COLOR; | ||
|
||
// Create first cue that will be nested in top level cue. Default styles. | ||
let currentCue = this.createStyledCue_(startTime, endTime, | ||
currentUnderline, currentItalics, | ||
currentTextColor, currentBackgroundColor); | ||
|
||
// Logic: Reduce rows into a single top level cue containing nested cues. | ||
// Each nested cue corresponds either a style change or a line break. | ||
const topLevelCue = new shaka.text.Cue( | ||
startTime, endTime, /* payload= */ ''); | ||
|
||
for (let i = firstNonEmptyRow; i <= lastNonEmptyRow; i++) { | ||
for (const styledChar of this.rows_[i]) { | ||
const underline = styledChar.isUnderlined(); | ||
const italics = styledChar.isItalicized(); | ||
const textColor = styledChar.getTextColor(); | ||
const backgroundColor = styledChar.getBackgroundColor(); | ||
|
||
// If any style properties have changed, we need to open a new cue. | ||
if (underline != currentUnderline || italics != currentItalics || | ||
textColor != currentTextColor || | ||
backgroundColor != currentBackgroundColor) { | ||
// Push the currently built cue and start a new cue, with new styles. | ||
if (currentCue.payload) { | ||
topLevelCue.nestedCues.push(currentCue); | ||
} | ||
currentCue = this.createStyledCue_(startTime, endTime, | ||
underline, italics, textColor, backgroundColor); | ||
|
||
currentUnderline = underline; | ||
currentItalics = italics; | ||
currentTextColor = textColor; | ||
currentBackgroundColor = backgroundColor; | ||
} | ||
|
||
currentCue.payload += styledChar.getChar(); | ||
} | ||
if (currentCue.payload) { | ||
topLevelCue.nestedCues.push(currentCue); | ||
} | ||
|
||
// Create and push a linebreak cue to create a new line. | ||
if (i !== lastNonEmptyRow) { | ||
const spacerCue = new shaka.text.Cue( | ||
startTime, endTime, /* payload= */ ''); | ||
spacerCue.spacer = true; | ||
topLevelCue.nestedCues.push(spacerCue); | ||
} | ||
|
||
// Create a new cue. | ||
currentCue = this.createStyledCue_(startTime, endTime, | ||
currentUnderline, currentItalics, | ||
currentTextColor, currentBackgroundColor); | ||
} | ||
|
||
if (topLevelCue.nestedCues.length) { | ||
return { | ||
cue: topLevelCue, | ||
stream, | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param {!number} startTime | ||
* @param {!number} endTime | ||
* @param {!boolean} underline | ||
* @param {!boolean} italics | ||
* @param {!string} txtColor | ||
* @param {!string} bgColor | ||
* @return {!shaka.text.Cue} | ||
* @private | ||
*/ | ||
createStyledCue_(startTime, endTime, underline, italics, txtColor, bgColor) { | ||
const cue = new shaka.text.Cue(startTime, endTime, /* payload= */ ''); | ||
if (underline) { | ||
cue.textDecoration.push(shaka.text.Cue.textDecoration.UNDERLINE); | ||
} | ||
if (italics) { | ||
cue.fontStyle = shaka.text.Cue.fontStyle.ITALIC; | ||
} | ||
cue.color = txtColor; | ||
cue.backgroundColor = bgColor; | ||
return cue; | ||
return shaka.cea.CeaUtils.getParsedCaption( | ||
topLevelCue, stream, this.rows_, startTime, endTime); | ||
} | ||
|
||
/** | ||
|
@@ -273,8 +162,9 @@ shaka.cea.Cea608Memory = class { | |
} | ||
|
||
if (char) { | ||
const styledChar = new shaka.cea.Cea608Char(char, this.underline_, | ||
this.italics_, this.backgroundColor_, this.textColor_); | ||
const styledChar = new shaka.cea.CeaUtils.StyledChar( | ||
char, this.underline_, this.italics_, | ||
this.backgroundColor_, this.textColor_); | ||
this.rows_[this.row_].push(styledChar); | ||
} | ||
} | ||
|
@@ -360,88 +250,12 @@ shaka.cea.Cea608Memory = class { | |
} | ||
}; | ||
|
||
shaka.cea.Cea608Char = class { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A very similar class was being used for CEA-708, so I broke it out into a utility. |
||
constructor(character, underline, italics, backgroundColor, textColor) { | ||
/** | ||
* @private {!string} | ||
*/ | ||
this.character_ = character; | ||
|
||
/** | ||
* @private {!boolean} | ||
*/ | ||
this.underline_ = underline; | ||
|
||
/** | ||
* @private {!boolean} | ||
*/ | ||
this.italics_ = italics; | ||
|
||
/** | ||
* @private {!string} | ||
*/ | ||
this.backgroundColor_ = backgroundColor; | ||
|
||
/** | ||
* @private {!string} | ||
*/ | ||
this.textColor_ = textColor; | ||
} | ||
|
||
/** | ||
* @return {!string} | ||
*/ | ||
getChar() { | ||
return this.character_; | ||
} | ||
|
||
/** | ||
* @return {!boolean} | ||
*/ | ||
isUnderlined() { | ||
return this.underline_; | ||
} | ||
|
||
/** | ||
* @return {!boolean} | ||
*/ | ||
isItalicized() { | ||
return this.italics_; | ||
} | ||
|
||
/** | ||
* @return {!string} | ||
*/ | ||
getBackgroundColor() { | ||
return this.backgroundColor_; | ||
} | ||
|
||
/** | ||
* @return {!string} | ||
*/ | ||
getTextColor() { | ||
return this.textColor_; | ||
} | ||
}; | ||
|
||
/** | ||
* Maximum number of rows in the buffer. | ||
* @const {!number} | ||
*/ | ||
shaka.cea.Cea608Memory.CC_ROWS = 15; | ||
|
||
/** | ||
* Default background color for text. | ||
* @const {!string} | ||
*/ | ||
shaka.cea.Cea608Memory.DEFAULT_BG_COLOR = 'black'; | ||
|
||
/** | ||
* Default text color. | ||
* @const {!string} | ||
*/ | ||
shaka.cea.Cea608Memory.DEFAULT_TXT_COLOR = 'white'; | ||
|
||
/** | ||
* Characters sets. | ||
* @const @enum {!number} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've broken this logic out into a utility, since the same logic is needed for CEA-708 caption emission.