michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #if !defined(MediaOmxReader_h_) michael@0: #define MediaOmxReader_h_ michael@0: michael@0: #include "MediaResource.h" michael@0: #include "MediaDecoderReader.h" michael@0: #include "nsRect.h" michael@0: #include "mozilla/dom/AudioChannelBinding.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace android { michael@0: class OmxDecoder; michael@0: class MediaExtractor; michael@0: } michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace dom { michael@0: class TimeRanges; michael@0: } michael@0: michael@0: class AbstractMediaDecoder; michael@0: michael@0: class MediaOmxReader : public MediaDecoderReader michael@0: { michael@0: nsCString mType; michael@0: bool mHasVideo; michael@0: bool mHasAudio; michael@0: nsIntRect mPicture; michael@0: nsIntSize mInitialFrame; michael@0: int64_t mVideoSeekTimeUs; michael@0: int64_t mAudioSeekTimeUs; michael@0: int32_t mSkipCount; michael@0: dom::AudioChannel mAudioChannel; michael@0: android::sp mAudioOffloadTrack; michael@0: michael@0: protected: michael@0: android::sp mOmxDecoder; michael@0: android::sp mExtractor; michael@0: michael@0: // Called by ReadMetadata() during MediaDecoderStateMachine::DecodeMetadata() michael@0: // on decode thread. It create and initialize the OMX decoder including michael@0: // setting up custom extractor. The extractor provide the essential michael@0: // information used for creating OMX decoder such as video/audio codec. michael@0: virtual nsresult InitOmxDecoder(); michael@0: michael@0: public: michael@0: MediaOmxReader(AbstractMediaDecoder* aDecoder); michael@0: ~MediaOmxReader(); michael@0: michael@0: virtual nsresult Init(MediaDecoderReader* aCloneDonor); michael@0: michael@0: virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset); michael@0: michael@0: virtual bool DecodeAudioData(); michael@0: virtual bool DecodeVideoFrame(bool &aKeyframeSkip, michael@0: int64_t aTimeThreshold); michael@0: michael@0: virtual bool HasAudio() michael@0: { michael@0: return mHasAudio; michael@0: } michael@0: michael@0: virtual bool HasVideo() michael@0: { michael@0: return mHasVideo; michael@0: } michael@0: michael@0: virtual bool IsWaitingMediaResources(); michael@0: michael@0: virtual bool IsDormantNeeded(); michael@0: virtual void ReleaseMediaResources(); michael@0: michael@0: virtual void ReleaseDecoder() MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult ReadMetadata(MediaInfo* aInfo, michael@0: MetadataTags** aTags); michael@0: virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime); michael@0: michael@0: virtual void SetIdle() MOZ_OVERRIDE; michael@0: virtual void SetActive() MOZ_OVERRIDE; michael@0: michael@0: void SetAudioChannel(dom::AudioChannel aAudioChannel) { michael@0: mAudioChannel = aAudioChannel; michael@0: } michael@0: michael@0: android::sp GetAudioOffloadTrack() { michael@0: return mAudioOffloadTrack; michael@0: } michael@0: michael@0: #ifdef MOZ_AUDIO_OFFLOAD michael@0: // Check whether it is possible to offload current audio track. This access michael@0: // canOffloadStream() from libStageFright Utils.cpp, which is not there in michael@0: // ANDROID_VERSION < 19 michael@0: void CheckAudioOffload(); michael@0: #endif michael@0: michael@0: private: michael@0: // This flag is true when SetActive() has been called without a matching michael@0: // SetIdle(). This is used to sanity check the SetIdle/SetActive calls, to michael@0: // ensure SetActive has been called before a decode call. michael@0: DebugOnly mIsActive; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif