Skip to content

Commit

Permalink
Strip private ID3 data from HLS sample formats
Browse files Browse the repository at this point in the history
Issue: #5063
PiperOrigin-RevId: 222975020
  • Loading branch information
ojw28 authored and andrewlewis committed Nov 27, 2018
1 parent 6819192 commit 1ce3336
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
7 changes: 5 additions & 2 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

### dev-v2 (not yet released) ###

* HLS: Fix issue causing unnecessary media playlist requests when playing live
streams ([#5059](https://github.com/google/ExoPlayer/issues/5059)).
* HLS:
* Fix issue causing unnecessary media playlist requests when playing live
streams ([#5059](https://github.com/google/ExoPlayer/issues/5059)).
* Fix decoder re-instantiation issue for packed audio streams
([#5063](https://github.com/google/ExoPlayer/issues/5063)).
* MP4: Support Opus and FLAC in the MP4 container, and in DASH
([#4883](https://github.com/google/ExoPlayer/issues/4883)).
* DASH: Fix detecting the end of live events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;

/**
* A queue of media samples.
*/
public final class SampleQueue implements TrackOutput {
/** A queue of media samples. */
public class SampleQueue implements TrackOutput {

/**
* A listener for changes to the upstream format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
/* package */ final class HlsMediaChunk extends MediaChunk {

private static final String PRIV_TIMESTAMP_FRAME_OWNER =
public static final String PRIV_TIMESTAMP_FRAME_OWNER =
"com.apple.streaming.transportStreamTimestamp";

private static final AtomicInteger uidSource = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.hls;

import android.os.Handler;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
Expand All @@ -24,6 +25,8 @@
import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.id3.PrivFrame;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.SampleQueue.UpstreamFormatChangedListener;
Expand Down Expand Up @@ -791,7 +794,7 @@ public TrackOutput track(int id, int type) {
return createDummyTrackOutput(id, type);
}
}
SampleQueue trackOutput = new SampleQueue(allocator);
SampleQueue trackOutput = new PrivTimestampStrippingSampleQueue(allocator);
trackOutput.setSampleOffsetUs(sampleOffsetUs);
trackOutput.sourceId(chunkUid);
trackOutput.setUpstreamFormatChangeListener(this);
Expand Down Expand Up @@ -1126,4 +1129,53 @@ private static DummyTrackOutput createDummyTrackOutput(int id, int type) {
Log.w(TAG, "Unmapped track with id " + id + " of type " + type);
return new DummyTrackOutput();
}

private static final class PrivTimestampStrippingSampleQueue extends SampleQueue {

public PrivTimestampStrippingSampleQueue(Allocator allocator) {
super(allocator);
}

@Override
public void format(Format format) {
super.format(format.copyWithMetadata(getAdjustedMetadata(format.metadata)));
}

/**
* Strips the private timestamp frame from metadata, if present. See:
* https://github.com/google/ExoPlayer/issues/5063
*/
@Nullable
private Metadata getAdjustedMetadata(@Nullable Metadata metadata) {
if (metadata == null) {
return null;
}
int length = metadata.length();
int transportStreamTimestampMetadataIndex = C.INDEX_UNSET;
for (int i = 0; i < length; i++) {
Metadata.Entry metadataEntry = metadata.get(i);
if (metadataEntry instanceof PrivFrame) {
PrivFrame privFrame = (PrivFrame) metadataEntry;
if (HlsMediaChunk.PRIV_TIMESTAMP_FRAME_OWNER.equals(privFrame.owner)) {
transportStreamTimestampMetadataIndex = i;
break;
}
}
}
if (transportStreamTimestampMetadataIndex == C.INDEX_UNSET) {
return metadata;
}
if (length == 1) {
return null;
}
Metadata.Entry[] newMetadataEntries = new Metadata.Entry[length - 1];
for (int i = 0; i < length; i++) {
if (i != transportStreamTimestampMetadataIndex) {
int newIndex = i < transportStreamTimestampMetadataIndex ? i : i - 1;
newMetadataEntries[newIndex] = metadata.get(i);
}
}
return new Metadata(newMetadataEntries);
}
}
}

0 comments on commit 1ce3336

Please sign in to comment.