NuPlayerDecoder.h revision f2ae3e19080938db8cbf29a963fd744a3964fcc2
1/*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NUPLAYER_DECODER_H_
18#define NUPLAYER_DECODER_H_
19
20#include "NuPlayer.h"
21
22#include "NuPlayerDecoderBase.h"
23
24namespace android {
25
26class MediaCodecBuffer;
27
28struct NuPlayer::Decoder : public DecoderBase {
29    Decoder(const sp<AMessage> &notify,
30            const sp<Source> &source,
31            pid_t pid,
32            uid_t uid,
33            const sp<Renderer> &renderer = NULL,
34            const sp<Surface> &surface = NULL,
35            const sp<CCDecoder> &ccDecoder = NULL);
36
37    virtual sp<AMessage> getStats() const;
38
39    // sets the output surface of video decoders.
40    virtual status_t setVideoSurface(const sp<Surface> &surface);
41
42protected:
43    virtual ~Decoder();
44
45    virtual void onMessageReceived(const sp<AMessage> &msg);
46
47    virtual void onConfigure(const sp<AMessage> &format);
48    virtual void onSetParameters(const sp<AMessage> &params);
49    virtual void onSetRenderer(const sp<Renderer> &renderer);
50    virtual void onGetInputBuffers(Vector<sp<MediaCodecBuffer> > *dstBuffers);
51    virtual void onResume(bool notifyComplete);
52    virtual void onFlush();
53    virtual void onShutdown(bool notifyComplete);
54    virtual bool doRequestBuffers();
55
56private:
57    enum {
58        kWhatCodecNotify         = 'cdcN',
59        kWhatRenderBuffer        = 'rndr',
60        kWhatSetVideoSurface     = 'sSur'
61    };
62
63    enum {
64        kMaxNumVideoTemporalLayers = 32,
65    };
66
67    sp<Surface> mSurface;
68
69    sp<Source> mSource;
70    sp<Renderer> mRenderer;
71    sp<CCDecoder> mCCDecoder;
72
73    sp<AMessage> mInputFormat;
74    sp<AMessage> mOutputFormat;
75    sp<MediaCodec> mCodec;
76    sp<ALooper> mCodecLooper;
77
78    List<sp<AMessage> > mPendingInputMessages;
79
80    Vector<sp<MediaCodecBuffer> > mInputBuffers;
81    Vector<sp<MediaCodecBuffer> > mOutputBuffers;
82    Vector<sp<ABuffer> > mCSDsForCurrentFormat;
83    Vector<sp<ABuffer> > mCSDsToSubmit;
84    Vector<bool> mInputBufferIsDequeued;
85    Vector<MediaBuffer *> mMediaBuffers;
86    Vector<size_t> mDequeuedInputBuffers;
87
88    const pid_t mPid;
89    const uid_t mUid;
90    int64_t mSkipRenderingUntilMediaTimeUs;
91    int64_t mNumFramesTotal;
92    int64_t mNumInputFramesDropped;
93    int64_t mNumOutputFramesDropped;
94    int32_t mVideoWidth;
95    int32_t mVideoHeight;
96    bool mIsAudio;
97    bool mIsVideoAVC;
98    bool mIsSecure;
99    bool mFormatChangePending;
100    bool mTimeChangePending;
101    float mFrameRateTotal;
102    float mPlaybackSpeed;
103    int32_t mNumVideoTemporalLayerTotal;
104    int32_t mNumVideoTemporalLayerAllowed;
105    int32_t mCurrentMaxVideoTemporalLayerId;
106    float mVideoTemporalLayerAggregateFps[kMaxNumVideoTemporalLayers];
107
108    bool mResumePending;
109    AString mComponentName;
110
111    void handleError(int32_t err);
112    bool handleAnInputBuffer(size_t index);
113    bool handleAnOutputBuffer(
114            size_t index,
115            size_t offset,
116            size_t size,
117            int64_t timeUs,
118            int32_t flags);
119    void handleOutputFormatChange(const sp<AMessage> &format);
120
121    void releaseAndResetMediaBuffers();
122    void requestCodecNotification();
123    bool isStaleReply(const sp<AMessage> &msg);
124
125    void doFlush(bool notifyComplete);
126    status_t fetchInputData(sp<AMessage> &reply);
127    bool onInputBufferFetched(const sp<AMessage> &msg);
128    void onRenderBuffer(const sp<AMessage> &msg);
129
130    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
131    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
132    void rememberCodecSpecificData(const sp<AMessage> &format);
133    bool isDiscontinuityPending() const;
134    void finishHandleDiscontinuity(bool flushOnTimeChange);
135
136    void notifyResumeCompleteIfNecessary();
137
138    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
139};
140
141}  // namespace android
142
143#endif  // NUPLAYER_DECODER_H_
144