Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | #if !defined(MediaOmxReader_h_) |
michael@0 | 7 | #define MediaOmxReader_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "MediaResource.h" |
michael@0 | 10 | #include "MediaDecoderReader.h" |
michael@0 | 11 | #include "nsRect.h" |
michael@0 | 12 | #include "mozilla/dom/AudioChannelBinding.h" |
michael@0 | 13 | #include <ui/GraphicBuffer.h> |
michael@0 | 14 | #include <stagefright/MediaSource.h> |
michael@0 | 15 | |
michael@0 | 16 | namespace android { |
michael@0 | 17 | class OmxDecoder; |
michael@0 | 18 | class MediaExtractor; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | |
michael@0 | 23 | namespace dom { |
michael@0 | 24 | class TimeRanges; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | class AbstractMediaDecoder; |
michael@0 | 28 | |
michael@0 | 29 | class MediaOmxReader : public MediaDecoderReader |
michael@0 | 30 | { |
michael@0 | 31 | nsCString mType; |
michael@0 | 32 | bool mHasVideo; |
michael@0 | 33 | bool mHasAudio; |
michael@0 | 34 | nsIntRect mPicture; |
michael@0 | 35 | nsIntSize mInitialFrame; |
michael@0 | 36 | int64_t mVideoSeekTimeUs; |
michael@0 | 37 | int64_t mAudioSeekTimeUs; |
michael@0 | 38 | int32_t mSkipCount; |
michael@0 | 39 | dom::AudioChannel mAudioChannel; |
michael@0 | 40 | android::sp<android::MediaSource> mAudioOffloadTrack; |
michael@0 | 41 | |
michael@0 | 42 | protected: |
michael@0 | 43 | android::sp<android::OmxDecoder> mOmxDecoder; |
michael@0 | 44 | android::sp<android::MediaExtractor> mExtractor; |
michael@0 | 45 | |
michael@0 | 46 | // Called by ReadMetadata() during MediaDecoderStateMachine::DecodeMetadata() |
michael@0 | 47 | // on decode thread. It create and initialize the OMX decoder including |
michael@0 | 48 | // setting up custom extractor. The extractor provide the essential |
michael@0 | 49 | // information used for creating OMX decoder such as video/audio codec. |
michael@0 | 50 | virtual nsresult InitOmxDecoder(); |
michael@0 | 51 | |
michael@0 | 52 | public: |
michael@0 | 53 | MediaOmxReader(AbstractMediaDecoder* aDecoder); |
michael@0 | 54 | ~MediaOmxReader(); |
michael@0 | 55 | |
michael@0 | 56 | virtual nsresult Init(MediaDecoderReader* aCloneDonor); |
michael@0 | 57 | |
michael@0 | 58 | virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset); |
michael@0 | 59 | |
michael@0 | 60 | virtual bool DecodeAudioData(); |
michael@0 | 61 | virtual bool DecodeVideoFrame(bool &aKeyframeSkip, |
michael@0 | 62 | int64_t aTimeThreshold); |
michael@0 | 63 | |
michael@0 | 64 | virtual bool HasAudio() |
michael@0 | 65 | { |
michael@0 | 66 | return mHasAudio; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | virtual bool HasVideo() |
michael@0 | 70 | { |
michael@0 | 71 | return mHasVideo; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | virtual bool IsWaitingMediaResources(); |
michael@0 | 75 | |
michael@0 | 76 | virtual bool IsDormantNeeded(); |
michael@0 | 77 | virtual void ReleaseMediaResources(); |
michael@0 | 78 | |
michael@0 | 79 | virtual void ReleaseDecoder() MOZ_OVERRIDE; |
michael@0 | 80 | |
michael@0 | 81 | virtual nsresult ReadMetadata(MediaInfo* aInfo, |
michael@0 | 82 | MetadataTags** aTags); |
michael@0 | 83 | virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime); |
michael@0 | 84 | |
michael@0 | 85 | virtual void SetIdle() MOZ_OVERRIDE; |
michael@0 | 86 | virtual void SetActive() MOZ_OVERRIDE; |
michael@0 | 87 | |
michael@0 | 88 | void SetAudioChannel(dom::AudioChannel aAudioChannel) { |
michael@0 | 89 | mAudioChannel = aAudioChannel; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | android::sp<android::MediaSource> GetAudioOffloadTrack() { |
michael@0 | 93 | return mAudioOffloadTrack; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | #ifdef MOZ_AUDIO_OFFLOAD |
michael@0 | 97 | // Check whether it is possible to offload current audio track. This access |
michael@0 | 98 | // canOffloadStream() from libStageFright Utils.cpp, which is not there in |
michael@0 | 99 | // ANDROID_VERSION < 19 |
michael@0 | 100 | void CheckAudioOffload(); |
michael@0 | 101 | #endif |
michael@0 | 102 | |
michael@0 | 103 | private: |
michael@0 | 104 | // This flag is true when SetActive() has been called without a matching |
michael@0 | 105 | // SetIdle(). This is used to sanity check the SetIdle/SetActive calls, to |
michael@0 | 106 | // ensure SetActive has been called before a decode call. |
michael@0 | 107 | DebugOnly<bool> mIsActive; |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | } // namespace mozilla |
michael@0 | 111 | |
michael@0 | 112 | #endif |