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