NuPlayerDecoder.h revision 29b7dcf6d3cdb97103467dc8106151c6260c239a
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 onResume(bool notifyComplete);
51    virtual void onFlush();
52    virtual void onShutdown(bool notifyComplete);
53    virtual bool doRequestBuffers();
54
55private:
56    enum {
57        kWhatCodecNotify         = 'cdcN',
58        kWhatRenderBuffer        = 'rndr',
59        kWhatSetVideoSurface     = 'sSur'
60    };
61
62    enum {
63        kMaxNumVideoTemporalLayers = 32,
64    };
65
66    sp<Surface> mSurface;
67
68    sp<Source> mSource;
69    sp<Renderer> mRenderer;
70    sp<CCDecoder> mCCDecoder;
71
72    sp<AMessage> mInputFormat;
73    sp<AMessage> mOutputFormat;
74    sp<MediaCodec> mCodec;
75    sp<ALooper> mCodecLooper;
76
77    List<sp<AMessage> > mPendingInputMessages;
78
79    Vector<sp<MediaCodecBuffer> > mInputBuffers;
80    Vector<sp<MediaCodecBuffer> > mOutputBuffers;
81    Vector<sp<ABuffer> > mCSDsForCurrentFormat;
82    Vector<sp<ABuffer> > mCSDsToSubmit;
83    Vector<bool> mInputBufferIsDequeued;
84    Vector<MediaBuffer *> mMediaBuffers;
85    Vector<size_t> mDequeuedInputBuffers;
86
87    const pid_t mPid;
88    const uid_t mUid;
89    int64_t mSkipRenderingUntilMediaTimeUs;
90    int64_t mNumFramesTotal;
91    int64_t mNumInputFramesDropped;
92    int64_t mNumOutputFramesDropped;
93    int32_t mVideoWidth;
94    int32_t mVideoHeight;
95    bool mIsAudio;
96    bool mIsVideoAVC;
97    bool mIsSecure;
98    bool mFormatChangePending;
99    bool mTimeChangePending;
100    float mFrameRateTotal;
101    float mPlaybackSpeed;
102    int32_t mNumVideoTemporalLayerTotal;
103    int32_t mNumVideoTemporalLayerAllowed;
104    int32_t mCurrentMaxVideoTemporalLayerId;
105    float mVideoTemporalLayerAggregateFps[kMaxNumVideoTemporalLayers];
106
107    bool mResumePending;
108    AString mComponentName;
109
110    void handleError(int32_t err);
111    bool handleAnInputBuffer(size_t index);
112    bool handleAnOutputBuffer(
113            size_t index,
114            size_t offset,
115            size_t size,
116            int64_t timeUs,
117            int32_t flags);
118    void handleOutputFormatChange(const sp<AMessage> &format);
119
120    void releaseAndResetMediaBuffers();
121    void requestCodecNotification();
122    bool isStaleReply(const sp<AMessage> &msg);
123
124    void doFlush(bool notifyComplete);
125    status_t fetchInputData(sp<AMessage> &reply);
126    bool onInputBufferFetched(const sp<AMessage> &msg);
127    void onRenderBuffer(const sp<AMessage> &msg);
128
129    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
130    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
131    void rememberCodecSpecificData(const sp<AMessage> &format);
132    bool isDiscontinuityPending() const;
133    void finishHandleDiscontinuity(bool flushOnTimeChange);
134
135    void notifyResumeCompleteIfNecessary();
136
137    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
138};
139
140}  // namespace android
141
142#endif  // NUPLAYER_DECODER_H_
143