android_media_MediaCodec.h revision 7c513b6bef8ed4dfc28e0af6c8594563fdb9f436
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 configure(
48            const sp<AMessage> &format,
49            const sp<IGraphicBufferProducer> &bufferProducer,
50            const sp<ICrypto> &crypto,
51            int flags);
52
53    status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
54
55    status_t start();
56    status_t stop();
57
58    status_t flush();
59
60    status_t queueInputBuffer(
61            size_t index,
62            size_t offset, size_t size, int64_t timeUs, uint32_t flags,
63            AString *errorDetailMsg);
64
65    status_t queueSecureInputBuffer(
66            size_t index,
67            size_t offset,
68            const CryptoPlugin::SubSample *subSamples,
69            size_t numSubSamples,
70            const uint8_t key[16],
71            const uint8_t iv[16],
72            CryptoPlugin::Mode mode,
73            int64_t presentationTimeUs,
74            uint32_t flags,
75            AString *errorDetailMsg);
76
77    status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
78
79    status_t dequeueOutputBuffer(
80            JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
81
82    status_t releaseOutputBuffer(
83            size_t index, bool render, bool updatePTS, int64_t timestampNs);
84
85    status_t signalEndOfInputStream();
86
87    status_t getOutputFormat(JNIEnv *env, jobject *format) const;
88
89    status_t getBuffers(
90            JNIEnv *env, bool input, jobjectArray *bufArray) const;
91
92    status_t getName(JNIEnv *env, jstring *name) const;
93
94    status_t setParameters(const sp<AMessage> &params);
95
96    void setVideoScalingMode(int mode);
97
98protected:
99    virtual ~JMediaCodec();
100
101    virtual void onMessageReceived(const sp<AMessage> &msg);
102
103private:
104    enum {
105        kWhatActivityNotify,
106        kWhatRequestActivityNotifications,
107        kWhatStopActivityNotifications,
108    };
109
110    jclass mClass;
111    jweak mObject;
112    sp<Surface> mSurfaceTextureClient;
113
114    sp<ALooper> mLooper;
115    sp<MediaCodec> mCodec;
116
117    sp<AMessage> mActivityNotification;
118    int32_t mGeneration;
119    bool mRequestedActivityNotification;
120
121    void requestActivityNotification();
122
123    DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
124};
125
126}  // namespace android
127
128#endif  // _ANDROID_MEDIA_MEDIACODEC_H_
129