Merge changes Ic0dc0824,Idc22c710 into sc-dev
* changes:
Fix seek handling in AAC and AMR extractors
fix extractor unit test
diff --git a/media/extractors/aac/AACExtractor.cpp b/media/extractors/aac/AACExtractor.cpp
index 8f60f6b..2fc4584 100644
--- a/media/extractors/aac/AACExtractor.cpp
+++ b/media/extractors/aac/AACExtractor.cpp
@@ -18,6 +18,8 @@
#define LOG_TAG "AACExtractor"
#include <utils/Log.h>
+#include <inttypes.h>
+
#include "AACExtractor.h"
#include <media/MediaExtractorPluginApi.h>
#include <media/stagefright/foundation/ABuffer.h>
@@ -277,7 +279,22 @@
ReadOptions::SeekMode mode;
if (options && options->getSeekTo(&seekTimeUs, &mode)) {
if (mFrameDurationUs > 0) {
- int64_t seekFrame = seekTimeUs / mFrameDurationUs;
+ int64_t seekFrame = 0;
+ switch(mode & 0x7) {
+ case ReadOptions::SEEK_NEXT_SYNC:
+ // "at or after"
+ seekFrame = (seekTimeUs + mFrameDurationUs - 1) / mFrameDurationUs;
+ break;
+ case ReadOptions::SEEK_CLOSEST_SYNC:
+ case ReadOptions::SEEK_CLOSEST:
+ seekFrame = (seekTimeUs + mFrameDurationUs/2) / mFrameDurationUs;
+ break;
+ case ReadOptions::SEEK_PREVIOUS_SYNC:
+ default:
+ // 'at or before'
+ seekFrame = seekTimeUs / mFrameDurationUs;
+ break;
+ }
if (seekFrame < 0 || seekFrame >= (int64_t)mOffsetVector.size()) {
android_errorWriteLog(0x534e4554, "70239507");
return AMEDIA_ERROR_MALFORMED;
diff --git a/media/extractors/amr/AMRExtractor.cpp b/media/extractors/amr/AMRExtractor.cpp
index 26431a4..e26ff0a 100644
--- a/media/extractors/amr/AMRExtractor.cpp
+++ b/media/extractors/amr/AMRExtractor.cpp
@@ -18,6 +18,8 @@
#define LOG_TAG "AMRExtractor"
#include <utils/Log.h>
+#include <inttypes.h>
+
#include "AMRExtractor.h"
#include <media/stagefright/foundation/ADebug.h>
@@ -283,8 +285,22 @@
ReadOptions::SeekMode mode;
if (mOffsetTableLength > 0 && options && options->getSeekTo(&seekTimeUs, &mode)) {
size_t size;
- int64_t seekFrame = seekTimeUs / 20000LL; // 20ms per frame.
- mCurrentTimeUs = seekFrame * 20000LL;
+ const int64_t frameDurationUs = 20000LL; // 20ms per frame.
+ int64_t seekFrame = 0;
+ switch(mode & 0x7) {
+ case ReadOptions::SEEK_NEXT_SYNC:
+ seekFrame = (seekTimeUs + frameDurationUs - 1) / frameDurationUs;
+ break;
+ case ReadOptions::SEEK_CLOSEST_SYNC:
+ case ReadOptions::SEEK_CLOSEST:
+ seekFrame = (seekTimeUs + frameDurationUs/2) / frameDurationUs;
+ break;
+ case ReadOptions::SEEK_PREVIOUS_SYNC:
+ default:
+ seekFrame = seekTimeUs / frameDurationUs;
+ break;
+ }
+ mCurrentTimeUs = seekFrame * frameDurationUs;
size_t index = seekFrame < 0 ? 0 : seekFrame / 50;
if (index >= mOffsetTableLength) {
diff --git a/media/extractors/tests/ExtractorUnitTest.cpp b/media/extractors/tests/ExtractorUnitTest.cpp
index d91fffa..84ec1f2 100644
--- a/media/extractors/tests/ExtractorUnitTest.cpp
+++ b/media/extractors/tests/ExtractorUnitTest.cpp
@@ -18,6 +18,8 @@
#define LOG_TAG "ExtractorUnitTest"
#include <utils/Log.h>
+#include <inttypes.h>
+
#include <datasource/FileSource.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaCodecConstants.h>
@@ -503,7 +505,7 @@
&trackSampleRate));
ASSERT_EQ(exChannelCount, trackChannelCount) << "ChannelCount not as expected";
ASSERT_EQ(exSampleRate, trackSampleRate) << "SampleRate not as expected";
- } else {
+ } else if (!strncmp(extractorMime, "video/", 6)) {
int32_t exWidth, exHeight;
int32_t trackWidth, trackHeight;
ASSERT_TRUE(AMediaFormat_getInt32(extractorFormat, AMEDIAFORMAT_KEY_WIDTH, &exWidth));
@@ -512,6 +514,8 @@
ASSERT_TRUE(AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_HEIGHT, &trackHeight));
ASSERT_EQ(exWidth, trackWidth) << "Width not as expected";
ASSERT_EQ(exHeight, trackHeight) << "Height not as expected";
+ } else {
+ ALOGV("non a/v track");
}
status = cTrack->stop(track);
ASSERT_EQ(OK, status) << "Failed to stop the track";
@@ -568,8 +572,9 @@
TEST_P(ExtractorFunctionalityTest, SeekTest) {
if (mDisableTest) return;
- ALOGV("Validates %s Extractor behaviour for different seek modes", mContainer.c_str());
string inputFileName = gEnv->getRes() + get<1>(GetParam());
+ ALOGV("Validates %s Extractor behaviour for different seek modes filename %s",
+ mContainer.c_str(), inputFileName.c_str());
int32_t status = setDataSource(inputFileName);
ASSERT_EQ(status, 0) << "SetDataSource failed for" << mContainer << "extractor";
@@ -680,7 +685,8 @@
if (seekIdx >= seekablePointsSize) seekIdx = seekablePointsSize - 1;
int64_t seekToTimeStamp = seekablePoints[seekIdx];
- if (seekablePointsSize > 1) {
+ if (seekIdx > 1) {
+ // pick a time just earlier than this seek point
int64_t prevTimeStamp = seekablePoints[seekIdx - 1];
seekToTimeStamp = seekToTimeStamp - ((seekToTimeStamp - prevTimeStamp) >> 3);
}
@@ -711,11 +717,7 @@
// CMediaTrackReadOptions::SEEK is 8. Using mask 0111b to get true modes
switch (mode & 0x7) {
case CMediaTrackReadOptions::SEEK_PREVIOUS_SYNC:
- if (seekablePointsSize == 1) {
- EXPECT_EQ(timeStamp, seekablePoints[seekIdx]);
- } else {
- EXPECT_EQ(timeStamp, seekablePoints[seekIdx - 1]);
- }
+ EXPECT_EQ(timeStamp, seekablePoints[seekIdx > 0 ? (seekIdx - 1) : 0]);
break;
case CMediaTrackReadOptions::SEEK_NEXT_SYNC:
case CMediaTrackReadOptions::SEEK_CLOSEST_SYNC:
@@ -743,8 +745,9 @@
// TODO(b/155630778): Enable test for wav extractors
if (mExtractorName == WAV) return;
- ALOGV("Validates %s Extractor behaviour for invalid seek points", mContainer.c_str());
string inputFileName = gEnv->getRes() + get<1>(GetParam());
+ ALOGV("Validates %s Extractor behaviour for invalid seek points, filename %s",
+ mContainer.c_str(), inputFileName.c_str());
int32_t status = setDataSource(inputFileName);
ASSERT_EQ(status, 0) << "SetDataSource failed for" << mContainer << "extractor";
@@ -832,8 +835,9 @@
// TODO(b/155626946): Enable test for MPEG2 TS/PS extractors
if (mExtractorName == MPEG2TS || mExtractorName == MPEG2PS) return;
- ALOGV("Validates %s Extractor behaviour for invalid tracks", mContainer.c_str());
string inputFileName = gEnv->getRes() + get<1>(GetParam());
+ ALOGV("Validates %s Extractor behaviour for invalid tracks - file %s",
+ mContainer.c_str(), inputFileName.c_str());
int32_t status = setDataSource(inputFileName);
ASSERT_EQ(status, 0) << "SetDataSource failed for" << mContainer << "extractor";
@@ -872,13 +876,17 @@
TEST_P(ConfigParamTest, ConfigParamValidation) {
if (mDisableTest) return;
+ const int trackNumber = 0;
+
string container = GetParam().first;
- ALOGV("Validates %s Extractor for input's file properties", container.c_str());
string inputFileName = gEnv->getRes();
inputID inputFileId = GetParam().second;
configFormat configParam;
getFileProperties(inputFileId, inputFileName, configParam);
+ ALOGV("Validates %s Extractor for input's file properties, file %s",
+ container.c_str(), inputFileName.c_str());
+
int32_t status = setDataSource(inputFileName);
ASSERT_EQ(status, 0) << "SetDataSource failed for " << container << "extractor";
@@ -888,7 +896,7 @@
int32_t numTracks = mExtractor->countTracks();
ASSERT_GT(numTracks, 0) << "Extractor didn't find any track for the given clip";
- MediaTrackHelper *track = mExtractor->getTrack(0);
+ MediaTrackHelper *track = mExtractor->getTrack(trackNumber);
ASSERT_NE(track, nullptr) << "Failed to get track for index 0";
AMediaFormat *trackFormat = AMediaFormat_new();
@@ -910,7 +918,7 @@
AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_SAMPLE_RATE, &trackSampleRate));
ASSERT_EQ(configParam.sampleRate, trackSampleRate) << "SampleRate not as expected";
ASSERT_EQ(configParam.channelCount, trackChannelCount) << "ChannelCount not as expected";
- } else {
+ } else if (!strncmp(trackMime, "video/", 6)) {
int32_t trackWidth, trackHeight;
ASSERT_TRUE(AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_WIDTH, &trackWidth));
ASSERT_TRUE(AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_HEIGHT, &trackHeight));