@ -19,15 +19,16 @@
# include <android-base/logging.h>
# include <gtest/gtest.h>
# include <hidl/GtestPrinter.h>
# include <stdio.h>
# include <fstream>
# include <codec2/hidl/client.h>
# include <C2AllocatorIon.h>
# include <C2Config.h>
# include <C2Debug.h>
# include <C2Buffer.h>
# include <C2BufferPriv.h>
# include <C2Config.h>
# include <C2Debug.h>
# include <codec2/hidl/client.h>
# include <gui/BufferQueue.h>
# include <gui/IConsumerListener.h>
# include <gui/IProducerListener.h>
@ -35,9 +36,8 @@
using android : : C2AllocatorIon ;
# include <VtsHalHidlTargetTestBase.h>
# include "media_c2_video_hidl_test_common.h"
# include "media_c2_hidl_test_common.h"
# include "media_c2_video_hidl_test_common.h"
struct FrameInfo {
int bytesCount ;
@ -45,61 +45,47 @@ struct FrameInfo {
int64_t timestamp ;
} ;
static std : : vector < std : : tuple < std : : string , std : : string , std : : string , std : : string > >
kDecodeTestParameters ;
// Resource directory
static std : : string sResourceDir = " " ;
class LinearBuffer : public C2Buffer {
public :
explicit LinearBuffer ( const std : : shared_ptr < C2LinearBlock > & block )
: C2Buffer (
{ block - > share ( block - > offset ( ) , block - > size ( ) , : : C2Fence ( ) ) } ) { }
: C2Buffer ( { block - > share ( block - > offset ( ) , block - > size ( ) , : : C2Fence ( ) ) } ) { }
explicit LinearBuffer ( const std : : shared_ptr < C2LinearBlock > & block , size_t size )
: C2Buffer (
{ block - > share ( block - > offset ( ) , size , : : C2Fence ( ) ) } ) { }
: C2Buffer ( { block - > share ( block - > offset ( ) , size , : : C2Fence ( ) ) } ) { }
} ;
static ComponentTestEnvironment * gEnv = nullptr ;
namespace {
class Codec2VideoDecHidlTest : public : : testing : : VtsHalHidlTargetTestBase {
private :
typedef : : testing : : VtsHalHidlTargetTestBase Super ;
class Codec2VideoDecHidlTestBase : public : : testing : : Test {
public :
: : std : : string getTestCaseInfo ( ) const override {
return : : std : : string ( ) +
" Component: " + gEnv - > getComponent ( ) . c_str ( ) + " | " +
" Instance: " + gEnv - > getInstance ( ) . c_str ( ) + " | " +
" Res: " + gEnv - > getRes ( ) . c_str ( ) ;
}
// google.codec2 Video test setup
virtual void SetUp ( ) override {
Super: : SetUp ( ) ;
getParams ( ) ;
mDisableTest = false ;
ALOGV ( " Codec2VideoDecHidlTest SetUp " ) ;
mClient = android : : Codec2Client : : CreateFromService (
gEnv - > getInstance ( ) . c_str ( ) ,
mInstanceName . c_str ( ) ,
! bool ( android : : Codec2Client : : CreateFromService ( " default " , true ) ) ) ;
ASSERT_NE ( mClient , nullptr ) ;
mListener . reset ( new CodecListener (
[ this ] ( std : : list < std : : unique_ptr < C2Work > > & workItems ) {
mListener . reset ( new CodecListener ( [ this ] ( std : : list < std : : unique_ptr < C2Work > > & workItems ) {
handleWorkDone ( workItems ) ;
} ) ) ;
ASSERT_NE ( mListener , nullptr ) ;
for ( int i = 0 ; i < MAX_INPUT_BUFFERS ; + + i ) {
mWorkQueue . emplace_back ( new C2Work ) ;
}
mClient - > createComponent ( gEnv - > getComponent ( ) . c_str ( ) , mListener ,
& mComponent ) ;
mClient - > createComponent ( mComponentName , mListener , & mComponent ) ;
ASSERT_NE ( mComponent , nullptr ) ;
std : : shared_ptr < C2AllocatorStore > store =
android : : GetCodec2PlatformAllocatorStore ( ) ;
CHECK_EQ ( store - > fetchAllocator ( C2AllocatorStore : : DEFAULT_LINEAR ,
& mLinearAllocator ) ,
C2_OK ) ;
mLinearPool = std : : make_shared < C2PooledBlockPool > ( mLinearAllocator ,
mBlockPoolId + + ) ;
std : : shared_ptr < C2AllocatorStore > store = android : : GetCodec2PlatformAllocatorStore ( ) ;
CHECK_EQ ( store - > fetchAllocator ( C2AllocatorStore : : DEFAULT_LINEAR , & mLinearAllocator ) , C2_OK ) ;
mLinearPool = std : : make_shared < C2PooledBlockPool > ( mLinearAllocator , mBlockPoolId + + ) ;
ASSERT_NE ( mLinearPool , nullptr ) ;
mCompName = unknown_comp ;
@ -113,13 +99,11 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
{ " hevc " , hevc } , { " vp8 " , vp8 } , { " vp9 " , vp9 } , { " av1 " , av1 } ,
} ;
const size_t kNumStringToName =
sizeof ( kStringToName ) / sizeof ( kStringToName [ 0 ] ) ;
const size_t kNumStringToName = sizeof ( kStringToName ) / sizeof ( kStringToName [ 0 ] ) ;
// Find the component type
std : : string comp = std : : string ( gEnv - > getComponent ( ) ) ;
for ( size_t i = 0 ; i < kNumStringToName ; + + i ) {
if ( strcasestr ( comp . c_str ( ) , kStringToName [ i ] . Name ) ) {
if ( strcasestr ( mComponentName . c_str ( ) , kStringToName [ i ] . Name ) ) {
mCompName = kStringToName [ i ] . CompName ;
break ;
}
@ -131,7 +115,7 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
if ( mCompName = = unknown_comp ) mDisableTest = true ;
C2SecureModeTuning secureModeTuning { } ;
mComponent - > query ( { & secureModeTuning } , { } , C2_MAY_BLOCK , nullptr ) ;
mComponent - > query ( { & secureModeTuning } , { } , C2_MAY_BLOCK , nullptr ) ;
if ( secureModeTuning . value = = C2Config : : SM_READ_PROTECTED ) {
mDisableTest = true ;
}
@ -145,9 +129,11 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
mComponent - > release ( ) ;
mComponent = nullptr ;
}
Super : : TearDown ( ) ;
}
// Get the test parameters from GetParam call.
virtual void getParams ( ) { }
// callback function to process onWorkDone received by Listener
void handleWorkDone ( std : : list < std : : unique_ptr < C2Work > > & workItems ) {
for ( std : : unique_ptr < C2Work > & work : workItems ) {
@ -157,13 +143,10 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
typedef std : : unique_lock < std : : mutex > ULock ;
bool codecConfig = ( ( work - > worklets . front ( ) - > output . flags &
C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 ) ;
if ( ! codecConfig & &
! work - > worklets . front ( ) - > output . buffers . empty ( ) ) {
EXPECT_GE (
( work - > worklets . front ( ) - > output . ordinal . timestamp . peeku ( ) ) ,
if ( ! codecConfig & & ! work - > worklets . front ( ) - > output . buffers . empty ( ) ) {
EXPECT_GE ( ( work - > worklets . front ( ) - > output . ordinal . timestamp . peeku ( ) ) ,
mTimestampUs ) ;
mTimestampUs =
work - > worklets . front ( ) - > output . ordinal . timestamp . peeku ( ) ;
mTimestampUs = work - > worklets . front ( ) - > output . ordinal . timestamp . peeku ( ) ;
ULock l ( mQueueLock ) ;
if ( mTimestampDevTest ) {
@ -179,8 +162,7 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
}
if ( tsHit = = false ) {
if ( mTimestampUslist . empty ( ) = = false ) {
EXPECT_EQ ( tsHit , true )
< < " TimeStamp not recognized " ;
EXPECT_EQ ( tsHit , true ) < < " TimeStamp not recognized " ;
} else {
std : : cout < < " [ INFO ] Received non-zero "
" output / TimeStamp not recognized \n " ;
@ -189,9 +171,8 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
}
}
bool mCsd ;
workDone ( mComponent , work , mFlushedIndices , mQueueLock ,
mQueueCondition , mWorkQueue , mEos , mCsd ,
mFramesReceived ) ;
workDone ( mComponent , work , mFlushedIndices , mQueueLock , mQueueCondition , mWorkQueue ,
mEos , mCsd , mFramesReceived ) ;
( void ) mCsd ;
}
}
@ -209,6 +190,9 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
unknown_comp ,
} ;
std : : string mInstanceName ;
std : : string mComponentName ;
bool mEos ;
bool mDisableTest ;
bool mTimestampDevTest ;
@ -235,8 +219,16 @@ class Codec2VideoDecHidlTest : public ::testing::VtsHalHidlTargetTestBase {
}
} ;
void validateComponent (
const std : : shared_ptr < android : : Codec2Client : : Component > & component ,
class Codec2VideoDecHidlTest
: public Codec2VideoDecHidlTestBase ,
public : : testing : : WithParamInterface < std : : tuple < std : : string , std : : string > > {
void getParams ( ) {
mInstanceName = std : : get < 0 > ( GetParam ( ) ) ;
mComponentName = std : : get < 1 > ( GetParam ( ) ) ;
}
} ;
void validateComponent ( const std : : shared_ptr < android : : Codec2Client : : Component > & component ,
Codec2VideoDecHidlTest : : standardComp compName , bool & disableTest ) {
// Validate its a C2 Component
if ( component - > getName ( ) . find ( " c2 " ) = = std : : string : : npos ) {
@ -252,14 +244,12 @@ void validateComponent(
return ;
}
std : : vector < std : : unique_ptr < C2Param > > queried ;
c2_status_t c2err =
component - > query ( { } , { C2PortMediaTypeSetting : : input : : PARAM_TYPE } ,
c2_status_t c2err = component - > query ( { } , { C2PortMediaTypeSetting : : input : : PARAM_TYPE } ,
C2_DONT_BLOCK , & queried ) ;
if ( c2err ! = C2_OK & & queried . size ( ) = = 0 ) {
ALOGE ( " Query media type failed => %d " , c2err ) ;
} else {
std : : string inputDomain =
( ( C2StreamMediaTypeSetting : : input * ) queried [ 0 ] . get ( ) ) - > m . value ;
std : : string inputDomain = ( ( C2StreamMediaTypeSetting : : input * ) queried [ 0 ] . get ( ) ) - > m . value ;
if ( inputDomain . find ( " video/ " ) = = std : : string : : npos ) {
ALOGE ( " Expected Video Component " ) ;
disableTest = true ;
@ -279,8 +269,8 @@ void validateComponent(
// number of elementary streams per component
# define STREAM_COUNT 2
// LookUpTable of clips and metadata for component testing
void GetURLForComponent ( Codec2VideoDecHidlTest : : standardComp comp , char * mURL ,
char * info , size_t streamIndex = 1 ) {
void GetURLForComponent ( Codec2VideoDecHidlTest : : standardComp comp , char * mURL , char * info ,
size_t streamIndex = 1 ) {
struct CompToURL {
Codec2VideoDecHidlTest : : standardComp comp ;
const char mURL [ STREAM_COUNT ] [ 512 ] ;
@ -290,20 +280,14 @@ void GetURLForComponent(Codec2VideoDecHidlTest::standardComp comp, char* mURL,
static const CompToURL kCompToURL [ ] = {
{ Codec2VideoDecHidlTest : : standardComp : : avc ,
{ " bbb_avc_176x144_300kbps_60fps.h264 " ,
" bbb_avc_640x360_768kbps_30fps.h264 " } ,
{ " bbb_avc_176x144_300kbps_60fps.info " ,
" bbb_avc_640x360_768kbps_30fps.info " } } ,
{ " bbb_avc_176x144_300kbps_60fps.h264 " , " bbb_avc_640x360_768kbps_30fps.h264 " } ,
{ " bbb_avc_176x144_300kbps_60fps.info " , " bbb_avc_640x360_768kbps_30fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : hevc ,
{ " bbb_hevc_176x144_176kbps_60fps.hevc " ,
" bbb_hevc_640x360_1600kbps_30fps.hevc " } ,
{ " bbb_hevc_176x144_176kbps_60fps.info " ,
" bbb_hevc_640x360_1600kbps_30fps.info " } } ,
{ " bbb_hevc_176x144_176kbps_60fps.hevc " , " bbb_hevc_640x360_1600kbps_30fps.hevc " } ,
{ " bbb_hevc_176x144_176kbps_60fps.info " , " bbb_hevc_640x360_1600kbps_30fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : mpeg2 ,
{ " bbb_mpeg2_176x144_105kbps_25fps.m2v " ,
" bbb_mpeg2_352x288_1mbps_60fps.m2v " } ,
{ " bbb_mpeg2_176x144_105kbps_25fps.info " ,
" bbb_mpeg2_352x288_1mbps_60fps.info " } } ,
{ " bbb_mpeg2_176x144_105kbps_25fps.m2v " , " bbb_mpeg2_352x288_1mbps_60fps.m2v " } ,
{ " bbb_mpeg2_176x144_105kbps_25fps.info " , " bbb_mpeg2_352x288_1mbps_60fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : h263 ,
{ " " , " bbb_h263_352x288_300kbps_12fps.h263 " } ,
{ " " , " bbb_h263_352x288_300kbps_12fps.info " } } ,
@ -311,20 +295,14 @@ void GetURLForComponent(Codec2VideoDecHidlTest::standardComp comp, char* mURL,
{ " " , " bbb_mpeg4_352x288_512kbps_30fps.m4v " } ,
{ " " , " bbb_mpeg4_352x288_512kbps_30fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : vp8 ,
{ " bbb_vp8_176x144_240kbps_60fps.vp8 " ,
" bbb_vp8_640x360_2mbps_30fps.vp8 " } ,
{ " bbb_vp8_176x144_240kbps_60fps.info " ,
" bbb_vp8_640x360_2mbps_30fps.info " } } ,
{ " bbb_vp8_176x144_240kbps_60fps.vp8 " , " bbb_vp8_640x360_2mbps_30fps.vp8 " } ,
{ " bbb_vp8_176x144_240kbps_60fps.info " , " bbb_vp8_640x360_2mbps_30fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : vp9 ,
{ " bbb_vp9_176x144_285kbps_60fps.vp9 " ,
" bbb_vp9_640x360_1600kbps_30fps.vp9 " } ,
{ " bbb_vp9_176x144_285kbps_60fps.info " ,
" bbb_vp9_640x360_1600kbps_30fps.info " } } ,
{ " bbb_vp9_176x144_285kbps_60fps.vp9 " , " bbb_vp9_640x360_1600kbps_30fps.vp9 " } ,
{ " bbb_vp9_176x144_285kbps_60fps.info " , " bbb_vp9_640x360_1600kbps_30fps.info " } } ,
{ Codec2VideoDecHidlTest : : standardComp : : av1 ,
{ " bbb_av1_640_360.av1 " ,
" bbb_av1_176_144.av1 " } ,
{ " bbb_av1_640_360.info " ,
" bbb_av1_176_144.info " } } ,
{ " bbb_av1_640_360.av1 " , " bbb_av1_176_144.av1 " } ,
{ " bbb_av1_640_360.info " , " bbb_av1_176_144.info " } } ,
} ;
for ( size_t i = 0 ; i < sizeof ( kCompToURL ) / sizeof ( kCompToURL [ 0 ] ) ; + + i ) {
@ -337,13 +315,11 @@ void GetURLForComponent(Codec2VideoDecHidlTest::standardComp comp, char* mURL,
}
void decodeNFrames ( const std : : shared_ptr < android : : Codec2Client : : Component > & component ,
std : : mutex & queueLock , std : : condition_variable & queueCondition ,
std : : mutex & queueLock , std : : condition_variable & queueCondition ,
std : : list < std : : unique_ptr < C2Work > > & workQueue ,
std : : list < uint64_t > & flushedIndices ,
std : : shared_ptr < C2BlockPool > & linearPool ,
std : : ifstream & eleStream ,
android : : Vector < FrameInfo > * Info ,
int offset , int range , bool signalEOS = true ) {
std : : list < uint64_t > & flushedIndices , std : : shared_ptr < C2BlockPool > & linearPool ,
std : : ifstream & eleStream , android : : Vector < FrameInfo > * Info , int offset ,
int range , bool signalEOS = true ) {
typedef std : : unique_lock < std : : mutex > ULock ;
int frameID = offset ;
int maxRetry = 0 ;
@ -367,8 +343,7 @@ void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& comp
}
int64_t timestamp = ( * Info ) [ frameID ] . timestamp ;
if ( ( * Info ) [ frameID ] . flags ) flags = ( 1 < < ( ( * Info ) [ frameID ] . flags - 1 ) ) ;
if ( signalEOS & & ( ( frameID = = ( int ) Info - > size ( ) - 1 ) | |
( frameID = = ( offset + range - 1 ) ) ) )
if ( signalEOS & & ( ( frameID = = ( int ) Info - > size ( ) - 1 ) | | ( frameID = = ( offset + range - 1 ) ) ) )
flags | = C2FrameData : : FLAG_END_OF_STREAM ;
work - > input . flags = ( C2FrameData : : flags_t ) flags ;
@ -390,10 +365,9 @@ void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& comp
auto alignedSize = ALIGN ( size , PAGE_SIZE ) ;
if ( size ) {
std : : shared_ptr < C2LinearBlock > block ;
ASSERT_EQ ( C2_OK ,
linearPool - > fetchLinearBlock (
alignedSize , { C2MemoryUsage : : CPU_READ , C2MemoryUsage : : CPU_WRITE } ,
& block ) ) ;
ASSERT_EQ ( C2_OK , linearPool - > fetchLinearBlock (
alignedSize ,
{ C2MemoryUsage : : CPU_READ , C2MemoryUsage : : CPU_WRITE } , & block ) ) ;
ASSERT_TRUE ( block ) ;
// Write View
@ -424,16 +398,16 @@ void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& comp
}
}
TEST_ F ( Codec2VideoDecHidlTest , validateCompName ) {
if ( mDisableTest ) return ;
TEST_ P ( Codec2VideoDecHidlTest , validateCompName ) {
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
ALOGV ( " Checks if the given component is a valid video component " ) ;
validateComponent ( mComponent , mCompName , mDisableTest ) ;
ASSERT_EQ ( mDisableTest , false ) ;
}
TEST_ F ( Codec2VideoDecHidlTest , configureTunnel ) {
TEST_ P ( Codec2VideoDecHidlTest , configureTunnel ) {
description ( " Attempts to configure tunneling " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
ALOGV ( " Checks if the component can be configured for tunneling " ) ;
native_handle_t * sidebandStream { } ;
c2_status_t err = mComponent - > configureVideoTunnel ( 0 , & sidebandStream ) ;
@ -465,30 +439,32 @@ TEST_F(Codec2VideoDecHidlTest, configureTunnel) {
virtual void onBuffersDiscarded ( const std : : vector < int32_t > & ) override { }
} ;
IGraphicBufferProducer : : QueueBufferOutput qbo { } ;
producer - > connect ( new DummyProducerListener ( ) ,
NATIVE_WINDOW_API_MEDIA ,
false ,
& qbo ) ;
producer - > connect ( new DummyProducerListener ( ) , NATIVE_WINDOW_API_MEDIA , false , & qbo ) ;
ASSERT_EQ ( producer - > setSidebandStream ( nativeHandle ) , NO_ERROR ) ;
}
class Codec2VideoDecDecodeTest
: public Codec2VideoDecHidlTest ,
public : : testing : : WithParamInterface < std : : pair < int32_t , bool > > {
: public Codec2VideoDecHidlTestBase ,
public : : testing : : WithParamInterface <
std : : tuple < std : : string , std : : string , std : : string , std : : string > > {
void getParams ( ) {
mInstanceName = std : : get < 0 > ( GetParam ( ) ) ;
mComponentName = std : : get < 1 > ( GetParam ( ) ) ;
}
} ;
// Bitstream Test
TEST_P ( Codec2VideoDecDecodeTest , DecodeTest ) {
description ( " Decodes input file " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
uint32_t streamIndex = GetParam( ) . first ;
bool signalEOS = GetParam ( ) . second ;
uint32_t streamIndex = std: : stoi ( std : : get < 2 > ( GetParam ( ) ) ) ;
bool signalEOS = ! std : : get < 2 > ( GetParam ( ) ) . compare ( " true " ) ;
char mURL [ 512 ] , info [ 512 ] ;
std : : ifstream eleStream , eleInfo ;
strcpy ( mURL , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( info , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( mURL , sResourceDir . c_str ( ) ) ;
strcpy ( info , sResourceDir . c_str ( ) ) ;
GetURLForComponent ( mCompName , mURL , info , streamIndex ) ;
eleInfo . open ( info ) ;
@ -504,10 +480,8 @@ TEST_P(Codec2VideoDecDecodeTest, DecodeTest) {
if ( ! ( eleInfo > > bytesCount ) ) break ;
eleInfo > > flags ;
eleInfo > > timestamp ;
bool codecConfig = flags ?
( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
if ( mTimestampDevTest & & ! codecConfig )
mTimestampUslist . push_back ( timestamp ) ;
bool codecConfig = flags ? ( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
if ( mTimestampDevTest & & ! codecConfig ) mTimestampUslist . push_back ( timestamp ) ;
Info . push_back ( { bytesCount , flags , timestamp } ) ;
}
eleInfo . close ( ) ;
@ -519,17 +493,15 @@ TEST_P(Codec2VideoDecDecodeTest, DecodeTest) {
ALOGV ( " mURL : %s " , mURL ) ;
eleStream . open ( mURL , std : : ifstream : : binary ) ;
ASSERT_EQ ( eleStream . is_open ( ) , true ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames (
mComponent , mQueueLock , mQueueCondition , mWorkQueue , mFlushedIndices ,
mLinearPool , eleStream , & Info , 0 , ( int ) Info . size ( ) , signalEOS ) ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , 0 ,
( int ) Info . size ( ) , signalEOS ) ) ;
// If EOS is not sent, sending empty input with EOS flag
size_t infoSize = Info . size ( ) ;
if ( ! signalEOS ) {
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue , 1 ) ) ;
ASSERT_NO_FATAL_FAILURE (
testInputBuffer ( mComponent , mQueueLock , mWorkQueue ,
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue , 1 ) ) ;
ASSERT_NO_FATAL_FAILURE ( testInputBuffer ( mComponent , mQueueLock , mWorkQueue ,
C2FrameData : : FLAG_END_OF_STREAM , false ) ) ;
infoSize + = 1 ;
}
@ -537,34 +509,26 @@ TEST_P(Codec2VideoDecDecodeTest, DecodeTest) {
// consumed
if ( ! mEos ) {
ALOGV ( " Waiting for input consumption " ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
}
eleStream . close ( ) ;
if ( mFramesReceived ! = infoSize ) {
ALOGE ( " Input buffer count and Output buffer count mismatch " ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived ,
infoSize ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived , infoSize ) ;
ASSERT_TRUE ( false ) ;
}
if ( mTimestampDevTest ) EXPECT_EQ ( mTimestampUslist . empty ( ) , true ) ;
ASSERT_EQ ( mComponent - > stop ( ) , C2_OK ) ;
}
// DecodeTest with StreamIndex and EOS / No EOS
INSTANTIATE_TEST_CASE_P ( StreamIndexAndEOS , Codec2VideoDecDecodeTest ,
: : testing : : Values ( std : : make_pair ( 0 , false ) ,
std : : make_pair ( 0 , true ) ,
std : : make_pair ( 1 , false ) ,
std : : make_pair ( 1 , true ) ) ) ;
// Adaptive Test
TEST_ F ( Codec2VideoDecHidlTest , AdaptiveDecodeTest ) {
TEST_P ( Codec2VideoDecHidlTest , AdaptiveDecodeTest ) {
description ( " Adaptive Decode Test " ) ;
if ( mDisableTest ) return ;
if ( ! ( mCompName = = avc | | mCompName = = hevc | | mCompName = = vp8 | |
mCompName = = vp9 | | mCompName = = mpeg2) )
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
if ( ! ( mCompName = = avc | | mCompName = = hevc | | mCompName = = vp8 | | mCompName = = vp9 | |
mCompName = = mpeg2) )
return ;
typedef std : : unique_lock < std : : mutex > ULock ;
@ -578,8 +542,8 @@ TEST_F(Codec2VideoDecHidlTest, AdaptiveDecodeTest) {
char mURL [ 512 ] , info [ 512 ] ;
std : : ifstream eleStream , eleInfo ;
strcpy ( mURL , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( info , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( mURL , sResourceDir . c_str ( ) ) ;
strcpy ( info , sResourceDir . c_str ( ) ) ;
GetURLForComponent ( mCompName , mURL , info , i % STREAM_COUNT ) ;
eleInfo . open ( info ) ;
@ -594,13 +558,12 @@ TEST_F(Codec2VideoDecHidlTest, AdaptiveDecodeTest) {
eleInfo > > timestamp ;
timestamp + = timestampOffset ;
Info . push_back ( { bytesCount , flags , timestamp } ) ;
bool codecConfig = flags ?
( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
bool codecConfig =
flags ? ( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
{
ULock l ( mQueueLock ) ;
if ( mTimestampDevTest & & ! codecConfig )
mTimestampUslist . push_back ( timestamp ) ;
if ( mTimestampDevTest & & ! codecConfig ) mTimestampUslist . push_back ( timestamp ) ;
}
if ( timestampMax < timestamp ) timestampMax = timestamp ;
}
@ -612,8 +575,7 @@ TEST_F(Codec2VideoDecHidlTest, AdaptiveDecodeTest) {
ALOGV ( " mURL : %s " , mURL ) ;
eleStream . open ( mURL , std : : ifstream : : binary ) ;
ASSERT_EQ ( eleStream . is_open ( ) , true ) ;
ASSERT_NO_FATAL_FAILURE (
decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info ,
offset , ( int ) ( Info . size ( ) - offset ) , false ) ) ;
@ -650,13 +612,11 @@ TEST_F(Codec2VideoDecHidlTest, AdaptiveDecodeTest) {
// blocking call to ensures application to Wait till all the inputs are
// consumed
ALOGV ( " Waiting for input consumption " ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
if ( mFramesReceived ! = ( ( Info . size ( ) ) + 1 ) ) {
ALOGE ( " Input buffer count and Output buffer count mismatch " ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived ,
Info . size ( ) + 1 ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived , Info . size ( ) + 1 ) ;
ASSERT_TRUE ( false ) ;
}
@ -664,15 +624,15 @@ TEST_F(Codec2VideoDecHidlTest, AdaptiveDecodeTest) {
}
// thumbnail test
TEST_ F ( Codec2VideoDecHidlTest , ThumbnailTest ) {
TEST_ P ( Codec2VideoDecHidlTest , ThumbnailTest ) {
description ( " Test Request for thumbnail " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
char mURL [ 512 ] , info [ 512 ] ;
std : : ifstream eleStream , eleInfo ;
strcpy ( mURL , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( info , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( mURL , sResourceDir . c_str ( ) ) ;
strcpy ( info , sResourceDir . c_str ( ) ) ;
GetURLForComponent ( mCompName , mURL , info ) ;
eleInfo . open ( info ) ;
@ -703,11 +663,10 @@ TEST_F(Codec2VideoDecHidlTest, ThumbnailTest) {
} while ( ! ( flags & SYNC_FRAME ) ) ;
eleStream . open ( mURL , std : : ifstream : : binary ) ;
ASSERT_EQ ( eleStream . is_open ( ) , true ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames (
mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , 0 , j + 1 ) ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , 0 ,
j + 1 ) ) ;
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
eleStream . close ( ) ;
EXPECT_GE ( mFramesReceived , 1U ) ;
ASSERT_EQ ( mEos , true ) ;
@ -716,9 +675,9 @@ TEST_F(Codec2VideoDecHidlTest, ThumbnailTest) {
ASSERT_EQ ( mComponent - > release ( ) , C2_OK ) ;
}
TEST_ F ( Codec2VideoDecHidlTest , EOSTest ) {
TEST_ P ( Codec2VideoDecHidlTest , EOSTest ) {
description ( " Test empty input buffer with EOS flag " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
typedef std : : unique_lock < std : : mutex > ULock ;
ASSERT_EQ ( mComponent - > start ( ) , C2_OK ) ;
std : : unique_ptr < C2Work > work ;
@ -756,16 +715,16 @@ TEST_F(Codec2VideoDecHidlTest, EOSTest) {
ASSERT_EQ ( mComponent - > stop ( ) , C2_OK ) ;
}
TEST_ F ( Codec2VideoDecHidlTest , FlushTest ) {
TEST_ P ( Codec2VideoDecHidlTest , FlushTest ) {
description ( " Tests Flush calls " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
typedef std : : unique_lock < std : : mutex > ULock ;
ASSERT_EQ ( mComponent - > start ( ) , C2_OK ) ;
char mURL [ 512 ] , info [ 512 ] ;
std : : ifstream eleStream , eleInfo ;
strcpy ( mURL , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( info , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( mURL , sResourceDir . c_str ( ) ) ;
strcpy ( info , sResourceDir . c_str ( ) ) ;
GetURLForComponent ( mCompName , mURL , info ) ;
eleInfo . open ( info ) ;
@ -790,16 +749,14 @@ TEST_F(Codec2VideoDecHidlTest, FlushTest) {
// frame after this so that the below section can be covered for all
// components
uint32_t numFramesFlushed = 128 ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames (
mComponent , mQueueLock , mQueueCondition , mWorkQueue , mFlushedIndices ,
mLinearPool , eleStream , & Info , 0 , numFramesFlushed , false ) ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , 0 ,
numFramesFlushed , false ) ) ;
// flush
std : : list < std : : unique_ptr < C2Work > > flushedWork ;
c2_status_t err =
mComponent - > flush ( C2Component : : FLUSH_COMPONENT , & flushedWork ) ;
c2_status_t err = mComponent - > flush ( C2Component : : FLUSH_COMPONENT , & flushedWork ) ;
ASSERT_EQ ( err , C2_OK ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ,
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ,
( size_t ) MAX_INPUT_BUFFERS - flushedWork . size ( ) ) ) ;
{
@ -807,11 +764,9 @@ TEST_F(Codec2VideoDecHidlTest, FlushTest) {
ULock l ( mQueueLock ) ;
for ( std : : unique_ptr < C2Work > & work : flushedWork ) {
ASSERT_NE ( work , nullptr ) ;
auto frameIndexIt =
std : : find ( mFlushedIndices . begin ( ) , mFlushedIndices . end ( ) ,
auto frameIndexIt = std : : find ( mFlushedIndices . begin ( ) , mFlushedIndices . end ( ) ,
work - > input . ordinal . frameIndex . peeku ( ) ) ;
if ( ! mFlushedIndices . empty ( ) & &
( frameIndexIt ! = mFlushedIndices . end ( ) ) ) {
if ( ! mFlushedIndices . empty ( ) & & ( frameIndexIt ! = mFlushedIndices . end ( ) ) ) {
mFlushedIndices . erase ( frameIndexIt ) ;
work - > input . buffers . clear ( ) ;
work - > worklets . clear ( ) ;
@ -835,16 +790,14 @@ TEST_F(Codec2VideoDecHidlTest, FlushTest) {
index + + ;
}
if ( keyFrame ) {
ASSERT_NO_FATAL_FAILURE (
decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , index ,
( int ) Info . size ( ) - index ) ) ;
}
eleStream . close ( ) ;
err = mComponent - > flush ( C2Component : : FLUSH_COMPONENT , & flushedWork ) ;
ASSERT_EQ ( err , C2_OK ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ,
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ,
( size_t ) MAX_INPUT_BUFFERS - flushedWork . size ( ) ) ) ;
{
// Update mFlushedIndices based on the index received from flush()
@ -852,10 +805,9 @@ TEST_F(Codec2VideoDecHidlTest, FlushTest) {
for ( std : : unique_ptr < C2Work > & work : flushedWork ) {
ASSERT_NE ( work , nullptr ) ;
uint64_t frameIndex = work - > input . ordinal . frameIndex . peeku ( ) ;
std : : list < uint64_t > : : iterator frameIndexIt = std : : find (
mFlushedIndices . begin ( ) , mFlushedIndices . end ( ) , frameIndex ) ;
if ( ! mFlushedIndices . empty ( ) & &
( frameIndexIt ! = mFlushedIndices . end ( ) ) ) {
std : : list < uint64_t > : : iterator frameIndexIt =
std : : find ( mFlushedIndices . begin ( ) , mFlushedIndices . end ( ) , frameIndex ) ;
if ( ! mFlushedIndices . empty ( ) & & ( frameIndexIt ! = mFlushedIndices . end ( ) ) ) {
mFlushedIndices . erase ( frameIndexIt ) ;
work - > input . buffers . clear ( ) ;
work - > worklets . clear ( ) ;
@ -867,15 +819,15 @@ TEST_F(Codec2VideoDecHidlTest, FlushTest) {
ASSERT_EQ ( mComponent - > stop ( ) , C2_OK ) ;
}
TEST_ F ( Codec2VideoDecHidlTest , DecodeTestEmptyBuffersInserted ) {
TEST_ P ( Codec2VideoDecHidlTest , DecodeTestEmptyBuffersInserted ) {
description ( " Decode with multiple empty input frames " ) ;
if ( mDisableTest ) return ;
if ( mDisableTest ) GTEST_SKIP ( ) < < " Test is disabled " ;
char mURL [ 512 ] , info [ 512 ] ;
std : : ifstream eleStream , eleInfo ;
strcpy ( mURL , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( info , gEnv- > getRes ( ) . c_str ( ) ) ;
strcpy ( mURL , sResourceDir . c_str ( ) ) ;
strcpy ( info , sResourceDir . c_str ( ) ) ;
GetURLForComponent ( mCompName , mURL , info ) ;
eleInfo . open ( info ) ;
@ -890,15 +842,16 @@ TEST_F(Codec2VideoDecHidlTest, DecodeTestEmptyBuffersInserted) {
// and empty input frames at an interval of 5 frames.
while ( 1 ) {
if ( ! ( frameId % 5 ) ) {
if ( ! ( frameId % 20 ) ) flags = 32 ;
else flags = 0 ;
if ( ! ( frameId % 20 ) )
flags = 32 ;
else
flags = 0 ;
bytesCount = 0 ;
} else {
if ( ! ( eleInfo > > bytesCount ) ) break ;
eleInfo > > flags ;
eleInfo > > timestamp ;
codecConfig = flags ?
( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
codecConfig = flags ? ( ( 1 < < ( flags - 1 ) ) & C2FrameData : : FLAG_CODEC_CONFIG ) ! = 0 : 0 ;
}
Info . push_back ( { bytesCount , flags , timestamp } ) ;
frameId + + ;
@ -909,39 +862,58 @@ TEST_F(Codec2VideoDecHidlTest, DecodeTestEmptyBuffersInserted) {
ALOGV ( " mURL : %s " , mURL ) ;
eleStream . open ( mURL , std : : ifstream : : binary ) ;
ASSERT_EQ ( eleStream . is_open ( ) , true ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames (
mComponent , mQueueLock , mQueueCondition , mWorkQueue , mFlushedIndices ,
mLinearPool , eleStream , & Info , 0 , ( int ) Info . size ( ) ) ) ;
ASSERT_NO_FATAL_FAILURE ( decodeNFrames ( mComponent , mQueueLock , mQueueCondition , mWorkQueue ,
mFlushedIndices , mLinearPool , eleStream , & Info , 0 ,
( int ) Info . size ( ) ) ) ;
// blocking call to ensures application to Wait till all the inputs are
// consumed
if ( ! mEos ) {
ALOGV ( " Waiting for input consumption " ) ;
ASSERT_NO_FATAL_FAILURE (
waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
ASSERT_NO_FATAL_FAILURE ( waitOnInputConsumption ( mQueueLock , mQueueCondition , mWorkQueue ) ) ;
}
eleStream . close ( ) ;
if ( mFramesReceived ! = Info . size ( ) ) {
ALOGE ( " Input buffer count and Output buffer count mismatch " ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived ,
Info . size ( ) ) ;
ALOGV ( " framesReceived : %d inputFrames : %zu " , mFramesReceived , Info . size ( ) ) ;
ASSERT_TRUE ( false ) ;
}
}
INSTANTIATE_TEST_SUITE_P ( PerInstance , Codec2VideoDecHidlTest , testing : : ValuesIn ( kTestParameters ) ,
android : : hardware : : PrintInstanceTupleNameToString < > ) ;
// DecodeTest with StreamIndex and EOS / No EOS
INSTANTIATE_TEST_SUITE_P ( StreamIndexAndEOS , Codec2VideoDecDecodeTest ,
testing : : ValuesIn ( kDecodeTestParameters ) ,
android : : hardware : : PrintInstanceTupleNameToString < > ) ;
} // anonymous namespace
// TODO : Video specific configuration Test
int main ( int argc , char * * argv ) {
gEnv = new ComponentTestEnvironment ( ) ;
: : testing : : AddGlobalTestEnvironment ( gEnv ) ;
: : testing : : InitGoogleTest ( & argc , argv ) ;
gEnv - > init ( & argc , argv ) ;
int status = gEnv - > initFromOptions ( argc , argv ) ;
if ( status = = 0 ) {
int status = RUN_ALL_TESTS ( ) ;
LOG ( INFO ) < < " C2 Test result = " < < status ;
kTestParameters = getTestParameters ( C2Component : : DOMAIN_VIDEO , C2Component : : KIND_DECODER ) ;
for ( auto params : kTestParameters ) {
kDecodeTestParameters . push_back (
std : : make_tuple ( std : : get < 0 > ( params ) , std : : get < 1 > ( params ) , " 0 " , " false " ) ) ;
kDecodeTestParameters . push_back (
std : : make_tuple ( std : : get < 0 > ( params ) , std : : get < 1 > ( params ) , " 0 " , " true " ) ) ;
kDecodeTestParameters . push_back (
std : : make_tuple ( std : : get < 0 > ( params ) , std : : get < 1 > ( params ) , " 1 " , " false " ) ) ;
kDecodeTestParameters . push_back (
std : : make_tuple ( std : : get < 0 > ( params ) , std : : get < 1 > ( params ) , " 1 " , " true " ) ) ;
}
// Set the resource directory based on command line args.
// Test will fail to set up if the argument is not set.
for ( int i = 1 ; i < argc ; i + + ) {
if ( strcmp ( argv [ i ] , " -P " ) = = 0 & & i < argc - 1 ) {
sResourceDir = argv [ i + 1 ] ;
break ;
}
return status ;
}
: : testing : : InitGoogleTest ( & argc , argv ) ;
return RUN_ALL_TESTS ( ) ;
}