blob: 2f2ea96d8aaedee33cc05467072e06d0172aa64c [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>
Andreas Huberaba67132013-10-22 12:40:01 -070024#include <media/stagefright/foundation/AHandler.h>
Andreas Huber88572f72012-02-21 11:47:18 -080025#include <utils/Errors.h>
Andreas Huber88572f72012-02-21 11:47:18 -080026
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;
Andy McFaddend47f7d82012-12-18 09:48:38 -080033struct IGraphicBufferProducer;
Andreas Huber88572f72012-02-21 11:47:18 -080034struct MediaCodec;
Mathias Agopian52800612013-02-14 17:11:20 -080035class Surface;
Andreas Huber88572f72012-02-21 11:47:18 -080036
Andreas Huberaba67132013-10-22 12:40:01 -070037struct JMediaCodec : public AHandler {
Andreas Huber88572f72012-02-21 11:47:18 -080038 JMediaCodec(
39 JNIEnv *env, jobject thiz,
40 const char *name, bool nameIsType, bool encoder);
41
42 status_t initCheck() const;
43
Andreas Huberaba67132013-10-22 12:40:01 -070044 void registerSelf();
Chong Zhang128b0122014-03-01 18:04:13 -080045 void release();
Andreas Huberaba67132013-10-22 12:40:01 -070046
Andreas Huber88572f72012-02-21 11:47:18 -080047 status_t configure(
48 const sp<AMessage> &format,
Andy McFaddend47f7d82012-12-18 09:48:38 -080049 const sp<IGraphicBufferProducer> &bufferProducer,
Andreas Huber8240d922012-04-04 14:06:32 -070050 const sp<ICrypto> &crypto,
Andreas Huber88572f72012-02-21 11:47:18 -080051 int flags);
52
Andy McFadden2621e402013-02-19 07:29:21 -080053 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
54
Andreas Huber88572f72012-02-21 11:47:18 -080055 status_t start();
56 status_t stop();
57
58 status_t flush();
59
60 status_t queueInputBuffer(
61 size_t index,
Andreas Huberbfc56f42012-04-19 12:47:07 -070062 size_t offset, size_t size, int64_t timeUs, uint32_t flags,
63 AString *errorDetailMsg);
Andreas Huber88572f72012-02-21 11:47:18 -080064
Andreas Huber9e6bcce2012-04-06 12:14:47 -070065 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,
Andreas Huberbfc56f42012-04-19 12:47:07 -070074 uint32_t flags,
75 AString *errorDetailMsg);
Andreas Huber9e6bcce2012-04-06 12:14:47 -070076
Andreas Huber88572f72012-02-21 11:47:18 -080077 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(size_t index, bool render);
83
Andy McFadden2621e402013-02-19 07:29:21 -080084 status_t signalEndOfInputStream();
85
Andreas Huber88572f72012-02-21 11:47:18 -080086 status_t getOutputFormat(JNIEnv *env, jobject *format) const;
87
88 status_t getBuffers(
89 JNIEnv *env, bool input, jobjectArray *bufArray) const;
90
Martin Storsjo056ef2e2012-09-25 11:53:04 +030091 status_t getName(JNIEnv *env, jstring *name) const;
92
Andreas Huber226065b2013-08-12 10:14:11 -070093 status_t setParameters(const sp<AMessage> &params);
94
Andreas Huberb12a5392012-04-30 14:18:33 -070095 void setVideoScalingMode(int mode);
96
Andreas Huber88572f72012-02-21 11:47:18 -080097protected:
98 virtual ~JMediaCodec();
99
Andreas Huberaba67132013-10-22 12:40:01 -0700100 virtual void onMessageReceived(const sp<AMessage> &msg);
101
Andreas Huber88572f72012-02-21 11:47:18 -0800102private:
Andreas Huberaba67132013-10-22 12:40:01 -0700103 enum {
104 kWhatActivityNotify,
105 kWhatRequestActivityNotifications,
106 kWhatStopActivityNotifications,
107 };
108
Andreas Huber88572f72012-02-21 11:47:18 -0800109 jclass mClass;
110 jweak mObject;
Mathias Agopian52800612013-02-14 17:11:20 -0800111 sp<Surface> mSurfaceTextureClient;
Andreas Huber88572f72012-02-21 11:47:18 -0800112
113 sp<ALooper> mLooper;
114 sp<MediaCodec> mCodec;
115
Andreas Huberaba67132013-10-22 12:40:01 -0700116 sp<AMessage> mActivityNotification;
117 int32_t mGeneration;
118 bool mRequestedActivityNotification;
119
120 void requestActivityNotification();
121
Andreas Huber88572f72012-02-21 11:47:18 -0800122 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
123};
124
125} // namespace android
126
127#endif // _ANDROID_MEDIA_MEDIACODEC_H_