1 /*
2  * Copyright (C) 2010 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_BASE_H_
18 
19 #define NUPLAYER_DECODER_BASE_H_
20 
21 #include "NuPlayer.h"
22 
23 #include <media/stagefright/foundation/AHandler.h>
24 
25 namespace android {
26 
27 struct ABuffer;
28 struct MediaCodec;
29 struct MediaBuffer;
30 
31 struct NuPlayer::DecoderBase : public AHandler {
32     DecoderBase(const sp<AMessage> &notify);
33 
34     void configure(const sp<AMessage> &format);
35     void init();
36 
37     void setRenderer(const sp<Renderer> &renderer);
38 
39     status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const;
40     void signalFlush();
41     void signalResume(bool notifyComplete);
42     void initiateShutdown();
43 
44     virtual void getStats(
45             int64_t *mNumFramesTotal,
46             int64_t *mNumFramesDropped) const = 0;
47 
48     enum {
49         kWhatInputDiscontinuity  = 'inDi',
50         kWhatVideoSizeChanged    = 'viSC',
51         kWhatFlushCompleted      = 'flsC',
52         kWhatShutdownCompleted   = 'shDC',
53         kWhatResumeCompleted     = 'resC',
54         kWhatEOS                 = 'eos ',
55         kWhatError               = 'err ',
56     };
57 
58 protected:
59 
60     virtual ~DecoderBase();
61 
62     virtual void onMessageReceived(const sp<AMessage> &msg);
63 
64     virtual void onConfigure(const sp<AMessage> &format) = 0;
65     virtual void onSetRenderer(const sp<Renderer> &renderer) = 0;
66     virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers) = 0;
67     virtual void onResume(bool notifyComplete) = 0;
68     virtual void onFlush(bool notifyComplete) = 0;
69     virtual void onShutdown(bool notifyComplete) = 0;
70 
71     void onRequestInputBuffers();
72     void scheduleRequestBuffers();
73     virtual void doRequestBuffers() = 0;
74     virtual void handleError(int32_t err);
75 
76     sp<AMessage> mNotify;
77     int32_t mBufferGeneration;
78 
79 private:
80     enum {
81         kWhatConfigure           = 'conf',
82         kWhatSetRenderer         = 'setR',
83         kWhatGetInputBuffers     = 'gInB',
84         kWhatRequestInputBuffers = 'reqB',
85         kWhatFlush               = 'flus',
86         kWhatShutdown            = 'shuD',
87     };
88 
89     sp<ALooper> mDecoderLooper;
90     bool mRequestInputBuffersPending;
91 
92     DISALLOW_EVIL_CONSTRUCTORS(DecoderBase);
93 };
94 
95 }  // namespace android
96 
97 #endif  // NUPLAYER_DECODER_BASE_H_
98