Don't include null text or bitmaps in Cue.toBundle()

`fromBundle` doesn't distinguish between `FIELD_BITMAP` and `FIELD_TEXT`
being present with a null value, or being absent, so we might as well
avoid including them when the value is null.

I've separated this from a later change to add
`Cue.toSerializableBundle` which will also skip setting a bitmap value
into the `Bundle` if `this.bitmap == null`. This is partly because it
results in changes to a lot of extractor test dump files, and it's
easier to review that as a separate change.

PiperOrigin-RevId: 586626141
This commit is contained in:
ibaker 2023-11-30 03:56:15 -08:00 committed by Copybara-Service
parent 03564fdbc6
commit 28c210686f
21 changed files with 70 additions and 66 deletions

View File

@ -851,16 +851,20 @@ public final class Cue implements Bundleable {
@Override
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putCharSequence(FIELD_TEXT, text);
if (text instanceof Spanned) {
ArrayList<Bundle> customSpanBundles = bundleCustomSpans((Spanned) text);
if (!customSpanBundles.isEmpty()) {
bundle.putParcelableArrayList(FIELD_CUSTOM_SPANS, customSpanBundles);
if (text != null) {
bundle.putCharSequence(FIELD_TEXT, text);
if (text instanceof Spanned) {
ArrayList<Bundle> customSpanBundles = bundleCustomSpans((Spanned) text);
if (!customSpanBundles.isEmpty()) {
bundle.putParcelableArrayList(FIELD_CUSTOM_SPANS, customSpanBundles);
}
}
}
bundle.putSerializable(FIELD_TEXT_ALIGNMENT, textAlignment);
bundle.putSerializable(FIELD_MULTI_ROW_ALIGNMENT, multiRowAlignment);
bundle.putParcelable(FIELD_BITMAP, bitmap);
if (bitmap != null) {
bundle.putParcelable(FIELD_BITMAP, bitmap);
}
bundle.putFloat(FIELD_LINE, line);
bundle.putInt(FIELD_LINE_TYPE, lineType);
bundle.putInt(FIELD_LINE_ANCHOR, lineAnchor);

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3017
total output bytes = 2954
sample count = 3
format 0:
id = 3
@ -278,13 +278,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 1002, hash 83D96DE7
data = length 981, hash 3A70FBFA
sample 1:
time = 150000
flags = 1
data = length 1007, hash BFF2DCF4
data = length 986, hash 8CA3E471
sample 2:
time = 200000
flags = 1
data = length 1008, hash 2B5F6191
data = length 987, hash 156157B4
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3017
total output bytes = 2954
sample count = 3
format 0:
id = 3
@ -278,13 +278,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 1002, hash 83D96DE7
data = length 981, hash 3A70FBFA
sample 1:
time = 150000
flags = 1
data = length 1007, hash BFF2DCF4
data = length 986, hash 8CA3E471
sample 2:
time = 200000
flags = 1
data = length 1008, hash 2B5F6191
data = length 987, hash 156157B4
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3017
total output bytes = 2954
sample count = 3
format 0:
id = 3
@ -278,13 +278,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 1002, hash 83D96DE7
data = length 981, hash 3A70FBFA
sample 1:
time = 150000
flags = 1
data = length 1007, hash BFF2DCF4
data = length 986, hash 8CA3E471
sample 2:
time = 200000
flags = 1
data = length 1008, hash 2B5F6191
data = length 987, hash 156157B4
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3017
total output bytes = 2954
sample count = 3
format 0:
id = 3
@ -278,13 +278,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 1002, hash 83D96DE7
data = length 981, hash 3A70FBFA
sample 1:
time = 150000
flags = 1
data = length 1007, hash BFF2DCF4
data = length 986, hash 8CA3E471
sample 2:
time = 200000
flags = 1
data = length 1008, hash 2B5F6191
data = length 987, hash 156157B4
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3017
total output bytes = 2954
sample count = 3
format 0:
id = 3
@ -278,13 +278,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 1002, hash 83D96DE7
data = length 981, hash 3A70FBFA
sample 1:
time = 150000
flags = 1
data = length 1007, hash BFF2DCF4
data = length 986, hash 8CA3E471
sample 2:
time = 200000
flags = 1
data = length 1008, hash 2B5F6191
data = length 987, hash 156157B4
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3002
total output bytes = 2939
sample count = 3
format 0:
id = 3
@ -281,13 +281,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 997, hash A1198858
data = length 976, hash 91D1729
sample 1:
time = 150000
flags = 1
data = length 1002, hash E686A781
data = length 981, hash 1B9102A8
sample 2:
time = 200000
flags = 1
data = length 1003, hash 27A316D2
data = length 982, hash 263F7393
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3002
total output bytes = 2939
sample count = 3
format 0:
id = 3
@ -281,13 +281,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 997, hash A1198858
data = length 976, hash 91D1729
sample 1:
time = 150000
flags = 1
data = length 1002, hash E686A781
data = length 981, hash 1B9102A8
sample 2:
time = 200000
flags = 1
data = length 1003, hash 27A316D2
data = length 982, hash 263F7393
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3002
total output bytes = 2939
sample count = 3
format 0:
id = 3
@ -281,13 +281,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 997, hash A1198858
data = length 976, hash 91D1729
sample 1:
time = 150000
flags = 1
data = length 1002, hash E686A781
data = length 981, hash 1B9102A8
sample 2:
time = 200000
flags = 1
data = length 1003, hash 27A316D2
data = length 982, hash 263F7393
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3002
total output bytes = 2939
sample count = 3
format 0:
id = 3
@ -281,13 +281,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 997, hash A1198858
data = length 976, hash 91D1729
sample 1:
time = 150000
flags = 1
data = length 1002, hash E686A781
data = length 981, hash 1B9102A8
sample 2:
time = 200000
flags = 1
data = length 1003, hash 27A316D2
data = length 982, hash 263F7393
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 3002
total output bytes = 2939
sample count = 3
format 0:
id = 3
@ -281,13 +281,13 @@ track 3:
sample 0:
time = 100000
flags = 1
data = length 997, hash A1198858
data = length 976, hash 91D1729
sample 1:
time = 150000
flags = 1
data = length 1002, hash E686A781
data = length 981, hash 1B9102A8
sample 2:
time = 200000
flags = 1
data = length 1003, hash 27A316D2
data = length 982, hash 263F7393
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 993
total output bytes = 972
sample count = 1
format 0:
id = 3
@ -279,5 +279,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 993, hash E926FD1E
data = length 972, hash 8E8A2E4B
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 993
total output bytes = 972
sample count = 1
format 0:
id = 3
@ -279,5 +279,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 993, hash E926FD1E
data = length 972, hash 8E8A2E4B
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 993
total output bytes = 972
sample count = 1
format 0:
id = 3
@ -279,5 +279,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 993, hash E926FD1E
data = length 972, hash 8E8A2E4B
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 993
total output bytes = 972
sample count = 1
format 0:
id = 3
@ -279,5 +279,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 993, hash E926FD1E
data = length 972, hash 8E8A2E4B
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 993
total output bytes = 972
sample count = 1
format 0:
id = 3
@ -279,5 +279,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 993, hash E926FD1E
data = length 972, hash 8E8A2E4B
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 1280
total output bytes = 1259
sample count = 1
format 0:
id = 3
@ -281,5 +281,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 1280, hash EEF152A1
data = length 1259, hash C880769E
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 1280
total output bytes = 1259
sample count = 1
format 0:
id = 3
@ -281,5 +281,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 1280, hash EEF152A1
data = length 1259, hash C880769E
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 1280
total output bytes = 1259
sample count = 1
format 0:
id = 3
@ -281,5 +281,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 1280, hash EEF152A1
data = length 1259, hash C880769E
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 1280
total output bytes = 1259
sample count = 1
format 0:
id = 3
@ -281,5 +281,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 1280, hash EEF152A1
data = length 1259, hash C880769E
tracksEnded = true

View File

@ -267,7 +267,7 @@ track 2:
flags = 1
data = length 418, hash 56AB8D37
track 3:
total output bytes = 1280
total output bytes = 1259
sample count = 1
format 0:
id = 3
@ -281,5 +281,5 @@ track 3:
sample 0:
time = 0
flags = 1
data = length 1280, hash EEF152A1
data = length 1259, hash C880769E
tracksEnded = true