xref: /aosp_15_r20/cts/tests/media/jni/NativeCodecUnitTest.cpp (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1*b7c941bbSAndroid Build Coastguard Worker /*
2*b7c941bbSAndroid Build Coastguard Worker  * Copyright (C) 2020 The Android Open Source Project
3*b7c941bbSAndroid Build Coastguard Worker  *
4*b7c941bbSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*b7c941bbSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*b7c941bbSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*b7c941bbSAndroid Build Coastguard Worker  *
8*b7c941bbSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*b7c941bbSAndroid Build Coastguard Worker  *
10*b7c941bbSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*b7c941bbSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*b7c941bbSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*b7c941bbSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*b7c941bbSAndroid Build Coastguard Worker  * limitations under the License.
15*b7c941bbSAndroid Build Coastguard Worker  */
16*b7c941bbSAndroid Build Coastguard Worker 
17*b7c941bbSAndroid Build Coastguard Worker //#define LOG_NDEBUG 0
18*b7c941bbSAndroid Build Coastguard Worker #define LOG_TAG "NativeCodecUnitTest"
19*b7c941bbSAndroid Build Coastguard Worker #include <log/log.h>
20*b7c941bbSAndroid Build Coastguard Worker 
21*b7c941bbSAndroid Build Coastguard Worker #include <jni.h>
22*b7c941bbSAndroid Build Coastguard Worker #include <media/NdkMediaExtractor.h>
23*b7c941bbSAndroid Build Coastguard Worker #include <sys/stat.h>
24*b7c941bbSAndroid Build Coastguard Worker 
25*b7c941bbSAndroid Build Coastguard Worker #include <thread>
26*b7c941bbSAndroid Build Coastguard Worker 
27*b7c941bbSAndroid Build Coastguard Worker #include "NativeCodecTestBase.h"
28*b7c941bbSAndroid Build Coastguard Worker #include "NativeMediaCommon.h"
29*b7c941bbSAndroid Build Coastguard Worker 
30*b7c941bbSAndroid Build Coastguard Worker class NativeCodecUnitTest final : CodecTestBase {
31*b7c941bbSAndroid Build Coastguard Worker   private:
32*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* mFormat;
33*b7c941bbSAndroid Build Coastguard Worker     bool enqueueInput(size_t bufferIndex) override;
34*b7c941bbSAndroid Build Coastguard Worker     bool dequeueOutput(size_t bufferIndex, AMediaCodecBufferInfo* bufferInfo) override;
35*b7c941bbSAndroid Build Coastguard Worker 
36*b7c941bbSAndroid Build Coastguard Worker     const long kStallTimeMs = 1000;
37*b7c941bbSAndroid Build Coastguard Worker 
38*b7c941bbSAndroid Build Coastguard Worker   public:
39*b7c941bbSAndroid Build Coastguard Worker     explicit NativeCodecUnitTest(const char* mediaType);
40*b7c941bbSAndroid Build Coastguard Worker     ~NativeCodecUnitTest();
41*b7c941bbSAndroid Build Coastguard Worker 
42*b7c941bbSAndroid Build Coastguard Worker     bool setupCodec(bool isAudio, bool isEncoder);
43*b7c941bbSAndroid Build Coastguard Worker 
44*b7c941bbSAndroid Build Coastguard Worker     bool testConfigureCodecForIncompleteFormat(bool isAudio, bool isEncoder);
45*b7c941bbSAndroid Build Coastguard Worker     bool testConfigureCodecForBadFlags(bool isEncoder);
46*b7c941bbSAndroid Build Coastguard Worker     bool testConfigureInInitState();
47*b7c941bbSAndroid Build Coastguard Worker     bool testConfigureInRunningState();
48*b7c941bbSAndroid Build Coastguard Worker     bool testConfigureInUnInitState();
49*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueInputBufferInInitState();
50*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueInputBufferInRunningState();
51*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueInputBufferInUnInitState();
52*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueOutputBufferInInitState();
53*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueOutputBufferInRunningState();
54*b7c941bbSAndroid Build Coastguard Worker     bool testDequeueOutputBufferInUnInitState();
55*b7c941bbSAndroid Build Coastguard Worker     bool testFlushInInitState();
56*b7c941bbSAndroid Build Coastguard Worker     bool testFlushInRunningState();
57*b7c941bbSAndroid Build Coastguard Worker     bool testFlushInUnInitState();
58*b7c941bbSAndroid Build Coastguard Worker     bool testGetNameInInitState();
59*b7c941bbSAndroid Build Coastguard Worker     bool testGetNameInRunningState();
60*b7c941bbSAndroid Build Coastguard Worker     bool testGetNameInUnInitState();
61*b7c941bbSAndroid Build Coastguard Worker     bool testSetAsyncNotifyCallbackInInitState();
62*b7c941bbSAndroid Build Coastguard Worker     bool testSetAsyncNotifyCallbackInRunningState();
63*b7c941bbSAndroid Build Coastguard Worker     bool testSetAsyncNotifyCallbackInUnInitState();
64*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputBufferInInitState();
65*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputBufferInRunningState();
66*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputBufferInUnInitState();
67*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputFormatInInitState();
68*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputFormatInRunningState();
69*b7c941bbSAndroid Build Coastguard Worker     bool testGetInputFormatInUnInitState();
70*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputBufferInInitState();
71*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputBufferInRunningState();
72*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputBufferInUnInitState();
73*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputFormatInInitState();
74*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputFormatInRunningState();
75*b7c941bbSAndroid Build Coastguard Worker     bool testGetOutputFormatInUnInitState();
76*b7c941bbSAndroid Build Coastguard Worker     bool testSetParametersInInitState();
77*b7c941bbSAndroid Build Coastguard Worker     bool testSetParametersInRunningState();
78*b7c941bbSAndroid Build Coastguard Worker     bool testSetParametersInUnInitState();
79*b7c941bbSAndroid Build Coastguard Worker     bool testStartInRunningState();
80*b7c941bbSAndroid Build Coastguard Worker     bool testStartInUnInitState();
81*b7c941bbSAndroid Build Coastguard Worker     bool testStopInInitState();
82*b7c941bbSAndroid Build Coastguard Worker     bool testStopInRunningState();
83*b7c941bbSAndroid Build Coastguard Worker     bool testStopInUnInitState();
84*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferInInitState();
85*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferWithBadIndex();
86*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferWithBadSize();
87*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferWithBadBuffInfo();
88*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferWithBadOffset();
89*b7c941bbSAndroid Build Coastguard Worker     bool testQueueInputBufferInUnInitState();
90*b7c941bbSAndroid Build Coastguard Worker     bool testReleaseOutputBufferInInitState();
91*b7c941bbSAndroid Build Coastguard Worker     bool testReleaseOutputBufferInRunningState();
92*b7c941bbSAndroid Build Coastguard Worker     bool testReleaseOutputBufferInUnInitState();
93*b7c941bbSAndroid Build Coastguard Worker     bool testGetBufferFormatInInitState();
94*b7c941bbSAndroid Build Coastguard Worker     bool testGetBufferFormatInRunningState();
95*b7c941bbSAndroid Build Coastguard Worker     bool testGetBufferFormatInUnInitState();
96*b7c941bbSAndroid Build Coastguard Worker };
97*b7c941bbSAndroid Build Coastguard Worker 
NativeCodecUnitTest(const char * mediaType)98*b7c941bbSAndroid Build Coastguard Worker NativeCodecUnitTest::NativeCodecUnitTest(const char* mediaType) : CodecTestBase(mediaType) {
99*b7c941bbSAndroid Build Coastguard Worker     mFormat = nullptr;
100*b7c941bbSAndroid Build Coastguard Worker }
101*b7c941bbSAndroid Build Coastguard Worker 
~NativeCodecUnitTest()102*b7c941bbSAndroid Build Coastguard Worker NativeCodecUnitTest::~NativeCodecUnitTest() {
103*b7c941bbSAndroid Build Coastguard Worker     if (mFormat) AMediaFormat_delete(mFormat);
104*b7c941bbSAndroid Build Coastguard Worker     mFormat = nullptr;
105*b7c941bbSAndroid Build Coastguard Worker }
106*b7c941bbSAndroid Build Coastguard Worker 
enqueueInput(size_t bufferIndex)107*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::enqueueInput(size_t bufferIndex) {
108*b7c941bbSAndroid Build Coastguard Worker     (void)bufferIndex;
109*b7c941bbSAndroid Build Coastguard Worker     return false;
110*b7c941bbSAndroid Build Coastguard Worker }
111*b7c941bbSAndroid Build Coastguard Worker 
dequeueOutput(size_t bufferIndex,AMediaCodecBufferInfo * info)112*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::dequeueOutput(size_t bufferIndex, AMediaCodecBufferInfo* info) {
113*b7c941bbSAndroid Build Coastguard Worker     if ((info->flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) != 0) {
114*b7c941bbSAndroid Build Coastguard Worker         mSawOutputEOS = true;
115*b7c941bbSAndroid Build Coastguard Worker     }
116*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_releaseOutputBuffer(mCodec, bufferIndex, false),
117*b7c941bbSAndroid Build Coastguard Worker                    "AMediaCodec_releaseOutputBuffer failed")
118*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
119*b7c941bbSAndroid Build Coastguard Worker }
120*b7c941bbSAndroid Build Coastguard Worker 
getSampleAudioFormat()121*b7c941bbSAndroid Build Coastguard Worker AMediaFormat* getSampleAudioFormat() {
122*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* format = AMediaFormat_new();
123*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_AUDIO_AAC);
124*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_BIT_RATE, 64000);
125*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, 16000);
126*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_CHANNEL_COUNT, 1);
127*b7c941bbSAndroid Build Coastguard Worker     return format;
128*b7c941bbSAndroid Build Coastguard Worker }
129*b7c941bbSAndroid Build Coastguard Worker 
getSampleVideoFormat()130*b7c941bbSAndroid Build Coastguard Worker AMediaFormat* getSampleVideoFormat() {
131*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* format = AMediaFormat_new();
132*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_VIDEO_AVC);
133*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_BIT_RATE, 512000);
134*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, 352);
135*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, 288);
136*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_FRAME_RATE, 30);
137*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setFloat(format, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, 1.0F);
138*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, COLOR_FormatYUV420Flexible);
139*b7c941bbSAndroid Build Coastguard Worker     return format;
140*b7c941bbSAndroid Build Coastguard Worker }
141*b7c941bbSAndroid Build Coastguard Worker 
setupCodec(bool isAudio,bool isEncoder)142*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::setupCodec(bool isAudio, bool isEncoder) {
143*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
144*b7c941bbSAndroid Build Coastguard Worker     mFormat = isAudio ? getSampleAudioFormat() : getSampleVideoFormat();
145*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
146*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
147*b7c941bbSAndroid Build Coastguard Worker     mCodec = isEncoder ? AMediaCodec_createEncoderByType(mediaType)
148*b7c941bbSAndroid Build Coastguard Worker                        : AMediaCodec_createDecoderByType(mediaType);
149*b7c941bbSAndroid Build Coastguard Worker     if (!mCodec) {
150*b7c941bbSAndroid Build Coastguard Worker         ALOGE("unable to create codec %s", mediaType);
151*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
152*b7c941bbSAndroid Build Coastguard Worker     }
153*b7c941bbSAndroid Build Coastguard Worker     return isPass;
154*b7c941bbSAndroid Build Coastguard Worker }
155*b7c941bbSAndroid Build Coastguard Worker 
156*b7c941bbSAndroid Build Coastguard Worker /* Structure to keep format key and their value to initialize format. Value can be of type
157*b7c941bbSAndroid Build Coastguard Worker  * string(stringVal) or int(intVal). At once, only one of stringVal or intVal is initialise with
158*b7c941bbSAndroid Build Coastguard Worker  * valid value. */
159*b7c941bbSAndroid Build Coastguard Worker struct formatKey {
160*b7c941bbSAndroid Build Coastguard Worker     const char* key = nullptr;
161*b7c941bbSAndroid Build Coastguard Worker     const char* stringVal = nullptr;
162*b7c941bbSAndroid Build Coastguard Worker     int32_t intVal = 0;
163*b7c941bbSAndroid Build Coastguard Worker };
164*b7c941bbSAndroid Build Coastguard Worker 
setUpDefaultFormatElementsList(std::vector<formatKey * > & vec,bool isAudio,bool isEncoder)165*b7c941bbSAndroid Build Coastguard Worker void setUpDefaultFormatElementsList(std::vector<formatKey*>& vec, bool isAudio, bool isEncoder) {
166*b7c941bbSAndroid Build Coastguard Worker     if (isAudio) {
167*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_AUDIO_AAC, -1});
168*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_SAMPLE_RATE, nullptr, 16000});
169*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_CHANNEL_COUNT, nullptr, 1});
170*b7c941bbSAndroid Build Coastguard Worker         if (isEncoder) {
171*b7c941bbSAndroid Build Coastguard Worker             vec.push_back(new formatKey{AMEDIAFORMAT_KEY_BIT_RATE, nullptr, 64000});
172*b7c941bbSAndroid Build Coastguard Worker         }
173*b7c941bbSAndroid Build Coastguard Worker     } else {
174*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_VIDEO_AVC, -1});
175*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_WIDTH, nullptr, 176});
176*b7c941bbSAndroid Build Coastguard Worker         vec.push_back(new formatKey{AMEDIAFORMAT_KEY_HEIGHT, nullptr, 144});
177*b7c941bbSAndroid Build Coastguard Worker         if (isEncoder) {
178*b7c941bbSAndroid Build Coastguard Worker             vec.push_back(new formatKey{AMEDIAFORMAT_KEY_FRAME_RATE, nullptr, 24});
179*b7c941bbSAndroid Build Coastguard Worker             vec.push_back(new formatKey{AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, nullptr, 1});
180*b7c941bbSAndroid Build Coastguard Worker             vec.push_back(new formatKey{AMEDIAFORMAT_KEY_BIT_RATE, nullptr, 256000});
181*b7c941bbSAndroid Build Coastguard Worker             vec.push_back(new formatKey{AMEDIAFORMAT_KEY_COLOR_FORMAT, nullptr,
182*b7c941bbSAndroid Build Coastguard Worker                                         COLOR_FormatYUV420Flexible});
183*b7c941bbSAndroid Build Coastguard Worker         }
184*b7c941bbSAndroid Build Coastguard Worker     }
185*b7c941bbSAndroid Build Coastguard Worker }
186*b7c941bbSAndroid Build Coastguard Worker 
deleteDefaultFormatElementsList(std::vector<formatKey * > & vector)187*b7c941bbSAndroid Build Coastguard Worker void deleteDefaultFormatElementsList(std::vector<formatKey*>& vector) {
188*b7c941bbSAndroid Build Coastguard Worker     for (auto& i : vector) delete i;
189*b7c941bbSAndroid Build Coastguard Worker }
190*b7c941bbSAndroid Build Coastguard Worker 
getSampleFormat(std::vector<formatKey * > vector,int skipIndex)191*b7c941bbSAndroid Build Coastguard Worker AMediaFormat* getSampleFormat(std::vector<formatKey*> vector, int skipIndex) {
192*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* format = AMediaFormat_new();
193*b7c941bbSAndroid Build Coastguard Worker     for (int i = 0; i < vector.size(); i++) {
194*b7c941bbSAndroid Build Coastguard Worker         if (skipIndex == i) continue;
195*b7c941bbSAndroid Build Coastguard Worker         formatKey* element = vector.at(i);
196*b7c941bbSAndroid Build Coastguard Worker         if (element->stringVal) {
197*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_setString(format, element->key, element->stringVal);
198*b7c941bbSAndroid Build Coastguard Worker         } else {
199*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_setInt32(format, element->key, element->intVal);
200*b7c941bbSAndroid Build Coastguard Worker         }
201*b7c941bbSAndroid Build Coastguard Worker     }
202*b7c941bbSAndroid Build Coastguard Worker     return format;
203*b7c941bbSAndroid Build Coastguard Worker }
204*b7c941bbSAndroid Build Coastguard Worker 
testConfigureCodecForIncompleteFormat(bool isAudio,bool isEncoder)205*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testConfigureCodecForIncompleteFormat(bool isAudio, bool isEncoder) {
206*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = isAudio ? AMEDIA_MIMETYPE_AUDIO_AAC : AMEDIA_MIMETYPE_VIDEO_AVC;
207*b7c941bbSAndroid Build Coastguard Worker     mCodec = isEncoder ? AMediaCodec_createEncoderByType(mediaType)
208*b7c941bbSAndroid Build Coastguard Worker                        : AMediaCodec_createDecoderByType(mediaType);
209*b7c941bbSAndroid Build Coastguard Worker     if (!mCodec) {
210*b7c941bbSAndroid Build Coastguard Worker         ALOGE("unable to create codec for media Type %s", mediaType);
211*b7c941bbSAndroid Build Coastguard Worker         return false;
212*b7c941bbSAndroid Build Coastguard Worker     }
213*b7c941bbSAndroid Build Coastguard Worker     std::vector<formatKey*> vector;
214*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
215*b7c941bbSAndroid Build Coastguard Worker     setUpDefaultFormatElementsList(vector, isAudio, isEncoder);
216*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* format = nullptr;
217*b7c941bbSAndroid Build Coastguard Worker     int i;
218*b7c941bbSAndroid Build Coastguard Worker     for (i = 0; i < vector.size(); i++) {
219*b7c941bbSAndroid Build Coastguard Worker         if (!isPass) break;
220*b7c941bbSAndroid Build Coastguard Worker         format = getSampleFormat(vector, i);
221*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
222*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, format, nullptr, nullptr,
223*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
224*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds for format with missing key %s", vector.at(i)->key);
225*b7c941bbSAndroid Build Coastguard Worker             isPass = false;
226*b7c941bbSAndroid Build Coastguard Worker         }
227*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(format);
228*b7c941bbSAndroid Build Coastguard Worker     }
229*b7c941bbSAndroid Build Coastguard Worker     format = getSampleFormat(vector, i);
230*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK !=
231*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_configure(mCodec, format, nullptr, nullptr,
232*b7c941bbSAndroid Build Coastguard Worker                               isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
233*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec configure fails for valid format %s", AMediaFormat_toString(format));
234*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
235*b7c941bbSAndroid Build Coastguard Worker     }
236*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_delete(format);
237*b7c941bbSAndroid Build Coastguard Worker     deleteDefaultFormatElementsList(vector);
238*b7c941bbSAndroid Build Coastguard Worker     return isPass;
239*b7c941bbSAndroid Build Coastguard Worker }
240*b7c941bbSAndroid Build Coastguard Worker 
testConfigureCodecForBadFlags(bool isEncoder)241*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testConfigureCodecForBadFlags(bool isEncoder) {
242*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
243*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
244*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
245*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK ==
246*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
247*b7c941bbSAndroid Build Coastguard Worker                               isEncoder ? 0 : AMEDIACODEC_CONFIGURE_FLAG_ENCODE)) {
248*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
249*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec configure succeeds with bad configure flag");
250*b7c941bbSAndroid Build Coastguard Worker     }
251*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec_stop(mCodec);
252*b7c941bbSAndroid Build Coastguard Worker     return isPass;
253*b7c941bbSAndroid Build Coastguard Worker }
254*b7c941bbSAndroid Build Coastguard Worker 
testConfigureInInitState()255*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testConfigureInInitState() {
256*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
257*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
258*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
259*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
260*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
261*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, true, isEncoder)) return false;
262*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
263*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
264*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
265*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds in initialized state");
266*b7c941bbSAndroid Build Coastguard Worker             return false;
267*b7c941bbSAndroid Build Coastguard Worker         }
268*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
269*b7c941bbSAndroid Build Coastguard Worker     }
270*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
271*b7c941bbSAndroid Build Coastguard Worker }
272*b7c941bbSAndroid Build Coastguard Worker 
testConfigureInRunningState()273*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testConfigureInRunningState() {
274*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
275*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
276*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
277*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
278*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
279*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
280*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
281*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
282*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
283*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
284*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds in initialized state");
285*b7c941bbSAndroid Build Coastguard Worker             return false;
286*b7c941bbSAndroid Build Coastguard Worker         }
287*b7c941bbSAndroid Build Coastguard Worker         if (!flushCodec()) return false;
288*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
289*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
290*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
291*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds in flush state");
292*b7c941bbSAndroid Build Coastguard Worker             return false;
293*b7c941bbSAndroid Build Coastguard Worker         }
294*b7c941bbSAndroid Build Coastguard Worker         if (mIsCodecInAsyncMode) {
295*b7c941bbSAndroid Build Coastguard Worker             RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
296*b7c941bbSAndroid Build Coastguard Worker         }
297*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
298*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
299*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
300*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
301*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds in running state");
302*b7c941bbSAndroid Build Coastguard Worker             return false;
303*b7c941bbSAndroid Build Coastguard Worker         }
304*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
305*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
306*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
307*b7c941bbSAndroid Build Coastguard Worker                                   isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0)) {
308*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec configure succeeds in eos state");
309*b7c941bbSAndroid Build Coastguard Worker             return false;
310*b7c941bbSAndroid Build Coastguard Worker         }
311*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
312*b7c941bbSAndroid Build Coastguard Worker     }
313*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
314*b7c941bbSAndroid Build Coastguard Worker }
315*b7c941bbSAndroid Build Coastguard Worker 
testConfigureInUnInitState()316*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testConfigureInUnInitState() {
317*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
318*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
319*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
320*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
321*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
322*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
323*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
324*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_configure(mCodec, mFormat, nullptr, nullptr,
325*b7c941bbSAndroid Build Coastguard Worker                                              isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0),
326*b7c941bbSAndroid Build Coastguard Worker                        "codec configure fails in uninitialized state")
327*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
328*b7c941bbSAndroid Build Coastguard Worker     }
329*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
330*b7c941bbSAndroid Build Coastguard Worker }
331*b7c941bbSAndroid Build Coastguard Worker 
testDequeueInputBufferInInitState()332*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueInputBufferInInitState() {
333*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
334*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
335*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
336*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
337*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
338*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
339*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueInputBuffer(mCodec, kQDeQTimeOutUs) >=
340*b7c941bbSAndroid Build Coastguard Worker             AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
341*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue input buffer succeeds in uninitialized state");
342*b7c941bbSAndroid Build Coastguard Worker             return false;
343*b7c941bbSAndroid Build Coastguard Worker         }
344*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
345*b7c941bbSAndroid Build Coastguard Worker     }
346*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
347*b7c941bbSAndroid Build Coastguard Worker }
348*b7c941bbSAndroid Build Coastguard Worker 
testDequeueInputBufferInRunningState()349*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueInputBufferInRunningState() {
350*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
351*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
352*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
353*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
354*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
355*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
356*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
357*b7c941bbSAndroid Build Coastguard Worker         if (mIsCodecInAsyncMode) {
358*b7c941bbSAndroid Build Coastguard Worker             if (AMediaCodec_dequeueInputBuffer(mCodec, kQDeQTimeOutUs) >=
359*b7c941bbSAndroid Build Coastguard Worker                 AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
360*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("dequeue input buffer succeeds in running state in async mode");
361*b7c941bbSAndroid Build Coastguard Worker                 return false;
362*b7c941bbSAndroid Build Coastguard Worker             }
363*b7c941bbSAndroid Build Coastguard Worker         }
364*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
365*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
366*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
367*b7c941bbSAndroid Build Coastguard Worker     }
368*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
369*b7c941bbSAndroid Build Coastguard Worker }
370*b7c941bbSAndroid Build Coastguard Worker 
testDequeueInputBufferInUnInitState()371*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueInputBufferInUnInitState() {
372*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
373*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
374*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
375*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
376*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
377*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueInputBuffer(mCodec, kQDeQTimeOutUs) >=
378*b7c941bbSAndroid Build Coastguard Worker             AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
379*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue input buffer succeeds in uninitialized state");
380*b7c941bbSAndroid Build Coastguard Worker             return false;
381*b7c941bbSAndroid Build Coastguard Worker         }
382*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
383*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
384*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
385*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueInputBuffer(mCodec, kQDeQTimeOutUs) >= -1) {
386*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue input buffer succeeds in stopped state");
387*b7c941bbSAndroid Build Coastguard Worker             return false;
388*b7c941bbSAndroid Build Coastguard Worker         }
389*b7c941bbSAndroid Build Coastguard Worker     }
390*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
391*b7c941bbSAndroid Build Coastguard Worker }
392*b7c941bbSAndroid Build Coastguard Worker 
testDequeueOutputBufferInInitState()393*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueOutputBufferInInitState() {
394*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
395*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
396*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
397*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
398*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
399*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
400*b7c941bbSAndroid Build Coastguard Worker         AMediaCodecBufferInfo outInfo;
401*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs) >=
402*b7c941bbSAndroid Build Coastguard Worker             AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
403*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue output buffer succeeds in uninitialized state");
404*b7c941bbSAndroid Build Coastguard Worker             return false;
405*b7c941bbSAndroid Build Coastguard Worker         }
406*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
407*b7c941bbSAndroid Build Coastguard Worker     }
408*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
409*b7c941bbSAndroid Build Coastguard Worker }
410*b7c941bbSAndroid Build Coastguard Worker 
testDequeueOutputBufferInRunningState()411*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueOutputBufferInRunningState() {
412*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
413*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
414*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
415*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
416*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
417*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
418*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
419*b7c941bbSAndroid Build Coastguard Worker         if (mIsCodecInAsyncMode) {
420*b7c941bbSAndroid Build Coastguard Worker             AMediaCodecBufferInfo outInfo;
421*b7c941bbSAndroid Build Coastguard Worker             if (AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs) >=
422*b7c941bbSAndroid Build Coastguard Worker                 AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
423*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("dequeue output buffer succeeds in running state in async mode");
424*b7c941bbSAndroid Build Coastguard Worker                 return false;
425*b7c941bbSAndroid Build Coastguard Worker             }
426*b7c941bbSAndroid Build Coastguard Worker         }
427*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
428*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
429*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
430*b7c941bbSAndroid Build Coastguard Worker     }
431*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
432*b7c941bbSAndroid Build Coastguard Worker }
433*b7c941bbSAndroid Build Coastguard Worker 
testDequeueOutputBufferInUnInitState()434*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testDequeueOutputBufferInUnInitState() {
435*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
436*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
437*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
438*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
439*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
440*b7c941bbSAndroid Build Coastguard Worker         AMediaCodecBufferInfo outInfo;
441*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs) >=
442*b7c941bbSAndroid Build Coastguard Worker             AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
443*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue output buffer succeeds in uninitialized state");
444*b7c941bbSAndroid Build Coastguard Worker             return false;
445*b7c941bbSAndroid Build Coastguard Worker         }
446*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
447*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
448*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
449*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs) >=
450*b7c941bbSAndroid Build Coastguard Worker             AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
451*b7c941bbSAndroid Build Coastguard Worker             ALOGE("dequeue output buffer succeeds in stopped state");
452*b7c941bbSAndroid Build Coastguard Worker             return false;
453*b7c941bbSAndroid Build Coastguard Worker         }
454*b7c941bbSAndroid Build Coastguard Worker     }
455*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
456*b7c941bbSAndroid Build Coastguard Worker }
457*b7c941bbSAndroid Build Coastguard Worker 
testFlushInInitState()458*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testFlushInInitState() {
459*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
460*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
461*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
462*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
463*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
464*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
465*b7c941bbSAndroid Build Coastguard Worker         if (flushCodec()) {
466*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec flush succeeds in uninitialized state");
467*b7c941bbSAndroid Build Coastguard Worker             return false;
468*b7c941bbSAndroid Build Coastguard Worker         }
469*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
470*b7c941bbSAndroid Build Coastguard Worker     }
471*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
472*b7c941bbSAndroid Build Coastguard Worker }
473*b7c941bbSAndroid Build Coastguard Worker 
testFlushInRunningState()474*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testFlushInRunningState() {
475*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
476*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
477*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
478*b7c941bbSAndroid Build Coastguard Worker     bool isAsync = true;
479*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
480*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
481*b7c941bbSAndroid Build Coastguard Worker     if (!flushCodec()) return false;
482*b7c941bbSAndroid Build Coastguard Worker     std::this_thread::sleep_for(std::chrono::milliseconds(kStallTimeMs));
483*b7c941bbSAndroid Build Coastguard Worker     if (!mAsyncHandle.isInputQueueEmpty()) {
484*b7c941bbSAndroid Build Coastguard Worker         ALOGE("received input buffer callback before start");
485*b7c941bbSAndroid Build Coastguard Worker         return false;
486*b7c941bbSAndroid Build Coastguard Worker     }
487*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
488*b7c941bbSAndroid Build Coastguard Worker     std::this_thread::sleep_for(std::chrono::milliseconds(kStallTimeMs));
489*b7c941bbSAndroid Build Coastguard Worker     if (mAsyncHandle.isInputQueueEmpty()) {
490*b7c941bbSAndroid Build Coastguard Worker         ALOGE("did not receive input buffer callback after start");
491*b7c941bbSAndroid Build Coastguard Worker         return false;
492*b7c941bbSAndroid Build Coastguard Worker     }
493*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
494*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
495*b7c941bbSAndroid Build Coastguard Worker }
496*b7c941bbSAndroid Build Coastguard Worker 
testFlushInUnInitState()497*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testFlushInUnInitState() {
498*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
499*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
500*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
501*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
502*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
503*b7c941bbSAndroid Build Coastguard Worker         if (flushCodec()) {
504*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec flush succeeds in uninitialized state");
505*b7c941bbSAndroid Build Coastguard Worker             return false;
506*b7c941bbSAndroid Build Coastguard Worker         }
507*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
508*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
509*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
510*b7c941bbSAndroid Build Coastguard Worker         if (flushCodec()) {
511*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec flush succeeds in uninitialized state");
512*b7c941bbSAndroid Build Coastguard Worker             return false;
513*b7c941bbSAndroid Build Coastguard Worker         }
514*b7c941bbSAndroid Build Coastguard Worker     }
515*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
516*b7c941bbSAndroid Build Coastguard Worker }
517*b7c941bbSAndroid Build Coastguard Worker 
testGetNameInInitState()518*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetNameInInitState() {
519*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
520*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
521*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
522*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
523*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
524*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
525*b7c941bbSAndroid Build Coastguard Worker         char* name = nullptr;
526*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_getName(mCodec, &name) || !name) {
527*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec get metadata call fails in initialized state");
528*b7c941bbSAndroid Build Coastguard Worker             if (name) AMediaCodec_releaseName(mCodec, name);
529*b7c941bbSAndroid Build Coastguard Worker             return false;
530*b7c941bbSAndroid Build Coastguard Worker         }
531*b7c941bbSAndroid Build Coastguard Worker         if (name) AMediaCodec_releaseName(mCodec, name);
532*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
533*b7c941bbSAndroid Build Coastguard Worker     }
534*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
535*b7c941bbSAndroid Build Coastguard Worker }
536*b7c941bbSAndroid Build Coastguard Worker 
testGetNameInRunningState()537*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetNameInRunningState() {
538*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
539*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
540*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
541*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
542*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
543*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
544*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
545*b7c941bbSAndroid Build Coastguard Worker         char* name = nullptr;
546*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_getName(mCodec, &name) || !name) {
547*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec get metadata call fails in running state");
548*b7c941bbSAndroid Build Coastguard Worker             if (name) AMediaCodec_releaseName(mCodec, name);
549*b7c941bbSAndroid Build Coastguard Worker             return false;
550*b7c941bbSAndroid Build Coastguard Worker         }
551*b7c941bbSAndroid Build Coastguard Worker         if (name) AMediaCodec_releaseName(mCodec, name);
552*b7c941bbSAndroid Build Coastguard Worker         name = nullptr;
553*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
554*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
555*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_getName(mCodec, &name) || !name) {
556*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec get metadata call fails in running state");
557*b7c941bbSAndroid Build Coastguard Worker             if (name) AMediaCodec_releaseName(mCodec, name);
558*b7c941bbSAndroid Build Coastguard Worker             return false;
559*b7c941bbSAndroid Build Coastguard Worker         }
560*b7c941bbSAndroid Build Coastguard Worker         if (name) AMediaCodec_releaseName(mCodec, name);
561*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
562*b7c941bbSAndroid Build Coastguard Worker     }
563*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
564*b7c941bbSAndroid Build Coastguard Worker }
565*b7c941bbSAndroid Build Coastguard Worker 
testGetNameInUnInitState()566*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetNameInUnInitState() {
567*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
568*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
569*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
570*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
571*b7c941bbSAndroid Build Coastguard Worker     char* name = nullptr;
572*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK != AMediaCodec_getName(mCodec, &name) || !name) {
573*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec get metadata call fails in uninitialized state");
574*b7c941bbSAndroid Build Coastguard Worker         if (name) AMediaCodec_releaseName(mCodec, name);
575*b7c941bbSAndroid Build Coastguard Worker         return false;
576*b7c941bbSAndroid Build Coastguard Worker     }
577*b7c941bbSAndroid Build Coastguard Worker     if (name) AMediaCodec_releaseName(mCodec, name);
578*b7c941bbSAndroid Build Coastguard Worker     name = nullptr;
579*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
580*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
581*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
582*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
583*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_getName(mCodec, &name) || !name) {
584*b7c941bbSAndroid Build Coastguard Worker             ALOGE("codec get metadata call fails in uninitialized state");
585*b7c941bbSAndroid Build Coastguard Worker             if (name) AMediaCodec_releaseName(mCodec, name);
586*b7c941bbSAndroid Build Coastguard Worker             return false;
587*b7c941bbSAndroid Build Coastguard Worker         }
588*b7c941bbSAndroid Build Coastguard Worker         if (name) AMediaCodec_releaseName(mCodec, name);
589*b7c941bbSAndroid Build Coastguard Worker     }
590*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
591*b7c941bbSAndroid Build Coastguard Worker }
592*b7c941bbSAndroid Build Coastguard Worker 
testSetAsyncNotifyCallbackInInitState()593*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetAsyncNotifyCallbackInInitState() {
594*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
595*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
596*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
597*b7c941bbSAndroid Build Coastguard Worker     bool isAsync = true;
598*b7c941bbSAndroid Build Coastguard Worker 
599*b7c941bbSAndroid Build Coastguard Worker     // configure component in sync mode
600*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, !isAsync, false, isEncoder)) return false;
601*b7c941bbSAndroid Build Coastguard Worker     // setCallBack in async mode
602*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(mAsyncHandle.setCallBack(mCodec, isAsync),
603*b7c941bbSAndroid Build Coastguard Worker                    "AMediaCodec_setAsyncNotifyCallback failed")
604*b7c941bbSAndroid Build Coastguard Worker     mIsCodecInAsyncMode = true;
605*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
606*b7c941bbSAndroid Build Coastguard Worker     if (!queueEOS()) return false;
607*b7c941bbSAndroid Build Coastguard Worker     if (!waitForAllOutputs()) return false;
608*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
609*b7c941bbSAndroid Build Coastguard Worker 
610*b7c941bbSAndroid Build Coastguard Worker     // configure component in async mode
611*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
612*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
613*b7c941bbSAndroid Build Coastguard Worker     if (!queueEOS()) return false;
614*b7c941bbSAndroid Build Coastguard Worker     if (!waitForAllOutputs()) return false;
615*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
616*b7c941bbSAndroid Build Coastguard Worker 
617*b7c941bbSAndroid Build Coastguard Worker     // configure component in async mode
618*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
619*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
620*b7c941bbSAndroid Build Coastguard Worker     // configure component in sync mode
621*b7c941bbSAndroid Build Coastguard Worker     if (!reConfigureCodec(mFormat, !isAsync, false, isEncoder)) return false;
622*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
623*b7c941bbSAndroid Build Coastguard Worker     if (!queueEOS()) return false;
624*b7c941bbSAndroid Build Coastguard Worker     if (!waitForAllOutputs()) return false;
625*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
626*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
627*b7c941bbSAndroid Build Coastguard Worker }
628*b7c941bbSAndroid Build Coastguard Worker 
testSetAsyncNotifyCallbackInRunningState()629*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetAsyncNotifyCallbackInRunningState() {
630*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
631*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
632*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
633*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
634*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
635*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
636*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
637*b7c941bbSAndroid Build Coastguard Worker         // setCallBack in async mode
638*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == mAsyncHandle.setCallBack(mCodec, true)) {
639*b7c941bbSAndroid Build Coastguard Worker             ALOGE("setAsyncNotifyCallback call succeeds in running state");
640*b7c941bbSAndroid Build Coastguard Worker             return false;
641*b7c941bbSAndroid Build Coastguard Worker         }
642*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
643*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
644*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
645*b7c941bbSAndroid Build Coastguard Worker     }
646*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
647*b7c941bbSAndroid Build Coastguard Worker }
648*b7c941bbSAndroid Build Coastguard Worker 
testSetAsyncNotifyCallbackInUnInitState()649*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetAsyncNotifyCallbackInUnInitState() {
650*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
651*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
652*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
653*b7c941bbSAndroid Build Coastguard Worker     bool isAsync = true;
654*b7c941bbSAndroid Build Coastguard Worker     // setCallBack in async mode
655*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(mAsyncHandle.setCallBack(mCodec, isAsync),
656*b7c941bbSAndroid Build Coastguard Worker                    "AMediaCodec_setAsyncNotifyCallback fails in uninitialized state")
657*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
658*b7c941bbSAndroid Build Coastguard Worker     // configure component in sync mode
659*b7c941bbSAndroid Build Coastguard Worker     if (!reConfigureCodec(mFormat, !isAsync, false, isEncoder)) return false;
660*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
661*b7c941bbSAndroid Build Coastguard Worker     if (!queueEOS()) return false;
662*b7c941bbSAndroid Build Coastguard Worker     if (!waitForAllOutputs()) return false;
663*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
664*b7c941bbSAndroid Build Coastguard Worker 
665*b7c941bbSAndroid Build Coastguard Worker     // setCallBack in async mode
666*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(mAsyncHandle.setCallBack(mCodec, isAsync),
667*b7c941bbSAndroid Build Coastguard Worker                    "AMediaCodec_setAsyncNotifyCallback fails in stopped state")
668*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
669*b7c941bbSAndroid Build Coastguard Worker     // configure component in sync mode
670*b7c941bbSAndroid Build Coastguard Worker     if (!reConfigureCodec(mFormat, !isAsync, false, isEncoder)) return false;
671*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
672*b7c941bbSAndroid Build Coastguard Worker     if (!queueEOS()) return false;
673*b7c941bbSAndroid Build Coastguard Worker     if (!waitForAllOutputs()) return false;
674*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
675*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
676*b7c941bbSAndroid Build Coastguard Worker }
677*b7c941bbSAndroid Build Coastguard Worker 
testGetInputBufferInInitState()678*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputBufferInInitState() {
679*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
680*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
681*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
682*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
683*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
684*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
685*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
686*b7c941bbSAndroid Build Coastguard Worker         uint8_t* buf = AMediaCodec_getInputBuffer(mCodec, 0, &bufSize);
687*b7c941bbSAndroid Build Coastguard Worker         if (buf != nullptr) {
688*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer succeeds in initialized state");
689*b7c941bbSAndroid Build Coastguard Worker             return false;
690*b7c941bbSAndroid Build Coastguard Worker         }
691*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
692*b7c941bbSAndroid Build Coastguard Worker     }
693*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
694*b7c941bbSAndroid Build Coastguard Worker }
695*b7c941bbSAndroid Build Coastguard Worker 
testGetInputBufferInRunningState()696*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputBufferInRunningState() {
697*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
698*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
699*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
700*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
701*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
702*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
703*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
704*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
705*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getInputBuffer(mCodec, -1, &bufSize) != nullptr) {
706*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer succeeds for bad buffer index -1");
707*b7c941bbSAndroid Build Coastguard Worker             return false;
708*b7c941bbSAndroid Build Coastguard Worker         }
709*b7c941bbSAndroid Build Coastguard Worker         int bufferIndex = mIsCodecInAsyncMode ? mAsyncHandle.getInput().bufferIndex
710*b7c941bbSAndroid Build Coastguard Worker                                               : AMediaCodec_dequeueInputBuffer(mCodec, -1);
711*b7c941bbSAndroid Build Coastguard Worker         uint8_t* buf = AMediaCodec_getInputBuffer(mCodec, bufferIndex, &bufSize);
712*b7c941bbSAndroid Build Coastguard Worker         if (buf == nullptr) {
713*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer fails for valid index");
714*b7c941bbSAndroid Build Coastguard Worker             return false;
715*b7c941bbSAndroid Build Coastguard Worker         }
716*b7c941bbSAndroid Build Coastguard Worker         if (!enqueueEOS(bufferIndex)) return false;
717*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
718*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
719*b7c941bbSAndroid Build Coastguard Worker     }
720*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
721*b7c941bbSAndroid Build Coastguard Worker }
722*b7c941bbSAndroid Build Coastguard Worker 
testGetInputBufferInUnInitState()723*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputBufferInUnInitState() {
724*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
725*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
726*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
727*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
728*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
729*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
730*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getInputBuffer(mCodec, 0, &bufSize) != nullptr) {
731*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer succeeds in uninitialized state");
732*b7c941bbSAndroid Build Coastguard Worker             return false;
733*b7c941bbSAndroid Build Coastguard Worker         }
734*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
735*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
736*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
737*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getInputBuffer(mCodec, 0, &bufSize) != nullptr) {
738*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer succeeds in stopped state");
739*b7c941bbSAndroid Build Coastguard Worker             return false;
740*b7c941bbSAndroid Build Coastguard Worker         }
741*b7c941bbSAndroid Build Coastguard Worker     }
742*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
743*b7c941bbSAndroid Build Coastguard Worker }
744*b7c941bbSAndroid Build Coastguard Worker 
testGetInputFormatInInitState()745*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputFormatInInitState() {
746*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
747*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = false;
748*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
749*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
750*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
751*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
752*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
753*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
754*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getInputFormat(mCodec);
755*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
756*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
757*b7c941bbSAndroid Build Coastguard Worker         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
758*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
759*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputFormat fails in initialized state");
760*b7c941bbSAndroid Build Coastguard Worker             return false;
761*b7c941bbSAndroid Build Coastguard Worker         }
762*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
763*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
764*b7c941bbSAndroid Build Coastguard Worker     }
765*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
766*b7c941bbSAndroid Build Coastguard Worker }
767*b7c941bbSAndroid Build Coastguard Worker 
testGetInputFormatInRunningState()768*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputFormatInRunningState() {
769*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
770*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = false;
771*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
772*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
773*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
774*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
775*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
776*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
777*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
778*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getInputFormat(mCodec);
779*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
780*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
781*b7c941bbSAndroid Build Coastguard Worker         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
782*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
783*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputFormat fails in running state");
784*b7c941bbSAndroid Build Coastguard Worker             return false;
785*b7c941bbSAndroid Build Coastguard Worker         }
786*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
787*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
788*b7c941bbSAndroid Build Coastguard Worker     }
789*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
790*b7c941bbSAndroid Build Coastguard Worker }
791*b7c941bbSAndroid Build Coastguard Worker 
testGetInputFormatInUnInitState()792*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetInputFormatInUnInitState() {
793*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
794*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
795*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
796*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
797*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
798*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
799*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
800*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getInputFormat(mCodec);
801*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
802*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
803*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
804*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
805*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputFormat succeeds in uninitialized state");
806*b7c941bbSAndroid Build Coastguard Worker             return false;
807*b7c941bbSAndroid Build Coastguard Worker         }
808*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
809*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
810*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
811*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
812*b7c941bbSAndroid Build Coastguard Worker         dupFormat = AMediaCodec_getInputFormat(mCodec);
813*b7c941bbSAndroid Build Coastguard Worker         dupMediaType = nullptr;
814*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
815*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
816*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
817*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputFormat succeeds in stopped state");
818*b7c941bbSAndroid Build Coastguard Worker             return false;
819*b7c941bbSAndroid Build Coastguard Worker         }
820*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
821*b7c941bbSAndroid Build Coastguard Worker     }
822*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
823*b7c941bbSAndroid Build Coastguard Worker }
824*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputBufferInInitState()825*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputBufferInInitState() {
826*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
827*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
828*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
829*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
830*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
831*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
832*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
833*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getOutputBuffer(mCodec, 0, &bufSize) != nullptr) {
834*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetOutputBuffer succeeds in initialized state");
835*b7c941bbSAndroid Build Coastguard Worker             return false;
836*b7c941bbSAndroid Build Coastguard Worker         }
837*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
838*b7c941bbSAndroid Build Coastguard Worker     }
839*b7c941bbSAndroid Build Coastguard Worker     return true;
840*b7c941bbSAndroid Build Coastguard Worker }
841*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputBufferInRunningState()842*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputBufferInRunningState() {
843*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
844*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
845*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
846*b7c941bbSAndroid Build Coastguard Worker     AMediaCodecBufferInfo outInfo;
847*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
848*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
849*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
850*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
851*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
852*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getOutputBuffer(mCodec, -1, &bufSize)) {
853*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetOutputBuffer succeeds for bad buffer index -1");
854*b7c941bbSAndroid Build Coastguard Worker             return false;
855*b7c941bbSAndroid Build Coastguard Worker         }
856*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
857*b7c941bbSAndroid Build Coastguard Worker         bool isOk = true;
858*b7c941bbSAndroid Build Coastguard Worker         if (!hasSeenError()) {
859*b7c941bbSAndroid Build Coastguard Worker             int bufferIndex = 0;
860*b7c941bbSAndroid Build Coastguard Worker             size_t buffSize;
861*b7c941bbSAndroid Build Coastguard Worker             while (!mSawOutputEOS && isOk) {
862*b7c941bbSAndroid Build Coastguard Worker                 if (mIsCodecInAsyncMode) {
863*b7c941bbSAndroid Build Coastguard Worker                     callbackObject element = mAsyncHandle.getOutput();
864*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = element.bufferIndex;
865*b7c941bbSAndroid Build Coastguard Worker                     if (element.bufferIndex >= 0) {
866*b7c941bbSAndroid Build Coastguard Worker                         if (!AMediaCodec_getOutputBuffer(mCodec, bufferIndex, &buffSize)) {
867*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetOutputBuffer fails for valid buffer index");
868*b7c941bbSAndroid Build Coastguard Worker                             return false;
869*b7c941bbSAndroid Build Coastguard Worker                         }
870*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(element.bufferIndex, &element.bufferInfo);
871*b7c941bbSAndroid Build Coastguard Worker                     }
872*b7c941bbSAndroid Build Coastguard Worker                 } else {
873*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs);
874*b7c941bbSAndroid Build Coastguard Worker                     if (bufferIndex >= 0) {
875*b7c941bbSAndroid Build Coastguard Worker                         if (!AMediaCodec_getOutputBuffer(mCodec, bufferIndex, &buffSize)) {
876*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetOutputBuffer fails for valid buffer index");
877*b7c941bbSAndroid Build Coastguard Worker                             return false;
878*b7c941bbSAndroid Build Coastguard Worker                         }
879*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(bufferIndex, &outInfo);
880*b7c941bbSAndroid Build Coastguard Worker                     }
881*b7c941bbSAndroid Build Coastguard Worker                 }
882*b7c941bbSAndroid Build Coastguard Worker                 if (hasSeenError() || !isOk) {
883*b7c941bbSAndroid Build Coastguard Worker                     ALOGE("Got unexpected error");
884*b7c941bbSAndroid Build Coastguard Worker                     return false;
885*b7c941bbSAndroid Build Coastguard Worker                 }
886*b7c941bbSAndroid Build Coastguard Worker             }
887*b7c941bbSAndroid Build Coastguard Worker             if (AMediaCodec_getOutputBuffer(mCodec, bufferIndex, &bufSize) != nullptr) {
888*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("getOutputBuffer succeeds for buffer index not owned by client");
889*b7c941bbSAndroid Build Coastguard Worker                 return false;
890*b7c941bbSAndroid Build Coastguard Worker             }
891*b7c941bbSAndroid Build Coastguard Worker         } else {
892*b7c941bbSAndroid Build Coastguard Worker             ALOGE("Got unexpected error");
893*b7c941bbSAndroid Build Coastguard Worker             return false;
894*b7c941bbSAndroid Build Coastguard Worker         }
895*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
896*b7c941bbSAndroid Build Coastguard Worker     }
897*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
898*b7c941bbSAndroid Build Coastguard Worker }
899*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputBufferInUnInitState()900*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputBufferInUnInitState() {
901*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
902*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
903*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
904*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
905*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
906*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
907*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getOutputBuffer(mCodec, 0, &bufSize) != nullptr) {
908*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetOutputBuffer succeeds in uninitialized state");
909*b7c941bbSAndroid Build Coastguard Worker             return false;
910*b7c941bbSAndroid Build Coastguard Worker         }
911*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
912*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
913*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
914*b7c941bbSAndroid Build Coastguard Worker         if (AMediaCodec_getOutputBuffer(mCodec, 0, &bufSize) != nullptr) {
915*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetOutputBuffer succeeds in stopped state");
916*b7c941bbSAndroid Build Coastguard Worker             return false;
917*b7c941bbSAndroid Build Coastguard Worker         }
918*b7c941bbSAndroid Build Coastguard Worker     }
919*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
920*b7c941bbSAndroid Build Coastguard Worker }
921*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputFormatInInitState()922*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputFormatInInitState() {
923*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
924*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
925*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
926*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
927*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
928*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
929*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
930*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
931*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getOutputFormat(mCodec);
932*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
933*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
934*b7c941bbSAndroid Build Coastguard Worker         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
935*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
936*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getOutputFormat fails in initialized state");
937*b7c941bbSAndroid Build Coastguard Worker             return false;
938*b7c941bbSAndroid Build Coastguard Worker         }
939*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
940*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
941*b7c941bbSAndroid Build Coastguard Worker     }
942*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
943*b7c941bbSAndroid Build Coastguard Worker }
944*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputFormatInRunningState()945*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputFormatInRunningState() {
946*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
947*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
948*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
949*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
950*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
951*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
952*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
953*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
954*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
955*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getOutputFormat(mCodec);
956*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
957*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
958*b7c941bbSAndroid Build Coastguard Worker         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
959*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
960*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getOutputFormat fails in running state");
961*b7c941bbSAndroid Build Coastguard Worker             return false;
962*b7c941bbSAndroid Build Coastguard Worker         }
963*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
964*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
965*b7c941bbSAndroid Build Coastguard Worker     }
966*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
967*b7c941bbSAndroid Build Coastguard Worker }
968*b7c941bbSAndroid Build Coastguard Worker 
testGetOutputFormatInUnInitState()969*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetOutputFormatInUnInitState() {
970*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
971*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
972*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
973*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
974*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
975*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getOutputFormat(mCodec);
976*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
977*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
978*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
979*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
980*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getOutputFormat succeeds in uninitialized state");
981*b7c941bbSAndroid Build Coastguard Worker             return false;
982*b7c941bbSAndroid Build Coastguard Worker         }
983*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
984*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
985*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
986*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
987*b7c941bbSAndroid Build Coastguard Worker         dupFormat = AMediaCodec_getOutputFormat(mCodec);
988*b7c941bbSAndroid Build Coastguard Worker         dupMediaType = nullptr;
989*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
990*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
991*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
992*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getOutputFormat succeeds in stopped state");
993*b7c941bbSAndroid Build Coastguard Worker             return false;
994*b7c941bbSAndroid Build Coastguard Worker         }
995*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
996*b7c941bbSAndroid Build Coastguard Worker     }
997*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
998*b7c941bbSAndroid Build Coastguard Worker }
999*b7c941bbSAndroid Build Coastguard Worker 
testSetParametersInInitState()1000*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetParametersInInitState() {
1001*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = false;
1002*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1003*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1004*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1005*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1006*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1007*b7c941bbSAndroid Build Coastguard Worker         int bitrate;
1008*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getInt32(mFormat, AMEDIAFORMAT_KEY_BIT_RATE, &bitrate);
1009*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* params = AMediaFormat_new();
1010*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_setInt32(params, TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE, bitrate >> 1);
1011*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_setParameters(mCodec, params)) {
1012*b7c941bbSAndroid Build Coastguard Worker             ALOGE("SetParameters succeeds in initialized state");
1013*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(params);
1014*b7c941bbSAndroid Build Coastguard Worker             return false;
1015*b7c941bbSAndroid Build Coastguard Worker         }
1016*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(params);
1017*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1018*b7c941bbSAndroid Build Coastguard Worker     }
1019*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1020*b7c941bbSAndroid Build Coastguard Worker }
1021*b7c941bbSAndroid Build Coastguard Worker 
testSetParametersInRunningState()1022*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetParametersInRunningState() {
1023*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = false;
1024*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1025*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1026*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1027*b7c941bbSAndroid Build Coastguard Worker     int bitrate;
1028*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getInt32(mFormat, AMEDIAFORMAT_KEY_BIT_RATE, &bitrate);
1029*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1030*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1031*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1032*b7c941bbSAndroid Build Coastguard Worker         // behaviour of setParams with null argument is acceptable according to SDK
1033*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_setParameters(mCodec, nullptr);
1034*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* params = AMediaFormat_new();
1035*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_setInt32(params, TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE, bitrate >> 1);
1036*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_setParameters(mCodec, params)) {
1037*b7c941bbSAndroid Build Coastguard Worker             ALOGE("SetParameters fails in running state");
1038*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(params);
1039*b7c941bbSAndroid Build Coastguard Worker             return false;
1040*b7c941bbSAndroid Build Coastguard Worker         }
1041*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
1042*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_setParameters(mCodec, nullptr);
1043*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_setInt32(mFormat, TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE, bitrate << 1);
1044*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_setParameters(mCodec, mFormat)) {
1045*b7c941bbSAndroid Build Coastguard Worker             ALOGE("SetParameters fails in running state");
1046*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(params);
1047*b7c941bbSAndroid Build Coastguard Worker             return false;
1048*b7c941bbSAndroid Build Coastguard Worker         }
1049*b7c941bbSAndroid Build Coastguard Worker         if (!waitForAllOutputs()) return false;
1050*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_setParameters(mCodec, nullptr);
1051*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_setInt32(mFormat, TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE, bitrate);
1052*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK != AMediaCodec_setParameters(mCodec, mFormat)) {
1053*b7c941bbSAndroid Build Coastguard Worker             ALOGE("SetParameters fails in running state");
1054*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(params);
1055*b7c941bbSAndroid Build Coastguard Worker             return false;
1056*b7c941bbSAndroid Build Coastguard Worker         }
1057*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(params);
1058*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1059*b7c941bbSAndroid Build Coastguard Worker     }
1060*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1061*b7c941bbSAndroid Build Coastguard Worker }
1062*b7c941bbSAndroid Build Coastguard Worker 
testSetParametersInUnInitState()1063*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testSetParametersInUnInitState() {
1064*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = false;
1065*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1066*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1067*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1068*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1069*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1070*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1071*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1072*b7c941bbSAndroid Build Coastguard Worker         int bitrate;
1073*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getInt32(mFormat, AMEDIAFORMAT_KEY_BIT_RATE, &bitrate);
1074*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* params = AMediaFormat_new();
1075*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_setInt32(params, TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE, bitrate >> 1);
1076*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_setParameters(mCodec, params)) {
1077*b7c941bbSAndroid Build Coastguard Worker             ALOGE("SetParameters succeeds in stopped state");
1078*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(params);
1079*b7c941bbSAndroid Build Coastguard Worker             return false;
1080*b7c941bbSAndroid Build Coastguard Worker         }
1081*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(params);
1082*b7c941bbSAndroid Build Coastguard Worker     }
1083*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1084*b7c941bbSAndroid Build Coastguard Worker }
1085*b7c941bbSAndroid Build Coastguard Worker 
testStartInRunningState()1086*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testStartInRunningState() {
1087*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1088*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1089*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1090*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, false, false, isEncoder)) return false;
1091*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1092*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK == AMediaCodec_start(mCodec)) {
1093*b7c941bbSAndroid Build Coastguard Worker         ALOGE("Start succeeds in running state");
1094*b7c941bbSAndroid Build Coastguard Worker         return false;
1095*b7c941bbSAndroid Build Coastguard Worker     }
1096*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1097*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1098*b7c941bbSAndroid Build Coastguard Worker }
1099*b7c941bbSAndroid Build Coastguard Worker 
testStartInUnInitState()1100*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testStartInUnInitState() {
1101*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1102*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1103*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1104*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK == AMediaCodec_start(mCodec)) {
1105*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec start succeeds before initialization");
1106*b7c941bbSAndroid Build Coastguard Worker         return false;
1107*b7c941bbSAndroid Build Coastguard Worker     }
1108*b7c941bbSAndroid Build Coastguard Worker     if (!configureCodec(mFormat, false, false, isEncoder)) return false;
1109*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1110*b7c941bbSAndroid Build Coastguard Worker     RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1111*b7c941bbSAndroid Build Coastguard Worker     if (AMEDIA_OK == AMediaCodec_start(mCodec)) {
1112*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec start succeeds in stopped state");
1113*b7c941bbSAndroid Build Coastguard Worker         return false;
1114*b7c941bbSAndroid Build Coastguard Worker     }
1115*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1116*b7c941bbSAndroid Build Coastguard Worker }
1117*b7c941bbSAndroid Build Coastguard Worker 
testStopInInitState()1118*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testStopInInitState() {
1119*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1120*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1121*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1122*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1123*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1124*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1125*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "Stop fails in initialized state")
1126*b7c941bbSAndroid Build Coastguard Worker     }
1127*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1128*b7c941bbSAndroid Build Coastguard Worker }
1129*b7c941bbSAndroid Build Coastguard Worker 
testStopInRunningState()1130*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testStopInRunningState() {
1131*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1132*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1133*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1134*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1135*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1136*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1137*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1138*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
1139*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "Stop fails in running state")
1140*b7c941bbSAndroid Build Coastguard Worker     }
1141*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1142*b7c941bbSAndroid Build Coastguard Worker }
1143*b7c941bbSAndroid Build Coastguard Worker 
testStopInUnInitState()1144*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testStopInUnInitState() {
1145*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1146*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1147*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1148*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1149*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1150*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1151*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1152*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1153*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "Stop fails in stopped state")
1154*b7c941bbSAndroid Build Coastguard Worker     }
1155*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1156*b7c941bbSAndroid Build Coastguard Worker }
1157*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferInInitState()1158*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferInInitState() {
1159*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1160*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1161*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1162*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1163*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1164*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1165*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
1166*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_queueInputBuffer(mCodec, 0, 0, 0, 0,
1167*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1168*b7c941bbSAndroid Build Coastguard Worker             ALOGE("queueInputBuffer succeeds in initialized state");
1169*b7c941bbSAndroid Build Coastguard Worker             return false;
1170*b7c941bbSAndroid Build Coastguard Worker         }
1171*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1172*b7c941bbSAndroid Build Coastguard Worker     }
1173*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1174*b7c941bbSAndroid Build Coastguard Worker }
1175*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferWithBadIndex()1176*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferWithBadIndex() {
1177*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1178*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1179*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1180*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1181*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1182*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1183*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1184*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
1185*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_queueInputBuffer(mCodec, -1, 0, 0, 0,
1186*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1187*b7c941bbSAndroid Build Coastguard Worker             ALOGE("queueInputBuffer succeeds with bad buffer index :: -1");
1188*b7c941bbSAndroid Build Coastguard Worker             return false;
1189*b7c941bbSAndroid Build Coastguard Worker         }
1190*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1191*b7c941bbSAndroid Build Coastguard Worker     }
1192*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1193*b7c941bbSAndroid Build Coastguard Worker }
1194*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferWithBadSize()1195*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferWithBadSize() {
1196*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1197*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1198*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1199*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1200*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1201*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1202*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1203*b7c941bbSAndroid Build Coastguard Worker         int bufferIndex = mIsCodecInAsyncMode ? mAsyncHandle.getInput().bufferIndex
1204*b7c941bbSAndroid Build Coastguard Worker                                               : AMediaCodec_dequeueInputBuffer(mCodec, -1);
1205*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
1206*b7c941bbSAndroid Build Coastguard Worker         uint8_t* buf = AMediaCodec_getInputBuffer(mCodec, bufferIndex, &bufSize);
1207*b7c941bbSAndroid Build Coastguard Worker         if (buf == nullptr) {
1208*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer fails for valid index");
1209*b7c941bbSAndroid Build Coastguard Worker             return false;
1210*b7c941bbSAndroid Build Coastguard Worker         } else {
1211*b7c941bbSAndroid Build Coastguard Worker             if (AMEDIA_OK ==
1212*b7c941bbSAndroid Build Coastguard Worker                 AMediaCodec_queueInputBuffer(mCodec, 0, 0, bufSize + 100, 0,
1213*b7c941bbSAndroid Build Coastguard Worker                                              AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1214*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("queueInputBuffer succeeds for bad size %zu, buffer capacity %zu ",
1215*b7c941bbSAndroid Build Coastguard Worker                       bufSize + 100, bufSize);
1216*b7c941bbSAndroid Build Coastguard Worker                 return false;
1217*b7c941bbSAndroid Build Coastguard Worker             }
1218*b7c941bbSAndroid Build Coastguard Worker         }
1219*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1220*b7c941bbSAndroid Build Coastguard Worker     }
1221*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1222*b7c941bbSAndroid Build Coastguard Worker }
1223*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferWithBadBuffInfo()1224*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferWithBadBuffInfo() {
1225*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1226*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1227*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1228*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1229*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1230*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1231*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1232*b7c941bbSAndroid Build Coastguard Worker         int bufferIndex = mIsCodecInAsyncMode ? mAsyncHandle.getInput().bufferIndex
1233*b7c941bbSAndroid Build Coastguard Worker                                               : AMediaCodec_dequeueInputBuffer(mCodec, -1);
1234*b7c941bbSAndroid Build Coastguard Worker         size_t bufSize;
1235*b7c941bbSAndroid Build Coastguard Worker         uint8_t* buf = AMediaCodec_getInputBuffer(mCodec, bufferIndex, &bufSize);
1236*b7c941bbSAndroid Build Coastguard Worker         if (buf == nullptr) {
1237*b7c941bbSAndroid Build Coastguard Worker             ALOGE("getInputBuffer fails for valid index");
1238*b7c941bbSAndroid Build Coastguard Worker             return false;
1239*b7c941bbSAndroid Build Coastguard Worker         } else {
1240*b7c941bbSAndroid Build Coastguard Worker             if (AMEDIA_OK ==
1241*b7c941bbSAndroid Build Coastguard Worker                 AMediaCodec_queueInputBuffer(mCodec, 0, 16, bufSize, 0,
1242*b7c941bbSAndroid Build Coastguard Worker                                              AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1243*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("queueInputBuffer succeeds with bad offset and size param");
1244*b7c941bbSAndroid Build Coastguard Worker                 return false;
1245*b7c941bbSAndroid Build Coastguard Worker             }
1246*b7c941bbSAndroid Build Coastguard Worker         }
1247*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1248*b7c941bbSAndroid Build Coastguard Worker     }
1249*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1250*b7c941bbSAndroid Build Coastguard Worker }
1251*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferWithBadOffset()1252*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferWithBadOffset() {
1253*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1254*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1255*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1256*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1257*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1258*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1259*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1260*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
1261*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_queueInputBuffer(mCodec, 0, -1, 0, 0,
1262*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1263*b7c941bbSAndroid Build Coastguard Worker             ALOGE("queueInputBuffer succeeds with bad buffer offset :: -1");
1264*b7c941bbSAndroid Build Coastguard Worker             return false;
1265*b7c941bbSAndroid Build Coastguard Worker         }
1266*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1267*b7c941bbSAndroid Build Coastguard Worker     }
1268*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1269*b7c941bbSAndroid Build Coastguard Worker }
1270*b7c941bbSAndroid Build Coastguard Worker 
testQueueInputBufferInUnInitState()1271*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testQueueInputBufferInUnInitState() {
1272*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1273*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1274*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1275*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1276*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1277*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
1278*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_queueInputBuffer(mCodec, 0, 0, 0, 0,
1279*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1280*b7c941bbSAndroid Build Coastguard Worker             ALOGE("queueInputBuffer succeeds in uninitialized state");
1281*b7c941bbSAndroid Build Coastguard Worker             return false;
1282*b7c941bbSAndroid Build Coastguard Worker         }
1283*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1284*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1285*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1286*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK ==
1287*b7c941bbSAndroid Build Coastguard Worker             AMediaCodec_queueInputBuffer(mCodec, 0, 0, 0, 0,
1288*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)) {
1289*b7c941bbSAndroid Build Coastguard Worker             ALOGE("queueInputBuffer succeeds in stopped state");
1290*b7c941bbSAndroid Build Coastguard Worker             return false;
1291*b7c941bbSAndroid Build Coastguard Worker         }
1292*b7c941bbSAndroid Build Coastguard Worker     }
1293*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1294*b7c941bbSAndroid Build Coastguard Worker }
1295*b7c941bbSAndroid Build Coastguard Worker 
testReleaseOutputBufferInInitState()1296*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testReleaseOutputBufferInInitState() {
1297*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1298*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1299*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1300*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1301*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1302*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1303*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_releaseOutputBuffer(mCodec, 0, false)) {
1304*b7c941bbSAndroid Build Coastguard Worker             ALOGE("ReleaseOutputBuffer succeeds in initialized state");
1305*b7c941bbSAndroid Build Coastguard Worker             return false;
1306*b7c941bbSAndroid Build Coastguard Worker         }
1307*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1308*b7c941bbSAndroid Build Coastguard Worker     }
1309*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1310*b7c941bbSAndroid Build Coastguard Worker }
1311*b7c941bbSAndroid Build Coastguard Worker 
testReleaseOutputBufferInRunningState()1312*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testReleaseOutputBufferInRunningState() {
1313*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1314*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1315*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1316*b7c941bbSAndroid Build Coastguard Worker     AMediaCodecBufferInfo outInfo;
1317*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1318*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1319*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1320*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1321*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_releaseOutputBuffer(mCodec, -1, false)) {
1322*b7c941bbSAndroid Build Coastguard Worker             ALOGE("ReleaseOutputBuffer succeeds for bad buffer index -1");
1323*b7c941bbSAndroid Build Coastguard Worker             return false;
1324*b7c941bbSAndroid Build Coastguard Worker         }
1325*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
1326*b7c941bbSAndroid Build Coastguard Worker         if (!hasSeenError()) {
1327*b7c941bbSAndroid Build Coastguard Worker             int bufferIndex = 0;
1328*b7c941bbSAndroid Build Coastguard Worker             size_t buffSize;
1329*b7c941bbSAndroid Build Coastguard Worker             bool isOk = true;
1330*b7c941bbSAndroid Build Coastguard Worker             while (!mSawOutputEOS && isOk) {
1331*b7c941bbSAndroid Build Coastguard Worker                 if (mIsCodecInAsyncMode) {
1332*b7c941bbSAndroid Build Coastguard Worker                     callbackObject element = mAsyncHandle.getOutput();
1333*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = element.bufferIndex;
1334*b7c941bbSAndroid Build Coastguard Worker                     if (element.bufferIndex >= 0) {
1335*b7c941bbSAndroid Build Coastguard Worker                         if (!AMediaCodec_getOutputBuffer(mCodec, bufferIndex, &buffSize)) {
1336*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetOutputBuffer fails for valid buffer index");
1337*b7c941bbSAndroid Build Coastguard Worker                             return false;
1338*b7c941bbSAndroid Build Coastguard Worker                         }
1339*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(element.bufferIndex, &element.bufferInfo);
1340*b7c941bbSAndroid Build Coastguard Worker                     }
1341*b7c941bbSAndroid Build Coastguard Worker                 } else {
1342*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs);
1343*b7c941bbSAndroid Build Coastguard Worker                     if (bufferIndex >= 0) {
1344*b7c941bbSAndroid Build Coastguard Worker                         if (!AMediaCodec_getOutputBuffer(mCodec, bufferIndex, &buffSize)) {
1345*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetOutputBuffer fails for valid buffer index");
1346*b7c941bbSAndroid Build Coastguard Worker                             return false;
1347*b7c941bbSAndroid Build Coastguard Worker                         }
1348*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(bufferIndex, &outInfo);
1349*b7c941bbSAndroid Build Coastguard Worker                     }
1350*b7c941bbSAndroid Build Coastguard Worker                 }
1351*b7c941bbSAndroid Build Coastguard Worker                 if (hasSeenError() || !isOk) {
1352*b7c941bbSAndroid Build Coastguard Worker                     ALOGE("Got unexpected error");
1353*b7c941bbSAndroid Build Coastguard Worker                     return false;
1354*b7c941bbSAndroid Build Coastguard Worker                 }
1355*b7c941bbSAndroid Build Coastguard Worker             }
1356*b7c941bbSAndroid Build Coastguard Worker             if (AMEDIA_OK == AMediaCodec_releaseOutputBuffer(mCodec, bufferIndex, false)) {
1357*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("ReleaseOutputBuffer succeeds for buffer index not owned by client");
1358*b7c941bbSAndroid Build Coastguard Worker                 return false;
1359*b7c941bbSAndroid Build Coastguard Worker             }
1360*b7c941bbSAndroid Build Coastguard Worker         } else {
1361*b7c941bbSAndroid Build Coastguard Worker             ALOGE("Got unexpected error");
1362*b7c941bbSAndroid Build Coastguard Worker             return false;
1363*b7c941bbSAndroid Build Coastguard Worker         }
1364*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1365*b7c941bbSAndroid Build Coastguard Worker     }
1366*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1367*b7c941bbSAndroid Build Coastguard Worker }
1368*b7c941bbSAndroid Build Coastguard Worker 
testReleaseOutputBufferInUnInitState()1369*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testReleaseOutputBufferInUnInitState() {
1370*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1371*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1372*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1373*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1374*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1375*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_releaseOutputBuffer(mCodec, 0, false)) {
1376*b7c941bbSAndroid Build Coastguard Worker             ALOGE("ReleaseOutputBuffer succeeds in uninitialized state");
1377*b7c941bbSAndroid Build Coastguard Worker             return false;
1378*b7c941bbSAndroid Build Coastguard Worker         }
1379*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1380*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1381*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1382*b7c941bbSAndroid Build Coastguard Worker         if (AMEDIA_OK == AMediaCodec_releaseOutputBuffer(mCodec, 0, false)) {
1383*b7c941bbSAndroid Build Coastguard Worker             ALOGE("ReleaseOutputBuffer succeeds in stopped state");
1384*b7c941bbSAndroid Build Coastguard Worker             return false;
1385*b7c941bbSAndroid Build Coastguard Worker         }
1386*b7c941bbSAndroid Build Coastguard Worker     }
1387*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1388*b7c941bbSAndroid Build Coastguard Worker }
1389*b7c941bbSAndroid Build Coastguard Worker 
testGetBufferFormatInInitState()1390*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetBufferFormatInInitState() {
1391*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1392*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1393*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1394*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1395*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1396*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1397*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getBufferFormat(mCodec, 0);
1398*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
1399*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1400*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
1401*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
1402*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetBufferFormat succeeds in initialized state");
1403*b7c941bbSAndroid Build Coastguard Worker             return false;
1404*b7c941bbSAndroid Build Coastguard Worker         }
1405*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
1406*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1407*b7c941bbSAndroid Build Coastguard Worker     }
1408*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1409*b7c941bbSAndroid Build Coastguard Worker }
1410*b7c941bbSAndroid Build Coastguard Worker 
testGetBufferFormatInRunningState()1411*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetBufferFormatInRunningState() {
1412*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1413*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1414*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1415*b7c941bbSAndroid Build Coastguard Worker     const char* mediaType = nullptr;
1416*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_getString(mFormat, AMEDIAFORMAT_KEY_MIME, &mediaType);
1417*b7c941bbSAndroid Build Coastguard Worker     AMediaCodecBufferInfo outInfo;
1418*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1419*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1420*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1421*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1422*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getBufferFormat(mCodec, -1);
1423*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
1424*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1425*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
1426*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
1427*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetBufferFormat succeeds for bad buffer index -1");
1428*b7c941bbSAndroid Build Coastguard Worker             return false;
1429*b7c941bbSAndroid Build Coastguard Worker         }
1430*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
1431*b7c941bbSAndroid Build Coastguard Worker         if (!queueEOS()) return false;
1432*b7c941bbSAndroid Build Coastguard Worker         if (!hasSeenError()) {
1433*b7c941bbSAndroid Build Coastguard Worker             int bufferIndex = 0;
1434*b7c941bbSAndroid Build Coastguard Worker             bool isOk = true;
1435*b7c941bbSAndroid Build Coastguard Worker             while (!mSawOutputEOS && isOk) {
1436*b7c941bbSAndroid Build Coastguard Worker                 if (mIsCodecInAsyncMode) {
1437*b7c941bbSAndroid Build Coastguard Worker                     callbackObject element = mAsyncHandle.getOutput();
1438*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = element.bufferIndex;
1439*b7c941bbSAndroid Build Coastguard Worker                     if (element.bufferIndex >= 0) {
1440*b7c941bbSAndroid Build Coastguard Worker                         dupFormat = AMediaCodec_getBufferFormat(mCodec, bufferIndex);
1441*b7c941bbSAndroid Build Coastguard Worker                         dupMediaType = nullptr;
1442*b7c941bbSAndroid Build Coastguard Worker                         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1443*b7c941bbSAndroid Build Coastguard Worker                         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
1444*b7c941bbSAndroid Build Coastguard Worker                             AMediaFormat_delete(dupFormat);
1445*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetBufferFormat fails in running state");
1446*b7c941bbSAndroid Build Coastguard Worker                             return false;
1447*b7c941bbSAndroid Build Coastguard Worker                         }
1448*b7c941bbSAndroid Build Coastguard Worker                         AMediaFormat_delete(dupFormat);
1449*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(element.bufferIndex, &element.bufferInfo);
1450*b7c941bbSAndroid Build Coastguard Worker                     }
1451*b7c941bbSAndroid Build Coastguard Worker                 } else {
1452*b7c941bbSAndroid Build Coastguard Worker                     bufferIndex = AMediaCodec_dequeueOutputBuffer(mCodec, &outInfo, kQDeQTimeOutUs);
1453*b7c941bbSAndroid Build Coastguard Worker                     if (bufferIndex >= 0) {
1454*b7c941bbSAndroid Build Coastguard Worker                         dupFormat = AMediaCodec_getBufferFormat(mCodec, bufferIndex);
1455*b7c941bbSAndroid Build Coastguard Worker                         dupMediaType = nullptr;
1456*b7c941bbSAndroid Build Coastguard Worker                         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1457*b7c941bbSAndroid Build Coastguard Worker                         if (!dupMediaType || strcmp(dupMediaType, mediaType) != 0) {
1458*b7c941bbSAndroid Build Coastguard Worker                             AMediaFormat_delete(dupFormat);
1459*b7c941bbSAndroid Build Coastguard Worker                             ALOGE("GetBufferFormat fails in running state");
1460*b7c941bbSAndroid Build Coastguard Worker                             return false;
1461*b7c941bbSAndroid Build Coastguard Worker                         }
1462*b7c941bbSAndroid Build Coastguard Worker                         AMediaFormat_delete(dupFormat);
1463*b7c941bbSAndroid Build Coastguard Worker                         isOk = dequeueOutput(bufferIndex, &outInfo);
1464*b7c941bbSAndroid Build Coastguard Worker                     }
1465*b7c941bbSAndroid Build Coastguard Worker                 }
1466*b7c941bbSAndroid Build Coastguard Worker                 if (hasSeenError() || !isOk) {
1467*b7c941bbSAndroid Build Coastguard Worker                     ALOGE("Got unexpected error");
1468*b7c941bbSAndroid Build Coastguard Worker                     return false;
1469*b7c941bbSAndroid Build Coastguard Worker                 }
1470*b7c941bbSAndroid Build Coastguard Worker             }
1471*b7c941bbSAndroid Build Coastguard Worker             dupFormat = AMediaCodec_getBufferFormat(mCodec, bufferIndex);
1472*b7c941bbSAndroid Build Coastguard Worker             dupMediaType = nullptr;
1473*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1474*b7c941bbSAndroid Build Coastguard Worker             if (dupMediaType) {
1475*b7c941bbSAndroid Build Coastguard Worker                 AMediaFormat_delete(dupFormat);
1476*b7c941bbSAndroid Build Coastguard Worker                 ALOGE("GetBufferFormat succeeds for buffer index not owned by client");
1477*b7c941bbSAndroid Build Coastguard Worker                 return false;
1478*b7c941bbSAndroid Build Coastguard Worker             }
1479*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
1480*b7c941bbSAndroid Build Coastguard Worker         } else {
1481*b7c941bbSAndroid Build Coastguard Worker             ALOGE("Got unexpected error");
1482*b7c941bbSAndroid Build Coastguard Worker             return false;
1483*b7c941bbSAndroid Build Coastguard Worker         }
1484*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1485*b7c941bbSAndroid Build Coastguard Worker     }
1486*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1487*b7c941bbSAndroid Build Coastguard Worker }
1488*b7c941bbSAndroid Build Coastguard Worker 
testGetBufferFormatInUnInitState()1489*b7c941bbSAndroid Build Coastguard Worker bool NativeCodecUnitTest::testGetBufferFormatInUnInitState() {
1490*b7c941bbSAndroid Build Coastguard Worker     bool isAudio = true;
1491*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1492*b7c941bbSAndroid Build Coastguard Worker     if (!setupCodec(isAudio, isEncoder)) return false;
1493*b7c941bbSAndroid Build Coastguard Worker     const bool boolStates[]{true, false};
1494*b7c941bbSAndroid Build Coastguard Worker     for (auto isAsync : boolStates) {
1495*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat* dupFormat = AMediaCodec_getBufferFormat(mCodec, 0);
1496*b7c941bbSAndroid Build Coastguard Worker         const char* dupMediaType = nullptr;
1497*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1498*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
1499*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
1500*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetBufferFormat succeeds in uninitialized state");
1501*b7c941bbSAndroid Build Coastguard Worker             return false;
1502*b7c941bbSAndroid Build Coastguard Worker         }
1503*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
1504*b7c941bbSAndroid Build Coastguard Worker         if (!configureCodec(mFormat, isAsync, false, isEncoder)) return false;
1505*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_start(mCodec), "AMediaCodec_start failed")
1506*b7c941bbSAndroid Build Coastguard Worker         RETURN_IF_FAIL(AMediaCodec_stop(mCodec), "AMediaCodec_stop failed")
1507*b7c941bbSAndroid Build Coastguard Worker         dupFormat = AMediaCodec_getBufferFormat(mCodec, 0);
1508*b7c941bbSAndroid Build Coastguard Worker         dupMediaType = nullptr;
1509*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_getString(dupFormat, AMEDIAFORMAT_KEY_MIME, &dupMediaType);
1510*b7c941bbSAndroid Build Coastguard Worker         if (dupMediaType) {
1511*b7c941bbSAndroid Build Coastguard Worker             AMediaFormat_delete(dupFormat);
1512*b7c941bbSAndroid Build Coastguard Worker             ALOGE("GetBufferFormat succeeds in stopped state");
1513*b7c941bbSAndroid Build Coastguard Worker             return false;
1514*b7c941bbSAndroid Build Coastguard Worker         }
1515*b7c941bbSAndroid Build Coastguard Worker         AMediaFormat_delete(dupFormat);
1516*b7c941bbSAndroid Build Coastguard Worker     }
1517*b7c941bbSAndroid Build Coastguard Worker     return !hasSeenError();
1518*b7c941bbSAndroid Build Coastguard Worker }
1519*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateByCodecNameForNull(JNIEnv *,jobject)1520*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateByCodecNameForNull(JNIEnv*, jobject) {
1521*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1522*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createCodecByName(nullptr);
1523*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1524*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1525*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createCodecByName succeeds with null argument");
1526*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1527*b7c941bbSAndroid Build Coastguard Worker     }
1528*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1529*b7c941bbSAndroid Build Coastguard Worker }
1530*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateByCodecNameForInvalidName(JNIEnv *,jobject)1531*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateByCodecNameForInvalidName(JNIEnv*, jobject) {
1532*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1533*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createCodecByName("invalid name");
1534*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1535*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1536*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createCodecByName succeeds with invalid name");
1537*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1538*b7c941bbSAndroid Build Coastguard Worker     }
1539*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1540*b7c941bbSAndroid Build Coastguard Worker }
1541*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateDecoderByTypeForNull(JNIEnv *,jobject)1542*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateDecoderByTypeForNull(JNIEnv*, jobject) {
1543*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1544*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createDecoderByType(nullptr);
1545*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1546*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1547*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createDecoderByType succeeds with null argument");
1548*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1549*b7c941bbSAndroid Build Coastguard Worker     }
1550*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1551*b7c941bbSAndroid Build Coastguard Worker }
1552*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateDecoderByTypeForInvalidMediaType(JNIEnv *,jobject)1553*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateDecoderByTypeForInvalidMediaType(JNIEnv*, jobject) {
1554*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1555*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createDecoderByType("invalid name");
1556*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1557*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1558*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createDecoderByType succeeds with invalid name");
1559*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1560*b7c941bbSAndroid Build Coastguard Worker     }
1561*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1562*b7c941bbSAndroid Build Coastguard Worker }
1563*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateEncoderByTypeForNull(JNIEnv *,jobject)1564*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateEncoderByTypeForNull(JNIEnv*, jobject) {
1565*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1566*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createEncoderByType(nullptr);
1567*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1568*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1569*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createEncoderByType succeeds with null argument");
1570*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1571*b7c941bbSAndroid Build Coastguard Worker     }
1572*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1573*b7c941bbSAndroid Build Coastguard Worker }
1574*b7c941bbSAndroid Build Coastguard Worker 
nativeTestCreateEncoderByTypeForInvalidMediaType(JNIEnv *,jobject)1575*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestCreateEncoderByTypeForInvalidMediaType(JNIEnv*, jobject) {
1576*b7c941bbSAndroid Build Coastguard Worker     bool isPass = true;
1577*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createEncoderByType("invalid name");
1578*b7c941bbSAndroid Build Coastguard Worker     if (codec) {
1579*b7c941bbSAndroid Build Coastguard Worker         AMediaCodec_delete(codec);
1580*b7c941bbSAndroid Build Coastguard Worker         ALOGE("AMediaCodec_createEncoderByType succeeds with invalid name");
1581*b7c941bbSAndroid Build Coastguard Worker         isPass = false;
1582*b7c941bbSAndroid Build Coastguard Worker     }
1583*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1584*b7c941bbSAndroid Build Coastguard Worker }
1585*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureForNullFormat(JNIEnv *,jobject)1586*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureForNullFormat(JNIEnv*, jobject) {
1587*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createEncoderByType(AMEDIA_MIMETYPE_AUDIO_AAC);
1588*b7c941bbSAndroid Build Coastguard Worker     if (!codec) {
1589*b7c941bbSAndroid Build Coastguard Worker         ALOGE("unable to create codec %s", AMEDIA_MIMETYPE_AUDIO_AAC);
1590*b7c941bbSAndroid Build Coastguard Worker         return static_cast<jboolean>(false);
1591*b7c941bbSAndroid Build Coastguard Worker     }
1592*b7c941bbSAndroid Build Coastguard Worker     bool isPass = (AMEDIA_OK !=
1593*b7c941bbSAndroid Build Coastguard Worker                    AMediaCodec_configure(codec, nullptr, nullptr, nullptr,
1594*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_CONFIGURE_FLAG_ENCODE));
1595*b7c941bbSAndroid Build Coastguard Worker     if (!isPass) {
1596*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec configure succeeds with null format");
1597*b7c941bbSAndroid Build Coastguard Worker     }
1598*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec_delete(codec);
1599*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1600*b7c941bbSAndroid Build Coastguard Worker }
1601*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureForEmptyFormat(JNIEnv *,jobject)1602*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureForEmptyFormat(JNIEnv*, jobject) {
1603*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec* codec = AMediaCodec_createEncoderByType(AMEDIA_MIMETYPE_AUDIO_AAC);
1604*b7c941bbSAndroid Build Coastguard Worker     if (!codec) {
1605*b7c941bbSAndroid Build Coastguard Worker         ALOGE("unable to create codec %s", AMEDIA_MIMETYPE_AUDIO_AAC);
1606*b7c941bbSAndroid Build Coastguard Worker         return static_cast<jboolean>(false);
1607*b7c941bbSAndroid Build Coastguard Worker     }
1608*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat* format = AMediaFormat_new();
1609*b7c941bbSAndroid Build Coastguard Worker     bool isPass = (AMEDIA_OK !=
1610*b7c941bbSAndroid Build Coastguard Worker                    AMediaCodec_configure(codec, format, nullptr, nullptr,
1611*b7c941bbSAndroid Build Coastguard Worker                                          AMEDIACODEC_CONFIGURE_FLAG_ENCODE));
1612*b7c941bbSAndroid Build Coastguard Worker     if (!isPass) {
1613*b7c941bbSAndroid Build Coastguard Worker         ALOGE("codec configure succeeds with empty format");
1614*b7c941bbSAndroid Build Coastguard Worker     }
1615*b7c941bbSAndroid Build Coastguard Worker     AMediaFormat_delete(format);
1616*b7c941bbSAndroid Build Coastguard Worker     AMediaCodec_delete(codec);
1617*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1618*b7c941bbSAndroid Build Coastguard Worker }
1619*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureCodecForIncompleteFormat(JNIEnv *,jobject,jboolean isAudio,jboolean isEncoder)1620*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureCodecForIncompleteFormat(JNIEnv*, jobject, jboolean isAudio,
1621*b7c941bbSAndroid Build Coastguard Worker                                                             jboolean isEncoder) {
1622*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1623*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureCodecForIncompleteFormat(isAudio, isEncoder);
1624*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1625*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1626*b7c941bbSAndroid Build Coastguard Worker }
1627*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureEncoderForBadFlags(JNIEnv *,jobject)1628*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureEncoderForBadFlags(JNIEnv*, jobject) {
1629*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1630*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = true;
1631*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureCodecForBadFlags(isEncoder);
1632*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1633*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1634*b7c941bbSAndroid Build Coastguard Worker }
1635*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureDecoderForBadFlags(JNIEnv *,jobject)1636*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureDecoderForBadFlags(JNIEnv*, jobject) {
1637*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1638*b7c941bbSAndroid Build Coastguard Worker     bool isEncoder = false;
1639*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureCodecForBadFlags(isEncoder);
1640*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1641*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1642*b7c941bbSAndroid Build Coastguard Worker }
1643*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureInInitState(JNIEnv *,jobject)1644*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureInInitState(JNIEnv*, jobject) {
1645*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1646*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureInInitState();
1647*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1648*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1649*b7c941bbSAndroid Build Coastguard Worker }
1650*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureInRunningState(JNIEnv *,jobject)1651*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureInRunningState(JNIEnv*, jobject) {
1652*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1653*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureInRunningState();
1654*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1655*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1656*b7c941bbSAndroid Build Coastguard Worker }
1657*b7c941bbSAndroid Build Coastguard Worker 
nativeTestConfigureInUnInitState(JNIEnv *,jobject)1658*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestConfigureInUnInitState(JNIEnv*, jobject) {
1659*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1660*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testConfigureInUnInitState();
1661*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1662*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1663*b7c941bbSAndroid Build Coastguard Worker }
1664*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueInputBufferInInitState(JNIEnv *,jobject)1665*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueInputBufferInInitState(JNIEnv*, jobject) {
1666*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1667*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueInputBufferInInitState();
1668*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1669*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1670*b7c941bbSAndroid Build Coastguard Worker }
1671*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueInputBufferInRunningState(JNIEnv *,jobject)1672*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueInputBufferInRunningState(JNIEnv*, jobject) {
1673*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1674*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueInputBufferInRunningState();
1675*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1676*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1677*b7c941bbSAndroid Build Coastguard Worker }
1678*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueInputBufferInUnInitState(JNIEnv *,jobject)1679*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueInputBufferInUnInitState(JNIEnv*, jobject) {
1680*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1681*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueInputBufferInUnInitState();
1682*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1683*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1684*b7c941bbSAndroid Build Coastguard Worker }
1685*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueOutputBufferInInitState(JNIEnv *,jobject)1686*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueOutputBufferInInitState(JNIEnv*, jobject) {
1687*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1688*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueOutputBufferInInitState();
1689*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1690*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1691*b7c941bbSAndroid Build Coastguard Worker }
1692*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueOutputBufferInRunningState(JNIEnv *,jobject)1693*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueOutputBufferInRunningState(JNIEnv*, jobject) {
1694*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1695*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueOutputBufferInRunningState();
1696*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1697*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1698*b7c941bbSAndroid Build Coastguard Worker }
1699*b7c941bbSAndroid Build Coastguard Worker 
nativeTestDequeueOutputBufferInUnInitState(JNIEnv *,jobject)1700*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestDequeueOutputBufferInUnInitState(JNIEnv*, jobject) {
1701*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1702*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testDequeueOutputBufferInUnInitState();
1703*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1704*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1705*b7c941bbSAndroid Build Coastguard Worker }
1706*b7c941bbSAndroid Build Coastguard Worker 
nativeTestFlushInInitState(JNIEnv *,jobject)1707*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestFlushInInitState(JNIEnv*, jobject) {
1708*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1709*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testFlushInInitState();
1710*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1711*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1712*b7c941bbSAndroid Build Coastguard Worker }
1713*b7c941bbSAndroid Build Coastguard Worker 
nativeTestFlushInRunningState(JNIEnv *,jobject)1714*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestFlushInRunningState(JNIEnv*, jobject) {
1715*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1716*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testFlushInRunningState();
1717*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1718*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1719*b7c941bbSAndroid Build Coastguard Worker }
1720*b7c941bbSAndroid Build Coastguard Worker 
nativeTestFlushInUnInitState(JNIEnv *,jobject)1721*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestFlushInUnInitState(JNIEnv*, jobject) {
1722*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1723*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testFlushInUnInitState();
1724*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1725*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1726*b7c941bbSAndroid Build Coastguard Worker }
1727*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetNameInInitState(JNIEnv *,jobject)1728*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetNameInInitState(JNIEnv*, jobject) {
1729*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1730*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetNameInInitState();
1731*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1732*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1733*b7c941bbSAndroid Build Coastguard Worker }
1734*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetNameInRunningState(JNIEnv *,jobject)1735*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetNameInRunningState(JNIEnv*, jobject) {
1736*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1737*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetNameInRunningState();
1738*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1739*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1740*b7c941bbSAndroid Build Coastguard Worker }
1741*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetNameInUnInitState(JNIEnv *,jobject)1742*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetNameInUnInitState(JNIEnv*, jobject) {
1743*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1744*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetNameInUnInitState();
1745*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1746*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1747*b7c941bbSAndroid Build Coastguard Worker }
1748*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetAsyncNotifyCallbackInInitState(JNIEnv *,jobject)1749*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetAsyncNotifyCallbackInInitState(JNIEnv*, jobject) {
1750*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1751*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetAsyncNotifyCallbackInInitState();
1752*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1753*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1754*b7c941bbSAndroid Build Coastguard Worker }
1755*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetAsyncNotifyCallbackInRunningState(JNIEnv *,jobject)1756*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetAsyncNotifyCallbackInRunningState(JNIEnv*, jobject) {
1757*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1758*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetAsyncNotifyCallbackInRunningState();
1759*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1760*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1761*b7c941bbSAndroid Build Coastguard Worker }
1762*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetAsyncNotifyCallbackInUnInitState(JNIEnv *,jobject)1763*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetAsyncNotifyCallbackInUnInitState(JNIEnv*, jobject) {
1764*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1765*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetAsyncNotifyCallbackInUnInitState();
1766*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1767*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1768*b7c941bbSAndroid Build Coastguard Worker }
1769*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputBufferInInitState(JNIEnv *,jobject)1770*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputBufferInInitState(JNIEnv*, jobject) {
1771*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1772*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputBufferInInitState();
1773*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1774*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1775*b7c941bbSAndroid Build Coastguard Worker }
1776*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputBufferInRunningState(JNIEnv *,jobject)1777*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputBufferInRunningState(JNIEnv*, jobject) {
1778*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1779*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputBufferInRunningState();
1780*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1781*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1782*b7c941bbSAndroid Build Coastguard Worker }
1783*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputBufferInUnInitState(JNIEnv *,jobject)1784*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputBufferInUnInitState(JNIEnv*, jobject) {
1785*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1786*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputBufferInUnInitState();
1787*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1788*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1789*b7c941bbSAndroid Build Coastguard Worker }
1790*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputFormatInInitState(JNIEnv *,jobject)1791*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputFormatInInitState(JNIEnv*, jobject) {
1792*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1793*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputFormatInInitState();
1794*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1795*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1796*b7c941bbSAndroid Build Coastguard Worker }
1797*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputFormatInRunningState(JNIEnv *,jobject)1798*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputFormatInRunningState(JNIEnv*, jobject) {
1799*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1800*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputFormatInRunningState();
1801*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1802*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1803*b7c941bbSAndroid Build Coastguard Worker }
1804*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetInputFormatInUnInitState(JNIEnv *,jobject)1805*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetInputFormatInUnInitState(JNIEnv*, jobject) {
1806*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1807*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetInputFormatInUnInitState();
1808*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1809*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1810*b7c941bbSAndroid Build Coastguard Worker }
1811*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputBufferInInitState(JNIEnv *,jobject)1812*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputBufferInInitState(JNIEnv*, jobject) {
1813*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1814*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputBufferInInitState();
1815*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1816*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1817*b7c941bbSAndroid Build Coastguard Worker }
1818*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputBufferInRunningState(JNIEnv *,jobject)1819*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputBufferInRunningState(JNIEnv*, jobject) {
1820*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1821*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputBufferInRunningState();
1822*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1823*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1824*b7c941bbSAndroid Build Coastguard Worker }
1825*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputBufferInUnInitState(JNIEnv *,jobject)1826*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputBufferInUnInitState(JNIEnv*, jobject) {
1827*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1828*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputBufferInUnInitState();
1829*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1830*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1831*b7c941bbSAndroid Build Coastguard Worker }
1832*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputFormatInInitState(JNIEnv *,jobject)1833*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputFormatInInitState(JNIEnv*, jobject) {
1834*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1835*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputFormatInInitState();
1836*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1837*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1838*b7c941bbSAndroid Build Coastguard Worker }
1839*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputFormatInRunningState(JNIEnv *,jobject)1840*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputFormatInRunningState(JNIEnv*, jobject) {
1841*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1842*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputFormatInRunningState();
1843*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1844*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1845*b7c941bbSAndroid Build Coastguard Worker }
1846*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetOutputFormatInUnInitState(JNIEnv *,jobject)1847*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetOutputFormatInUnInitState(JNIEnv*, jobject) {
1848*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1849*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetOutputFormatInUnInitState();
1850*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1851*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1852*b7c941bbSAndroid Build Coastguard Worker }
1853*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetParametersInInitState(JNIEnv *,jobject)1854*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetParametersInInitState(JNIEnv*, jobject) {
1855*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1856*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetParametersInInitState();
1857*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1858*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1859*b7c941bbSAndroid Build Coastguard Worker }
1860*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetParametersInRunningState(JNIEnv *,jobject)1861*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetParametersInRunningState(JNIEnv*, jobject) {
1862*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1863*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetParametersInRunningState();
1864*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1865*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1866*b7c941bbSAndroid Build Coastguard Worker }
1867*b7c941bbSAndroid Build Coastguard Worker 
nativeTestSetParametersInUnInitState(JNIEnv *,jobject)1868*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestSetParametersInUnInitState(JNIEnv*, jobject) {
1869*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1870*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testSetParametersInUnInitState();
1871*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1872*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1873*b7c941bbSAndroid Build Coastguard Worker }
1874*b7c941bbSAndroid Build Coastguard Worker 
nativeTestStartInRunningState(JNIEnv *,jobject)1875*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestStartInRunningState(JNIEnv*, jobject) {
1876*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1877*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testStartInRunningState();
1878*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1879*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1880*b7c941bbSAndroid Build Coastguard Worker }
1881*b7c941bbSAndroid Build Coastguard Worker 
nativeTestStartInUnInitState(JNIEnv *,jobject)1882*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestStartInUnInitState(JNIEnv*, jobject) {
1883*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1884*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testStartInUnInitState();
1885*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1886*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1887*b7c941bbSAndroid Build Coastguard Worker }
1888*b7c941bbSAndroid Build Coastguard Worker 
nativeTestStopInInitState(JNIEnv *,jobject)1889*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestStopInInitState(JNIEnv*, jobject) {
1890*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1891*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testStopInInitState();
1892*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1893*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1894*b7c941bbSAndroid Build Coastguard Worker }
1895*b7c941bbSAndroid Build Coastguard Worker 
nativeTestStopInRunningState(JNIEnv *,jobject)1896*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestStopInRunningState(JNIEnv*, jobject) {
1897*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1898*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testStopInRunningState();
1899*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1900*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1901*b7c941bbSAndroid Build Coastguard Worker }
1902*b7c941bbSAndroid Build Coastguard Worker 
nativeTestStopInUnInitState(JNIEnv *,jobject)1903*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestStopInUnInitState(JNIEnv*, jobject) {
1904*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1905*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testStopInUnInitState();
1906*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1907*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1908*b7c941bbSAndroid Build Coastguard Worker }
1909*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferInInitState(JNIEnv *,jobject)1910*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferInInitState(JNIEnv*, jobject) {
1911*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1912*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferInInitState();
1913*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1914*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1915*b7c941bbSAndroid Build Coastguard Worker }
1916*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferWithBadIndex(JNIEnv *,jobject)1917*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferWithBadIndex(JNIEnv*, jobject) {
1918*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1919*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferWithBadIndex();
1920*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1921*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1922*b7c941bbSAndroid Build Coastguard Worker }
1923*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferWithBadSize(JNIEnv *,jobject)1924*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferWithBadSize(JNIEnv*, jobject) {
1925*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1926*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferWithBadSize();
1927*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1928*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1929*b7c941bbSAndroid Build Coastguard Worker }
1930*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferWithBadBuffInfo(JNIEnv *,jobject)1931*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferWithBadBuffInfo(JNIEnv*, jobject) {
1932*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1933*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferWithBadBuffInfo();
1934*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1935*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1936*b7c941bbSAndroid Build Coastguard Worker }
1937*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferWithBadOffset(JNIEnv *,jobject)1938*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferWithBadOffset(JNIEnv*, jobject) {
1939*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1940*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferWithBadOffset();
1941*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1942*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1943*b7c941bbSAndroid Build Coastguard Worker }
1944*b7c941bbSAndroid Build Coastguard Worker 
nativeTestQueueInputBufferInUnInitState(JNIEnv *,jobject)1945*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestQueueInputBufferInUnInitState(JNIEnv*, jobject) {
1946*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1947*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testQueueInputBufferInUnInitState();
1948*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1949*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1950*b7c941bbSAndroid Build Coastguard Worker }
1951*b7c941bbSAndroid Build Coastguard Worker 
nativeTestReleaseOutputBufferInInitState(JNIEnv *,jobject)1952*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestReleaseOutputBufferInInitState(JNIEnv*, jobject) {
1953*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1954*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testReleaseOutputBufferInInitState();
1955*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1956*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1957*b7c941bbSAndroid Build Coastguard Worker }
1958*b7c941bbSAndroid Build Coastguard Worker 
nativeTestReleaseOutputBufferInRunningState(JNIEnv *,jobject)1959*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestReleaseOutputBufferInRunningState(JNIEnv*, jobject) {
1960*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1961*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testReleaseOutputBufferInRunningState();
1962*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1963*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1964*b7c941bbSAndroid Build Coastguard Worker }
1965*b7c941bbSAndroid Build Coastguard Worker 
nativeTestReleaseOutputBufferInUnInitState(JNIEnv *,jobject)1966*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestReleaseOutputBufferInUnInitState(JNIEnv*, jobject) {
1967*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1968*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testReleaseOutputBufferInUnInitState();
1969*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1970*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1971*b7c941bbSAndroid Build Coastguard Worker }
1972*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetBufferFormatInInitState(JNIEnv *,jobject)1973*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetBufferFormatInInitState(JNIEnv*, jobject) {
1974*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1975*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetBufferFormatInInitState();
1976*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1977*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1978*b7c941bbSAndroid Build Coastguard Worker }
1979*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetBufferFormatInRunningState(JNIEnv *,jobject)1980*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetBufferFormatInRunningState(JNIEnv*, jobject) {
1981*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1982*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetBufferFormatInRunningState();
1983*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1984*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1985*b7c941bbSAndroid Build Coastguard Worker }
1986*b7c941bbSAndroid Build Coastguard Worker 
nativeTestGetBufferFormatInUnInitState(JNIEnv *,jobject)1987*b7c941bbSAndroid Build Coastguard Worker static jboolean nativeTestGetBufferFormatInUnInitState(JNIEnv*, jobject) {
1988*b7c941bbSAndroid Build Coastguard Worker     auto* nativeCodecUnitTest = new NativeCodecUnitTest(AMEDIA_MIMETYPE_AUDIO_AAC);
1989*b7c941bbSAndroid Build Coastguard Worker     bool isPass = nativeCodecUnitTest->testGetBufferFormatInUnInitState();
1990*b7c941bbSAndroid Build Coastguard Worker     delete nativeCodecUnitTest;
1991*b7c941bbSAndroid Build Coastguard Worker     return static_cast<jboolean>(isPass);
1992*b7c941bbSAndroid Build Coastguard Worker }
1993*b7c941bbSAndroid Build Coastguard Worker 
registerAndroidMediaV2CtsCodecUnitTest(JNIEnv * env)1994*b7c941bbSAndroid Build Coastguard Worker int registerAndroidMediaV2CtsCodecUnitTest(JNIEnv* env) {
1995*b7c941bbSAndroid Build Coastguard Worker     const JNINativeMethod methodTable[] = {
1996*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateByCodecNameForNull", "()Z",
1997*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateByCodecNameForNull},
1998*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateByCodecNameForInvalidName", "()Z",
1999*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateByCodecNameForInvalidName},
2000*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateDecoderByTypeForNull", "()Z",
2001*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateDecoderByTypeForNull},
2002*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateDecoderByTypeForInvalidMediaType", "()Z",
2003*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateDecoderByTypeForInvalidMediaType},
2004*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateEncoderByTypeForNull", "()Z",
2005*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateEncoderByTypeForNull},
2006*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestCreateEncoderByTypeForInvalidMediaType", "()Z",
2007*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestCreateEncoderByTypeForInvalidMediaType},
2008*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureForNullFormat", "()Z", (void*)nativeTestConfigureForNullFormat},
2009*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureForEmptyFormat", "()Z", (void*)nativeTestConfigureForEmptyFormat},
2010*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureCodecForIncompleteFormat", "(ZZ)Z",
2011*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestConfigureCodecForIncompleteFormat},
2012*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureEncoderForBadFlags", "()Z",
2013*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestConfigureEncoderForBadFlags},
2014*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureDecoderForBadFlags", "()Z",
2015*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestConfigureDecoderForBadFlags},
2016*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureInInitState", "()Z", (void*)nativeTestConfigureInInitState},
2017*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureInRunningState", "()Z", (void*)nativeTestConfigureInRunningState},
2018*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestConfigureInUnInitState", "()Z", (void*)nativeTestConfigureInUnInitState},
2019*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueInputBufferInInitState", "()Z",
2020*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueInputBufferInInitState},
2021*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueInputBufferInRunningState", "()Z",
2022*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueInputBufferInRunningState},
2023*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueInputBufferInUnInitState", "()Z",
2024*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueInputBufferInUnInitState},
2025*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueOutputBufferInInitState", "()Z",
2026*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueOutputBufferInInitState},
2027*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueOutputBufferInRunningState", "()Z",
2028*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueOutputBufferInRunningState},
2029*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestDequeueOutputBufferInUnInitState", "()Z",
2030*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestDequeueOutputBufferInUnInitState},
2031*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestFlushInInitState", "()Z", (void*)nativeTestFlushInInitState},
2032*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestFlushInRunningState", "()Z", (void*)nativeTestFlushInRunningState},
2033*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestFlushInUnInitState", "()Z", (void*)nativeTestFlushInUnInitState},
2034*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetNameInInitState", "()Z", (void*)nativeTestGetNameInInitState},
2035*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetNameInRunningState", "()Z", (void*)nativeTestGetNameInRunningState},
2036*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetNameInUnInitState", "()Z", (void*)nativeTestGetNameInUnInitState},
2037*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetAsyncNotifyCallbackInInitState", "()Z",
2038*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetAsyncNotifyCallbackInInitState},
2039*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetAsyncNotifyCallbackInRunningState", "()Z",
2040*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetAsyncNotifyCallbackInRunningState},
2041*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetAsyncNotifyCallbackInUnInitState", "()Z",
2042*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetAsyncNotifyCallbackInUnInitState},
2043*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputBufferInInitState", "()Z",
2044*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputBufferInInitState},
2045*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputBufferInRunningState", "()Z",
2046*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputBufferInRunningState},
2047*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputBufferInUnInitState", "()Z",
2048*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputBufferInUnInitState},
2049*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputFormatInInitState", "()Z",
2050*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputFormatInInitState},
2051*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputFormatInRunningState", "()Z",
2052*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputFormatInRunningState},
2053*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetInputFormatInUnInitState", "()Z",
2054*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetInputFormatInUnInitState},
2055*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputBufferInInitState", "()Z",
2056*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputBufferInInitState},
2057*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputBufferInRunningState", "()Z",
2058*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputBufferInRunningState},
2059*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputBufferInUnInitState", "()Z",
2060*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputBufferInUnInitState},
2061*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputFormatInInitState", "()Z",
2062*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputFormatInInitState},
2063*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputFormatInRunningState", "()Z",
2064*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputFormatInRunningState},
2065*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetOutputFormatInUnInitState", "()Z",
2066*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetOutputFormatInUnInitState},
2067*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetParametersInInitState", "()Z",
2068*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetParametersInInitState},
2069*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetParametersInRunningState", "()Z",
2070*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetParametersInRunningState},
2071*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestSetParametersInUnInitState", "()Z",
2072*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestSetParametersInUnInitState},
2073*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestStartInRunningState", "()Z", (void*)nativeTestStartInRunningState},
2074*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestStartInUnInitState", "()Z", (void*)nativeTestStartInUnInitState},
2075*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestStopInInitState", "()Z", (void*)nativeTestStopInInitState},
2076*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestStopInRunningState", "()Z", (void*)nativeTestStopInRunningState},
2077*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestStopInUnInitState", "()Z", (void*)nativeTestStopInUnInitState},
2078*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferInInitState", "()Z",
2079*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferInInitState},
2080*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferWithBadIndex", "()Z",
2081*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferWithBadIndex},
2082*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferWithBadSize", "()Z",
2083*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferWithBadSize},
2084*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferWithBadBuffInfo", "()Z",
2085*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferWithBadBuffInfo},
2086*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferWithBadOffset", "()Z",
2087*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferWithBadOffset},
2088*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestQueueInputBufferInUnInitState", "()Z",
2089*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestQueueInputBufferInUnInitState},
2090*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestReleaseOutputBufferInInitState", "()Z",
2091*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestReleaseOutputBufferInInitState},
2092*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestReleaseOutputBufferInRunningState", "()Z",
2093*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestReleaseOutputBufferInRunningState},
2094*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestReleaseOutputBufferInUnInitState", "()Z",
2095*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestReleaseOutputBufferInUnInitState},
2096*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetBufferFormatInInitState", "()Z",
2097*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetBufferFormatInInitState},
2098*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetBufferFormatInRunningState", "()Z",
2099*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetBufferFormatInRunningState},
2100*b7c941bbSAndroid Build Coastguard Worker             {"nativeTestGetBufferFormatInUnInitState", "()Z",
2101*b7c941bbSAndroid Build Coastguard Worker              (void*)nativeTestGetBufferFormatInUnInitState},
2102*b7c941bbSAndroid Build Coastguard Worker 
2103*b7c941bbSAndroid Build Coastguard Worker     };
2104*b7c941bbSAndroid Build Coastguard Worker     jclass c = env->FindClass("android/mediav2/cts/CodecUnitTest$TestApiNative");
2105*b7c941bbSAndroid Build Coastguard Worker     return env->RegisterNatives(c, methodTable, sizeof(methodTable) / sizeof(JNINativeMethod));
2106*b7c941bbSAndroid Build Coastguard Worker }
2107*b7c941bbSAndroid Build Coastguard Worker 
JNI_OnLoad(JavaVM * vm,void *)2108*b7c941bbSAndroid Build Coastguard Worker extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
2109*b7c941bbSAndroid Build Coastguard Worker     JNIEnv* env;
2110*b7c941bbSAndroid Build Coastguard Worker     if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) return JNI_ERR;
2111*b7c941bbSAndroid Build Coastguard Worker     if (registerAndroidMediaV2CtsCodecUnitTest(env) != JNI_OK) return JNI_ERR;
2112*b7c941bbSAndroid Build Coastguard Worker     return JNI_VERSION_1_6;
2113*b7c941bbSAndroid Build Coastguard Worker }
2114