Fix E-AC3 format propagation
Issue: Issue: #7611 PiperOrigin-RevId: 324884412
This commit is contained in:
parent
8da7fc7d2f
commit
c0ee267a6c
@ -631,6 +631,13 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
throws ExoPlaybackException {
|
throws ExoPlaybackException {
|
||||||
boolean outputFormatChanged = false;
|
boolean outputFormatChanged = false;
|
||||||
@Nullable Format format = formatQueue.pollFloor(presentationTimeUs);
|
@Nullable Format format = formatQueue.pollFloor(presentationTimeUs);
|
||||||
|
if (format == null && codecOutputMediaFormatChanged) {
|
||||||
|
// If the codec's output MediaFormat has changed then there should be a corresponding Format
|
||||||
|
// change, which we've not found. Check the Format queue in case the corresponding
|
||||||
|
// presentation timestamp is greater than presentationTimeUs, which can happen for some codecs
|
||||||
|
// [Internal ref: b/162719047].
|
||||||
|
format = formatQueue.pollFirst();
|
||||||
|
}
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
outputFormat = format;
|
outputFormat = format;
|
||||||
outputFormatChanged = true;
|
outputFormatChanged = true;
|
||||||
|
@ -62,6 +62,12 @@ public final class TimedValueQueue<V> {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes and returns the first value in the queue, or null if the queue is empty. */
|
||||||
|
@Nullable
|
||||||
|
public synchronized V pollFirst() {
|
||||||
|
return size == 0 ? null : popFirst();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value with the greatest timestamp which is less than or equal to the given
|
* Returns the value with the greatest timestamp which is less than or equal to the given
|
||||||
* timestamp. Removes all older values and the returned one from the buffer.
|
* timestamp. Removes all older values and the returned one from the buffer.
|
||||||
@ -71,7 +77,8 @@ public final class TimedValueQueue<V> {
|
|||||||
* timestamp or null if there is no such value.
|
* timestamp or null if there is no such value.
|
||||||
* @see #poll(long)
|
* @see #poll(long)
|
||||||
*/
|
*/
|
||||||
public synchronized @Nullable V pollFloor(long timestamp) {
|
@Nullable
|
||||||
|
public synchronized V pollFloor(long timestamp) {
|
||||||
return poll(timestamp, /* onlyOlder= */ true);
|
return poll(timestamp, /* onlyOlder= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +90,8 @@ public final class TimedValueQueue<V> {
|
|||||||
* @return The value with the closest timestamp or null if the buffer is empty.
|
* @return The value with the closest timestamp or null if the buffer is empty.
|
||||||
* @see #pollFloor(long)
|
* @see #pollFloor(long)
|
||||||
*/
|
*/
|
||||||
public synchronized @Nullable V poll(long timestamp) {
|
@Nullable
|
||||||
|
public synchronized V poll(long timestamp) {
|
||||||
return poll(timestamp, /* onlyOlder= */ false);
|
return poll(timestamp, /* onlyOlder= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +107,7 @@ public final class TimedValueQueue<V> {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private V poll(long timestamp, boolean onlyOlder) {
|
private V poll(long timestamp, boolean onlyOlder) {
|
||||||
V value = null;
|
@Nullable V value = null;
|
||||||
long previousTimeDiff = Long.MAX_VALUE;
|
long previousTimeDiff = Long.MAX_VALUE;
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
long timeDiff = timestamp - timestamps[first];
|
long timeDiff = timestamp - timestamps[first];
|
||||||
@ -107,14 +115,21 @@ public final class TimedValueQueue<V> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
previousTimeDiff = timeDiff;
|
previousTimeDiff = timeDiff;
|
||||||
value = values[first];
|
value = popFirst();
|
||||||
values[first] = null;
|
|
||||||
first = (first + 1) % values.length;
|
|
||||||
size--;
|
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private V popFirst() {
|
||||||
|
Assertions.checkState(size > 0);
|
||||||
|
@Nullable V value = values[first];
|
||||||
|
values[first] = null;
|
||||||
|
first = (first + 1) % values.length;
|
||||||
|
size--;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
private void clearBufferOnTimeDiscontinuity(long timestamp) {
|
private void clearBufferOnTimeDiscontinuity(long timestamp) {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
int last = (first + size - 1) % values.length;
|
int last = (first + size - 1) % values.length;
|
||||||
@ -131,7 +146,7 @@ public final class TimedValueQueue<V> {
|
|||||||
}
|
}
|
||||||
int newCapacity = capacity * 2;
|
int newCapacity = capacity * 2;
|
||||||
long[] newTimestamps = new long[newCapacity];
|
long[] newTimestamps = new long[newCapacity];
|
||||||
V[] newValues = newArray(newCapacity);
|
@NullableType V[] newValues = newArray(newCapacity);
|
||||||
// Reset the loop starting index to 0 while coping to the new buffer.
|
// Reset the loop starting index to 0 while coping to the new buffer.
|
||||||
// First copy the values from 'first' index to the end of original array.
|
// First copy the values from 'first' index to the end of original array.
|
||||||
int length = capacity - first;
|
int length = capacity - first;
|
||||||
@ -155,7 +170,7 @@ public final class TimedValueQueue<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static <V> V[] newArray(int length) {
|
private static <V> @NullableType V[] newArray(int length) {
|
||||||
return (V[]) new Object[length];
|
return (V[]) new Object[length];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,23 +33,13 @@ public class TimedValueQueueTest {
|
|||||||
queue = new TimedValueQueue<>();
|
queue = new TimedValueQueue<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAndPollValues() {
|
|
||||||
queue.add(0, "a");
|
|
||||||
queue.add(1, "b");
|
|
||||||
queue.add(2, "c");
|
|
||||||
assertThat(queue.poll(0)).isEqualTo("a");
|
|
||||||
assertThat(queue.poll(1)).isEqualTo("b");
|
|
||||||
assertThat(queue.poll(2)).isEqualTo("c");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bufferCapacityIncreasesAutomatically() {
|
public void bufferCapacityIncreasesAutomatically() {
|
||||||
queue = new TimedValueQueue<>(1);
|
queue = new TimedValueQueue<>(1);
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
queue.add(i, "" + i);
|
queue.add(i, "" + i);
|
||||||
if ((i & 1) == 1) {
|
if ((i & 1) == 1) {
|
||||||
assertThat(queue.poll(0)).isEqualTo("" + (i / 2));
|
assertThat(queue.pollFirst()).isEqualTo("" + (i / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertThat(queue.size()).isEqualTo(10);
|
assertThat(queue.size()).isEqualTo(10);
|
||||||
@ -61,7 +51,7 @@ public class TimedValueQueueTest {
|
|||||||
queue.add(2, "c");
|
queue.add(2, "c");
|
||||||
queue.add(0, "a");
|
queue.add(0, "a");
|
||||||
assertThat(queue.size()).isEqualTo(1);
|
assertThat(queue.size()).isEqualTo(1);
|
||||||
assertThat(queue.poll(0)).isEqualTo("a");
|
assertThat(queue.pollFirst()).isEqualTo("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -71,7 +61,37 @@ public class TimedValueQueueTest {
|
|||||||
queue.add(3, "c");
|
queue.add(3, "c");
|
||||||
queue.add(2, "a");
|
queue.add(2, "a");
|
||||||
assertThat(queue.size()).isEqualTo(1);
|
assertThat(queue.size()).isEqualTo(1);
|
||||||
assertThat(queue.poll(2)).isEqualTo("a");
|
assertThat(queue.pollFirst()).isEqualTo("a");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pollFirstReturnsValues() {
|
||||||
|
queue.add(0, "a");
|
||||||
|
queue.add(1, "b");
|
||||||
|
queue.add(2, "c");
|
||||||
|
assertThat(queue.pollFirst()).isEqualTo("a");
|
||||||
|
assertThat(queue.size()).isEqualTo(2);
|
||||||
|
assertThat(queue.pollFirst()).isEqualTo("b");
|
||||||
|
assertThat(queue.size()).isEqualTo(1);
|
||||||
|
assertThat(queue.pollFirst()).isEqualTo("c");
|
||||||
|
assertThat(queue.size()).isEqualTo(0);
|
||||||
|
assertThat(queue.pollFirst()).isEqualTo(null);
|
||||||
|
assertThat(queue.size()).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pollReturnsValues() {
|
||||||
|
queue.add(0, "a");
|
||||||
|
queue.add(1, "b");
|
||||||
|
queue.add(2, "c");
|
||||||
|
assertThat(queue.poll(0)).isEqualTo("a");
|
||||||
|
assertThat(queue.size()).isEqualTo(2);
|
||||||
|
assertThat(queue.poll(1)).isEqualTo("b");
|
||||||
|
assertThat(queue.size()).isEqualTo(1);
|
||||||
|
assertThat(queue.poll(2)).isEqualTo("c");
|
||||||
|
assertThat(queue.size()).isEqualTo(0);
|
||||||
|
assertThat(queue.pollFirst()).isEqualTo(null);
|
||||||
|
assertThat(queue.size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user