diff options
Diffstat (limited to 'media/libstagefright/MediaPlayerImpl.cpp')
-rw-r--r-- | media/libstagefright/MediaPlayerImpl.cpp | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/media/libstagefright/MediaPlayerImpl.cpp b/media/libstagefright/MediaPlayerImpl.cpp index 622ea7e..c1044a3 100644 --- a/media/libstagefright/MediaPlayerImpl.cpp +++ b/media/libstagefright/MediaPlayerImpl.cpp @@ -18,16 +18,17 @@ #define LOG_TAG "MediaPlayerImpl" #include "utils/Log.h" +#include "include/stagefright_string.h" +#include "include/HTTPStream.h" + #include <OMX_Component.h> #include <unistd.h> #include <media/stagefright/AudioPlayer.h> -#include <media/stagefright/CachingDataSource.h> // #include <media/stagefright/CameraSource.h> -#include <media/stagefright/HTTPDataSource.h> -#include <media/stagefright/HTTPStream.h> #include <media/stagefright/MediaDebug.h> +#include <media/stagefright/MediaDefs.h> #include <media/stagefright/MediaExtractor.h> #include <media/stagefright/MediaPlayerImpl.h> #include <media/stagefright/MetaData.h> @@ -51,7 +52,7 @@ MediaPlayerImpl::MediaPlayerImpl(const char *uri) mPlaying(false), mPaused(false), mSeeking(false) { - LOGI("MediaPlayerImpl(%s)", uri); + LOGV("MediaPlayerImpl(%s)", uri); DataSource::RegisterDefaultSniffers(); status_t err = mClient.connect(); @@ -69,18 +70,7 @@ MediaPlayerImpl::MediaPlayerImpl(const char *uri) mVideoDecoder = CameraSource::Create(); #endif } else { - sp<DataSource> source; - if (!strncasecmp("file://", uri, 7)) { - source = new MmapSource(uri + 7); - } else if (!strncasecmp("http://", uri, 7)) { - source = new HTTPDataSource(uri); - source = new CachingDataSource(source, 64 * 1024, 10); - } else { - // Assume it's a filename. - source = new MmapSource(uri); - } - - mExtractor = MediaExtractor::Create(source); + mExtractor = MediaExtractor::CreateFromURI(uri); if (mExtractor == NULL) { return; @@ -103,7 +93,7 @@ MediaPlayerImpl::MediaPlayerImpl(int fd, int64_t offset, int64_t length) mPlaying(false), mPaused(false), mSeeking(false) { - LOGI("MediaPlayerImpl(%d, %lld, %lld)", fd, offset, length); + LOGV("MediaPlayerImpl(%d, %lld, %lld)", fd, offset, length); DataSource::RegisterDefaultSniffers(); status_t err = mClient.connect(); @@ -140,7 +130,7 @@ MediaPlayerImpl::~MediaPlayerImpl() { } void MediaPlayerImpl::play() { - LOGI("play"); + LOGV("play"); if (mPlaying) { if (mPaused) { @@ -241,7 +231,7 @@ void MediaPlayerImpl::videoEntry() { { Mutex::Autolock autoLock(mLock); if (mSeeking) { - LOGI("seek-options to %lld", mSeekTimeUs); + LOGV("seek-options to %lld", mSeekTimeUs); options.setSeekTo(mSeekTimeUs); mSeeking = false; @@ -258,6 +248,13 @@ void MediaPlayerImpl::videoEntry() { status_t err = mVideoDecoder->read(&buffer, &options); CHECK((err == OK && buffer != NULL) || (err != OK && buffer == NULL)); + if (err == INFO_FORMAT_CHANGED) { + LOGV("format changed."); + depopulateISurface(); + populateISurface(); + continue; + } + if (err == ERROR_END_OF_STREAM || err != OK) { eof = true; continue; @@ -269,15 +266,9 @@ void MediaPlayerImpl::videoEntry() { continue; } - int32_t units, scale; - bool success = - buffer->meta_data()->findInt32(kKeyTimeUnits, &units); - CHECK(success); - success = - buffer->meta_data()->findInt32(kKeyTimeScale, &scale); - CHECK(success); + int64_t pts_us; + CHECK(buffer->meta_data()->findInt64(kKeyTime, &pts_us)); - int64_t pts_us = (int64_t)units * 1000000 / scale; { Mutex::Autolock autoLock(mLock); mVideoPosition = pts_us; @@ -332,14 +323,14 @@ void MediaPlayerImpl::displayOrDiscardFrame( if (delay_us < -15000) { // We're late. - LOGI("we're late by %lld ms, dropping a frame\n", + LOGV("we're late by %lld ms, dropping a frame\n", -delay_us / 1000); buffer->release(); buffer = NULL; return; } else if (delay_us > 100000) { - LOGI("we're much too early (by %lld ms)\n", + LOGV("we're much too early (by %lld ms)\n", delay_us / 1000); usleep(100000); continue; @@ -391,12 +382,10 @@ void MediaPlayerImpl::init() { sp<MediaSource> source = mExtractor->getTrack(i); - int32_t units, scale; - if (meta->findInt32(kKeyDuration, &units) - && meta->findInt32(kKeyTimeScale, &scale)) { - int64_t duration_us = (int64_t)units * 1000000 / scale; - if (duration_us > mDuration) { - mDuration = duration_us; + int64_t durationUs; + if (meta->findInt64(kKeyDuration, &durationUs)) { + if (durationUs > mDuration) { + mDuration = durationUs; } } @@ -410,17 +399,24 @@ void MediaPlayerImpl::init() { } void MediaPlayerImpl::setAudioSource(const sp<MediaSource> &source) { - LOGI("setAudioSource"); + LOGV("setAudioSource"); mAudioSource = source; sp<MetaData> meta = source->getFormat(); - mAudioDecoder = OMXCodec::Create( - mClient.interface(), meta, false /* createEncoder */, source); + const char *mime; + CHECK(meta->findCString(kKeyMIMEType, &mime)); + + if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) { + mAudioDecoder = source; + } else { + mAudioDecoder = OMXCodec::Create( + mClient.interface(), meta, false /* createEncoder */, source); + } } void MediaPlayerImpl::setVideoSource(const sp<MediaSource> &source) { - LOGI("setVideoSource"); + LOGV("setVideoSource"); mVideoSource = source; sp<MetaData> meta = source->getFormat(); @@ -441,7 +437,7 @@ void MediaPlayerImpl::setVideoSource(const sp<MediaSource> &source) { } void MediaPlayerImpl::setSurface(const sp<Surface> &surface) { - LOGI("setSurface %p", surface.get()); + LOGV("setSurface %p", surface.get()); Mutex::Autolock autoLock(mLock); depopulateISurface(); @@ -455,7 +451,7 @@ void MediaPlayerImpl::setSurface(const sp<Surface> &surface) { } void MediaPlayerImpl::setISurface(const sp<ISurface> &isurface) { - LOGI("setISurface %p", isurface.get()); + LOGV("setISurface %p", isurface.get()); Mutex::Autolock autoLock(mLock); depopulateISurface(); @@ -499,7 +495,7 @@ MediaSource *MediaPlayerImpl::makeShoutcastSource(const char *uri) { host = string(host, 0, colon - host.c_str()); } - LOGI("Connecting to host '%s', port %d, path '%s'", + LOGV("Connecting to host '%s', port %d, path '%s'", host.c_str(), port, path.c_str()); HTTPStream *http = new HTTPStream; @@ -533,7 +529,7 @@ MediaSource *MediaPlayerImpl::makeShoutcastSource(const char *uri) { http->disconnect(); - LOGI("Redirecting to %s\n", location.c_str()); + LOGV("Redirecting to %s\n", location.c_str()); host = string(location, 0, slashPos); @@ -588,7 +584,7 @@ int64_t MediaPlayerImpl::getPosition() { } status_t MediaPlayerImpl::seekTo(int64_t time) { - LOGI("seekTo %lld", time); + LOGV("seekTo %lld", time); if (mPaused) { return UNKNOWN_ERROR; @@ -621,6 +617,9 @@ void MediaPlayerImpl::populateISurface() { success = success && meta->findInt32(kKeyHeight, &decodedHeight); CHECK(success); + LOGV("mVideoWidth=%d, mVideoHeight=%d, decodedWidth=%d, decodedHeight=%d", + mVideoWidth, mVideoHeight, decodedWidth, decodedHeight); + if (mSurface.get() != NULL) { mVideoRenderer = mClient.interface()->createRenderer( @@ -651,7 +650,7 @@ void MediaPlayerImpl::sendFrameToISurface(MediaBuffer *buffer) { void MediaPlayerImpl::setAudioSink( const sp<MediaPlayerBase::AudioSink> &audioSink) { - LOGI("setAudioSink %p", audioSink.get()); + LOGV("setAudioSink %p", audioSink.get()); mAudioSink = audioSink; } |