Skip to content

Multi Period SSAI DASH MediaTailor and others Crash error 1000 ERROR_CODE_UNSPECIFIED #3550

Open

Description

@Iragne

Version

Media3 main branch

More version details

all version we tested till 1.9.2

Devices that reproduce the issue

All

Devices that do not reproduce the issue

None

Reproducible in the demo app?

Yes

Reproduction steps

In SSAI context we can have the following update manifest with period [A] [B] [C] [D] then [C] [D]
This create an index out of bound exception.

Expected result

Playback should work not stop and crash

Actual result

It's crashing

Media

I have a use case with unit test and a patch. I will create a pr.
We found additional use case that may rarely happens but we also have a fix too

Bug Report

Activity

  1. Iragne commented on Nov 14, 2026

    @Iragne
    Author

    Propose PR that will write share later today

    private static int getRemovedPeriodCount(
          @Nullable DashManifest oldManifest,
          DashManifest newManifest) {
    
        // Initial manifest load.
        if (oldManifest == null) {
          return 0;
        }
    
        int oldCount = oldManifest.getPeriodCount();
        int newCount = newManifest.getPeriodCount();
    
        if (oldCount == 0 || newCount == 0) {
          return 0;
        }
    
        String firstNewId = newManifest.getPeriod(0).id;
    
        // Find the new first Period in the previous manifest.
        // DASH Periods are ordered; removed Periods form a prefix.
        if (firstNewId != null) {
          for (int oldIndex = 0; oldIndex < oldCount; oldIndex++) {
    
            if (!firstNewId.equals(oldManifest.getPeriod(oldIndex).id)) {
              continue;
            }
    
            // Validate the entire overlapping sequence.
            int overlap = Math.min(oldCount - oldIndex, newCount);
            boolean valid = true;
    
            for (int i = 0; i < overlap; i++) {
              String oldId = oldManifest.getPeriod(oldIndex + i).id;
              String newId = newManifest.getPeriod(i).id;
    
              if (oldId == null || !oldId.equals(newId)) {
                valid = false;
                break;
              }
            }
    
            if (valid) {
              return oldIndex;
            }
    
            // Same first ID but inconsistent subsequent Periods.
            // Do not trust the overlap calculation.
            break;
          }
        }
    
        // Original Media3 timestamp-based fallback.
        long newFirstStartMs = newManifest.getPeriod(0).startMs;
        int removedCount = 0;
    
        while (removedCount < oldCount
            && oldManifest.getPeriod(removedCount).startMs < newFirstStartMs) {
          removedCount++;
        }
    
        return removedCount;
      }
    
    /* package */ void onManifestLoadCompleted(
          ParsingLoadable<DashManifest> loadable, long elapsedRealtimeMs, long loadDurationMs) {
        LoadEventInfo loadEventInfo =
            new LoadEventInfo(
                loadable.loadTaskId,
                loadable.dataSpec,
                loadable.getUri(),
                loadable.getResponseHeaders(),
                elapsedRealtimeMs,
                loadDurationMs,
                loadable.bytesLoaded());
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
        manifestEventDispatcher.loadCompleted(loadEventInfo, loadable.type);
        DashManifest newManifest = loadable.getResult();
    
        if (newManifest == null) {
          Log.w(TAG, "DASH manifest update skipped: parsed manifest is null");
          return;
        }
        int oldPeriodCount = manifest == null ? 0 : manifest.getPeriodCount();
        int removedPeriodCount = getRemovedPeriodCount(manifest, newManifest);
    
        if (newManifest.dynamic) {
          boolean isManifestStale = false;
          if (oldPeriodCount - removedPeriodCount > newManifest.getPeriodCount()) {
            Log.w(TAG,
                "DASH manifest Period count reduced unexpectedly"
                    + ": oldPeriodCount=" + oldPeriodCount
                    + ", removedPeriodCount=" + removedPeriodCount
                    + ", newPeriodCount=" + newManifest.getPeriodCount());
            // Do not set isManifestStale here.
            // A reduction in Period count alone does not prove
            // that the new manifest is stale.
          } else if (expiredManifestPublishTimeUs != C.TIME_UNSET
              && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs) {
            // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
            // expired, or it's dynamic and we know the presentation has ended), then this manifest is
            // stale.
            Log.w(
                TAG,
                "Loaded stale dynamic manifest: "
                    + newManifest.publishTimeMs
                    + ", "
                    + expiredManifestPublishTimeUs);
            isManifestStale = true;
          }

    and

    @Override
      public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
    
        // Keep Media3's normal Period index handling.
        List<AdaptationSet> sets =
            newManifest.getPeriod(newPeriodIndex).adaptationSets;
    
        List<Representation> representations = new ArrayList<>();
    
        for (int index : adaptationSetIndices) {
          if (index < 0 || index >= sets.size()) {
            Log.w(TAG, "DASH update skipped: missing AdaptationSet " + index);
            return;
          }
          representations.addAll(sets.get(index).representations);
        }
    
        for (int i = 0; i < representationHolders.length; i++) {
          int index = trackSelection.getIndexInTrackGroup(i);
          if (index < 0 || index >= representations.size()) {
            Log.w(TAG, "DASH update skipped: missing Representation " + index);
            return;
          }
        }
    
        try {
          long durationUs = newManifest.getPeriodDurationUs(newPeriodIndex);
          RepresentationHolder[] updated = representationHolders.clone();
    
          for (int i = 0; i < updated.length; i++) {
            updated[i] = representationHolders[i].copyWithNewRepresentation(
                durationUs,
                representations.get(trackSelection.getIndexInTrackGroup(i)));
          }
    
          manifest = newManifest;
          periodIndex = newPeriodIndex;
          System.arraycopy(updated, 0, representationHolders, 0, updated.length);
    
        } catch (BehindLiveWindowException e) {
          fatalError = e;
        }
      }
  2. Iragne commented on Nov 17, 2026

    @Iragne
    Author

    Sorry late on the PR it will be for today

  3. Iragne commented on Nov 17, 2026

    @Iragne
    Author

    Here you have my PR @tonihei and @oceanjules

  4. Iragne commented on Nov 20, 2026

    @Iragne
    Author

    @oceanjules or @tonihei please let me know if you are fine with it ;)

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions