android_media_MediaCodec.h revision 8034d60f6e044deafe48501dfbfe17c31284bc17
1/* 2 * Copyright 2012, 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 _ANDROID_MEDIA_MEDIACODEC_H_ 18#define _ANDROID_MEDIA_MEDIACODEC_H_ 19 20#include "jni.h" 21 22#include <media/hardware/CryptoAPI.h> 23#include <media/stagefright/foundation/ABase.h> 24#include <media/stagefright/foundation/AHandler.h> 25#include <utils/Errors.h> 26 27namespace android { 28 29struct ABuffer; 30struct ALooper; 31struct AMessage; 32struct AString; 33struct ICrypto; 34struct IGraphicBufferProducer; 35struct MediaCodec; 36struct PersistentSurface; 37class Surface; 38 39struct JMediaCodec : public AHandler { 40 JMediaCodec( 41 JNIEnv *env, jobject thiz, 42 const char *name, bool nameIsType, bool encoder); 43 44 status_t initCheck() const; 45 46 void registerSelf(); 47 void release(); 48 49 status_t setCallback(jobject cb); 50 51 status_t configure( 52 const sp<AMessage> &format, 53 const sp<IGraphicBufferProducer> &bufferProducer, 54 const sp<ICrypto> &crypto, 55 int flags); 56 57 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer); 58 status_t usePersistentInputSurface(const sp<PersistentSurface> &surface); 59 60 status_t start(); 61 status_t stop(); 62 status_t reset(); 63 64 status_t flush(); 65 66 status_t queueInputBuffer( 67 size_t index, 68 size_t offset, size_t size, int64_t timeUs, uint32_t flags, 69 AString *errorDetailMsg); 70 71 status_t queueSecureInputBuffer( 72 size_t index, 73 size_t offset, 74 const CryptoPlugin::SubSample *subSamples, 75 size_t numSubSamples, 76 const uint8_t key[16], 77 const uint8_t iv[16], 78 CryptoPlugin::Mode mode, 79 int64_t presentationTimeUs, 80 uint32_t flags, 81 AString *errorDetailMsg); 82 83 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs); 84 85 status_t dequeueOutputBuffer( 86 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs); 87 88 status_t releaseOutputBuffer( 89 size_t index, bool render, bool updatePTS, int64_t timestampNs); 90 91 status_t signalEndOfInputStream(); 92 93 status_t getFormat(JNIEnv *env, bool input, jobject *format) const; 94 95 status_t getOutputFormat(JNIEnv *env, size_t index, jobject *format) const; 96 97 status_t getBuffers( 98 JNIEnv *env, bool input, jobjectArray *bufArray) const; 99 100 status_t getBuffer( 101 JNIEnv *env, bool input, size_t index, jobject *buf) const; 102 103 status_t getImage( 104 JNIEnv *env, bool input, size_t index, jobject *image) const; 105 106 status_t getName(JNIEnv *env, jstring *name) const; 107 108 status_t setParameters(const sp<AMessage> ¶ms); 109 110 void setVideoScalingMode(int mode); 111 112protected: 113 virtual ~JMediaCodec(); 114 115 virtual void onMessageReceived(const sp<AMessage> &msg); 116 void handleCallback(const sp<AMessage> &msg); 117 118private: 119 enum { 120 kWhatCallbackNotify, 121 }; 122 123 jclass mClass; 124 jweak mObject; 125 sp<Surface> mSurfaceTextureClient; 126 127 // java objects cached 128 jclass mByteBufferClass; 129 jobject mNativeByteOrderObj; 130 jmethodID mByteBufferOrderMethodID; 131 jmethodID mByteBufferPositionMethodID; 132 jmethodID mByteBufferLimitMethodID; 133 jmethodID mByteBufferAsReadOnlyBufferMethodID; 134 135 sp<ALooper> mLooper; 136 sp<MediaCodec> mCodec; 137 138 sp<AMessage> mCallbackNotification; 139 140 status_t mInitStatus; 141 142 status_t createByteBufferFromABuffer( 143 JNIEnv *env, bool readOnly, bool clearBuffer, const sp<ABuffer> &buffer, 144 jobject *buf) const; 145 146 void cacheJavaObjects(JNIEnv *env); 147 void deleteJavaObjects(JNIEnv *env); 148 149 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec); 150}; 151 152} // namespace android 153 154#endif // _ANDROID_MEDIA_MEDIACODEC_H_ 155