2 * Copyright 2012, The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _ANDROID_MEDIA_MEDIACODEC_H_
18 #define _ANDROID_MEDIA_MEDIACODEC_H_
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>
34 struct IGraphicBufferProducer;
38 struct JMediaCodec : public AHandler {
40 JNIEnv *env, jobject thiz,
41 const char *name, bool nameIsType, bool encoder);
43 status_t initCheck() const;
48 status_t setCallback(jobject cb);
51 const sp<AMessage> &format,
52 const sp<IGraphicBufferProducer> &bufferProducer,
53 const sp<ICrypto> &crypto,
56 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
64 status_t queueInputBuffer(
66 size_t offset, size_t size, int64_t timeUs, uint32_t flags,
67 AString *errorDetailMsg);
69 status_t queueSecureInputBuffer(
72 const CryptoPlugin::SubSample *subSamples,
74 const uint8_t key[16],
76 CryptoPlugin::Mode mode,
77 int64_t presentationTimeUs,
79 AString *errorDetailMsg);
81 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
83 status_t dequeueOutputBuffer(
84 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
86 status_t releaseOutputBuffer(
87 size_t index, bool render, bool updatePTS, int64_t timestampNs);
89 status_t signalEndOfInputStream();
91 status_t getFormat(JNIEnv *env, bool input, jobject *format) const;
93 status_t getOutputFormat(JNIEnv *env, size_t index, jobject *format) const;
96 JNIEnv *env, bool input, jobjectArray *bufArray) const;
99 JNIEnv *env, bool input, size_t index, jobject *buf) const;
102 JNIEnv *env, bool input, size_t index, jobject *image) const;
104 status_t getName(JNIEnv *env, jstring *name) const;
106 status_t setParameters(const sp<AMessage> ¶ms);
108 void setVideoScalingMode(int mode);
111 virtual ~JMediaCodec();
113 virtual void onMessageReceived(const sp<AMessage> &msg);
114 void handleCallback(const sp<AMessage> &msg);
123 sp<Surface> mSurfaceTextureClient;
125 // java objects cached
126 jclass mByteBufferClass;
127 jobject mNativeByteOrderObj;
128 jmethodID mByteBufferOrderMethodID;
129 jmethodID mByteBufferPositionMethodID;
130 jmethodID mByteBufferLimitMethodID;
131 jmethodID mByteBufferAsReadOnlyBufferMethodID;
134 sp<MediaCodec> mCodec;
136 sp<AMessage> mCallbackNotification;
138 status_t mInitStatus;
140 status_t createByteBufferFromABuffer(
141 JNIEnv *env, bool readOnly, bool clearBuffer, const sp<ABuffer> &buffer,
144 void cacheJavaObjects(JNIEnv *env);
145 void deleteJavaObjects(JNIEnv *env);
147 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
150 } // namespace android
152 #endif // _ANDROID_MEDIA_MEDIACODEC_H_