android_media_MediaCodec.h revision d4023114e8cf7ec7db4d07958a303699b658f2c0
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 ALooper; 30struct AMessage; 31struct AString; 32struct ICrypto; 33struct IGraphicBufferProducer; 34struct MediaCodec; 35class Surface; 36 37struct JMediaCodec : public AHandler { 38 JMediaCodec( 39 JNIEnv *env, jobject thiz, 40 const char *name, bool nameIsType, bool encoder); 41 42 status_t initCheck() const; 43 44 void registerSelf(); 45 void release(); 46 47 status_t setCallback(jobject cb); 48 49 status_t configure( 50 const sp<AMessage> &format, 51 const sp<IGraphicBufferProducer> &bufferProducer, 52 const sp<ICrypto> &crypto, 53 int flags); 54 55 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer); 56 57 status_t start(); 58 status_t stop(); 59 60 status_t flush(); 61 62 status_t queueInputBuffer( 63 size_t index, 64 size_t offset, size_t size, int64_t timeUs, uint32_t flags, 65 AString *errorDetailMsg); 66 67 status_t queueSecureInputBuffer( 68 size_t index, 69 size_t offset, 70 const CryptoPlugin::SubSample *subSamples, 71 size_t numSubSamples, 72 const uint8_t key[16], 73 const uint8_t iv[16], 74 CryptoPlugin::Mode mode, 75 int64_t presentationTimeUs, 76 uint32_t flags, 77 AString *errorDetailMsg); 78 79 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs); 80 81 status_t dequeueOutputBuffer( 82 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs); 83 84 status_t releaseOutputBuffer( 85 size_t index, bool render, bool updatePTS, int64_t timestampNs); 86 87 status_t signalEndOfInputStream(); 88 89 status_t getFormat(JNIEnv *env, bool input, jobject *format) const; 90 91 status_t getOutputFormat(JNIEnv *env, size_t index, jobject *format) const; 92 93 status_t getBuffers( 94 JNIEnv *env, bool input, jobjectArray *bufArray) const; 95 96 status_t getBuffer( 97 JNIEnv *env, bool input, size_t index, jobject *buf) const; 98 99 status_t getImage( 100 JNIEnv *env, bool input, size_t index, jobject *image) const; 101 102 status_t getName(JNIEnv *env, jstring *name) const; 103 104 status_t setParameters(const sp<AMessage> ¶ms); 105 106 void setVideoScalingMode(int mode); 107 108protected: 109 virtual ~JMediaCodec(); 110 111 virtual void onMessageReceived(const sp<AMessage> &msg); 112 void handleCallback(const sp<AMessage> &msg); 113 114private: 115 enum { 116 kWhatCallbackNotify, 117 }; 118 119 jclass mClass; 120 jweak mObject; 121 sp<Surface> mSurfaceTextureClient; 122 123 sp<ALooper> mLooper; 124 sp<MediaCodec> mCodec; 125 126 sp<AMessage> mCallbackNotification; 127 128 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec); 129}; 130 131} // namespace android 132 133#endif // _ANDROID_MEDIA_MEDIACODEC_H_ 134