diff options
Diffstat (limited to 'media/libmediaplayerservice/nuplayer/NuPlayer.cpp')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 4f88f02..c01f16a 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -33,6 +33,8 @@ #include "ATSParser.h" +#include <cutils/properties.h> + #include <media/stagefright/foundation/hexdump.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> @@ -453,8 +455,10 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { size_t trackIndex; int32_t select; + int64_t timeUs; CHECK(msg->findSize("trackIndex", &trackIndex)); CHECK(msg->findInt32("select", &select)); + CHECK(msg->findInt64("timeUs", &timeUs)); status_t err = INVALID_OPERATION; @@ -468,7 +472,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } if (trackIndex < inbandTracks) { - err = mSource->selectTrack(trackIndex, select); + err = mSource->selectTrack(trackIndex, select, timeUs); if (!select && err == OK) { int32_t type; @@ -604,8 +608,17 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { instantiateDecoder(false, &mVideoDecoder); } - if (mAudioSink != NULL) { - if (mOffloadAudio) { + // Don't try to re-open audio sink if there's an existing decoder. + if (mAudioSink != NULL && mAudioDecoder == NULL) { + sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */); + sp<AMessage> videoFormat = mSource->getFormat(false /* audio */); + audio_stream_type_t streamType = mAudioSink->getAudioStreamType(); + bool canOffload = canOffloadStream(audioMeta, (videoFormat != NULL), + true /* is_streaming */, streamType); + if (canOffload) { + if (!mOffloadAudio) { + mRenderer->signalEnableOffloadAudio(); + } // open audio sink early under offload mode. sp<AMessage> format = mSource->getFormat(true /*audio*/); openAudioSink(format, true /*offloadOnly*/); @@ -839,7 +852,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { ALOGV("media rendering started"); notifyListener(MEDIA_STARTED, 0, 0); } else if (what == Renderer::kWhatAudioOffloadTearDown) { - ALOGV("Tear down audio offload, fall back to s/w path"); + ALOGV("Tear down audio offload, fall back to s/w path if due to error."); int64_t positionUs; CHECK(msg->findInt64("positionUs", &positionUs)); int32_t reason; @@ -851,11 +864,11 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { if (mVideoDecoder != NULL) { mRenderer->flush(false /* audio */); } - mRenderer->signalDisableOffloadAudio(); - mOffloadAudio = false; performSeek(positionUs, false /* needNotify */); if (reason == Renderer::kDueToError) { + mRenderer->signalDisableOffloadAudio(); + mOffloadAudio = false; instantiateDecoder(true /* audio */, &mAudioDecoder); } } @@ -1190,6 +1203,17 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) { notify->setInt32("generation", mVideoDecoderGeneration); *decoder = new Decoder(notify, mSource, mRenderer, mNativeWindow); + + // enable FRC if high-quality AV sync is requested, even if not + // queuing to native window, as this will even improve textureview + // playback. + { + char value[PROPERTY_VALUE_MAX]; + if (property_get("persist.sys.media.avsync", value, NULL) && + (!strcmp("1", value) || !strcasecmp("true", value))) { + format->setInt32("auto-frc", 1); + } + } } (*decoder)->init(); (*decoder)->configure(format); @@ -1321,6 +1345,12 @@ status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) { // This stream is unaffected by the discontinuity return -EWOULDBLOCK; } + } else if (err == ERROR_END_OF_STREAM + && doBufferAggregation && (mAggregateBuffer != NULL)) { + // send out the last bit of aggregated data + reply->setBuffer("buffer", mAggregateBuffer); + mAggregateBuffer.clear(); + err = OK; } reply->setInt32("err", err); @@ -1624,10 +1654,11 @@ status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const { return err; } -status_t NuPlayer::selectTrack(size_t trackIndex, bool select) { +status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) { sp<AMessage> msg = new AMessage(kWhatSelectTrack, id()); msg->setSize("trackIndex", trackIndex); msg->setInt32("select", select); + msg->setInt64("timeUs", timeUs); sp<AMessage> response; status_t err = msg->postAndAwaitResponse(&response); |