NuPlayerDecoder.h revision 7137ec7e005a5a6e3c0edb91cfacf16a31f4bf6a
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 onSetRenderer(const sp<Renderer> &renderer);
44    virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
45    virtual void onResume();
46    virtual void onFlush(bool notifyComplete);
47    virtual void onShutdown(bool notifyComplete);
48    virtual void doRequestBuffers();
49
50private:
51    enum {
52        kWhatCodecNotify         = 'cdcN',
53        kWhatRenderBuffer        = 'rndr',
54    };
55
56    sp<AMessage> mNotify;
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
86    int32_t mBufferGeneration;
87    bool mPaused;
88    AString mComponentName;
89
90    void handleError(int32_t err);
91    bool handleAnInputBuffer();
92    bool handleAnOutputBuffer();
93
94    void releaseAndResetMediaBuffers();
95    void requestCodecNotification();
96    bool isStaleReply(const sp<AMessage> &msg);
97
98    status_t fetchInputData(sp<AMessage> &reply);
99    bool onInputBufferFetched(const sp<AMessage> &msg);
100    void onRenderBuffer(const sp<AMessage> &msg);
101
102    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
103    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
104    void rememberCodecSpecificData(const sp<AMessage> &format);
105
106    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
107};
108
109}  // namespace android
110
111#endif  // NUPLAYER_DECODER_H_
112