CodecBase.h revision 5b05e49e6550cb2abf1a88272d6cd460b8957176
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/MediaCodecInfo.h>
25#include <media/stagefright/foundation/AHandler.h>
26
27namespace android {
28
29struct ABuffer;
30struct PersistentSurface;
31
32struct CodecBase : public AHandler {
33    enum {
34        kWhatFillThisBuffer      = 'fill',
35        kWhatDrainThisBuffer     = 'drai',
36        kWhatEOS                 = 'eos ',
37        kWhatShutdownCompleted   = 'scom',
38        kWhatFlushCompleted      = 'fcom',
39        kWhatOutputFormatChanged = 'outC',
40        kWhatError               = 'erro',
41        kWhatComponentAllocated  = 'cAll',
42        kWhatComponentConfigured = 'cCon',
43        kWhatInputSurfaceCreated = 'isfc',
44        kWhatInputSurfaceAccepted = 'isfa',
45        kWhatSignaledInputEOS    = 'seos',
46        kWhatBuffersAllocated    = 'allc',
47        kWhatOutputFramesRendered = 'outR',
48    };
49
50    virtual void setNotificationMessage(const sp<AMessage> &msg) = 0;
51
52    virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0;
53    virtual void initiateConfigureComponent(const sp<AMessage> &msg) = 0;
54    virtual void initiateCreateInputSurface() = 0;
55    virtual void initiateSetInputSurface(
56            const sp<PersistentSurface> &surface) = 0;
57    virtual void initiateStart() = 0;
58    virtual void initiateShutdown(bool keepComponentAllocated = false) = 0;
59
60    // require an explicit message handler
61    virtual void onMessageReceived(const sp<AMessage> &msg) = 0;
62
63    virtual status_t queryCapabilities(
64            const AString &name, const AString &mime, bool isEncoder,
65            sp<MediaCodecInfo::Capabilities> *caps /* nonnull */) { return INVALID_OPERATION; }
66
67    virtual status_t setSurface(const sp<Surface> &surface) { return INVALID_OPERATION; }
68
69    virtual void signalFlush() = 0;
70    virtual void signalResume() = 0;
71
72    virtual void signalRequestIDRFrame() = 0;
73    virtual void signalSetParameters(const sp<AMessage> &msg) = 0;
74    virtual void signalEndOfInputStream() = 0;
75
76    struct PortDescription : public RefBase {
77        virtual size_t countBuffers() = 0;
78        virtual IOMX::buffer_id bufferIDAt(size_t index) const = 0;
79        virtual sp<ABuffer> bufferAt(size_t index) const = 0;
80        virtual sp<RefBase> memRefAt(size_t index) const { return NULL; }
81
82    protected:
83        PortDescription();
84        virtual ~PortDescription();
85
86    private:
87        DISALLOW_EVIL_CONSTRUCTORS(PortDescription);
88    };
89
90protected:
91    CodecBase();
92    virtual ~CodecBase();
93
94private:
95    DISALLOW_EVIL_CONSTRUCTORS(CodecBase);
96};
97
98}  // namespace android
99
100#endif  // CODEC_BASE_H_
101
102