mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
get 2 SeekPoints from the getSeekPosition() in flac_parser
This commit is contained in:
parent
a02237de20
commit
d9529479fa
@ -223,7 +223,7 @@ import java.nio.ByteBuffer;
|
|||||||
* @return The corresponding position (byte offset) in the flac stream or -1 if the stream doesn't
|
* @return The corresponding position (byte offset) in the flac stream or -1 if the stream doesn't
|
||||||
* have a seek table.
|
* have a seek table.
|
||||||
*/
|
*/
|
||||||
public long getSeekPosition(long timeUs) {
|
public long[] getSeekPosition(long timeUs) {
|
||||||
return flacGetSeekPosition(nativeDecoderContext, timeUs);
|
return flacGetSeekPosition(nativeDecoderContext, timeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ import java.nio.ByteBuffer;
|
|||||||
|
|
||||||
private native long flacGetNextFrameFirstSampleIndex(long context);
|
private native long flacGetNextFrameFirstSampleIndex(long context);
|
||||||
|
|
||||||
private native long flacGetSeekPosition(long context, long timeUs);
|
private native long[] flacGetSeekPosition(long context, long timeUs);
|
||||||
|
|
||||||
private native String flacGetStateString(long context);
|
private native String flacGetStateString(long context);
|
||||||
|
|
||||||
|
@ -276,7 +276,8 @@ public final class FlacExtractor implements Extractor {
|
|||||||
FlacStreamMetadata streamMetadata,
|
FlacStreamMetadata streamMetadata,
|
||||||
long streamLength,
|
long streamLength,
|
||||||
ExtractorOutput output) {
|
ExtractorOutput output) {
|
||||||
boolean hasSeekTable = decoderJni.getSeekPosition(/* timeUs= */ 0) != -1;
|
long[] result = decoderJni.getSeekPosition(/* timeUs= */ 0);
|
||||||
|
boolean hasSeekTable = result.length == 4 && result[1] != -1 && result[3] != -1;
|
||||||
FlacBinarySearchSeeker binarySearchSeeker = null;
|
FlacBinarySearchSeeker binarySearchSeeker = null;
|
||||||
SeekMap seekMap;
|
SeekMap seekMap;
|
||||||
if (hasSeekTable) {
|
if (hasSeekTable) {
|
||||||
@ -341,8 +342,12 @@ public final class FlacExtractor implements Extractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SeekPoints getSeekPoints(long timeUs) {
|
public SeekPoints getSeekPoints(long timeUs) {
|
||||||
// TODO: Access the seek table via JNI to return two seek points when appropriate.
|
long[] result = decoderJni.getSeekPosition(timeUs);
|
||||||
return new SeekPoints(new SeekPoint(timeUs, decoderJni.getSeekPosition(timeUs)));
|
if (result.length == 4) {
|
||||||
|
return new SeekPoints(new SeekPoint(result[0], result[1]), new SeekPoint(result[2], result[3]));
|
||||||
|
} else {
|
||||||
|
return new SeekPoints(new SeekPoint(timeUs, decoderJni.getDecodePosition()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -200,9 +200,13 @@ DECODER_FUNC(jlong, flacGetNextFrameFirstSampleIndex, jlong jContext) {
|
|||||||
return context->parser->getNextFrameFirstSampleIndex();
|
return context->parser->getNextFrameFirstSampleIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
DECODER_FUNC(jlong, flacGetSeekPosition, jlong jContext, jlong timeUs) {
|
DECODER_FUNC(jlongArray, flacGetSeekPosition, jlong jContext, jlong timeUs) {
|
||||||
Context *context = reinterpret_cast<Context *>(jContext);
|
Context *context = reinterpret_cast<Context *>(jContext);
|
||||||
return context->parser->getSeekPosition(timeUs);
|
int64_t *result = context->parser->getSeekPosition(timeUs);
|
||||||
|
const jlong resultJLong[4] = {result[0], result[1], result[2], result[3]};
|
||||||
|
jlongArray resultArray = env->NewLongArray(4);
|
||||||
|
env->SetLongArrayRegion(resultArray, 0, 4, resultJLong);
|
||||||
|
return resultArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECODER_FUNC(jstring, flacGetStateString, jlong jContext) {
|
DECODER_FUNC(jstring, flacGetStateString, jlong jContext) {
|
||||||
|
@ -438,9 +438,11 @@ size_t FLACParser::readBuffer(void *output, size_t output_size) {
|
|||||||
return bufferSize;
|
return bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FLACParser::getSeekPosition(int64_t timeUs) {
|
int64_t* FLACParser::getSeekPosition(int64_t timeUs) {
|
||||||
|
int64_t *result = new int64_t[4];
|
||||||
|
memset(result, -1, sizeof(result));
|
||||||
if (!mSeekTable) {
|
if (!mSeekTable) {
|
||||||
return -1;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t sample = (timeUs * getSampleRate()) / 1000000LL;
|
int64_t sample = (timeUs * getSampleRate()) / 1000000LL;
|
||||||
@ -452,8 +454,21 @@ int64_t FLACParser::getSeekPosition(int64_t timeUs) {
|
|||||||
for (unsigned i = mSeekTable->num_points; i > 0; ) {
|
for (unsigned i = mSeekTable->num_points; i > 0; ) {
|
||||||
i--;
|
i--;
|
||||||
if (points[i].sample_number <= sample) {
|
if (points[i].sample_number <= sample) {
|
||||||
return firstFrameOffset + points[i].stream_offset;
|
result[0] = points[i].sample_number / getSampleRate() * 1000000LL;
|
||||||
|
result[1] = firstFrameOffset + points[i].stream_offset;
|
||||||
|
if (i + 1 <= mSeekTable->num_points) {
|
||||||
|
result[2] = points[i + 1].sample_number / getSampleRate() * 1000000LL;
|
||||||
|
result[3] = firstFrameOffset + points[i + 1].stream_offset;
|
||||||
|
} else {
|
||||||
|
result[2] = result[0];
|
||||||
|
result[3] = result[1];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return firstFrameOffset;
|
result[0] = timeUs;
|
||||||
|
result[1] = firstFrameOffset;
|
||||||
|
result[2] = timeUs;
|
||||||
|
result[3] = firstFrameOffset;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class FLACParser {
|
|||||||
bool decodeMetadata();
|
bool decodeMetadata();
|
||||||
size_t readBuffer(void *output, size_t output_size);
|
size_t readBuffer(void *output, size_t output_size);
|
||||||
|
|
||||||
int64_t getSeekPosition(int64_t timeUs);
|
int64_t* getSeekPosition(int64_t timeUs);
|
||||||
|
|
||||||
void flush() {
|
void flush() {
|
||||||
reset(mCurrentPos);
|
reset(mCurrentPos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user