NuPlayerDecoder.h revision 8db8813d39e3c8b5fbd580dfc3062830744afd63
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
26struct NuPlayer::Decoder : public DecoderBase {
27    Decoder(const sp<AMessage> &notify,
28            const sp<Source> &source,
29            const sp<Renderer> &renderer = NULL,
30            const sp<NativeWindowWrapper> &nativeWindow = NULL,
31            const sp<CCDecoder> &ccDecoder = NULL);
32
33    virtual void getStats(
34            int64_t *mNumFramesTotal,
35            int64_t *mNumFramesDropped) const;
36
37protected:
38    virtual ~Decoder();
39
40    virtual void onMessageReceived(const sp<AMessage> &msg);
41
42    virtual void onConfigure(const sp<AMessage> &format);
43    virtual void onSetParameters(const sp<AMessage> &params);
44    virtual void onSetRenderer(const sp<Renderer> &renderer);
45    virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
46    virtual void onResume(bool notifyComplete);
47    virtual void onFlush();
48    virtual void onShutdown(bool notifyComplete);
49    virtual bool doRequestBuffers();
50
51private:
52    enum {
53        kWhatCodecNotify         = 'cdcN',
54        kWhatRenderBuffer        = 'rndr',
55    };
56
57    sp<NativeWindowWrapper> mNativeWindow;
58
59    sp<Source> mSource;
60    sp<Renderer> mRenderer;
61    sp<CCDecoder> mCCDecoder;
62
63    sp<AMessage> mInputFormat;
64    sp<AMessage> mOutputFormat;
65    sp<MediaCodec> mCodec;
66    sp<ALooper> mCodecLooper;
67
68    List<sp<AMessage> > mPendingInputMessages;
69
70    Vector<sp<ABuffer> > mInputBuffers;
71    Vector<sp<ABuffer> > mOutputBuffers;
72    Vector<sp<ABuffer> > mCSDsForCurrentFormat;
73    Vector<sp<ABuffer> > mCSDsToSubmit;
74    Vector<bool> mInputBufferIsDequeued;
75    Vector<MediaBuffer *> mMediaBuffers;
76    Vector<size_t> mDequeuedInputBuffers;
77
78    int64_t mSkipRenderingUntilMediaTimeUs;
79    int64_t mNumFramesTotal;
80    int64_t mNumFramesDropped;
81    bool mIsAudio;
82    bool mIsVideoAVC;
83    bool mIsSecure;
84    bool mFormatChangePending;
85    bool mTimeChangePending;
86
87    bool mPaused;
88    bool mResumePending;
89    AString mComponentName;
90
91    void handleError(int32_t err);
92    bool handleAnInputBuffer(size_t index);
93    bool handleAnOutputBuffer(
94            size_t index,
95            size_t offset,
96            size_t size,
97            int64_t timeUs,
98            int32_t flags);
99    void handleOutputFormatChange(const sp<AMessage> &format);
100
101    void releaseAndResetMediaBuffers();
102    void requestCodecNotification();
103    bool isStaleReply(const sp<AMessage> &msg);
104
105    void doFlush(bool notifyComplete);
106    status_t fetchInputData(sp<AMessage> &reply);
107    bool onInputBufferFetched(const sp<AMessage> &msg);
108    void onRenderBuffer(const sp<AMessage> &msg);
109
110    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
111    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
112    void rememberCodecSpecificData(const sp<AMessage> &format);
113    bool isDiscontinuityPending() const;
114    void finishHandleDiscontinuity(bool flushOnTimeChange);
115
116    void notifyResumeCompleteIfNecessary();
117
118    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
119};
120
121}  // namespace android
122
123#endif  // NUPLAYER_DECODER_H_
124