1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/omx/MediaOmxReader.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#if !defined(MediaOmxReader_h_) 1.10 +#define MediaOmxReader_h_ 1.11 + 1.12 +#include "MediaResource.h" 1.13 +#include "MediaDecoderReader.h" 1.14 +#include "nsRect.h" 1.15 +#include "mozilla/dom/AudioChannelBinding.h" 1.16 +#include <ui/GraphicBuffer.h> 1.17 +#include <stagefright/MediaSource.h> 1.18 + 1.19 +namespace android { 1.20 +class OmxDecoder; 1.21 +class MediaExtractor; 1.22 +} 1.23 + 1.24 +namespace mozilla { 1.25 + 1.26 +namespace dom { 1.27 + class TimeRanges; 1.28 +} 1.29 + 1.30 +class AbstractMediaDecoder; 1.31 + 1.32 +class MediaOmxReader : public MediaDecoderReader 1.33 +{ 1.34 + nsCString mType; 1.35 + bool mHasVideo; 1.36 + bool mHasAudio; 1.37 + nsIntRect mPicture; 1.38 + nsIntSize mInitialFrame; 1.39 + int64_t mVideoSeekTimeUs; 1.40 + int64_t mAudioSeekTimeUs; 1.41 + int32_t mSkipCount; 1.42 + dom::AudioChannel mAudioChannel; 1.43 + android::sp<android::MediaSource> mAudioOffloadTrack; 1.44 + 1.45 +protected: 1.46 + android::sp<android::OmxDecoder> mOmxDecoder; 1.47 + android::sp<android::MediaExtractor> mExtractor; 1.48 + 1.49 + // Called by ReadMetadata() during MediaDecoderStateMachine::DecodeMetadata() 1.50 + // on decode thread. It create and initialize the OMX decoder including 1.51 + // setting up custom extractor. The extractor provide the essential 1.52 + // information used for creating OMX decoder such as video/audio codec. 1.53 + virtual nsresult InitOmxDecoder(); 1.54 + 1.55 +public: 1.56 + MediaOmxReader(AbstractMediaDecoder* aDecoder); 1.57 + ~MediaOmxReader(); 1.58 + 1.59 + virtual nsresult Init(MediaDecoderReader* aCloneDonor); 1.60 + 1.61 + virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset); 1.62 + 1.63 + virtual bool DecodeAudioData(); 1.64 + virtual bool DecodeVideoFrame(bool &aKeyframeSkip, 1.65 + int64_t aTimeThreshold); 1.66 + 1.67 + virtual bool HasAudio() 1.68 + { 1.69 + return mHasAudio; 1.70 + } 1.71 + 1.72 + virtual bool HasVideo() 1.73 + { 1.74 + return mHasVideo; 1.75 + } 1.76 + 1.77 + virtual bool IsWaitingMediaResources(); 1.78 + 1.79 + virtual bool IsDormantNeeded(); 1.80 + virtual void ReleaseMediaResources(); 1.81 + 1.82 + virtual void ReleaseDecoder() MOZ_OVERRIDE; 1.83 + 1.84 + virtual nsresult ReadMetadata(MediaInfo* aInfo, 1.85 + MetadataTags** aTags); 1.86 + virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime); 1.87 + 1.88 + virtual void SetIdle() MOZ_OVERRIDE; 1.89 + virtual void SetActive() MOZ_OVERRIDE; 1.90 + 1.91 + void SetAudioChannel(dom::AudioChannel aAudioChannel) { 1.92 + mAudioChannel = aAudioChannel; 1.93 + } 1.94 + 1.95 + android::sp<android::MediaSource> GetAudioOffloadTrack() { 1.96 + return mAudioOffloadTrack; 1.97 + } 1.98 + 1.99 +#ifdef MOZ_AUDIO_OFFLOAD 1.100 + // Check whether it is possible to offload current audio track. This access 1.101 + // canOffloadStream() from libStageFright Utils.cpp, which is not there in 1.102 + // ANDROID_VERSION < 19 1.103 + void CheckAudioOffload(); 1.104 +#endif 1.105 + 1.106 +private: 1.107 + // This flag is true when SetActive() has been called without a matching 1.108 + // SetIdle(). This is used to sanity check the SetIdle/SetActive calls, to 1.109 + // ensure SetActive has been called before a decode call. 1.110 + DebugOnly<bool> mIsActive; 1.111 +}; 1.112 + 1.113 +} // namespace mozilla 1.114 + 1.115 +#endif