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 class MediaBuffer;
30 class Surface;
31 
32 struct NuPlayer::DecoderBase : public AHandler {
33     DecoderBase(const sp<AMessage> &notify);
34 
35     void configure(const sp<AMessage> &format);
36     void init();
37     void setParameters(const sp<AMessage> &params);
38 
39     void setRenderer(const sp<Renderer> &renderer);
setVideoSurfaceDecoderBase40     virtual status_t setVideoSurface(const sp<Surface> &) { return INVALID_OPERATION; }
41 
42     status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const;
43     void signalFlush();
44     void signalResume(bool notifyComplete);
45     void initiateShutdown();
46 
getStatsDecoderBase47     virtual sp<AMessage> getStats() const {
48         return mStats;
49     }
50 
51     enum {
52         kWhatInputDiscontinuity  = 'inDi',
53         kWhatVideoSizeChanged    = 'viSC',
54         kWhatFlushCompleted      = 'flsC',
55         kWhatShutdownCompleted   = 'shDC',
56         kWhatResumeCompleted     = 'resC',
57         kWhatEOS                 = 'eos ',
58         kWhatError               = 'err ',
59     };
60 
61 protected:
62 
63     virtual ~DecoderBase();
64 
65     virtual void onMessageReceived(const sp<AMessage> &msg);
66 
67     virtual void onConfigure(const sp<AMessage> &format) = 0;
68     virtual void onSetParameters(const sp<AMessage> &params) = 0;
69     virtual void onSetRenderer(const sp<Renderer> &renderer) = 0;
70     virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers) = 0;
71     virtual void onResume(bool notifyComplete) = 0;
72     virtual void onFlush() = 0;
73     virtual void onShutdown(bool notifyComplete) = 0;
74 
75     void onRequestInputBuffers();
76     virtual bool doRequestBuffers() = 0;
77     virtual void handleError(int32_t err);
78 
79     sp<AMessage> mNotify;
80     int32_t mBufferGeneration;
81     sp<AMessage> mStats;
82 
83 private:
84     enum {
85         kWhatConfigure           = 'conf',
86         kWhatSetParameters       = 'setP',
87         kWhatSetRenderer         = 'setR',
88         kWhatGetInputBuffers     = 'gInB',
89         kWhatRequestInputBuffers = 'reqB',
90         kWhatFlush               = 'flus',
91         kWhatShutdown            = 'shuD',
92     };
93 
94     sp<ALooper> mDecoderLooper;
95     bool mRequestInputBuffersPending;
96 
97     DISALLOW_EVIL_CONSTRUCTORS(DecoderBase);
98 };
99 
100 }  // namespace android
101 
102 #endif  // NUPLAYER_DECODER_BASE_H_
103