summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-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.cpp104
-rw-r--r--media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp62
-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--media/omx/1.0/vts/functional/common/Android.bp39
-rw-r--r--media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp244
-rw-r--r--media/omx/1.0/vts/functional/common/media_hidl_test_common.h55
-rw-r--r--media/omx/1.0/vts/functional/component/Android.bp27
-rw-r--r--media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp349
-rw-r--r--media/omx/1.0/vts/functional/master/Android.bp24
-rw-r--r--media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp4
-rw-r--r--media/omx/1.0/vts/functional/video/Android.bp69
-rw-r--r--media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp428
-rw-r--r--media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp119
-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
-rw-r--r--[-rwxr-xr-x]media/res/bbb_aac_stereo_128kbps_48000hz.aacbin159216 -> 159216 bytes
-rw-r--r--[-rwxr-xr-x]media/res/bbb_aac_stereo_128kbps_48000hz.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_amrwb_1ch_14kbps_16000hz.amrwbbin20254 -> 20254 bytes
-rw-r--r--[-rwxr-xr-x]media/res/bbb_amrwb_1ch_14kbps_16000hz.info0
-rw-r--r--media/res/bbb_avc_176x144_300kbps_60fps.h264bin0 -> 37899 bytes
-rw-r--r--media/res/bbb_avc_176x144_300kbps_60fps.info62
-rw-r--r--media/res/bbb_flac_stereo_680kbps_48000hz.flacbin0 -> 840775 bytes
-rw-r--r--media/res/bbb_flac_stereo_680kbps_48000hz.info415
-rw-r--r--[-rwxr-xr-x]media/res/bbb_g711alaw_1ch_8khz.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_g711alaw_1ch_8khz.raw0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_g711mulaw_1ch_8khz.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_g711mulaw_1ch_8khz.raw0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_gsm_1ch_8khz_13kbps.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_gsm_1ch_8khz_13kbps.rawbin16120 -> 16120 bytes
-rw-r--r--media/res/bbb_hevc_176x144_176kbps_60fps.hevcbin0 -> 20503 bytes
-rw-r--r--media/res/bbb_hevc_176x144_176kbps_60fps.info61
-rw-r--r--media/res/bbb_mpeg2_352x288_1mbps_60fps.info60
-rw-r--r--media/res/bbb_mpeg2_352x288_1mbps_60fps.m2vbin0 -> 123976 bytes
-rw-r--r--[-rwxr-xr-x]media/res/bbb_opus_stereo_128kbps_48000hz.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_opus_stereo_128kbps_48000hz.opusbin163743 -> 163743 bytes
-rw-r--r--[-rwxr-xr-x]media/res/bbb_raw_1ch_8khz_s32le.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_raw_1ch_8khz_s32le.rawbin158380 -> 158380 bytes
-rw-r--r--[-rwxr-xr-x]media/res/bbb_vorbis_stereo_128kbps_48000hz.info0
-rw-r--r--[-rwxr-xr-x]media/res/bbb_vorbis_stereo_128kbps_48000hz.vorbisbin147450 -> 147450 bytes
-rw-r--r--media/res/bbb_vp8_176x144_240kbps_60fps.info60
-rw-r--r--media/res/bbb_vp8_176x144_240kbps_60fps.vp8bin0 -> 28992 bytes
-rw-r--r--media/res/bbb_vp9_176x144_285kbps_60fps.info60
-rw-r--r--media/res/bbb_vp9_176x144_285kbps_60fps.vp9bin0 -> 34848 bytes
46 files changed, 1638 insertions, 688 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 1aae7bc3..11614449 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>
@@ -171,7 +175,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
171 {"mp3", mp3}, {"amrnb", amrnb}, {"amrwb", amrwb}, 175 {"mp3", mp3}, {"amrnb", amrnb}, {"amrwb", amrwb},
172 {"aac", aac}, {"vorbis", vorbis}, {"opus", opus}, 176 {"aac", aac}, {"vorbis", vorbis}, {"opus", opus},
173 {"pcm", pcm}, {"g711alaw", g711alaw}, {"g711mlaw", g711mlaw}, 177 {"pcm", pcm}, {"g711alaw", g711alaw}, {"g711mlaw", g711mlaw},
174 {"gsm", gsm}, {"raw", raw}, 178 {"gsm", gsm}, {"raw", raw}, {"flac", flac},
175 }; 179 };
176 const size_t kNumStringToName = 180 const size_t kNumStringToName =
177 sizeof(kStringToName) / sizeof(kStringToName[0]); 181 sizeof(kStringToName) / sizeof(kStringToName[0]);
@@ -204,6 +208,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
204 {g711mlaw, OMX_AUDIO_CodingG711}, 208 {g711mlaw, OMX_AUDIO_CodingG711},
205 {gsm, OMX_AUDIO_CodingGSMFR}, 209 {gsm, OMX_AUDIO_CodingGSMFR},
206 {raw, OMX_AUDIO_CodingPCM}, 210 {raw, OMX_AUDIO_CodingPCM},
211 {flac, OMX_AUDIO_CodingFLAC},
207 }; 212 };
208 static const size_t kNumCompToCoding = 213 static const size_t kNumCompToCoding =
209 sizeof(kCompToCoding) / sizeof(kCompToCoding[0]); 214 sizeof(kCompToCoding) / sizeof(kCompToCoding[0]);
@@ -219,7 +224,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
219 framesReceived = 0; 224 framesReceived = 0;
220 timestampUs = 0; 225 timestampUs = 0;
221 timestampDevTest = false; 226 timestampDevTest = false;
222 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 227 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
223 } 228 }
224 229
225 virtual void TearDown() override { 230 virtual void TearDown() override {
@@ -263,9 +268,8 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
263 EXPECT_EQ(tsHit, true) 268 EXPECT_EQ(tsHit, true)
264 << "TimeStamp not recognized"; 269 << "TimeStamp not recognized";
265 } else { 270 } else {
266 std::cerr 271 std::cout << "[ INFO ] Received non-zero "
267 << "[ ] Warning ! Received non-zero " 272 "output / TimeStamp not recognized \n";
268 "output / TimeStamp not recognized \n";
269 } 273 }
270 } 274 }
271 } 275 }
@@ -301,6 +305,7 @@ class AudioDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
301 g711mlaw, 305 g711mlaw,
302 gsm, 306 gsm,
303 raw, 307 raw,
308 flac,
304 unknown_comp, 309 unknown_comp,
305 }; 310 };
306 311
@@ -431,6 +436,16 @@ void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
431 *nSampleRate = param.nSampleRate; 436 *nSampleRate = param.nSampleRate;
432 break; 437 break;
433 } 438 }
439 case OMX_AUDIO_CodingFLAC: {
440 OMX_AUDIO_PARAM_FLACTYPE param;
441 status = getPortParam(omxNode, OMX_IndexParamAudioFlac,
442 kPortIndexInput, &param);
443 ASSERT_EQ(status,
444 ::android::hardware::media::omx::V1_0::Status::OK);
445 *nChannels = param.nChannels;
446 *nSampleRate = param.nSampleRate;
447 break;
448 }
434 default: 449 default:
435 ASSERT_TRUE(false); 450 ASSERT_TRUE(false);
436 break; 451 break;
@@ -472,6 +487,9 @@ void GetURLForComponent(AudioDecHidlTest::standardComp comp, char* mURL,
472 "bbb_gsm_1ch_8khz_13kbps.info"}, 487 "bbb_gsm_1ch_8khz_13kbps.info"},
473 {AudioDecHidlTest::standardComp::raw, "bbb_raw_1ch_8khz_s32le.raw", 488 {AudioDecHidlTest::standardComp::raw, "bbb_raw_1ch_8khz_s32le.raw",
474 "bbb_raw_1ch_8khz_s32le.info"}, 489 "bbb_raw_1ch_8khz_s32le.info"},
490 {AudioDecHidlTest::standardComp::flac,
491 "bbb_flac_stereo_680kbps_48000hz.flac",
492 "bbb_flac_stereo_680kbps_48000hz.info"},
475 }; 493 };
476 494
477 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) { 495 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
@@ -588,12 +606,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
588 AudioDecHidlTest::standardComp comp) { 606 AudioDecHidlTest::standardComp comp) {
589 android::hardware::media::omx::V1_0::Status status; 607 android::hardware::media::omx::V1_0::Status status;
590 Message msg; 608 Message msg;
591 int timeOut = TIMEOUT_COUNTER; 609 int timeOut = TIMEOUT_COUNTER_Q;
592 610
593 while (timeOut--) { 611 while (timeOut--) {
594 size_t i = 0; 612 size_t i = 0;
595 status = 613 status =
596 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 614 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
597 if (status == android::hardware::media::omx::V1_0::Status::OK) { 615 if (status == android::hardware::media::omx::V1_0::Status::OK) {
598 EXPECT_EQ(msg.type, Message::Type::EVENT); 616 EXPECT_EQ(msg.type, Message::Type::EVENT);
599 packedArgs audioArgs = {eEncoding, comp}; 617 packedArgs audioArgs = {eEncoding, comp};
@@ -613,8 +631,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
613 size_t index; 631 size_t index;
614 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 632 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
615 dispatchOutputBuffer(omxNode, oBuffer, index); 633 dispatchOutputBuffer(omxNode, oBuffer, index);
634 timeOut = TIMEOUT_COUNTER_Q;
616 } 635 }
617 timeOut--;
618 } 636 }
619} 637}
620 638
@@ -628,38 +646,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
628 AudioDecHidlTest::standardComp comp, bool signalEOS = true) { 646 AudioDecHidlTest::standardComp comp, bool signalEOS = true) {
629 android::hardware::media::omx::V1_0::Status status; 647 android::hardware::media::omx::V1_0::Status status;
630 Message msg; 648 Message msg;
631 649 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; 650 uint32_t flags = 0;
638 int frameID = offset; 651 int frameID = offset;
639 for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) && 652 int timeOut = TIMEOUT_COUNTER_Q;
640 (frameID < (offset + range)); 653 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 654
657 int timeOut = TIMEOUT_COUNTER;
658 bool stall = false;
659 while (1) { 655 while (1) {
656 iQueued = oQueued = false;
660 status = 657 status =
661 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 658 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
662
663 // Port Reconfiguration 659 // Port Reconfiguration
664 if (status == android::hardware::media::omx::V1_0::Status::OK && 660 if (status == android::hardware::media::omx::V1_0::Status::OK &&
665 msg.type == Message::Type::EVENT) { 661 msg.type == Message::Type::EVENT) {
@@ -672,7 +668,6 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
672 if (frameID == (int)Info->size() || frameID == (offset + range)) break; 668 if (frameID == (int)Info->size() || frameID == (offset + range)) break;
673 669
674 // Dispatch input buffer 670 // Dispatch input buffer
675 size_t index = 0;
676 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 671 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
677 char* ipBuffer = static_cast<char*>( 672 char* ipBuffer = static_cast<char*>(
678 static_cast<void*>((*iBuffer)[index].mMemory->getPointer())); 673 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -681,6 +676,11 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
681 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount); 676 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
682 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount); 677 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
683 flags = (*Info)[frameID].flags; 678 flags = (*Info)[frameID].flags;
679 // Indicate to omx core that the buffer contains a full frame worth
680 // of data
681 flags |= OMX_BUFFERFLAG_ENDOFFRAME;
682 // Indicate the omx core that this is the last buffer it needs to
683 // process
684 if (signalEOS && ((frameID == (int)Info->size() - 1) || 684 if (signalEOS && ((frameID == (int)Info->size() - 1) ||
685 (frameID == (offset + range - 1)))) 685 (frameID == (offset + range - 1))))
686 flags |= OMX_BUFFERFLAG_EOS; 686 flags |= OMX_BUFFERFLAG_EOS;
@@ -688,18 +688,18 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
688 (*Info)[frameID].bytesCount, flags, 688 (*Info)[frameID].bytesCount, flags,
689 (*Info)[frameID].timestamp); 689 (*Info)[frameID].timestamp);
690 frameID++; 690 frameID++;
691 stall = false; 691 iQueued = true;
692 } else 692 }
693 stall = true; 693 // Dispatch output buffer
694 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 694 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
695 dispatchOutputBuffer(omxNode, oBuffer, index); 695 dispatchOutputBuffer(omxNode, oBuffer, index);
696 stall = false; 696 oQueued = true;
697 } else 697 }
698 stall = true; 698 // Reset Counters when either input or output buffer is dispatched
699 if (stall) 699 if (iQueued || oQueued)
700 timeOut--; 700 timeOut = TIMEOUT_COUNTER_Q;
701 else 701 else
702 timeOut = TIMEOUT_COUNTER; 702 timeOut--;
703 if (timeOut == 0) { 703 if (timeOut == 0) {
704 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 704 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
705 break; 705 break;
@@ -717,7 +717,7 @@ TEST_F(AudioDecHidlTest, SetRole) {
717} 717}
718 718
719// port format enumeration 719// port format enumeration
720TEST_F(AudioDecHidlTest, DISABLED_EnumeratePortFormat) { 720TEST_F(AudioDecHidlTest, EnumeratePortFormat) {
721 description("Test Component on Mandatory Port Parameters (Port Format)"); 721 description("Test Component on Mandatory Port Parameters (Port Format)");
722 if (disableTest) return; 722 if (disableTest) return;
723 android::hardware::media::omx::V1_0::Status status; 723 android::hardware::media::omx::V1_0::Status status;
@@ -823,11 +823,7 @@ TEST_F(AudioDecHidlTest, DecodeTest) {
823} 823}
824 824
825// end of sequence test 825// end of sequence test
826// SPECIAL CASE; Sending Empty input EOS buffer is not supported across all 826TEST_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"); 827 description("Test end of stream monkeying");
832 if (disableTest) return; 828 if (disableTest) return;
833 android::hardware::media::omx::V1_0::Status status; 829 android::hardware::media::omx::V1_0::Status status;
@@ -1149,9 +1145,8 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1149 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding, 1145 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
1150 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0, 1146 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0,
1151 nFrames, compName, false); 1147 nFrames, compName, false);
1152 // Note: Assumes 200 ms is enough to end any decode call that started
1153 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1148 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1154 kPortIndexOutput, 200000); 1149 kPortIndexOutput);
1155 framesReceived = 0; 1150 framesReceived = 0;
1156 1151
1157 // Seek to next key frame and start decoding till the end 1152 // Seek to next key frame and start decoding till the end
@@ -1172,9 +1167,8 @@ TEST_F(AudioDecHidlTest, FlushTest) {
1172 kPortIndexInput, kPortIndexOutput, eleStream, &Info, 1167 kPortIndexInput, kPortIndexOutput, eleStream, &Info,
1173 index, Info.size() - index, compName, false); 1168 index, Info.size() - index, compName, false);
1174 } 1169 }
1175 // Note: Assumes 200 ms is enough to end any decode call that started
1176 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1170 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1177 kPortIndexOutput, 200000); 1171 kPortIndexOutput);
1178 framesReceived = 0; 1172 framesReceived = 0;
1179 1173
1180 // set state to idle 1174 // set state to idle
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..66c46371 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>
@@ -206,7 +210,7 @@ class AudioEncHidlTest : public ::testing::VtsHalHidlTargetTestBase {
206 } 210 }
207 if (i == kNumCompToCoding) disableTest = true; 211 if (i == kNumCompToCoding) disableTest = true;
208 eosFlag = false; 212 eosFlag = false;
209 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 213 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
210 } 214 }
211 215
212 virtual void TearDown() override { 216 virtual void TearDown() override {
@@ -342,12 +346,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
342 android::Vector<BufferInfo>* oBuffer) { 346 android::Vector<BufferInfo>* oBuffer) {
343 android::hardware::media::omx::V1_0::Status status; 347 android::hardware::media::omx::V1_0::Status status;
344 Message msg; 348 Message msg;
345 int timeOut = TIMEOUT_COUNTER; 349 int timeOut = TIMEOUT_COUNTER_Q;
346 350
347 while (timeOut--) { 351 while (timeOut--) {
348 size_t i = 0; 352 size_t i = 0;
349 status = 353 status =
350 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 354 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
351 EXPECT_EQ(status, 355 EXPECT_EQ(status,
352 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 356 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
353 // status == TIMED_OUT, it could be due to process time being large 357 // status == TIMED_OUT, it could be due to process time being large
@@ -362,8 +366,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
362 size_t index; 366 size_t index;
363 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 367 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
364 dispatchOutputBuffer(omxNode, oBuffer, index); 368 dispatchOutputBuffer(omxNode, oBuffer, index);
369 timeOut = TIMEOUT_COUNTER_Q;
365 } 370 }
366 timeOut--;
367 } 371 }
368} 372}
369 373
@@ -376,43 +380,25 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
376 bool signalEOS = true) { 380 bool signalEOS = true) {
377 android::hardware::media::omx::V1_0::Status status; 381 android::hardware::media::omx::V1_0::Status status;
378 Message msg; 382 Message msg;
379 383 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; 384 int bytesCount = samplesPerFrame * nChannels * 2;
386 int32_t timestampIncr = 385 int32_t timestampIncr =
387 (int)(((float)samplesPerFrame / nSampleRate) * 1000000); 386 (int)(((float)samplesPerFrame / nSampleRate) * 1000000);
388 uint64_t timestamp = 0; 387 uint64_t timestamp = 0;
389 uint32_t flags = 0; 388 uint32_t flags = 0;
390 for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) { 389 int timeOut = TIMEOUT_COUNTER_Q;
391 char* ipBuffer = static_cast<char*>( 390 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 391
403 int timeOut = TIMEOUT_COUNTER;
404 bool stall = false;
405 while (1) { 392 while (1) {
393 iQueued = oQueued = false;
406 status = 394 status =
407 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 395 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
408
409 if (status == android::hardware::media::omx::V1_0::Status::OK) 396 if (status == android::hardware::media::omx::V1_0::Status::OK)
410 ASSERT_TRUE(false); 397 ASSERT_TRUE(false);
411 398
412 if (nFrames == 0) break; 399 if (nFrames == 0) break;
413 400
414 // Dispatch input buffer 401 // Dispatch input buffer
415 size_t index = 0;
416 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 402 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
417 char* ipBuffer = static_cast<char*>( 403 char* ipBuffer = static_cast<char*>(
418 static_cast<void*>((*iBuffer)[index].mMemory->getPointer())); 404 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -420,24 +406,24 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
420 static_cast<int>((*iBuffer)[index].mMemory->getSize())); 406 static_cast<int>((*iBuffer)[index].mMemory->getSize()));
421 eleStream.read(ipBuffer, bytesCount); 407 eleStream.read(ipBuffer, bytesCount);
422 if (eleStream.gcount() != bytesCount) break; 408 if (eleStream.gcount() != bytesCount) break;
423 if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS; 409 flags = OMX_BUFFERFLAG_ENDOFFRAME;
410 if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
424 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags, 411 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
425 timestamp); 412 timestamp);
426 timestamp += timestampIncr; 413 timestamp += timestampIncr;
427 nFrames--; 414 nFrames--;
428 stall = false; 415 iQueued = true;
429 } else 416 }
430 stall = true;
431 // Dispatch output buffer 417 // Dispatch output buffer
432 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 418 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
433 dispatchOutputBuffer(omxNode, oBuffer, index); 419 dispatchOutputBuffer(omxNode, oBuffer, index);
434 stall = false; 420 oQueued = true;
435 } else 421 }
436 stall = true; 422 // Reset Counters when either input or output buffer is dispatched
437 if (stall) 423 if (iQueued || oQueued)
438 timeOut--; 424 timeOut = TIMEOUT_COUNTER_Q;
439 else 425 else
440 timeOut = TIMEOUT_COUNTER; 426 timeOut--;
441 if (timeOut == 0) { 427 if (timeOut == 0) {
442 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 428 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
443 break; 429 break;
@@ -455,7 +441,7 @@ TEST_F(AudioEncHidlTest, SetRole) {
455} 441}
456 442
457// port format enumeration 443// port format enumeration
458TEST_F(AudioEncHidlTest, DISABLED_EnumeratePortFormat) { 444TEST_F(AudioEncHidlTest, EnumeratePortFormat) {
459 description("Test Component on Mandatory Port Parameters (Port Format)"); 445 description("Test Component on Mandatory Port Parameters (Port Format)");
460 if (disableTest) return; 446 if (disableTest) return;
461 android::hardware::media::omx::V1_0::Status status; 447 android::hardware::media::omx::V1_0::Status status;
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 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..28616e21 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,156 @@ 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 EXPECT_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 EXPECT_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 int32_t nStride;
323 buffer->owner = client;
324 buffer->omxBuffer.type = CodecBuffer::Type::ANW_BUFFER;
325 allocateGraphicBuffers(omxNode, portIndex, buffer,
326 portDef.format.video.nFrameWidth,
327 portDef.format.video.nFrameHeight, &nStride,
328 portDef.format.video.eColorFormat);
329 omxNode->useBuffer(
330 portIndex, buffer->omxBuffer,
331 [&status, &buffer](android::hardware::media::omx::V1_0::Status _s,
332 uint32_t id) {
333 status = _s;
334 buffer->id = id;
335 });
336 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
337 }
338}
339
189// allocate buffers needed on a component port 340// allocate buffers needed on a component port
190void allocatePortBuffers(sp<IOmxNode> omxNode, 341void allocatePortBuffers(sp<IOmxNode> omxNode,
191 android::Vector<BufferInfo>* buffArray, 342 android::Vector<BufferInfo>* buffArray,
192 OMX_U32 portIndex, PortMode portMode) { 343 OMX_U32 portIndex, PortMode portMode, bool allocGrap) {
193 android::hardware::media::omx::V1_0::Status status; 344 android::hardware::media::omx::V1_0::Status status;
194 OMX_PARAM_PORTDEFINITIONTYPE portDef; 345 OMX_PARAM_PORTDEFINITIONTYPE portDef;
195 346
@@ -199,70 +350,18 @@ void allocatePortBuffers(sp<IOmxNode> omxNode,
199 &portDef); 350 &portDef);
200 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 351 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
201 352
202 if (portMode == PortMode::PRESET_SECURE_BUFFER) { 353 for (size_t i = 0; i < portDef.nBufferCountActual; i++) {
203 for (size_t i = 0; i < portDef.nBufferCountActual; i++) { 354 BufferInfo buffer;
204 BufferInfo buffer; 355 allocateBuffer(omxNode, &buffer, portIndex, portDef.nBufferSize,
205 buffer.owner = client; 356 portMode);
206 buffer.omxBuffer.type = CodecBuffer::Type::NATIVE_HANDLE; 357 if (allocGrap && portMode == PortMode::DYNAMIC_ANW_BUFFER) {
207 omxNode->allocateSecureBuffer( 358 int32_t nStride;
208 portIndex, portDef.nBufferSize, 359 allocateGraphicBuffers(omxNode, portIndex, &buffer,
209 [&status, &buffer]( 360 portDef.format.video.nFrameWidth,
210 android::hardware::media::omx::V1_0::Status _s, uint32_t id, 361 portDef.format.video.nFrameHeight, &nStride,
211 ::android::hardware::hidl_handle const& nativeHandle) { 362 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 } 363 }
364 buffArray->push(buffer);
266 } 365 }
267} 366}
268 367
@@ -273,7 +372,7 @@ void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
273 android::Vector<BufferInfo>* iBuffer, 372 android::Vector<BufferInfo>* iBuffer,
274 android::Vector<BufferInfo>* oBuffer, 373 android::Vector<BufferInfo>* oBuffer,
275 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput, 374 OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
276 PortMode* portMode) { 375 PortMode* portMode, bool allocGrap) {
277 android::hardware::media::omx::V1_0::Status status; 376 android::hardware::media::omx::V1_0::Status status;
278 Message msg; 377 Message msg;
279 PortMode defaultPortMode[2], *pm; 378 PortMode defaultPortMode[2], *pm;
@@ -292,14 +391,14 @@ void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
292 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT); 391 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
293 392
294 // allocate buffers on input port 393 // allocate buffers on input port
295 allocatePortBuffers(omxNode, iBuffer, kPortIndexInput, pm[0]); 394 allocatePortBuffers(omxNode, iBuffer, kPortIndexInput, pm[0], allocGrap);
296 395
297 // Dont switch states until the ports are populated 396 // Dont switch states until the ports are populated
298 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 397 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
299 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT); 398 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
300 399
301 // allocate buffers on output port 400 // allocate buffers on output port
302 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, pm[1]); 401 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, pm[1], allocGrap);
303 402
304 // As the ports are populated, check if the state transition is complete 403 // As the ports are populated, check if the state transition is complete
305 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 404 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
@@ -439,6 +538,7 @@ void dispatchOutputBuffer(sp<IOmxNode> omxNode,
439 status = 538 status =
440 omxNode->fillBuffer((*buffArray)[bufferIndex].id, t, fenceNh); 539 omxNode->fillBuffer((*buffArray)[bufferIndex].id, t, fenceNh);
441 break; 540 break;
541 case PortMode::PRESET_ANW_BUFFER:
442 case PortMode::PRESET_SECURE_BUFFER: 542 case PortMode::PRESET_SECURE_BUFFER:
443 case PortMode::PRESET_BYTE_BUFFER: 543 case PortMode::PRESET_BYTE_BUFFER:
444 t.sharedMemory = android::hardware::hidl_memory(); 544 t.sharedMemory = android::hardware::hidl_memory();
@@ -551,7 +651,7 @@ void testEOS(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
551 } 651 }
552 } 652 }
553 653
554 int timeOut = TIMEOUT_COUNTER; 654 int timeOut = TIMEOUT_COUNTER_PE;
555 while (timeOut--) { 655 while (timeOut--) {
556 // Dispatch all client owned output buffers to recover remaining frames 656 // Dispatch all client owned output buffers to recover remaining frames
557 while (1) { 657 while (1) {
@@ -560,15 +660,15 @@ void testEOS(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
560 // if dispatch is successful, perhaps there is a latency 660 // if dispatch is successful, perhaps there is a latency
561 // in the component. Dont be in a haste to leave. reset timeout 661 // in the component. Dont be in a haste to leave. reset timeout
562 // counter 662 // counter
563 timeOut = TIMEOUT_COUNTER; 663 timeOut = TIMEOUT_COUNTER_PE;
564 } else { 664 } else {
565 break; 665 break;
566 } 666 }
567 } 667 }
568 668
569 Message msg; 669 Message msg;
570 status = 670 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, iBuffer,
571 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 671 oBuffer);
572 if (status == android::hardware::media::omx::V1_0::Status::OK) { 672 if (status == android::hardware::media::omx::V1_0::Status::OK) {
573 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) { 673 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
574 if (fptr) { 674 if (fptr) {
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..de043b2c 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
@@ -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..5d0ac35e 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>
@@ -181,7 +185,7 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase {
181 strlen(gEnv->getComponent().c_str()) - suffixLen, 185 strlen(gEnv->getComponent().c_str()) - suffixLen,
182 ".secure"); 186 ".secure");
183 } 187 }
184 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 188 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
185 } 189 }
186 190
187 virtual void TearDown() override { 191 virtual void TearDown() override {
@@ -213,9 +217,6 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase {
213 } 217 }
214}; 218};
215 219
216// Random Index used for monkey testing while get/set parameters
217#define RANDOM_INDEX 1729
218
219void initPortMode(PortMode* pm, bool isSecure, 220void initPortMode(PortMode* pm, bool isSecure,
220 ComponentHidlTest::standardCompClass compClass) { 221 ComponentHidlTest::standardCompClass compClass) {
221 pm[0] = PortMode::PRESET_BYTE_BUFFER; 222 pm[0] = PortMode::PRESET_BYTE_BUFFER;
@@ -293,7 +294,7 @@ TEST_F(ComponentHidlTest, DISABLED_GetPortIndices) {
293} 294}
294 295
295// port format enumeration 296// port format enumeration
296TEST_F(ComponentHidlTest, DISABLED_EnumeratePortFormat) { 297TEST_F(ComponentHidlTest, EnumeratePortFormat) {
297 description("Test Component on Mandatory Port Parameters (Port Format)"); 298 description("Test Component on Mandatory Port Parameters (Port Format)");
298 if (disableTest) return; 299 if (disableTest) return;
299 android::hardware::media::omx::V1_0::Status status; 300 android::hardware::media::omx::V1_0::Status status;
@@ -374,7 +375,7 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
374 kPortIndexOutput = kPortIndexInput + 1; 375 kPortIndexOutput = kPortIndexInput + 1;
375 } 376 }
376 377
377 for (size_t i = kPortIndexInput; i < kPortIndexOutput; i++) { 378 for (size_t i = kPortIndexInput; i <= kPortIndexOutput; i++) {
378 OMX_PARAM_PORTDEFINITIONTYPE portDef; 379 OMX_PARAM_PORTDEFINITIONTYPE portDef;
379 status = 380 status =
380 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 381 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
@@ -400,28 +401,30 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
400 EXPECT_NE(status, 401 EXPECT_NE(status,
401 ::android::hardware::media::omx::V1_0::Status::OK); 402 ::android::hardware::media::omx::V1_0::Status::OK);
402 403
403 // Edit Read-Only fields. 404 // Port Direction - Read Only
404 portDef = mirror; 405 portDef = mirror;
405 portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX); 406 portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX);
406 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 407 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
407 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 408 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
408 EXPECT_EQ(portDef.eDir, mirror.eDir); 409 if (portDef.eDir != mirror.eDir) {
409 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); 410 std::cerr << "[ ERROR ] port direction has to be read only "
410 411 "but is changeable \n";
411 portDef = mirror; 412 }
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); 413 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
417 414
415 // Port Min BufferCount - Read Only
418 portDef = mirror; 416 portDef = mirror;
419 portDef.nBufferCountMin += 1; 417 portDef.nBufferCountMin += 1;
420 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 418 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
421 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); 419 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
420 if (portDef.nBufferCountMin != mirror.nBufferCountMin) {
421 std::cerr << "[ ERROR ] port Min BufferCount has to be "
422 "read only but is changeable \n";
423 }
422 EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin); 424 EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin);
423 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); 425 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
424 426
427 // Port Actual BufferCount
425 portDef = mirror; 428 portDef = mirror;
426 portDef.nBufferCountActual += 1; 429 portDef.nBufferCountActual += 1;
427 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, 430 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i,
@@ -433,19 +436,47 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) {
433 mirror.nBufferCountActual + 1); 436 mirror.nBufferCountActual + 1);
434 } 437 }
435 438
439 // Port BufferSize is although read only as per OMX-IL 1.2, android
440 // doesnt abide by this.
441 // Decrease buffer size
436 portDef = mirror; 442 portDef = mirror;
437 portDef.nBufferSize = mirror.nBufferSize << 1; 443 OMX_U32 nBufferSize = portDef.nBufferSize >> 1;
438 status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, 444 if (nBufferSize != 0) {
439 &portDef); 445 if (!strncmp(gEnv->getComponent().c_str(), "OMX.google.", 11)) {
440 if (status == ::android::hardware::media::omx::V1_0::Status::OK) { 446 portDef.nBufferSize = nBufferSize;
441 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, i, 447 } else {
442 &portDef); 448 // Probable alignment requirements of vendor component
443 if (portDef.nBufferSize != mirror.nBufferSize) { 449 portDef.nBufferSize = ALIGN_POWER_OF_TWO(nBufferSize, 12);
444 std::cout 450 nBufferSize = portDef.nBufferSize;
445 << "[ ] Warning ! Component input port does " 451 }
446 "not preserve Read-Only fields \n"; 452 } else {
453 ASSERT_TRUE(false) << "Unexpected buffer size";
454 }
455 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
456 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
457 // SPECIAL CASE: For video decoder, allow configuration of input
458 // buffer size even if it is less than minimum requirement and
459 // similarly for encoder allow configuration of output port buffer
460 // size.
461 if ((compClass == video_encoder && i == kPortIndexOutput) ||
462 (compClass == video_decoder && i == kPortIndexInput)) {
463 double dev = (portDef.nBufferSize / (double)nBufferSize);
464 dev -= 1;
465 if (dev < 0 || dev > 0.1) {
466 std::cerr << "[ ERROR ] port buffer size deviation "
467 "larger than expected \n";
447 } 468 }
469 } else {
470 EXPECT_EQ(portDef.nBufferSize, mirror.nBufferSize);
448 } 471 }
472 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror);
473
474 // Increase buffer size
475 portDef = mirror;
476 portDef.nBufferSize = mirror.nBufferSize << 1;
477 setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
478 getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef);
479 EXPECT_EQ(portDef.nBufferSize, (mirror.nBufferSize << 1));
449 } 480 }
450 } 481 }
451} 482}
@@ -470,8 +501,10 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) {
470 portBase = params.nStartPortNumber; 501 portBase = params.nStartPortNumber;
471 } 502 }
472 503
473 sp<IAllocator> allocator = IAllocator::getService("ashmem"); 504 // set state to idle
474 EXPECT_NE(allocator.get(), nullptr); 505 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
506 OMX_StateIdle);
507 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
475 508
476 OMX_PARAM_PORTDEFINITIONTYPE portDef; 509 OMX_PARAM_PORTDEFINITIONTYPE portDef;
477 status = 510 status =
@@ -485,30 +518,9 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) {
485 518
486 for (size_t i = 0; i < portDef.nBufferCountActual; i++) { 519 for (size_t i = 0; i < portDef.nBufferCountActual; i++) {
487 BufferInfo buffer; 520 BufferInfo buffer;
488 buffer.owner = client; 521 allocateBuffer(omxNode, &buffer, portBase, nBufferSize,
489 buffer.omxBuffer.type = CodecBuffer::Type::SHARED_MEM; 522 PortMode::PRESET_BYTE_BUFFER);
490 buffer.omxBuffer.attr.preset.rangeOffset = 0;
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); 523 pBuffer.push(buffer);
511 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
512 } 524 }
513 525
514 status = 526 status =
@@ -583,9 +595,9 @@ TEST_F(ComponentHidlTest, Flush) {
583 kPortIndexInput, kPortIndexOutput); 595 kPortIndexInput, kPortIndexOutput);
584} 596}
585 597
586// state transitions test 598// Flush test - monkeying
587TEST_F(ComponentHidlTest, StateTransitions) { 599TEST_F(ComponentHidlTest, Flush_M) {
588 description("Test State Transitions Loaded<->Idle<->Execute"); 600 description("Test Flush monkeying");
589 if (disableTest) return; 601 if (disableTest) return;
590 android::hardware::media::omx::V1_0::Status status; 602 android::hardware::media::omx::V1_0::Status status;
591 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; 603 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
@@ -615,29 +627,250 @@ TEST_F(ComponentHidlTest, StateTransitions) {
615 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 627 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
616 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 628 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
617 629
630 // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
631 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
632 // OMX_ALL);
633 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
634
618 // set state to idle 635 // set state to idle
619 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 636 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
620 kPortIndexInput, kPortIndexOutput, portMode); 637 kPortIndexInput, kPortIndexOutput, portMode);
638
639 // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
640 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
641 // OMX_ALL);
642 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
643
621 // set state to executing 644 // set state to executing
622 changeStateIdletoExecute(omxNode, observer); 645 changeStateIdletoExecute(omxNode, observer);
623 // dispatch buffers 646 // dispatch buffers
624 for (size_t i = 0; i < oBuffer.size(); i++) { 647 for (size_t i = 0; i < oBuffer.size(); i++) {
625 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]); 648 dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]);
626 } 649 }
650
651 // // flush invalid port, expecting OMX_ErrorBadPortIndex
652 // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
653 // RANDOM_INDEX);
654 // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);
655
656 // Flush all ports
657 status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), OMX_ALL);
658 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
659
660 for (int j = 0; j < 2; j++) {
661 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer,
662 &oBuffer);
663 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
664 ASSERT_EQ(msg.type, Message::Type::EVENT);
665 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
666 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
667 if (msg.data.eventData.data2 == kPortIndexInput) {
668 // test if client got all its buffers back
669 for (size_t i = 0; i < iBuffer.size(); ++i) {
670 EXPECT_EQ(iBuffer[i].owner, client);
671 }
672 } else if (msg.data.eventData.data2 == kPortIndexOutput) {
673 // test if client got all its buffers back
674 for (size_t i = 0; i < oBuffer.size(); ++i) {
675 EXPECT_EQ(oBuffer[i].owner, client);
676 }
677 } else {
678 EXPECT_TRUE(false) << "Bad port Index";
679 }
680 }
681
682 // SPECIAL CASE: When OMX_ALL is used as argument, Android OMX Core sends
683 // an additional flush event with argument OMX_ALL. This we believe is
684 // not recognized by OMX-IL Spec. So read this event and ignore it
685 status =
686 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer, &oBuffer);
687 if (status == android::hardware::media::omx::V1_0::Status::OK) {
688 ASSERT_EQ(msg.type, Message::Type::EVENT);
689 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
690 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
691 ASSERT_EQ(msg.data.eventData.data2, OMX_ALL);
692 }
693
627 // set state to idle 694 // set state to idle
628 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 695 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
696 // set state to loaded
697 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer,
698 kPortIndexInput, kPortIndexOutput);
699}
700
701// test port mode configuration when the component is in various states
702TEST_F(ComponentHidlTest, PortModeConfig) {
703 description("Test Port Mode Configuration");
704 if (disableTest) return;
705 android::hardware::media::omx::V1_0::Status status;
706 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
707 Message msg;
708
709 status = setRole(omxNode, gEnv->getRole().c_str());
710 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
711 OMX_PORT_PARAM_TYPE params;
712 if (compClass == audio_decoder || compClass == audio_encoder) {
713 status = getParam(omxNode, OMX_IndexParamAudioInit, &params);
714 } else {
715 status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
716 }
717 if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
718 ASSERT_EQ(params.nPorts, 2U);
719 kPortIndexInput = params.nStartPortNumber;
720 kPortIndexOutput = kPortIndexInput + 1;
721 }
722
723 android::Vector<BufferInfo> iBuffer, oBuffer;
724
725 // set port mode
726 PortMode portMode[2];
727 initPortMode(portMode, isSecure, compClass);
728 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
729 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
730 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
731 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
732
733 // set state to idle
734 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
735 kPortIndexInput, kPortIndexOutput, portMode);
736 // Only Allow Port Mode configuration in loaded state
737 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
738 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
739 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
740 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
741
742 // set state to executing
743 changeStateIdletoExecute(omxNode, observer);
744 // Only Allow Port Mode configuration in loaded state
745 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
746 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
747 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
748 EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
749
750 // set state to idle
751 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
752 // set state to loaded
753 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer,
754 kPortIndexInput, kPortIndexOutput);
755
756 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
757 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
758 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
759 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
760}
761
762// state transitions test
763TEST_F(ComponentHidlTest, StateTransitions) {
764 description("Test State Transitions Loaded<->Idle<->Execute");
765 if (disableTest) return;
766 android::hardware::media::omx::V1_0::Status status;
767 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
768 OMX_U32 portBase = 0;
769 Message msg;
770 status = setRole(omxNode, gEnv->getRole().c_str());
771 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
772 OMX_PORT_PARAM_TYPE params;
773 if (compClass == audio_decoder || compClass == audio_encoder) {
774 status = getParam(omxNode, OMX_IndexParamAudioInit, &params);
775 } else {
776 status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
777 }
778 if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
779 ASSERT_EQ(params.nPorts, 2U);
780 portBase = params.nStartPortNumber;
781 }
782 kPortIndexInput = portBase;
783 kPortIndexOutput = portBase + 1;
784
785 android::Vector<BufferInfo> pBuffer[2];
786
787 // set port mode
788 PortMode portMode[2];
789 initPortMode(portMode, isSecure, compClass);
790 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
791 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
792 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
793 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
794
795 // set state to idle
796 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
797 OMX_StateIdle);
798 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
799
800 for (size_t j = portBase; j < portBase + 2; j++) {
801 pBuffer[j - portBase].clear();
802
803 OMX_PARAM_PORTDEFINITIONTYPE def;
804 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, j, &def);
805 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
806
807 for (size_t i = 0; i < def.nBufferCountActual; i++) {
808 // Dont switch states until the ports are populated
809 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
810 &pBuffer[0], &pBuffer[1]);
811 ASSERT_EQ(status,
812 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
813
814 BufferInfo buffer;
815 allocateBuffer(omxNode, &buffer, j, def.nBufferSize,
816 portMode[j - portBase]);
817 pBuffer[j - portBase].push(buffer);
818 }
819 }
820
821 // As the ports are populated, check if the state transition is complete
822 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0],
823 &pBuffer[1]);
824 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
825 ASSERT_EQ(msg.type, Message::Type::EVENT);
826 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
827 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet);
828 ASSERT_EQ(msg.data.eventData.data2, OMX_StateIdle);
829
830 // set state to executing
831 changeStateIdletoExecute(omxNode, observer);
832 // dispatch buffers
833 for (size_t i = 0; i < pBuffer[1].size(); i++) {
834 dispatchOutputBuffer(omxNode, &pBuffer[1], i, portMode[1]);
835 }
836 // set state to idle
837 changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]);
629 // // set state to executing 838 // // set state to executing
630 // changeStateIdletoExecute(omxNode, observer); 839 // changeStateIdletoExecute(omxNode, observer);
631 // // TODO: Sending empty input buffers is slightly tricky. 840 // // TODO: Sending empty input buffers is slightly tricky.
632 // // dispatch buffers 841 // // dispatch buffers
633 // for (size_t i = 0; i < iBuffer.size(); i++) { 842 // for (size_t i = 0; i < pBuffer[0].size(); i++) {
634 // dispatchInputBuffer(omxNode, &iBuffer, i, 0, 0, 0, portMode[0]); 843 // dispatchInputBuffer(omxNode, &pBuffer[0], i, 0, 0, 0,
844 // portMode[0]);
635 // } 845 // }
636 // // set state to idle 846 // // set state to idle
637 // changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); 847 // changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]);
848
638 // set state to loaded 849 // set state to loaded
639 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, 850 status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet),
640 kPortIndexInput, kPortIndexOutput); 851 OMX_StateLoaded);
852 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
853
854 for (size_t j = portBase; j < portBase + 2; j++) {
855 for (size_t i = 0; i < pBuffer[j].size(); ++i) {
856 // Dont switch states until the ports are populated
857 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
858 &pBuffer[0], &pBuffer[1]);
859 ASSERT_EQ(status,
860 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
861
862 status = omxNode->freeBuffer(j, pBuffer[j][i].id);
863 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
864 }
865 }
866
867 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0],
868 &pBuffer[1]);
869 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
870 ASSERT_EQ(msg.type, Message::Type::EVENT);
871 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
872 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet);
873 ASSERT_EQ(msg.data.eventData.data2, OMX_StateLoaded);
641} 874}
642 875
643// state transitions test - monkeying 876// state transitions 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..7cffea8c 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>
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 ff031dde..a2547e89 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>
@@ -27,10 +28,7 @@
27#include <android/hidl/allocator/1.0/IAllocator.h> 28#include <android/hidl/allocator/1.0/IAllocator.h>
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#include <cutils/atomic.h>
31 31
32using ::android::hardware::graphics::common::V1_0::BufferUsage;
33using ::android::hardware::graphics::common::V1_0::PixelFormat;
34using ::android::hardware::media::omx::V1_0::IOmx; 32using ::android::hardware::media::omx::V1_0::IOmx;
35using ::android::hardware::media::omx::V1_0::IOmxObserver; 33using ::android::hardware::media::omx::V1_0::IOmxObserver;
36using ::android::hardware::media::omx::V1_0::IOmxNode; 34using ::android::hardware::media::omx::V1_0::IOmxNode;
@@ -219,6 +217,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
219 timestampUs = 0; 217 timestampUs = 0;
220 timestampDevTest = false; 218 timestampDevTest = false;
221 isSecure = false; 219 isSecure = false;
220 portSettingsChange = false;
222 size_t suffixLen = strlen(".secure"); 221 size_t suffixLen = strlen(".secure");
223 if (strlen(gEnv->getComponent().c_str()) >= suffixLen) { 222 if (strlen(gEnv->getComponent().c_str()) >= suffixLen) {
224 isSecure = 223 isSecure =
@@ -227,7 +226,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
227 ".secure"); 226 ".secure");
228 } 227 }
229 if (isSecure) disableTest = true; 228 if (isSecure) disableTest = true;
230 if (disableTest) std::cout << "[ ] Warning ! Test Disabled\n"; 229 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
231 } 230 }
232 231
233 virtual void TearDown() override { 232 virtual void TearDown() override {
@@ -271,9 +270,8 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
271 EXPECT_EQ(tsHit, true) 270 EXPECT_EQ(tsHit, true)
272 << "TimeStamp not recognized"; 271 << "TimeStamp not recognized";
273 } else { 272 } else {
274 std::cout 273 std::cout << "[ INFO ] Received non-zero "
275 << "[ ] Warning ! Received non-zero " 274 "output / TimeStamp not recognized \n";
276 "output / TimeStamp not recognized \n";
277 } 275 }
278 } 276 }
279 } 277 }
@@ -295,6 +293,13 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
295 } 293 }
296#endif 294#endif
297 } 295 }
296 } else if (msg.type == Message::Type::EVENT) {
297 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
298 if ((msg.data.eventData.data2 == OMX_IndexParamPortDefinition ||
299 msg.data.eventData.data2 == 0)) {
300 portSettingsChange = true;
301 }
302 }
298 } 303 }
299 } 304 }
300 305
@@ -322,6 +327,7 @@ class VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
322 ::android::List<uint64_t> timestampUslist; 327 ::android::List<uint64_t> timestampUslist;
323 bool timestampDevTest; 328 bool timestampDevTest;
324 bool isSecure; 329 bool isSecure;
330 bool portSettingsChange;
325 331
326 protected: 332 protected:
327 static void description(const std::string& description) { 333 static void description(const std::string& description) {
@@ -369,122 +375,61 @@ void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
369 } 375 }
370} 376}
371 377
378// number of elementary streams per component
379#define STREAM_COUNT 2
372// LookUpTable of clips and metadata for component testing 380// LookUpTable of clips and metadata for component testing
373void GetURLForComponent(VideoDecHidlTest::standardComp comp, char* mURL, 381void GetURLForComponent(VideoDecHidlTest::standardComp comp, char* mURL,
374 char* info) { 382 char* info, size_t streamIndex = 1) {
375 struct CompToURL { 383 struct CompToURL {
376 VideoDecHidlTest::standardComp comp; 384 VideoDecHidlTest::standardComp comp;
377 const char* mURL; 385 const char mURL[STREAM_COUNT][512];
378 const char* info; 386 const char info[STREAM_COUNT][512];
379 }; 387 };
388 ASSERT_TRUE(streamIndex < STREAM_COUNT);
389
380 static const CompToURL kCompToURL[] = { 390 static const CompToURL kCompToURL[] = {
381 {VideoDecHidlTest::standardComp::avc, 391 {VideoDecHidlTest::standardComp::avc,
382 "bbb_avc_1920x1080_5000kbps_30fps.h264", 392 {"bbb_avc_176x144_300kbps_60fps.h264",
383 "bbb_avc_1920x1080_5000kbps_30fps.info"}, 393 "bbb_avc_1920x1080_5000kbps_30fps.h264"},
394 {"bbb_avc_176x144_300kbps_60fps.info",
395 "bbb_avc_1920x1080_5000kbps_30fps.info"}},
384 {VideoDecHidlTest::standardComp::hevc, 396 {VideoDecHidlTest::standardComp::hevc,
385 "bbb_hevc_640x360_1600kbps_30fps.hevc", 397 {"bbb_hevc_176x144_176kbps_60fps.hevc",
386 "bbb_hevc_640x360_1600kbps_30fps.info"}, 398 "bbb_hevc_640x360_1600kbps_30fps.hevc"},
399 {"bbb_hevc_176x144_176kbps_60fps.info",
400 "bbb_hevc_640x360_1600kbps_30fps.info"}},
387 {VideoDecHidlTest::standardComp::mpeg2, 401 {VideoDecHidlTest::standardComp::mpeg2,
388 "bbb_mpeg2_176x144_105kbps_25fps.m2v", 402 {"bbb_mpeg2_176x144_105kbps_25fps.m2v",
389 "bbb_mpeg2_176x144_105kbps_25fps.info"}, 403 "bbb_mpeg2_352x288_1mbps_60fps.m2v"},
404 {"bbb_mpeg2_176x144_105kbps_25fps.info",
405 "bbb_mpeg2_352x288_1mbps_60fps.info"}},
390 {VideoDecHidlTest::standardComp::h263, 406 {VideoDecHidlTest::standardComp::h263,
391 "bbb_h263_352x288_300kbps_12fps.h263", 407 {"", "bbb_h263_352x288_300kbps_12fps.h263"},
392 "bbb_h263_352x288_300kbps_12fps.info"}, 408 {"", "bbb_h263_352x288_300kbps_12fps.info"}},
393 {VideoDecHidlTest::standardComp::mpeg4, 409 {VideoDecHidlTest::standardComp::mpeg4,
394 "bbb_mpeg4_1280x720_1000kbps_25fps.m4v", 410 {"", "bbb_mpeg4_1280x720_1000kbps_25fps.m4v"},
395 "bbb_mpeg4_1280x720_1000kbps_25fps.info"}, 411 {"", "bbb_mpeg4_1280x720_1000kbps_25fps.info"}},
396 {VideoDecHidlTest::standardComp::vp8, "bbb_vp8_640x360_2mbps_30fps.vp8", 412 {VideoDecHidlTest::standardComp::vp8,
397 "bbb_vp8_640x360_2mbps_30fps.info"}, 413 {"bbb_vp8_176x144_240kbps_60fps.vp8",
414 "bbb_vp8_640x360_2mbps_30fps.vp8"},
415 {"bbb_vp8_176x144_240kbps_60fps.info",
416 "bbb_vp8_640x360_2mbps_30fps.info"}},
398 {VideoDecHidlTest::standardComp::vp9, 417 {VideoDecHidlTest::standardComp::vp9,
399 "bbb_vp9_640x360_1600kbps_30fps.vp9", 418 {"bbb_vp9_176x144_285kbps_60fps.vp9",
400 "bbb_vp9_640x360_1600kbps_30fps.info"}, 419 "bbb_vp9_640x360_1600kbps_30fps.vp9"},
420 {"bbb_vp9_176x144_285kbps_60fps.info",
421 "bbb_vp9_640x360_1600kbps_30fps.info"}},
401 }; 422 };
402 423
403 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) { 424 for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
404 if (kCompToURL[i].comp == comp) { 425 if (kCompToURL[i].comp == comp) {
405 strcat(mURL, kCompToURL[i].mURL); 426 strcat(mURL, kCompToURL[i].mURL[streamIndex]);
406 strcat(info, kCompToURL[i].info); 427 strcat(info, kCompToURL[i].info[streamIndex]);
407 return; 428 return;
408 } 429 }
409 } 430 }
410} 431}
411 432
412void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex,
413 android::Vector<BufferInfo>* buffArray,
414 uint32_t nFrameWidth, uint32_t nFrameHeight,
415 int32_t* nStride, int format, uint32_t count) {
416 android::hardware::media::omx::V1_0::Status status;
417 sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
418 android::hardware::graphics::allocator::V2_0::IAllocator::getService();
419 ASSERT_NE(nullptr, allocator.get());
420
421 sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
422 android::hardware::graphics::mapper::V2_0::IMapper::getService();
423 ASSERT_NE(mapper.get(), nullptr);
424
425 android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
426 descriptorInfo;
427 uint32_t usage;
428
429 descriptorInfo.width = nFrameWidth;
430 descriptorInfo.height = nFrameHeight;
431 descriptorInfo.layerCount = 1;
432 descriptorInfo.format = static_cast<PixelFormat>(format);
433 descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
434 omxNode->getGraphicBufferUsage(
435 portIndex,
436 [&status, &usage](android::hardware::media::omx::V1_0::Status _s,
437 uint32_t _n1) {
438 status = _s;
439 usage = _n1;
440 });
441 if (status == android::hardware::media::omx::V1_0::Status::OK) {
442 descriptorInfo.usage |= usage;
443 }
444
445 ::android::hardware::hidl_vec<uint32_t> descriptor;
446 android::hardware::graphics::mapper::V2_0::Error error;
447 mapper->createDescriptor(
448 descriptorInfo, [&error, &descriptor](
449 android::hardware::graphics::mapper::V2_0::Error _s,
450 ::android::hardware::hidl_vec<uint32_t> _n1) {
451 error = _s;
452 descriptor = _n1;
453 });
454 EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
455
456 EXPECT_EQ(buffArray->size(), count);
457
458 static volatile int32_t nextId = 0;
459 uint64_t id = static_cast<uint64_t>(getpid()) << 32;
460 allocator->allocate(
461 descriptor, count,
462 [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
463 const ::android::hardware::hidl_vec<
464 ::android::hardware::hidl_handle>& _n2) {
465 ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
466 _s);
467 *nStride = _n1;
468 ASSERT_EQ(count, _n2.size());
469 for (uint32_t i = 0; i < count; i++) {
470 buffArray->editItemAt(i).omxBuffer.nativeHandle = _n2[i];
471 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.width =
472 nFrameWidth;
473 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.height =
474 nFrameHeight;
475 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.stride = _n1;
476 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.format =
477 descriptorInfo.format;
478 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.usage =
479 descriptorInfo.usage;
480 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.layerCount =
481 descriptorInfo.layerCount;
482 buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.id =
483 id | static_cast<uint32_t>(android_atomic_inc(&nextId));
484 }
485 });
486}
487
488// port settings reconfiguration during runtime. reconfigures frame dimensions 433// port settings reconfiguration during runtime. reconfigures frame dimensions
489void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer, 434void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
490 android::Vector<BufferInfo>* iBuffer, 435 android::Vector<BufferInfo>* iBuffer,
@@ -568,22 +513,7 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
568 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 513 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
569 514
570 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, 515 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput,
571 oPortMode); 516 oPortMode, true);
572 if (oPortMode != PortMode::PRESET_BYTE_BUFFER) {
573 OMX_PARAM_PORTDEFINITIONTYPE portDef;
574
575 status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
576 kPortIndexOutput, &portDef);
577 ASSERT_EQ(
578 status,
579 ::android::hardware::media::omx::V1_0::Status::OK);
580 allocateGraphicBuffers(omxNode, kPortIndexOutput, oBuffer,
581 portDef.format.video.nFrameWidth,
582 portDef.format.video.nFrameHeight,
583 &portDef.format.video.nStride,
584 portDef.format.video.eColorFormat,
585 portDef.nBufferCountActual);
586 }
587 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, 517 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
588 iBuffer, oBuffer); 518 iBuffer, oBuffer);
589 ASSERT_EQ(status, 519 ASSERT_EQ(status,
@@ -611,14 +541,14 @@ void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
611 } 541 }
612 } else if (msg.data.eventData.data2 == 542 } else if (msg.data.eventData.data2 ==
613 OMX_IndexConfigCommonOutputCrop) { 543 OMX_IndexConfigCommonOutputCrop) {
614 std::cout << "[ ] Warning ! OMX_EventPortSettingsChanged/ " 544 std::cout << "[ INFO ] OMX_EventPortSettingsChanged/ "
615 "OMX_IndexConfigCommonOutputCrop not handled \n"; 545 "OMX_IndexConfigCommonOutputCrop not handled \n";
616 } else if (msg.data.eventData.data2 == OMX_IndexVendorStartUnused + 3) { 546 } else if (msg.data.eventData.data2 == OMX_IndexVendorStartUnused + 3) {
617 std::cout << "[ ] Warning ! OMX_EventPortSettingsChanged/ " 547 std::cout << "[ INFO ] OMX_EventPortSettingsChanged/ "
618 "kDescribeColorAspectsIndex not handled \n"; 548 "kDescribeColorAspectsIndex not handled \n";
619 } 549 }
620 } else if (msg.data.eventData.event == OMX_EventError) { 550 } else if (msg.data.eventData.event == OMX_EventError) {
621 std::cout << "[ ] Warning ! OMX_EventError/ " 551 std::cerr << "[ ERROR ] OMX_EventError/ "
622 "Decode Frame Call might be failed \n"; 552 "Decode Frame Call might be failed \n";
623 return; 553 return;
624 } else { 554 } else {
@@ -635,12 +565,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
635 PortMode oPortMode) { 565 PortMode oPortMode) {
636 android::hardware::media::omx::V1_0::Status status; 566 android::hardware::media::omx::V1_0::Status status;
637 Message msg; 567 Message msg;
638 int timeOut = TIMEOUT_COUNTER; 568 int timeOut = TIMEOUT_COUNTER_Q;
639 569
640 while (timeOut--) { 570 while (timeOut--) {
641 size_t i = 0; 571 size_t i = 0;
642 status = 572 status =
643 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 573 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
644 if (status == android::hardware::media::omx::V1_0::Status::OK) { 574 if (status == android::hardware::media::omx::V1_0::Status::OK) {
645 EXPECT_EQ(msg.type, Message::Type::EVENT); 575 EXPECT_EQ(msg.type, Message::Type::EVENT);
646 portReconfiguration(omxNode, observer, iBuffer, oBuffer, 576 portReconfiguration(omxNode, observer, iBuffer, oBuffer,
@@ -659,8 +589,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
659 size_t index; 589 size_t index;
660 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 590 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
661 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode); 591 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
592 timeOut = TIMEOUT_COUNTER_Q;
662 } 593 }
663 timeOut--;
664 } 594 }
665} 595}
666 596
@@ -674,38 +604,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
674 bool signalEOS = true) { 604 bool signalEOS = true) {
675 android::hardware::media::omx::V1_0::Status status; 605 android::hardware::media::omx::V1_0::Status status;
676 Message msg; 606 Message msg;
677 607 size_t index;
678 // dispatch output buffers
679 for (size_t i = 0; i < oBuffer->size(); i++) {
680 dispatchOutputBuffer(omxNode, oBuffer, i, oPortMode);
681 }
682 // dispatch input buffers
683 uint32_t flags = 0; 608 uint32_t flags = 0;
684 int frameID = offset; 609 int frameID = offset;
685 for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) && 610 int timeOut = TIMEOUT_COUNTER_Q;
686 (frameID < (offset + range)); 611 bool iQueued, oQueued;
687 i++) {
688 char* ipBuffer = static_cast<char*>(
689 static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
690 ASSERT_LE((*Info)[frameID].bytesCount,
691 static_cast<int>((*iBuffer)[i].mMemory->getSize()));
692 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
693 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
694 flags = (*Info)[frameID].flags;
695 if (signalEOS && ((frameID == (int)Info->size() - 1) ||
696 (frameID == (offset + range - 1))))
697 flags |= OMX_BUFFERFLAG_EOS;
698 dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
699 flags, (*Info)[frameID].timestamp);
700 frameID++;
701 }
702 612
703 int timeOut = TIMEOUT_COUNTER;
704 bool stall = false;
705 while (1) { 613 while (1) {
614 iQueued = oQueued = false;
706 status = 615 status =
707 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 616 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
708
709 // Port Reconfiguration 617 // Port Reconfiguration
710 if (status == android::hardware::media::omx::V1_0::Status::OK && 618 if (status == android::hardware::media::omx::V1_0::Status::OK &&
711 msg.type == Message::Type::EVENT) { 619 msg.type == Message::Type::EVENT) {
@@ -717,7 +625,6 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
717 if (frameID == (int)Info->size() || frameID == (offset + range)) break; 625 if (frameID == (int)Info->size() || frameID == (offset + range)) break;
718 626
719 // Dispatch input buffer 627 // Dispatch input buffer
720 size_t index = 0;
721 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 628 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
722 char* ipBuffer = static_cast<char*>( 629 char* ipBuffer = static_cast<char*>(
723 static_cast<void*>((*iBuffer)[index].mMemory->getPointer())); 630 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -726,6 +633,11 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
726 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount); 633 eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
727 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount); 634 ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
728 flags = (*Info)[frameID].flags; 635 flags = (*Info)[frameID].flags;
636 // Indicate to omx core that the buffer contains a full frame worth
637 // of data
638 flags |= OMX_BUFFERFLAG_ENDOFFRAME;
639 // Indicate the omx core that this is the last buffer it needs to
640 // process
729 if (signalEOS && ((frameID == (int)Info->size() - 1) || 641 if (signalEOS && ((frameID == (int)Info->size() - 1) ||
730 (frameID == (offset + range - 1)))) 642 (frameID == (offset + range - 1))))
731 flags |= OMX_BUFFERFLAG_EOS; 643 flags |= OMX_BUFFERFLAG_EOS;
@@ -733,18 +645,18 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
733 (*Info)[frameID].bytesCount, flags, 645 (*Info)[frameID].bytesCount, flags,
734 (*Info)[frameID].timestamp); 646 (*Info)[frameID].timestamp);
735 frameID++; 647 frameID++;
736 stall = false; 648 iQueued = true;
737 } else 649 }
738 stall = true; 650 // Dispatch output buffer
739 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 651 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
740 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode); 652 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
741 stall = false; 653 oQueued = true;
742 } else 654 }
743 stall = true; 655 // Reset Counters when either input or output buffer is dispatched
744 if (stall) 656 if (iQueued || oQueued)
745 timeOut--; 657 timeOut = TIMEOUT_COUNTER_Q;
746 else 658 else
747 timeOut = TIMEOUT_COUNTER; 659 timeOut--;
748 if (timeOut == 0) { 660 if (timeOut == 0) {
749 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 661 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
750 break; 662 break;
@@ -840,7 +752,7 @@ void getDefaultColorFormat(sp<IOmxNode> omxNode, OMX_U32 kPortIndexOutput,
840 OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat; 752 OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
841 *eColorFormat = OMX_COLOR_FormatUnused; 753 *eColorFormat = OMX_COLOR_FormatUnused;
842 portFormat.nIndex = 0; 754 portFormat.nIndex = 0;
843 while (1) { 755 while (portFormat.nIndex < 512) {
844 status = getPortParam(omxNode, OMX_IndexParamVideoPortFormat, 756 status = getPortParam(omxNode, OMX_IndexParamVideoPortFormat,
845 kPortIndexOutput, &portFormat); 757 kPortIndexOutput, &portFormat);
846 if (status != ::android::hardware::media::omx::V1_0::Status::OK) break; 758 if (status != ::android::hardware::media::omx::V1_0::Status::OK) break;
@@ -854,7 +766,9 @@ void getDefaultColorFormat(sp<IOmxNode> omxNode, OMX_U32 kPortIndexOutput,
854 break; 766 break;
855 } 767 }
856 if (OMX_COLOR_FormatYUV420SemiPlanar == portFormat.eColorFormat || 768 if (OMX_COLOR_FormatYUV420SemiPlanar == portFormat.eColorFormat ||
857 OMX_COLOR_FormatYUV420Planar == portFormat.eColorFormat) { 769 OMX_COLOR_FormatYUV420Planar == portFormat.eColorFormat ||
770 OMX_COLOR_FormatYUV420PackedPlanar == portFormat.eColorFormat ||
771 OMX_COLOR_FormatYUV420PackedSemiPlanar == portFormat.eColorFormat) {
858 *eColorFormat = portFormat.eColorFormat; 772 *eColorFormat = portFormat.eColorFormat;
859 break; 773 break;
860 } 774 }
@@ -971,30 +885,14 @@ TEST_F(VideoDecHidlTest, DecodeTest) {
971 setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused, 885 setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
972 eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate); 886 eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
973 887
974 // disabling adaptive playback.
975 omxNode->prepareForAdaptivePlayback(kPortIndexOutput, false, 1920, 1080);
976
977 android::Vector<BufferInfo> iBuffer, oBuffer; 888 android::Vector<BufferInfo> iBuffer, oBuffer;
978 889
979 // set state to idle 890 // set state to idle
980 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 891 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
981 kPortIndexInput, kPortIndexOutput, portMode); 892 kPortIndexInput, kPortIndexOutput, portMode, true);
982 // set state to executing 893 // set state to executing
983 changeStateIdletoExecute(omxNode, observer); 894 changeStateIdletoExecute(omxNode, observer);
984 895
985 if (portMode[1] != PortMode::PRESET_BYTE_BUFFER) {
986 OMX_PARAM_PORTDEFINITIONTYPE portDef;
987
988 status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
989 kPortIndexOutput, &portDef);
990 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
991 allocateGraphicBuffers(
992 omxNode, kPortIndexOutput, &oBuffer,
993 portDef.format.video.nFrameWidth, portDef.format.video.nFrameHeight,
994 &portDef.format.video.nStride, portDef.format.video.eColorFormat,
995 portDef.nBufferCountActual);
996 }
997
998 // Port Reconfiguration 896 // Port Reconfiguration
999 eleStream.open(mURL, std::ifstream::binary); 897 eleStream.open(mURL, std::ifstream::binary);
1000 ASSERT_EQ(eleStream.is_open(), true); 898 ASSERT_EQ(eleStream.is_open(), true);
@@ -1014,6 +912,148 @@ TEST_F(VideoDecHidlTest, DecodeTest) {
1014 kPortIndexInput, kPortIndexOutput); 912 kPortIndexInput, kPortIndexOutput);
1015} 913}
1016 914
915// Test for adaptive playback support
916TEST_F(VideoDecHidlTest, AdaptivePlaybackTest) {
917 description("Tests for Adaptive Playback support");
918 if (disableTest) return;
919 if (!(compName == avc || compName == hevc || compName == vp8 ||
920 compName == vp9 || compName == mpeg2))
921 return;
922 android::hardware::media::omx::V1_0::Status status;
923 uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
924 status = setRole(omxNode, gEnv->getRole().c_str());
925 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
926 OMX_PORT_PARAM_TYPE params;
927 status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
928 if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
929 ASSERT_EQ(params.nPorts, 2U);
930 kPortIndexInput = params.nStartPortNumber;
931 kPortIndexOutput = kPortIndexInput + 1;
932 }
933
934 // set port mode
935 portMode[0] = PortMode::PRESET_BYTE_BUFFER;
936 portMode[1] = PortMode::DYNAMIC_ANW_BUFFER;
937 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
938 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
939 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
940 if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
941 portMode[1] = PortMode::PRESET_BYTE_BUFFER;
942 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
943 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
944 }
945
946 // prepare for adaptive playback
947 uint32_t adaptiveMaxWidth = 320;
948 uint32_t adaptiveMaxHeight = 240;
949 status = omxNode->prepareForAdaptivePlayback(
950 kPortIndexOutput, true, adaptiveMaxWidth, adaptiveMaxHeight);
951 if (strncmp(gEnv->getComponent().c_str(), "OMX.google.", 11) == 0) {
952 // SoftOMX Decoders donot support graphic buffer modes. So for them
953 // support for adaptive play back is mandatory in Byte Buffer mode
954 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
955 } else {
956 // for vendor codecs, support for adaptive play back is optional
957 // in byte buffer mode.
958 if (portMode[1] == PortMode::PRESET_BYTE_BUFFER) return;
959 if (status != ::android::hardware::media::omx::V1_0::Status::OK) return;
960 }
961
962 // TODO: Handle this better !!!
963 // Without the knowledge of the maximum resolution of the frame to be
964 // decoded it is not possible to choose the size of the input buffer.
965 // The value below is based on the info. files of clips in res folder.
966 status = setPortBufferSize(omxNode, kPortIndexInput, 482304);
967 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
968
969 // set Port Params
970 uint32_t nFrameWidth, nFrameHeight, xFramerate;
971 getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
972 &xFramerate);
973 // get default color format
974 OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
975 getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
976 &eColorFormat);
977 ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
978 status =
979 setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
980 eColorFormat, xFramerate);
981 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
982 setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
983 eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
984
985 android::Vector<BufferInfo> iBuffer, oBuffer;
986
987 // set state to idle
988 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
989 kPortIndexInput, kPortIndexOutput, portMode, true);
990 // set state to executing
991 changeStateIdletoExecute(omxNode, observer);
992
993 timestampDevTest = true;
994 uint32_t timestampOffset = 0;
995 for (uint32_t i = 0; i < STREAM_COUNT * 2; i++) {
996 std::ifstream eleStream, eleInfo;
997 char mURL[512], info[512];
998 android::Vector<FrameData> Info;
999 strcpy(mURL, gEnv->getRes().c_str());
1000 strcpy(info, gEnv->getRes().c_str());
1001 GetURLForComponent(compName, mURL, info, i % STREAM_COUNT);
1002 eleInfo.open(info);
1003 ASSERT_EQ(eleInfo.is_open(), true);
1004 int bytesCount = 0;
1005 uint32_t flags = 0;
1006 uint32_t timestamp = 0;
1007 uint32_t timestampMax = 0;
1008 while (1) {
1009 if (!(eleInfo >> bytesCount)) break;
1010 eleInfo >> flags;
1011 eleInfo >> timestamp;
1012 timestamp += timestampOffset;
1013 Info.push_back({bytesCount, flags, timestamp});
1014 if (timestampDevTest && (flags != OMX_BUFFERFLAG_CODECCONFIG))
1015 timestampUslist.push_back(timestamp);
1016 if (timestampMax < timestamp) timestampMax = timestamp;
1017 }
1018 timestampOffset = timestampMax;
1019 eleInfo.close();
1020
1021 // Port Reconfiguration
1022 eleStream.open(mURL, std::ifstream::binary);
1023 ASSERT_EQ(eleStream.is_open(), true);
1024 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1025 kPortIndexOutput, eleStream, &Info, 0, (int)Info.size(),
1026 portMode[1], false);
1027 eleStream.close();
1028
1029 getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth,
1030 &nFrameHeight, &xFramerate);
1031 if ((nFrameWidth > adaptiveMaxWidth) ||
1032 (nFrameHeight > adaptiveMaxHeight)) {
1033 if (nFrameWidth > adaptiveMaxWidth) adaptiveMaxWidth = nFrameWidth;
1034 if (nFrameHeight > adaptiveMaxHeight)
1035 adaptiveMaxHeight = nFrameHeight;
1036 EXPECT_TRUE(portSettingsChange);
1037 } else {
1038 // In DynamicANW Buffer mode, its ok to do a complete
1039 // reconfiguration even if a partial reconfiguration is sufficient.
1040 if (portMode[1] != PortMode::DYNAMIC_ANW_BUFFER)
1041 EXPECT_FALSE(portSettingsChange);
1042 }
1043 portSettingsChange = false;
1044 }
1045 waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
1046 kPortIndexInput, kPortIndexOutput, portMode[1]);
1047 testEOS(omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
1048 portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr);
1049 if (timestampDevTest) EXPECT_EQ(timestampUslist.empty(), true);
1050 // set state to idle
1051 changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
1052 // set state to executing
1053 changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer,
1054 kPortIndexInput, kPortIndexOutput);
1055}
1056
1017// end of sequence test 1057// end of sequence test
1018TEST_F(VideoDecHidlTest, EOSTest_M) { 1058TEST_F(VideoDecHidlTest, EOSTest_M) {
1019 description("Test End of stream monkeying"); 1059 description("Test End of stream monkeying");
@@ -1056,7 +1096,7 @@ TEST_F(VideoDecHidlTest, EOSTest_M) {
1056 1096
1057 // set state to idle 1097 // set state to idle
1058 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1098 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
1059 kPortIndexInput, kPortIndexOutput, portMode); 1099 kPortIndexInput, kPortIndexOutput, portMode, true);
1060 // set state to executing 1100 // set state to executing
1061 changeStateIdletoExecute(omxNode, observer); 1101 changeStateIdletoExecute(omxNode, observer);
1062 1102
@@ -1144,7 +1184,7 @@ TEST_F(VideoDecHidlTest, ThumbnailTest) {
1144 1184
1145 // set state to idle 1185 // set state to idle
1146 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1186 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
1147 kPortIndexInput, kPortIndexOutput, portMode); 1187 kPortIndexInput, kPortIndexOutput, portMode, true);
1148 // set state to executing 1188 // set state to executing
1149 changeStateIdletoExecute(omxNode, observer); 1189 changeStateIdletoExecute(omxNode, observer);
1150 1190
@@ -1232,10 +1272,16 @@ TEST_F(VideoDecHidlTest, SimpleEOSTest) {
1232 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1272 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1233 1273
1234 // set port mode 1274 // set port mode
1275 portMode[0] = PortMode::PRESET_BYTE_BUFFER;
1276 portMode[1] = PortMode::PRESET_ANW_BUFFER;
1235 status = omxNode->setPortMode(kPortIndexInput, portMode[0]); 1277 status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
1236 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1278 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1237 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); 1279 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1238 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 1280 if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
1281 portMode[1] = PortMode::PRESET_BYTE_BUFFER;
1282 status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1283 ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1284 }
1239 1285
1240 // set Port Params 1286 // set Port Params
1241 uint32_t nFrameWidth, nFrameHeight, xFramerate; 1287 uint32_t nFrameWidth, nFrameHeight, xFramerate;
@@ -1257,7 +1303,7 @@ TEST_F(VideoDecHidlTest, SimpleEOSTest) {
1257 1303
1258 // set state to idle 1304 // set state to idle
1259 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1305 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
1260 kPortIndexInput, kPortIndexOutput, portMode); 1306 kPortIndexInput, kPortIndexOutput, portMode, true);
1261 // set state to executing 1307 // set state to executing
1262 changeStateIdletoExecute(omxNode, observer); 1308 changeStateIdletoExecute(omxNode, observer);
1263 1309
@@ -1352,7 +1398,7 @@ TEST_F(VideoDecHidlTest, FlushTest) {
1352 1398
1353 // set state to idle 1399 // set state to idle
1354 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, 1400 changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
1355 kPortIndexInput, kPortIndexOutput, portMode); 1401 kPortIndexInput, kPortIndexOutput, portMode, true);
1356 // set state to executing 1402 // set state to executing
1357 changeStateIdletoExecute(omxNode, observer); 1403 changeStateIdletoExecute(omxNode, observer);
1358 1404
@@ -1365,9 +1411,8 @@ TEST_F(VideoDecHidlTest, FlushTest) {
1365 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1411 decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1366 kPortIndexOutput, eleStream, &Info, 0, nFrames, portMode[1], 1412 kPortIndexOutput, eleStream, &Info, 0, nFrames, portMode[1],
1367 false); 1413 false);
1368 // Note: Assumes 200 ms is enough to end any decode call that started
1369 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1414 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1370 kPortIndexOutput, 200000); 1415 kPortIndexOutput);
1371 framesReceived = 0; 1416 framesReceived = 0;
1372 1417
1373 // Seek to next key frame and start decoding till the end 1418 // Seek to next key frame and start decoding till the end
@@ -1388,10 +1433,9 @@ TEST_F(VideoDecHidlTest, FlushTest) {
1388 kPortIndexOutput, eleStream, &Info, index, 1433 kPortIndexOutput, eleStream, &Info, index,
1389 Info.size() - index, portMode[1], false); 1434 Info.size() - index, portMode[1], false);
1390 } 1435 }
1391 // Note: Assumes 200 ms is enough to end any decode call that started
1392 eleStream.close(); 1436 eleStream.close();
1393 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput, 1437 flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1394 kPortIndexOutput, 200000); 1438 kPortIndexOutput);
1395 framesReceived = 0; 1439 framesReceived = 0;
1396 1440
1397 // set state to idle 1441 // set state to idle
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
index c6d688f4..df90ccce 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
@@ -237,7 +237,7 @@ class VideoEncHidlTest : public ::testing::VtsHalHidlTargetTestBase {
237 ".secure"); 237 ".secure");
238 } 238 }
239 if (isSecure) disableTest = true; 239 if (isSecure) disableTest = true;
240 if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; 240 if (disableTest) std::cout << "[ WARN ] Test Disabled \n";
241 } 241 }
242 242
243 virtual void TearDown() override { 243 virtual void TearDown() override {
@@ -278,9 +278,8 @@ class VideoEncHidlTest : public ::testing::VtsHalHidlTargetTestBase {
278 EXPECT_EQ(tsHit, true) 278 EXPECT_EQ(tsHit, true)
279 << "TimeStamp not recognized"; 279 << "TimeStamp not recognized";
280 } else { 280 } else {
281 std::cerr 281 std::cout << "[ INFO ] Received non-zero "
282 << "[ ] Warning ! Received non-zero " 282 "output / TimeStamp not recognized \n";
283 "output / TimeStamp not recognized \n";
284 } 283 }
285 } 284 }
286 } 285 }
@@ -442,7 +441,7 @@ void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) {
442 status = setPortConfig(omxNode, OMX_IndexConfigVideoIntraVOPRefresh, 441 status = setPortConfig(omxNode, OMX_IndexConfigVideoIntraVOPRefresh,
443 portIndex, &param); 442 portIndex, &param);
444 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 443 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
445 std::cerr << "[ ] Warning ! unable to request IDR \n"; 444 std::cout << "[ INFO ] unable to request IDR \n";
446} 445}
447 446
448// modify bitrate 447// modify bitrate
@@ -453,7 +452,7 @@ void changeBitrate(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t nBitrate) {
453 status = 452 status =
454 setPortConfig(omxNode, OMX_IndexConfigVideoBitrate, portIndex, &param); 453 setPortConfig(omxNode, OMX_IndexConfigVideoBitrate, portIndex, &param);
455 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 454 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
456 std::cerr << "[ ] Warning ! unable to change Bitrate \n"; 455 std::cout << "[ INFO ] unable to change Bitrate \n";
457} 456}
458 457
459// modify framerate 458// modify framerate
@@ -465,7 +464,7 @@ Return<android::hardware::media::omx::V1_0::Status> changeFrameRate(
465 status = setPortConfig(omxNode, OMX_IndexConfigVideoFramerate, portIndex, 464 status = setPortConfig(omxNode, OMX_IndexConfigVideoFramerate, portIndex,
466 &param); 465 &param);
467 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 466 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
468 std::cerr << "[ ] Warning ! unable to change Framerate \n"; 467 std::cout << "[ INFO ] unable to change Framerate \n";
469 return status; 468 return status;
470} 469}
471 470
@@ -479,7 +478,7 @@ void changeRefreshPeriod(sp<IOmxNode> omxNode, OMX_U32 portIndex,
479 (OMX_INDEXTYPE)OMX_IndexConfigAndroidIntraRefresh, 478 (OMX_INDEXTYPE)OMX_IndexConfigAndroidIntraRefresh,
480 portIndex, &param); 479 portIndex, &param);
481 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 480 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
482 std::cerr << "[ ] Warning ! unable to change Refresh Period\n"; 481 std::cout << "[ INFO ] unable to change Refresh Period\n";
483} 482}
484 483
485// set intra refresh interval 484// set intra refresh interval
@@ -505,7 +504,7 @@ void setRefreshPeriod(sp<IOmxNode> omxNode, OMX_U32 portIndex,
505 status = setPortParam(omxNode, OMX_IndexParamVideoIntraRefresh, portIndex, 504 status = setPortParam(omxNode, OMX_IndexParamVideoIntraRefresh, portIndex,
506 &param); 505 &param);
507 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 506 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
508 std::cerr << "[ ] Warning ! unable to set Refresh Period \n"; 507 std::cout << "[ INFO ] unable to set Refresh Period \n";
509} 508}
510 509
511void setLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t latency) { 510void setLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t latency) {
@@ -515,7 +514,7 @@ void setLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t latency) {
515 status = setPortConfig(omxNode, (OMX_INDEXTYPE)OMX_IndexConfigLatency, 514 status = setPortConfig(omxNode, (OMX_INDEXTYPE)OMX_IndexConfigLatency,
516 portIndex, &param); 515 portIndex, &param);
517 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 516 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
518 std::cerr << "[ ] Warning ! unable to set latency\n"; 517 std::cout << "[ INFO ] unable to set latency\n";
519} 518}
520 519
521void getLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t* latency) { 520void getLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t* latency) {
@@ -524,7 +523,7 @@ void getLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t* latency) {
524 status = getPortConfig(omxNode, (OMX_INDEXTYPE)OMX_IndexConfigLatency, 523 status = getPortConfig(omxNode, (OMX_INDEXTYPE)OMX_IndexConfigLatency,
525 portIndex, &param); 524 portIndex, &param);
526 if (status != ::android::hardware::media::omx::V1_0::Status::OK) 525 if (status != ::android::hardware::media::omx::V1_0::Status::OK)
527 std::cerr << "[ ] Warning ! unable to get latency\n"; 526 std::cout << "[ INFO ] unable to get latency\n";
528 else 527 else
529 *latency = param.nU32; 528 *latency = param.nU32;
530} 529}
@@ -532,12 +531,15 @@ void getLatency(sp<IOmxNode> omxNode, OMX_U32 portIndex, uint32_t* latency) {
532// Set Default port param. 531// Set Default port param.
533void setDefaultPortParam(sp<IOmxNode> omxNode, OMX_U32 portIndex, 532void setDefaultPortParam(sp<IOmxNode> omxNode, OMX_U32 portIndex,
534 OMX_VIDEO_CODINGTYPE eCompressionFormat, 533 OMX_VIDEO_CODINGTYPE eCompressionFormat,
534 OMX_U32 nFrameWidth, OMX_U32 nFrameHeight,
535 OMX_U32 nBitrate, OMX_U32 xFramerate) { 535 OMX_U32 nBitrate, OMX_U32 xFramerate) {
536 android::hardware::media::omx::V1_0::Status status; 536 android::hardware::media::omx::V1_0::Status status;
537 OMX_PARAM_PORTDEFINITIONTYPE portDef; 537 OMX_PARAM_PORTDEFINITIONTYPE portDef;
538 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex, 538 status = getPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex,
539 &portDef); 539 &portDef);
540 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); 540 EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
541 portDef.format.video.nFrameWidth = nFrameWidth;
542 portDef.format.video.nFrameHeight = nFrameHeight;
541 portDef.format.video.nBitrate = nBitrate; 543 portDef.format.video.nBitrate = nBitrate;
542 portDef.format.video.xFramerate = xFramerate; 544 portDef.format.video.xFramerate = xFramerate;
543 portDef.format.video.bFlagErrorConcealment = OMX_TRUE; 545 portDef.format.video.bFlagErrorConcealment = OMX_TRUE;
@@ -609,12 +611,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
609 sp<CodecProducerListener> listener = nullptr) { 611 sp<CodecProducerListener> listener = nullptr) {
610 android::hardware::media::omx::V1_0::Status status; 612 android::hardware::media::omx::V1_0::Status status;
611 Message msg; 613 Message msg;
612 int timeOut = TIMEOUT_COUNTER; 614 int timeOut = TIMEOUT_COUNTER_Q;
613 615
614 while (timeOut--) { 616 while (timeOut--) {
615 size_t i = 0; 617 size_t i = 0;
616 status = 618 status =
617 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 619 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
618 EXPECT_EQ(status, 620 EXPECT_EQ(status,
619 android::hardware::media::omx::V1_0::Status::TIMED_OUT); 621 android::hardware::media::omx::V1_0::Status::TIMED_OUT);
620 // status == TIMED_OUT, it could be due to process time being large 622 // status == TIMED_OUT, it could be due to process time being large
@@ -633,6 +635,7 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
633 size_t index; 635 size_t index;
634 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 636 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
635 dispatchOutputBuffer(omxNode, oBuffer, index); 637 dispatchOutputBuffer(omxNode, oBuffer, index);
638 timeOut = TIMEOUT_COUNTER_Q;
636 } 639 }
637 } 640 }
638} 641}
@@ -979,57 +982,25 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
979 sp<CodecProducerListener> listener = nullptr) { 982 sp<CodecProducerListener> listener = nullptr) {
980 android::hardware::media::omx::V1_0::Status status; 983 android::hardware::media::omx::V1_0::Status status;
981 Message msg; 984 Message msg;
982 uint32_t ipCount = 0; 985 uint64_t timestamp = 0;
986 uint32_t flags = 0;
987 int timeOut = TIMEOUT_COUNTER_Q;
988 bool iQueued, oQueued;
983 989
990 uint32_t ipCount = 0;
984 if (ipCount == 0) { 991 if (ipCount == 0) {
985 status = changeFrameRate(omxNode, portIndexOutput, (24U << 16)); 992 status = changeFrameRate(omxNode, portIndexOutput, (24U << 16));
986 if (status == ::android::hardware::media::omx::V1_0::Status::OK) 993 if (status == ::android::hardware::media::omx::V1_0::Status::OK)
987 xFramerate = (24U << 16); 994 xFramerate = (24U << 16);
988 } 995 }
989
990 // dispatch output buffers
991 for (size_t i = 0; i < oBuffer->size(); i++) {
992 dispatchOutputBuffer(omxNode, oBuffer, i);
993 }
994 // dispatch input buffers
995 int32_t timestampIncr = (int)((float)1000000 / (xFramerate >> 16)); 996 int32_t timestampIncr = (int)((float)1000000 / (xFramerate >> 16));
996 // timestamp scale = Nano sec 997 if (inputDataIsMeta) timestampIncr *= 1000; // timestamp scale: Nano sec
997 if (inputDataIsMeta) timestampIncr *= 1000;
998 uint64_t timestamp = 0;
999 uint32_t flags = 0;
1000 for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) {
1001 if (inputDataIsMeta) {
1002 if (listener->freeBuffers > listener->minUnDequeuedCount) {
1003 if (dispatchGraphicBuffer(omxNode, producer, listener, iBuffer,
1004 portIndexInput, eleStream, timestamp))
1005 break;
1006 timestamp += timestampIncr;
1007 nFrames--;
1008 ipCount++;
1009 }
1010 } else {
1011 char* ipBuffer = static_cast<char*>(
1012 static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
1013 ASSERT_LE(bytesCount,
1014 static_cast<int>((*iBuffer)[i].mMemory->getSize()));
1015 if (fillByteBuffer(omxNode, ipBuffer, portIndexInput, eleStream))
1016 break;
1017 if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
1018 dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags,
1019 timestamp);
1020 if (timestampUslist) timestampUslist->push_back(timestamp);
1021 timestamp += timestampIncr;
1022 nFrames--;
1023 ipCount++;
1024 }
1025 }
1026 998
1027 int timeOut = TIMEOUT_COUNTER;
1028 bool stall = false;
1029 while (1) { 999 while (1) {
1000 iQueued = oQueued = false;
1030 status = 1001 status =
1031 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer); 1002 observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
1032 1003 // Port Reconfiguration
1033 if (status == android::hardware::media::omx::V1_0::Status::OK) { 1004 if (status == android::hardware::media::omx::V1_0::Status::OK) {
1034 ASSERT_EQ(msg.type, Message::Type::EVENT); 1005 ASSERT_EQ(msg.type, Message::Type::EVENT);
1035 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) { 1006 if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
@@ -1039,6 +1010,9 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
1039 } else if (msg.data.eventData.event == OMX_EventError) { 1010 } else if (msg.data.eventData.event == OMX_EventError) {
1040 EXPECT_TRUE(false) << "Received OMX_EventError, not sure why"; 1011 EXPECT_TRUE(false) << "Received OMX_EventError, not sure why";
1041 break; 1012 break;
1013 } else if (msg.data.eventData.event == OMX_EventDataSpaceChanged) {
1014 // TODO: how am i supposed to respond now?
1015 std::cout << "[ INFO ] OMX_EventDataSpaceChanged \n";
1042 } else { 1016 } else {
1043 ASSERT_TRUE(false); 1017 ASSERT_TRUE(false);
1044 } 1018 }
@@ -1056,9 +1030,7 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
1056 timestamp += timestampIncr; 1030 timestamp += timestampIncr;
1057 nFrames--; 1031 nFrames--;
1058 ipCount++; 1032 ipCount++;
1059 stall = false; 1033 iQueued = true;
1060 } else {
1061 stall = true;
1062 } 1034 }
1063 } else { 1035 } else {
1064 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) { 1036 if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
@@ -1070,31 +1042,32 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
1070 if (fillByteBuffer(omxNode, ipBuffer, portIndexInput, 1042 if (fillByteBuffer(omxNode, ipBuffer, portIndexInput,
1071 eleStream)) 1043 eleStream))
1072 break; 1044 break;
1073 if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS; 1045 flags = OMX_BUFFERFLAG_ENDOFFRAME;
1046 if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
1074 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags, 1047 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
1075 timestamp); 1048 timestamp);
1076 if (timestampUslist) timestampUslist->push_back(timestamp); 1049 if (timestampUslist) timestampUslist->push_back(timestamp);
1077 timestamp += timestampIncr; 1050 timestamp += timestampIncr;
1078 nFrames--; 1051 nFrames--;
1079 ipCount++; 1052 ipCount++;
1080 stall = false; 1053 iQueued = true;
1081 } else {
1082 stall = true;
1083 } 1054 }
1084 } 1055 }
1056 // Dispatch output buffer
1085 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) { 1057 if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
1086 dispatchOutputBuffer(omxNode, oBuffer, index); 1058 dispatchOutputBuffer(omxNode, oBuffer, index);
1087 stall = false; 1059 oQueued = true;
1088 } else 1060 }
1089 stall = true; 1061 // Reset Counters when either input or output buffer is dispatched
1090 if (stall) 1062 if (iQueued || oQueued)
1091 timeOut--; 1063 timeOut = TIMEOUT_COUNTER_Q;
1092 else 1064 else
1093 timeOut = TIMEOUT_COUNTER; 1065 timeOut--;
1094 if (timeOut == 0) { 1066 if (timeOut == 0) {
1095 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite"; 1067 EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
1096 break; 1068 break;
1097 } 1069 }
1070 // Runtime Param Configuration
1098 if (ipCount == 15) { 1071 if (ipCount == 15) {
1099 changeBitrate(omxNode, portIndexOutput, 768000); 1072 changeBitrate(omxNode, portIndexOutput, 768000);
1100 requestIDR(omxNode, portIndexOutput); 1073 requestIDR(omxNode, portIndexOutput);
@@ -1245,8 +1218,8 @@ TEST_F(VideoEncHidlTest, EncodeTest) {
1245 1218
1246 // Configure output port 1219 // Configure output port
1247 uint32_t nBitRate = 512000; 1220 uint32_t nBitRate = 512000;
1248 setDefaultPortParam(omxNode, kPortIndexOutput, eCompressionFormat, nBitRate, 1221 setDefaultPortParam(omxNode, kPortIndexOutput, eCompressionFormat,
1249 xFramerate); 1222 nFrameWidth, nFrameHeight, nBitRate, xFramerate);
1250 setRefreshPeriod(omxNode, kPortIndexOutput, 0); 1223 setRefreshPeriod(omxNode, kPortIndexOutput, 0);