blob: 2e650e3708a8338f34cce0ac43b931ad4afa5624 [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
Chong Zhang8d5e5562014-07-08 18:49:21 -070047 status_t setCallback(jobject cb);
48
Andreas Huber88572f72012-02-21 11:47:18 -080049 status_t configure(
50 const sp<AMessage> &format,
Andy McFaddend47f7d82012-12-18 09:48:38 -080051 const sp<IGraphicBufferProducer> &bufferProducer,
Andreas Huber8240d922012-04-04 14:06:32 -070052 const sp<ICrypto> &crypto,
Andreas Huber88572f72012-02-21 11:47:18 -080053 int flags);
54
Andy McFadden2621e402013-02-19 07:29:21 -080055 status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
56
Andreas Huber88572f72012-02-21 11:47:18 -080057 status_t start();
58 status_t stop();
59
60 status_t flush();
61
62 status_t queueInputBuffer(
63 size_t index,
Andreas Huberbfc56f42012-04-19 12:47:07 -070064 size_t offset, size_t size, int64_t timeUs, uint32_t flags,
65 AString *errorDetailMsg);
Andreas Huber88572f72012-02-21 11:47:18 -080066
Andreas Huber9e6bcce2012-04-06 12:14:47 -070067 status_t queueSecureInputBuffer(
68 size_t index,
69 size_t offset,
70 const CryptoPlugin::SubSample *subSamples,
71 size_t numSubSamples,
72 const uint8_t key[16],
73 const uint8_t iv[16],
74 CryptoPlugin::Mode mode,
75 int64_t presentationTimeUs,
Andreas Huberbfc56f42012-04-19 12:47:07 -070076 uint32_t flags,
77 AString *errorDetailMsg);
Andreas Huber9e6bcce2012-04-06 12:14:47 -070078
Andreas Huber88572f72012-02-21 11:47:18 -080079 status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs);
80
81 status_t dequeueOutputBuffer(
82 JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs);
83
Lajos Molnar7c513b6b2014-05-08 17:16:45 -070084 status_t releaseOutputBuffer(
85 size_t index, bool render, bool updatePTS, int64_t timestampNs);
Andreas Huber88572f72012-02-21 11:47:18 -080086
Andy McFadden2621e402013-02-19 07:29:21 -080087 status_t signalEndOfInputStream();
88
Lajos Molnard4023112014-07-11 15:12:59 -070089 status_t getFormat(JNIEnv *env, bool input, jobject *format) const;
90
91 status_t getOutputFormat(JNIEnv *env, size_t index, jobject *format) const;
Andreas Huber88572f72012-02-21 11:47:18 -080092
93 status_t getBuffers(
94 JNIEnv *env, bool input, jobjectArray *bufArray) const;
95
Lajos Molnard4023112014-07-11 15:12:59 -070096 status_t getBuffer(
97 JNIEnv *env, bool input, size_t index, jobject *buf) const;
98
99 status_t getImage(
100 JNIEnv *env, bool input, size_t index, jobject *image) const;
101
Martin Storsjo056ef2e2012-09-25 11:53:04 +0300102 status_t getName(JNIEnv *env, jstring *name) const;
103
Andreas Huber226065b2013-08-12 10:14:11 -0700104 status_t setParameters(const sp<AMessage> &params);
105
Andreas Huberb12a5392012-04-30 14:18:33 -0700106 void setVideoScalingMode(int mode);
107
Andreas Huber88572f72012-02-21 11:47:18 -0800108protected:
109 virtual ~JMediaCodec();
110
Andreas Huberaba67132013-10-22 12:40:01 -0700111 virtual void onMessageReceived(const sp<AMessage> &msg);
Chong Zhang8d5e5562014-07-08 18:49:21 -0700112 void handleCallback(const sp<AMessage> &msg);
Andreas Huberaba67132013-10-22 12:40:01 -0700113
Andreas Huber88572f72012-02-21 11:47:18 -0800114private:
Andreas Huberaba67132013-10-22 12:40:01 -0700115 enum {
Chong Zhang8d5e5562014-07-08 18:49:21 -0700116 kWhatCallbackNotify,
Andreas Huberaba67132013-10-22 12:40:01 -0700117 };
118
Andreas Huber88572f72012-02-21 11:47:18 -0800119 jclass mClass;
120 jweak mObject;
Mathias Agopian52800612013-02-14 17:11:20 -0800121 sp<Surface> mSurfaceTextureClient;
Andreas Huber88572f72012-02-21 11:47:18 -0800122
123 sp<ALooper> mLooper;
124 sp<MediaCodec> mCodec;
125
Chong Zhang8d5e5562014-07-08 18:49:21 -0700126 sp<AMessage> mCallbackNotification;
Andreas Huberaba67132013-10-22 12:40:01 -0700127
Andreas Huber88572f72012-02-21 11:47:18 -0800128 DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec);
129};
130
131} // namespace android
132
133#endif // _ANDROID_MEDIA_MEDIACODEC_H_