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 23 #define STRINGIFY_ENUMS 24 25 #include <media/IOMX.h> 26 #include <media/MediaCodecInfo.h> 27 #include <media/stagefright/foundation/AHandler.h> 28 #include <media/stagefright/foundation/ColorUtils.h> 29 #include <media/hardware/HardwareAPI.h> 30 31 #include <utils/NativeHandle.h> 32 33 #include <system/graphics.h> 34 35 namespace android { 36 37 struct ABuffer; 38 struct PersistentSurface; 39 40 struct CodecBase : public AHandler, /* static */ ColorUtils { 41 enum { 42 kWhatFillThisBuffer = 'fill', 43 kWhatDrainThisBuffer = 'drai', 44 kWhatEOS = 'eos ', 45 kWhatShutdownCompleted = 'scom', 46 kWhatFlushCompleted = 'fcom', 47 kWhatOutputFormatChanged = 'outC', 48 kWhatError = 'erro', 49 kWhatComponentAllocated = 'cAll', 50 kWhatComponentConfigured = 'cCon', 51 kWhatInputSurfaceCreated = 'isfc', 52 kWhatInputSurfaceAccepted = 'isfa', 53 kWhatSignaledInputEOS = 'seos', 54 kWhatBuffersAllocated = 'allc', 55 kWhatOutputFramesRendered = 'outR', 56 }; 57 58 enum { 59 kMaxCodecBufferSize = 8192 * 4096 * 4, // 8K RGBA 60 }; 61 62 virtual void setNotificationMessage(const sp<AMessage> &msg) = 0; 63 64 virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0; 65 virtual void initiateConfigureComponent(const sp<AMessage> &msg) = 0; 66 virtual void initiateCreateInputSurface() = 0; 67 virtual void initiateSetInputSurface( 68 const sp<PersistentSurface> &surface) = 0; 69 virtual void initiateStart() = 0; 70 virtual void initiateShutdown(bool keepComponentAllocated = false) = 0; 71 72 // require an explicit message handler 73 virtual void onMessageReceived(const sp<AMessage> &msg) = 0; 74 queryCapabilitiesCodecBase75 virtual status_t queryCapabilities( 76 const AString &name, const AString &mime, bool isEncoder, 77 sp<MediaCodecInfo::Capabilities> *caps /* nonnull */) { return INVALID_OPERATION; } 78 setSurfaceCodecBase79 virtual status_t setSurface(const sp<Surface> &surface) { return INVALID_OPERATION; } 80 81 virtual void signalFlush() = 0; 82 virtual void signalResume() = 0; 83 84 virtual void signalRequestIDRFrame() = 0; 85 virtual void signalSetParameters(const sp<AMessage> &msg) = 0; 86 virtual void signalEndOfInputStream() = 0; 87 88 struct PortDescription : public RefBase { 89 virtual size_t countBuffers() = 0; 90 virtual IOMX::buffer_id bufferIDAt(size_t index) const = 0; 91 virtual sp<ABuffer> bufferAt(size_t index) const = 0; handleAtCodecBase::PortDescription92 virtual sp<NativeHandle> handleAt(size_t index) const { return NULL; }; memRefAtCodecBase::PortDescription93 virtual sp<RefBase> memRefAt(size_t index) const { return NULL; } 94 95 protected: 96 PortDescription(); 97 virtual ~PortDescription(); 98 99 private: 100 DISALLOW_EVIL_CONSTRUCTORS(PortDescription); 101 }; 102 103 /* 104 * Codec-related defines 105 */ 106 107 protected: 108 CodecBase(); 109 virtual ~CodecBase(); 110 111 private: 112 DISALLOW_EVIL_CONSTRUCTORS(CodecBase); 113 }; 114 115 } // namespace android 116 117 #endif // CODEC_BASE_H_ 118 119