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 CODEC_BASE_H_
18 
19 #define CODEC_BASE_H_
20 
21 #include <stdint.h>
22 #include <media/IOMX.h>
23 
24 #include <media/stagefright/foundation/AHandler.h>
25 
26 namespace android {
27 
28 struct ABuffer;
29 
30 struct CodecBase : public AHandler {
31     enum {
32         kWhatFillThisBuffer      = 'fill',
33         kWhatDrainThisBuffer     = 'drai',
34         kWhatEOS                 = 'eos ',
35         kWhatShutdownCompleted   = 'scom',
36         kWhatFlushCompleted      = 'fcom',
37         kWhatOutputFormatChanged = 'outC',
38         kWhatError               = 'erro',
39         kWhatComponentAllocated  = 'cAll',
40         kWhatComponentConfigured = 'cCon',
41         kWhatInputSurfaceCreated = 'isfc',
42         kWhatSignaledInputEOS    = 'seos',
43         kWhatBuffersAllocated    = 'allc',
44     };
45 
46     virtual void setNotificationMessage(const sp<AMessage> &msg) = 0;
47 
48     virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0;
49     virtual void initiateConfigureComponent(const sp<AMessage> &msg) = 0;
50     virtual void initiateCreateInputSurface() = 0;
51     virtual void initiateStart() = 0;
52     virtual void initiateShutdown(bool keepComponentAllocated = false) = 0;
53 
54     // require an explicit message handler
55     virtual void onMessageReceived(const sp<AMessage> &msg) = 0;
56 
57     virtual void signalFlush() = 0;
58     virtual void signalResume() = 0;
59 
60     virtual void signalRequestIDRFrame() = 0;
61     virtual void signalSetParameters(const sp<AMessage> &msg) = 0;
62     virtual void signalEndOfInputStream() = 0;
63 
64     struct PortDescription : public RefBase {
65         virtual size_t countBuffers() = 0;
66         virtual IOMX::buffer_id bufferIDAt(size_t index) const = 0;
67         virtual sp<ABuffer> bufferAt(size_t index) const = 0;
68 
69     protected:
70         PortDescription();
71         virtual ~PortDescription();
72 
73     private:
74         DISALLOW_EVIL_CONSTRUCTORS(PortDescription);
75     };
76 
77 protected:
78     CodecBase();
79     virtual ~CodecBase();
80 
81 private:
82     DISALLOW_EVIL_CONSTRUCTORS(CodecBase);
83 };
84 
85 }  // namespace android
86 
87 #endif  // CODEC_BASE_H_
88 
89