NuPlayerDecoderPassThrough.h revision c6cfd70f24a11b946859485ce398a189c301a4e2
1/*
2 * Copyright (C) 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_PASS_THROUGH_H_
18
19#define NUPLAYER_DECODER_PASS_THROUGH_H_
20
21#include "NuPlayer.h"
22
23#include "NuPlayerDecoder.h"
24
25namespace android {
26
27struct NuPlayer::DecoderPassThrough : public Decoder {
28    DecoderPassThrough(const sp<AMessage> &notify,
29                       const sp<Source> &source,
30                       const sp<Renderer> &renderer);
31
32    virtual void configure(const sp<AMessage> &format);
33    virtual void init();
34
35    virtual void signalFlush();
36    virtual void signalResume();
37    virtual void initiateShutdown();
38
39    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
40
41protected:
42
43    virtual ~DecoderPassThrough();
44
45    virtual void onMessageReceived(const sp<AMessage> &msg);
46
47private:
48    enum {
49        kWhatRequestABuffer     = 'reqB',
50        kWhatBufferConsumed     = 'bufC',
51    };
52
53    sp<AMessage> mNotify;
54    sp<ALooper> mDecoderLooper;
55
56    sp<Source> mSource;
57    sp<Renderer> mRenderer;
58
59    /** Returns true if a buffer was requested.
60     * Returns false if at EOS or cache already full.
61     */
62    bool requestABuffer();
63    bool isStaleReply(const sp<AMessage> &msg);
64
65    void onConfigure(const sp<AMessage> &format);
66    void onFlush();
67    void onInputBufferFilled(const sp<AMessage> &msg);
68    void onBufferConsumed(int32_t size);
69    void requestMaxBuffers();
70    void onShutdown();
71
72    int64_t mSkipRenderingUntilMediaTimeUs;
73
74    int32_t mBufferGeneration;
75    bool    mReachedEOS;
76    // TODO mPendingBuffersToFill and mPendingBuffersToDrain are only for
77    // debugging. They can be removed when the power investigation is done.
78    size_t  mPendingBuffersToFill;
79    size_t  mPendingBuffersToDrain;
80    size_t  mCachedBytes;
81    AString mComponentName;
82
83    DISALLOW_EVIL_CONSTRUCTORS(DecoderPassThrough);
84};
85
86}  // namespace android
87
88#endif  // NUPLAYER_DECODER_PASS_THROUGH_H_
89