summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/nuplayer
diff options
context:
space:
mode:
Diffstat (limited to 'media/libmediaplayerservice/nuplayer')
-rw-r--r--media/libmediaplayerservice/nuplayer/Android.mk8
-rw-r--r--media/libmediaplayerservice/nuplayer/GenericSource.cpp58
-rw-r--r--media/libmediaplayerservice/nuplayer/GenericSource.h10
-rw-r--r--media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp21
-rw-r--r--media/libmediaplayerservice/nuplayer/HTTPLiveSource.h4
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayer.cpp155
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayer.h24
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp50
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h4
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.cpp14
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.h11
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp8
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp129
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h12
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayerSource.h6
-rw-r--r--media/libmediaplayerservice/nuplayer/RTSPSource.cpp20
-rw-r--r--media/libmediaplayerservice/nuplayer/StreamingSource.cpp4
17 files changed, 405 insertions, 133 deletions
diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk
index cd20837..cc1bdb4 100644
--- a/media/libmediaplayerservice/nuplayer/Android.mk
+++ b/media/libmediaplayerservice/nuplayer/Android.mk
@@ -23,7 +23,9 @@ LOCAL_C_INCLUDES := \
$(TOP)/frameworks/av/media/libstagefright/rtsp \
$(TOP)/frameworks/av/media/libstagefright/timedtext \
$(TOP)/frameworks/av/media/libmediaplayerservice \
- $(TOP)/frameworks/native/include/media/openmax
+ $(TOP)/frameworks/native/include/media/openmax \
+ $(TOP)/frameworks/av/media/libavextensions \
+ $(TOP)/frameworks/av/include/media \
LOCAL_CFLAGS += -Werror -Wall
@@ -32,6 +34,10 @@ ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
LOCAL_CFLAGS += -DENABLE_STAGEFRIGHT_EXPERIMENTS
endif
+ifeq ($(TARGET_BOARD_PLATFORM),msm8974)
+LOCAL_CFLAGS += -DTARGET_8974
+endif
+
LOCAL_CLANG := true
LOCAL_MODULE:= libstagefright_nuplayer
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index 45da218..3ffb0f9 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -37,6 +37,7 @@
#include "../../libstagefright/include/NuCachedSource2.h"
#include "../../libstagefright/include/WVMExtractor.h"
#include "../../libstagefright/include/HTTPBase.h"
+#include "mediaplayerservice/AVNuExtensions.h"
namespace android {
@@ -60,6 +61,7 @@ NuPlayer::GenericSource::GenericSource(
mAudioIsVorbis(false),
mIsWidevine(false),
mIsSecure(false),
+ mUseSetBuffers(false),
mIsStreaming(false),
mUIDValid(uidValid),
mUID(uid),
@@ -126,6 +128,7 @@ status_t NuPlayer::GenericSource::setDataSource(
status_t NuPlayer::GenericSource::setDataSource(const sp<DataSource>& source) {
resetDataSource();
+ Mutex::Autolock _l(mSourceLock);
mDataSource = source;
return OK;
}
@@ -153,7 +156,12 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
return UNKNOWN_ERROR;
}
} else if (mIsStreaming) {
- if (!mDataSource->sniff(&mimeType, &confidence, &dummy)) {
+ sp<DataSource> dataSource;
+ {
+ Mutex::Autolock _l(mSourceLock);
+ dataSource = mDataSource;
+ }
+ if (!dataSource->sniff(&mimeType, &confidence, &dummy)) {
return UNKNOWN_ERROR;
}
isWidevineStreaming = !strcasecmp(
@@ -171,8 +179,14 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
}
extractor = mWVMExtractor;
} else {
+#ifndef TARGET_8974
+ int32_t flags = AVNuUtils::get()->getFlags();
+#else
+ int32_t flags = 0;
+#endif
extractor = MediaExtractor::Create(mDataSource,
- mimeType.isEmpty() ? NULL : mimeType.string());
+ mimeType.isEmpty() ? NULL : mimeType.string(),
+ mIsStreaming ? 0 : flags);
}
if (extractor == NULL) {
@@ -202,6 +216,13 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
}
}
+#ifndef TARGET_8974
+ if (AVNuUtils::get()->canUseSetBuffers(mFileMeta)) {
+ mUseSetBuffers = true;
+ ALOGI("setBuffers mode enabled");
+ }
+#endif
+
int32_t totalBitrate = 0;
size_t numtracks = extractor->countTracks();
@@ -318,7 +339,7 @@ int64_t NuPlayer::GenericSource::getLastReadPosition() {
status_t NuPlayer::GenericSource::setBuffers(
bool audio, Vector<MediaBuffer *> &buffers) {
- if (mIsSecure && !audio) {
+ if ((mIsSecure || mUseSetBuffers) && !audio) {
return mVideoTrack.mSource->setBuffers(buffers);
}
return INVALID_OPERATION;
@@ -372,13 +393,20 @@ void NuPlayer::GenericSource::onPrepareAsync() {
}
}
- mDataSource = DataSource::CreateFromURI(
+ sp<DataSource> dataSource;
+ dataSource = DataSource::CreateFromURI(
mHTTPService, uri, &mUriHeaders, &contentType,
- static_cast<HTTPBase *>(mHttpSource.get()));
+ static_cast<HTTPBase *>(mHttpSource.get()),
+ true /*use extended cache*/);
+ Mutex::Autolock _l(mSourceLock);
+ mDataSource = dataSource;
} else {
mIsWidevine = false;
- mDataSource = new FileSource(mFd, mOffset, mLength);
+ sp<DataSource> dataSource;
+ dataSource = new FileSource(mFd, mOffset, mLength);
+ Mutex::Autolock _l(mSourceLock);
+ mDataSource = dataSource;
mFd = -1;
}
@@ -427,7 +455,8 @@ void NuPlayer::GenericSource::onPrepareAsync() {
| FLAG_CAN_PAUSE
| FLAG_CAN_SEEK_BACKWARD
| FLAG_CAN_SEEK_FORWARD
- | FLAG_CAN_SEEK);
+ | FLAG_CAN_SEEK
+ | (mUseSetBuffers ? FLAG_USE_SET_BUFFERS : 0));
if (mIsSecure) {
// secure decoders must be instantiated before starting widevine source
@@ -1024,7 +1053,8 @@ status_t NuPlayer::GenericSource::dequeueAccessUnit(
// start pulling in more buffers if we only have one (or no) buffer left
// so that decoder has less chance of being starved
- if (track->mPackets->getAvailableBufferCount(&finalResult) < 2) {
+ if ((track->mPackets->getAvailableBufferCount(&finalResult) < 2)
+ && !mUseSetBuffers) {
postReadBuffer(audio? MEDIA_TRACK_TYPE_AUDIO : MEDIA_TRACK_TYPE_VIDEO);
}
@@ -1368,7 +1398,7 @@ sp<ABuffer> NuPlayer::GenericSource::mediaBufferToABuffer(
}
sp<ABuffer> ab;
- if (mIsSecure && !audio) {
+ if ((mIsSecure || mUseSetBuffers) && !audio) {
// data is already provided in the buffer
ab = new ABuffer(NULL, mb->range_length());
mb->add_ref();
@@ -1483,7 +1513,9 @@ void NuPlayer::GenericSource::readBuffer(
break;
case MEDIA_TRACK_TYPE_AUDIO:
track = &mAudioTrack;
- if (mIsWidevine) {
+ if (mHttpSource != NULL && getTrackCount() == 1) {
+ maxBuffers = 16;
+ } else if (mIsWidevine || (mHttpSource != NULL)) {
maxBuffers = 8;
} else {
maxBuffers = 64;
@@ -1514,9 +1546,10 @@ void NuPlayer::GenericSource::readBuffer(
if (seekTimeUs >= 0) {
options.setSeekTo(seekTimeUs, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
seeking = true;
+ track->mPackets->clear();
}
- if (mIsWidevine) {
+ if (mIsWidevine || mUseSetBuffers) {
options.setNonBlocking();
}
@@ -1538,7 +1571,8 @@ void NuPlayer::GenericSource::readBuffer(
queueDiscontinuityIfNeeded(seeking, formatChange, trackType, track);
sp<ABuffer> buffer = mediaBufferToABuffer(
- mbuf, trackType, seekTimeUs, actualTimeUs);
+ mbuf, trackType, seekTimeUs,
+ numBuffers == 0 ? actualTimeUs : NULL);
track->mPackets->queueAccessUnit(buffer);
formatChange = false;
seeking = false;
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.h b/media/libmediaplayerservice/nuplayer/GenericSource.h
index ac980ef..9f8556e 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.h
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.h
@@ -42,7 +42,7 @@ class WVMExtractor;
struct NuPlayer::GenericSource : public NuPlayer::Source {
GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
- status_t setDataSource(
+ virtual status_t setDataSource(
const sp<IMediaHTTPService> &httpService,
const char *url,
const KeyedVector<String8, String8> *headers);
@@ -84,7 +84,7 @@ protected:
virtual sp<MetaData> getFormatMeta(bool audio);
-private:
+protected:
enum {
kWhatPrepareAsync,
kWhatFetchSubtitleData,
@@ -126,6 +126,7 @@ private:
bool mAudioIsVorbis;
bool mIsWidevine;
bool mIsSecure;
+ bool mUseSetBuffers;
bool mIsStreaming;
bool mUIDValid;
uid_t mUID;
@@ -136,6 +137,7 @@ private:
int64_t mOffset;
int64_t mLength;
+ Mutex mSourceLock;
sp<DataSource> mDataSource;
sp<NuCachedSource2> mCachedSource;
sp<DataSource> mHttpSource;
@@ -164,7 +166,7 @@ private:
int64_t getLastReadPosition();
void setDrmPlaybackStatusIfNeeded(int playbackStatus, int64_t position);
- void notifyPreparedAndCleanup(status_t err);
+ virtual void notifyPreparedAndCleanup(status_t err);
void onSecureDecodersInstantiated(status_t err);
void finishPrepareAsync();
status_t startSources();
@@ -181,7 +183,7 @@ private:
void onSeek(sp<AMessage> msg);
status_t doSeek(int64_t seekTimeUs);
- void onPrepareAsync();
+ virtual void onPrepareAsync();
void fetchTextData(
uint32_t what, media_track_type type,
diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
index 126625a..a57fdc1 100644
--- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
@@ -30,6 +30,8 @@
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/Utils.h>
+
namespace android {
@@ -118,6 +120,19 @@ sp<AMessage> NuPlayer::HTTPLiveSource::getFormat(bool audio) {
return format;
}
+sp<MetaData> NuPlayer::HTTPLiveSource::getFormatMeta(bool audio) {
+ sp<AMessage> format = getFormat(audio);
+
+ if (format == NULL) {
+ return NULL;
+ }
+
+ sp<MetaData> meta = new MetaData;
+ convertMessageToMetaData(format, meta);
+ return meta;
+}
+
+
status_t NuPlayer::HTTPLiveSource::feedMoreTSData() {
return OK;
}
@@ -197,7 +212,11 @@ status_t NuPlayer::HTTPLiveSource::selectTrack(size_t trackIndex, bool select, i
}
status_t NuPlayer::HTTPLiveSource::seekTo(int64_t seekTimeUs) {
- return mLiveSession->seekTo(seekTimeUs);
+ if (mLiveSession->isSeekable()) {
+ return mLiveSession->seekTo(seekTimeUs);
+ } else {
+ return INVALID_OPERATION;
+ }
}
void NuPlayer::HTTPLiveSource::pollForRawData(
diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
index 9e0ec2f..388156c 100644
--- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
+++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
@@ -39,6 +39,7 @@ struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
virtual sp<AMessage> getFormat(bool audio);
+ virtual sp<MetaData> getFormatMeta(bool audio);
virtual status_t feedMoreTSData();
virtual status_t getDuration(int64_t *durationUs);
@@ -53,7 +54,6 @@ protected:
virtual void onMessageReceived(const sp<AMessage> &msg);
-private:
enum Flags {
// Don't log any URLs.
kFlagIncognito = 1,
@@ -78,7 +78,7 @@ private:
bool mHasMetadata;
bool mMetadataSelected;
- void onSessionNotify(const sp<AMessage> &msg);
+ virtual void onSessionNotify(const sp<AMessage> &msg);
void pollForRawData(
const sp<AMessage> &msg, int32_t currentGeneration,
LiveSession::StreamType fetchType, int32_t pushWhat);
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 26532d7..de507f1 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -56,6 +56,7 @@
#include "ESDS.h"
#include <media/stagefright/Utils.h>
+#include "mediaplayerservice/AVNuExtensions.h"
namespace android {
@@ -130,6 +131,23 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(FlushDecoderAction);
};
+struct NuPlayer::InstantiateDecoderAction : public Action {
+ InstantiateDecoderAction(bool audio, sp<DecoderBase> *decoder)
+ : mAudio(audio),
+ mdecoder(decoder) {
+ }
+
+ virtual void execute(NuPlayer *player) {
+ player->instantiateDecoder(mAudio, mdecoder);
+ }
+
+private:
+ bool mAudio;
+ sp<DecoderBase> *mdecoder;
+
+ DISALLOW_EVIL_CONSTRUCTORS(InstantiateDecoderAction);
+};
+
struct NuPlayer::PostMessageAction : public Action {
PostMessageAction(const sp<AMessage> &msg)
: mMessage(msg) {
@@ -188,6 +206,7 @@ NuPlayer::NuPlayer(pid_t pid)
mPlaybackSettings(AUDIO_PLAYBACK_RATE_DEFAULT),
mVideoFpsHint(-1.f),
mStarted(false),
+ mResetting(false),
mSourceStarted(false),
mPaused(false),
mPausedByClient(false),
@@ -216,7 +235,7 @@ void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
msg->post();
}
-static bool IsHTTPLiveURL(const char *url) {
+bool NuPlayer::IsHTTPLiveURL(const char *url) {
if (!strncasecmp("http://", url, 7)
|| !strncasecmp("https://", url, 8)
|| !strncasecmp("file://", url, 7)) {
@@ -1098,40 +1117,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
int32_t reason;
CHECK(msg->findInt32("reason", &reason));
ALOGV("Tear down audio with reason %d.", reason);
- mAudioDecoder.clear();
- ++mAudioDecoderGeneration;
- bool needsToCreateAudioDecoder = true;
- if (mFlushingAudio == FLUSHING_DECODER) {
- mFlushComplete[1 /* audio */][1 /* isDecoder */] = true;
- mFlushingAudio = FLUSHED;
- finishFlushIfPossible();
- } else if (mFlushingAudio == FLUSHING_DECODER_SHUTDOWN
- || mFlushingAudio == SHUTTING_DOWN_DECODER) {
- mFlushComplete[1 /* audio */][1 /* isDecoder */] = true;
- mFlushingAudio = SHUT_DOWN;
- finishFlushIfPossible();
- needsToCreateAudioDecoder = false;
- }
- if (mRenderer == NULL) {
- break;
- }
- closeAudioSink();
- mRenderer->flush(
- true /* audio */, false /* notifyComplete */);
- if (mVideoDecoder != NULL) {
- mRenderer->flush(
- false /* audio */, false /* notifyComplete */);
- }
-
- int64_t positionUs;
- if (!msg->findInt64("positionUs", &positionUs)) {
- positionUs = mPreviousSeekTimeUs;
- }
- performSeek(positionUs);
-
- if (reason == Renderer::kDueToError && needsToCreateAudioDecoder) {
- instantiateDecoder(true /* audio */, &mAudioDecoder);
- }
+ performTearDown(msg);
}
break;
}
@@ -1145,12 +1131,17 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
{
ALOGV("kWhatReset");
+ mResetting = true;
+
mDeferredActions.push_back(
new FlushDecoderAction(
FLUSH_CMD_SHUTDOWN /* audio */,
FLUSH_CMD_SHUTDOWN /* video */));
mDeferredActions.push_back(
+ new SimpleAction(&NuPlayer::closeAudioSink));
+
+ mDeferredActions.push_back(
new SimpleAction(&NuPlayer::performReset));
processDeferredActions();
@@ -1227,7 +1218,8 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
}
void NuPlayer::onResume() {
- if (!mPaused) {
+ if (!mPaused || mResetting) {
+ ALOGD_IF(mResetting, "resetting, onResume discarded");
return;
}
mPaused = false;
@@ -1301,6 +1293,7 @@ void NuPlayer::onStart(int64_t startPositionUs) {
}
sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
+ AVNuUtils::get()->setSourcePCMFormat(audioMeta);
audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
if (mAudioSink != NULL) {
streamType = mAudioSink->getAudioStreamType();
@@ -1310,6 +1303,10 @@ void NuPlayer::onStart(int64_t startPositionUs) {
mOffloadAudio =
canOffloadStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
+ if (!mOffloadAudio) {
+ mOffloadAudio = canOffloadDecodedPCMStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
+ }
+
if (mOffloadAudio) {
flags |= Renderer::FLAG_OFFLOAD_AUDIO;
}
@@ -1317,7 +1314,7 @@ void NuPlayer::onStart(int64_t startPositionUs) {
sp<AMessage> notify = new AMessage(kWhatRendererNotify, this);
++mRendererGeneration;
notify->setInt32("generation", mRendererGeneration);
- mRenderer = new Renderer(mAudioSink, notify, flags);
+ mRenderer = AVNuFactory::get()->createRenderer(mAudioSink, notify, flags);
mRendererLooper = new ALooper;
mRendererLooper->setName("NuPlayerRenderer");
mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
@@ -1446,7 +1443,7 @@ void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVi
// is possible; otherwise the decoders call the renderer openAudioSink directly.
status_t err = mRenderer->openAudioSink(
- format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio);
+ format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio, mSource->isStreaming());
if (err != OK) {
// Any failure we turn off mOffloadAudio.
mOffloadAudio = false;
@@ -1476,8 +1473,11 @@ void NuPlayer::determineAudioModeChange() {
sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
const bool hasVideo = (videoFormat != NULL);
- const bool canOffload = canOffloadStream(
+ bool canOffload = canOffloadStream(
audioMeta, hasVideo, mSource->isStreaming(), streamType);
+ if (!canOffload) {
+ canOffload = canOffloadDecodedPCMStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
+ }
if (canOffload) {
if (!mOffloadAudio) {
mRenderer->signalEnableOffloadAudio();
@@ -1489,6 +1489,7 @@ void NuPlayer::determineAudioModeChange() {
if (mOffloadAudio) {
mRenderer->signalDisableOffloadAudio();
mOffloadAudio = false;
+ setDecodedPcmOffload(false);
}
}
}
@@ -1499,7 +1500,10 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
if (*decoder != NULL || (audio && mFlushingAudio == SHUT_DOWN)) {
return OK;
}
-
+ if (mSource == NULL) {
+ ALOGD("%s Ignore instantiate decoder after clearing source", __func__);
+ return INVALID_OPERATION;
+ }
sp<AMessage> format = mSource->getFormat(audio);
if (format == NULL) {
@@ -1537,12 +1541,17 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
notify->setInt32("generation", mAudioDecoderGeneration);
determineAudioModeChange();
- if (mOffloadAudio) {
+
+ if (AVNuUtils::get()->isRAWFormat(format)) {
+ AVNuUtils::get()->setPCMFormat(format,
+ AVNuUtils::get()->getKeyPCMFormat(mSource->getFormatMeta(true /* audio */)));
+ }
+ if (mOffloadAudio && !ifDecodedPCMOffload()) {
const bool hasVideo = (mSource->getFormat(false /*audio */) != NULL);
format->setInt32("has-video", hasVideo);
- *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
+ *decoder = AVNuFactory::get()->createPassThruDecoder(notify, mSource, mRenderer);
} else {
- *decoder = new Decoder(notify, mSource, mPID, mRenderer);
+ *decoder = AVNuFactory::get()->createDecoder(notify, mSource, mPID, mRenderer);
}
} else {
sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
@@ -1567,7 +1576,8 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
(*decoder)->configure(format);
// allocate buffers to decrypt widevine source buffers
- if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
+ if (!audio && ((mSourceFlags & Source::FLAG_SECURE) ||
+ (mSourceFlags & Source::FLAG_USE_SET_BUFFERS))) {
Vector<sp<ABuffer> > inputBufs;
CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
@@ -1930,6 +1940,7 @@ void NuPlayer::performReset() {
}
mStarted = false;
+ mResetting = false;
mSourceStarted = false;
}
@@ -2190,7 +2201,7 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
int posMs;
int64_t timeUs, posUs;
driver->getCurrentPosition(&posMs);
- posUs = posMs * 1000;
+ posUs = (int64_t) posMs * 1000ll;
CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
if (posUs < timeUs) {
@@ -2223,6 +2234,13 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
break;
}
+ case Source::kWhatRTCPByeReceived:
+ {
+ ALOGV("notify the client that Bye message is received");
+ notifyListener(MEDIA_INFO, 2000, 0);
+ break;
+ }
+
default:
TRESPASS();
}
@@ -2368,4 +2386,51 @@ void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
TRESPASS();
}
+//
+// There is a flush from within the decoder's onFlush handling.
+// Without it, it is still possible that a buffer can be queueued
+// after NuPlayer issues a flush on the renderer's audio queue.
+//
+void NuPlayer::performTearDown(const sp<AMessage> &msg) {
+ int32_t reason;
+ CHECK(msg->findInt32("reason", &reason));
+
+ if (mAudioDecoder != NULL) {
+ switch (mFlushingAudio) {
+ case NONE:
+ case FLUSHING_DECODER:
+ mDeferredActions.push_back(
+ new FlushDecoderAction(FLUSH_CMD_SHUTDOWN /* audio */,
+ FLUSH_CMD_NONE /* video */));
+
+ if (reason == Renderer::kDueToError) {
+ mDeferredActions.push_back(
+ new InstantiateDecoderAction(true /* audio */, &mAudioDecoder));
+ }
+
+ int64_t positionUs;
+ if (!msg->findInt64("positionUs", &positionUs)) {
+ positionUs = mPreviousSeekTimeUs;
+ }
+ mDeferredActions.push_back(new SeekAction(positionUs));
+ break;
+ default:
+ ALOGW("performTearDown while flushing audio in %d", mFlushingAudio);
+ break;
+ }
+ }
+
+ if (mRenderer != NULL) {
+ closeAudioSink();
+ // see comment at beginning of function
+ mRenderer->flush(
+ true /* audio */, false /* notifyComplete */);
+ if (mVideoDecoder != NULL) {
+ mRenderer->flush(
+ false /* audio */, false /* notifyComplete */);
+ }
+ }
+ processDeferredActions();
+}
+
} // namespace android
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h
index c9f0bbd..ee0f3e6 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h
@@ -41,7 +41,7 @@ struct NuPlayer : public AHandler {
void setDataSourceAsync(const sp<IStreamSource> &source);
- void setDataSourceAsync(
+ virtual void setDataSourceAsync(
const sp<IMediaHTTPService> &httpService,
const char *url,
const KeyedVector<String8, String8> *headers);
@@ -86,12 +86,15 @@ protected:
virtual ~NuPlayer();
virtual void onMessageReceived(const sp<AMessage> &msg);
-
+ virtual bool ifDecodedPCMOffload() {return false;}
+ virtual void setDecodedPcmOffload(bool /*decodePcmOffload*/) {}
+ virtual bool canOffloadDecodedPCMStream(const sp<MetaData> /*meta*/,
+ bool /*hasVideo*/, bool /*isStreaming*/, audio_stream_type_t /*streamType*/) {return false;}
+ static bool IsHTTPLiveURL(const char *url);
public:
struct NuPlayerStreamListener;
struct Source;
-private:
struct Decoder;
struct DecoderBase;
struct DecoderPassThrough;
@@ -106,9 +109,11 @@ private:
struct SetSurfaceAction;
struct ResumeDecoderAction;
struct FlushDecoderAction;
+ struct InstantiateDecoderAction;
struct PostMessageAction;
struct SimpleAction;
+protected:
enum {
kWhatSetDataSource = '=DaS',
kWhatPrepare = 'prep',
@@ -197,6 +202,7 @@ private:
AVSyncSettings mSyncSettings;
float mVideoFpsHint;
bool mStarted;
+ bool mResetting;
bool mSourceStarted;
// Actual pause state, either as requested by client or due to buffering.
@@ -221,11 +227,11 @@ private:
mFlushComplete[1][1] = false;
}
- void tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo);
+ virtual void tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo);
void closeAudioSink();
void determineAudioModeChange();
- status_t instantiateDecoder(bool audio, sp<DecoderBase> *decoder);
+ virtual status_t instantiateDecoder(bool audio, sp<DecoderBase> *decoder);
status_t onInstantiateSecureDecoders();
@@ -233,7 +239,7 @@ private:
const sp<AMessage> &inputFormat,
const sp<AMessage> &outputFormat = NULL);
- void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL);
+ virtual void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL);
void handleFlushComplete(bool audio, bool isDecoder);
void finishFlushIfPossible();
@@ -256,14 +262,14 @@ private:
void processDeferredActions();
- void performSeek(int64_t seekTimeUs);
+ virtual void performSeek(int64_t seekTimeUs);
void performDecoderFlush(FlushCommand audio, FlushCommand video);
void performReset();
void performScanSources();
void performSetSurface(const sp<Surface> &wrapper);
void performResumeDecoders(bool needNotify);
- void onSourceNotify(const sp<AMessage> &msg);
+ virtual void onSourceNotify(const sp<AMessage> &msg);
void onClosedCaptionNotify(const sp<AMessage> &msg);
void queueDecoderShutdown(
@@ -275,6 +281,8 @@ private:
void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const;
+ void performTearDown(const sp<AMessage> &msg);
+
DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
};
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp
index c005f3f..d23a9e2 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp
@@ -34,10 +34,14 @@
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
+#include <stagefright/AVExtensions.h>
+#include <stagefright/FFMPEGSoftCodec.h>
#include <gui/Surface.h>
#include "avc_utils.h"
#include "ATSParser.h"
+#include "mediaplayerservice/AVNuExtensions.h"
+
namespace android {
@@ -78,7 +82,9 @@ NuPlayer::Decoder::Decoder(
}
NuPlayer::Decoder::~Decoder() {
- mCodec->release();
+ if (mCodec != NULL) {
+ mCodec->release();
+ }
releaseAndResetMediaBuffers();
}
@@ -251,8 +257,17 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
mComponentName.append(" decoder");
ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());
- mCodec = MediaCodec::CreateByType(
- mCodecLooper, mime.c_str(), false /* encoder */, NULL /* err */, mPid);
+ mCodec = AVUtils::get()->createCustomComponentByName(mCodecLooper, mime.c_str(), false /* encoder */, format);
+ FFMPEGSoftCodec::overrideComponentName(0, format, &mComponentName, &mime, false);
+
+ if (mCodec == NULL) {
+ if (!mComponentName.startsWith(mime.c_str())) {
+ mCodec = MediaCodec::CreateByComponentName(mCodecLooper, mComponentName.c_str());
+ } else {
+ mCodec = MediaCodec::CreateByType(mCodecLooper, mime.c_str(), false /* encoder */);
+ }
+ }
+
int32_t secure = 0;
if (format->findInt32("secure", &secure) && secure != 0) {
if (mCodec != NULL) {
@@ -357,7 +372,14 @@ void NuPlayer::Decoder::onResume(bool notifyComplete) {
if (notifyComplete) {
mResumePending = true;
}
- mCodec->start();
+
+ if (mCodec != NULL) {
+ mCodec->start();
+ } else {
+ ALOGW("Decoder %s onResume without a valid codec object",
+ mComponentName.c_str());
+ handleError(NO_INIT);
+ }
}
void NuPlayer::Decoder::doFlush(bool notifyComplete) {
@@ -558,6 +580,11 @@ bool NuPlayer::Decoder::handleAnOutputBuffer(
sp<ABuffer> buffer;
mCodec->getOutputBuffer(index, &buffer);
+ if (buffer == NULL) {
+ handleError(UNKNOWN_ERROR);
+ return false;
+ }
+
if (index >= mOutputBuffers.size()) {
for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
mOutputBuffers.add();
@@ -569,6 +596,10 @@ bool NuPlayer::Decoder::handleAnOutputBuffer(
buffer->setRange(offset, size);
buffer->meta()->clear();
buffer->meta()->setInt64("timeUs", timeUs);
+ setPcmFormat(buffer->meta());
+#ifdef TARGET_8974
+ AVNuUtils::get()->addFlagsInMeta(buffer, flags, mIsAudio);
+#endif
bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
// we do not expect CODECCONFIG or SYNCFRAME for decoder
@@ -577,6 +608,14 @@ bool NuPlayer::Decoder::handleAnOutputBuffer(
reply->setSize("buffer-ix", index);
reply->setInt32("generation", mBufferGeneration);
+ if ((flags & MediaCodec::BUFFER_FLAG_DATACORRUPT) &&
+ AVNuUtils::get()->dropCorruptFrame()) {
+ ALOGV("[%s] dropping corrupt buffer at time %lld as requested.",
+ mComponentName.c_str(), (long long)timeUs);
+ reply->post();
+ return true;
+ }
+
if (eos) {
ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
@@ -636,7 +675,7 @@ void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
}
status_t err = mRenderer->openAudioSink(
- format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */);
+ format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */, mSource->isStreaming());
if (err != OK) {
handleError(err);
}
@@ -711,6 +750,7 @@ status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
// treat seamless format change separately
formatChange = !seamlessFormatChange;
}
+ AVNuUtils::get()->checkFormatChange(&formatChange, accessUnit);
// For format or time change, return EOS to queue EOS input,
// then wait for EOS on output.
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h
index eeb4af4..5f84a06 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h
@@ -49,8 +49,8 @@ protected:
virtual void onFlush();
virtual void onShutdown(bool notifyComplete);
virtual bool doRequestBuffers();
+ virtual void setPcmFormat(const sp<AMessage> & /*format*/) {}
-private:
enum {
kWhatCodecNotify = 'cdcN',
kWhatRenderBuffer = 'rndr',
@@ -103,7 +103,7 @@ private:
size_t size,
int64_t timeUs,
int32_t flags);
- void handleOutputFormatChange(const sp<AMessage> &format);
+ virtual void handleOutputFormatChange(const sp<AMessage> &format);
void releaseAndResetMediaBuffers();
void requestCodecNotification();
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.cpp
index 30146c4..937936d 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.cpp
@@ -29,14 +29,12 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/MediaErrors.h>
+#include "mediaplayerservice/AVNuExtensions.h"
#include "ATSParser.h"
namespace android {
-// TODO optimize buffer size for power consumption
-// The offload read buffer size is 32 KB but 24 KB uses less power.
-static const size_t kAggregateBufferSizeBytes = 24 * 1024;
static const size_t kMaxCachedBytes = 200000;
NuPlayer::DecoderPassThrough::DecoderPassThrough(
@@ -46,6 +44,9 @@ NuPlayer::DecoderPassThrough::DecoderPassThrough(
: DecoderBase(notify),
mSource(source),
mRenderer(renderer),
+ // TODO optimize buffer size for power consumption
+ // The offload read buffer size is 32 KB but 24 KB uses less power.
+ mAggregateBufferSizeBytes(24 * 1024),
mSkipRenderingUntilMediaTimeUs(-1ll),
mPaused(false),
mReachedEOS(true),
@@ -76,7 +77,7 @@ void NuPlayer::DecoderPassThrough::onConfigure(const sp<AMessage> &format) {
// format is different.
status_t err = mRenderer->openAudioSink(
format, true /* offloadOnly */, hasVideo,
- AUDIO_OUTPUT_FLAG_NONE /* flags */, NULL /* isOffloaded */);
+ AUDIO_OUTPUT_FLAG_NONE /* flags */, NULL /* isOffloaded */, mSource->isStreaming());
if (err != OK) {
handleError(err);
}
@@ -173,9 +174,9 @@ sp<ABuffer> NuPlayer::DecoderPassThrough::aggregateBuffer(
size_t smallSize = accessUnit->size();
if ((mAggregateBuffer == NULL)
// Don't bother if only room for a few small buffers.
- && (smallSize < (kAggregateBufferSizeBytes / 3))) {
+ && (smallSize < (mAggregateBufferSizeBytes / 3))) {
// Create a larger buffer for combining smaller buffers from the extractor.
- mAggregateBuffer = new ABuffer(kAggregateBufferSizeBytes);
+ mAggregateBuffer = new ABuffer(mAggregateBufferSizeBytes);
mAggregateBuffer->setRange(0, 0); // start empty
}
@@ -201,6 +202,7 @@ sp<ABuffer> NuPlayer::DecoderPassThrough::aggregateBuffer(
if ((bigSize == 0) && smallTimestampValid) {
mAggregateBuffer->meta()->setInt64("timeUs", timeUs);
}
+ setPcmFormat(mAggregateBuffer->meta());
// Append small buffer to the bigger buffer.
memcpy(mAggregateBuffer->base() + bigSize, accessUnit->data(), smallSize);
bigSize += smallSize;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.h b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.h
index db33e87..629e266 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderPassThrough.h
@@ -43,25 +43,27 @@ protected:
virtual void onFlush();
virtual void onShutdown(bool notifyComplete);
virtual bool doRequestBuffers();
+ virtual void setPcmFormat(const sp<AMessage> & /*format*/) {}
+ virtual sp<ABuffer> aggregateBuffer(const sp<ABuffer> &accessUnit);
-private:
enum {
kWhatBufferConsumed = 'bufC',
};
sp<Source> mSource;
sp<Renderer> mRenderer;
+ size_t mAggregateBufferSizeBytes;
int64_t mSkipRenderingUntilMediaTimeUs;
bool mPaused;
-
- bool mReachedEOS;
+ bool mReachedEOS;
// Used by feedDecoderInputData to aggregate small buffers into
// one large buffer.
+ status_t mPendingAudioErr;
sp<ABuffer> mPendingAudioAccessUnit;
- status_t mPendingAudioErr;
sp<ABuffer> mAggregateBuffer;
+private:
// mPendingBuffersToDrain are only for debugging. It can be removed
// when the power investigation is done.
size_t mPendingBuffersToDrain;
@@ -72,7 +74,6 @@ private:
bool isDoneFetching() const;
status_t dequeueAccessUnit(sp<ABuffer> *accessUnit);
- sp<ABuffer> aggregateBuffer(const sp<ABuffer> &accessUnit);
status_t fetchInputData(sp<AMessage> &reply);
void doFlush(bool notifyComplete);
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index f288c36..716c353 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -31,6 +31,9 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/Utils.h>
+#include "mediaplayerservice/AVNuExtensions.h"
+#include "mediaplayerservice/AVMediaServiceExtensions.h"
+
namespace android {
NuPlayerDriver::NuPlayerDriver(pid_t pid)
@@ -55,7 +58,7 @@ NuPlayerDriver::NuPlayerDriver(pid_t pid)
true, /* canCallJava */
PRIORITY_AUDIO);
- mPlayer = new NuPlayer(pid);
+ mPlayer = AVNuFactory::get()->createNuPlayer(pid);
mLooper->registerHandler(mPlayer);
mPlayer->setDriver(this);
@@ -114,6 +117,7 @@ status_t NuPlayerDriver::setDataSource(int fd, int64_t offset, int64_t length) {
mCondition.wait(mLock);
}
+ AVNuUtils::get()->printFileName(fd);
return mAsyncResult;
}
@@ -607,6 +611,8 @@ status_t NuPlayerDriver::getMetadata(
Metadata::kSeekAvailable,
mPlayerFlags & NuPlayer::Source::FLAG_CAN_SEEK);
+ AVMediaServiceUtils::get()->appendMeta(&meta);
+
return OK;
}
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
index 4d25294..049b79d 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -26,12 +26,15 @@
#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/AWakeLock.h>
#include <media/stagefright/MediaClock.h>
+#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/Utils.h>
#include <media/stagefright/VideoFrameScheduler.h>
#include <inttypes.h>
+#include "mediaplayerservice/AVNuExtensions.h"
+#include "stagefright/AVExtensions.h"
namespace android {
@@ -81,6 +84,16 @@ const NuPlayer::Renderer::PcmInfo NuPlayer::Renderer::AUDIO_PCMINFO_INITIALIZER
// static
const int64_t NuPlayer::Renderer::kMinPositionUpdateDelayUs = 100000ll;
+static bool sFrameAccurateAVsync = false;
+
+static void readProperties() {
+ char value[PROPERTY_VALUE_MAX];
+ if (property_get("persist.sys.media.avsync", value, NULL)) {
+ sFrameAccurateAVsync =
+ !strcmp("1", value) || !strcasecmp("true", value);
+ }
+}
+
NuPlayer::Renderer::Renderer(
const sp<MediaPlayerBase::AudioSink> &sink,
const sp<AMessage> &notify,
@@ -102,6 +115,7 @@ NuPlayer::Renderer::Renderer(
mVideoLateByUs(0ll),
mHasAudio(false),
mHasVideo(false),
+ mFoundAudioEOS(false),
mNotifyCompleteAudio(false),
mNotifyCompleteVideo(false),
mSyncQueues(false),
@@ -123,6 +137,7 @@ NuPlayer::Renderer::Renderer(
mMediaClock = new MediaClock;
mPlaybackRate = mPlaybackSettings.mSpeed;
mMediaClock->setPlaybackRate(mPlaybackRate);
+ readProperties();
}
NuPlayer::Renderer::~Renderer() {
@@ -313,7 +328,8 @@ void NuPlayer::Renderer::setVideoFrameRate(float fps) {
// Called on any threads.
status_t NuPlayer::Renderer::getCurrentPosition(int64_t *mediaUs) {
- return mMediaClock->getMediaTime(ALooper::GetNowUs(), mediaUs);
+ return mMediaClock->getMediaTime(
+ ALooper::GetNowUs(), mediaUs, (mHasAudio && mFoundAudioEOS));
}
void NuPlayer::Renderer::clearAudioFirstAnchorTime_l() {
@@ -349,18 +365,20 @@ status_t NuPlayer::Renderer::openAudioSink(
bool offloadOnly,
bool hasVideo,
uint32_t flags,
- bool *isOffloaded) {
+ bool *isOffloaded,
+ bool isStreaming) {
sp<AMessage> msg = new AMessage(kWhatOpenAudioSink, this);
msg->setMessage("format", format);
msg->setInt32("offload-only", offloadOnly);
msg->setInt32("has-video", hasVideo);
msg->setInt32("flags", flags);
+ msg->setInt32("isStreaming", isStreaming);
sp<AMessage> response;
- msg->postAndAwaitResponse(&response);
+ status_t postStatus = msg->postAndAwaitResponse(&response);
int32_t err;
- if (!response->findInt32("err", &err)) {
+ if (postStatus != OK || !response->findInt32("err", &err)) {
err = INVALID_OPERATION;
} else if (err == OK && isOffloaded != NULL) {
int32_t offload;
@@ -393,7 +411,10 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) {
uint32_t flags;
CHECK(msg->findInt32("flags", (int32_t *)&flags));
- status_t err = onOpenAudioSink(format, offloadOnly, hasVideo, flags);
+ uint32_t isStreaming;
+ CHECK(msg->findInt32("isStreaming", (int32_t *)&isStreaming));
+
+ status_t err = onOpenAudioSink(format, offloadOnly, hasVideo, flags, isStreaming);
sp<AMessage> response = new AMessage;
response->setInt32("err", err);
@@ -436,9 +457,10 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) {
if (onDrainAudioQueue()) {
uint32_t numFramesPlayed;
- CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed),
- (status_t)OK);
-
+ if (mAudioSink->getPosition(&numFramesPlayed) != OK) {
+ ALOGW("mAudioSink->getPosition failed");
+ break;
+ }
uint32_t numFramesPendingPlayout =
mNumFramesWritten - numFramesPlayed;
@@ -1042,6 +1064,9 @@ void NuPlayer::Renderer::postDrainVideoQueue() {
mMediaClock->updateAnchor(mediaTimeUs, nowUs, mediaTimeUs);
mAnchorTimeMediaUs = mediaTimeUs;
realTimeUs = nowUs;
+ } else if (!mVideoSampleReceived) {
+ // Always render the first video frame.
+ realTimeUs = nowUs;
} else {
realTimeUs = getRealTimeUs(mediaTimeUs, nowUs);
}
@@ -1078,6 +1103,11 @@ void NuPlayer::Renderer::postDrainVideoQueue() {
ALOGW_IF(delayUs > 500000, "unusually high delayUs: %" PRId64, delayUs);
// post 2 display refreshes before rendering is due
+ // FIXME currently this increases power consumption, so unless frame-accurate
+ // AV sync is requested, post closer to required render time (at 0.63 vsyncs)
+ if (!sFrameAccurateAVsync) {
+ twoVsyncsUs >>= 4;
+ }
msg->post(delayUs > twoVsyncsUs ? delayUs - twoVsyncsUs : 0);
mDrainVideoQueuePending = true;
@@ -1102,7 +1132,7 @@ void NuPlayer::Renderer::onDrainVideoQueue() {
return;
}
- int64_t nowUs = -1;
+ int64_t nowUs = ALooper::GetNowUs();
int64_t realTimeUs;
if (mFlags & FLAG_REAL_TIME) {
CHECK(entry->mBuffer->meta()->findInt64("timeUs", &realTimeUs));
@@ -1110,16 +1140,12 @@ void NuPlayer::Renderer::onDrainVideoQueue() {
int64_t mediaTimeUs;
CHECK(entry->mBuffer->meta()->findInt64("timeUs", &mediaTimeUs));
- nowUs = ALooper::GetNowUs();
realTimeUs = getRealTimeUs(mediaTimeUs, nowUs);
}
bool tooLate = false;
if (!mPaused) {
- if (nowUs == -1) {
- nowUs = ALooper::GetNowUs();
- }
setVideoLateByUs(nowUs - realTimeUs);
tooLate = (mVideoLateByUs > 40000);
@@ -1143,6 +1169,12 @@ void NuPlayer::Renderer::onDrainVideoQueue() {
}
}
+ // Always render the first video frame while keeping stats on A/V sync.
+ if (!mVideoSampleReceived) {
+ realTimeUs = nowUs;
+ tooLate = false;
+ }
+
entry->mNotifyConsumed->setInt64("timestampNs", realTimeUs * 1000ll);
entry->mNotifyConsumed->setInt32("render", !tooLate);
entry->mNotifyConsumed->post();
@@ -1168,6 +1200,9 @@ void NuPlayer::Renderer::notifyVideoRenderingStart() {
}
void NuPlayer::Renderer::notifyEOS(bool audio, status_t finalResult, int64_t delayUs) {
+ if (audio) {
+ mFoundAudioEOS = true;
+ }
sp<AMessage> notify = mNotify->dup();
notify->setInt32("what", kWhatEOS);
notify->setInt32("audio", static_cast<int32_t>(audio));
@@ -1483,6 +1518,7 @@ void NuPlayer::Renderer::onPause() {
mDrainAudioQueuePending = false;
mDrainVideoQueuePending = false;
+ mVideoRenderingStarted = false; // force-notify NOTE_INFO MEDIA_INFO_RENDERING_START after resume
if (mHasAudio) {
mAudioSink->pause();
@@ -1494,15 +1530,18 @@ void NuPlayer::Renderer::onPause() {
}
void NuPlayer::Renderer::onResume() {
+ readProperties();
+
if (!mPaused) {
return;
}
if (mHasAudio) {
+ status_t status = NO_ERROR;
cancelAudioOffloadPauseTimeout();
- status_t err = mAudioSink->start();
- if (err != OK) {
- ALOGE("cannot start AudioSink err %d", err);
+ status = mAudioSink->start();
+ if (offloadingAudio() && status != NO_ERROR && status != INVALID_OPERATION) {
+ ALOGD("received error :%d on resume for offload track posting TEAR_DOWN event",status);
notifyAudioTearDown();
}
}
@@ -1566,6 +1605,7 @@ int64_t NuPlayer::Renderer::getPlayedOutAudioDurationUs(int64_t nowUs) {
int64_t numFramesPlayedAt;
AudioTimestamp ts;
static const int64_t kStaleTimestamp100ms = 100000;
+ int64_t durationUs;
status_t res = mAudioSink->getTimestamp(ts);
if (res == OK) { // case 1: mixing audio tracks and offloaded tracks.
@@ -1592,14 +1632,20 @@ int64_t NuPlayer::Renderer::getPlayedOutAudioDurationUs(int64_t nowUs) {
// numFramesPlayed, (long long)numFramesPlayedAt);
} else { // case 3: transitory at new track or audio fast tracks.
res = mAudioSink->getPosition(&numFramesPlayed);
- CHECK_EQ(res, (status_t)OK);
- numFramesPlayedAt = nowUs;
- numFramesPlayedAt += 1000LL * mAudioSink->latency() / 2; /* XXX */
+ if (res != OK) {
+ //query to getPosition fails, use media clock to simulate render position
+ getCurrentPosition(&durationUs);
+ durationUs = durationUs - mAnchorTimeMediaUs;
+ return durationUs;
+ } else {
+ numFramesPlayedAt = nowUs;
+ numFramesPlayedAt += 1000LL * mAudioSink->latency() / 2; /* XXX */
+ }
//ALOGD("getPosition: %u %lld", numFramesPlayed, (long long)numFramesPlayedAt);
}
//CHECK_EQ(numFramesPlayed & (1 << 31), 0); // can't be negative until 12.4 hrs, test
- int64_t durationUs = getDurationUsIfPlayedAtSampleRate(numFramesPlayed)
+ durationUs = getDurationUsIfPlayedAtSampleRate(numFramesPlayed)
+ nowUs - numFramesPlayedAt;
if (durationUs < 0) {
// Occurs when numFramesPlayed position is very small and the following:
@@ -1657,7 +1703,8 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
const sp<AMessage> &format,
bool offloadOnly,
bool hasVideo,
- uint32_t flags) {
+ uint32_t flags,
+ bool isStreaming) {
ALOGV("openAudioSink: offloadOnly(%d) offloadingAudio(%d)",
offloadOnly, offloadingAudio());
bool audioSinkChanged = false;
@@ -1671,13 +1718,17 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
}
+ int32_t bitWidth = 16;
+ format->findInt32("bits-per-sample", &bitWidth);
+
int32_t sampleRate;
CHECK(format->findInt32("sample-rate", &sampleRate));
+ AString mime;
+ CHECK(format->findString("mime", &mime));
+
if (offloadingAudio()) {
audio_format_t audioFormat = AUDIO_FORMAT_PCM_16_BIT;
- AString mime;
- CHECK(format->findString("mime", &mime));
status_t err = mapMimeToAudioFormat(audioFormat, mime.c_str());
if (err != OK) {
@@ -1685,22 +1736,34 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
"audio_format", mime.c_str());
onDisableOffloadAudio();
} else {
- ALOGV("Mime \"%s\" mapped to audio_format 0x%x",
- mime.c_str(), audioFormat);
+ audioFormat = AVUtils::get()->updateAudioFormat(audioFormat, format);
+ bitWidth = AVUtils::get()->getAudioSampleBits(format);
int avgBitRate = -1;
- format->findInt32("bit-rate", &avgBitRate);
+ format->findInt32("bitrate", &avgBitRate);
int32_t aacProfile = -1;
if (audioFormat == AUDIO_FORMAT_AAC
&& format->findInt32("aac-profile", &aacProfile)) {
// Redefine AAC format as per aac profile
- mapAACProfileToAudioFormat(
- audioFormat,
- aacProfile);
+ int32_t isADTSSupported;
+ isADTSSupported = AVUtils::get()->mapAACProfileToAudioFormat(format,
+ audioFormat,
+ aacProfile);
+ if (!isADTSSupported) {
+ mapAACProfileToAudioFormat(audioFormat,
+ aacProfile);
+ } else {
+ ALOGV("Format is AAC ADTS\n");
+ }
}
+ int32_t offloadBufferSize =
+ AVUtils::get()->getAudioMaxInputBufferSize(
+ audioFormat,
+ format);
audio_offload_info_t offloadInfo = AUDIO_INFO_INITIALIZER;
+
offloadInfo.duration_us = -1;
format->findInt64(
"durationUs", &offloadInfo.duration_us);
@@ -1710,7 +1773,9 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
offloadInfo.stream_type = AUDIO_STREAM_MUSIC;
offloadInfo.bit_rate = avgBitRate;
offloadInfo.has_video = hasVideo;
- offloadInfo.is_streaming = true;
+ offloadInfo.is_streaming = isStreaming;
+ offloadInfo.bit_width = bitWidth;
+ offloadInfo.offload_buffer_size = offloadBufferSize;
if (memcmp(&mCurrentOffloadInfo, &offloadInfo, sizeof(offloadInfo)) == 0) {
ALOGV("openAudioSink: no change in offload mode");
@@ -1774,7 +1839,7 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
const PcmInfo info = {
(audio_channel_mask_t)channelMask,
(audio_output_flags_t)pcmFlags,
- AUDIO_FORMAT_PCM_16_BIT, // TODO: change to audioFormat
+ getPCMFormat(format),
numChannels,
sampleRate
};
@@ -1809,7 +1874,7 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
sampleRate,
numChannels,
(audio_channel_mask_t)channelMask,
- AUDIO_FORMAT_PCM_16_BIT,
+ getPCMFormat(format),
0 /* bufferCount - unused */,
mUseAudioCallback ? &NuPlayer::Renderer::AudioSinkCallback : NULL,
mUseAudioCallback ? this : NULL,
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
index 9479c31..e872227 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
@@ -73,12 +73,15 @@ struct NuPlayer::Renderer : public AHandler {
status_t getCurrentPosition(int64_t *mediaUs);
int64_t getVideoLateByUs();
+ virtual audio_stream_type_t getAudioStreamType(){return AUDIO_STREAM_DEFAULT;}
+
status_t openAudioSink(
const sp<AMessage> &format,
bool offloadOnly,
bool hasVideo,
uint32_t flags,
- bool *isOffloaded);
+ bool *isOffloaded,
+ bool isStreaming);
void closeAudioSink();
enum {
@@ -101,7 +104,6 @@ protected:
virtual void onMessageReceived(const sp<AMessage> &msg);
-private:
enum {
kWhatDrainAudioQueue = 'draA',
kWhatDrainVideoQueue = 'draV',
@@ -162,6 +164,7 @@ private:
int64_t mVideoLateByUs;
bool mHasAudio;
bool mHasVideo;
+ bool mFoundAudioEOS;
bool mNotifyCompleteAudio;
bool mNotifyCompleteVideo;
@@ -229,7 +232,7 @@ private:
void prepareForMediaRenderingStart_l();
void notifyIfMediaRenderingStarted_l();
- void onQueueBuffer(const sp<AMessage> &msg);
+ virtual void onQueueBuffer(const sp<AMessage> &msg);
void onQueueEOS(const sp<AMessage> &msg);
void onFlush(const sp<AMessage> &msg);
void onAudioSinkChanged();
@@ -251,7 +254,8 @@ private:
const sp<AMessage> &format,
bool offloadOnly,
bool hasVideo,
- uint32_t flags);
+ uint32_t flags,
+ bool isStreaming);
void onCloseAudioSink();
void notifyEOS(bool audio, status_t finalResult, int64_t delayUs = 0);
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
index 11a6a9f..b248316 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
@@ -39,6 +39,7 @@ struct NuPlayer::Source : public AHandler {
FLAG_DYNAMIC_DURATION = 16,
FLAG_SECURE = 32,
FLAG_PROTECTED = 64,
+ FLAG_USE_SET_BUFFERS = 128,
};
enum {
@@ -57,6 +58,7 @@ struct NuPlayer::Source : public AHandler {
kWhatQueueDecoderShutdown,
kWhatDrmNoLicense,
kWhatInstantiateSecureDecoders,
+ kWhatRTCPByeReceived,
};
// The provides message is used to notify the player about various
@@ -132,10 +134,10 @@ protected:
void notifyFlagsChanged(uint32_t flags);
void notifyVideoSizeChanged(const sp<AMessage> &format = NULL);
void notifyInstantiateSecureDecoders(const sp<AMessage> &reply);
- void notifyPrepared(status_t err = OK);
+ virtual void notifyPrepared(status_t err = OK);
-private:
sp<AMessage> mNotify;
+private:
DISALLOW_EVIL_CONSTRUCTORS(Source);
};
diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
index af0351e..35567a5 100644
--- a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
@@ -27,6 +27,7 @@
#include <media/IMediaHTTPService.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MetaData.h>
+#include <mediaplayerservice/AVMediaServiceExtensions.h>
namespace android {
@@ -131,6 +132,10 @@ void NuPlayer::RTSPSource::pause() {
// Check if EOS or ERROR is received
if (source != NULL && source->isFinished(mediaDurationUs)) {
+ if (mHandler != NULL) {
+ ALOGI("Nearing EOS...No Pause is issued");
+ mHandler->cancelTimeoutCheck();
+ }
return;
}
}
@@ -476,8 +481,11 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
if (!info->mNPTMappingValid) {
// This is a live stream, we didn't receive any normal
// playtime mapping. We won't map to npt time.
- source->queueAccessUnit(accessUnit);
- break;
+ if (!AVMediaServiceUtils::get()->checkNPTMapping(&info->mRTPTime,
+ &info->mNormalPlaytimeUs, &info->mNPTMappingValid, rtpTime)) {
+ source->queueAccessUnit(accessUnit);
+ break;
+ }
}
int64_t nptUs =
@@ -563,6 +571,14 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
break;
}
+ case MyHandler::kWhatByeReceived:
+ {
+ sp<AMessage> msg = dupNotify();
+ msg->setInt32("what", kWhatRTCPByeReceived);
+ msg->post();
+ break;
+ }
+
case SDPLoader::kWhatSDPLoaded:
{
onSDPLoaded(msg);
diff --git a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
index 0246b59..d4c88de 100644
--- a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
@@ -32,6 +32,8 @@
namespace android {
+const int32_t kNumListenerQueuePackets = 80;
+
NuPlayer::StreamingSource::StreamingSource(
const sp<AMessage> &notify,
const sp<IStreamSource> &source)
@@ -84,7 +86,7 @@ status_t NuPlayer::StreamingSource::feedMoreTSData() {
}
void NuPlayer::StreamingSource::onReadBuffer() {
- for (int32_t i = 0; i < 50; ++i) {
+ for (int32_t i = 0; i < kNumListenerQueuePackets; ++i) {
char buffer[188];
sp<AMessage> extra;
ssize_t n = mStreamListener->read(buffer, sizeof(buffer), &extra);