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 MediaCodecBuffer;
31 class Surface;
32 
33 struct NuPlayer::DecoderBase : public AHandler {
34     explicit DecoderBase(const sp<AMessage> &notify);
35 
36     void configure(const sp<AMessage> &format);
37     void init();
38     void setParameters(const sp<AMessage> &params);
39 
40     // Synchronous call to ensure decoder will not request or send out data.
41     void pause();
42 
43     void setRenderer(const sp<Renderer> &renderer);
setVideoSurfaceDecoderBase44     virtual status_t setVideoSurface(const sp<Surface> &) { return INVALID_OPERATION; }
45 
46     void signalFlush();
47     void signalResume(bool notifyComplete);
48     void initiateShutdown();
49 
getStatsDecoderBase50     virtual sp<AMessage> getStats() {
51         return mStats;
52     }
53 
releaseCryptoDecoderBase54     virtual status_t releaseCrypto() {
55         return INVALID_OPERATION;
56     }
57 
58     enum {
59         kWhatInputDiscontinuity  = 'inDi',
60         kWhatVideoSizeChanged    = 'viSC',
61         kWhatFlushCompleted      = 'flsC',
62         kWhatShutdownCompleted   = 'shDC',
63         kWhatResumeCompleted     = 'resC',
64         kWhatEOS                 = 'eos ',
65         kWhatError               = 'err ',
66     };
67 
68 protected:
69 
70     virtual ~DecoderBase();
71 
72     void stopLooper();
73 
74     virtual void onMessageReceived(const sp<AMessage> &msg);
75 
76     virtual void onConfigure(const sp<AMessage> &format) = 0;
77     virtual void onSetParameters(const sp<AMessage> &params) = 0;
78     virtual void onSetRenderer(const sp<Renderer> &renderer) = 0;
79     virtual void onResume(bool notifyComplete) = 0;
80     virtual void onFlush() = 0;
81     virtual void onShutdown(bool notifyComplete) = 0;
82 
83     void onRequestInputBuffers();
84     virtual bool doRequestBuffers() = 0;
85     virtual void handleError(int32_t err);
86 
87     sp<AMessage> mNotify;
88     int32_t mBufferGeneration;
89     bool mPaused;
90     sp<AMessage> mStats;
91     Mutex mStatsLock;
92 
93 private:
94     enum {
95         kWhatConfigure           = 'conf',
96         kWhatSetParameters       = 'setP',
97         kWhatSetRenderer         = 'setR',
98         kWhatPause               = 'paus',
99         kWhatRequestInputBuffers = 'reqB',
100         kWhatFlush               = 'flus',
101         kWhatShutdown            = 'shuD',
102     };
103 
104     sp<ALooper> mDecoderLooper;
105     bool mRequestInputBuffersPending;
106 
107     DISALLOW_EVIL_CONSTRUCTORS(DecoderBase);
108 };
109 
110 }  // namespace android
111 
112 #endif  // NUPLAYER_DECODER_BASE_H_
113