blob: e2688bec374672ce6c1463ef056e4af855d03f86 [file] [log] [blame]
Andreas Huber88572f72012-02-21 11:47:18 -08001/*
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
Andreas Huber9e6bcce2012-04-06 12:14:47 -070022#include <media/hardware/CryptoAPI.h>
Andreas Huber88572f72012-02-21 11:47:18 -080023#include <media/stagefright/foundation/ABase.h>
24#include <utils/Errors.h>
25#include <utils/RefBase.h>
26
27namespace android {
28
29struct ALooper;
30struct AMessage;
Andreas Huberbfc56f42012-04-19 12:47:07 -070031struct AString;
Andreas Huber8240d922012-04-04 14:06:32 -070032struct ICrypto;
Andreas Huber88572f72012-02-21 11:47:18 -080033struct ISurfaceTexture;
34struct MediaCodec;
35
36struct JMediaCodec : public RefBase {
37 JMediaCodec(
38 JNIEnv *env, jobject thiz,
39 const char *name, bool nameIsType, bool encoder);
40
41 status_t initCheck() const;
42
43 status_t configure(
44 const sp<AMessage> &format,
45 const sp<ISurfaceTexture> &surfaceTexture,
Andreas Huber8240d922012-04-04 14:06:32 -070046 const sp<ICrypto> &crypto,
Andreas Huber88572f72012-02-21 11:47:18 -080047 int flags);
48
49 status_t start();
50 status_t stop();
51
52 status_t flush();
53
54 status_t queueInputBuffer(
55 size_t index,
Andreas Huberbfc56f42012-04-19 12:47:07 -070056 size_t offset, size_t size, int64_t timeUs, uint32_t flags,
57 AString *errorDetailMsg);
Andreas Huber88572f72012-02-21 11:47:18 -080058
Andreas Huber9e6bcce2012-04-06 12:14:47 -070059 status_t queueSecureInputBuffer(
60 size_t index,
61 size_t offset,
62 const CryptoPlugin::SubSample *subSamples,
63 size_t numSubSamples,
64 const uint8_t key[16],
65 const uint8_t iv[16],
66 CryptoPlugin::Mode mode,
67 int64_t presentationTimeUs,
Andreas Huberbfc56f42012-04-19 12:47:07 -070068 uint32_t flags,
69 AString *errorDetailMsg);
Andreas Huber9e6bcce2012-04-06 12:14:47 -070070
Andreas Huber88572f72012-02-21 11:47:18 -080071 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
72
73 status_t dequeueOutputBuffer(
74 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
75
76 status_t releaseOutputBuffer(size_t index, bool render);
77
78 status_t getOutputFormat(JNIEnv *env, jobject *format) const;
79
80 status_t getBuffers(
81 JNIEnv *env, bool input, jobjectArray *bufArray) const;
82
83protected:
84 virtual ~JMediaCodec();
85
86private:
87 jclass mClass;
88 jweak mObject;
89
90 sp<ALooper> mLooper;
91 sp<MediaCodec> mCodec;
92
93 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
94};
95
96} // namespace android
97
98#endif // _ANDROID_MEDIA_MEDIACODEC_H_