Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 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 | |
Andreas Huber | 9e6bcce | 2012-04-06 12:14:47 -0700 | [diff] [blame] | 22 | #include <media/hardware/CryptoAPI.h> |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 23 | #include <media/stagefright/foundation/ABase.h> |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/RefBase.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | struct ALooper; |
| 30 | struct AMessage; |
Andreas Huber | bfc56f4 | 2012-04-19 12:47:07 -0700 | [diff] [blame] | 31 | struct AString; |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 32 | struct ICrypto; |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 33 | struct IGraphicBufferProducer; |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 34 | struct MediaCodec; |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 35 | class Surface; |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 36 | |
| 37 | struct JMediaCodec : public RefBase { |
| 38 | JMediaCodec( |
| 39 | JNIEnv *env, jobject thiz, |
| 40 | const char *name, bool nameIsType, bool encoder); |
| 41 | |
| 42 | status_t initCheck() const; |
| 43 | |
| 44 | status_t configure( |
| 45 | const sp<AMessage> &format, |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 46 | const sp<IGraphicBufferProducer> &bufferProducer, |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 47 | const sp<ICrypto> &crypto, |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 48 | int flags); |
| 49 | |
Andy McFadden | 2621e40 | 2013-02-19 07:29:21 -0800 | [diff] [blame] | 50 | status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer); |
| 51 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 52 | status_t start(); |
| 53 | status_t stop(); |
| 54 | |
| 55 | status_t flush(); |
| 56 | |
| 57 | status_t queueInputBuffer( |
| 58 | size_t index, |
Andreas Huber | bfc56f4 | 2012-04-19 12:47:07 -0700 | [diff] [blame] | 59 | size_t offset, size_t size, int64_t timeUs, uint32_t flags, |
| 60 | AString *errorDetailMsg); |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 61 | |
Andreas Huber | 9e6bcce | 2012-04-06 12:14:47 -0700 | [diff] [blame] | 62 | status_t queueSecureInputBuffer( |
| 63 | size_t index, |
| 64 | size_t offset, |
| 65 | const CryptoPlugin::SubSample *subSamples, |
| 66 | size_t numSubSamples, |
| 67 | const uint8_t key[16], |
| 68 | const uint8_t iv[16], |
| 69 | CryptoPlugin::Mode mode, |
| 70 | int64_t presentationTimeUs, |
Andreas Huber | bfc56f4 | 2012-04-19 12:47:07 -0700 | [diff] [blame] | 71 | uint32_t flags, |
| 72 | AString *errorDetailMsg); |
Andreas Huber | 9e6bcce | 2012-04-06 12:14:47 -0700 | [diff] [blame] | 73 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 74 | status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs); |
| 75 | |
| 76 | status_t dequeueOutputBuffer( |
| 77 | JNIEnv *env, jobject bufferInfo, size_t *index, int64_t timeoutUs); |
| 78 | |
| 79 | status_t releaseOutputBuffer(size_t index, bool render); |
| 80 | |
Andy McFadden | 2621e40 | 2013-02-19 07:29:21 -0800 | [diff] [blame] | 81 | status_t signalEndOfInputStream(); |
| 82 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 83 | status_t getOutputFormat(JNIEnv *env, jobject *format) const; |
| 84 | |
| 85 | status_t getBuffers( |
| 86 | JNIEnv *env, bool input, jobjectArray *bufArray) const; |
| 87 | |
Martin Storsjo | 056ef2e | 2012-09-25 11:53:04 +0300 | [diff] [blame] | 88 | status_t getName(JNIEnv *env, jstring *name) const; |
| 89 | |
Andreas Huber | 226065b | 2013-08-12 10:14:11 -0700 | [diff] [blame^] | 90 | status_t setParameters(const sp<AMessage> ¶ms); |
| 91 | |
Andreas Huber | b12a539 | 2012-04-30 14:18:33 -0700 | [diff] [blame] | 92 | void setVideoScalingMode(int mode); |
| 93 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 94 | protected: |
| 95 | virtual ~JMediaCodec(); |
| 96 | |
| 97 | private: |
| 98 | jclass mClass; |
| 99 | jweak mObject; |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 100 | sp<Surface> mSurfaceTextureClient; |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 101 | |
| 102 | sp<ALooper> mLooper; |
| 103 | sp<MediaCodec> mCodec; |
| 104 | |
| 105 | DISALLOW_EVIL_CONSTRUCTORS(JMediaCodec); |
| 106 | }; |
| 107 | |
| 108 | } // namespace android |
| 109 | |
| 110 | #endif // _ANDROID_MEDIA_MEDIACODEC_H_ |