Skip to content

Commit e284a79

Browse files
committed
Add protected methods to ConstantBitrateSeekMap instead of intercepting values in the constructor
1 parent 8bd337b commit e284a79

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

libraries/extractor/src/main/java/androidx/media3/extractor/ConstantBitrateSeekMap.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,32 @@ public long getTimeUsAtPosition(long position) {
166166
return getTimeUsAtPosition(position, firstFrameBytePosition, bitrate);
167167
}
168168

169+
/** Returns the byte position of the first frame in the stream (as passed to the constructor). */
170+
protected final long getFirstFramePosition() {
171+
return firstFrameBytePosition;
172+
}
173+
174+
/**
175+
* Returns the size of each frame in the stream in bytes, or {@code 1} if {@link C#LENGTH_UNSET}
176+
* was passed to the constructor.
177+
*/
178+
protected final int getFrameSize() {
179+
return frameSize;
180+
}
181+
182+
/** Returns the bitrate of the stream (as passed to the constructor). */
183+
protected final int getBitrate() {
184+
return bitrate;
185+
}
186+
187+
/**
188+
* Returns whether seeking is permitted if the stream length is unknown (as passed to the
189+
* constructor).
190+
*/
191+
protected final boolean shouldAllowSeeksIfLengthUnknown() {
192+
return allowSeeksIfLengthUnknown;
193+
}
194+
169195
// Internal methods
170196

171197
/**

libraries/extractor/src/main/java/androidx/media3/extractor/mp3/ConstantBitrateSeeker.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
*/
2727
/* package */ final class ConstantBitrateSeeker extends ConstantBitrateSeekMap implements Seeker {
2828

29-
private final long firstFramePosition;
30-
private final int bitrate;
31-
private final int frameSize;
32-
private final boolean allowSeeksIfLengthUnknown;
3329
private final long durationUs;
3430
private final long dataEndPosition;
3531

@@ -101,10 +97,6 @@ private ConstantBitrateSeeker(
10197
frameSize,
10298
allowSeeksIfLengthUnknown,
10399
isEstimated);
104-
this.firstFramePosition = firstFramePosition;
105-
this.bitrate = bitrate;
106-
this.frameSize = frameSize == C.LENGTH_UNSET ? 1 : frameSize;
107-
this.allowSeeksIfLengthUnknown = allowSeeksIfLengthUnknown;
108100
this.durationUs = durationUs;
109101
dataEndPosition = inputLength != C.LENGTH_UNSET ? inputLength : C.INDEX_UNSET;
110102
}
@@ -117,8 +109,8 @@ public long getTimeUs(long position) {
117109
@Override
118110
public SeekPoints getSeekPoints(long timeUs) {
119111
if (durationUs != C.TIME_UNSET && timeUs >= durationUs && dataEndPosition != C.INDEX_UNSET) {
120-
long finalFramePosition = Math.max(firstFramePosition, dataEndPosition - frameSize);
121-
long frameDurationUs = getTimeUsAtPosition(firstFramePosition + frameSize);
112+
long finalFramePosition = Math.max(getFirstFramePosition(), dataEndPosition - getFrameSize());
113+
long frameDurationUs = getTimeUsAtPosition(getFirstFramePosition() + getFrameSize());
122114
return new SeekPoints(
123115
new SeekPoint(Math.max(0, durationUs - frameDurationUs), finalFramePosition));
124116
}
@@ -127,7 +119,7 @@ public SeekPoints getSeekPoints(long timeUs) {
127119

128120
@Override
129121
public long getDataStartPosition() {
130-
return firstFramePosition;
122+
return getFirstFramePosition();
131123
}
132124

133125
@Override
@@ -142,16 +134,16 @@ public long getDurationUs() {
142134

143135
@Override
144136
public int getAverageBitrate() {
145-
return bitrate;
137+
return getBitrate();
146138
}
147139

148140
public ConstantBitrateSeeker copyWithNewDataEndPosition(long dataEndPosition) {
149141
return new ConstantBitrateSeeker(
150142
/* inputLength= */ dataEndPosition,
151-
firstFramePosition,
152-
bitrate,
153-
frameSize,
154-
allowSeeksIfLengthUnknown,
143+
getFirstFramePosition(),
144+
getAverageBitrate(),
145+
getFrameSize(),
146+
shouldAllowSeeksIfLengthUnknown(),
155147
/* isEstimated= */ false,
156148
durationUs);
157149
}

0 commit comments

Comments
 (0)