1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #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 
22 #include <android-base/logging.h>
23 
24 #include <android/hardware/media/omx/1.0/IOmx.h>
25 #include <android/hardware/media/omx/1.0/IOmxNode.h>
26 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
27 #include <android/hardware/media/omx/1.0/types.h>
28 #include <android/hidl/allocator/1.0/IAllocator.h>
29 #include <android/hidl/memory/1.0/IMapper.h>
30 #include <android/hidl/memory/1.0/IMemory.h>
31 #include <gtest/gtest.h>
32 #include <hidl/GtestPrinter.h>
33 
34 using ::android::hardware::media::omx::V1_0::IOmx;
35 using ::android::hardware::media::omx::V1_0::IOmxObserver;
36 using ::android::hardware::media::omx::V1_0::IOmxNode;
37 using ::android::hardware::media::omx::V1_0::Message;
38 using ::android::hardware::media::omx::V1_0::CodecBuffer;
39 using ::android::hardware::media::omx::V1_0::PortMode;
40 using ::android::hidl::allocator::V1_0::IAllocator;
41 using ::android::hidl::memory::V1_0::IMemory;
42 using ::android::hidl::memory::V1_0::IMapper;
43 using ::android::hardware::Return;
44 using ::android::hardware::Void;
45 using ::android::hardware::hidl_vec;
46 using ::android::hardware::hidl_string;
47 using ::android::sp;
48 
49 #include <getopt.h>
50 #include <media/hardware/HardwareAPI.h>
51 #include <media_video_hidl_test_common.h>
52 #include <fstream>
53 
54 // Resource directory
55 std::string sResourceDir = "";
56 
57 // video decoder test fixture class
58 class VideoDecHidlTest
59     : public ::testing::TestWithParam<std::tuple<std::string, std::string, std::string>> {
60   public:
getTestCaseInfo() const61     ::std::string getTestCaseInfo() const {
62         return ::std::string() + "Component: " + component_ + " | " + "Role: " + role_ + " | " +
63                "Instance: " + instance_ + " | " + "Res: " + sResourceDir;
64     }
65 
SetUp()66     virtual void SetUp() override {
67         instance_ = std::get<0>(GetParam());
68         component_ = std::get<1>(GetParam());
69         role_ = std::get<2>(GetParam());
70         ASSERT_NE(sResourceDir.empty(), true);
71 
72         disableTest = false;
73         android::hardware::media::omx::V1_0::Status status;
74         omx = IOmx::getService(instance_);
75         ASSERT_NE(omx, nullptr);
76         observer =
77             new CodecObserver([this](Message msg, const BufferInfo* buffer) {
78                 handleMessage(msg, buffer);
79             });
80         ASSERT_NE(observer, nullptr);
81         if (component_.find("OMX.") != 0) disableTest = true;
82         EXPECT_TRUE(omx->allocateNode(component_, observer,
83                                       [&](android::hardware::media::omx::V1_0::Status _s,
84                                           sp<IOmxNode> const& _nl) {
85                                           status = _s;
86                                           this->omxNode = _nl;
87                                       })
88                             .isOk());
89         if (status == android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND) {
90             disableTest = true;
91             std::cout << "[   WARN   ] Test Disabled, component not present\n";
92             return;
93         }
94         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
95         ASSERT_NE(omxNode, nullptr);
96         ASSERT_NE(role_.empty(), true) << "Invalid Component Role";
97         struct StringToName {
98             const char* Name;
99             standardComp CompName;
100         };
101         const StringToName kStringToName[] = {
102             {"h263", h263}, {"avc", avc}, {"mpeg2", mpeg2}, {"mpeg4", mpeg4},
103             {"hevc", hevc}, {"vp8", vp8}, {"vp9", vp9},
104         };
105         const size_t kNumStringToName =
106             sizeof(kStringToName) / sizeof(kStringToName[0]);
107         const char* pch;
108         char substring[OMX_MAX_STRINGNAME_SIZE];
109         strcpy(substring, role_.c_str());
110         pch = strchr(substring, '.');
111         ASSERT_NE(pch, nullptr);
112         compName = unknown_comp;
113         for (size_t i = 0; i < kNumStringToName; ++i) {
114             if (!strcasecmp(pch + 1, kStringToName[i].Name)) {
115                 compName = kStringToName[i].CompName;
116                 break;
117             }
118         }
119         if (compName == unknown_comp) disableTest = true;
120         struct CompToCompression {
121             standardComp CompName;
122             OMX_VIDEO_CODINGTYPE eCompressionFormat;
123         };
124         static const CompToCompression kCompToCompression[] = {
125             {h263, OMX_VIDEO_CodingH263},   {avc, OMX_VIDEO_CodingAVC},
126             {mpeg2, OMX_VIDEO_CodingMPEG2}, {mpeg4, OMX_VIDEO_CodingMPEG4},
127             {hevc, OMX_VIDEO_CodingHEVC},   {vp8, OMX_VIDEO_CodingVP8},
128             {vp9, OMX_VIDEO_CodingVP9},
129         };
130         static const size_t kNumCompToCompression =
131             sizeof(kCompToCompression) / sizeof(kCompToCompression[0]);
132         size_t i;
133         for (i = 0; i < kNumCompToCompression; ++i) {
134             if (kCompToCompression[i].CompName == compName) {
135                 eCompressionFormat = kCompToCompression[i].eCompressionFormat;
136                 break;
137             }
138         }
139         if (i == kNumCompToCompression) disableTest = true;
140         portMode[0] = portMode[1] = PortMode::PRESET_BYTE_BUFFER;
141         eosFlag = false;
142         framesReceived = 0;
143         timestampUs = 0;
144         timestampDevTest = false;
145         isSecure = false;
146         portSettingsChange = false;
147         size_t suffixLen = strlen(".secure");
148         if (component_.rfind(".secure") == component_.length() - suffixLen) {
149             isSecure = true;
150         }
151         if (isSecure) disableTest = true;
152         omxNode->configureVideoTunnelMode(
153             1, OMX_TRUE, 0,
154             [&](android::hardware::media::omx::V1_0::Status _s,
155                 const ::android::hardware::hidl_handle& sidebandHandle) {
156                 (void)sidebandHandle;
157                 if (_s == android::hardware::media::omx::V1_0::Status::OK)
158                     this->disableTest = true;
159             });
160         if (disableTest) std::cout << "[   WARN   ] Test Disabled \n";
161         // NOTES: secure and tunneled components are not covered in these tests.
162         // we are disabling tests for them
163     }
164 
TearDown()165     virtual void TearDown() override {
166         if (omxNode != nullptr) {
167             // If you have encountered a fatal failure, it is possible that
168             // freeNode() will not go through. Instead of hanging the app.
169             // let it pass through and report errors
170             if (::testing::Test::HasFatalFailure()) return;
171             EXPECT_TRUE((omxNode->freeNode()).isOk());
172             omxNode = nullptr;
173         }
174     }
175 
176     // callback function to process messages received by onMessages() from IL
177     // client.
handleMessage(Message msg,const BufferInfo * buffer)178     void handleMessage(Message msg, const BufferInfo* buffer) {
179         (void)buffer;
180         if (msg.type == Message::Type::FILL_BUFFER_DONE) {
181             if (msg.data.extendedBufferData.flags & OMX_BUFFERFLAG_EOS) {
182                 eosFlag = true;
183             }
184             if (msg.data.extendedBufferData.rangeLength != 0) {
185                 framesReceived += 1;
186                 // For decoder components current timestamp always exceeds
187                 // previous timestamp
188                 EXPECT_GE(msg.data.extendedBufferData.timestampUs, timestampUs);
189                 timestampUs = msg.data.extendedBufferData.timestampUs;
190                 // Test if current timestamp is among the list of queued
191                 // timestamps
192                 if (timestampDevTest) {
193                     bool tsHit = false;
194                     android::List<uint64_t>::iterator it =
195                         timestampUslist.begin();
196                     while (it != timestampUslist.end()) {
197                         if (*it == timestampUs) {
198                             timestampUslist.erase(it);
199                             tsHit = true;
200                             break;
201                         }
202                         it++;
203                     }
204                     if (tsHit == false) {
205                         if (timestampUslist.empty() == false) {
206                             EXPECT_EQ(tsHit, true)
207                                 << "TimeStamp not recognized";
208                         } else {
209                             std::cout << "[   INFO   ] Received non-zero "
210                                          "output / TimeStamp not recognized \n";
211                         }
212                     }
213                 }
214 #define WRITE_OUTPUT 0
215 #if WRITE_OUTPUT
216                 static int count = 0;
217                 FILE* ofp = nullptr;
218                 if (count)
219                     ofp = fopen("out.bin", "ab");
220                 else
221                     ofp = fopen("out.bin", "wb");
222                 if (ofp != nullptr &&
223                     portMode[1] == PortMode::PRESET_BYTE_BUFFER) {
224                     fwrite(static_cast<void*>(buffer->mMemory->getPointer()),
225                            sizeof(char),
226                            msg.data.extendedBufferData.rangeLength, ofp);
227                     fclose(ofp);
228                     count++;
229                 }
230 #endif
231             }
232         } else if (msg.type == Message::Type::EVENT) {
233             if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
234                 if ((msg.data.eventData.data2 == OMX_IndexParamPortDefinition ||
235                      msg.data.eventData.data2 == 0)) {
236                     portSettingsChange = true;
237                 }
238             }
239         }
240     }
241 
242     enum standardComp {
243         h263,
244         avc,
245         mpeg2,
246         mpeg4,
247         hevc,
248         vp8,
249         vp9,
250         unknown_comp,
251     };
252 
253     std::string component_;
254     std::string role_;
255     std::string instance_;
256 
257     sp<IOmx> omx;
258     sp<CodecObserver> observer;
259     sp<IOmxNode> omxNode;
260     standardComp compName;
261     OMX_VIDEO_CODINGTYPE eCompressionFormat;
262     bool disableTest;
263     PortMode portMode[2];
264     bool eosFlag;
265     uint32_t framesReceived;
266     uint64_t timestampUs;
267     ::android::List<uint64_t> timestampUslist;
268     bool timestampDevTest;
269     bool isSecure;
270     bool portSettingsChange;
271 
272    protected:
description(const std::string & description)273     static void description(const std::string& description) {
274         RecordProperty("description", description);
275     }
276 };
277 
278 // Set Default port param.
setDefaultPortParam(sp<IOmxNode> omxNode,OMX_U32 portIndex,OMX_VIDEO_CODINGTYPE eCompressionFormat,OMX_COLOR_FORMATTYPE eColorFormat,OMX_U32 nFrameWidth=352,OMX_U32 nFrameHeight=288,OMX_U32 nBitrate=0,OMX_U32 xFramerate=(24U<<16))279 void setDefaultPortParam(sp<IOmxNode> omxNode, OMX_U32 portIndex,
280                          OMX_VIDEO_CODINGTYPE eCompressionFormat,
281                          OMX_COLOR_FORMATTYPE eColorFormat,
282                          OMX_U32 nFrameWidth = 352, OMX_U32 nFrameHeight = 288,
283                          OMX_U32 nBitrate = 0,
284                          OMX_U32 xFramerate = (24U << 16)) {
285     switch ((int)eCompressionFormat) {
286         case OMX_VIDEO_CodingUnused:
287             setupRAWPort(omxNode, portIndex, nFrameWidth, nFrameHeight,
288                          nBitrate, xFramerate, eColorFormat);
289             break;
290         default:
291             break;
292     }
293 }
294 
295 // In decoder components, often the input port parameters get updated upon
296 // parsing the header of elementary stream. Client needs to collect this
297 // information to reconfigure other ports that share data with this input
298 // port.
getInputChannelInfo(sp<IOmxNode> omxNode,OMX_U32 kPortIndexInput,uint32_t * nFrameWidth,uint32_t * nFrameHeight,uint32_t * xFramerate)299 void getInputChannelInfo(sp<IOmxNode> omxNode, OMX_U32 kPortIndexInput,
300                          uint32_t* nFrameWidth, uint32_t* nFrameHeight,
301                          uint32_t* xFramerate) {
302     android::hardware::media::omx::V1_0::Status status;
303     *nFrameWidth = 352;
304     *nFrameHeight = 288;
305     *xFramerate = (24U << 16);
306 
307     OMX_PARAM_PORTDEFINITIONTYPE portDef;
308     status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
309                           kPortIndexInput, &portDef);
310     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
311     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
312         *nFrameWidth = portDef.format.video.nFrameWidth;
313         *nFrameHeight = portDef.format.video.nFrameHeight;
314         *xFramerate = portDef.format.video.xFramerate;
315     }
316 }
317 
318 // number of elementary streams per component
319 #define STREAM_COUNT 2
320 // LookUpTable of clips and metadata for component testing
GetURLForComponent(VideoDecHidlTest::standardComp comp,char * mURL,char * info,size_t streamIndex=1)321 void GetURLForComponent(VideoDecHidlTest::standardComp comp, char* mURL,
322                         char* info, size_t streamIndex = 1) {
323     struct CompToURL {
324         VideoDecHidlTest::standardComp comp;
325         const char mURL[STREAM_COUNT][512];
326         const char info[STREAM_COUNT][512];
327     };
328     ASSERT_TRUE(streamIndex < STREAM_COUNT);
329 
330     static const CompToURL kCompToURL[] = {
331         {VideoDecHidlTest::standardComp::avc,
332          {"bbb_avc_176x144_300kbps_60fps.h264",
333           "bbb_avc_640x360_768kbps_30fps.h264"},
334          {"bbb_avc_176x144_300kbps_60fps.info",
335           "bbb_avc_640x360_768kbps_30fps.info"}},
336         {VideoDecHidlTest::standardComp::hevc,
337          {"bbb_hevc_176x144_176kbps_60fps.hevc",
338           "bbb_hevc_640x360_1600kbps_30fps.hevc"},
339          {"bbb_hevc_176x144_176kbps_60fps.info",
340           "bbb_hevc_640x360_1600kbps_30fps.info"}},
341         {VideoDecHidlTest::standardComp::mpeg2,
342          {"bbb_mpeg2_176x144_105kbps_25fps.m2v",
343           "bbb_mpeg2_352x288_1mbps_60fps.m2v"},
344          {"bbb_mpeg2_176x144_105kbps_25fps.info",
345           "bbb_mpeg2_352x288_1mbps_60fps.info"}},
346         {VideoDecHidlTest::standardComp::h263,
347          {"", "bbb_h263_352x288_300kbps_12fps.h263"},
348          {"", "bbb_h263_352x288_300kbps_12fps.info"}},
349         {VideoDecHidlTest::standardComp::mpeg4,
350          {"", "bbb_mpeg4_352x288_512kbps_30fps.m4v"},
351          {"", "bbb_mpeg4_352x288_512kbps_30fps.info"}},
352         {VideoDecHidlTest::standardComp::vp8,
353          {"bbb_vp8_176x144_240kbps_60fps.vp8",
354           "bbb_vp8_640x360_2mbps_30fps.vp8"},
355          {"bbb_vp8_176x144_240kbps_60fps.info",
356           "bbb_vp8_640x360_2mbps_30fps.info"}},
357         {VideoDecHidlTest::standardComp::vp9,
358          {"bbb_vp9_176x144_285kbps_60fps.vp9",
359           "bbb_vp9_640x360_1600kbps_30fps.vp9"},
360          {"bbb_vp9_176x144_285kbps_60fps.info",
361           "bbb_vp9_640x360_1600kbps_30fps.info"}},
362     };
363 
364     for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
365         if (kCompToURL[i].comp == comp) {
366             strcat(mURL, kCompToURL[i].mURL[streamIndex]);
367             strcat(info, kCompToURL[i].info[streamIndex]);
368             return;
369         }
370     }
371 }
372 
373 // port settings reconfiguration during runtime. reconfigures frame dimensions
portReconfiguration(sp<IOmxNode> omxNode,sp<CodecObserver> observer,android::Vector<BufferInfo> * iBuffer,android::Vector<BufferInfo> * oBuffer,OMX_U32 kPortIndexInput,OMX_U32 kPortIndexOutput,Message msg,PortMode oPortMode,void * args)374 void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
375                          android::Vector<BufferInfo>* iBuffer,
376                          android::Vector<BufferInfo>* oBuffer,
377                          OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
378                          Message msg, PortMode oPortMode, void* args) {
379     android::hardware::media::omx::V1_0::Status status;
380     (void)args;
381 
382     if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
383         ASSERT_EQ(msg.data.eventData.data1, kPortIndexOutput);
384         if (msg.data.eventData.data2 == OMX_IndexParamPortDefinition ||
385             msg.data.eventData.data2 == 0) {
386             // Components can send various kinds of port settings changed events
387             // all at once. Before committing to a full port reconfiguration,
388             // defer any events waiting in the queue to be addressed to a later
389             // point.
390             android::List<Message> msgQueueDefer;
391             while (1) {
392                 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
393                                                   iBuffer, oBuffer);
394                 if (status !=
395                     android::hardware::media::omx::V1_0::Status::TIMED_OUT) {
396                     msgQueueDefer.push_back(msg);
397                     continue;
398                 } else
399                     break;
400             }
401             status = omxNode->sendCommand(
402                 toRawCommandType(OMX_CommandPortDisable), kPortIndexOutput);
403             ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
404 
405             status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer,
406                                               oBuffer);
407             if (status ==
408                 android::hardware::media::omx::V1_0::Status::TIMED_OUT) {
409                 for (size_t i = 0; i < oBuffer->size(); ++i) {
410                     // test if client got all its buffers back
411                     EXPECT_EQ((*oBuffer)[i].owner, client);
412                     // free the buffers
413                     status =
414                         omxNode->freeBuffer(kPortIndexOutput, (*oBuffer)[i].id);
415                     ASSERT_EQ(status,
416                               android::hardware::media::omx::V1_0::Status::OK);
417                 }
418                 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
419                                                   iBuffer, oBuffer);
420                 ASSERT_EQ(status,
421                           android::hardware::media::omx::V1_0::Status::OK);
422                 ASSERT_EQ(msg.type, Message::Type::EVENT);
423                 ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
424                 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandPortDisable);
425                 ASSERT_EQ(msg.data.eventData.data2, kPortIndexOutput);
426 
427                 // set Port Params
428                 uint32_t nFrameWidth, nFrameHeight, xFramerate;
429                 getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth,
430                                     &nFrameHeight, &xFramerate);
431                 // get configured color format
432                 OMX_PARAM_PORTDEFINITIONTYPE portDef;
433                 status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
434                                       kPortIndexOutput, &portDef);
435                 setDefaultPortParam(omxNode, kPortIndexOutput,
436                                     OMX_VIDEO_CodingUnused,
437                                     portDef.format.video.eColorFormat,
438                                     nFrameWidth, nFrameHeight, 0, xFramerate);
439 
440                 // If you can disable a port, then you should be able to
441                 // enable it as well
442                 status = omxNode->sendCommand(
443                     toRawCommandType(OMX_CommandPortEnable), kPortIndexOutput);
444                 ASSERT_EQ(status,
445                           android::hardware::media::omx::V1_0::Status::OK);
446 
447                 // do not enable the port until all the buffers are supplied
448                 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
449                                                   iBuffer, oBuffer);
450                 ASSERT_EQ(
451                     status,
452                     android::hardware::media::omx::V1_0::Status::TIMED_OUT);
453 
454                 ASSERT_NO_FATAL_FAILURE(allocatePortBuffers(
455                     omxNode, oBuffer, kPortIndexOutput, oPortMode, true));
456                 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
457                                                   iBuffer, oBuffer);
458                 ASSERT_EQ(status,
459                           android::hardware::media::omx::V1_0::Status::OK);
460                 ASSERT_EQ(msg.type, Message::Type::EVENT);
461                 ASSERT_EQ(msg.data.eventData.data1, OMX_CommandPortEnable);
462                 ASSERT_EQ(msg.data.eventData.data2, kPortIndexOutput);
463 
464                 // Push back deferred messages to the list
465                 android::List<Message>::iterator it = msgQueueDefer.begin();
466                 while (it != msgQueueDefer.end()) {
467                     status = omxNode->dispatchMessage(*it);
468                     ASSERT_EQ(
469                         status,
470                         ::android::hardware::media::omx::V1_0::Status::OK);
471                     it++;
472                 }
473 
474                 // dispatch output buffers
475                 for (size_t i = 0; i < oBuffer->size(); i++) {
476                     ASSERT_NO_FATAL_FAILURE(
477                         dispatchOutputBuffer(omxNode, oBuffer, i, oPortMode));
478                 }
479             } else {
480                 ASSERT_TRUE(false);
481             }
482         } else if (msg.data.eventData.data2 ==
483                    OMX_IndexConfigCommonOutputCrop) {
484             std::cout << "[   INFO   ] OMX_EventPortSettingsChanged/ "
485                          "OMX_IndexConfigCommonOutputCrop not handled \n";
486         } else if (msg.data.eventData.data2 == OMX_IndexVendorStartUnused + 3) {
487             std::cout << "[   INFO   ] OMX_EventPortSettingsChanged/ "
488                          "kDescribeColorAspectsIndex not handled \n";
489         }
490     } else if (msg.data.eventData.event == OMX_EventError) {
491         std::cerr << "[   ERROR   ] OMX_EventError/ "
492                      "Decode Frame Call might be failed \n";
493         ASSERT_TRUE(false);
494     } else {
495         // something unexpected happened
496         ASSERT_TRUE(false);
497     }
498 }
499 
500 // blocking call to ensures application to Wait till all the inputs are consumed
waitOnInputConsumption(sp<IOmxNode> omxNode,sp<CodecObserver> observer,android::Vector<BufferInfo> * iBuffer,android::Vector<BufferInfo> * oBuffer,OMX_U32 kPortIndexInput,OMX_U32 kPortIndexOutput,PortMode oPortMode)501 void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
502                             android::Vector<BufferInfo>* iBuffer,
503                             android::Vector<BufferInfo>* oBuffer,
504                             OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
505                             PortMode oPortMode) {
506     android::hardware::media::omx::V1_0::Status status;
507     Message msg;
508     int timeOut = TIMEOUT_COUNTER_Q;
509 
510     while (timeOut--) {
511         size_t i = 0;
512         status =
513             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
514         if (status == android::hardware::media::omx::V1_0::Status::OK) {
515             ASSERT_EQ(msg.type, Message::Type::EVENT);
516             ASSERT_NO_FATAL_FAILURE(portReconfiguration(
517                 omxNode, observer, iBuffer, oBuffer, kPortIndexInput,
518                 kPortIndexOutput, msg, oPortMode, nullptr));
519         }
520         // status == TIMED_OUT, it could be due to process time being large
521         // than DEFAULT_TIMEOUT or component needs output buffers to start
522         // processing.
523         for (; i < iBuffer->size(); i++) {
524             if ((*iBuffer)[i].owner != client) break;
525         }
526         if (i == iBuffer->size()) break;
527 
528         // Dispatch an output buffer assuming outQueue.empty() is true
529         size_t index;
530         if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
531             ASSERT_NO_FATAL_FAILURE(
532                 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode));
533             timeOut = TIMEOUT_COUNTER_Q;
534         }
535     }
536 }
537 
538 // Decode N Frames
decodeNFrames(sp<IOmxNode> omxNode,sp<CodecObserver> observer,android::Vector<BufferInfo> * iBuffer,android::Vector<BufferInfo> * oBuffer,OMX_U32 kPortIndexInput,OMX_U32 kPortIndexOutput,std::ifstream & eleStream,android::Vector<FrameData> * Info,int offset,int range,PortMode oPortMode,bool signalEOS=true)539 void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
540                    android::Vector<BufferInfo>* iBuffer,
541                    android::Vector<BufferInfo>* oBuffer,
542                    OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
543                    std::ifstream& eleStream, android::Vector<FrameData>* Info,
544                    int offset, int range, PortMode oPortMode,
545                    bool signalEOS = true) {
546     android::hardware::media::omx::V1_0::Status status;
547     Message msg;
548     size_t index;
549     uint32_t flags = 0;
550     int frameID = offset;
551     int timeOut = TIMEOUT_COUNTER_Q;
552     bool iQueued, oQueued;
553 
554     while (1) {
555         iQueued = oQueued = false;
556         status =
557             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
558         // Port Reconfiguration
559         if (status == android::hardware::media::omx::V1_0::Status::OK &&
560             msg.type == Message::Type::EVENT) {
561             ASSERT_NO_FATAL_FAILURE(portReconfiguration(
562                 omxNode, observer, iBuffer, oBuffer, kPortIndexInput,
563                 kPortIndexOutput, msg, oPortMode, nullptr));
564         }
565 
566         if (frameID == (int)Info->size() || frameID == (offset + range)) break;
567 
568         // Dispatch input buffer
569         if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
570             char* ipBuffer = static_cast<char*>(
571                 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
572             ASSERT_LE((*Info)[frameID].bytesCount,
573                       static_cast<int>((*iBuffer)[index].mMemory->getSize()));
574             eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
575             ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
576             flags = (*Info)[frameID].flags;
577             // Indicate to omx core that the buffer contains a full frame worth
578             // of data
579             flags |= OMX_BUFFERFLAG_ENDOFFRAME;
580             // Indicate the omx core that this is the last buffer it needs to
581             // process
582             if (signalEOS && ((frameID == (int)Info->size() - 1) ||
583                               (frameID == (offset + range - 1))))
584                 flags |= OMX_BUFFERFLAG_EOS;
585             ASSERT_NO_FATAL_FAILURE(dispatchInputBuffer(
586                 omxNode, iBuffer, index, (*Info)[frameID].bytesCount, flags,
587                 (*Info)[frameID].timestamp));
588             frameID++;
589             iQueued = true;
590         }
591         // Dispatch output buffer
592         if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
593             ASSERT_NO_FATAL_FAILURE(
594                 dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode));
595             oQueued = true;
596         }
597         // Reset Counters when either input or output buffer is dispatched
598         if (iQueued || oQueued)
599             timeOut = TIMEOUT_COUNTER_Q;
600         else
601             timeOut--;
602         if (timeOut == 0) {
603             ASSERT_TRUE(false) << "Wait on Input/Output is found indefinite";
604         }
605     }
606 }
607 
608 // DescribeColorFormatParams Copy Constructor (Borrowed from OMXUtils.cpp)
DescribeColorFormatParams(const android::DescribeColorFormat2Params & params)609 android::DescribeColorFormatParams::DescribeColorFormatParams(
610     const android::DescribeColorFormat2Params& params) {
611     eColorFormat = params.eColorFormat;
612     nFrameWidth = params.nFrameWidth;
613     nFrameHeight = params.nFrameHeight;
614     nStride = params.nStride;
615     nSliceHeight = params.nSliceHeight;
616     bUsingNativeBuffers = params.bUsingNativeBuffers;
617 };
618 
isColorFormatFlexibleYUV(sp<IOmxNode> omxNode,OMX_COLOR_FORMATTYPE eColorFormat)619 bool isColorFormatFlexibleYUV(sp<IOmxNode> omxNode,
620                               OMX_COLOR_FORMATTYPE eColorFormat) {
621     android::hardware::media::omx::V1_0::Status status;
622     unsigned int index = OMX_IndexMax, index2 = OMX_IndexMax;
623     omxNode->getExtensionIndex(
624         "OMX.google.android.index.describeColorFormat",
625         [&index](android::hardware::media::omx::V1_0::Status _s,
626                           unsigned int _nl) {
627             if (_s == ::android::hardware::media::omx::V1_0::Status::OK)
628                 index = _nl;
629         });
630     omxNode->getExtensionIndex(
631         "OMX.google.android.index.describeColorFormat2",
632         [&index2](android::hardware::media::omx::V1_0::Status _s,
633                            unsigned int _nl) {
634             if (_s == ::android::hardware::media::omx::V1_0::Status::OK)
635                 index2 = _nl;
636         });
637 
638     android::DescribeColorFormat2Params describeParams;
639     describeParams.eColorFormat = eColorFormat;
640     describeParams.nFrameWidth = 128;
641     describeParams.nFrameHeight = 128;
642     describeParams.nStride = 128;
643     describeParams.nSliceHeight = 128;
644     describeParams.bUsingNativeBuffers = OMX_FALSE;
645     if (index != OMX_IndexMax) {
646         android::DescribeColorFormatParams describeParamsV1(describeParams);
647         status = getParam(omxNode, static_cast<OMX_INDEXTYPE>(index),
648                           &describeParamsV1);
649         if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
650             android::MediaImage& img = describeParamsV1.sMediaImage;
651             if (img.mType == android::MediaImage::MEDIA_IMAGE_TYPE_YUV) {
652                 if (img.mNumPlanes == 3 &&
653                     img.mPlane[img.Y].mHorizSubsampling == 1 &&
654                     img.mPlane[img.Y].mVertSubsampling == 1) {
655                     if (img.mPlane[img.U].mHorizSubsampling == 2 &&
656                         img.mPlane[img.U].mVertSubsampling == 2 &&
657                         img.mPlane[img.V].mHorizSubsampling == 2 &&
658                         img.mPlane[img.V].mVertSubsampling == 2) {
659                         if (img.mBitDepth <= 8) {
660                             return true;
661                         }
662                     }
663                 }
664             }
665         }
666     } else if (index2 != OMX_IndexMax) {
667         status = getParam(omxNode, static_cast<OMX_INDEXTYPE>(index2),
668                           &describeParams);
669         android::MediaImage2& img = describeParams.sMediaImage;
670         if (img.mType == android::MediaImage2::MEDIA_IMAGE_TYPE_YUV) {
671             if (img.mNumPlanes == 3 &&
672                 img.mPlane[img.Y].mHorizSubsampling == 1 &&
673                 img.mPlane[img.Y].mVertSubsampling == 1) {
674                 if (img.mPlane[img.U].mHorizSubsampling == 2 &&
675                     img.mPlane[img.U].mVertSubsampling == 2 &&
676                     img.mPlane[img.V].mHorizSubsampling == 2 &&
677                     img.mPlane[img.V].mVertSubsampling == 2) {
678                     if (img.mBitDepth <= 8) {
679                         return true;
680                     }
681                 }
682             }
683         }
684     }
685     return false;
686 }
687 
688 // get default color format for output port
getDefaultColorFormat(sp<IOmxNode> omxNode,OMX_U32 kPortIndexOutput,PortMode oPortMode,OMX_COLOR_FORMATTYPE * eColorFormat)689 void getDefaultColorFormat(sp<IOmxNode> omxNode, OMX_U32 kPortIndexOutput,
690                            PortMode oPortMode,
691                            OMX_COLOR_FORMATTYPE* eColorFormat) {
692     android::hardware::media::omx::V1_0::Status status;
693     OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
694     *eColorFormat = OMX_COLOR_FormatUnused;
695     portFormat.nIndex = 0;
696     while (portFormat.nIndex < 512) {
697         status = getPortParam(omxNode, OMX_IndexParamVideoPortFormat,
698                               kPortIndexOutput, &portFormat);
699         if (status != ::android::hardware::media::omx::V1_0::Status::OK) break;
700         EXPECT_EQ(portFormat.eCompressionFormat, OMX_VIDEO_CodingUnused);
701         if (oPortMode != PortMode::PRESET_BYTE_BUFFER) {
702             *eColorFormat = portFormat.eColorFormat;
703             break;
704         }
705         if (isColorFormatFlexibleYUV(omxNode, portFormat.eColorFormat)) {
706             *eColorFormat = portFormat.eColorFormat;
707             break;
708         }
709         if (OMX_COLOR_FormatYUV420SemiPlanar == portFormat.eColorFormat ||
710             OMX_COLOR_FormatYUV420Planar == portFormat.eColorFormat ||
711             OMX_COLOR_FormatYUV420PackedPlanar == portFormat.eColorFormat ||
712             OMX_COLOR_FormatYUV420PackedSemiPlanar == portFormat.eColorFormat) {
713             *eColorFormat = portFormat.eColorFormat;
714             break;
715         }
716         portFormat.nIndex++;
717     }
718 }
719 
720 // set component role
TEST_P(VideoDecHidlTest,SetRole)721 TEST_P(VideoDecHidlTest, SetRole) {
722     description("Test Set Component Role");
723     if (disableTest) return;
724     android::hardware::media::omx::V1_0::Status status;
725     status = setRole(omxNode, role_);
726     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
727 }
728 
729 // port format enumeration
TEST_P(VideoDecHidlTest,EnumeratePortFormat)730 TEST_P(VideoDecHidlTest, EnumeratePortFormat) {
731     description("Test Component on Mandatory Port Parameters (Port Format)");
732     if (disableTest) return;
733     android::hardware::media::omx::V1_0::Status status;
734     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
735     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatYUV420Planar;
736     OMX_U32 xFramerate = (24U << 16);
737     status = setRole(omxNode, role_);
738     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
739     OMX_PORT_PARAM_TYPE params;
740     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
741     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
742         ASSERT_EQ(params.nPorts, 2U);
743         kPortIndexInput = params.nStartPortNumber;
744         kPortIndexOutput = kPortIndexInput + 1;
745     }
746     status = setVideoPortFormat(omxNode, kPortIndexInput, eCompressionFormat,
747                                 OMX_COLOR_FormatUnused, 0U);
748     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
749     status =
750         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
751                            eColorFormat, xFramerate);
752     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
753 }
754 
755 // test port settings reconfiguration, elementary stream decode and timestamp
756 // deviation
TEST_P(VideoDecHidlTest,DecodeTest)757 TEST_P(VideoDecHidlTest, DecodeTest) {
758     description("Tests Port Reconfiguration, Decode and timestamp deviation");
759     if (disableTest) return;
760     android::hardware::media::omx::V1_0::Status status;
761     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
762     status = setRole(omxNode, role_);
763     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
764     OMX_PORT_PARAM_TYPE params;
765     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
766     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
767         ASSERT_EQ(params.nPorts, 2U);
768         kPortIndexInput = params.nStartPortNumber;
769         kPortIndexOutput = kPortIndexInput + 1;
770     }
771     char mURL[512], info[512];
772     strcpy(mURL, sResourceDir.c_str());
773     strcpy(info, sResourceDir.c_str());
774     GetURLForComponent(compName, mURL, info);
775 
776     std::ifstream eleStream, eleInfo;
777 
778     eleInfo.open(info);
779     ASSERT_EQ(eleInfo.is_open(), true);
780     android::Vector<FrameData> Info;
781     int bytesCount = 0, maxBytesCount = 0;
782     uint32_t flags = 0;
783     uint32_t timestamp = 0;
784     timestampDevTest = true;
785     while (1) {
786         if (!(eleInfo >> bytesCount)) break;
787         eleInfo >> flags;
788         eleInfo >> timestamp;
789         Info.push_back({bytesCount, flags, timestamp});
790         if (timestampDevTest && (flags != OMX_BUFFERFLAG_CODECCONFIG))
791             timestampUslist.push_back(timestamp);
792         if (maxBytesCount < bytesCount) maxBytesCount = bytesCount;
793     }
794     eleInfo.close();
795 
796     // As the frame sizes are known ahead, use it to configure i/p buffer size
797     maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10);
798     status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount);
799     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
800 
801     // set port mode
802     portMode[0] = PortMode::PRESET_BYTE_BUFFER;
803     portMode[1] = PortMode::DYNAMIC_ANW_BUFFER;
804     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
805     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
806     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
807     if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
808         portMode[1] = PortMode::PRESET_BYTE_BUFFER;
809         status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
810         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
811     }
812 
813     // set Port Params
814     uint32_t nFrameWidth, nFrameHeight, xFramerate;
815     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
816                         &xFramerate);
817     // get default color format
818     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
819     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
820                           &eColorFormat);
821     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
822     status =
823         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
824                            eColorFormat, xFramerate);
825     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
826     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
827                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
828 
829     android::Vector<BufferInfo> iBuffer, oBuffer;
830 
831     // set state to idle
832     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
833         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
834         kPortIndexOutput, portMode, true));
835     // set state to executing
836     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
837 
838     // Port Reconfiguration
839     eleStream.open(mURL, std::ifstream::binary);
840     ASSERT_EQ(eleStream.is_open(), true);
841     ASSERT_NO_FATAL_FAILURE(decodeNFrames(
842         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
843         kPortIndexOutput, eleStream, &Info, 0, (int)Info.size(), portMode[1]));
844     eleStream.close();
845     ASSERT_NO_FATAL_FAILURE(
846         waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
847                                kPortIndexInput, kPortIndexOutput, portMode[1]));
848     ASSERT_NO_FATAL_FAILURE(testEOS(
849         omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, portMode,
850         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
851     if (timestampDevTest) EXPECT_EQ(timestampUslist.empty(), true);
852     // set state to idle
853     ASSERT_NO_FATAL_FAILURE(
854         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
855     // set state to executing
856     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
857                                                     &oBuffer, kPortIndexInput,
858                                                     kPortIndexOutput));
859 }
860 
861 // Test for adaptive playback support
TEST_P(VideoDecHidlTest,AdaptivePlaybackTest)862 TEST_P(VideoDecHidlTest, AdaptivePlaybackTest) {
863     description("Tests for Adaptive Playback support");
864     if (disableTest) return;
865     if (!(compName == avc || compName == hevc || compName == vp8 ||
866           compName == vp9 || compName == mpeg2))
867         return;
868     android::hardware::media::omx::V1_0::Status status;
869     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
870     status = setRole(omxNode, role_);
871     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
872     OMX_PORT_PARAM_TYPE params;
873     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
874     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
875         ASSERT_EQ(params.nPorts, 2U);
876         kPortIndexInput = params.nStartPortNumber;
877         kPortIndexOutput = kPortIndexInput + 1;
878     }
879 
880     // set port mode
881     portMode[0] = PortMode::PRESET_BYTE_BUFFER;
882     portMode[1] = PortMode::DYNAMIC_ANW_BUFFER;
883     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
884     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
885     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
886     if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
887         portMode[1] = PortMode::PRESET_BYTE_BUFFER;
888         status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
889         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
890     }
891 
892     // prepare for adaptive playback
893     uint32_t adaptiveMaxWidth = 320;
894     uint32_t adaptiveMaxHeight = 240;
895     status = omxNode->prepareForAdaptivePlayback(
896         kPortIndexOutput, true, adaptiveMaxWidth, adaptiveMaxHeight);
897     if (component_.find("OMX.google.") == 0) {
898         // SoftOMX Decoders donot support graphic buffer modes. So for them
899         // support for adaptive play back is mandatory in Byte Buffer mode
900         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
901     } else {
902         // for vendor codecs, support for adaptive play back is optional
903         // in byte buffer mode.
904         if (portMode[1] == PortMode::PRESET_BYTE_BUFFER) return;
905         if (status != ::android::hardware::media::omx::V1_0::Status::OK) return;
906     }
907 
908     // TODO: Handle this better !!!
909     // Without the knowledge of the maximum resolution of the frame to be
910     // decoded it is not possible to choose the size of the input buffer.
911     // The value below is based on the info. files of clips in res folder.
912     status = setPortBufferSize(omxNode, kPortIndexInput, 482304);
913     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
914 
915     // set Port Params
916     uint32_t nFrameWidth, nFrameHeight, xFramerate;
917     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
918                         &xFramerate);
919     // get default color format
920     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
921     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
922                           &eColorFormat);
923     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
924     status =
925         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
926                            eColorFormat, xFramerate);
927     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
928     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
929                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
930 
931     android::Vector<BufferInfo> iBuffer, oBuffer;
932 
933     // set state to idle
934     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
935         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
936         kPortIndexOutput, portMode, true));
937     // set state to executing
938     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
939 
940     timestampDevTest = true;
941     uint32_t timestampOffset = 0;
942     for (uint32_t i = 0; i < STREAM_COUNT * 2; i++) {
943         std::ifstream eleStream, eleInfo;
944         char mURL[512], info[512];
945         android::Vector<FrameData> Info;
946         strcpy(mURL, sResourceDir.c_str());
947         strcpy(info, sResourceDir.c_str());
948         GetURLForComponent(compName, mURL, info, i % STREAM_COUNT);
949         eleInfo.open(info);
950         ASSERT_EQ(eleInfo.is_open(), true);
951         int bytesCount = 0;
952         uint32_t flags = 0;
953         uint32_t timestamp = 0;
954         uint32_t timestampMax = 0;
955         while (1) {
956             if (!(eleInfo >> bytesCount)) break;
957             eleInfo >> flags;
958             eleInfo >> timestamp;
959             timestamp += timestampOffset;
960             Info.push_back({bytesCount, flags, timestamp});
961             if (timestampDevTest && (flags != OMX_BUFFERFLAG_CODECCONFIG))
962                 timestampUslist.push_back(timestamp);
963             if (timestampMax < timestamp) timestampMax = timestamp;
964         }
965         timestampOffset = timestampMax;
966         eleInfo.close();
967 
968         // Port Reconfiguration
969         eleStream.open(mURL, std::ifstream::binary);
970         ASSERT_EQ(eleStream.is_open(), true);
971         ASSERT_NO_FATAL_FAILURE(
972             decodeNFrames(omxNode, observer, &iBuffer, &oBuffer,
973                           kPortIndexInput, kPortIndexOutput, eleStream, &Info,
974                           0, (int)Info.size(), portMode[1], false));
975         eleStream.close();
976 
977         getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth,
978                             &nFrameHeight, &xFramerate);
979         if ((nFrameWidth > adaptiveMaxWidth) ||
980             (nFrameHeight > adaptiveMaxHeight)) {
981             if (nFrameWidth > adaptiveMaxWidth) adaptiveMaxWidth = nFrameWidth;
982             if (nFrameHeight > adaptiveMaxHeight)
983                 adaptiveMaxHeight = nFrameHeight;
984             EXPECT_TRUE(portSettingsChange);
985         } else {
986             // In DynamicANW Buffer mode, its ok to do a complete
987             // reconfiguration even if a partial reconfiguration is sufficient.
988             if (portMode[1] != PortMode::DYNAMIC_ANW_BUFFER)
989                 EXPECT_FALSE(portSettingsChange);
990         }
991         portSettingsChange = false;
992     }
993     ASSERT_NO_FATAL_FAILURE(
994         waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
995                                kPortIndexInput, kPortIndexOutput, portMode[1]));
996     ASSERT_NO_FATAL_FAILURE(testEOS(
997         omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
998         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
999     if (timestampDevTest) EXPECT_EQ(timestampUslist.empty(), true);
1000     // set state to idle
1001     ASSERT_NO_FATAL_FAILURE(
1002         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1003     // set state to executing
1004     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1005                                                     &oBuffer, kPortIndexInput,
1006                                                     kPortIndexOutput));
1007 }
1008 
1009 // end of sequence test
TEST_P(VideoDecHidlTest,EOSTest_M)1010 TEST_P(VideoDecHidlTest, EOSTest_M) {
1011     description("Test End of stream monkeying");
1012     if (disableTest) return;
1013     android::hardware::media::omx::V1_0::Status status;
1014     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
1015     status = setRole(omxNode, role_);
1016     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1017     OMX_PORT_PARAM_TYPE params;
1018     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
1019     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
1020         ASSERT_EQ(params.nPorts, 2U);
1021         kPortIndexInput = params.nStartPortNumber;
1022         kPortIndexOutput = kPortIndexInput + 1;
1023     }
1024 
1025     // set port mode
1026     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
1027     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1028     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1029     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1030 
1031     // set Port Params
1032     uint32_t nFrameWidth, nFrameHeight, xFramerate;
1033     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
1034                         &xFramerate);
1035     // get default color format
1036     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
1037     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
1038                           &eColorFormat);
1039     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
1040     status =
1041         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1042                            eColorFormat, xFramerate);
1043     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1044     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1045                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
1046 
1047     android::Vector<BufferInfo> iBuffer, oBuffer;
1048 
1049     // set state to idle
1050     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
1051         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1052         kPortIndexOutput, portMode, true));
1053     // set state to executing
1054     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1055 
1056     // request EOS at the start
1057     ASSERT_NO_FATAL_FAILURE(testEOS(
1058         omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
1059         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
1060     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1061                                        kPortIndexInput, kPortIndexOutput));
1062     EXPECT_GE(framesReceived, 0U);
1063     framesReceived = 0;
1064     timestampUs = 0;
1065 
1066     // set state to idle
1067     ASSERT_NO_FATAL_FAILURE(
1068         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1069     // set state to executing
1070     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1071                                                     &oBuffer, kPortIndexInput,
1072                                                     kPortIndexOutput));
1073 }
1074 
1075 // end of sequence test
TEST_P(VideoDecHidlTest,ThumbnailTest)1076 TEST_P(VideoDecHidlTest, ThumbnailTest) {
1077     description("Test Request for thumbnail");
1078     if (disableTest) return;
1079     android::hardware::media::omx::V1_0::Status status;
1080     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
1081     status = setRole(omxNode, role_);
1082     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1083     OMX_PORT_PARAM_TYPE params;
1084     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
1085     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
1086         ASSERT_EQ(params.nPorts, 2U);
1087         kPortIndexInput = params.nStartPortNumber;
1088         kPortIndexOutput = kPortIndexInput + 1;
1089     }
1090     char mURL[512], info[512];
1091     strcpy(mURL, sResourceDir.c_str());
1092     strcpy(info, sResourceDir.c_str());
1093     GetURLForComponent(compName, mURL, info);
1094 
1095     std::ifstream eleStream, eleInfo;
1096 
1097     eleInfo.open(info);
1098     ASSERT_EQ(eleInfo.is_open(), true);
1099     android::Vector<FrameData> Info;
1100     int bytesCount = 0, maxBytesCount = 0;
1101     uint32_t flags = 0;
1102     uint32_t timestamp = 0;
1103     while (1) {
1104         if (!(eleInfo >> bytesCount)) break;
1105         eleInfo >> flags;
1106         eleInfo >> timestamp;
1107         Info.push_back({bytesCount, flags, timestamp});
1108         if (maxBytesCount < bytesCount) maxBytesCount = bytesCount;
1109     }
1110     eleInfo.close();
1111 
1112     // As the frame sizes are known ahead, use it to configure i/p buffer size
1113     maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10);
1114     status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount);
1115     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1116 
1117     // set port mode
1118     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
1119     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1120     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1121     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1122 
1123     // set Port Params
1124     uint32_t nFrameWidth, nFrameHeight, xFramerate;
1125     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
1126                         &xFramerate);
1127     // get default color format
1128     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
1129     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
1130                           &eColorFormat);
1131     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
1132     status =
1133         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1134                            eColorFormat, xFramerate);
1135     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1136     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1137                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
1138 
1139     android::Vector<BufferInfo> iBuffer, oBuffer;
1140 
1141     // set state to idle
1142     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
1143         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1144         kPortIndexOutput, portMode, true));
1145     // set state to executing
1146     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1147 
1148     // request EOS for thumbnail
1149     size_t i = 0;
1150     while (!(Info[i].flags & OMX_BUFFERFLAG_SYNCFRAME)) i++;
1151     eleStream.open(mURL, std::ifstream::binary);
1152     ASSERT_EQ(eleStream.is_open(), true);
1153     ASSERT_NO_FATAL_FAILURE(decodeNFrames(
1154         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1155         kPortIndexOutput, eleStream, &Info, 0, i + 1, portMode[1]));
1156     eleStream.close();
1157     ASSERT_NO_FATAL_FAILURE(
1158         waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
1159                                kPortIndexInput, kPortIndexOutput, portMode[1]));
1160     ASSERT_NO_FATAL_FAILURE(testEOS(
1161         omxNode, observer, &iBuffer, &oBuffer, false, eosFlag, portMode,
1162         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
1163     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1164                                        kPortIndexInput, kPortIndexOutput));
1165     EXPECT_GE(framesReceived, 1U);
1166     framesReceived = 0;
1167     timestampUs = 0;
1168 
1169     eleStream.open(mURL, std::ifstream::binary);
1170     ASSERT_EQ(eleStream.is_open(), true);
1171     ASSERT_NO_FATAL_FAILURE(decodeNFrames(
1172         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1173         kPortIndexOutput, eleStream, &Info, 0, i + 1, portMode[1], false));
1174     eleStream.close();
1175     ASSERT_NO_FATAL_FAILURE(
1176         waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
1177                                kPortIndexInput, kPortIndexOutput, portMode[1]));
1178     ASSERT_NO_FATAL_FAILURE(testEOS(
1179         omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
1180         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
1181     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1182                                        kPortIndexInput, kPortIndexOutput));
1183     EXPECT_GE(framesReceived, 1U);
1184     framesReceived = 0;
1185     timestampUs = 0;
1186 
1187     // set state to idle
1188     ASSERT_NO_FATAL_FAILURE(
1189         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1190     // set state to executing
1191     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1192                                                     &oBuffer, kPortIndexInput,
1193                                                     kPortIndexOutput));
1194 }
1195 
1196 // end of sequence test
TEST_P(VideoDecHidlTest,SimpleEOSTest)1197 TEST_P(VideoDecHidlTest, SimpleEOSTest) {
1198     description("Test End of stream");
1199     if (disableTest) return;
1200     android::hardware::media::omx::V1_0::Status status;
1201     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
1202     status = setRole(omxNode, role_);
1203     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1204     OMX_PORT_PARAM_TYPE params;
1205     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
1206     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
1207         ASSERT_EQ(params.nPorts, 2U);
1208         kPortIndexInput = params.nStartPortNumber;
1209         kPortIndexOutput = kPortIndexInput + 1;
1210     }
1211     char mURL[512], info[512];
1212     strcpy(mURL, sResourceDir.c_str());
1213     strcpy(info, sResourceDir.c_str());
1214     GetURLForComponent(compName, mURL, info);
1215 
1216     std::ifstream eleStream, eleInfo;
1217 
1218     eleInfo.open(info);
1219     ASSERT_EQ(eleInfo.is_open(), true);
1220     android::Vector<FrameData> Info;
1221     int bytesCount = 0, maxBytesCount = 0;
1222     uint32_t flags = 0;
1223     uint32_t timestamp = 0;
1224     while (1) {
1225         if (!(eleInfo >> bytesCount)) break;
1226         eleInfo >> flags;
1227         eleInfo >> timestamp;
1228         Info.push_back({bytesCount, flags, timestamp});
1229         if (maxBytesCount < bytesCount) maxBytesCount = bytesCount;
1230     }
1231     eleInfo.close();
1232 
1233     // As the frame sizes are known ahead, use it to configure i/p buffer size
1234     maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10);
1235     status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount);
1236     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1237 
1238     // set port mode
1239     portMode[0] = PortMode::PRESET_BYTE_BUFFER;
1240     portMode[1] = PortMode::PRESET_ANW_BUFFER;
1241     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
1242     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1243     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1244     if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
1245         portMode[1] = PortMode::PRESET_BYTE_BUFFER;
1246         status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1247         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1248     }
1249 
1250     // set Port Params
1251     uint32_t nFrameWidth, nFrameHeight, xFramerate;
1252     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
1253                         &xFramerate);
1254     // get default color format
1255     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
1256     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
1257                           &eColorFormat);
1258     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
1259     status =
1260         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1261                            eColorFormat, xFramerate);
1262     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1263     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1264                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
1265 
1266     android::Vector<BufferInfo> iBuffer, oBuffer;
1267 
1268     // set state to idle
1269     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
1270         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1271         kPortIndexOutput, portMode, true));
1272     // set state to executing
1273     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1274 
1275     // request EOS at the end
1276     eleStream.open(mURL, std::ifstream::binary);
1277     ASSERT_EQ(eleStream.is_open(), true);
1278     ASSERT_NO_FATAL_FAILURE(decodeNFrames(omxNode, observer, &iBuffer, &oBuffer,
1279                                           kPortIndexInput, kPortIndexOutput,
1280                                           eleStream, &Info, 0, (int)Info.size(),
1281                                           portMode[1], false));
1282     eleStream.close();
1283     ASSERT_NO_FATAL_FAILURE(
1284         waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
1285                                kPortIndexInput, kPortIndexOutput, portMode[1]));
1286     ASSERT_NO_FATAL_FAILURE(testEOS(
1287         omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
1288         portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr));
1289     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1290                                        kPortIndexInput, kPortIndexOutput));
1291     framesReceived = 0;
1292     timestampUs = 0;
1293 
1294     // set state to idle
1295     ASSERT_NO_FATAL_FAILURE(
1296         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1297     // set state to executing
1298     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1299                                                     &oBuffer, kPortIndexInput,
1300                                                     kPortIndexOutput));
1301 }
1302 
1303 // test input/output port flush
TEST_P(VideoDecHidlTest,FlushTest)1304 TEST_P(VideoDecHidlTest, FlushTest) {
1305     description("Test Flush");
1306     if (disableTest) return;
1307     android::hardware::media::omx::V1_0::Status status;
1308     uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
1309     status = setRole(omxNode, role_);
1310     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1311     OMX_PORT_PARAM_TYPE params;
1312     status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
1313     if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
1314         ASSERT_EQ(params.nPorts, 2U);
1315         kPortIndexInput = params.nStartPortNumber;
1316         kPortIndexOutput = kPortIndexInput + 1;
1317     }
1318     char mURL[512], info[512];
1319     strcpy(mURL, sResourceDir.c_str());
1320     strcpy(info, sResourceDir.c_str());
1321     GetURLForComponent(compName, mURL, info);
1322 
1323     std::ifstream eleStream, eleInfo;
1324 
1325     eleInfo.open(info);
1326     ASSERT_EQ(eleInfo.is_open(), true);
1327     android::Vector<FrameData> Info;
1328     int bytesCount = 0, maxBytesCount = 0;
1329     uint32_t flags = 0;
1330     uint32_t timestamp = 0;
1331     while (1) {
1332         if (!(eleInfo >> bytesCount)) break;
1333         eleInfo >> flags;
1334         eleInfo >> timestamp;
1335         Info.push_back({bytesCount, flags, timestamp});
1336         if (maxBytesCount < bytesCount) maxBytesCount = bytesCount;
1337     }
1338     eleInfo.close();
1339 
1340     // As the frame sizes are known ahead, use it to configure i/p buffer size
1341     maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10);
1342     status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount);
1343     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1344 
1345     // set port mode
1346     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
1347     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1348     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
1349     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1350 
1351     // set Port Params
1352     uint32_t nFrameWidth, nFrameHeight, xFramerate;
1353     getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
1354                         &xFramerate);
1355     // get default color format
1356     OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
1357     getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
1358                           &eColorFormat);
1359     ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
1360     status =
1361         setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1362                            eColorFormat, xFramerate);
1363     EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
1364     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
1365                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
1366 
1367     android::Vector<BufferInfo> iBuffer, oBuffer;
1368 
1369     // set state to idle
1370     ASSERT_NO_FATAL_FAILURE(changeStateLoadedtoIdle(
1371         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1372         kPortIndexOutput, portMode, true));
1373     // set state to executing
1374     ASSERT_NO_FATAL_FAILURE(changeStateIdletoExecute(omxNode, observer));
1375 
1376     // Decode 128 frames and flush. here 128 is chosen to ensure there is a key
1377     // frame after this so that the below section can be convered for all
1378     // components
1379     int nFrames = 128;
1380     eleStream.open(mURL, std::ifstream::binary);
1381     ASSERT_EQ(eleStream.is_open(), true);
1382     ASSERT_NO_FATAL_FAILURE(decodeNFrames(
1383         omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
1384         kPortIndexOutput, eleStream, &Info, 0, nFrames, portMode[1], false));
1385     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1386                                        kPortIndexInput, kPortIndexOutput));
1387     framesReceived = 0;
1388 
1389     // Seek to next key frame and start decoding till the end
1390     int index = nFrames;
1391     bool keyFrame = false;
1392     while (index < (int)Info.size()) {
1393         if ((Info[index].flags & OMX_BUFFERFLAG_SYNCFRAME) ==
1394             OMX_BUFFERFLAG_SYNCFRAME) {
1395             timestampUs = Info[index - 1].timestamp;
1396             keyFrame = true;
1397             break;
1398         }
1399         eleStream.ignore(Info[index].bytesCount);
1400         index++;
1401     }
1402     if (keyFrame) {
1403         ASSERT_NO_FATAL_FAILURE(
1404             decodeNFrames(omxNode, observer, &iBuffer, &oBuffer,
1405                           kPortIndexInput, kPortIndexOutput, eleStream, &Info,
1406                           index, Info.size() - index, portMode[1], false));
1407     }
1408     eleStream.close();
1409     ASSERT_NO_FATAL_FAILURE(flushPorts(omxNode, observer, &iBuffer, &oBuffer,
1410                                        kPortIndexInput, kPortIndexOutput));
1411     framesReceived = 0;
1412 
1413     // set state to idle
1414     ASSERT_NO_FATAL_FAILURE(
1415         changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer));
1416     // set state to executing
1417     ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer,
1418                                                     &oBuffer, kPortIndexInput,
1419                                                     kPortIndexOutput));
1420 }
1421 
1422 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VideoDecHidlTest);
1423 INSTANTIATE_TEST_SUITE_P(PerInstance, VideoDecHidlTest, testing::ValuesIn(kTestParameters),
1424                          android::hardware::PrintInstanceTupleNameToString<>);
1425 
main(int argc,char ** argv)1426 int main(int argc, char** argv) {
1427     kTestParameters = getTestParameters("video_decoder");
1428     ::testing::InitGoogleTest(&argc, argv);
1429 
1430     // Set the resource directory based on command line args.
1431     // Test will fail to set up if the argument is not set.
1432     for (int i = 1; i < argc; i++) {
1433         if (strcmp(argv[i], "-P") == 0 && i < argc - 1) {
1434             sResourceDir = argv[i + 1];
1435             break;
1436         }
1437     }
1438 
1439     return RUN_ALL_TESTS();
1440 }