Skip to content

HLS CMCD is causing exception for encrypted content #2312

Description

@TheAwesomeGem

Version

Media3 1.6.0

More version details

Looks like these changes from 1.6: 8d2f531

is causing issue where the assert for chunkDurationMs being unset is being triggered:

CmcdData.java:256

boolean isMediaObjectType = isMediaObjectType(objectType);
      if (isMediaObjectType) {
        checkState(bufferedDurationUs != C.TIME_UNSET, "Buffered duration must be set");
        checkState(chunkDurationUs != C.TIME_UNSET, "Chunk duration must be set");
      }

This is due to the segment being a media segment and encrypted which calls this method inside HlsChunkSource.java

@Nullable
  private Chunk maybeCreateEncryptionChunkFor(
      @Nullable Uri keyUri,
      int selectedTrackIndex,
      boolean isInitSegment,
      @Nullable CmcdData.Factory cmcdDataFactory) {
    if (keyUri == null) {
      return null;
    }

    @Nullable byte[] encryptionKey = keyCache.remove(keyUri);
    if (encryptionKey != null) {
      // The key was present in the key cache. We re-insert it to prevent it from being evicted by
      // the following key addition. Note that removal of the key is necessary to affect the
      // eviction order.
      keyCache.put(keyUri, encryptionKey);
      return null;
    }

    DataSpec dataSpec =
        new DataSpec.Builder().setUri(keyUri).setFlags(DataSpec.FLAG_ALLOW_GZIP).build();
    if (cmcdDataFactory != null) {
      if (isInitSegment) {
        cmcdDataFactory.setObjectType(CmcdData.OBJECT_TYPE_INIT_SEGMENT);
      }
      CmcdData cmcdData = cmcdDataFactory.createCmcdData();
      dataSpec = cmcdData.addToDataSpec(dataSpec);
    }

As you can see, setChunkDurationUs is not set there causing the assertion for encrypted media segment.

For non encrypted media segment, it's properly being set here in HlsMediaChunk.java here:

if (cmcdDataFactory != null) {
      CmcdData cmcdData =
          cmcdDataFactory.setChunkDurationUs(mediaSegment.durationUs).createCmcdData();
      dataSpec = cmcdData.addToDataSpec(dataSpec);
    }

Devices that reproduce the issue

  • Pixel 7 Pro Android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

The demo app doesn't contain encrypted HLS media.

Expected result

Media3 should be able to load encrypted media 3 successfully with CMCD config.

Actual result

It crashes due to the "Chunk duration must be set" assertion.

Media

I am unable to provide proper encrypted hls stream but I can email them.

Bug Report

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions