Skip to content

Commit

Permalink
Tentative fix for roll-up row count
Browse files Browse the repository at this point in the history
Issue: #3513

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177804505
  • Loading branch information
ojw28 committed Dec 12, 2017
1 parent 10b24be commit a8298b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
seek.
* Use the same listener `MediaSourceEventListener` for all MediaSource
implementations.
* CEA-608: Fix handling of row count changes in roll-up mode
([#3513](https://github.com/google/ExoPlayer/issues/3513)).

### 2.6.0 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
Expand Down Expand Up @@ -185,7 +184,7 @@ public final class Cea608Decoder extends CeaDecoder {
private final ParsableByteArray ccData;
private final int packetLength;
private final int selectedField;
private final LinkedList<CueBuilder> cueBuilders;
private final ArrayList<CueBuilder> cueBuilders;

private CueBuilder currentCueBuilder;
private List<Cue> cues;
Expand All @@ -200,7 +199,7 @@ public final class Cea608Decoder extends CeaDecoder {

public Cea608Decoder(String mimeType, int accessibilityChannel) {
ccData = new ParsableByteArray();
cueBuilders = new LinkedList<>();
cueBuilders = new ArrayList<>();
currentCueBuilder = new CueBuilder(CC_MODE_UNKNOWN, DEFAULT_CAPTIONS_ROW_COUNT);
packetLength = MimeTypes.APPLICATION_MP4CEA608.equals(mimeType) ? 2 : 3;
switch (accessibilityChannel) {
Expand Down Expand Up @@ -230,8 +229,8 @@ public void flush() {
cues = null;
lastCues = null;
setCaptionMode(CC_MODE_UNKNOWN);
setCaptionRowCount(DEFAULT_CAPTIONS_ROW_COUNT);
resetCueBuilders();
captionRowCount = DEFAULT_CAPTIONS_ROW_COUNT;
repeatableControlSet = false;
repeatableControlCc1 = 0;
repeatableControlCc2 = 0;
Expand Down Expand Up @@ -434,23 +433,26 @@ private void handlePreambleAddressCode(byte cc1, byte cc2) {
private void handleMiscCode(byte cc2) {
switch (cc2) {
case CTRL_ROLL_UP_CAPTIONS_2_ROWS:
captionRowCount = 2;
setCaptionMode(CC_MODE_ROLL_UP);
setCaptionRowCount(2);
return;
case CTRL_ROLL_UP_CAPTIONS_3_ROWS:
captionRowCount = 3;
setCaptionMode(CC_MODE_ROLL_UP);
setCaptionRowCount(3);
return;
case CTRL_ROLL_UP_CAPTIONS_4_ROWS:
captionRowCount = 4;
setCaptionMode(CC_MODE_ROLL_UP);
setCaptionRowCount(4);
return;
case CTRL_RESUME_CAPTION_LOADING:
setCaptionMode(CC_MODE_POP_ON);
return;
case CTRL_RESUME_DIRECT_CAPTIONING:
setCaptionMode(CC_MODE_PAINT_ON);
return;
default:
// Fall through.
break;
}

if (captionMode == CC_MODE_UNKNOWN) {
Expand Down Expand Up @@ -484,6 +486,9 @@ private void handleMiscCode(byte cc2) {
case CTRL_DELETE_TO_END_OF_ROW:
// TODO: implement
break;
default:
// Fall through.
break;
}
}

Expand Down Expand Up @@ -515,8 +520,13 @@ private void setCaptionMode(int captionMode) {
}
}

private void setCaptionRowCount(int captionRowCount) {
this.captionRowCount = captionRowCount;
currentCueBuilder.setCaptionRowCount(captionRowCount);
}

private void resetCueBuilders() {
currentCueBuilder.reset(captionMode, captionRowCount);
currentCueBuilder.reset(captionMode);
cueBuilders.clear();
cueBuilders.add(currentCueBuilder);
}
Expand Down Expand Up @@ -594,24 +604,28 @@ private static class CueBuilder {
public CueBuilder(int captionMode, int captionRowCount) {
preambleStyles = new ArrayList<>();
midrowStyles = new ArrayList<>();
rolledUpCaptions = new LinkedList<>();
rolledUpCaptions = new ArrayList<>();
captionStringBuilder = new SpannableStringBuilder();
reset(captionMode, captionRowCount);
reset(captionMode);
setCaptionRowCount(captionRowCount);
}

public void reset(int captionMode, int captionRowCount) {
public void reset(int captionMode) {
this.captionMode = captionMode;
preambleStyles.clear();
midrowStyles.clear();
rolledUpCaptions.clear();
captionStringBuilder.clear();
row = BASE_ROW;
indent = 0;
tabOffset = 0;
this.captionMode = captionMode;
this.captionRowCount = captionRowCount;
underlineStartPosition = POSITION_UNSET;
}

public void setCaptionRowCount(int captionRowCount) {
this.captionRowCount = captionRowCount;
}

public boolean isEmpty() {
return preambleStyles.isEmpty() && midrowStyles.isEmpty() && rolledUpCaptions.isEmpty()
&& captionStringBuilder.length() == 0;
Expand Down

0 comments on commit a8298b4

Please # to comment.