summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Li2017-11-14 14:08:38 -0600
committerXin Li2017-11-14 14:08:38 -0600
commitbb9e38fef95b7bc932ebcad18508e03228f9f7d3 (patch)
tree29e859e08879c87f591507de0f370abd1ec66fe2 /media/omx/1.0
parentb86b2d2881d53219c59a5eb85a3d73cb45942661 (diff)
parent1a06284b24f5eb7bb9c1fea0817da8898b3b1bff (diff)
downloadplatform-hardware-interfaces-bb9e38fef95b7bc932ebcad18508e03228f9f7d3.tar.gz
platform-hardware-interfaces-bb9e38fef95b7bc932ebcad18508e03228f9f7d3.tar.xz
platform-hardware-interfaces-bb9e38fef95b7bc932ebcad18508e03228f9f7d3.zip
Merge commit '1a06284b24f5eb7bb9c1fea0817da8898b3b1bff' from
oc-mr1-dev-plus-aosp into stage-aosp-master Change-Id: I2a044eb8c9981d0a8198ffe2df55559afbd76341 Merged-In: I4fb9f18884f7ef21162015a0032c4431444f7025
Diffstat (limited to 'media/omx/1.0')
-rw-r--r--media/omx/1.0/IOmxStore.hal6
-rw-r--r--media/omx/1.0/vts/functional/audio/Android.bp62
-rw-r--r--media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp372
-rw-r--r--media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp114
-rw-r--r--media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.cpp4
-rw-r--r--media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.h5
-rw-r--r--[-rwxr-xr-x]media/omx/1.0/vts/functional/common/Android.bp39
-rw-r--r--[-rwxr-xr-x]media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp263
-rw-r--r--media/omx/1.0/vts/functional/common/media_hidl_test_common.h57
-rw-r--r--media/omx/1.0/vts/functional/component/Android.bp27
-rw-r--r--media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp507
-rw-r--r--media/omx/1.0/vts/functional/master/Android.bp24
-rw-r--r--media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp7
-rw-r--r--media/omx/1.0/vts/functional/video/Android.bp69
-rw-r--r--media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp864
-rw-r--r--media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp259
-rw-r--r--media/omx/1.0/vts/functional/video/media_video_hidl_test_common.cpp1
-rw-r--r--media/omx/1.0/vts/functional/video/media_video_hidl_test_common.h6
18 files changed, 1616 insertions, 1070 deletions
diff --git a/media/omx/1.0/IOmxStore.hal b/media/omx/1.0/IOmxStore.hal
index a224b0e1..3ec05357 100644
--- a/media/omx/1.0/IOmxStore.hal
+++ b/media/omx/1.0/IOmxStore.hal
@@ -39,7 +39,7 @@ interface IOmxStore {
39 * string: arbitrary string 39 * string: arbitrary string
40 * size: <num>x<num> 40 * size: <num>x<num>
41 * ratio: <num>:<num> 41 * ratio: <num>:<num>
42 * range<type>: <type>-<type> 42 * range<type>: <type> | <type>-<type>
43 * list<type>: <type> | <type>,<list<type>> 43 * list<type>: <type> | <type>,<list<type>>
44 */ 44 */
45 struct Attribute { 45 struct Attribute {
@@ -97,7 +97,7 @@ interface IOmxStore {
97 * 97 *
98 * Required node attributes for video nodes that are required by Android to 98 * Required node attributes for video nodes that are required by Android to
99 * describe measured values for this device: 99 * describe measured values for this device:
100 * key: 'measured-frame-rate-<width>-<height>-range', 100 * key: 'measured-frame-rate-<width>x<height>-range',
101 * value-type: range<num>; where width: num, height: num 101 * value-type: range<num>; where width: num, height: num
102 * 102 *
103 * Optional node attributes for decoders to describe supported values: 103 * Optional node attributes for decoders to describe supported values:
@@ -111,7 +111,7 @@ interface IOmxStore {
111 * Optional node attributes for encoders to describe supported values: 111 * Optional node attributes for encoders to describe supported values:
112 * key: 'complexity-default', value-type: num 112 * key: 'complexity-default', value-type: num
113 * key: 'complexity-range', value-type: range<num> 113 * key: 'complexity-range', value-type: range<num>
114 * key: 'feature-bitrate-control', value-type: list<enum<VBR,CBR,CQ>> 114 * key: 'feature-bitrate-modes', value-type: list<enum<VBR,CBR,CQ>>
115 * key: 'feature-intra-refresh', value-type: enum<0,1> 115 * key: 'feature-intra-refresh', value-type: enum<0,1>
116 * key: 'quality-default', value-type: num 116 * key: 'quality-default', value-type: num
117 * key: 'quality-range', value-type: range<num> 117 * key: 'quality-range', value-type: range<num>
diff --git a/media/omx/1.0/vts/functional/audio/Android.bp b/media/omx/1.0/vts/functional/audio/Android.bp
index 66fd20be..f517fa1d 100644
--- a/media/omx/1.0/vts/functional/audio/Android.bp
+++ b/media/omx/1.0/vts/functional/audio/Android.bp
@@ -16,65 +16,19 @@
16 16
17cc_test { 17cc_test {
18 name: "VtsHalMediaOmxV1_0TargetAudioEncTest", 18 name: "VtsHalMediaOmxV1_0TargetAudioEncTest",
19 defaults: ["hidl_defaults"], 19 defaults: ["VtsHalMediaOmxV1_0Defaults"],
20 srcs: ["VtsHalMediaOmxV1_0TargetAudioEncTest.cpp", 20 srcs: [
21 "media_audio_hidl_test_common.cpp"], 21 "VtsHalMediaOmxV1_0TargetAudioEncTest.cpp",
22 shared_libs: [ 22 "media_audio_hidl_test_common.cpp"
23 "libbase",
24 "liblog",
25 "libcutils",
26 "libhidlbase",
27 "libhidlmemory",
28 "libhidltransport",
29 "libhwbinder",
30 "libnativehelper",
31 "libutils",
32 "libstagefright_foundation",
33 "android.hidl.allocator@1.0",
34 "android.hidl.memory@1.0",
35 "android.hardware.media.omx@1.0",
36 ],
37 static_libs: ["VtsHalHidlTargetTestBase",
38 "VtsHalMediaOmxV1_0CommonUtil"],
39 cflags: [
40 "-O0",
41 "-g",
42 ],
43 include_dirs: [
44 "frameworks/native/include/media/openmax/",
45 "hardware/interfaces/media/omx/1.0/vts/functional/common",
46 ], 23 ],
47} 24}
48 25
49cc_test { 26cc_test {
50 name: "VtsHalMediaOmxV1_0TargetAudioDecTest", 27 name: "VtsHalMediaOmxV1_0TargetAudioDecTest",
51 defaults: ["hidl_defaults"], 28 defaults: ["VtsHalMediaOmxV1_0Defaults"],
52 srcs: ["VtsHalMediaOmxV1_0TargetAudioDecTest.cpp", 29 srcs: [
53 "media_audio_hidl_test_common.cpp"], 30 "VtsHalMediaOmxV1_0TargetAudioDecTest.cpp",
54 shared_libs: [ 31 "media_audio_hidl_test_common.cpp"
55 "libbase",
56 "liblog",
57 "libcutils",
58 "libhidlbase",
59 "libhidlmemory",
60 "libhidltransport",
61 "libhwbinder",
62 "libnativehelper",
63 "libutils",
64 "libstagefright_foundation",
65 "android.hidl.allocator@1.0",
66 "android.hidl.memory@1.0",
67 "android.hardware.media.omx@1.0",
68 ],
69 static_libs: ["VtsHalHidlTargetTestBase",
70 "VtsHalMediaOmxV1_0CommonUtil"],
71 cflags: [
72 "-O0",
73 "-g",
74 ],
75 include_dirs: [
76 "frameworks/native/include/media/openmax/",
77 "hardware/interfaces/media/omx/1.0/vts/functional/common",
78 ], 32 ],
79} 33}
80 34
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
index 336cab48..38cdcd65 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
@@ -15,6 +15,10 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_audio_dec_test" 17#define LOG_TAG "media_omx_hidl_audio_dec_test"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
@@ -161,6 +165,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
161 this->omxNode = _nl; 165 this->omxNode = _nl;
162 }) 166 })
163 .isOk()); 167 .isOk());
168 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
164 ASSERT_NE(omxNode, nullptr); 169 ASSERT_NE(omxNode, nullptr);
165 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role"; 170 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role";
166 struct StringToName { 171 struct StringToName {
@@ -171,7 +176,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
171 {"mp3", mp3}, {"amrnb", amrnb}, {"amrwb", amrwb}, 176 {"mp3", mp3}, {"amrnb", amrnb}, {"amrwb", amrwb},
172 {"aac", aac}, {"vorbis", vorbis}, {"opus", opus}, 177 {"aac", aac}, {"vorbis", vorbis}, {"opus", opus},
173 {"pcm", pcm}, {"g711alaw", g711alaw}, {"g711mlaw", g711mlaw}, 178 {"pcm", pcm}, {"g711alaw", g711alaw}, {"g711mlaw", g711mlaw},
174 {"gsm", gsm}, {"raw", raw}, 179 {"gsm", gsm}, {"raw", raw}, {"flac", flac},
175 }; 180 };
176 const size_t kNumStringToName = 181 const size_t kNumStringToName =
177 sizeof(kStringToName) / sizeof(kStringToName[0]); 182 sizeof(kStringToName) / sizeof(kStringToName[0]);
@@ -204,6 +209,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
204 {g711mlaw, OMX_AUDIO_CodingG711}, 209 {g711mlaw, OMX_AUDIO_CodingG711},
205 {gsm, OMX_AUDIO_CodingGSMFR}, 210 {gsm, OMX_AUDIO_CodingGSMFR},
206 {raw, OMX_AUDIO_CodingPCM}, 211 {raw, OMX_AUDIO_CodingPCM},
212 {flac, OMX_AUDIO_CodingFLAC},
207 }; 213 };
208 static const size_t kNumCompToCoding = 214 static const size_t kNumCompToCoding =
209 sizeof(kCompToCoding) / sizeof(kCompToCoding[0]); 215 sizeof(kCompToCoding) / sizeof(kCompToCoding[0]);
@@ -219,11 +225,15 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
219 framesReceived = 0; 225 framesReceived = 0;
220 timestampUs = 0; 226 timestampUs = 0;
221 timestampDevTest = false; 227 timestampDevTest = false;
222 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 228 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
223 } 229 }
224 230
225 virtual void TearDown() override { 231 virtual void TearDown() override {
226 if (omxNode != nullptr) { 232 if (omxNode != nullptr) {
233 // If you have encountered a fatal failure, it is possible that
234 // freeNode() will not go through. Instead of hanging the app.
235 // let it pass through and report errors
236 if (::testing::Test::HasFatalFailure()) return;
227 EXPECT_TRUE((omxNode->freeNode()).isOk()); 237 EXPECT_TRUE((omxNode->freeNode()).isOk());
228 omxNode = nullptr; 238 omxNode = nullptr;
229 } 239 }
@@ -263,9 +273,8 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
263 EXPECT_EQ(tsHit, true) 273 EXPECT_EQ(tsHit, true)
264 << "TimeStamp not recognized"; 274 << "TimeStamp not recognized";
265 } else { 275 } else {
266 std::cerr 276 std::cout << "[ INFO ] Received non-zero "
267 << "[ ] Warning ! Received non-zero " 277 "output / TimeStamp not recognized \n";
268 "output / TimeStamp not recognized \n";
269 } 278 }
270 } 279 }
271 } 280 }
@@ -301,6 +310,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
301 g711mlaw, 310 g711mlaw,
302 gsm, 311 gsm,
303 raw, 312 raw,
313 flac,
304 unknown_comp, 314 unknown_comp,
305 }; 315 };
306 316
@@ -418,6 +428,9 @@ void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
418 ASSERT_EQ(status, 428 ASSERT_EQ(status,
419 ::android::hardware::media::omx::V1_0::Status::OK); 429 ::android::hardware::media::omx::V1_0::Status::OK);
420 *nChannels = param.nChannels; 430 *nChannels = param.nChannels;
431 // NOTE: For amrnb sample rate is 8k and amrwb sample rate is 16k.
432 // There is no nSampleRate field in OMX_AUDIO_PARAM_AMRTYPE. Just
433 // return 8k to avoid returning uninit variable.
421 *nSampleRate = 8000; 434 *nSampleRate = 8000;
422 break; 435 break;
423 } 436 }
@@ -431,6 +444,16 @@ void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
431 *nSampleRate = param.nSampleRate; 444 *nSampleRate = param.nSampleRate;
432 break; 445 break;
433 } 446 }
447 case OMX_AUDIO_CodingFLAC: {
448 OMX_AUDIO_PARAM_FLACTYPE param;
449 status = getPortParam(omxNode, OMX_IndexParamAudioFlac,
450 kPortIndexInput, &param);
451 ASSERT_EQ(status,
452 ::android::hardware::media::omx::V1_0::Status::OK);
453 *nChannels = param.nChannels;
454 *nSampleRate = param.nSampleRate;
455 break;
456 }
434 default: 457 default:
435 ASSERT_TRUE(false); 458 ASSERT_TRUE(false);
436 break; 459 break;
@@ -472,6 +495,9 @@ void GetURLForComponent(AudioDecHidlTest::standardComp comp, char* mURL,
472 "bbb_gsm_1ch_8khz_13kbps.info"}, 495 "bbb_gsm_1ch_8khz_13kbps.info"},
473 {AudioDecHidlTest::standardComp::raw, "bbb_raw_1ch_8khz_s32le.raw", 496 {AudioDecHidlTest::standardComp::raw, "bbb_raw_1ch_8khz_s32le.raw",
474 "bbb_raw_1ch_8khz_s32le.info"}, 497 "bbb_raw_1ch_8khz_s32le.info"},
498 {AudioDecHidlTest::standardComp::flac,
499 "bbb_flac_stereo_680kbps_48000hz.flac",
500 "bbb_flac_stereo_680kbps_48000hz.info"},
475 }; 501 };
476 502
477 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) { 503 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
@@ -530,13 +556,13 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
530 // set Port Params 556 // set Port Params
531 int32_t nChannels; 557 int32_t nChannels;
532 int32_t nSampleRate; 558 int32_t nSampleRate;
533 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 559 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
534 &nSampleRate); 560 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
535 // Configure output port 561 // Configure output port
536 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way 562 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way
537 // to 563 // to configure output PCM port. The port undergoes auto
538 // configure output PCM port. The port undergoes auto configuration 564 // configuration internally basing on parsed elementary stream
539 // internally basing on parsed elementary stream information. 565 // information.
540 if (comp != AudioDecHidlTest::standardComp::vorbis && 566 if (comp != AudioDecHidlTest::standardComp::vorbis &&
541 comp != AudioDecHidlTest::standardComp::opus && 567 comp != AudioDecHidlTest::standardComp::opus &&
542 comp != AudioDecHidlTest::standardComp::raw) { 568 comp != AudioDecHidlTest::standardComp::raw) {
@@ -545,9 +571,8 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
545 nSampleRate); 571 nSampleRate);
546 } 572 }
547 573
548 // If you can disable a port, then you should be able to 574 // If you can disable a port, then you should be able to enable it
549 // enable 575 // as well
550 // it as well
551 status = omxNode->sendCommand( 576 status = omxNode->sendCommand(
552 toRawCommandType(OMX_CommandPortEnable), kPortIndexOutput); 577 toRawCommandType(OMX_CommandPortEnable), kPortIndexOutput);
553 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); 578 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
@@ -558,7 +583,8 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
558 ASSERT_EQ(status, 583 ASSERT_EQ(status,
559 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 584 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
560 585
561 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput); 586 ASSERT_NO_FATAL_FAILURE(
587 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput));
562 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, 588 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer,
563 oBuffer); 589 oBuffer);
564 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); 590 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
@@ -568,14 +594,14 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
568 594
569 // dispatch output buffers 595 // dispatch output buffers
570 for (size_t i = 0; i < oBuffer->size(); i++) { 596 for (size_t i = 0; i < oBuffer->size(); i++) {
571 dispatchOutputBuffer(omxNode, oBuffer, i); 597 ASSERT_NO_FATAL_FAILURE(
598 dispatchOutputBuffer(omxNode, oBuffer, i));
572 } 599 }
573 } else { 600 } else {
574 ASSERT_TRUE(false); 601 ASSERT_TRUE(false);
575 } 602 }
576 } else { 603 } else {
577 EXPECT_TRUE(false); 604 ASSERT_TRUE(false);
578 return;
579 } 605 }
580} 606}
581 607
@@ -588,18 +614,19 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
588 AudioDecHidlTest::standardComp comp) { 614 AudioDecHidlTest::standardComp comp) {
589 android::hardware::media::omx::V1_0::Status status; 615 android::hardware::media::omx::V1_0::Status status;
590 Message msg; 616 Message msg;
591 int timeOut = TIMEOUT_COUNTER; 617 int timeOut = TIMEOUT_COUNTER_Q;
592 618
593 while (timeOut--) { 619 while (timeOut--) {
594 size_t i = 0; 620 size_t i = 0;
595 status = 621 status =
596 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 622 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
597 if (status == android::hardware::media::omx::V1_0::Status::OK) { 623 if (status == android::hardware::media::omx::V1_0::Status::OK) {
598 EXPECT_EQ(msg.type, Message::Type::EVENT); 624 ASSERT_EQ(msg.type, Message::Type::EVENT);
599 packedArgs audioArgs = {eEncoding, comp}; 625 packedArgs audioArgs = {eEncoding, comp};
600 portReconfiguration(omxNode, observer, iBuffer, oBuffer, 626 ASSERT_NO_FATAL_FAILURE(
601 kPortIndexInput, kPortIndexOutput, msg, 627 portReconfiguration(omxNode, observer, iBuffer, oBuffer,
602 PortMode::PRESET_BYTE_BUFFER, &audioArgs); 628 kPortIndexInput, kPortIndexOutput, msg,
629 PortMode::PRESET_BYTE_BUFFER, &audioArgs));
603 } 630 }
604 // status == TIMED_OUT, it could be due to process time being large 631 // status == TIMED_OUT, it could be due to process time being large
605 // than DEFAULT_TIMEOUT or component needs output buffers to start 632 // than DEFAULT_TIMEOUT or component needs output buffers to start
@@ -612,9 +639,10 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
612 // Dispatch an output buffer assuming outQueue.empty() is true 639 // Dispatch an output buffer assuming outQueue.empty() is true
613 size_t index; 640 size_t index;
614 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 641 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
615 dispatchOutputBuffer(omxNode, oBuffer, index); 642 ASSERT_NO_FATAL_FAILURE(
643 dispatchOutputBuffer(omxNode, oBuffer, index));
644 timeOut = TIMEOUT_COUNTER_Q;
616 } 645 }
617 timeOut--;
618 } 646 }
619} 647}
620 648
@@ -628,51 +656,29 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
628 AudioDecHidlTest::standardComp comp, bool signalEOS = true) { 656 AudioDecHidlTest::standardComp comp, bool signalEOS = true) {
629 android::hardware::media::omx::V1_0::Status status; 657 android::hardware::media::omx::V1_0::Status status;
630 Message msg; 658 Message msg;
631 659 size_t index;
632 // dispatch output buffers
633 for (size_t i = 0; i < oBuffer->size(); i++) {
634 dispatchOutputBuffer(omxNode, oBuffer, i);
635 }
636 // dispatch input buffers
637 uint32_t flags = 0; 660 uint32_t flags = 0;
638 int frameID = offset; 661 int frameID = offset;
639 for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) && 662 int timeOut = TIMEOUT_COUNTER_Q;
640 (frameID < (offset + range)); 663 bool iQueued, oQueued;
641 i++) {
642 char* ipBuffer = static_cast<char*>(
643 static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
644 ASSERT_LE((*Info)[frameID].bytesCount,
645 static_cast<int>((*iBuffer)[i].mMemory->getSize()));
646 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
647 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
648 flags = (*Info)[frameID].flags;
649 if (signalEOS && ((frameID == (int)Info->size() - 1) ||
650 (frameID == (offset + range - 1))))
651 flags |= OMX_BUFFERFLAG_EOS;
652 dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
653 flags, (*Info)[frameID].timestamp);
654 frameID++;
655 }
656 664
657 int timeOut = TIMEOUT_COUNTER;
658 bool stall = false;
659 while (1) { 665 while (1) {
666 iQueued = oQueued = false;
660 status = 667 status =
661 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 668 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
662
663 // Port Reconfiguration 669 // Port Reconfiguration
664 if (status == android::hardware::media::omx::V1_0::Status::OK && 670 if (status == android::hardware::media::omx::V1_0::Status::OK &&
665 msg.type == Message::Type::EVENT) { 671 msg.type == Message::Type::EVENT) {
666 packedArgs audioArgs = {eEncoding, comp}; 672 packedArgs audioArgs = {eEncoding, comp};
667 portReconfiguration(omxNode, observer, iBuffer, oBuffer, 673 ASSERT_NO_FATAL_FAILURE(
668 kPortIndexInput, kPortIndexOutput, msg, 674 portReconfiguration(omxNode, observer, iBuffer, oBuffer,
669 PortMode::PRESET_BYTE_BUFFER, &audioArgs); 675 kPortIndexInput, kPortIndexOutput, msg,
676 PortMode::PRESET_BYTE_BUFFER, &audioArgs));
670 } 677 }
671 678
672 if (frameID == (int)Info->size() || frameID == (offset + range)) break; 679 if (frameID == (int)Info->size() || frameID == (offset + range)) break;
673 680
674 // Dispatch input buffer 681 // Dispatch input buffer
675 size_t index = 0;
676 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 682 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
677 char* ipBuffer = static_cast<char*>( 683 char* ipBuffer = static_cast<char*>(
678 static_cast<void*>((*iBuffer)[index].mMemory->getPointer())); 684 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -681,28 +687,33 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
681 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount); 687 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
682 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount); 688 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
683 flags = (*Info)[frameID].flags; 689 flags = (*Info)[frameID].flags;
690 // Indicate to omx core that the buffer contains a full frame worth
691 // of data
692 flags |= OMX_BUFFERFLAG_ENDOFFRAME;
693 // Indicate the omx core that this is the last buffer it needs to
694 // process
684 if (signalEOS && ((frameID == (int)Info->size() - 1) || 695 if (signalEOS && ((frameID == (int)Info->size() - 1) ||
685 (frameID == (offset + range - 1)))) 696 (frameID == (offset + range - 1))))
686 flags |= OMX_BUFFERFLAG_EOS; 697 flags |= OMX_BUFFERFLAG_EOS;
687 dispatchInputBuffer(omxNode, iBuffer, index, 698 ASSERT_NO_FATAL_FAILURE(dispatchInputBuffer(
688 (*Info)[frameID].bytesCount, flags, 699 omxNode, iBuffer, index, (*Info)[frameID].bytesCount, flags,
689 (*Info)[frameID].timestamp); 700 (*Info)[frameID].timestamp));
690 frameID++; 701 frameID++;
691 stall = false; 702 iQueued = true;
692 } else 703 }
693 stall = true; 704 // Dispatch output buffer
694 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 705 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
695 dispatchOutputBuffer(omxNode, oBuffer, index); 706 ASSERT_NO_FATAL_FAILURE(
696 stall = false; 707 dispatchOutputBuffer(omxNode, oBuffer, index));
697 } else 708 oQueued = true;
698 stall = true; 709 }
699 if (stall) 710 // Reset Counters when either input or output buffer is dispatched
700 timeOut--; 711 if (iQueued || oQueued)
712 timeOut = TIMEOUT_COUNTER_Q;
701 else 713 else
702 timeOut = TIMEOUT_COUNTER; 714 timeOut--;
703 if (timeOut == 0) { 715 if (timeOut == 0) {
704 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 716 ASSERT_TRUE(false) << "Wait on Input/Output is found indefinite";
705 break;
706 } 717 }
707 } 718 }
708} 719}
@@ -717,7 +728,7 @@ TEST_F(AudioDecHidlTest, SetRole) {
717} 728}
718 729
719// port format enumeration 730// port format enumeration
720TEST_F(AudioDecHidlTest, DISABLED_EnumeratePortFormat) { 731TEST_F(AudioDecHidlTest, EnumeratePortFormat) {
721 description("Test Component on Mandatory Port Parameters (Port Format)"); 732 description("Test Component on Mandatory Port Parameters (Port Format)");
722 if (disableTest) return; 733 if (disableTest) return;
723 android::hardware::media::omx::V1_0::Status status; 734 android::hardware::media::omx::V1_0::Status status;
@@ -766,13 +777,13 @@ TEST_F(AudioDecHidlTest, DecodeTest) {
766 int bytesCount = 0; 777 int bytesCount = 0;
767 uint32_t flags = 0; 778 uint32_t flags = 0;
768 uint32_t timestamp = 0; 779 uint32_t timestamp = 0;
769 timestampDevTest = true; 780 timestampDevTest = false;
770 while (1) { 781 while (1) {
771 if (!(eleInfo >> bytesCount)) break; 782 if (!(eleInfo >> bytesCount)) break;
772 eleInfo >> flags; 783 eleInfo >> flags;
773 eleInfo >> timestamp; 784 eleInfo >> timestamp;
774 Info.push_back({bytesCount, flags, timestamp}); 785 Info.push_back({bytesCount, flags, timestamp});
775 if (flags != OMX_BUFFERFLAG_CODECCONFIG) 786 if (timestampDevTest && (flags != OMX_BUFFERFLAG_CODECCONFIG))
776 timestampUslist.push_back(timestamp); 787 timestampUslist.push_back(timestamp);
777 } 788 }
778 eleInfo.close(); 789 eleInfo.close();
@@ -784,8 +795,8 @@ TEST_F(AudioDecHidlTest, DecodeTest) {
784 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000, 795 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000,
785 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned, 796 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned,
786 32); 797 32);
787 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 798 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
788 &nSampleRate); 799 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
789 // Configure output port 800 // Configure output port
790 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to 801 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to
791 // configure output PCM port. The port undergoes auto configuration 802 // configure output PCM port. The port undergoes auto configuration
@@ -798,36 +809,37 @@ TEST_F(AudioDecHidlTest, DecodeTest) {
798 android::Vector<BufferInfo> iBuffer, oBuffer; 809 android::Vector<BufferInfo> iBuffer, oBuffer;
799 810
800 // set state to idle 811 // set state to idle
801 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 812 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
802 kPortIndexInput, kPortIndexOutput); 813 &oBuffer, kPortIndexInput,
814 kPortIndexOutput));
803 // set state to executing 815 // set state to executing
804 changeStateIdletoExecute(omxNode, observer); 816 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
805 // Port Reconfiguration 817 // Port Reconfiguration
806 eleStream.open(mURL, std::ifstream::binary); 818 eleStream.open(mURL, std::ifstream::binary);
807 ASSERT_EQ(eleStream.is_open(), true); 819 ASSERT_EQ(eleStream.is_open(), true);
808 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 820 ASSERT_NO_FATAL_FAILURE(decodeNFrames(
809 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, 821 omxNode, observer, &iBuffer, &oBuffer, eEncoding, kPortIndexInput,
810 (int)Info.size(), compName); 822 kPortIndexOutput, eleStream, &Info, 0, (int)Info.size(), compName));
811 eleStream.close(); 823 eleStream.close();
812 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 824 ASSERT_NO_FATAL_FAILURE(
813 kPortIndexInput, kPortIndexOutput, compName); 825 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
826 kPortIndexInput, kPortIndexOutput, compName));
814 packedArgs audioArgs = {eEncoding, compName}; 827 packedArgs audioArgs = {eEncoding, compName};
815 testEOS(omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, nullptr, 828 ASSERT_NO_FATAL_FAILURE(testEOS(
816 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs); 829 omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, nullptr,
817 EXPECT_EQ(timestampUslist.empty(), true); 830 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs));
831 if (timestampDevTest) EXPECT_EQ(timestampUslist.empty(), true);
818 // set state to idle 832 // set state to idle
819 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 833 ASSERT_NO_FATAL_FAILURE(
834 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
820 // set state to executing 835 // set state to executing
821 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 836 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
822 kPortIndexInput, kPortIndexOutput); 837 &oBuffer, kPortIndexInput,
838 kPortIndexOutput));
823} 839}
824 840
825// end of sequence test 841// end of sequence test
826// SPECIAL CASE; Sending Empty input EOS buffer is not supported across all 842TEST_F(AudioDecHidlTest, EOSTest_M) {
827// components. For instance soft vorbis and soft opus expects CSD buffers at
828// the start. Disabling this test for now. We shall revisit this at a later
829// stage
830TEST_F(AudioDecHidlTest, DISABLED_EOSTest_M) {
831 description("Test end of stream monkeying"); 843 description("Test end of stream monkeying");
832 if (disableTest) return; 844 if (disableTest) return;
833 android::hardware::media::omx::V1_0::Status status; 845 android::hardware::media::omx::V1_0::Status status;
@@ -849,8 +861,8 @@ TEST_F(AudioDecHidlTest, DISABLED_EOSTest_M) {
849 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000, 861 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000,
850 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned, 862 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned,
851 32); 863 32);
852 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 864 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
853 &nSampleRate); 865 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
854 // Configure output port 866 // Configure output port
855 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to 867 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to
856 // configure output PCM port. The port undergoes auto configuration 868 // configure output PCM port. The port undergoes auto configuration
@@ -863,26 +875,31 @@ TEST_F(AudioDecHidlTest, DISABLED_EOSTest_M) {
863 android::Vector<BufferInfo> iBuffer, oBuffer; 875 android::Vector<BufferInfo> iBuffer, oBuffer;
864 876
865 // set state to idle 877 // set state to idle
866 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 878 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
867 kPortIndexInput, kPortIndexOutput); 879 &oBuffer, kPortIndexInput,
880 kPortIndexOutput));
868 // set state to executing 881 // set state to executing
869 changeStateIdletoExecute(omxNode, observer); 882 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
870 883
871 // request EOS at the start 884 // request EOS at the start
872 packedArgs audioArgs = {eEncoding, compName}; 885 packedArgs audioArgs = {eEncoding, compName};
873 testEOS(omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr, 886 ASSERT_NO_FATAL_FAILURE(testEOS(
874 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs); 887 omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr,
875 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 888 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs));
876 kPortIndexOutput); 889 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
890 kPortIndexInput, kPortIndexOutput));
877 EXPECT_GE(framesReceived, 0U); 891 EXPECT_GE(framesReceived, 0U);
878 framesReceived = 0; 892 framesReceived = 0;
879 timestampUs = 0; 893 timestampUs = 0;
880 894
881 // set state to idle 895 // set state to idle
882 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 896 ASSERT_NO_FATAL_FAILURE(
897 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
898
883 // set state to executing 899 // set state to executing
884 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 900 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
885 kPortIndexInput, kPortIndexOutput); 901 &oBuffer, kPortIndexInput,
902 kPortIndexOutput));
886} 903}
887 904
888// end of sequence test 905// end of sequence test
@@ -928,8 +945,8 @@ TEST_F(AudioDecHidlTest, ThumbnailTest) {
928 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000, 945 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000,
929 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned, 946 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned,
930 32); 947 32);
931 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 948 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
932 &nSampleRate); 949 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
933 // Configure output port 950 // Configure output port
934 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to 951 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to
935 // configure output PCM port. The port undergoes auto configuration 952 // configure output PCM port. The port undergoes auto configuration
@@ -942,10 +959,11 @@ TEST_F(AudioDecHidlTest, ThumbnailTest) {
942 android::Vector<BufferInfo> iBuffer, oBuffer; 959 android::Vector<BufferInfo> iBuffer, oBuffer;
943 960
944 // set state to idle 961 // set state to idle
945 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 962 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
946 kPortIndexInput, kPortIndexOutput); 963 &oBuffer, kPortIndexInput,
964 kPortIndexOutput));
947 // set state to executing 965 // set state to executing
948 changeStateIdletoExecute(omxNode, observer); 966 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
949 967
950 // request EOS for thumbnail 968 // request EOS for thumbnail
951 // signal EOS flag with last frame 969 // signal EOS flag with last frame
@@ -953,17 +971,19 @@ TEST_F(AudioDecHidlTest, ThumbnailTest) {
953 while (!(Info[i].flags & OMX_BUFFERFLAG_SYNCFRAME)) i++; 971 while (!(Info[i].flags & OMX_BUFFERFLAG_SYNCFRAME)) i++;
954 eleStream.open(mURL, std::ifstream::binary); 972 eleStream.open(mURL, std::ifstream::binary);
955 ASSERT_EQ(eleStream.is_open(), true); 973 ASSERT_EQ(eleStream.is_open(), true);
956 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 974 ASSERT_NO_FATAL_FAILURE(decodeNFrames(
957 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, i + 1, 975 omxNode, observer, &iBuffer, &oBuffer, eEncoding, kPortIndexInput,
958 compName); 976 kPortIndexOutput, eleStream, &Info, 0, i + 1, compName));
959 eleStream.close(); 977 eleStream.close();
960 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 978 ASSERT_NO_FATAL_FAILURE(
961 kPortIndexInput, kPortIndexOutput, compName); 979 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
980 kPortIndexInput, kPortIndexOutput, compName));
962 packedArgs audioArgs = {eEncoding, compName}; 981 packedArgs audioArgs = {eEncoding, compName};
963 testEOS(omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, nullptr, 982 ASSERT_NO_FATAL_FAILURE(testEOS(
964 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs); 983 omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, nullptr,
965 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 984 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs));
966 kPortIndexOutput); 985 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
986 kPortIndexInput, kPortIndexOutput));
967 EXPECT_GE(framesReceived, 1U); 987 EXPECT_GE(framesReceived, 1U);
968 framesReceived = 0; 988 framesReceived = 0;
969 timestampUs = 0; 989 timestampUs = 0;
@@ -971,25 +991,29 @@ TEST_F(AudioDecHidlTest, ThumbnailTest) {
971 // signal EOS flag after last frame 991 // signal EOS flag after last frame
972 eleStream.open(mURL, std::ifstream::binary); 992 eleStream.open(mURL, std::ifstream::binary);
973 ASSERT_EQ(eleStream.is_open(), true); 993 ASSERT_EQ(eleStream.is_open(), true);
974 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 994 ASSERT_NO_FATAL_FAILURE(decodeNFrames(
975 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, i + 1, 995 omxNode, observer, &iBuffer, &oBuffer, eEncoding, kPortIndexInput,
976 compName, false); 996 kPortIndexOutput, eleStream, &Info, 0, i + 1, compName, false));
977 eleStream.close(); 997 eleStream.close();
978 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 998 ASSERT_NO_FATAL_FAILURE(
979 kPortIndexInput, kPortIndexOutput, compName); 999 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
980 testEOS(omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr, 1000 kPortIndexInput, kPortIndexOutput, compName));
981 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs); 1001 ASSERT_NO_FATAL_FAILURE(testEOS(
982 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1002 omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr,
983 kPortIndexOutput); 1003 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs));
1004 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1005 kPortIndexInput, kPortIndexOutput));
984 EXPECT_GE(framesReceived, 1U); 1006 EXPECT_GE(framesReceived, 1U);
985 framesReceived = 0; 1007 framesReceived = 0;
986 timestampUs = 0; 1008 timestampUs = 0;
987 1009
988 // set state to idle 1010 // set state to idle
989 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 1011 ASSERT_NO_FATAL_FAILURE(
1012 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
990 // set state to executing 1013 // set state to executing
991 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 1014 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
992 kPortIndexInput, kPortIndexOutput); 1015 &oBuffer, kPortIndexInput,
1016 kPortIndexOutput));
993} 1017}
994 1018
995// end of sequence test 1019// end of sequence test
@@ -1035,8 +1059,8 @@ TEST_F(AudioDecHidlTest, SimpleEOSTest) {
1035 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000, 1059 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000,
1036 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned, 1060 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned,
1037 32); 1061 32);
1038 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 1062 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
1039 &nSampleRate); 1063 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
1040 // Configure output port 1064 // Configure output port
1041 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to 1065 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to
1042 // configure output PCM port. The port undergoes auto configuration 1066 // configure output PCM port. The port undergoes auto configuration
@@ -1049,33 +1073,39 @@ TEST_F(AudioDecHidlTest, SimpleEOSTest) {
1049 android::Vector<BufferInfo> iBuffer, oBuffer; 1073 android::Vector<BufferInfo> iBuffer, oBuffer;
1050 1074
1051 // set state to idle 1075 // set state to idle
1052 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1076 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
1053 kPortIndexInput, kPortIndexOutput); 1077 &oBuffer, kPortIndexInput,
1078 kPortIndexOutput));
1054 // set state to executing 1079 // set state to executing
1055 changeStateIdletoExecute(omxNode, observer); 1080 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1056 1081
1057 // request EOS at the end 1082 // request EOS at the end
1058 eleStream.open(mURL, std::ifstream::binary); 1083 eleStream.open(mURL, std::ifstream::binary);
1059 ASSERT_EQ(eleStream.is_open(), true); 1084 ASSERT_EQ(eleStream.is_open(), true);
1060 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 1085 ASSERT_NO_FATAL_FAILURE(decodeNFrames(omxNode, observer, &iBuffer, &oBuffer,
1061 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, 1086 eEncoding, kPortIndexInput,
1062 (int)Info.size(), compName, false); 1087 kPortIndexOutput, eleStream, &Info, 0,
1088 (int)Info.size(), compName, false));
1063 eleStream.close(); 1089 eleStream.close();
1064 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 1090 ASSERT_NO_FATAL_FAILURE(
1065 kPortIndexInput, kPortIndexOutput, compName); 1091 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
1092 kPortIndexInput, kPortIndexOutput, compName));
1066 packedArgs audioArgs = {eEncoding, compName}; 1093 packedArgs audioArgs = {eEncoding, compName};
1067 testEOS(omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr, 1094 ASSERT_NO_FATAL_FAILURE(testEOS(
1068 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs); 1095 omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, nullptr,
1069 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1096 portReconfiguration, kPortIndexInput, kPortIndexOutput, &audioArgs));
1070 kPortIndexOutput); 1097 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1098 kPortIndexInput, kPortIndexOutput));
1071 framesReceived = 0; 1099 framesReceived = 0;
1072 timestampUs = 0; 1100 timestampUs = 0;
1073 1101
1074 // set state to idle 1102 // set state to idle
1075 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 1103 ASSERT_NO_FATAL_FAILURE(
1104 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1076 // set state to executing 1105 // set state to executing
1077 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 1106 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1078 kPortIndexInput, kPortIndexOutput); 1107 &oBuffer, kPortIndexInput,
1108 kPortIndexOutput));
1079} 1109}
1080 1110
1081// test input/output port flush 1111// test input/output port flush
@@ -1121,8 +1151,8 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1121 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000, 1151 setDefaultPortParam(omxNode, kPortIndexInput, eEncoding, 1, 8000,
1122 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned, 1152 OMX_AUDIO_PCMModeLinear, OMX_NumericalDataSigned,
1123 32); 1153 32);
1124 getInputChannelInfo(omxNode, kPortIndexInput, eEncoding, &nChannels, 1154 ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(
1125 &nSampleRate); 1155 omxNode, kPortIndexInput, eEncoding, &nChannels, &nSampleRate));
1126 // Configure output port 1156 // Configure output port
1127 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to 1157 // SPECIAL CASE: Soft Vorbis, Opus and Raw Decoders do not offer way to
1128 // configure output PCM port. The port undergoes auto configuration 1158 // configure output PCM port. The port undergoes auto configuration
@@ -1135,10 +1165,11 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1135 android::Vector<BufferInfo> iBuffer, oBuffer; 1165 android::Vector<BufferInfo> iBuffer, oBuffer;
1136 1166
1137 // set state to idle 1167 // set state to idle
1138 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1168 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
1139 kPortIndexInput, kPortIndexOutput); 1169 &oBuffer, kPortIndexInput,
1170 kPortIndexOutput));
1140 // set state to executing 1171 // set state to executing
1141 changeStateIdletoExecute(omxNode, observer); 1172 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1142 1173
1143 // Decode 128 frames and flush. here 128 is chosen to ensure there is a key 1174 // Decode 128 frames and flush. here 128 is chosen to ensure there is a key
1144 // frame after this so that the below section can be convered for all 1175 // frame after this so that the below section can be convered for all
@@ -1146,12 +1177,11 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1146 int nFrames = 128; 1177 int nFrames = 128;
1147 eleStream.open(mURL, std::ifstream::binary); 1178 eleStream.open(mURL, std::ifstream::binary);
1148 ASSERT_EQ(eleStream.is_open(), true); 1179 ASSERT_EQ(eleStream.is_open(), true);
1149 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 1180 ASSERT_NO_FATAL_FAILURE(decodeNFrames(
1150 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, 1181 omxNode, observer, &iBuffer, &oBuffer, eEncoding, kPortIndexInput,
1151 nFrames, compName, false); 1182 kPortIndexOutput, eleStream, &Info, 0, nFrames, compName, false));
1152 // Note: Assumes 200 ms is enough to end any decode call that started 1183 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1153 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1184 kPortIndexInput, kPortIndexOutput));
1154 kPortIndexOutput, 200000);
1155 framesReceived = 0; 1185 framesReceived = 0;
1156 1186
1157 // Seek to next key frame and start decoding till the end 1187 // Seek to next key frame and start decoding till the end
@@ -1168,20 +1198,22 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1168 index++; 1198 index++;
1169 } 1199 }
1170 if (keyFrame) { 1200 if (keyFrame) {
1171 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 1201 ASSERT_NO_FATAL_FAILURE(
1172 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 1202 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
1173 index, Info.size() - index, compName, false); 1203 kPortIndexInput, kPortIndexOutput, eleStream, &Info,
1204 index, Info.size() - index, compName, false));
1174 } 1205 }
1175 // Note: Assumes 200 ms is enough to end any decode call that started 1206 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1176 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1207 kPortIndexInput, kPortIndexOutput));
1177 kPortIndexOutput, 200000);
1178 framesReceived = 0; 1208 framesReceived = 0;
1179 1209
1180 // set state to idle 1210 // set state to idle
1181 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 1211 ASSERT_NO_FATAL_FAILURE(
1212 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1182 // set state to executing 1213 // set state to executing
1183 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 1214 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1184 kPortIndexInput, kPortIndexOutput); 1215 &oBuffer, kPortIndexInput,
1216 kPortIndexOutput));
1185} 1217}
1186 1218
1187int main(int argc, char** argv) { 1219int main(int argc, char** argv) {
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
index ae79e826..953dc750 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
@@ -15,6 +15,10 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_audio_enc_test" 17#define LOG_TAG "media_omx_hidl_audio_enc_test"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
@@ -161,6 +165,7 @@ class AudioEncHidlTest : public ::testing::VtsHalHidlTargetTestBase {
161 this->omxNode = _nl; 165 this->omxNode = _nl;
162 }) 166 })
163 .isOk()); 167 .isOk());
168 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
164 ASSERT_NE(omxNode, nullptr); 169 ASSERT_NE(omxNode, nullptr);
165 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role"; 170 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role";
166 struct StringToName { 171 struct StringToName {
@@ -206,11 +211,15 @@ class AudioEncHidlTest : public ::testing::VtsHalHidlTargetTestBase {
206 } 211 }
207 if (i == kNumCompToCoding) disableTest = true; 212 if (i == kNumCompToCoding) disableTest = true;
208 eosFlag = false; 213 eosFlag = false;
209 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 214 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
210 } 215 }
211 216
212 virtual void TearDown() override { 217 virtual void TearDown() override {
213 if (omxNode != nullptr) { 218 if (omxNode != nullptr) {
219 // If you have encountered a fatal failure, it is possible that
220 // freeNode() will not go through. Instead of hanging the app.
221 // let it pass through and report errors
222 if (::testing::Test::HasFatalFailure()) return;
214 EXPECT_TRUE((omxNode->freeNode()).isOk()); 223 EXPECT_TRUE((omxNode->freeNode()).isOk());
215 omxNode = nullptr; 224 omxNode = nullptr;
216 } 225 }
@@ -342,13 +351,13 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
342 android::Vector<BufferInfo>* oBuffer) { 351 android::Vector<BufferInfo>* oBuffer) {
343 android::hardware::media::omx::V1_0::Status status; 352 android::hardware::media::omx::V1_0::Status status;
344 Message msg; 353 Message msg;
345 int timeOut = TIMEOUT_COUNTER; 354 int timeOut = TIMEOUT_COUNTER_Q;
346 355
347 while (timeOut--) { 356 while (timeOut--) {
348 size_t i = 0; 357 size_t i = 0;
349 status = 358 status =
350 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 359 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
351 EXPECT_EQ(status, 360 ASSERT_EQ(status,
352 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 361 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
353 // status == TIMED_OUT, it could be due to process time being large 362 // status == TIMED_OUT, it could be due to process time being large
354 // than DEFAULT_TIMEOUT or component needs output buffers to start 363 // than DEFAULT_TIMEOUT or component needs output buffers to start
@@ -361,9 +370,10 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
361 // Dispatch an output buffer assuming outQueue.empty() is true 370 // Dispatch an output buffer assuming outQueue.empty() is true
362 size_t index; 371 size_t index;
363 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 372 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
364 dispatchOutputBuffer(omxNode, oBuffer, index); 373 ASSERT_NO_FATAL_FAILURE(
374 dispatchOutputBuffer(omxNode, oBuffer, index));
375 timeOut = TIMEOUT_COUNTER_Q;
365 } 376 }
366 timeOut--;
367 } 377 }
368} 378}
369 379
@@ -376,43 +386,25 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
376 bool signalEOS = true) { 386 bool signalEOS = true) {
377 android::hardware::media::omx::V1_0::Status status; 387 android::hardware::media::omx::V1_0::Status status;
378 Message msg; 388 Message msg;
379 389 size_t index;
380 // dispatch output buffers
381 for (size_t i = 0; i < oBuffer->size(); i++) {
382 dispatchOutputBuffer(omxNode, oBuffer, i);
383 }
384 // dispatch input buffers
385 int bytesCount = samplesPerFrame * nChannels * 2; 390 int bytesCount = samplesPerFrame * nChannels * 2;
386 int32_t timestampIncr = 391 int32_t timestampIncr =
387 (int)(((float)samplesPerFrame / nSampleRate) * 1000000); 392 (int)(((float)samplesPerFrame / nSampleRate) * 1000000);
388 uint64_t timestamp = 0; 393 uint64_t timestamp = 0;
389 uint32_t flags = 0; 394 uint32_t flags = 0;
390 for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) { 395 int timeOut = TIMEOUT_COUNTER_Q;
391 char* ipBuffer = static_cast<char*>( 396 bool iQueued, oQueued;
392 static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
393 ASSERT_LE(bytesCount,
394 static_cast<int>((*iBuffer)[i].mMemory->getSize()));
395 eleStream.read(ipBuffer, bytesCount);
396 if (eleStream.gcount() != bytesCount) break;
397 if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
398 dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags, timestamp);
399 timestamp += timestampIncr;
400 nFrames--;
401 }
402 397
403 int timeOut = TIMEOUT_COUNTER;
404 bool stall = false;
405 while (1) { 398 while (1) {
399 iQueued = oQueued = false;
406 status = 400 status =
407 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 401 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
408
409 if (status == android::hardware::media::omx::V1_0::Status::OK) 402 if (status == android::hardware::media::omx::V1_0::Status::OK)
410 ASSERT_TRUE(false); 403 ASSERT_TRUE(false);
411 404
412 if (nFrames == 0) break; 405 if (nFrames == 0) break;
413 406
414 // Dispatch input buffer 407 // Dispatch input buffer
415 size_t index = 0;
416 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 408 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
417 char* ipBuffer = static_cast<char*>( 409 char* ipBuffer = static_cast<char*>(
418 static_cast<void*>((*iBuffer)[index].mMemory->getPointer())); 410 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -420,27 +412,27 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
420 static_cast<int>((*iBuffer)[index].mMemory->getSize())); 412 static_cast<int>((*iBuffer)[index].mMemory->getSize()));
421 eleStream.read(ipBuffer, bytesCount); 413 eleStream.read(ipBuffer, bytesCount);
422 if (eleStream.gcount() != bytesCount) break; 414 if (eleStream.gcount() != bytesCount) break;
423 if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS; 415 flags = OMX_BUFFERFLAG_ENDOFFRAME;
424 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags, 416 if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
425 timestamp); 417 ASSERT_NO_FATAL_FAILURE(dispatchInputBuffer(
418 omxNode, iBuffer, index, bytesCount, flags, timestamp));
426 timestamp += timestampIncr; 419 timestamp += timestampIncr;
427 nFrames--; 420 nFrames--;
428 stall = false; 421 iQueued = true;
429 } else 422 }
430 stall = true;
431 // Dispatch output buffer 423 // Dispatch output buffer
432 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 424 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
433 dispatchOutputBuffer(omxNode, oBuffer, index); 425 ASSERT_NO_FATAL_FAILURE(
434 stall = false; 426 dispatchOutputBuffer(omxNode, oBuffer, index));
435 } else 427 oQueued = true;
436 stall = true; 428 }
437 if (stall) 429 // Reset Counters when either input or output buffer is dispatched
438 timeOut--; 430 if (iQueued || oQueued)
431 timeOut = TIMEOUT_COUNTER_Q;
439 else 432 else
440 timeOut = TIMEOUT_COUNTER; 433 timeOut--;
441 if (timeOut == 0) { 434 if (timeOut == 0) {
442 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 435 ASSERT_TRUE(false) << "Wait on Input/Output is found indefinite";
443 break;
444 } 436 }
445 } 437 }
446} 438}
@@ -455,7 +447,7 @@ TEST_F(AudioEncHidlTest, SetRole) {
455} 447}
456 448
457// port format enumeration 449// port format enumeration
458TEST_F(AudioEncHidlTest, DISABLED_EnumeratePortFormat) { 450TEST_F(AudioEncHidlTest, EnumeratePortFormat) {
459 description("Test Component on Mandatory Port Parameters (Port Format)"); 451 description("Test Component on Mandatory Port Parameters (Port Format)");
460 if (disableTest) return; 452 if (disableTest) return;
461 android::hardware::media::omx::V1_0::Status status; 453 android::hardware::media::omx::V1_0::Status status;
@@ -531,31 +523,39 @@ TEST_F(AudioEncHidlTest, SimpleEncodeTest) {
531 } 523 }
532 setupPCMPort(omxNode, kPortIndexInput, nChannels, OMX_NumericalDataSigned, 524 setupPCMPort(omxNode, kPortIndexInput, nChannels, OMX_NumericalDataSigned,
533 16, nSampleRate, OMX_AUDIO_PCMModeLinear); 525 16, nSampleRate, OMX_AUDIO_PCMModeLinear);
526
534 // Configure output port 527 // Configure output port
535 setDefaultPortParam(omxNode, kPortIndexOutput, eEncoding, compName, 528 ASSERT_NO_FATAL_FAILURE(setDefaultPortParam(omxNode, kPortIndexOutput,
536 nChannels, nSampleRate, nBitRate); 529 eEncoding, compName, nChannels,
530 nSampleRate, nBitRate));
537 531
538 android::Vector<BufferInfo> iBuffer, oBuffer; 532 android::Vector<BufferInfo> iBuffer, oBuffer;
539 533
540 // set state to idle 534 // set state to idle
541 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 535 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
542 kPortIndexInput, kPortIndexOutput); 536 &oBuffer, kPortIndexInput,
537 kPortIndexOutput));
543 // set state to executing 538 // set state to executing
544 changeStateIdletoExecute(omxNode, observer); 539 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
545 540
546 eleStream.open(mURL, std::ifstream::binary); 541 eleStream.open(mURL, std::ifstream::binary);
547 ASSERT_EQ(eleStream.is_open(), true); 542 ASSERT_EQ(eleStream.is_open(), true);
548 encodeNFrames(omxNode, observer, &iBuffer, &oBuffer, 128, samplesPerFrame, 543 ASSERT_NO_FATAL_FAILURE(encodeNFrames(omxNode, observer, &iBuffer, &oBuffer,
549 nChannels, nSampleRate, eleStream); 544 128, samplesPerFrame, nChannels,
545 nSampleRate, eleStream));
550 eleStream.close(); 546 eleStream.close();
551 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer);
552 testEOS(omxNode, observer, &iBuffer, &oBuffer, false, eosFlag);
553 547
548 ASSERT_NO_FATAL_FAILURE(
549 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer));
550 ASSERT_NO_FATAL_FAILURE(
551 testEOS(omxNode, observer, &iBuffer, &oBuffer, false, eosFlag));
554 // set state to idle 552 // set state to idle
555 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 553 ASSERT_NO_FATAL_FAILURE(
554 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
556 // set state to executing 555 // set state to executing
557 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 556 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
558 kPortIndexInput, kPortIndexOutput); 557 &oBuffer, kPortIndexInput,
558 kPortIndexOutput));
559} 559}
560 560
561int main(int argc, char** argv) { 561int main(int argc, char** argv) {
diff --git a/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.cpp b/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.cpp
index 4c68219b..9500094d 100644
--- a/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.cpp
+++ b/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.cpp
@@ -15,6 +15,10 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_audio_test_common" 17#define LOG_TAG "media_omx_hidl_audio_test_common"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
diff --git a/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.h b/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.h
index 08b3d9cd..b187d284 100644
--- a/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.h
+++ b/media/omx/1.0/vts/functional/audio/media_audio_hidl_test_common.h
@@ -20,11 +20,6 @@
20#include <media_hidl_test_common.h> 20#include <media_hidl_test_common.h>
21 21
22/* 22/*
23 * Random Index used for monkey testing while get/set parameters
24 */
25#define RANDOM_INDEX 1729
26
27/*
28 * Common audio utils 23 * Common audio utils
29 */ 24 */
30void enumerateProfile(sp<IOmxNode> omxNode, OMX_U32 portIndex, 25void enumerateProfile(sp<IOmxNode> omxNode, OMX_U32 portIndex,
diff --git a/media/omx/1.0/vts/functional/common/Android.bp b/media/omx/1.0/vts/functional/common/Android.bp
index 93251fe8..cdc52fb4 100755..100644
--- a/media/omx/1.0/vts/functional/common/Android.bp
+++ b/media/omx/1.0/vts/functional/common/Android.bp
@@ -16,18 +16,43 @@
16 16
17cc_library_static { 17cc_library_static {
18 name: "VtsHalMediaOmxV1_0CommonUtil", 18 name: "VtsHalMediaOmxV1_0CommonUtil",
19 defaults: ["hidl_defaults"],
20 srcs: ["media_hidl_test_common.cpp"], 19 srcs: ["media_hidl_test_common.cpp"],
21 shared_libs: [ 20
22 "liblog", 21 header_libs: ["media_plugin_headers"],
22 export_header_lib_headers: ["media_plugin_headers"],
23 export_include_dirs: ["."],
24
25 static_libs: [
26 "VtsHalHidlTargetTestBase",
23 "libhidlmemory", 27 "libhidlmemory",
24 "android.hidl.allocator@1.0", 28 "android.hidl.allocator@1.0",
25 "android.hidl.memory@1.0", 29 "android.hidl.memory@1.0",
26 "android.hardware.media.omx@1.0", 30 "android.hardware.media.omx@1.0",
31 "android.hardware.graphics.allocator@2.0",
27 ], 32 ],
28 static_libs: ["VtsHalHidlTargetTestBase"], 33}
29 cflags: [ "-O0", "-g", ], 34
30 include_dirs: [ 35cc_defaults {
31 "frameworks/native/include/media/openmax/", 36 name: "VtsHalMediaOmxV1_0Defaults",
37 defaults: ["VtsHalTargetTestDefaults"],
38
39 // Link to these statically as they are not guaranteed to be on the device.
40 static_libs: [
41 "VtsHalMediaOmxV1_0CommonUtil",
42 "android.hardware.graphics.allocator@2.0",
43 "android.hardware.graphics.mapper@2.0",
44 "android.hardware.graphics.bufferqueue@1.0",
45 "android.hardware.graphics.common@1.0",
46 "android.hardware.media.omx@1.0",
47 "android.hardware.media@1.0",
48 "android.hidl.allocator@1.0",
49 "android.hidl.memory@1.0",
50 "libhidlmemory",
51 "libnativehelper",
52 ],
53
54 // TODO(b/64437680): Assume these libs are always available on the device.
55 shared_libs: [
56 "libstagefright_foundation",
32 ], 57 ],
33} 58}
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
index 1f67e2b6..34a96a0c 100755..100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
@@ -15,13 +15,15 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_video_test_common" 17#define LOG_TAG "media_omx_hidl_video_test_common"
18
19#ifdef __LP64__ 18#ifdef __LP64__
20#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS 19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
21#endif 20#endif
22 21
23#include <android-base/logging.h> 22#include <android-base/logging.h>
24 23
24#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
25#include <android/hardware/graphics/mapper/2.0/IMapper.h>
26#include <android/hardware/graphics/mapper/2.0/types.h>
25#include <android/hardware/media/omx/1.0/IOmx.h> 27#include <android/hardware/media/omx/1.0/IOmx.h>
26#include <android/hardware/media/omx/1.0/IOmxNode.h> 28#include <android/hardware/media/omx/1.0/IOmxNode.h>
27#include <android/hardware/media/omx/1.0/IOmxObserver.h> 29#include <android/hardware/media/omx/1.0/IOmxObserver.h>
@@ -29,7 +31,10 @@
29#include <android/hidl/allocator/1.0/IAllocator.h> 31#include <android/hidl/allocator/1.0/IAllocator.h>
30#include <android/hidl/memory/1.0/IMapper.h> 32#include <android/hidl/memory/1.0/IMapper.h>
31#include <android/hidl/memory/1.0/IMemory.h> 33#include <android/hidl/memory/1.0/IMemory.h>
34#include <cutils/atomic.h>
32 35
36using ::android::hardware::graphics::common::V1_0::BufferUsage;
37using ::android::hardware::graphics::common::V1_0::PixelFormat;
33using ::android::hardware::media::omx::V1_0::IOmx; 38using ::android::hardware::media::omx::V1_0::IOmx;
34using ::android::hardware::media::omx::V1_0::IOmxObserver; 39using ::android::hardware::media::omx::V1_0::IOmxObserver;
35using ::android::hardware::media::omx::V1_0::IOmxNode; 40using ::android::hardware::media::omx::V1_0::IOmxNode;
@@ -186,10 +191,157 @@ Return<android::hardware::media::omx::V1_0::Status> setAudioPortFormat(
186 return status; 191 return status;
187} 192}
188 193
194void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex,
195 BufferInfo* buffer, uint32_t nFrameWidth,
196 uint32_t nFrameHeight, int32_t* nStride,
197 int format) {
198 android::hardware::media::omx::V1_0::Status status;
199 sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
200 android::hardware::graphics::allocator::V2_0::IAllocator::getService();
201 ASSERT_NE(nullptr, allocator.get());
202
203 sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
204 android::hardware::graphics::mapper::V2_0::IMapper::getService();
205 ASSERT_NE(mapper.get(), nullptr);
206
207 android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
208 descriptorInfo;
209 uint32_t usage;
210
211 descriptorInfo.width = nFrameWidth;
212 descriptorInfo.height = nFrameHeight;
213 descriptorInfo.layerCount = 1;
214 descriptorInfo.format = static_cast<PixelFormat>(format);
215 descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
216 omxNode->getGraphicBufferUsage(
217 portIndex,
218 [&status, &usage](android::hardware::media::omx::V1_0::Status _s,
219 uint32_t _n1) {
220 status = _s;
221 usage = _n1;
222 });
223 if (status == android::hardware::media::omx::V1_0::Status::OK) {
224 descriptorInfo.usage |= usage;
225 }
226
227 ::android::hardware::hidl_vec<uint32_t> descriptor;
228 android::hardware::graphics::mapper::V2_0::Error error;
229 mapper->createDescriptor(
230 descriptorInfo, [&error, &descriptor](
231 android::hardware::graphics::mapper::V2_0::Error _s,
232 ::android::hardware::hidl_vec<uint32_t> _n1) {
233 error = _s;
234 descriptor = _n1;
235 });
236 ASSERT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
237
238 static volatile int32_t nextId = 0;
239 uint64_t id = static_cast<uint64_t>(getpid()) << 32;
240 allocator->allocate(
241 descriptor, 1,
242 [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
243 const ::android::hardware::hidl_vec<
244 ::android::hardware::hidl_handle>& _n2) {
245 ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
246 _s);
247 *nStride = _n1;
248 buffer->omxBuffer.nativeHandle = _n2[0];
249 buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
250 buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
251 buffer->omxBuffer.attr.anwBuffer.stride = _n1;
252 buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format;
253 buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage;
254 buffer->omxBuffer.attr.anwBuffer.layerCount =
255 descriptorInfo.layerCount;
256 buffer->omxBuffer.attr.anwBuffer.id =
257 id | static_cast<uint32_t>(android_atomic_inc(&nextId));
258 });
259}
260
261// allocate buffers needed on a component port
262void allocateBuffer(sp<IOmxNode> omxNode, BufferInfo* buffer, OMX_U32 portIndex,
263 OMX_U32 nBufferSize, PortMode portMode) {
264 android::hardware::media::omx::V1_0::Status status;
265
266 if (portMode == PortMode::PRESET_SECURE_BUFFER) {
267 buffer->owner = client;
268 buffer->omxBuffer.type = CodecBuffer::Type::NATIVE_HANDLE;
269 omxNode->allocateSecureBuffer(
270 portIndex, nBufferSize,
271 [&status, &buffer](
272 android::hardware::media::omx::V1_0::Status _s, uint32_t id,
273 ::android::hardware::hidl_handle const& nativeHandle) {
274 status = _s;
275 buffer->id = id;
276 buffer->omxBuffer.nativeHandle = nativeHandle;
277 });
278 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
279 } else if (portMode == PortMode::PRESET_BYTE_BUFFER ||
280 portMode == PortMode::DYNAMIC_ANW_BUFFER) {
281 sp<IAllocator> allocator = IAllocator::getService("ashmem");
282 ASSERT_NE(allocator.get(), nullptr);
283
284 buffer->owner = client;
285 buffer->omxBuffer.type = CodecBuffer::Type::SHARED_MEM;
286 buffer->omxBuffer.attr.preset.rangeOffset = 0;
287 buffer->omxBuffer.attr.preset.rangeLength = 0;
288 bool success = false;
289 if (portMode != PortMode::PRESET_BYTE_BUFFER) {
290 nBufferSize = sizeof(android::VideoNativeMetadata);
291 }
292 allocator->allocate(
293 nBufferSize,
294 [&success, &buffer](bool _s,
295 ::android::hardware::hidl_memory const& mem) {
296 success = _s;
297 buffer->omxBuffer.sharedMemory = mem;
298 });
299 ASSERT_EQ(success, true);
300 ASSERT_EQ(buffer->omxBuffer.sharedMemory.size(), nBufferSize);
301 buffer->mMemory = mapMemory(buffer->omxBuffer.sharedMemory);
302 ASSERT_NE(buffer->mMemory, nullptr);
303 if (portMode == PortMode::DYNAMIC_ANW_BUFFER) {
304 android::VideoNativeMetadata* metaData =
305 static_cast<android::VideoNativeMetadata*>(
306 static_cast<void*>(buffer->mMemory->getPointer()));
307 metaData->nFenceFd = -1;
308 buffer->slot = -1;
309 }
310 omxNode->useBuffer(
311 portIndex, buffer->omxBuffer,
312 [&status, &buffer](android::hardware::media::omx::V1_0::Status _s,
313 uint32_t id) {
314 status = _s;
315 buffer->id = id;
316 });
317 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
318 } else if (portMode == PortMode::PRESET_ANW_BUFFER) {
319 OMX_PARAM_PORTDEFINITIONTYPE portDef;
320 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex,
321 &portDef);
322 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
323 int32_t nStride;
324 buffer->owner = client;
325 buffer->omxBuffer.type = CodecBuffer::Type::ANW_BUFFER;
326 ASSERT_NO_FATAL_FAILURE(allocateGraphicBuffers(
327 omxNode, portIndex, buffer, portDef.format.video.nFrameWidth,
328 portDef.format.video.nFrameHeight, &nStride,
329 portDef.format.video.eColorFormat));
330 omxNode->useBuffer(
331 portIndex, buffer->omxBuffer,
332 [&status, &buffer](android::hardware::media::omx::V1_0::Status _s,
333 uint32_t id) {
334 status = _s;
335 buffer->id = id;
336 });
337 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
338 }
339}
340
189// allocate buffers needed on a component port 341// allocate buffers needed on a component port
190void allocatePortBuffers(sp<IOmxNode> omxNode, 342void allocatePortBuffers(sp<IOmxNode> omxNode,
191 android::Vector<BufferInfo>* buffArray, 343 android::Vector<BufferInfo>* buffArray,
192 OMX_U32 portIndex, PortMode portMode) { 344 OMX_U32 portIndex, PortMode portMode, bool allocGrap) {
193 android::hardware::media::omx::V1_0::Status status; 345 android::hardware::media::omx::V1_0::Status status;
194 OMX_PARAM_PORTDEFINITIONTYPE portDef; 346 OMX_PARAM_PORTDEFINITIONTYPE portDef;
195 347
@@ -199,70 +351,18 @@ void allocatePortBuffers(sp<IOmxNode> omxNode,
199 &portDef); 351 &portDef);
200 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 352 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
201 353
202 if (portMode == PortMode::PRESET_SECURE_BUFFER) { 354 for (size_t i = 0; i < portDef.nBufferCountActual; i++) {
203 for (size_t i = 0; i < portDef.nBufferCountActual; i++) { 355 BufferInfo buffer;
204 BufferInfo buffer; 356 ASSERT_NO_FATAL_FAILURE(allocateBuffer(omxNode, &buffer, portIndex,
205 buffer.owner = client; 357 portDef.nBufferSize, portMode));
206 buffer.omxBuffer.type = CodecBuffer::Type::NATIVE_HANDLE; 358 if (allocGrap && portMode == PortMode::DYNAMIC_ANW_BUFFER) {
207 omxNode->allocateSecureBuffer( 359 int32_t nStride;
208 portIndex, portDef.nBufferSize, 360 ASSERT_NO_FATAL_FAILURE(allocateGraphicBuffers(
209 [&status, &buffer]( 361 omxNode, portIndex, &buffer, portDef.format.video.nFrameWidth,
210 android::hardware::media::omx::V1_0::Status _s, uint32_t id, 362 portDef.format.video.nFrameHeight, &nStride,
211 ::android::hardware::hidl_handle const& nativeHandle) { 363 portDef.format.video.eColorFormat));
212 status = _s;
213 buffer.id = id;
214 buffer.omxBuffer.nativeHandle = nativeHandle;
215 });
216 buffArray->push(buffer);
217 ASSERT_EQ(status,
218 ::android::hardware::media::omx::V1_0::Status::OK);
219 }
220 } else if (portMode == PortMode::PRESET_BYTE_BUFFER ||
221 portMode == PortMode::DYNAMIC_ANW_BUFFER) {
222 sp<IAllocator> allocator = IAllocator::getService("ashmem");
223 EXPECT_NE(allocator.get(), nullptr);
224
225 for (size_t i = 0; i < portDef.nBufferCountActual; i++) {
226 BufferInfo buffer;
227 buffer.owner = client;
228 buffer.omxBuffer.type = CodecBuffer::Type::SHARED_MEM;
229 buffer.omxBuffer.attr.preset.rangeOffset = 0;
230 buffer.omxBuffer.attr.preset.rangeLength = 0;
231 bool success = false;
232 if (portMode != PortMode::PRESET_BYTE_BUFFER) {
233 portDef.nBufferSize = sizeof(android::VideoNativeMetadata);
234 }
235 allocator->allocate(
236 portDef.nBufferSize,
237 [&success, &buffer](
238 bool _s, ::android::hardware::hidl_memory const& mem) {
239 success = _s;
240 buffer.omxBuffer.sharedMemory = mem;
241 });
242 ASSERT_EQ(success, true);
243 ASSERT_EQ(buffer.omxBuffer.sharedMemory.size(),
244 portDef.nBufferSize);
245 buffer.mMemory = mapMemory(buffer.omxBuffer.sharedMemory);
246 ASSERT_NE(buffer.mMemory, nullptr);
247 if (portMode == PortMode::DYNAMIC_ANW_BUFFER) {
248 android::VideoNativeMetadata* metaData =
249 static_cast<android::VideoNativeMetadata*>(
250 static_cast<void*>(buffer.mMemory->getPointer()));
251 metaData->nFenceFd = -1;
252 buffer.slot = -1;
253 }
254 omxNode->useBuffer(
255 portIndex, buffer.omxBuffer,
256 [&status, &buffer](
257 android::hardware::media::omx::V1_0::Status _s,
258 uint32_t id) {
259 status = _s;
260 buffer.id = id;
261 });
262 buffArray->push(buffer);
263 ASSERT_EQ(status,
264 ::android::hardware::media::omx::V1_0::Status::OK);
265 } 364 }
365 buffArray->push(buffer);
266 } 366 }
267} 367}
268 368
@@ -273,7 +373,7 @@ void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
273 android::Vector<BufferInfo>* iBuffer, 373 android::Vector<BufferInfo>* iBuffer,
274 android::Vector<BufferInfo>* oBuffer, 374 android::Vector<BufferInfo>* oBuffer,
275 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput, 375 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
276 PortMode* portMode) { 376 PortMode* portMode, bool allocGrap) {
277 android::hardware::media::omx::V1_0::Status status; 377 android::hardware::media::omx::V1_0::Status status;
278 Message msg; 378 Message msg;
279 PortMode defaultPortMode[2], *pm; 379 PortMode defaultPortMode[2], *pm;
@@ -292,14 +392,16 @@ void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
292 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT); 392 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
293 393
294 // allocate buffers on input port 394 // allocate buffers on input port
295 allocatePortBuffers(omxNode, iBuffer, kPortIndexInput, pm[0]); 395 ASSERT_NO_FATAL_FAILURE(allocatePortBuffers(
396 omxNode, iBuffer, kPortIndexInput, pm[0], allocGrap));
296 397
297 // Dont switch states until the ports are populated 398 // Dont switch states until the ports are populated
298 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 399 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
299 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT); 400 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
300 401
301 // allocate buffers on output port 402 // allocate buffers on output port
302 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, pm[1]); 403 ASSERT_NO_FATAL_FAILURE(allocatePortBuffers(
404 omxNode, oBuffer, kPortIndexOutput, pm[1], allocGrap));
303 405
304 // As the ports are populated, check if the state transition is complete 406 // As the ports are populated, check if the state transition is complete
305 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 407 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
@@ -439,6 +541,7 @@ void dispatchOutputBuffer(sp<IOmxNode> omxNode,
439 status = 541 status =
440 omxNode->fillBuffer((*buffArray)[bufferIndex].id, t, fenceNh); 542 omxNode->fillBuffer((*buffArray)[bufferIndex].id, t, fenceNh);
441 break; 543 break;
544 case PortMode::PRESET_ANW_BUFFER:
442 case PortMode::PRESET_SECURE_BUFFER: 545 case PortMode::PRESET_SECURE_BUFFER:
443 case PortMode::PRESET_BYTE_BUFFER: 546 case PortMode::PRESET_BYTE_BUFFER:
444 t.sharedMemory = android::hardware::hidl_memory(); 547 t.sharedMemory = android::hardware::hidl_memory();
@@ -545,43 +648,45 @@ void testEOS(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
545 if (signalEOS) { 648 if (signalEOS) {
546 if ((i = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 649 if ((i = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
547 // signal an empty buffer with flag set to EOS 650 // signal an empty buffer with flag set to EOS
548 dispatchInputBuffer(omxNode, iBuffer, i, 0, OMX_BUFFERFLAG_EOS, 0); 651 ASSERT_NO_FATAL_FAILURE(dispatchInputBuffer(omxNode, iBuffer, i, 0,
652 OMX_BUFFERFLAG_EOS, 0));
549 } else { 653 } else {
550 ASSERT_TRUE(false); 654 ASSERT_TRUE(false);
551 } 655 }
552 } 656 }
553 657
554 int timeOut = TIMEOUT_COUNTER; 658 int timeOut = TIMEOUT_COUNTER_PE;
555 while (timeOut--) { 659 while (timeOut--) {
556 // Dispatch all client owned output buffers to recover remaining frames 660 // Dispatch all client owned output buffers to recover remaining frames
557 while (1) { 661 while (1) {
558 if ((i = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 662 if ((i = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
559 dispatchOutputBuffer(omxNode, oBuffer, i, pm[1]); 663 ASSERT_NO_FATAL_FAILURE(
664 dispatchOutputBuffer(omxNode, oBuffer, i, pm[1]));
560 // if dispatch is successful, perhaps there is a latency 665 // if dispatch is successful, perhaps there is a latency
561 // in the component. Dont be in a haste to leave. reset timeout 666 // in the component. Dont be in a haste to leave. reset timeout
562 // counter 667 // counter
563 timeOut = TIMEOUT_COUNTER; 668 timeOut = TIMEOUT_COUNTER_PE;
564 } else { 669 } else {
565 break; 670 break;
566 } 671 }
567 } 672 }
568 673
569 Message msg; 674 Message msg;
570 status = 675 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, iBuffer,
571 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 676 oBuffer);
572 if (status == android::hardware::media::omx::V1_0::Status::OK) { 677 if (status == android::hardware::media::omx::V1_0::Status::OK) {
573 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) { 678 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
574 if (fptr) { 679 if (fptr) {
575 (*fptr)(omxNode, observer, iBuffer, oBuffer, 680 ASSERT_NO_FATAL_FAILURE((*fptr)(
576 kPortIndexInput, kPortIndexOutput, msg, pm[1], 681 omxNode, observer, iBuffer, oBuffer, kPortIndexInput,
577 args); 682 kPortIndexOutput, msg, pm[1], args));
578 } else { 683 } else {
579 // something unexpected happened 684 // something unexpected happened
580 EXPECT_TRUE(false); 685 ASSERT_TRUE(false);
581 } 686 }
582 } else { 687 } else {
583 // something unexpected happened 688 // something unexpected happened
584 EXPECT_TRUE(false); 689 ASSERT_TRUE(false);
585 } 690 }
586 } 691 }
587 if (eosFlag == true) break; 692 if (eosFlag == true) break;
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
index 0adea14e..bec733dc 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2016, The Android Open Source Project 2 * Copyright 2017, The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
@@ -33,8 +33,21 @@
33#include <media/openmax/OMX_AudioExt.h> 33#include <media/openmax/OMX_AudioExt.h>
34#include <media/openmax/OMX_VideoExt.h> 34#include <media/openmax/OMX_VideoExt.h>
35 35
36/* TIME OUTS (Wait time in dequeueMessage()) */
37
38/* As component is switching states (loaded<->idle<->execute), dequeueMessage()
39 * expects the events to be received within this duration */
36#define DEFAULT_TIMEOUT 100000 40#define DEFAULT_TIMEOUT 100000
37#define TIMEOUT_COUNTER (10000000 / DEFAULT_TIMEOUT) 41/* Time interval between successive Input/Output enqueues */
42#define DEFAULT_TIMEOUT_Q 2000
43/* While the component is amidst a process call, asynchronous commands like
44 * flush, change states can get delayed (at max by process call time). Instead
45 * of waiting on DEFAULT_TIMEOUT, we give an additional leeway. */
46#define DEFAULT_TIMEOUT_PE 500000
47
48/* Breakout Timeout :: 5 sec*/
49#define TIMEOUT_COUNTER_Q (5000000 / DEFAULT_TIMEOUT_Q)
50#define TIMEOUT_COUNTER_PE (5000000 / DEFAULT_TIMEOUT_PE)
38 51
39/* 52/*
40 * Random Index used for monkey testing while get/set parameters 53 * Random Index used for monkey testing while get/set parameters
@@ -120,13 +133,15 @@ struct CodecObserver : public IOmxObserver {
120 if (it->type == 133 if (it->type ==
121 android::hardware::media::omx::V1_0::Message::Type::EVENT) { 134 android::hardware::media::omx::V1_0::Message::Type::EVENT) {
122 *msg = *it; 135 *msg = *it;
123 msgQueue.erase(it); 136 if (callBack) callBack(*it, nullptr);
137 it = msgQueue.erase(it);
124 // OMX_EventBufferFlag event is sent when the component has 138 // OMX_EventBufferFlag event is sent when the component has
125 // processed a buffer with its EOS flag set. This event is 139 // processed a buffer with its EOS flag set. This event is
126 // not sent by soft omx components. Vendor components can 140 // not sent by soft omx components. Vendor components can
127 // send this. From IOMX point of view, we will ignore this 141 // send this. From IOMX point of view, we will ignore this
128 // event. 142 // event.
129 if (msg->data.eventData.event == OMX_EventBufferFlag) break; 143 if (msg->data.eventData.event == OMX_EventBufferFlag)
144 continue;
130 return ::android::hardware::media::omx::V1_0::Status::OK; 145 return ::android::hardware::media::omx::V1_0::Status::OK;
131 } else if (it->type == android::hardware::media::omx::V1_0:: 146 } else if (it->type == android::hardware::media::omx::V1_0::
132 Message::Type::FILL_BUFFER_DONE) { 147 Message::Type::FILL_BUFFER_DONE) {
@@ -137,7 +152,7 @@ struct CodecObserver : public IOmxObserver {
137 it->data.bufferData.buffer) { 152 it->data.bufferData.buffer) {
138 if (callBack) callBack(*it, &(*oBuffers)[i]); 153 if (callBack) callBack(*it, &(*oBuffers)[i]);
139 oBuffers->editItemAt(i).owner = client; 154 oBuffers->editItemAt(i).owner = client;
140 msgQueue.erase(it); 155 it = msgQueue.erase(it);
141 break; 156 break;
142 } 157 }
143 } 158 }
@@ -152,24 +167,22 @@ struct CodecObserver : public IOmxObserver {
152 it->data.bufferData.buffer) { 167 it->data.bufferData.buffer) {
153 if (callBack) callBack(*it, &(*iBuffers)[i]); 168 if (callBack) callBack(*it, &(*iBuffers)[i]);
154 iBuffers->editItemAt(i).owner = client; 169 iBuffers->editItemAt(i).owner = client;
155 msgQueue.erase(it); 170 it = msgQueue.erase(it);
156 break; 171 break;
157 } 172 }
158 } 173 }
159 EXPECT_LE(i, iBuffers->size()); 174 EXPECT_LE(i, iBuffers->size());
160 } 175 }
176 } else {
177 EXPECT_TRUE(false) << "Received unexpected message";
178 ++it;
161 } 179 }
162 ++it;
163 } 180 }
164 if (finishBy - android::ALooper::GetNowUs() < 0) 181 int64_t delayUs = finishBy - android::ALooper::GetNowUs();
165 return toStatus(android::TIMED_OUT); 182 if (delayUs < 0) return toStatus(android::TIMED_OUT);
166 android::status_t err = 183 (timeoutUs < 0)
167 (timeoutUs < 0) 184 ? msgCondition.wait(msgLock)
168 ? msgCondition.wait(msgLock) 185 : msgCondition.waitRelative(msgLock, delayUs * 1000ll);
169 : msgCondition.waitRelative(
170 msgLock,
171 (finishBy - android::ALooper::GetNowUs()) * 1000ll);
172 if (err == android::TIMED_OUT) return toStatus(err);
173 } 186 }
174 } 187 }
175 188
@@ -284,16 +297,21 @@ Return<android::hardware::media::omx::V1_0::Status> setVideoPortFormat(
284Return<android::hardware::media::omx::V1_0::Status> setAudioPortFormat( 297Return<android::hardware::media::omx::V1_0::Status> setAudioPortFormat(
285 sp<IOmxNode> omxNode, OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE eEncoding); 298 sp<IOmxNode> omxNode, OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE eEncoding);
286 299
300void allocateBuffer(sp<IOmxNode> omxNode, BufferInfo* buffer, OMX_U32 portIndex,
301 OMX_U32 nBufferSize, PortMode portMode);
302
287void allocatePortBuffers(sp<IOmxNode> omxNode, 303void allocatePortBuffers(sp<IOmxNode> omxNode,
288 android::Vector<BufferInfo>* buffArray, 304 android::Vector<BufferInfo>* buffArray,
289 OMX_U32 portIndex, 305 OMX_U32 portIndex,
290 PortMode portMode = PortMode::PRESET_BYTE_BUFFER); 306 PortMode portMode = PortMode::PRESET_BYTE_BUFFER,
307 bool allocGrap = false);
291 308
292void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer, 309void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
293 android::Vector<BufferInfo>* iBuffer, 310 android::Vector<BufferInfo>* iBuffer,
294 android::Vector<BufferInfo>* oBuffer, 311 android::Vector<BufferInfo>* oBuffer,
295 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput, 312 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
296 PortMode* portMode = nullptr); 313 PortMode* portMode = nullptr,
314 bool allocGrap = false);
297 315
298void changeStateIdletoLoaded(sp<IOmxNode> omxNode, sp<CodecObserver> observer, 316void changeStateIdletoLoaded(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
299 android::Vector<BufferInfo>* iBuffer, 317 android::Vector<BufferInfo>* iBuffer,
@@ -322,7 +340,8 @@ void dispatchInputBuffer(sp<IOmxNode> omxNode,
322void flushPorts(sp<IOmxNode> omxNode, sp<CodecObserver> observer, 340void flushPorts(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
323 android::Vector<BufferInfo>* iBuffer, 341 android::Vector<BufferInfo>* iBuffer,
324 android::Vector<BufferInfo>* oBuffer, OMX_U32 kPortIndexInput, 342 android::Vector<BufferInfo>* oBuffer, OMX_U32 kPortIndexInput,
325 OMX_U32 kPortIndexOutput, int64_t timeoutUs = DEFAULT_TIMEOUT); 343 OMX_U32 kPortIndexOutput,
344 int64_t timeoutUs = DEFAULT_TIMEOUT_PE);
326 345
327typedef void (*portreconfig)(sp<IOmxNode> omxNode, sp<CodecObserver> observer, 346typedef void (*portreconfig)(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
328 android::Vector<BufferInfo>* iBuffer, 347 android::Vector<BufferInfo>* iBuffer,
diff --git a/media/omx/1.0/vts/functional/component/Android.bp b/media/omx/1.0/vts/functional/component/Android.bp
index fd3210fb..f76b6e94 100644
--- a/media/omx/1.0/vts/functional/component/Android.bp
+++ b/media/omx/1.0/vts/functional/component/Android.bp
@@ -16,32 +16,7 @@
16 16
17cc_test { 17cc_test {
18 name: "VtsHalMediaOmxV1_0TargetComponentTest", 18 name: "VtsHalMediaOmxV1_0TargetComponentTest",
19 defaults: ["hidl_defaults"], 19 defaults: ["VtsHalMediaOmxV1_0Defaults"],
20 srcs: ["VtsHalMediaOmxV1_0TargetComponentTest.cpp"], 20 srcs: ["VtsHalMediaOmxV1_0TargetComponentTest.cpp"],
21 shared_libs: [
22 "libbase",
23 "liblog",
24 "libcutils",
25 "libhidlbase",
26 "libhidlmemory",
27 "libhidltransport",
28 "libhwbinder",
29 "libnativehelper",
30 "libutils",
31 "libstagefright_foundation",
32 "android.hidl.allocator@1.0",
33 "android.hidl.memory@1.0",
34 "android.hardware.media.omx@1.0",
35 ],
36 static_libs: ["VtsHalHidlTargetTestBase",
37 "VtsHalMediaOmxV1_0CommonUtil"],
38 cflags: [
39 "-O0",
40 "-g",
41 ],
42 include_dirs: [
43 "frameworks/native/include/media/openmax/",
44 "hardware/interfaces/media/omx/1.0/vts/functional/common",
45 ],
46} 21}
47 22
diff --git a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
index 2d91e827..d66136d2 100644
--- a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
+++ b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
@@ -15,6 +15,10 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_component_test" 17#define LOG_TAG "media_omx_hidl_component_test"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
@@ -145,6 +149,7 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase {
145 this->omxNode = _nl; 149 this->omxNode = _nl;
146 }) 150 })
147 .isOk()); 151 .isOk());
152 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
148 ASSERT_NE(omxNode, nullptr); 153 ASSERT_NE(omxNode, nullptr);
149 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role"; 154 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role";
150 struct StringToClass { 155 struct StringToClass {
@@ -181,11 +186,15 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase {
181 strlen(gEnv->getComponent().c_str()) - suffixLen, 186 strlen(gEnv->getComponent().c_str()) - suffixLen,
182 ".secure"); 187 ".secure");
183 } 188 }
184 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 189 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
185 } 190 }
186 191
187 virtual void TearDown() override { 192 virtual void TearDown() override {
188 if (omxNode != nullptr) { 193 if (omxNode != nullptr) {
194 // If you have encountered a fatal failure, it is possible that
195 // freeNode() will not go through. Instead of hanging the app.
196 // let it pass through and report errors
197 if (::testing::Test::HasFatalFailure()) return;
189 EXPECT_TRUE((omxNode->freeNode()).isOk()); 198 EXPECT_TRUE((omxNode->freeNode()).isOk());
190 omxNode = nullptr; 199 omxNode = nullptr;
191 } 200 }
@@ -213,9 +222,6 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase {
213 } 222 }
214}; 223};
215 224
216// Random Index used for monkey testing while get/set parameters
217#define RANDOM_INDEX 1729
218
219void initPortMode(PortMode* pm, bool isSecure, 225void initPortMode(PortMode* pm, bool isSecure,
220 ComponentHidlTest::standardCompClass compClass) { 226 ComponentHidlTest::standardCompClass compClass) {
221 pm[0] = PortMode::PRESET_BYTE_BUFFER; 227 pm[0] = PortMode::PRESET_BYTE_BUFFER;
@@ -232,7 +238,6 @@ void initPortMode(PortMode* pm, bool isSecure,
232 break; 238 break;
233 } 239 }
234 } 240 }
235 return;
236} 241}
237 242
238// test dispatch message API call 243// test dispatch message API call
@@ -293,7 +298,7 @@ TEST_F(ComponentHidlTest, DISABLED_GetPortIndices) {
293} 298}
294 299
295// port format enumeration 300// port format enumeration
296TEST_F(ComponentHidlTest, DISABLED_EnumeratePortFormat) { 301TEST_F(ComponentHidlTest, EnumeratePortFormat) {
297 description("Test Component on Mandatory Port Parameters (Port Format)"); 302 description("Test Component on Mandatory Port Parameters (Port Format)");
298 if (disableTest) return; 303 if (disableTest) return;
299 android::hardware::media::omx::V1_0::Status status; 304 android::hardware::media::omx::V1_0::Status status;
@@ -374,7 +379,7 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
374 kPortIndexOutput = kPortIndexInput + 1; 379 kPortIndexOutput = kPortIndexInput + 1;
375 } 380 }
376 381
377 for (size_t i = kPortIndexInput; i < kPortIndexOutput; i++) { 382 for (size_t i = kPortIndexInput; i <= kPortIndexOutput; i++) {
378 OMX_PARAM_PORTDEFINITIONTYPE portDef; 383 OMX_PARAM_PORTDEFINITIONTYPE portDef;
379 status = 384 status =
380 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 385 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
@@ -400,28 +405,31 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
400 EXPECT_NE(status, 405 EXPECT_NE(status,
401 ::android::hardware::media::omx::V1_0::Status::OK); 406 ::android::hardware::media::omx::V1_0::Status::OK);
402 407
403 // Edit Read-Only fields. 408 // Port Direction - Read Only
404 portDef = mirror; 409 portDef = mirror;
405 portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX); 410 portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX);
406 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 411 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
407 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 412 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
413 if (portDef.eDir != mirror.eDir) {
414 std::cerr << "[ ERROR ] port direction has to be read only "
415 "but is changeable \n";
416 }
408 EXPECT_EQ(portDef.eDir, mirror.eDir); 417 EXPECT_EQ(portDef.eDir, mirror.eDir);
409 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); 418 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
410 419
411 portDef = mirror; 420 // Port Min BufferCount - Read Only
412 portDef.nBufferSize >>= 1;
413 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
414 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
415 EXPECT_EQ(portDef.nBufferSize, mirror.nBufferSize);
416 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
417
418 portDef = mirror; 421 portDef = mirror;
419 portDef.nBufferCountMin += 1; 422 portDef.nBufferCountMin += 1;
420 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 423 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
421 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 424 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
425 if (portDef.nBufferCountMin != mirror.nBufferCountMin) {
426 std::cerr << "[ ERROR ] port Min BufferCount has to be "
427 "read only but is changeable \n";
428 }
422 EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin); 429 EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin);
423 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); 430 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
424 431
432 // Port Actual BufferCount
425 portDef = mirror; 433 portDef = mirror;
426 portDef.nBufferCountActual += 1; 434 portDef.nBufferCountActual += 1;
427 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, 435 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i,
@@ -432,20 +440,49 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
432 EXPECT_EQ(portDef.nBufferCountActual, 440 EXPECT_EQ(portDef.nBufferCountActual,
433 mirror.nBufferCountActual + 1); 441 mirror.nBufferCountActual + 1);
434 } 442 }
443 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
435 444
445 // Port BufferSize is although read only as per OMX-IL 1.2, android
446 // doesnt abide by this.
447 // Decrease buffer size
436 portDef = mirror; 448 portDef = mirror;
437 portDef.nBufferSize = mirror.nBufferSize << 1; 449 OMX_U32 nBufferSize = portDef.nBufferSize >> 1;
438 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, 450 if (nBufferSize != 0) {
439 &portDef); 451 if (!strncmp(gEnv->getComponent().c_str(), "OMX.google.", 11)) {
440 if (status == ::android::hardware::media::omx::V1_0::Status::OK) { 452 portDef.nBufferSize = nBufferSize;
441 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, i, 453 } else {
442 &portDef); 454 // Probable alignment requirements of vendor component
443 if (portDef.nBufferSize != mirror.nBufferSize) { 455 portDef.nBufferSize = ALIGN_POWER_OF_TWO(nBufferSize, 12);
444 std::cout 456 nBufferSize = portDef.nBufferSize;
445 << "[ ] Warning ! Component input port does "
446 "not preserve Read-Only fields \n";
447 } 457 }
458 } else {
459 ASSERT_TRUE(false) << "Unexpected buffer size";
448 } 460 }
461 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
462 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
463 // SPECIAL CASE: For video decoder, allow configuration of input
464 // buffer size even if it is less than minimum requirement and
465 // similarly for encoder allow configuration of output port buffer
466 // size.
467 if ((compClass == video_encoder && i == kPortIndexOutput) ||
468 (compClass == video_decoder && i == kPortIndexInput)) {
469 double dev = (portDef.nBufferSize / (double)nBufferSize);
470 dev -= 1;
471 if (dev < 0 || dev > 0.1) {
472 std::cerr << "[ ERROR ] port buffer size deviation "
473 "larger than expected \n";
474 }
475 } else {
476 EXPECT_EQ(portDef.nBufferSize, mirror.nBufferSize);
477 }
478 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
479
480 // Increase buffer size
481 portDef = mirror;
482 portDef.nBufferSize = mirror.nBufferSize << 1;
483 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
484 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
485 EXPECT_EQ(portDef.nBufferSize, (mirror.nBufferSize << 1));
449 } 486 }
450 } 487 }
451} 488}
@@ -470,8 +507,10 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) {
470 portBase = params.nStartPortNumber; 507 portBase = params.nStartPortNumber;
471 } 508 }
472 509
473 sp<IAllocator> allocator = IAllocator::getService("ashmem"); 510 // set state to idle
474 EXPECT_NE(allocator.get(), nullptr); 511 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
512 OMX_StateIdle);
513 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
475 514
476 OMX_PARAM_PORTDEFINITIONTYPE portDef; 515 OMX_PARAM_PORTDEFINITIONTYPE portDef;
477 status = 516 status =
@@ -485,30 +524,10 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) {
485 524
486 for (size_t i = 0; i < portDef.nBufferCountActual; i++) { 525 for (size_t i = 0; i < portDef.nBufferCountActual; i++) {
487 BufferInfo buffer; 526 BufferInfo buffer;
488 buffer.owner = client; 527 ASSERT_NO_FATAL_FAILURE(allocateBuffer(omxNode, &buffer, portBase,
489 buffer.omxBuffer.type = CodecBuffer::Type::SHARED_MEM; 528 nBufferSize,
490 buffer.omxBuffer.attr.preset.rangeOffset = 0; 529 PortMode::PRESET_BYTE_BUFFER));
491 buffer.omxBuffer.attr.preset.rangeLength = 0;
492 bool success = false;
493 allocator->allocate(
494 nBufferSize,
495 [&success, &buffer](bool _s,
496 ::android::hardware::hidl_memory const& mem) {
497 success = _s;
498 buffer.omxBuffer.sharedMemory = mem;
499 });
500 ASSERT_EQ(success, true);
501 ASSERT_EQ(buffer.omxBuffer.sharedMemory.size(), nBufferSize);
502
503 omxNode->useBuffer(
504 portBase, buffer.omxBuffer,
505 [&status, &buffer](android::hardware::media::omx::V1_0::Status _s,
506 uint32_t id) {
507 status = _s;
508 buffer.id = id;
509 });
510 pBuffer.push(buffer); 530 pBuffer.push(buffer);
511 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
512 } 531 }
513 532
514 status = 533 status =
@@ -548,44 +567,52 @@ TEST_F(ComponentHidlTest, Flush) {
548 PortMode portMode[2]; 567 PortMode portMode[2];
549 initPortMode(portMode, isSecure, compClass); 568 initPortMode(portMode, isSecure, compClass);
550 status = omxNode->setPortMode(kPortIndexInput, portMode[0]); 569 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
551 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 570 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
552 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 571 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
553 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 572 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
554 573
555 // set state to idle 574 // set state to idle
556 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 575 ASSERT_NO_FATAL_FAILURE(
557 kPortIndexInput, kPortIndexOutput, portMode); 576 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
577 kPortIndexInput, kPortIndexOutput, portMode));
558 // set state to executing 578 // set state to executing
559 changeStateIdletoExecute(omxNode, observer); 579 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
560 // dispatch buffers 580 // dispatch buffers
561 for (size_t i = 0; i < oBuffer.size(); i++) { 581 for (size_t i = 0; i < oBuffer.size(); i++) {
562 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]); 582 ASSERT_NO_FATAL_FAILURE(
583 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]));
563 } 584 }
564 // flush port 585 // flush port
565 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 586 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
566 kPortIndexOutput); 587 kPortIndexInput, kPortIndexOutput));
588#if 0
567 // TODO: Sending empty input buffers is slightly tricky. 589 // TODO: Sending empty input buffers is slightly tricky.
568 // Components sometimes process input buffers even when output buffers are 590 // Components sometimes process input buffers even when output buffers are
569 // not dispatched. For instance Parsing sequence header does not require 591 // not dispatched. For instance Parsing sequence header does not require
570 // output buffers. In such instances sending 0 size input buffers might 592 // output buffers. In such instances sending 0 size input buffers might
571 // make component to send error events. so lets skip this aspect of testing. 593 // make component to send error events. so lets skip this aspect of testing.
572 // dispatch buffers 594 // dispatch buffers
573 // for (size_t i = 0; i < iBuffer.size(); i++) { 595 for (size_t i = 0; i < iBuffer.size(); i++) {
574 // dispatchInputBuffer(omxNode, &iBuffer, i, 0, 0, 0, portMode[0]); 596 ASSERT_NO_FATAL_FAILURE(
575 // } 597 dispatchInputBuffer(omxNode, &iBuffer, i, 0, 0, 0, portMode[0]));
576 // // flush ports 598 }
577 // flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 599 // flush ports
578 // kPortIndexOutput); 600 ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
601 kPortIndexInput, kPortIndexOutput));
602#endif
603
579 // set state to idle 604 // set state to idle
580 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 605 ASSERT_NO_FATAL_FAILURE(
606 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
581 // set state to loaded 607 // set state to loaded
582 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 608 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
583 kPortIndexInput, kPortIndexOutput); 609 &oBuffer, kPortIndexInput,
610 kPortIndexOutput));
584} 611}
585 612
586// state transitions test 613// Flush test - monkeying
587TEST_F(ComponentHidlTest, StateTransitions) { 614TEST_F(ComponentHidlTest, Flush_M) {
588 description("Test State Transitions Loaded<->Idle<->Execute"); 615 description("Test Flush monkeying");
589 if (disableTest) return; 616 if (disableTest) return;
590 android::hardware::media::omx::V1_0::Status status; 617 android::hardware::media::omx::V1_0::Status status;
591 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; 618 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
@@ -611,33 +638,267 @@ TEST_F(ComponentHidlTest, StateTransitions) {
611 PortMode portMode[2]; 638 PortMode portMode[2];
612 initPortMode(portMode, isSecure, compClass); 639 initPortMode(portMode, isSecure, compClass);
613 status = omxNode->setPortMode(kPortIndexInput, portMode[0]); 640 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
641 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
642 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
643 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
644
645 // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
646 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
647 // OMX_ALL);
648 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
649
650 // set state to idle
651 ASSERT_NO_FATAL_FAILURE(
652 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
653 kPortIndexInput, kPortIndexOutput, portMode));
654
655 // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
656 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
657 // OMX_ALL);
658 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
659
660 // set state to executing
661 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
662
663 // dispatch buffers
664 for (size_t i = 0; i < oBuffer.size(); i++) {
665 ASSERT_NO_FATAL_FAILURE(
666 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]));
667 }
668
669 // // flush invalid port, expecting OMX_ErrorBadPortIndex
670 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
671 // RANDOM_INDEX);
672 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
673
674 // Flush all ports
675 status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), OMX_ALL);
676 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
677
678 for (int j = 0; j < 2; j++) {
679 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer,
680 &oBuffer);
681 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
682 ASSERT_EQ(msg.type, Message::Type::EVENT);
683 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
684 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
685 if (msg.data.eventData.data2 == kPortIndexInput) {
686 // test if client got all its buffers back
687 for (size_t i = 0; i < iBuffer.size(); ++i) {
688 EXPECT_EQ(iBuffer[i].owner, client);
689 }
690 } else if (msg.data.eventData.data2 == kPortIndexOutput) {
691 // test if client got all its buffers back
692 for (size_t i = 0; i < oBuffer.size(); ++i) {
693 EXPECT_EQ(oBuffer[i].owner, client);
694 }
695 } else {
696 EXPECT_TRUE(false) << "Bad port Index";
697 }
698 }
699
700 // SPECIAL CASE: When OMX_ALL is used as argument, Android OMX Core sends
701 // an additional flush event with argument OMX_ALL. This we believe is
702 // not recognized by OMX-IL Spec. So read this event and ignore it
703 status =
704 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer, &oBuffer);
705 if (status == android::hardware::media::omx::V1_0::Status::OK) {
706 ASSERT_EQ(msg.type, Message::Type::EVENT);
707 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
708 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
709 ASSERT_EQ(msg.data.eventData.data2, OMX_ALL);
710 }
711
712 // set state to idle
713 ASSERT_NO_FATAL_FAILURE(
714 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
715 // set state to loaded
716 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
717 &oBuffer, kPortIndexInput,
718 kPortIndexOutput));
719}
720
721// test port mode configuration when the component is in various states
722TEST_F(ComponentHidlTest, PortModeConfig) {
723 description("Test Port Mode Configuration");
724 if (disableTest) return;
725 android::hardware::media::omx::V1_0::Status status;
726 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
727 Message msg;
728
729 status = setRole(omxNode, gEnv->getRole().c_str());
730 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
731 OMX_PORT_PARAM_TYPE params;
732 if (compClass == audio_decoder || compClass == audio_encoder) {
733 status = getParam(omxNode, OMX_IndexParamAudioInit, &params);
734 } else {
735 status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
736 }
737 if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
738 ASSERT_EQ(params.nPorts, 2U);
739 kPortIndexInput = params.nStartPortNumber;
740 kPortIndexOutput = kPortIndexInput + 1;
741 }
742
743 android::Vector<BufferInfo> iBuffer, oBuffer;
744
745 // set port mode
746 PortMode portMode[2];
747 initPortMode(portMode, isSecure, compClass);
748 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
749 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
750 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
751 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
752
753 // set state to idle
754 ASSERT_NO_FATAL_FAILURE(
755 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
756 kPortIndexInput, kPortIndexOutput, portMode));
757 // Only Allow Port Mode configuration in loaded state
758 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
759 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
760 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
761 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
762
763 // set state to executing
764 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
765 // Only Allow Port Mode configuration in loaded state
766 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
767 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
768 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
769 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
770
771 // set state to idle
772 ASSERT_NO_FATAL_FAILURE(
773 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
774 // set state to loaded
775 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
776 &oBuffer, kPortIndexInput,
777 kPortIndexOutput));
778
779 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
614 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 780 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
615 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 781 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
616 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 782 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
783}
784
785// state transitions test
786TEST_F(ComponentHidlTest, StateTransitions) {
787 description("Test State Transitions Loaded<->Idle<->Execute");
788 if (disableTest) return;
789 android::hardware::media::omx::V1_0::Status status;
790 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
791 OMX_U32 portBase = 0;
792 Message msg;
793 status = setRole(omxNode, gEnv->getRole().c_str());
794 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
795 OMX_PORT_PARAM_TYPE params;
796 if (compClass == audio_decoder || compClass == audio_encoder) {
797 status = getParam(omxNode, OMX_IndexParamAudioInit, &params);
798 } else {
799 status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
800 }
801 if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
802 ASSERT_EQ(params.nPorts, 2U);
803 portBase = params.nStartPortNumber;
804 }
805 kPortIndexInput = portBase;
806 kPortIndexOutput = portBase + 1;
807
808 android::Vector<BufferInfo> pBuffer[2];
809
810 // set port mode
811 PortMode portMode[2];
812 initPortMode(portMode, isSecure, compClass);
813 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
814 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
815 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
816 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
817
818 // set state to idle
819 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
820 OMX_StateIdle);
821 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
822
823 for (size_t j = portBase; j < portBase + 2; j++) {
824 pBuffer[j - portBase].clear();
617 825
826 OMX_PARAM_PORTDEFINITIONTYPE def;
827 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, j, &def);
828 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
829
830 for (size_t i = 0; i < def.nBufferCountActual; i++) {
831 // Dont switch states until the ports are populated
832 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
833 &pBuffer[0], &pBuffer[1]);
834 ASSERT_EQ(status,
835 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
836
837 BufferInfo buffer;
838 ASSERT_NO_FATAL_FAILURE(allocateBuffer(
839 omxNode, &buffer, j, def.nBufferSize, portMode[j - portBase]));
840 pBuffer[j - portBase].push(buffer);
841 }
842 }
843
844 // As the ports are populated, check if the state transition is complete
845 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0],
846 &pBuffer[1]);
847 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
848 ASSERT_EQ(msg.type, Message::Type::EVENT);
849 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
850 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet);
851 ASSERT_EQ(msg.data.eventData.data2, OMX_StateIdle);
852
853 // set state to executing
854 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
855 // dispatch buffers
856 for (size_t i = 0; i < pBuffer[1].size(); i++) {
857 ASSERT_NO_FATAL_FAILURE(
858 dispatchOutputBuffer(omxNode, &pBuffer[1], i, portMode[1]));
859 }
618 // set state to idle 860 // set state to idle
619 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 861 ASSERT_NO_FATAL_FAILURE(
620 kPortIndexInput, kPortIndexOutput, portMode); 862 changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]));
863#if 0
621 // set state to executing 864 // set state to executing
622 changeStateIdletoExecute(omxNode, observer); 865 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
866 // TODO: Sending empty input buffers is slightly tricky.
623 // dispatch buffers 867 // dispatch buffers
624 for (size_t i = 0; i < oBuffer.size(); i++) { 868 for (size_t i = 0; i < pBuffer[0].size(); i++) {
625 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]); 869 ASSERT_NO_FATAL_FAILURE(
870 dispatchInputBuffer(omxNode, &pBuffer[0], i, 0, 0, 0, portMode[0]));
626 } 871 }
627 // set state to idle 872 // set state to idle
628 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 873 ASSERT_NO_FATAL_FAILURE(
629 // // set state to executing 874 changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]));
630 // changeStateIdletoExecute(omxNode, observer); 875#endif
631 // // TODO: Sending empty input buffers is slightly tricky. 876
632 // // dispatch buffers
633 // for (size_t i = 0; i < iBuffer.size(); i++) {
634 // dispatchInputBuffer(omxNode, &iBuffer, i, 0, 0, 0, portMode[0]);
635 // }
636 // // set state to idle
637 // changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
638 // set state to loaded 877 // set state to loaded
639 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 878 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
640 kPortIndexInput, kPortIndexOutput); 879 OMX_StateLoaded);
880 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
881
882 for (size_t j = portBase; j < portBase + 2; j++) {
883 for (size_t i = 0; i < pBuffer[j].size(); ++i) {
884 // Dont switch states until the ports are populated
885 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
886 &pBuffer[0], &pBuffer[1]);
887 ASSERT_EQ(status,
888 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
889
890 status = omxNode->freeBuffer(j, pBuffer[j][i].id);
891 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
892 }
893 }
894
895 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0],
896 &pBuffer[1]);
897 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
898 ASSERT_EQ(msg.type, Message::Type::EVENT);
899 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
900 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet);
901 ASSERT_EQ(msg.data.eventData.data2, OMX_StateLoaded);
641} 902}
642 903
643// state transitions test - monkeying 904// state transitions test - monkeying
@@ -675,8 +936,9 @@ TEST_F(ComponentHidlTest, DISABLED_StateTransitions_M) {
675 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK); 936 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
676 937
677 // set state to idle 938 // set state to idle
678 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 939 ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(omxNode, observer, &iBuffer,
679 kPortIndexInput, kPortIndexOutput); 940 &oBuffer, kPortIndexInput,
941 kPortIndexOutput));
680 942
681 // set state to idle ; receive error OMX_ErrorSameState 943 // set state to idle ; receive error OMX_ErrorSameState
682 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), 944 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
@@ -684,7 +946,7 @@ TEST_F(ComponentHidlTest, DISABLED_StateTransitions_M) {
684 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK); 946 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
685 947
686 // set state to executing 948 // set state to executing
687 changeStateIdletoExecute(omxNode, observer); 949 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
688 950
689 // set state to executing ; receive error OMX_ErrorSameState 951 // set state to executing ; receive error OMX_ErrorSameState
690 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), 952 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
@@ -696,12 +958,13 @@ TEST_F(ComponentHidlTest, DISABLED_StateTransitions_M) {
696 OMX_StateLoaded); 958 OMX_StateLoaded);
697 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK); 959 EXPECT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
698 960
699 // set state to Idle 961 // set state to idle
700 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 962 ASSERT_NO_FATAL_FAILURE(
701 963 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
702 // set state to Loaded 964 // set state to loaded
703 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 965 ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
704 kPortIndexInput, kPortIndexOutput); 966 &oBuffer, kPortIndexInput,
967 kPortIndexOutput));
705} 968}
706 969
707// port enable disable test 970// port enable disable test
@@ -784,14 +1047,14 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Idle) {
784 PortMode portMode[2]; 1047 PortMode portMode[2];
785 initPortMode(portMode, isSecure, compClass); 1048 initPortMode(portMode, isSecure, compClass);
786 status = omxNode->setPortMode(kPortIndexInput, portMode[0]); 1049 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
787 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1050 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
788 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 1051 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
789 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1052 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
790 1053
791 // set state to idle 1054 // set state to idle
792 changeStateLoadedtoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1], 1055 ASSERT_NO_FATAL_FAILURE(
793 kPortIndexInput, kPortIndexOutput, portMode); 1056 changeStateLoadedtoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1],
794 1057 kPortIndexInput, kPortIndexOutput, portMode));
795 for (size_t i = portBase; i < portBase + 2; i++) { 1058 for (size_t i = portBase; i < portBase + 2; i++) {
796 status = 1059 status =
797 omxNode->sendCommand(toRawCommandType(OMX_CommandPortDisable), i); 1060 omxNode->sendCommand(toRawCommandType(OMX_CommandPortDisable), i);
@@ -839,8 +1102,8 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Idle) {
839 ASSERT_EQ(status, 1102 ASSERT_EQ(status,
840 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 1103 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
841 1104
842 allocatePortBuffers(omxNode, &pBuffer[i - portBase], i, 1105 ASSERT_NO_FATAL_FAILURE(allocatePortBuffers(
843 portMode[i - portBase]); 1106 omxNode, &pBuffer[i - portBase], i, portMode[i - portBase]));
844 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, 1107 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
845 &pBuffer[0], &pBuffer[1]); 1108 &pBuffer[0], &pBuffer[1]);
846 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); 1109 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
@@ -854,8 +1117,9 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Idle) {
854 } 1117 }
855 1118
856 // set state to Loaded 1119 // set state to Loaded
857 changeStateIdletoLoaded(omxNode, observer, &pBuffer[0], &pBuffer[1], 1120 ASSERT_NO_FATAL_FAILURE(
858 kPortIndexInput, kPortIndexOutput); 1121 changeStateIdletoLoaded(omxNode, observer, &pBuffer[0], &pBuffer[1],
1122 kPortIndexInput, kPortIndexOutput));
859} 1123}
860 1124
861// port enable disable test 1125// port enable disable test
@@ -888,20 +1152,20 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Execute) {
888 PortMode portMode[2]; 1152 PortMode portMode[2];
889 initPortMode(portMode, isSecure, compClass); 1153 initPortMode(portMode, isSecure, compClass);
890 status = omxNode->setPortMode(kPortIndexInput, portMode[0]); 1154 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
891 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1155 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
892 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 1156 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
893 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1157 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
894 1158
895 // set state to idle 1159 // set state to idle
896 changeStateLoadedtoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1], 1160 ASSERT_NO_FATAL_FAILURE(
897 kPortIndexInput, kPortIndexOutput, portMode); 1161 changeStateLoadedtoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1],
898 1162 kPortIndexInput, kPortIndexOutput, portMode));
899 // set state to executing 1163 // set state to executing
900 changeStateIdletoExecute(omxNode, observer); 1164 ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
901
902 // dispatch buffers 1165 // dispatch buffers
903 for (size_t i = 0; i < pBuffer[1].size(); i++) { 1166 for (size_t i = 0; i < pBuffer[1].size(); i++) {
904 dispatchOutputBuffer(omxNode, &pBuffer[1], i, portMode[1]); 1167 ASSERT_NO_FATAL_FAILURE(
1168 dispatchOutputBuffer(omxNode, &pBuffer[1], i, portMode[1]));
905 } 1169 }
906 1170
907 for (size_t i = portBase; i < portBase + 2; i++) { 1171 for (size_t i = portBase; i < portBase + 2; i++) {
@@ -954,8 +1218,8 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Execute) {
954 ASSERT_EQ(status, 1218 ASSERT_EQ(status,
955 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 1219 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
956 1220
957 allocatePortBuffers(omxNode, &pBuffer[i - portBase], i, 1221 ASSERT_NO_FATAL_FAILURE(allocatePortBuffers(
958 portMode[i - portBase]); 1222 omxNode, &pBuffer[i - portBase], i, portMode[i - portBase]));
959 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, 1223 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
960 &pBuffer[0], &pBuffer[1]); 1224 &pBuffer[0], &pBuffer[1]);
961 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); 1225 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
@@ -968,12 +1232,13 @@ TEST_F(ComponentHidlTest, PortEnableDisable_Execute) {
968 } 1232 }
969 } 1233 }
970 1234
971 // set state to Idle 1235 // set state to idle
972 changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]); 1236 ASSERT_NO_FATAL_FAILURE(
973 1237 changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]));
974 // set state to Loaded 1238 // set state to loaded
975 changeStateIdletoLoaded(omxNode, observer, &pBuffer[0], &pBuffer[1], 1239 ASSERT_NO_FATAL_FAILURE(
976 kPortIndexInput, kPortIndexOutput); 1240 changeStateIdletoLoaded(omxNode, observer, &pBuffer[0], &pBuffer[1],
1241 kPortIndexInput, kPortIndexOutput));
977} 1242}
978 1243
979// port enable disable test - monkeying 1244// port enable disable test - monkeying
diff --git a/media/omx/1.0/vts/functional/master/Android.bp b/media/omx/1.0/vts/functional/master/Android.bp
index e24b79b8..4a45e692 100644
--- a/media/omx/1.0/vts/functional/master/Android.bp
+++ b/media/omx/1.0/vts/functional/master/Android.bp
@@ -16,29 +16,7 @@
16 16
17cc_test { 17cc_test {
18 name: "VtsHalMediaOmxV1_0TargetMasterTest", 18 name: "VtsHalMediaOmxV1_0TargetMasterTest",
19 defaults: ["hidl_defaults"], 19 defaults: ["VtsHalMediaOmxV1_0Defaults"],
20 srcs: ["VtsHalMediaOmxV1_0TargetMasterTest.cpp"], 20 srcs: ["VtsHalMediaOmxV1_0TargetMasterTest.cpp"],
21 shared_libs: [
22 "libbase",
23 "liblog",
24 "libcutils",
25 "libhidlbase",
26 "libhidltransport",
27 "libhwbinder",
28 "libnativehelper",
29 "libutils",
30 "android.hidl.allocator@1.0",
31 "android.hidl.memory@1.0",
32 "android.hardware.media.omx@1.0",
33 ],
34 static_libs: ["VtsHalHidlTargetTestBase"],
35 cflags: [
36 "-O0",
37 "-g",
38 ],
39 include_dirs: [
40 "frameworks/native/include/media/openmax/",
41 "hardware/interfaces/media/omx/1.0/vts/functional/common",
42 ],
43} 21}
44 22
diff --git a/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp b/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
index e8f5f77d..5a31d691 100644
--- a/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
+++ b/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
@@ -15,6 +15,10 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_master_test" 17#define LOG_TAG "media_omx_hidl_master_test"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
@@ -146,6 +150,7 @@ TEST_F(MasterHidlTest, ListServiceAttr) {
146 attributes = _nl; 150 attributes = _nl;
147 }) 151 })
148 .isOk()); 152 .isOk());
153 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
149 if (attributes.size() == 0) ALOGV("Warning, Attribute list empty"); 154 if (attributes.size() == 0) ALOGV("Warning, Attribute list empty");
150} 155}
151 156
@@ -182,6 +187,7 @@ TEST_F(MasterHidlTest, ListNodes) {
182 nodeList = _nl; 187 nodeList = _nl;
183 }) 188 })
184 .isOk()); 189 .isOk());
190 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
185 if (nodeList.size() == 0) 191 if (nodeList.size() == 0)
186 ALOGV("Warning, ComponentInfo list empty"); 192 ALOGV("Warning, ComponentInfo list empty");
187 else { 193 else {
@@ -200,6 +206,7 @@ TEST_F(MasterHidlTest, ListNodes) {
200 omxNode = _nl; 206 omxNode = _nl;
201 }) 207 })
202 .isOk()); 208 .isOk());
209 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
203 if (omxNode == nullptr) { 210 if (omxNode == nullptr) {
204 isPass = false; 211 isPass = false;
205 std::cerr << "[ !OK ] " << nodeList[i].mName.c_str() 212 std::cerr << "[ !OK ] " << nodeList[i].mName.c_str()
diff --git a/media/omx/1.0/vts/functional/video/Android.bp b/media/omx/1.0/vts/functional/video/Android.bp
index 4e94f3b3..f0da2b39 100644
--- a/media/omx/1.0/vts/functional/video/Android.bp
+++ b/media/omx/1.0/vts/functional/video/Android.bp
@@ -16,70 +16,21 @@
16 16
17cc_test { 17cc_test {
18 name: "VtsHalMediaOmxV1_0TargetVideoDecTest", 18 name: "VtsHalMediaOmxV1_0TargetVideoDecTest",
19 defaults: ["hidl_defaults"], 19 defaults: ["VtsHalMediaOmxV1_0Defaults"],
20 srcs: ["VtsHalMediaOmxV1_0TargetVideoDecTest.cpp", 20 srcs: [
21 "media_video_hidl_test_common.cpp"], 21 "VtsHalMediaOmxV1_0TargetVideoDecTest.cpp",
22 shared_libs: [ 22 "media_video_hidl_test_common.cpp"
23 "libbase",
24 "liblog",
25 "libcutils",
26 "libhidlbase",
27 "libhidlmemory",
28 "libhidltransport",
29 "libhwbinder",
30 "libnativehelper",
31 "libutils",
32 "libstagefright_foundation",
33 "android.hidl.allocator@1.0",
34 "android.hidl.memory@1.0",
35 "android.hardware.media.omx@1.0",
36 "android.hardware.graphics.allocator@2.0",
37 "android.hardware.graphics.mapper@2.0",
38 "android.hardware.graphics.common@1.0",
39 ],
40 static_libs: ["VtsHalHidlTargetTestBase",
41 "VtsHalMediaOmxV1_0CommonUtil"],
42 cflags: [
43 "-O0",
44 "-g",
45 ],
46 include_dirs: [
47 "frameworks/native/include/media/openmax/",
48 "hardware/interfaces/media/omx/1.0/vts/functional/common",
49 ], 23 ],
50} 24}
51 25
52cc_test { 26cc_test {
53 name: "VtsHalMediaOmxV1_0TargetVideoEncTest", 27 name: "VtsHalMediaOmxV1_0TargetVideoEncTest",
54 defaults: ["hidl_defaults"], 28 defaults: ["VtsHalMediaOmxV1_0Defaults"],
55 srcs: ["VtsHalMediaOmxV1_0TargetVideoEncTest.cpp", 29 srcs: [
56 "media_video_hidl_test_common.cpp"], 30 "VtsHalMediaOmxV1_0TargetVideoEncTest.cpp",
57 shared_libs: [ 31 "media_video_hidl_test_common.cpp"
58 "libbase",
59 "liblog",
60 "libcutils",
61 "libhidlbase",
62 "libhidlmemory",
63 "libhidltransport",
64 "libhwbinder",
65 "libnativehelper",
66 "libnativewindow",
67 "libutils",
68 "libstagefright_foundation",
69 "android.hidl.allocator@1.0",
70 "android.hidl.memory@1.0",
71 "android.hardware.media.omx@1.0",
72 "android.hardware.graphics.bufferqueue@1.0",
73 "android.hardware.graphics.mapper@2.0",
74 ], 32 ],
75 static_libs: ["VtsHalHidlTargetTestBase", 33 static_libs: [
76 "VtsHalMediaOmxV1_0CommonUtil"], 34 "libnativewindow",
77 cflags: [
78 "-O0",
79 "-g",
80 ],
81 include_dirs: [
82 "frameworks/native/include/media/openmax/",
83 "hardware/interfaces/media/omx/1.0/vts/functional/common",
84 ], 35 ],
85} 36}
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
index 438dd707..9b74a339 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
@@ -15,11 +15,12 @@
15 */ 15 */
16 16
17#define LOG_TAG "media_omx_hidl_video_dec_test" 17#define LOG_TAG "media_omx_hidl_video_dec_test"
18#ifdef __LP64__
19#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20#endif
21
18#include <android-base/logging.h> 22#include <android-base/logging.h>
19 23
20#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
21#include <android/hardware/graphics/mapper/2.0/IMapper.h>
22#include <android/hardware/graphics/mapper/2.0/types.h>
23#include <android/hardware/media/omx/1.0/IOmx.h> 24#include <android/hardware/media/omx/1.0/IOmx.h>
24#include <android/hardware/media/omx/1.0/IOmxNode.h> 25#include <android/hardware/media/omx/1.0/IOmxNode.h>
25#include <android/hardware/media/omx/1.0/IOmxObserver.h> 26#include <android/hardware/media/omx/1.0/IOmxObserver.h>
@@ -28,8 +29,6 @@
28#include <android/hidl/memory/1.0/IMapper.h> 29#include <android/hidl/memory/1.0/IMapper.h>
29#include <android/hidl/memory/1.0/IMemory.h> 30#include <android/hidl/memory/1.0/IMemory.h>
30 31
31using ::android::hardware::graphics::common::V1_0::BufferUsage;
32using ::android::hardware::graphics::common::V1_0::PixelFormat;
33using ::android::hardware::media::omx::V1_0::IOmx; 32using ::android::hardware::media::omx::V1_0::IOmx;
34using ::android::hardware::media::omx::V1_0::IOmxObserver; 33using ::android::hardware::media::omx::V1_0::IOmxObserver;
35using ::android::hardware::media::omx::V1_0::IOmxNode; 34using ::android::hardware::media::omx::V1_0::IOmxNode;
@@ -47,6 +46,7 @@ using ::android::sp;
47 46
48#include <VtsHalHidlTargetTestBase.h> 47#include <VtsHalHidlTargetTestBase.h>
49#include <getopt.h> 48#include <getopt.h>
49#include <media/hardware/HardwareAPI.h>
50#include <media_hidl_test_common.h> 50#include <media_hidl_test_common.h>
51#include <media_video_hidl_test_common.h> 51#include <media_video_hidl_test_common.h>
52#include <fstream> 52#include <fstream>
@@ -166,6 +166,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
166 this->omxNode = _nl; 166 this->omxNode = _nl;
167 }) 167 })
168 .isOk()); 168 .isOk());
169 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
169 ASSERT_NE(omxNode, nullptr); 170 ASSERT_NE(omxNode, nullptr);
170 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role"; 171 ASSERT_NE(gEnv->getRole().empty(), true) << "Invalid Component Role";
171 struct StringToName { 172 struct StringToName {
@@ -217,6 +218,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
217 timestampUs = 0; 218 timestampUs = 0;
218 timestampDevTest = false; 219 timestampDevTest = false;
219 isSecure = false; 220 isSecure = false;
221 portSettingsChange = false;
220 size_t suffixLen = strlen(".secure"); 222 size_t suffixLen = strlen(".secure");
221 if (strlen(gEnv->getComponent().c_str()) >= suffixLen) { 223 if (strlen(gEnv->getComponent().c_str()) >= suffixLen) {
222 isSecure = 224 isSecure =
@@ -225,11 +227,15 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
225 ".secure"); 227 ".secure");
226 } 228 }
227 if (isSecure) disableTest = true; 229 if (isSecure) disableTest = true;
228 if (disableTest) std::cout << "[ ] Warning ! Test Disabled\n"; 230 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
229 } 231 }
230 232
231 virtual void TearDown() override { 233 virtual void TearDown() override {
232 if (omxNode != nullptr) { 234 if (omxNode != nullptr) {
235 // If you have encountered a fatal failure, it is possible that
236 // freeNode() will not go through. Instead of hanging the app.
237 // let it pass through and report errors
238 if (::testing::Test::HasFatalFailure()) return;
233 EXPECT_TRUE((omxNode->freeNode()).isOk()); 239 EXPECT_TRUE((omxNode->freeNode()).isOk());
234 omxNode = nullptr; 240 omxNode = nullptr;
235 } 241 }
@@ -269,9 +275,8 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
269 EXPECT_EQ(tsHit, true) 275 EXPECT_EQ(tsHit, true)
270 << "TimeStamp not recognized"; 276 << "TimeStamp not recognized";
271 } else { 277 } else {
272 std::cout 278 std::cout << "[ INFO ] Received non-zero "
273 << "[ ] Warning ! Received non-zero " 279 "output / TimeStamp not recognized \n";
274 "output / TimeStamp not recognized \n";
275 } 280 }
276 } 281 }
277 } 282 }
@@ -293,6 +298,13 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
293 } 298 }
294#endif 299#endif
295 } 300 }
301 } else if (msg.type == Message::Type::EVENT) {
302 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
303 if ((msg.data.eventData.data2 == OMX_IndexParamPortDefinition ||
304 msg.data.eventData.data2 == 0)) {
305 portSettingsChange = true;
306 }
307 }
296 } 308 }
297 } 309 }
298 310
@@ -320,6 +332,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
320 ::android::List<uint64_t> timestampUslist; 332 ::android::List<uint64_t> timestampUslist;
321 bool timestampDevTest; 333 bool timestampDevTest;
322 bool isSecure; 334 bool isSecure;
335 bool portSettingsChange;
323 336
324 protected: 337 protected:
325 static void description(const std::string& description) { 338 static void description(const std::string& description) {
@@ -367,119 +380,61 @@ void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
367 } 380 }