3 #if IV_ENABLE_ANDROID_JNI
7 #include <android/asset_manager.h>
8 #include <android/asset_manager_jni.h>
17 class AndroidAsset_streambuf :
public std::streambuf
20 static constexpr
int const BufferCapacity = 128;
22 AndroidAsset_streambuf( AAsset * asset, ClientMarker
const * cm ) :
31 ~AndroidAsset_streambuf()
35 virtual int underflow()
override
38 int received = AAsset_read( this->asset, this->buffer.data(), AndroidAsset_streambuf::BufferCapacity );
42 this->cm->warning(
SRC_INFO,
"Failed to read android asset data (errcode ", received,
")." );
45 return traits_type::eof();
48 setg( this->buffer.data(), this->buffer.data(), this->buffer.data() + received );
51 return traits_type::to_int_type( *gptr() );
55 ClientMarker
const * cm;
58 std::array< char, AndroidAsset_streambuf::BufferCapacity > buffer;
63 class AndroidAsset_istream :
public std::istream
66 AndroidAsset_istream( AAsset * asset, ClientMarker
const * cm ) :
67 std::istream( new AndroidAsset_streambuf( asset, cm ) )
71 ~AndroidAsset_istream()
77 static AAssetManager * l_GetAndroidAssetManager()
79 return glfmAndroidGetActivity()->assetManager;
83 StreamResourceProvider( inst, priority ),
84 cm( inst, this,
"AndroidAssetResourceProvider" ),
92 LambdaLogTrace _log_trace(
93 [&]( std::ostream & out )
95 out <<
"Android asset '" << this->toFsPath( path ) <<
"':" << std::endl;
101 std::string rpath = path.string();
102 if( rpath.size() > 0 )
106 AAsset * asset = AAssetManager_open( l_GetAndroidAssetManager(), rpath.c_str(), AASSET_MODE_STREAMING );
114 AndroidAsset_istream in( asset, &this->
cm );
118 AAsset_close( asset );
123 this->
with_stream( ResourcePath(
"/metadata.json" ), f );
160 std::string AndroidAssetResourceProvider::toFsPath( ResourcePath path )
const
162 return path.to_real_path( this->root.c_str() );