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/MediaAnalyticsItem.h>
23 #include <media/hardware/CryptoAPI.h>
24 #include <media/stagefright/foundation/ABase.h>
25 #include <media/stagefright/foundation/AHandler.h>
26 #include <utils/Errors.h>
35 class IGraphicBufferProducer;
37 struct PersistentSurface;
45 using hardware::cas::native::V1_0::IDescrambler;
47 struct JMediaCodec : public AHandler {
49 JNIEnv *env, jobject thiz,
50 const char *name, bool nameIsType, bool encoder);
52 status_t initCheck() const;
57 status_t enableOnFrameRenderedListener(jboolean enable);
59 status_t setCallback(jobject cb);
62 const sp<AMessage> &format,
63 const sp<IGraphicBufferProducer> &bufferProducer,
64 const sp<ICrypto> &crypto,
65 const sp<IDescrambler> &descrambler,
69 const sp<IGraphicBufferProducer> &surface);
71 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
72 status_t setInputSurface(const sp<PersistentSurface> &surface);
80 status_t queueInputBuffer(
82 size_t offset, size_t size, int64_t timeUs, uint32_t flags,
83 AString *errorDetailMsg);
85 status_t queueSecureInputBuffer(
88 const CryptoPlugin::SubSample *subSamples,
90 const uint8_t key[16],
92 CryptoPlugin::Mode mode,
93 const CryptoPlugin::Pattern &pattern,
94 int64_t presentationTimeUs,
96 AString *errorDetailMsg);
98 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
100 status_t dequeueOutputBuffer(
101 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
103 status_t releaseOutputBuffer(
104 size_t index, bool render, bool updatePTS, int64_t timestampNs);
106 status_t signalEndOfInputStream();
108 status_t getFormat(JNIEnv *env, bool input, jobject *format) const;
110 status_t getOutputFormat(JNIEnv *env, size_t index, jobject *format) const;
113 JNIEnv *env, bool input, jobjectArray *bufArray) const;
116 JNIEnv *env, bool input, size_t index, jobject *buf) const;
119 JNIEnv *env, bool input, size_t index, jobject *image) const;
121 status_t getName(JNIEnv *env, jstring *name) const;
123 status_t getMetrics(JNIEnv *env, MediaAnalyticsItem * &reply) const;
125 status_t setParameters(const sp<AMessage> ¶ms);
127 void setVideoScalingMode(int mode);
130 virtual ~JMediaCodec();
132 virtual void onMessageReceived(const sp<AMessage> &msg);
142 sp<Surface> mSurfaceTextureClient;
144 // java objects cached
145 jclass mByteBufferClass;
146 jobject mNativeByteOrderObj;
147 jmethodID mByteBufferOrderMethodID;
148 jmethodID mByteBufferPositionMethodID;
149 jmethodID mByteBufferLimitMethodID;
150 jmethodID mByteBufferAsReadOnlyBufferMethodID;
153 sp<MediaCodec> mCodec;
155 sp<AMessage> mCallbackNotification;
156 sp<AMessage> mOnFrameRenderedNotification;
158 status_t mInitStatus;
160 template <typename T>
161 status_t createByteBufferFromABuffer(
162 JNIEnv *env, bool readOnly, bool clearBuffer, const sp<T> &buffer,
165 void cacheJavaObjects(JNIEnv *env);
166 void deleteJavaObjects(JNIEnv *env);
167 void handleCallback(const sp<AMessage> &msg);
168 void handleFrameRenderedNotification(const sp<AMessage> &msg);
170 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
173 } // namespace android
175 #endif // _ANDROID_MEDIA_MEDIACODEC_H_