android_media_MediaCodec.h revision 88572f7a3e9d7ef85c26865a0150f3c2041561c2
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/stagefright/foundation/ABase.h>
23#include <utils/Errors.h>
24#include <utils/RefBase.h>
25
26namespace android {
27
28struct ALooper;
29struct AMessage;
30struct ISurfaceTexture;
31struct MediaCodec;
32
33struct JMediaCodec : public RefBase {
34    JMediaCodec(
35            JNIEnv *env, jobject thiz,
36            const char *name, bool nameIsType, bool encoder);
37
38    status_t initCheck() const;
39
40    status_t configure(
41            const sp<AMessage> &format,
42            const sp<ISurfaceTexture> &surfaceTexture,
43            int flags);
44
45    status_t start();
46    status_t stop();
47
48    status_t flush();
49
50    status_t queueInputBuffer(
51            size_t index,
52            size_t offset, size_t size, int64_t timeUs, uint32_t flags);
53
54    status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
55
56    status_t dequeueOutputBuffer(
57            JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
58
59    status_t releaseOutputBuffer(size_t index, bool render);
60
61    status_t getOutputFormat(JNIEnv *env, jobject *format) const;
62
63    status_t getBuffers(
64            JNIEnv *env, bool input, jobjectArray *bufArray) const;
65
66protected:
67    virtual ~JMediaCodec();
68
69private:
70    jclass mClass;
71    jweak mObject;
72
73    sp<ALooper> mLooper;
74    sp<MediaCodec> mCodec;
75
76    DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
77};
78
79}  // namespace android
80
81#endif  // _ANDROID_MEDIA_MEDIACODEC_H_
82