diff options
Diffstat (limited to 'media/libstagefright/include')
21 files changed, 900 insertions, 88 deletions
diff --git a/media/libstagefright/include/AACDecoder.h b/media/libstagefright/include/AACDecoder.h index f09addd..200f93c 100644 --- a/media/libstagefright/include/AACDecoder.h +++ b/media/libstagefright/include/AACDecoder.h @@ -25,6 +25,7 @@ struct tPVMP4AudioDecoderExternal; namespace android { struct MediaBufferGroup; +struct MetaData; struct AACDecoder : public MediaSource { AACDecoder(const sp<MediaSource> &source); @@ -41,6 +42,7 @@ protected: virtual ~AACDecoder(); private: + sp<MetaData> mMeta; sp<MediaSource> mSource; bool mStarted; @@ -50,9 +52,11 @@ private: void *mDecoderBuf; int64_t mAnchorTimeUs; int64_t mNumSamplesOutput; + status_t mInitCheck; MediaBuffer *mInputBuffer; + status_t initCheck(); AACDecoder(const AACDecoder &); AACDecoder &operator=(const AACDecoder &); }; diff --git a/media/libstagefright/include/AACEncoder.h b/media/libstagefright/include/AACEncoder.h new file mode 100644 index 0000000..ecc533f --- /dev/null +++ b/media/libstagefright/include/AACEncoder.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AAC_ENCODER_H +#define AAC_ENCODER_H + +#include <media/stagefright/MediaSource.h> +#include <media/stagefright/MetaData.h> + +struct VO_AUDIO_CODECAPI; +struct VO_MEM_OPERATOR; + +namespace android { + +struct MediaBufferGroup; + +class AACEncoder: public MediaSource { + public: + AACEncoder(const sp<MediaSource> &source, const sp<MetaData> &meta); + + virtual status_t start(MetaData *params); + virtual status_t stop(); + virtual sp<MetaData> getFormat(); + virtual status_t read( + MediaBuffer **buffer, const ReadOptions *options); + + + protected: + virtual ~AACEncoder(); + + private: + sp<MediaSource> mSource; + sp<MetaData> mMeta; + bool mStarted; + MediaBufferGroup *mBufferGroup; + MediaBuffer *mInputBuffer; + status_t mInitCheck; + int32_t mSampleRate; + int32_t mChannels; + int32_t mBitRate; + int32_t mFrameCount; + + int64_t mAnchorTimeUs; + int64_t mNumInputSamples; + + enum { + kNumSamplesPerFrame = 1024, + }; + + int16_t mInputFrame[kNumSamplesPerFrame]; + + uint8_t mAudioSpecificConfigData[2]; // auido specific data + void *mEncoderHandle; + VO_AUDIO_CODECAPI *mApiHandle; + VO_MEM_OPERATOR *mMemOperator; + + status_t setAudioSpecificConfigData(); + status_t initCheck(); + + AACEncoder& operator=(const AACEncoder &rhs); + AACEncoder(const AACEncoder& copy); + +}; + +} + +#endif //#ifndef AAC_ENCODER_H + diff --git a/media/libstagefright/include/AMRNBEncoder.h b/media/libstagefright/include/AMRNBEncoder.h index 7167c00..71160e6 100644 --- a/media/libstagefright/include/AMRNBEncoder.h +++ b/media/libstagefright/include/AMRNBEncoder.h @@ -19,13 +19,14 @@ #define AMR_NB_ENCODER_H_ #include <media/stagefright/MediaSource.h> +#include <media/stagefright/MetaData.h> namespace android { struct MediaBufferGroup; struct AMRNBEncoder : public MediaSource { - AMRNBEncoder(const sp<MediaSource> &source); + AMRNBEncoder(const sp<MediaSource> &source, const sp<MetaData> &meta); virtual status_t start(MetaData *params); virtual status_t stop(); @@ -40,6 +41,7 @@ protected: private: sp<MediaSource> mSource; + sp<MetaData> mMeta; bool mStarted; MediaBufferGroup *mBufferGroup; diff --git a/media/libstagefright/include/AMRWBEncoder.h b/media/libstagefright/include/AMRWBEncoder.h new file mode 100644 index 0000000..f2d155f --- /dev/null +++ b/media/libstagefright/include/AMRWBEncoder.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AMR_WB_ENCODER_H +#define AMR_WB_ENCODER_H + +#include <media/stagefright/MediaSource.h> +#include <media/stagefright/MetaData.h> + +struct VO_AUDIO_CODECAPI; +struct VO_MEM_OPERATOR; + +namespace android { + +struct MediaBufferGroup; + +class AMRWBEncoder: public MediaSource { + public: + AMRWBEncoder(const sp<MediaSource> &source, const sp<MetaData> &meta); + + virtual status_t start(MetaData *params); + virtual status_t stop(); + virtual sp<MetaData> getFormat(); + virtual status_t read( + MediaBuffer **buffer, const ReadOptions *options); + + + protected: + virtual ~AMRWBEncoder(); + + private: + sp<MediaSource> mSource; + sp<MetaData> mMeta; + bool mStarted; + MediaBufferGroup *mBufferGroup; + MediaBuffer *mInputBuffer; + status_t mInitCheck; + int32_t mBitRate; + void *mEncoderHandle; + VO_AUDIO_CODECAPI *mApiHandle; + VO_MEM_OPERATOR *mMemOperator; + + int64_t mAnchorTimeUs; + int64_t mNumFramesOutput; + + int16_t mInputFrame[320]; + int32_t mNumInputSamples; + + status_t initCheck(); + + AMRWBEncoder& operator=(const AMRWBEncoder &rhs); + AMRWBEncoder(const AMRWBEncoder& copy); + +}; + +} + +#endif //#ifndef AMR_WB_ENCODER_H + diff --git a/media/libstagefright/include/ARTSPController.h b/media/libstagefright/include/ARTSPController.h new file mode 100644 index 0000000..55efd41 --- /dev/null +++ b/media/libstagefright/include/ARTSPController.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_RTSP_CONTROLLER_H_ + +#define A_RTSP_CONTROLLER_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/MediaExtractor.h> + +namespace android { + +struct ALooper; +struct MyHandler; + +struct ARTSPController : public MediaExtractor { + ARTSPController(const sp<ALooper> &looper); + + status_t connect(const char *url); + void disconnect(); + + virtual size_t countTracks(); + virtual sp<MediaSource> getTrack(size_t index); + + virtual sp<MetaData> getTrackMetaData( + size_t index, uint32_t flags); + +protected: + virtual ~ARTSPController(); + +private: + sp<ALooper> mLooper; + sp<MyHandler> mHandler; + + DISALLOW_EVIL_CONSTRUCTORS(ARTSPController); +}; + +} // namespace android + +#endif // A_RTSP_CONTROLLER_H_ diff --git a/media/libstagefright/include/AVCDecoder.h b/media/libstagefright/include/AVCDecoder.h index 621aa9a..7810171 100644 --- a/media/libstagefright/include/AVCDecoder.h +++ b/media/libstagefright/include/AVCDecoder.h @@ -58,6 +58,9 @@ private: int64_t mAnchorTimeUs; int64_t mNumSamplesOutput; int64_t mPendingSeekTimeUs; + MediaSource::ReadOptions::SeekMode mPendingSeekMode; + + int64_t mTargetTimeUs; void addCodecSpecificData(const uint8_t *data, size_t size); diff --git a/media/libstagefright/include/AVCEncoder.h b/media/libstagefright/include/AVCEncoder.h new file mode 100644 index 0000000..4fe2e30 --- /dev/null +++ b/media/libstagefright/include/AVCEncoder.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AVC_ENCODER_H_ + +#define AVC_ENCODER_H_ + +#include <media/stagefright/MediaBuffer.h> +#include <media/stagefright/MediaSource.h> +#include <utils/Vector.h> + +struct tagAVCHandle; +struct tagAVCEncParam; + +namespace android { + +struct MediaBuffer; +struct MediaBufferGroup; + +struct AVCEncoder : public MediaSource, + public MediaBufferObserver { + AVCEncoder(const sp<MediaSource> &source, + const sp<MetaData>& meta); + + virtual status_t start(MetaData *params); + virtual status_t stop(); + + virtual sp<MetaData> getFormat(); + + virtual status_t read( + MediaBuffer **buffer, const ReadOptions *options); + + virtual void signalBufferReturned(MediaBuffer *buffer); + + // Callbacks required by the encoder + int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers); + void unbindOutputBuffer(int32_t index); + int32_t bindOutputBuffer(int32_t index, uint8_t **yuv); + +protected: + virtual ~AVCEncoder(); + +private: + sp<MediaSource> mSource; + sp<MetaData> mFormat; + sp<MetaData> mMeta; + + int32_t mVideoWidth; + int32_t mVideoHeight; + int32_t mVideoFrameRate; + int32_t mVideoBitRate; + int32_t mVideoColorFormat; + int64_t mNumInputFrames; + status_t mInitCheck; + bool mStarted; + bool mSpsPpsHeaderReceived; + bool mReadyForNextFrame; + int32_t mIsIDRFrame; // for set kKeyIsSyncFrame + + tagAVCHandle *mHandle; + tagAVCEncParam *mEncParams; + MediaBuffer *mInputBuffer; + uint8_t *mInputFrameData; + MediaBufferGroup *mGroup; + Vector<MediaBuffer *> mOutputBuffers; + + + status_t initCheck(const sp<MetaData>& meta); + void releaseOutputBuffers(); + + AVCEncoder(const AVCEncoder &); + AVCEncoder &operator=(const AVCEncoder &); +}; + +} // namespace android + +#endif // AVC_ENCODER_H_ diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 9455743..8d0877c 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -18,12 +18,13 @@ #define AWESOME_PLAYER_H_ +#include "NuHTTPDataSource.h" #include "TimedEventQueue.h" #include <media/MediaPlayerInterface.h> #include <media/stagefright/DataSource.h> -#include <media/stagefright/HTTPDataSource.h> #include <media/stagefright/OMXClient.h> +#include <media/stagefright/TimeSource.h> #include <utils/threads.h> namespace android { @@ -33,8 +34,10 @@ struct DataSource; struct MediaBuffer; struct MediaExtractor; struct MediaSource; -struct Prefetcher; -struct TimeSource; +struct NuCachedSource2; + +struct ALooper; +struct ARTSPController; struct AwesomeRenderer : public RefBase { AwesomeRenderer() {} @@ -98,6 +101,9 @@ private: PREPARED = 16, AT_EOS = 32, PREPARE_CANCELLED = 64, + CACHE_UNDERRUN = 128, + AUDIO_AT_EOS = 256, + VIDEO_AT_EOS = 512, }; mutable Mutex mLock; @@ -111,6 +117,7 @@ private: sp<ISurface> mISurface; sp<MediaPlayerBase::AudioSink> mAudioSink; + SystemTimeSource mSystemTimeSource; TimeSource *mTimeSource; String8 mUri; @@ -166,8 +173,11 @@ private: MediaBuffer *mLastVideoBuffer; MediaBuffer *mVideoBuffer; - sp<Prefetcher> mPrefetcher; - sp<HTTPDataSource> mConnectingDataSource; + sp<NuHTTPDataSource> mConnectingDataSource; + sp<NuCachedSource2> mCachedSource; + + sp<ALooper> mLooper; + sp<ARTSPController> mRTSPController; struct SuspensionState { String8 mUri; diff --git a/media/libstagefright/include/LiveSource.h b/media/libstagefright/include/LiveSource.h new file mode 100644 index 0000000..c55508c --- /dev/null +++ b/media/libstagefright/include/LiveSource.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIVE_SOURCE_H_ + +#define LIVE_SOURCE_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AString.h> +#include <media/stagefright/DataSource.h> +#include <utils/Vector.h> + +namespace android { + +struct ABuffer; +struct NuHTTPDataSource; +struct M3UParser; + +struct LiveSource : public DataSource { + LiveSource(const char *url); + + virtual status_t initCheck() const; + + virtual ssize_t readAt(off_t offset, void *data, size_t size); + + virtual uint32_t flags() { + return kWantsPrefetching; + } + +protected: + virtual ~LiveSource(); + +private: + AString mURL; + status_t mInitCheck; + + sp<M3UParser> mPlaylist; + int32_t mFirstItemSequenceNumber; + size_t mPlaylistIndex; + int64_t mLastFetchTimeUs; + + sp<NuHTTPDataSource> mSource; + off_t mSourceSize; + off_t mOffsetBias; + + status_t fetchM3U(const char *url, sp<ABuffer> *buffer); + + bool switchToNext(); + bool loadPlaylist(); + + DISALLOW_EVIL_CONSTRUCTORS(LiveSource); +}; + +} // namespace android + +#endif // LIVE_SOURCE_H_ diff --git a/media/libstagefright/include/M3UParser.h b/media/libstagefright/include/M3UParser.h new file mode 100644 index 0000000..36553de --- /dev/null +++ b/media/libstagefright/include/M3UParser.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef M3U_PARSER_H_ + +#define M3U_PARSER_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AMessage.h> +#include <media/stagefright/foundation/AString.h> +#include <utils/Vector.h> + +namespace android { + +struct M3UParser : public RefBase { + M3UParser(const char *baseURI, const void *data, size_t size); + + status_t initCheck() const; + + bool isExtM3U() const; + bool isVariantPlaylist() const; + + sp<AMessage> meta(); + + size_t size(); + bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL); + +protected: + virtual ~M3UParser(); + +private: + struct Item { + AString mURI; + sp<AMessage> mMeta; + }; + + status_t mInitCheck; + + AString mBaseURI; + bool mIsExtM3U; + bool mIsVariantPlaylist; + + sp<AMessage> mMeta; + Vector<Item> mItems; + + status_t parse(const void *data, size_t size); + + static status_t parseMetaData( + const AString &line, sp<AMessage> *meta, const char *key); + + static status_t ParseInt32(const char *s, int32_t *x); + + DISALLOW_EVIL_CONSTRUCTORS(M3UParser); +}; + +} // namespace android + +#endif // M3U_PARSER_H_ diff --git a/media/libstagefright/include/M4vH263Decoder.h b/media/libstagefright/include/M4vH263Decoder.h index ec49e80..7d73e30 100644 --- a/media/libstagefright/include/M4vH263Decoder.h +++ b/media/libstagefright/include/M4vH263Decoder.h @@ -54,6 +54,7 @@ private: MediaBuffer *mInputBuffer; int64_t mNumSamplesOutput; + int64_t mTargetTimeUs; void allocateFrames(int32_t width, int32_t height); void releaseFrames(); diff --git a/media/libstagefright/include/M4vH263Encoder.h b/media/libstagefright/include/M4vH263Encoder.h new file mode 100644 index 0000000..dd146f4 --- /dev/null +++ b/media/libstagefright/include/M4vH263Encoder.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef M4V_H263_ENCODER_H_ + +#define M4V_H263_ENCODER_H_ + +#include <media/stagefright/MediaBuffer.h> +#include <media/stagefright/MediaSource.h> + +struct tagvideoEncControls; +struct tagvideoEncOptions; + +namespace android { + +struct MediaBuffer; +struct MediaBufferGroup; + +struct M4vH263Encoder : public MediaSource, + public MediaBufferObserver { + M4vH263Encoder(const sp<MediaSource> &source, + const sp<MetaData>& meta); + + virtual status_t start(MetaData *params); + virtual status_t stop(); + + virtual sp<MetaData> getFormat(); + + virtual status_t read( + MediaBuffer **buffer, const ReadOptions *options); + + virtual void signalBufferReturned(MediaBuffer *buffer); + +protected: + virtual ~M4vH263Encoder(); + +private: + sp<MediaSource> mSource; + sp<MetaData> mFormat; + sp<MetaData> mMeta; + + int32_t mVideoWidth; + int32_t mVideoHeight; + int32_t mVideoFrameRate; + int32_t mVideoBitRate; + int32_t mVideoColorFormat; + int64_t mNumInputFrames; + int64_t mNextModTimeUs; + status_t mInitCheck; + bool mStarted; + + tagvideoEncControls *mHandle; + tagvideoEncOptions *mEncParams; + MediaBuffer *mInputBuffer; + uint8_t *mInputFrameData; + MediaBufferGroup *mGroup; + + status_t initCheck(const sp<MetaData>& meta); + void releaseOutputBuffers(); + + M4vH263Encoder(const M4vH263Encoder &); + M4vH263Encoder &operator=(const M4vH263Encoder &); +}; + +} // namespace android + +#endif // M4V_H263_ENCODER_H_ diff --git a/media/libstagefright/include/MP3Decoder.h b/media/libstagefright/include/MP3Decoder.h index 88aa4c6..4086fb6 100644 --- a/media/libstagefright/include/MP3Decoder.h +++ b/media/libstagefright/include/MP3Decoder.h @@ -42,6 +42,9 @@ protected: private: sp<MediaSource> mSource; + sp<MetaData> mMeta; + int32_t mNumChannels; + bool mStarted; MediaBufferGroup *mBufferGroup; @@ -49,10 +52,12 @@ private: tPVMP3DecoderExternal *mConfig; void *mDecoderBuf; int64_t mAnchorTimeUs; - int64_t mNumSamplesOutput; + int64_t mNumFramesOutput; MediaBuffer *mInputBuffer; + void init(); + MP3Decoder(const MP3Decoder &); MP3Decoder &operator=(const MP3Decoder &); }; diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h new file mode 100644 index 0000000..c96973b --- /dev/null +++ b/media/libstagefright/include/MPEG2TSExtractor.h @@ -0,0 +1,54 @@ +#ifndef MPEG2_TS_EXTRACTOR_H_ + +#define MPEG2_TS_EXTRACTOR_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/MediaExtractor.h> +#include <utils/threads.h> +#include <utils/Vector.h> + +namespace android { + +struct AnotherPacketSource; +struct ATSParser; +struct DataSource; +struct MPEG2TSSource; +struct String8; + +struct MPEG2TSExtractor : public MediaExtractor { + MPEG2TSExtractor(const sp<DataSource> &source); + + virtual size_t countTracks(); + virtual sp<MediaSource> getTrack(size_t index); + virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags); + + virtual sp<MetaData> getMetaData(); + + virtual uint32_t flags() const { + return CAN_PAUSE; + } + +private: + friend struct MPEG2TSSource; + + Mutex mLock; + + sp<DataSource> mDataSource; + sp<ATSParser> mParser; + + Vector<sp<AnotherPacketSource> > mSourceImpls; + + off_t mOffset; + + void init(); + status_t feedMore(); + + DISALLOW_EVIL_CONSTRUCTORS(MPEG2TSExtractor); +}; + +bool SniffMPEG2TS( + const sp<DataSource> &source, String8 *mimeType, float *confidence); + +} // namespace android + +#endif // MPEG2_TS_EXTRACTOR_H_ diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h new file mode 100644 index 0000000..3a20c16 --- /dev/null +++ b/media/libstagefright/include/NuCachedSource2.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NU_CACHED_SOURCE_2_H_ + +#define NU_CACHED_SOURCE_2_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AHandlerReflector.h> +#include <media/stagefright/DataSource.h> + +namespace android { + +struct ALooper; +struct PageCache; + +struct NuCachedSource2 : public DataSource { + NuCachedSource2(const sp<DataSource> &source); + + virtual status_t initCheck() const; + + virtual ssize_t readAt(off_t offset, void *data, size_t size); + + virtual status_t getSize(off_t *size); + virtual uint32_t flags(); + + //////////////////////////////////////////////////////////////////////////// + + size_t cachedSize(); + size_t approxDataRemaining(bool *eos); + +protected: + virtual ~NuCachedSource2(); + +private: + friend struct AHandlerReflector<NuCachedSource2>; + + enum { + kPageSize = 65536, + kHighWaterThreshold = 5 * 1024 * 1024, + kLowWaterThreshold = 512 * 1024, + + // Read data after a 15 sec timeout whether we're actively + // fetching or not. + kKeepAliveIntervalUs = 15000000, + }; + + enum { + kWhatFetchMore = 'fetc', + kWhatRead = 'read', + }; + + sp<DataSource> mSource; + sp<AHandlerReflector<NuCachedSource2> > mReflector; + sp<ALooper> mLooper; + + Mutex mSerializer; + Mutex mLock; + Condition mCondition; + + PageCache *mCache; + off_t mCacheOffset; + status_t mFinalStatus; + off_t mLastAccessPos; + sp<AMessage> mAsyncResult; + bool mFetching; + int64_t mLastFetchTimeUs; + + void onMessageReceived(const sp<AMessage> &msg); + void onFetch(); + void onRead(const sp<AMessage> &msg); + + void fetchInternal(); + ssize_t readInternal(off_t offset, void *data, size_t size); + status_t seekInternal_l(off_t offset); + + size_t approxDataRemaining_l(bool *eos); + void restartPrefetcherIfNecessary_l(); + + DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2); +}; + +} // namespace android + +#endif // NU_CACHED_SOURCE_2_H_ diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h new file mode 100644 index 0000000..8593a91 --- /dev/null +++ b/media/libstagefright/include/NuHTTPDataSource.h @@ -0,0 +1,73 @@ +#ifndef NU_HTTP_DATA_SOURCE_H_ + +#define NU_HTTP_DATA_SOURCE_H_ + +#include <media/stagefright/DataSource.h> +#include <utils/String8.h> +#include <utils/threads.h> + +#include "HTTPStream.h" + +namespace android { + +struct NuHTTPDataSource : public DataSource { + NuHTTPDataSource(); + + status_t connect( + const char *uri, + const KeyedVector<String8, String8> *headers = NULL, + off_t offset = 0); + + void disconnect(); + + virtual status_t initCheck() const; + + virtual ssize_t readAt(off_t offset, void *data, size_t size); + virtual status_t getSize(off_t *size); + virtual uint32_t flags(); + +protected: + virtual ~NuHTTPDataSource(); + +private: + enum State { + DISCONNECTED, + CONNECTING, + CONNECTED + }; + + Mutex mLock; + + State mState; + + String8 mHost; + unsigned mPort; + String8 mPath; + String8 mHeaders; + + HTTPStream mHTTP; + off_t mOffset; + off_t mContentLength; + bool mContentLengthValid; + + status_t connect( + const char *uri, const String8 &headers, off_t offset); + + status_t connect( + const char *host, unsigned port, const char *path, + const String8 &headers, + off_t offset); + + void applyTimeoutResponse(); + + static void MakeFullHeaders( + const KeyedVector<String8, String8> *overrides, + String8 *headers); + + NuHTTPDataSource(const NuHTTPDataSource &); + NuHTTPDataSource &operator=(const NuHTTPDataSource &); +}; + +} // namespace android + +#endif // NU_HTTP_DATA_SOURCE_H_ diff --git a/media/libstagefright/include/OMX.h b/media/libstagefright/include/OMX.h index ea131e8..c99da59 100644 --- a/media/libstagefright/include/OMX.h +++ b/media/libstagefright/include/OMX.h @@ -102,7 +102,7 @@ public: OMX_IN OMX_U32 nData1, OMX_IN OMX_U32 nData2, OMX_IN OMX_PTR pEventData); - + OMX_ERRORTYPE OnEmptyBufferDone( node_id node, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); @@ -115,20 +115,19 @@ protected: virtual ~OMX(); private: - Mutex mLock; - - OMXMaster *mMaster; - struct CallbackDispatcher; - sp<CallbackDispatcher> mDispatcher; + Mutex mLock; + OMXMaster *mMaster; int32_t mNodeCounter; KeyedVector<wp<IBinder>, OMXNodeInstance *> mLiveNodes; KeyedVector<node_id, OMXNodeInstance *> mNodeIDToInstance; + KeyedVector<node_id, sp<CallbackDispatcher> > mDispatchers; node_id makeNodeID(OMXNodeInstance *instance); OMXNodeInstance *findInstance(node_id node); + sp<CallbackDispatcher> findDispatcher(node_id node); void invalidateNodeID_l(node_id node); diff --git a/media/libstagefright/include/Prefetcher.h b/media/libstagefright/include/Prefetcher.h deleted file mode 100644 index b411d1b..0000000 --- a/media/libstagefright/include/Prefetcher.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PREFETCHER_H_ - -#define PREFETCHER_H_ - -#include <utils/RefBase.h> -#include <utils/Vector.h> -#include <utils/threads.h> - -namespace android { - -struct MediaSource; -struct PrefetchedSource; - -struct Prefetcher : public RefBase { - Prefetcher(); - - // Given an existing MediaSource returns a new MediaSource - // that will benefit from prefetching/caching the original one. - sp<MediaSource> addSource(const sp<MediaSource> &source); - - int64_t getCachedDurationUs(bool *noMoreData = NULL); - - // If provided (non-NULL), "continueFunc" will be called repeatedly - // while preparing and preparation will finish early if it returns - // false. In this case "-EINTR" is returned as a result. - status_t prepare( - bool (*continueFunc)(void *cookie) = NULL, - void *cookie = NULL); - -protected: - virtual ~Prefetcher(); - -private: - Mutex mLock; - Condition mCondition; - - Vector<wp<PrefetchedSource> > mSources; - android_thread_id_t mThread; - bool mDone; - bool mThreadExited; - - void startThread(); - void stopThread(); - - static int ThreadWrapper(void *me); - void threadFunc(); - - Prefetcher(const Prefetcher &); - Prefetcher &operator=(const Prefetcher &); -}; - -} // namespace android - -#endif // PREFETCHER_H_ diff --git a/media/libstagefright/include/SampleTable.h b/media/libstagefright/include/SampleTable.h index 533ce84..a2b2c99 100644 --- a/media/libstagefright/include/SampleTable.h +++ b/media/libstagefright/include/SampleTable.h @@ -63,11 +63,17 @@ public: uint32_t *decodingTime); enum { - kSyncSample_Flag = 1 + kFlagBefore, + kFlagAfter, + kFlagClosest }; - status_t findClosestSample( + status_t findSampleAtTime( uint32_t req_time, uint32_t *sample_index, uint32_t flags); + status_t findSyncSampleNear( + uint32_t start_sample_index, uint32_t *sample_index, + uint32_t flags); + status_t findThumbnailSample(uint32_t *sample_index); protected: @@ -111,9 +117,6 @@ private: friend struct SampleIterator; - status_t findClosestSyncSample_l( - uint32_t start_sample_index, uint32_t *sample_index); - status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size); SampleTable(const SampleTable &); diff --git a/media/libstagefright/include/ThrottledSource.h b/media/libstagefright/include/ThrottledSource.h new file mode 100644 index 0000000..88164b3 --- /dev/null +++ b/media/libstagefright/include/ThrottledSource.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef THROTTLED_SOURCE_H_ + +#define THROTTLED_SOURCE_H_ + +#include <media/stagefright/DataSource.h> +#include <utils/threads.h> + +namespace android { + +struct ThrottledSource : public DataSource { + ThrottledSource( + const sp<DataSource> &source, + int32_t bandwidthLimitBytesPerSecond); + + virtual status_t initCheck() const; + + virtual ssize_t readAt(off_t offset, void *data, size_t size); + + virtual status_t getSize(off_t *size); + virtual uint32_t flags(); + +private: + Mutex mLock; + + sp<DataSource> mSource; + int32_t mBandwidthLimitBytesPerSecond; + int64_t mStartTimeUs; + size_t mTotalTransferred; + + ThrottledSource(const ThrottledSource &); + ThrottledSource &operator=(const ThrottledSource &); +}; + +} // namespace android + +#endif // THROTTLED_SOURCE_H_ diff --git a/media/libstagefright/include/VPXDecoder.h b/media/libstagefright/include/VPXDecoder.h new file mode 100644 index 0000000..3b8362d --- /dev/null +++ b/media/libstagefright/include/VPXDecoder.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VPX_DECODER_H_ + +#define VPX_DECODER_H_ + +#include <media/stagefright/MediaSource.h> +#include <utils/Vector.h> + +namespace android { + +struct MediaBufferGroup; + +struct VPXDecoder : public MediaSource { + VPXDecoder(const sp<MediaSource> &source); + + virtual status_t start(MetaData *params); + virtual status_t stop(); + + virtual sp<MetaData> getFormat(); + + virtual status_t read( + MediaBuffer **buffer, const ReadOptions *options); + +protected: + virtual ~VPXDecoder(); + +private: + sp<MediaSource> mSource; + bool mStarted; + int32_t mWidth, mHeight; + size_t mBufferSize; + + void *mCtx; + MediaBufferGroup *mBufferGroup; + + int64_t mTargetTimeUs; + + sp<MetaData> mFormat; + + VPXDecoder(const VPXDecoder &); + VPXDecoder &operator=(const VPXDecoder &); +}; + +} // namespace android + +#endif // VPX_DECODER_H_ + |