|
16 | 16 | package androidx.media3.exoplayer.mediacodec; |
17 | 17 |
|
18 | 18 | import static androidx.media3.common.MimeTypes.AUDIO_AAC; |
| 19 | +import static androidx.media3.common.MimeTypes.AUDIO_AC4; |
| 20 | +import static androidx.media3.common.MimeTypes.AUDIO_E_AC3; |
| 21 | +import static androidx.media3.common.MimeTypes.AUDIO_E_AC3_JOC; |
19 | 22 | import static androidx.media3.common.MimeTypes.VIDEO_AV1; |
20 | 23 | import static androidx.media3.common.MimeTypes.VIDEO_H264; |
21 | 24 | import static androidx.media3.exoplayer.DecoderReuseEvaluation.DISCARD_REASON_AUDIO_CHANNEL_COUNT_CHANGED; |
@@ -74,6 +77,31 @@ public final class MediaCodecInfoTest { |
74 | 77 | .setInitializationData(ImmutableList.of(new byte[] {4, 4, 1, 0, 0})) |
75 | 78 | .build(); |
76 | 79 |
|
| 80 | + private static final Format FORMAT_EAC3 = |
| 81 | + new Format.Builder() |
| 82 | + .setSampleMimeType(AUDIO_E_AC3) |
| 83 | + .setChannelCount(6) |
| 84 | + .setSampleRate(48000) |
| 85 | + .setAverageBitrate(5000) |
| 86 | + .build(); |
| 87 | + |
| 88 | + private static final Format FORMAT_EAC3JOC = |
| 89 | + new Format.Builder() |
| 90 | + .setSampleMimeType(AUDIO_E_AC3_JOC) |
| 91 | + .setChannelCount(12) |
| 92 | + .setSampleRate(48000) |
| 93 | + .setAverageBitrate(5000) |
| 94 | + .build(); |
| 95 | + |
| 96 | + private static final Format FORMAT_AC4 = |
| 97 | + new Format.Builder() |
| 98 | + .setSampleMimeType(AUDIO_AC4) |
| 99 | + .setCodecs("ac-4.02.01.01") |
| 100 | + .setChannelCount(21) |
| 101 | + .setSampleRate(48000) |
| 102 | + .setAverageBitrate(5000) |
| 103 | + .build(); |
| 104 | + |
77 | 105 | @Test |
78 | 106 | public void canReuseCodec_withDifferentMimeType_returnsNo() { |
79 | 107 | MediaCodecInfo codecInfo = buildH264CodecInfo(/* adaptive= */ true); |
@@ -318,6 +346,87 @@ public void canReuseCodec_differentVideoCrop_returnsNo() { |
318 | 346 | DISCARD_REASON_WORKAROUND)); |
319 | 347 | } |
320 | 348 |
|
| 349 | + @Test |
| 350 | + public void canReuseCodec_eac3_returnsYesWithoutReconfiguration() { |
| 351 | + MediaCodecInfo codecInfo = |
| 352 | + new MediaCodecInfo( |
| 353 | + "eac3joc", |
| 354 | + AUDIO_E_AC3, |
| 355 | + AUDIO_E_AC3, |
| 356 | + /* capabilities= */ null, |
| 357 | + /* hardwareAccelerated= */ false, |
| 358 | + /* softwareOnly= */ true, |
| 359 | + /* vendor= */ true, |
| 360 | + /* adaptive= */ false, |
| 361 | + /* tunneling= */ false, |
| 362 | + /* secure= */ false, |
| 363 | + /* detachedSurfaceSupported= */ false); |
| 364 | + |
| 365 | + assertThat(codecInfo.canReuseCodec(FORMAT_EAC3, FORMAT_EAC3)) |
| 366 | + .isEqualTo( |
| 367 | + new DecoderReuseEvaluation( |
| 368 | + codecInfo.name, |
| 369 | + FORMAT_EAC3, |
| 370 | + FORMAT_EAC3, |
| 371 | + DecoderReuseEvaluation.REUSE_RESULT_YES_WITHOUT_RECONFIGURATION, |
| 372 | + /* discardReasons= */ 0)); |
| 373 | + } |
| 374 | + |
| 375 | + @Test |
| 376 | + public void canReuseCodec_eac3joc_returnsYesWithoutReconfiguration() { |
| 377 | + MediaCodecInfo codecInfo = |
| 378 | + new MediaCodecInfo( |
| 379 | + "eac3joc", |
| 380 | + AUDIO_E_AC3_JOC, |
| 381 | + AUDIO_E_AC3_JOC, |
| 382 | + /* capabilities= */ null, |
| 383 | + /* hardwareAccelerated= */ false, |
| 384 | + /* softwareOnly= */ true, |
| 385 | + /* vendor= */ true, |
| 386 | + /* adaptive= */ false, |
| 387 | + /* tunneling= */ false, |
| 388 | + /* secure= */ false, |
| 389 | + /* detachedSurfaceSupported= */ false); |
| 390 | + |
| 391 | + assertThat(codecInfo.canReuseCodec(FORMAT_EAC3JOC, FORMAT_EAC3JOC)) |
| 392 | + .isEqualTo( |
| 393 | + new DecoderReuseEvaluation( |
| 394 | + codecInfo.name, |
| 395 | + FORMAT_EAC3JOC, |
| 396 | + FORMAT_EAC3JOC, |
| 397 | + DecoderReuseEvaluation.REUSE_RESULT_YES_WITHOUT_RECONFIGURATION, |
| 398 | + /* discardReasons= */ 0)); |
| 399 | + } |
| 400 | + |
| 401 | + @Test |
| 402 | + public void canReuseCodec_ac4_returnsYesWithoutReconfiguration() { |
| 403 | + MediaCodecInfo codecInfo = buildAc4CodecInfo(); |
| 404 | + |
| 405 | + assertThat(codecInfo.canReuseCodec(FORMAT_AC4, FORMAT_AC4)) |
| 406 | + .isEqualTo( |
| 407 | + new DecoderReuseEvaluation( |
| 408 | + codecInfo.name, |
| 409 | + FORMAT_AC4, |
| 410 | + FORMAT_AC4, |
| 411 | + DecoderReuseEvaluation.REUSE_RESULT_YES_WITHOUT_RECONFIGURATION, |
| 412 | + /* discardReasons= */ 0)); |
| 413 | + } |
| 414 | + |
| 415 | + @Test |
| 416 | + public void canReuseCodec_ac4WithDifferentCodecs_returnsYesWithFlush() { |
| 417 | + MediaCodecInfo codecInfo = buildAc4CodecInfo(); |
| 418 | + |
| 419 | + Format ac4VariantFormat = FORMAT_AC4.buildUpon().setCodecs("ac-4.02.01.03").build(); |
| 420 | + assertThat(codecInfo.canReuseCodec(FORMAT_AC4, ac4VariantFormat)) |
| 421 | + .isEqualTo( |
| 422 | + new DecoderReuseEvaluation( |
| 423 | + codecInfo.name, |
| 424 | + FORMAT_AC4, |
| 425 | + ac4VariantFormat, |
| 426 | + REUSE_RESULT_YES_WITH_FLUSH, |
| 427 | + /* discardReasons= */ 0)); |
| 428 | + } |
| 429 | + |
321 | 430 | private static MediaCodecInfo buildH264CodecInfo(boolean adaptive) { |
322 | 431 | return new MediaCodecInfo( |
323 | 432 | "h264", |
@@ -348,6 +457,21 @@ private static MediaCodecInfo buildAacCodecInfo() { |
348 | 457 | /* detachedSurfaceSupported= */ false); |
349 | 458 | } |
350 | 459 |
|
| 460 | + private static MediaCodecInfo buildAc4CodecInfo() { |
| 461 | + return new MediaCodecInfo( |
| 462 | + "ac4", |
| 463 | + AUDIO_AC4, |
| 464 | + AUDIO_AC4, |
| 465 | + /* capabilities= */ null, |
| 466 | + /* hardwareAccelerated= */ false, |
| 467 | + /* softwareOnly= */ true, |
| 468 | + /* vendor= */ true, |
| 469 | + /* adaptive= */ false, |
| 470 | + /* tunneling= */ false, |
| 471 | + /* secure= */ false, |
| 472 | + /* detachedSurfaceSupported= */ false); |
| 473 | + } |
| 474 | + |
351 | 475 | private static ColorInfo buildHdrColorInfo(@C.ColorSpace int colorSpace) { |
352 | 476 | return new ColorInfo.Builder() |
353 | 477 | .setColorSpace(colorSpace) |
|
0 commit comments