summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/AwesomePlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/AwesomePlayer.cpp')
-rw-r--r--media/libstagefright/AwesomePlayer.cpp89
1 files changed, 69 insertions, 20 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index c912f75..29c007a 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -19,6 +19,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "AwesomePlayer"
#define ATRACE_TAG ATRACE_TAG_VIDEO
+#include <inttypes.h>
#include <utils/Log.h>
#include <utils/Trace.h>
@@ -606,6 +607,9 @@ void AwesomePlayer::reset_l() {
mWatchForAudioSeekComplete = false;
mWatchForAudioEOS = false;
+
+ mMediaRenderingStartGeneration = 0;
+ mStartGeneration = 0;
}
void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) {
@@ -722,7 +726,7 @@ void AwesomePlayer::onBufferingUpdate() {
if ((mFlags & PLAYING) && !eos
&& (cachedDataRemaining < kLowWaterMarkBytes)) {
- ALOGI("cache is running low (< %d) , pausing.",
+ ALOGI("cache is running low (< %zu) , pausing.",
kLowWaterMarkBytes);
modifyFlags(CACHE_UNDERRUN, SET);
pause_l();
@@ -731,12 +735,12 @@ void AwesomePlayer::onBufferingUpdate() {
notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
} else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
if (mFlags & CACHE_UNDERRUN) {
- ALOGI("cache has filled up (> %d), resuming.",
+ ALOGI("cache has filled up (> %zu), resuming.",
kHighWaterMarkBytes);
modifyFlags(CACHE_UNDERRUN, CLEAR);
play_l();
} else if (mFlags & PREPARING) {
- ALOGV("cache has filled up (> %d), prepare is done",
+ ALOGV("cache has filled up (> %zu), prepare is done",
kHighWaterMarkBytes);
finishAsyncPrepare_l();
}
@@ -798,7 +802,7 @@ void AwesomePlayer::onBufferingUpdate() {
}
}
- if (mFlags & (PLAYING | PREPARING)) {
+ if (mFlags & (PLAYING | PREPARING | CACHE_UNDERRUN)) {
postBufferingEvent_l();
}
}
@@ -895,6 +899,8 @@ status_t AwesomePlayer::play_l() {
return OK;
}
+ mMediaRenderingStartGeneration = ++mStartGeneration;
+
if (!(mFlags & PREPARED)) {
status_t err = prepare_l();
@@ -1197,8 +1203,7 @@ void AwesomePlayer::initRenderer_l() {
setVideoScalingMode_l(mVideoScalingMode);
if (USE_SURFACE_ALLOC
&& !strncmp(component, "OMX.", 4)
- && strncmp(component, "OMX.google.", 11)
- && strcmp(component, "OMX.Nvidia.mpeg2v.decode")) {
+ && strncmp(component, "OMX.google.", 11)) {
// Hardware decoders avoid the CPU color conversion by decoding
// directly to ANativeBuffers, so we must use a renderer that
// just pushes those buffers to the ANativeWindow.
@@ -1495,7 +1500,13 @@ status_t AwesomePlayer::initAudioDecoder() {
// This doesn't guarantee that the hardware has a free stream
// but it avoids us attempting to open (and re-open) an offload
// stream to hardware that doesn't have the necessary codec
- mOffloadAudio = canOffloadStream(meta, (mVideoSource != NULL), isStreamingHTTP());
+ audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
+ if (mAudioSink != NULL) {
+ streamType = mAudioSink->getAudioStreamType();
+ }
+
+ mOffloadAudio = canOffloadStream(meta, (mVideoSource != NULL),
+ isStreamingHTTP(), streamType);
if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
ALOGV("createAudioPlayer: bypass OMX (raw)");
@@ -1927,7 +1938,7 @@ void AwesomePlayer::onVideoEvent() {
++mStats.mNumVideoFramesDropped;
}
- postVideoEvent_l();
+ postVideoEvent_l(0);
return;
}
}
@@ -1967,6 +1978,41 @@ void AwesomePlayer::onVideoEvent() {
return;
}
+ /* get next frame time */
+ if (wasSeeking == NO_SEEK) {
+ MediaSource::ReadOptions options;
+ for (;;) {
+ status_t err = mVideoSource->read(&mVideoBuffer, &options);
+ if (err != OK) {
+ // deal with any errors next time
+ CHECK(mVideoBuffer == NULL);
+ postVideoEvent_l(0);
+ return;
+ }
+
+ if (mVideoBuffer->range_length() != 0) {
+ break;
+ }
+
+ // Some decoders, notably the PV AVC software decoder
+ // return spurious empty buffers that we just want to ignore.
+
+ mVideoBuffer->release();
+ mVideoBuffer = NULL;
+ }
+
+ {
+ Mutex::Autolock autoLock(mStatsLock);
+ ++mStats.mNumVideoFramesDecoded;
+ }
+
+ int64_t nextTimeUs;
+ CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &nextTimeUs));
+ int64_t delayUs = nextTimeUs - ts->getRealTimeUs() + mTimeSourceDeltaUs;
+ postVideoEvent_l(delayUs > 10000 ? 10000 : delayUs < 0 ? 0 : delayUs);
+ return;
+ }
+
postVideoEvent_l();
}
@@ -2051,7 +2097,10 @@ void AwesomePlayer::onCheckAudioStatus() {
mSeekNotificationSent = true;
}
- mSeeking = NO_SEEK;
+ if (mVideoSource == NULL) {
+ // For video the mSeeking flag is always reset in finishSeekIfNecessary
+ mSeeking = NO_SEEK;
+ }
notifyIfMediaStarted_l();
}
@@ -2247,8 +2296,8 @@ status_t AwesomePlayer::finishSetDataSource_l() {
sniffedMIME = tmp.string();
if (meta == NULL
- || !meta->findInt64(
- "meta-data-size", &metaDataSize)) {
+ || !meta->findInt64("meta-data-size",
+ reinterpret_cast<int64_t*>(&metaDataSize))) {
metaDataSize = kHighWaterMarkBytes;
}
@@ -2535,12 +2584,12 @@ status_t AwesomePlayer::getTrackInfo(Parcel *reply) const {
status_t AwesomePlayer::selectAudioTrack_l(
const sp<MediaSource>& source, size_t trackIndex) {
- ALOGI("selectAudioTrack_l: trackIndex=%d, mFlags=0x%x", trackIndex, mFlags);
+ ALOGI("selectAudioTrack_l: trackIndex=%zu, mFlags=0x%x", trackIndex, mFlags);
{
Mutex::Autolock autoLock(mStatsLock);
if ((ssize_t)trackIndex == mActiveAudioTrackIndex) {
- ALOGI("Track %d is active. Does nothing.", trackIndex);
+ ALOGI("Track %zu is active. Does nothing.", trackIndex);
return OK;
}
//mStats.mFlags = mFlags;
@@ -2613,7 +2662,7 @@ status_t AwesomePlayer::selectTrack(size_t trackIndex, bool select) {
trackCount += mTextDriver->countExternalTracks();
}
if (trackIndex >= trackCount) {
- ALOGE("Track index (%d) is out of range [0, %d)", trackIndex, trackCount);
+ ALOGE("Track index (%zu) is out of range [0, %zu)", trackIndex, trackCount);
return ERROR_OUT_OF_RANGE;
}
@@ -2625,14 +2674,14 @@ status_t AwesomePlayer::selectTrack(size_t trackIndex, bool select) {
isAudioTrack = !strncasecmp(mime, "audio/", 6);
if (!isAudioTrack && strcasecmp(mime, MEDIA_MIMETYPE_TEXT_3GPP) != 0) {
- ALOGE("Track %d is not either audio or timed text", trackIndex);
+ ALOGE("Track %zu is not either audio or timed text", trackIndex);
return ERROR_UNSUPPORTED;
}
}
if (isAudioTrack) {
if (!select) {
- ALOGE("Deselect an audio track (%d) is not supported", trackIndex);
+ ALOGE("Deselect an audio track (%zu) is not supported", trackIndex);
return ERROR_UNSUPPORTED;
}
return selectAudioTrack_l(mExtractor->getTrack(trackIndex), trackIndex);
@@ -2770,7 +2819,7 @@ status_t AwesomePlayer::dump(int fd, const Vector<String16> &args) const {
fprintf(out, ", flags(0x%08x)", mStats.mFlags);
if (mStats.mBitrate >= 0) {
- fprintf(out, ", bitrate(%lld bps)", mStats.mBitrate);
+ fprintf(out, ", bitrate(%" PRId64 " bps)", mStats.mBitrate);
}
fprintf(out, "\n");
@@ -2778,7 +2827,7 @@ status_t AwesomePlayer::dump(int fd, const Vector<String16> &args) const {
for (size_t i = 0; i < mStats.mTracks.size(); ++i) {
const TrackStat &stat = mStats.mTracks.itemAt(i);
- fprintf(out, " Track %d\n", i + 1);
+ fprintf(out, " Track %zu\n", i + 1);
fprintf(out, " MIME(%s)", stat.mMIME.string());
if (!stat.mDecoderName.isEmpty()) {
@@ -2790,8 +2839,8 @@ status_t AwesomePlayer::dump(int fd, const Vector<String16> &args) const {
if ((ssize_t)i == mStats.mVideoTrackIndex) {
fprintf(out,
" videoDimensions(%d x %d), "
- "numVideoFramesDecoded(%lld), "
- "numVideoFramesDropped(%lld)\n",
+ "numVideoFramesDecoded(%" PRId64 "), "
+ "numVideoFramesDropped(%" PRId64 ")\n",
mStats.mVideoWidth,
mStats.mVideoHeight,
mStats.mNumVideoFramesDecoded,