diff options
author | Andreas Huber <andih@google.com> | 2010-05-06 11:27:35 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-05-06 11:27:35 -0700 |
commit | 100ef9bee48c9beb83d885d233de6a42c64f55af (patch) | |
tree | 3b9a59401802c2ac195acccdb869a190acbfa075 /media | |
parent | 5305627d5b78b8d63ce344c4eb5d1a28ef44d3d0 (diff) | |
parent | 62f7ffe106a7126ef31b199552c5cfc6599bc3d1 (diff) | |
download | frameworks_base-100ef9bee48c9beb83d885d233de6a42c64f55af.zip frameworks_base-100ef9bee48c9beb83d885d233de6a42c64f55af.tar.gz frameworks_base-100ef9bee48c9beb83d885d233de6a42c64f55af.tar.bz2 |
Merge "Disable vorbis seek when streaming from localhost." into froyo
Diffstat (limited to 'media')
-rw-r--r-- | media/libmediaplayerservice/StagefrightPlayer.cpp | 29 | ||||
-rw-r--r-- | media/libmediaplayerservice/StagefrightPlayer.h | 3 | ||||
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 24 | ||||
-rw-r--r-- | media/libstagefright/HTTPDataSource.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/MediaExtractor.cpp | 4 | ||||
-rw-r--r-- | media/libstagefright/VorbisExtractor.cpp | 32 | ||||
-rw-r--r-- | media/libstagefright/include/AwesomePlayer.h | 6 | ||||
-rw-r--r-- | media/libstagefright/include/VorbisExtractor.h | 2 |
8 files changed, 106 insertions, 5 deletions
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp index 7776b4e..2c96d6d 100644 --- a/media/libmediaplayerservice/StagefrightPlayer.cpp +++ b/media/libmediaplayerservice/StagefrightPlayer.cpp @@ -6,6 +6,9 @@ #include "AwesomePlayer.h" +#include <media/Metadata.h> +#include <media/stagefright/MediaExtractor.h> + namespace android { StagefrightPlayer::StagefrightPlayer() @@ -109,7 +112,8 @@ status_t StagefrightPlayer::getDuration(int *msec) { status_t err = mPlayer->getDuration(&durationUs); if (err != OK) { - return err; + *msec = 0; + return OK; } *msec = (durationUs + 500) / 1000; @@ -156,4 +160,27 @@ void StagefrightPlayer::setAudioSink(const sp<AudioSink> &audioSink) { mPlayer->setAudioSink(audioSink); } +status_t StagefrightPlayer::getMetadata( + const media::Metadata::Filter& ids, Parcel *records) { + using media::Metadata; + + uint32_t flags = mPlayer->flags(); + + Metadata metadata(records); + + metadata.appendBool( + Metadata::kPauseAvailable, + flags & MediaExtractor::CAN_PAUSE); + + metadata.appendBool( + Metadata::kSeekBackwardAvailable, + flags & MediaExtractor::CAN_SEEK_BACKWARD); + + metadata.appendBool( + Metadata::kSeekForwardAvailable, + flags & MediaExtractor::CAN_SEEK_FORWARD); + + return OK; +} + } // namespace android diff --git a/media/libmediaplayerservice/StagefrightPlayer.h b/media/libmediaplayerservice/StagefrightPlayer.h index 4446582..781eb44 100644 --- a/media/libmediaplayerservice/StagefrightPlayer.h +++ b/media/libmediaplayerservice/StagefrightPlayer.h @@ -53,6 +53,9 @@ public: virtual status_t suspend(); virtual status_t resume(); + virtual status_t getMetadata( + const media::Metadata::Filter& ids, Parcel *records); + private: AwesomePlayer *mPlayer; diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index b14a03c..475160e 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -184,6 +184,7 @@ AwesomePlayer::AwesomePlayer() mVideoRendererIsPreview(false), mAudioPlayer(NULL), mFlags(0), + mExtractorFlags(0), mLastVideoBuffer(NULL), mVideoBuffer(NULL), mSuspensionState(NULL) { @@ -310,7 +311,13 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) { } } - return !haveAudio && !haveVideo ? UNKNOWN_ERROR : OK; + if (!haveAudio && !haveVideo) { + return UNKNOWN_ERROR; + } + + mExtractorFlags = extractor->flags(); + + return OK; } void AwesomePlayer::reset() { @@ -390,6 +397,7 @@ void AwesomePlayer::reset_l() { mDurationUs = -1; mFlags = 0; + mExtractorFlags = 0; mVideoWidth = mVideoHeight = -1; mTimeSourceDeltaUs = 0; mVideoTimeUs = 0; @@ -683,8 +691,14 @@ status_t AwesomePlayer::getPosition(int64_t *positionUs) { } status_t AwesomePlayer::seekTo(int64_t timeUs) { - Mutex::Autolock autoLock(mLock); - return seekTo_l(timeUs); + if (mExtractorFlags + & (MediaExtractor::CAN_SEEK_FORWARD + | MediaExtractor::CAN_SEEK_BACKWARD)) { + Mutex::Autolock autoLock(mLock); + return seekTo_l(timeUs); + } + + return OK; } status_t AwesomePlayer::seekTo_l(int64_t timeUs) { @@ -1362,5 +1376,9 @@ status_t AwesomePlayer::resume() { return OK; } +uint32_t AwesomePlayer::flags() const { + return mExtractorFlags; +} + } // namespace android diff --git a/media/libstagefright/HTTPDataSource.cpp b/media/libstagefright/HTTPDataSource.cpp index cca6062..8e26c37e 100644 --- a/media/libstagefright/HTTPDataSource.cpp +++ b/media/libstagefright/HTTPDataSource.cpp @@ -425,5 +425,16 @@ void HTTPDataSource::initHeaders( } } +uint32_t HTTPDataSource::flags() { + uint32_t f = kWantsPrefetching; + + if (!strcasecmp(mStartingHost.string(), "localhost") + || !strcmp(mStartingHost.string(), "127.0.0.1")) { + f |= kStreamedFromLocalHost; + } + + return f; +} + } // namespace android diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp index 832db04..dfddbe0 100644 --- a/media/libstagefright/MediaExtractor.cpp +++ b/media/libstagefright/MediaExtractor.cpp @@ -36,6 +36,10 @@ sp<MetaData> MediaExtractor::getMetaData() { return new MetaData; } +uint32_t MediaExtractor::flags() const { + return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE; +} + // static sp<MediaExtractor> MediaExtractor::Create( const sp<DataSource> &source, const char *mime) { diff --git a/media/libstagefright/VorbisExtractor.cpp b/media/libstagefright/VorbisExtractor.cpp index 96b05c0..e7b62d6 100644 --- a/media/libstagefright/VorbisExtractor.cpp +++ b/media/libstagefright/VorbisExtractor.cpp @@ -20,6 +20,7 @@ #include "include/VorbisExtractor.h" +#include <cutils/properties.h> #include <media/stagefright/DataSource.h> #include <media/stagefright/MediaBuffer.h> #include <media/stagefright/MediaBufferGroup.h> @@ -37,8 +38,23 @@ namespace android { struct VorbisDataSource { sp<DataSource> mDataSource; off_t mOffset; + bool mSeekDisabled; }; +static bool ShouldDisableSeek(const sp<DataSource> &source) { + char value[PROPERTY_VALUE_MAX]; + if (property_get("media.vorbis.always-allow-seek", value, NULL) + && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { + return false; + } + + // This is a workaround for an application streaming data through + // a local HTTP proxy that doesn't really conform to the HTTP/1.1 + // specs. We have to disable seek functionality in this case. + + return source->flags() & DataSource::kStreamedFromLocalHost; +} + static size_t VorbisRead( void *ptr, size_t size, size_t nmemb, void *datasource) { VorbisDataSource *vds = (VorbisDataSource *)datasource; @@ -58,6 +74,11 @@ static int VorbisSeek( void *datasource, ogg_int64_t offset, int whence) { VorbisDataSource *vds = (VorbisDataSource *)datasource; + if (vds->mSeekDisabled) { + errno = ESPIPE; + return -1; + } + switch (whence) { case SEEK_SET: vds->mOffset = offset; @@ -218,6 +239,7 @@ VorbisExtractor::VorbisExtractor(const sp<DataSource> &source) mInitCheck(NO_INIT) { mVorbisDataSource->mDataSource = mDataSource; mVorbisDataSource->mOffset = 0; + mVorbisDataSource->mSeekDisabled = ShouldDisableSeek(mDataSource); int res = ov_open_callbacks( mVorbisDataSource, mFile, NULL, 0, gVorbisCallbacks); @@ -291,6 +313,7 @@ bool SniffVorbis( VorbisDataSource vds; vds.mDataSource = source; vds.mOffset = 0; + vds.mSeekDisabled = ShouldDisableSeek(source); int res = ov_test_callbacks(&vds, &file, NULL, 0, gVorbisCallbacks); @@ -308,4 +331,13 @@ bool SniffVorbis( return true; } +uint32_t VorbisExtractor::flags() const { + if (ShouldDisableSeek(mDataSource)) { + LOGI("This is streamed from local host, seek disabled"); + return CAN_PAUSE; + } else { + return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE; + } +} + } // namespace android diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 9e8a674..9455743 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -84,10 +84,13 @@ struct AwesomePlayer { status_t suspend(); status_t resume(); + // This is a mask of MediaExtractor::Flags. + uint32_t flags() const; + private: friend struct AwesomeEvent; - enum Flags { + enum { PLAYING = 1, LOOPING = 2, FIRST_FRAME = 4, @@ -126,6 +129,7 @@ private: int64_t mDurationUs; uint32_t mFlags; + uint32_t mExtractorFlags; int32_t mVideoWidth, mVideoHeight; int64_t mTimeSourceDeltaUs; diff --git a/media/libstagefright/include/VorbisExtractor.h b/media/libstagefright/include/VorbisExtractor.h index 8e38a93..2bb7deb 100644 --- a/media/libstagefright/include/VorbisExtractor.h +++ b/media/libstagefright/include/VorbisExtractor.h @@ -38,6 +38,8 @@ struct VorbisExtractor : public MediaExtractor { virtual sp<MetaData> getMetaData(); + uint32_t flags() const; + protected: virtual ~VorbisExtractor(); |