i am trying to implent test ads on my Flutter app. So far, what i notice is that 3 out of 4 times my test ad rewarded video are showing, but sometimes they are not. This is what i am getting when the video is not loading. Since the other times the video laods, i don't think that is a setup problem, but i am attaching my code.
This is the error: (Real device, Samsung Galaxy S10)
I/DynamiteModule( 9385): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:221908400
I/DynamiteModule( 9385): Selected remote version of com.google.android.gms.ads.dynamite, version >= 221908400
V/DynamiteModule( 9385): Dynamite loader version >= 2, using loadModule2NoCrashUtils
I/Ads ( 9385): Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("57D8CCEE680443B3894B93AB5E6F61C8")) to get test ads on this device.
W/Ads ( 9385): Not retrying to fetch app settings
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 0
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 1
I/ExoPlayerImpl( 9385): Init ExoPlayerLib/2.4.2 [beyond1, SM-G973F, samsung, 31]
D/MetadataUtil( 9385): Skipped unknown metadata entry: gsst
D/MetadataUtil( 9385): Skipped unknown metadata entry: gstd
I/CCodec ( 9385): state->set(ALLOCATING)
I/CCodec ( 9385): allocate(c2.android.aac.decoder)
I/CCodec ( 9385): setting up 'default' as default (vendor) store
I/CCodec ( 9385): Created component [c2.android.aac.decoder]
I/CCodec ( 9385): state->set(ALLOCATED)
D/CCodecConfig( 9385): read media type: audio/mp4a-latm
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: algo.buffers.max-count.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: output.subscribed-indices.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: input.buffers.allocator-ids.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: output.buffers.allocator-ids.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: algo.buffers.allocator-ids.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: output.buffers.pool-ids.values
D/ReflectedParamUpdater( 9385): extent() != 1 for single value type: algo.buffers.pool-ids.values
I/CCodecConfig( 9385): query failed after returning 19 values (BAD_INDEX)
D/CCodecConfig( 9385): c2 config diff is Dict {
D/CCodecConfig( 9385): c2::u32 coded.aac-packaging.value = 0
D/CCodecConfig( 9385): c2::u32 coded.bitrate.value = 64000
D/CCodecConfig( 9385): c2::u32 coded.pl.level = 0
D/CCodecConfig( 9385): c2::u32 coded.pl.profile = 8192
D/CCodecConfig( 9385): c2::i32 coding.drc.album-mode.value = 0
D/CCodecConfig( 9385): c2::float coding.drc.attenuation-factor.value = 1
D/CCodecConfig( 9385): c2::float coding.drc.boost-factor.value = 1
D/CCodecConfig( 9385): c2::i32 coding.drc.compression-mode.value = 3
D/CCodecConfig( 9385): c2::i32 coding.drc.effect-type.value = 3
D/CCodecConfig( 9385): c2::float coding.drc.encoded-level.value = 0.25
D/CCodecConfig( 9385): c2::float coding.drc.reference-level.value = -16
D/CCodecConfig( 9385): c2::u32 input.buffers.max-size.value = 8192
D/CCodecConfig( 9385): c2::u32 input.delay.value = 0
D/CCodecConfig( 9385): string input.media-type.value = "audio/mp4a-latm"
D/CCodecConfig( 9385): c2::u32 output.delay.value = 2
D/CCodecConfig( 9385): c2::float output.drc.output-loudness.value = 0.25
D/CCodecConfig( 9385): string output.media-type.value = "audio/raw"
D/CCodecConfig( 9385): c2::u32 raw.channel-count.value = 1
D/CCodecConfig( 9385): c2::u32 raw.max-channel-count.value = 8
D/CCodecConfig( 9385): c2::u32 raw.sample-rate.value = 44100
D/CCodecConfig( 9385): }
D/CCodec ( 9385): [c2.android.aac.decoder] buffers are bound to CCodec for this session
I/CCodec ( 9385): appPid(9385) width(0) height(0)
D/CCodecConfig( 9385): no c2 equivalents for language
D/CCodecConfig( 9385): no c2 equivalents for flags
D/CCodecConfig( 9385): config failed => CORRUPTED
D/CCodecConfig( 9385): c2 config diff is c2::u32 raw.channel-count.value = 2
W/Codec2Client( 9385): query -- param skipped: index = 1107298332.
D/CCodec ( 9385): client requested max input size 540, which is smaller than what component recommended (8192); overriding with component recommendation.
W/CCodec ( 9385): This behavior is subject to change. It is recommended that app developers double check whether the requested max input size is in reasonable range.
D/CCodec ( 9385): setup formats input: AMessage(what = 0x00000000) = {
D/CCodec ( 9385): int32_t aac-drc-album-mode = 0
D/CCodec ( 9385): int32_t aac-drc-boost-level = 127
D/CCodec ( 9385): int32_t aac-drc-cut-level = 127
D/CCodec ( 9385): int32_t aac-drc-effect-type = 3
D/CCodec ( 9385): int32_t aac-encoded-target-level = -1
D/CCodec ( 9385): int32_t aac-max-output-channel_count = 8
D/CCodec ( 9385): int32_t aac-target-ref-level = 64
D/CCodec ( 9385): int32_t bitrate = 64000
D/CCodec ( 9385): int32_t channel-count = 2
D/CCodec ( 9385): int32_t level = 0
D/CCodec ( 9385): int32_t max-input-size = 8192
D/CCodec ( 9385): string mime = "audio/mp4a-latm"
D/CCodec ( 9385): int32_t profile = 2
D/CCodec ( 9385): int32_t sample-rate = 44100
D/CCodec ( 9385): int64_t durationUs = 0
D/CCodec ( 9385): }
D/CCodec ( 9385): setup formats output: AMessage(what = 0x00000000) = {
D/CCodec ( 9385): int32_t aac-drc-album-mode = 0
D/CCodec ( 9385): int32_t aac-drc-boost-level = 127
D/CCodec ( 9385): int32_t aac-drc-cut-level = 127
D/CCodec ( 9385): int32_t aac-drc-effect-type = 3
D/CCodec ( 9385): int32_t aac-drc-output-loudness = -1
D/CCodec ( 9385): int32_t aac-encoded-target-level = -1
D/CCodec ( 9385): int32_t aac-max-output-channel_count = 8
D/CCodec ( 9385): int32_t aac-target-ref-level = 64
D/CCodec ( 9385): int32_t channel-count = 2
D/CCodec ( 9385): string mime = "audio/raw"
D/CCodec ( 9385): int32_t sample-rate = 44100
D/CCodec ( 9385): }
I/CCodecConfig( 9385): query failed after returning 19 values (BAD_INDEX)
I/CCodec ( 9385): state->set(STARTING)
W/Codec2Client( 9385): query -- param skipped: index = 1342179345.
W/Codec2Client( 9385): query -- param skipped: index = 2415921170.
W/Codec2Client( 9385): query -- param skipped: index = 1610614798.
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] Created input block pool with allocatorID 16 => poolID 48 - OK (0)
I/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] Created output block pool with allocatorID 16 => poolID 277 - OK
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] Configured output block pool ids 277 => OK
I/CCodec ( 9385): state->set(RUNNING)
I/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] 4 initial input buffers available
I/ACodec ( 9385): [] Now uninitialized
I/ACodec ( 9385): [] onAllocateComponent
I/OMXClient( 9385): IOmx service obtained
E/ACodec ( 9385): Unable to instantiate codec 'OMX.Exynos.avc.dec' with err 0xfffffff4.
E/ACodec ( 9385): signalError(omxError 0xfffffff4, internalError -12)
E/MediaCodec( 9385): Codec reported err 0xfffffff4, actionCode 0, while in state 1/INITIALIZING
W/MediaCodec-JNI( 9385): try to release MediaCodec from JMediaCodec::~JMediaCodec()...
W/MediaCodec-JNI( 9385): done releasing MediaCodec from JMediaCodec::~JMediaCodec().
E/ExoPlayerImplInternal( 9385): Renderer error.
E/ExoPlayerImplInternal( 9385): com.google.android.gms.ads.exoplayer3.c
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:20)
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.G(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:4)
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.video.h.G(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:1)
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.z(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:3)
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.n.handleMessage(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:42)
E/ExoPlayerImplInternal( 9385): at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal( 9385): at android.os.Looper.loopOnce(Looper.java:226)
E/ExoPlayerImplInternal( 9385): at android.os.Looper.loop(Looper.java:313)
E/ExoPlayerImplInternal( 9385): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 9385): Caused by: com.google.android.gms.ads.exoplayer3.mediacodec.b: Decoder init failed: OMX.Exynos.avc.dec, Format(1, null, video/avc, -1, null, [1280, 720, -1.0], [-1, -1])
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:19)
E/ExoPlayerImplInternal( 9385): ... 8 more
E/ExoPlayerImplInternal( 9385): Caused by: android.media.MediaCodec$CodecException: Failed to initialize OMX.Exynos.avc.dec, error 0xfffffff4
E/ExoPlayerImplInternal( 9385): at android.media.MediaCodec.native_setup(Native Method)
E/ExoPlayerImplInternal( 9385): at android.media.MediaCodec.<init>(MediaCodec.java:1961)
E/ExoPlayerImplInternal( 9385): at android.media.MediaCodec.createByCodecName(MediaCodec.java:1938)
E/ExoPlayerImplInternal( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:9)
E/ExoPlayerImplInternal( 9385): ... 8 more
I/CCodec ( 9385): state->set(STOPPING)
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
W/Ads ( 9385): Precache error
W/Ads ( 9385): com.google.android.gms.ads.exoplayer3.c
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:20)
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.G(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:4)
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.video.h.G(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:1)
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.z(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:3)
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.n.handleMessage(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:42)
W/Ads ( 9385): at android.os.Handler.dispatchMessage(Handler.java:102)
W/Ads ( 9385): at android.os.Looper.loopOnce(Looper.java:226)
W/Ads ( 9385): at android.os.Looper.loop(Looper.java:313)
W/Ads ( 9385): at android.os.HandlerThread.run(HandlerThread.java:67)
W/Ads ( 9385): Caused by: com.google.android.gms.ads.exoplayer3.mediacodec.b: Decoder init failed: OMX.Exynos.avc.dec, Format(1, null, video/avc, -1, null, [1280, 720, -1.0], [-1, -1])
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:19)
W/Ads ( 9385): ... 8 more
W/Ads ( 9385): Caused by: android.media.MediaCodec$CodecException: Failed to initialize OMX.Exynos.avc.dec, error 0xfffffff4
W/Ads ( 9385): at android.media.MediaCodec.native_setup(Native Method)
W/Ads ( 9385): at android.media.MediaCodec.<init>(MediaCodec.java:1961)
W/Ads ( 9385): at android.media.MediaCodec.createByCodecName(MediaCodec.java:1938)
W/Ads ( 9385): at com.google.android.gms.ads.exoplayer3.mediacodec.c.N(:com.google.android.gms.policy_ads_fdr_dynamite#221908400#221908400057.447330857.447330857:9)
W/Ads ( 9385): ... 8 more
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
D/CCodecBufferChannel( 9385): [c2.android.aac.decoder#324] MediaCodec discarded an unknown buffer
I/CCodec ( 9385): state->set(ALLOCATED)
I/CCodec ( 9385): state->set(RELEASING)
I/CCodec ( 9385): [c2.android.aac.decoder] release(1)
I/CCodec ( 9385): state->set(RELEASED)
I/hw-BpHwBinder( 9385): onLastStrongRef automatically unlinking death recipients
I/MediaCodec( 9385): Codec shutdown complete
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 0
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 1
D/BufferPoolAccessor2.0( 9385): bufferpool2 0x777c2d7a08 : 0(0 size) total buffers - 0(0 size) used buffers - 1/6 (recycle/alloc) - 5/8 (fetch/transfer)
D/BufferPoolAccessor2.0( 9385): evictor expired: 1, evicted: 1
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 0
I/ViewRootImpl#563214[MainActivity]( 9385): ViewPostIme pointer 1
D/BufferPoolAccessor2.0( 9385): evictor expired: 1, evicted: 0
D/BufferPoolAccessor2.0( 9385): bufferpool2 0x777c3571a8 : 0(0 size) total buffers - 0(0 size) used buffers - 1/6 (recycle/alloc) - 5/8 (fetch/transfer)
D/BufferPoolAccessor2.0( 9385): evictor expired: 1, evicted: 1
I/pestini.essenc( 9385): Background concurrent copying GC freed 573699(23MB) AllocSpace objects, 4(80KB) LOS objects, 43% free, 30MB/54MB, paused 232us,136us total 120.237ms
I/Ads ( 9385): Ad failed to load : 0
I/flutter ( 9385): Failed to load a rewarded ad: Internal error.
W/Ads ( 9385): Failed to preload url gcache://video/media/8744318498482049952?url=https%3A%2F%2Frr1---sn-uxaxpu5ap5-apol.googlevideo.com%2Fvideoplayback%3Fexpire%3D1661099020%26ei%3DjOsBY_yGIor_gAehs6ow%26ip%3D79.21.162.29%26id%3D795a0f5850e653a0%26itag%3D22%26source%3Dyoutube%26requiressl%3Dyes%26mh%3DLS%26mm%3D31%26mn%3Dsn-uxaxpu5ap5-apol%26ms%3Dau%26mv%3Dm%26mvi%3D1%26pl%3D24%26susc%3Dgvp%26acao%3Dyes%26ctier%3DL%26mime%3Dvideo%252Fmp4%26vprv%3D1%26dur%3D5.038%26lmt%3D1606000670604054%26mt%3D1661069832%26txp%3D1211222%26sparams%3Dexpire%252Cei%252Cip%252Cid%252Citag%252Csource%252Crequiressl%252Csusc%252Cacao%252Cctier%252Cmime%252Cvprv%252Cdur%252Clmt%26sig%3DAOq0QJ8wRQIgGnvHqkqA7FF7lDY492LRjEjdWvBXmcPJ7xXW7TyqniICIQDPrVizMFRdNZ_sfM9-LixHUPOCGqZuFQiFX131KzmH4w%253D%253D%26lsparams%3Dmh%252Cmm%252Cmn%252Cms%252Cmv%252Cmvi%252Cpl%26lsig%3DAG3C_xAwRQIgVaTrgTmchNN6aeKKZ3jqu_Jn8ufCI8Rc0FS9eq4kMLMCIQDRyVb6NYdv4le9BEjPs4N8loanOFOPpM27bOZ22ZM2gQ%253D%253D%26cpn%3DnVl-a3BtlRhfCqIr%26ic%3Dgmasdk&tag.duration=5038&tag.check_url=https%3A%2F%2Frr1---sn-uxaxpu5ap5-apol.googlevideo.com%2Fvideoplayback%3Fexpire%3D1661099020%26ei%3DjOsBY_yGIor_gAehs6ow%26ip%3D79.21.162.29%26id%3D795a0f5850e653a0%26itag%3D22%26source%3Dyoutube%26requiressl%3Dyes%26mh%3DLS%26mm%3D31%26mn%3Dsn-uxaxpu5ap5-apol%26ms%3Dau%26mv%3Dm%26mvi%3D1%26pl%3D24%26susc%3Dgvp%26acao%3Dyes%26ctier%3DL%26mime%3Dvideo%2Fmp4%26vprv%3D1%26dur%3D5.038%26lmt%3D1606000670604054%26mt%3D1661069832%26txp%3D1211222%26sparams%3Dexpire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Csusc%2Cacao%2Cctier%2Cmime%2Cvprv%2Cdur%2Clmt%26sig%3DAOq0QJ8wRQIgGnvHqkqA7FF7lDY492LRjEjdWvBXmcPJ7xXW7TyqniICIQDPrVizMFRdNZ_sfM9-LixHUPOCGqZuFQiFX131KzmH4w%3D%3D%26lsparams%3Dmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%26lsig%3DAG3C_xAwRQIgVaTrgTmchNN6aeKKZ3jqu_Jn8ufCI8Rc0FS9eq4kMLMCIQDRyVb6NYdv4le9BEjPs4N8loanOFOPpM27bOZ22ZM2gQ%3D%3D%26cpn%3DnVl-a3BtlRhfCqIr Exception: ExoPlayer was released during preloading.
W/Ads ( 9385): #004 The webview is destroyed. Ignoring action.
W/Ads ( 9385): Failed to preload url gcache://video/media/-438303185308675417?url=https%3A%2F%2Frr2---sn-uxaxpu5ap5-apol.googlevideo.com%2Fvideoplayback%3Fexpire%3D1661098796%26ei%3DrOoBY-STOoXix_APlPi-sAI%26ip%3D79.21.162.29%26id%3Df9ead5933fc112a7%26itag%3D22%26source%3Dyoutube%26requiressl%3Dyes%26mh%3DEA%26mm%3D31%26mn%3Dsn-uxaxpu5ap5-apol%26ms%3Dau%26mv%3Dm%26mvi%3D2%26pcm2cms%3Dyes%26pl%3D24%26susc%3Dgvp%26acao%3Dyes%26ctier%3DL%26mime%3Dvideo%252Fmp4%26vprv%3D1%26dur%3D7.267%26lmt%3D1609247274254961%26mt%3D1661069127%26txp%3D1211222%26sparams%3Dexpire%252Cei%252Cip%252Cid%252Citag%252Csource%252Crequiressl%252Csusc%252Cacao%252Cctier%252Cmime%252Cvprv%252Cdur%252Clmt%26sig%3DAOq0QJ8wRQIhAKtTUzu10duuyNKA-tGUC1RWgchGK_uGHSDZdrav3sdGAiBCwnEMg6POUb_KHgvB6F8pf_4KmvyXoLJhS3_q8b-Iug%253D%253D%26lsparams%3Dmh%252Cmm%252Cmn%252Cms%252Cmv%252Cmvi%252Cpcm2cms%252Cpl%26lsig%3DAG3C_xAwRAIgTTAj7kuZyg1hKG_X6a9PcblwqoCCmRioT58RU7RQGccCIB7KyWOT9_iD5cpwMF9gEGrUgKNYFgees0Wxq_VTQeca%26cpn%3DKwm_j2j_MqowGqx3%26ic%3Dgmasdk&tag.duration=7267&tag.check_url=https%3A%2F%2Frr2---sn-uxaxpu5ap5-apol.googlevideo.com%2Fvideoplayback%3Fexpire%3D1661098796%26ei%3DrOoBY-STOoXix_APlPi-sAI%26ip%3D79.21.162.29%26id%3Df9ead5933fc112a7%26itag%3D22%26source%3Dyoutube%26requiressl%3Dyes%26mh%3DEA%26mm%3D31%26mn%3Dsn-uxaxpu5ap5-apol%26ms%3Dau%26mv%3Dm%26mvi%3D2%26pcm2cms%3Dyes%26pl%3D24%26susc%3Dgvp%26acao%3Dyes%26ctier%3DL%26mime%3Dvideo%2Fmp4%26vprv%3D1%26dur%3D7.267%26lmt%3D1609247274254961%26mt%3D1661069127%26txp%3D1211222%26sparams%3Dexpire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Csusc%2Cacao%2Cctier%2Cmime%2Cvprv%2Cdur%2Clmt%26sig%3DAOq0QJ8wRQIhAKtTUzu10duuyNKA-tGUC1RWgchGK_uGHSDZdrav3sdGAiBCwnEMg6POUb_KHgvB6F8pf_4KmvyXoLJhS3_q8b-Iug%3D%3D%26lsparams%3Dmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%26lsig%3DAG3C_xAwRAIgTTAj7kuZyg1hKG_X6a9PcblwqoCCmRioT58RU7RQGccCIB7KyWOT9_iD5cpwMF9gEGrUgKNYFgees0Wxq_VTQeca%26cpn%3DKwm_j2j_MqowGqx3 Exception: Timeout reached. Limit: 300000 ms
This is how i implemented rewared video test ads.
bool _isRewardedAdReady = false;
RewardedAd? _rewardedAd;
void _loadRewardedAd() {
RewardedAd.load(
adUnitId: AdHelper.rewardedAdUnitId,
request: AdRequest(),
rewardedAdLoadCallback: RewardedAdLoadCallback(
onAdLoaded: (ad) {
_rewardedAd = ad;
ad.fullScreenContentCallback = FullScreenContentCallback(
onAdDismissedFullScreenContent: (ad) {
setState(() {
_isRewardedAdReady = false;
});
_loadRewardedAd();
},
);
setState(() {
_isRewardedAdReady = true;
});
},
onAdFailedToLoad: (err) {
print('Failed to load a rewarded ad: ${err.message}');
setState(() {
_isRewardedAdReady = false;
});
},
),
);
}
#override
void initState() {
super.initState();
_loadRewardedAd();
}
#override
void dispose() {
_rewardedAd?.dispose();
super.dispose();
}
On the widget, i want to use to display the ad, i have this code
if (isRewardedAdReady) {
rewardedAd?.show(onUserEarnedReward:
(AdWithoutView ad, RewardItem reward) {
print(
'$ad with reward $RewardItem(${reward.amount}, ${reward.type}');
});
}
The implementation looks correct. You can may be check if the rewarded video is loaded or not before you load a new one..
if(isRewardedAdReady == false)
{
load a new ad here;
}
Also When you open the screen on which you wish to show the ad first load the ad and keep it ready. Then when you wish to display it check if its ready and display it. That gives you some time to load the ad. In the current implementation I see that you are setting state of isRewardedAdReady and that will trigger showing the ad immediately the ad is ready(unless they are implemented differently, sorry if I am wrong). Also please check the variables _isRewardedAdReady and isRewardedAdReady are they same or different (notice you missed the underscore). Since you mentioned that it is displaying ads properly you may also try on other devices or simulator too.
Related
I am trying to create a dog photo/video generator app using Flutter and Dart. It basically sends a get request to a website called random.Dog to get a url to show on my app. Sometimes the url is a video and sometimes it is a img. When it is a video my app just buffers and this console message keeps on coming:
E/flutter ( 4345): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception:
MissingPluginException(No implementation found for method init on channel better_player_channel)
E/flutter ( 4345): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter ( 4345): <asynchronous suspension>
E/flutter ( 4345):
E/flutter ( 4345): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method create on channel better_player_channel)
E/flutter ( 4345): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter ( 4345): <asynchronous suspension>
E/flutter ( 4345): #1 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:358:43)
E/flutter ( 4345): <asynchronous suspension>
E/flutter ( 4345): #2 MethodChannelVideoPlayer.create (package:better_player/src/video_player/method_channel_video_player.dart:38:9)
E/flutter ( 4345): <asynchronous suspension>
E/flutter ( 4345): #3 VideoPlayerController._create (package:better_player/src/video_player/video_player.dart:202:18)
E/flutter ( 4345): <asynchronous suspension>
E/flutter ( 4345):
I/flutter ( 4345): {"fileSizeBytes":3294982,"url":"https://random.dog/a922da9a-437c-4400-9d94-f36ec2e5452c.mp4"}
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
D/BufferPoolAccessor2.0( 4345): bufferpool2 0xeac5e4a8 : 5(40960 size) total buffers - 5(40960 size) used buffers - 1/7 (recycle/alloc) - 6/45600 (fetch/transfer)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
I/CCodecConfig( 4345): query failed after returning 19 values (BAD_INDEX)
D/CCodecConfig( 4345): c2 config diff is c2::i32 coding.drc.compression-mode.value = 3
W/Codec2Client( 4345): query -- param skipped: index = 1342179345.
W/Codec2Client( 4345): query -- param skipped: index = 2415921170.
W/Codec2Client( 4345): query -- param skipped: index = 1610614798.
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:Output[N]] popFromStashAndRegister: output format changed to AMessage(what = 0x00000000) = {
D/CCodecBuffers( 4345): int32_t aac-drc-album-mode = 0
D/CCodecBuffers( 4345): int32_t aac-drc-boost-level = 127
D/CCodecBuffers( 4345): int32_t aac-drc-cut-level = 127
D/CCodecBuffers( 4345): int32_t aac-drc-effect-type = 3
D/CCodecBuffers( 4345): int32_t aac-drc-heavy-compression = 3
D/CCodecBuffers( 4345): int32_t aac-drc-output-loudness = -1
D/CCodecBuffers( 4345): int32_t aac-encoded-target-level = -1
D/CCodecBuffers( 4345): int32_t aac-max-output-channel_count = 8
D/CCodecBuffers( 4345): int32_t aac-target-ref-level = 64
D/CCodecBuffers( 4345): int32_t channel-count = 1
D/CCodecBuffers( 4345): string mime = "audio/raw"
D/CCodecBuffers( 4345): int32_t sample-rate = 44100
D/CCodecBuffers( 4345): }
D/CCodecConfig( 4345): c2 config diff is c2::i32 coding.drc.compression-mode.value = 1
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:Output[N]] popFromStashAndRegister: output format changed to AMessage(what = 0x00000000) = {
D/CCodecBuffers( 4345): int32_t aac-drc-album-mode = 0
D/CCodecBuffers( 4345): int32_t aac-drc-boost-level = 127
D/CCodecBuffers( 4345): int32_t aac-drc-cut-level = 127
D/CCodecBuffers( 4345): int32_t aac-drc-effect-type = 3
D/CCodecBuffers( 4345): int32_t aac-drc-heavy-compression = 1
D/CCodecBuffers( 4345): int32_t aac-drc-output-loudness = -1
D/CCodecBuffers( 4345): int32_t aac-encoded-target-level = -1
D/CCodecBuffers( 4345): int32_t aac-max-output-channel_count = 8
D/CCodecBuffers( 4345): int32_t aac-target-ref-level = 64
D/CCodecBuffers( 4345): int32_t channel-count = 1
D/CCodecBuffers( 4345): string mime = "audio/raw"
D/CCodecBuffers( 4345): int32_t sample-rate = 44100
D/CCodecBuffers( 4345): }
D/BufferPoolAccessor2.0( 4345): bufferpool2 0xeac5e4a8 : 5(40960 size) total buffers - 5(40960 size) used buffers - 1/7 (recycle/alloc) - 6/45824 (fetch/transfer)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 1)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
I/chatty ( 4345): uid=10154(com.example.randomdog) HwBinder:4345_1 identical 4 lines
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
D/BufferPoolAccessor2.0( 4345): bufferpool2 0xeac5e4a8 : 5(40960 size) total buffers - 5(40960 size) used buffers - 1/7 (recycle/alloc) - 6/46039 (fetch/transfer)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 3)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 4)
D/BufferPoolAccessor2.0( 4345): bufferpool2 0xeac5e4a8 : 5(40960 size) total buffers - 5(40960 size) used buffers - 1/7 (recycle/alloc) - 6/46268 (fetch/transfer)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 2)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 1)
D/BufferPoolAccessor2.0( 4345): bufferpool2 0xeac5e4a8 : 5(40960 size) total buffers - 5(40960 size) used buffers - 1/7 (recycle/alloc) - 6/46498 (fetch/transfer)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 3)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 4)
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:1D-Input.Impl[N]] codec released a buffer owned by client (index 0)
I/CCodecConfig( 4345): query failed after returning 19 values (BAD_INDEX)
D/CCodecConfig( 4345): c2 config diff is c2::i32 coding.drc.compression-mode.value = 3
W/Codec2Client( 4345): query -- param skipped: index = 1342179345.
W/Codec2Client( 4345): query -- param skipped: index = 2415921170.
W/Codec2Client( 4345): query -- param skipped: index = 1610614798.
D/CCodecBuffers( 4345): [c2.android.aac.decoder#768:Output[N]] popFromStashAndRegister: output format changed to AMessage(what = 0x00000000) = {
And my video doenst show up on my emulator. What seems to be the problem and how do I fix it? My minimal code:
import 'package:better_player/better_player.dart';
void main() => runApp(MaterialApp(home: RandomDog()));
class RandomDog extends StatefulWidget {
#override
_RandomDogState createState() => _RandomDogState();
}
class _RandomDogState extends State<RandomDog> {
var headers = {'Content-Type': 'application/json'};
var body = {};
var video = false;
var img = false;
var message;
var loading = true;
var _controller;
#override
void initState() {
getDog();
super.initState();
}
getDog() async {
loading=true;
var response = await http.get(Uri.https('random.dog', '/woof.json'));
print(response.body);
message = jsonDecode(response.body);
if (message['url'].contains('gif') || message['url'].contains('png') ||
message['url'].contains('jpg') || message['url'].contains('jpeg')) {
video = false;
img = true;
} else {
video = true;
img = false;
}
loading = false;
setState(() {
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
. . .
body: Center(
child: loading == true ? CircularProgressIndicator() : Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Visibility(visible: img,
child: Image.network(message['url'], fit: BoxFit.scaleDown,)),
// Visibility(visible: video,child: VideoApp(url:message['url'])),
video == true? CircularProgressIndicator() :
Visibility(visible: video, child: BetterPlayer.network(message['url'],betterPlayerConfiguration: BetterPlayerConfiguration(autoPlay: true),)), //Chewie(controller: _controller,)
OutlinedButton(onPressed: () async {
getDog();
}, child: Text('GENERATE')),
],
),
),
);
}
}
Hope this solution work for you, Try to initialize your betterPlayer in your function getDog() by using :
BetterPlayerController _betterPlayerController; //declare first
BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"message[url]");
_betterPlayerController = BetterPlayerController(
BetterPlayerConfiguration(),
betterPlayerDataSource: betterPlayerDataSource);
after that in your widget after CircularProgressIndicator you add this :
BetterPlayer(
controller: _betterPlayerController, ),
I'm using Firebase Authentication in my app and I have the following code to allow the user to sign out:
FirebaseAuth.getInstance().signOut()
userInfo.removeEventListener(listener)
val intent = Intent(this#SettingsFragment.context, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
The code successfully logs out the user, but I get this toast that says The client does not have permission to perform this operation. Why am I getting this toast? How do I prevent it from occurring?
UPDATE 1: Firebase Realtime Database Code and Removal of Event Listener
Below I have included my code for using Firebase Realtime Database:
userInfo = database.getReference("users").child(auth.currentUser!!.uid)
listener = userInfo.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (postSnapshot in dataSnapshot.children) {
if (postSnapshot.key == "firstName") {
firstNamePreference.text = postSnapshot.getValue(String::class.java)
} else if (postSnapshot.key == "lastName") {
lastNamePreference.text = postSnapshot.getValue(String::class.java)
} else if (postSnapshot.key == "username") {
userNamePreference.title =
"Username: ${postSnapshot.getValue(String::class.java)}"
}
}
}
override fun onCancelled(databaseError: DatabaseError) {
Toast.makeText(
context, databaseError.message,
Toast.LENGTH_LONG
).show()
}
})
I have also included userInfo.removeEventListener(listener) in my sign out code, but I am still getting the error message.
UPDATE 2: Logcat in debug mode for logging out the user
D/InputTransport: Input channel destroyed: fd=77
D/ViewRootImpl#b3aa7b8[SettingsActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView#6d11dc3[SettingsActivity]
D/InputMethodManager: getNavigationBarColor() -855310
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy#f47f5fd
W/SyncTree: Listen at /users/ezTJRHVKZXhHyMGQGGljdQpfzGv1 failed: DatabaseError: This client does not have permission to perform this operation
I/DecorView: createDecorCaptionView >> DecorView#aa5b516[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D/InputTransport: Input channel constructed: fd=78
D/ViewRootImpl#46f9f6b[LoginActivity]: setView = DecorView#aa5b516[LoginActivity] TM=true MM=false
D/ViewRootImpl#46f9f6b[LoginActivity]: dispatchAttachedToWindow
D/ViewRootImpl#46f9f6b[LoginActivity]: Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x7 surface={valid=true 480479002624} changed=true
D/OpenGLRenderer: eglCreateWindowSurface = 0x6fdfef7280, 0x6fdec7c010
D/ViewRootImpl#46f9f6b[LoginActivity]: MSG_RESIZED: frame=Rect(0, 0 - 1440, 2960) ci=Rect(0, 96 - 0, 192) vi=Rect(0, 96 - 0, 192) or=1
D/ViewRootImpl#46f9f6b[LoginActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView#aa5b516[LoginActivity]
D/InputMethodManager: getNavigationBarColor() -855310
D/InputMethodManager: prepareNavigationBarInfo() DecorView#aa5b516[LoginActivity]
D/InputMethodManager: getNavigationBarColor() -855310
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport: Input channel constructed: fd=89
D/InputTransport: Input channel destroyed: fd=97
D/FA: Connected to remote service
D/InputTransport: Input channel constructed: fd=92
D/ViewRootImpl#346cbca[Toast]: setView = android.widget.LinearLayout{75c95b1 V.E...... ......I. 0,0-0,0} TM=true MM=false
D/ViewRootImpl#346cbca[Toast]: dispatchAttachedToWindow
D/ViewRootImpl#346cbca[Toast]: Relayout returned: old=[0,96][1440,2768] new=[115,2282][1324,2512] result=0x7 surface={valid=true 480480571392} changed=true
D/OpenGLRenderer: eglCreateWindowSurface = 0x6fdf199d80, 0x6fdedfb010
D/ViewRootImpl#346cbca[Toast]: MSG_RESIZED: frame=Rect(115, 2282 - 1324, 2512) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/OpenGLRenderer: eglDestroySurface = 0x6fdfff3d00, 0x6fdfd7c000
D/ViewRootImpl#b3aa7b8[SettingsActivity]: Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl#b3aa7b8[SettingsActivity]: setWindowStopped(true) old=false
D/ViewRootImpl#b3aa7b8[SettingsActivity]: Surface release. android.view.WindowManagerGlobal.setStoppedState:669 android.app.Activity.performStop:7647 android.app.ActivityThread.callActivityOnStop:4379 android.app.ActivityThread.performStopActivityInner:4357 android.app.ActivityThread.handleStopActivity:4432 android.app.servertransaction.TransactionExecutor.performLifecycleSequence:192 android.app.servertransaction.TransactionExecutor.cycleToPath:165 android.app.servertransaction.TransactionExecutor.executeLifecycleState:142
D/ViewRootImpl#b3aa7b8[SettingsActivity]: dispatchDetachedFromWindow
D/ViewRootImpl#b3aa7b8[SettingsActivity]: Surface release. android.view.ViewRootImpl.doDie:7967 android.view.ViewRootImpl.die:7935 android.view.WindowManagerGlobal.removeViewLocked:497 android.view.WindowManagerGlobal.removeView:435 android.view.WindowManagerImpl.removeViewImmediate:124 android.app.ActivityThread.handleDestroyActivity:4753 android.app.servertransaction.DestroyActivityItem.execute:39 android.app.servertransaction.TransactionExecutor.executeLifecycleState:145
D/InputTransport: Input channel destroyed: fd=91
D/OpenGLRenderer: eglDestroySurface = 0x6fdf199d80, 0x6fdedfb000
D/ViewRootImpl#346cbca[Toast]: dispatchDetachedFromWindow
D/ViewRootImpl#346cbca[Toast]: Surface release. android.view.ViewRootImpl.doDie:7967 android.view.ViewRootImpl.die:7935 android.view.WindowManagerGlobal.removeViewLocked:497 android.view.WindowManagerGlobal.removeView:435 android.view.WindowManagerImpl.removeViewImmediate:124 android.widget.Toast$TN.handleHide:1110 android.widget.Toast$TN$1.handleMessage:898 android.os.Handler.dispatchMessage:106
D/InputTransport: Input channel destroyed: fd=92
It sounds like you have a listener to one of the Firebase databases (either Realtime Database or Cloud Firestore), and this listener requires that the user is authenticated. When you sign the user out, the listener becomes invalid, and gets cancelled by Firebase with the error message you see.
The solution is to remove the listener before signing the user out.
I'm maintaining an Android video replay app through Android Studio. All aspects of the application work fine across multiple devices (Samsung S8, S10, S20 etc) except for 64bit devices where the video decode fails. I'm looking for advice and/or an explaination as to what's causing the problem.
Below is a snippet of the code that is causing me grief. Below are the resultant logs. Basically the application works fine when run using jniLibs/armeabi however fails when run using jnilibs/arm64-v8a. The decoder threads keep failing with IllogicalArgumentException.
Code:
private class PlayerThread3 extends Thread {
private MediaCodec decoder;
private Surface surface;
public PlayerThread3(Surface surface) {
this.surface = surface;
}
#Override
public void run() {
Log.d("PlayerThread3->Run", "Entry surface=" + surface.toString());
MediaFormat format = MediaFormat.createVideoFormat("video/avc", mSurfaceWidth, mSurfaceHeight);
try {
Log.d("PlayerThread3->Run", "MediaFormat=" + format.toString());
decoder = MediaCodec.createByCodecName("OMX.google.h264.decoder");
Log.d("PlayerThread3->Run", "MediaCodec=" + decoder.toString());
if (surface.isValid()) {
Log.d("PlayerThread3->Run", "surface.isValid=" + surface.toString());
decoder.configure(format, surface, null, 0);
} else {
Log.i("debug","decoder31");
Message msg = Message.obtain();
msg.what = 3;
msg.obj = "Failed to start live video(surface)";
handler.sendMessage(msg);
return;
}
} catch (IllegalArgumentException e) {
Log.d("PlayerThread3->Run", "IA surface=" + surface.toString());
e.printStackTrace();
Log.i("debug", "decoder32");
Message msg = Message.obtain();
msg.what = 3;
msg.obj = "Failed to start live video(arg)";
handler.sendMessage(msg);
return;
} catch (IOException e) {
e.printStackTrace();
Log.i("debug", "decoder33");
Message msg = Message.obtain();
msg.what = 3;
msg.obj = "Failed to start live video(IO)";
handler.sendMessage(msg);
return;
}
try {
decoder.start();
inputBuffers3 = decoder.getInputBuffers();
Message msg = Message.obtain();
msg.what = 3;
handler.sendMessage(msg);
while (preferences_isAlways.getBoolean("indexDecode3" + index, false)) {
if (decoder_array3 != null) {
offerDecoder(decoder_array3, decoder_array3.length);
decoder_array3 = null;
}
}
decoder.stop();
decoder.release();
} catch (IllegalStateException e) {
e.printStackTrace();
Log.i("debug", "decoder34");
Message msg = Message.obtain();
msg.what = 3;
msg.obj = "Failed to start live video(IS)";
handler.sendMessage(msg);
}
}
Log:
I/frameRate: 2
I/whichPartOfFrame: 0
I/s_frame_serial: 40
I/frame_packet_body: 1952
D/PlayerThread3->Run: Entry surface=Surface(name=null)/#0x68f7d48
D/PlayerThread3->Run: MediaFormat={mime=video/avc, width=536, height=437}
D/CCodec: allocate(c2.android.avc.decoder)
I/CCodec: Created component [c2.android.avc.decoder]
D/CCodecConfig: read media type: video/avc
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.max-count.values
extent() != 1 for single value type: output.subscribed-indices.values
D/ReflectedParamUpdater: extent() != 1 for single value type: input.buffers.allocator-ids.values
extent() != 1 for single value type: output.buffers.allocator-ids.values
extent() != 1 for single value type: algo.buffers.allocator-ids.values
extent() != 1 for single value type: output.buffers.pool-ids.values
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.pool-ids.values
D/ReflectedParamUpdater: ignored struct field coded.color-format.locations
D/CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
ignoring local param raw.color (0xd2001809) as it is already supported
D/ReflectedParamUpdater: ignored struct field raw.hdr-static-info.mastering
I/CCodecConfig: query failed after returning 12 values (BAD_INDEX)
D/CCodecConfig: c2 config is Dict {
c2::u32 coded.pl.level = 20496
c2::u32 coded.pl.profile = 20481
c2::u32 coded.vui.color.matrix = 0
c2::u32 coded.vui.color.primaries = 0
c2::u32 coded.vui.color.range = 2
c2::u32 coded.vui.color.transfer = 0
c2::u32 default.color.matrix = 0
c2::u32 default.color.primaries = 0
c2::u32 default.color.range = 0
c2::u32 default.color.transfer = 0
c2::u32 input.buffers.max-size.value = 57600
c2::u32 input.delay.value = 0
string input.media-type.value = "video/avc"
c2::u32 output.delay.value = 8
string output.media-type.value = "video/raw"
c2::u32 raw.color.matrix = 0
c2::u32 raw.color.primaries = 0
c2::u32 raw.color.range = 2
c2::u32 raw.color.transfer = 0
c2::u32 raw.max-size.height = 240
c2::u32 raw.max-size.width = 320
c2::u32 raw.pixel-format.value = 35
c2::i32 raw.rotation.flip = 0
c2::i32 raw.rotation.value = 0
c2::u32 raw.sar.height = 1
c2::u32 raw.sar.width = 1
c2::u32 raw.size.height = 240
c2::u32 raw.size.width = 320
c2::u32 ra
W/ColorUtils: expected specified color aspects (2:0:0:0)
D/PlayerThread3->Run: MediaCodec=android.media.MediaCodec#da3c906
surface.isValid=Surface(name=null)/#0x68f7d48
D/SurfaceUtils: connecting to surface 0x7645de8010, reason connectToSurface
I/MediaCodec: [c2.android.avc.decoder] setting surface generation to 27948035
D/SurfaceUtils: disconnecting from surface 0x7645de8010, reason connectToSurface(reconnect)
connecting to surface 0x7645de8010, reason connectToSurface(reconnect)
D/CCodecConfig: no c2 equivalents for native-window
config failed => CORRUPTED
Bad parameter value
D/CCodecConfig: c2 config is Dict {
c2::u32 coded.pl.level = 20496
c2::u32 coded.pl.profile = 20481
c2::u32 coded.vui.color.matrix = 0
c2::u32 coded.vui.color.primaries = 0
c2::u32 coded.vui.color.range = 2
c2::u32 coded.vui.color.transfer = 0
c2::u32 default.color.matrix = 0
c2::u32 default.color.primaries = 0
c2::u32 default.color.range = 0
c2::u32 default.color.transfer = 0
c2::u32 input.buffers.max-size.value = 57600
c2::u32 input.delay.value = 0
string input.media-type.value = "video/avc"
c2::u32 output.delay.value = 8
string output.media-type.value = "video/raw"
c2::u32 raw.color.matrix = 0
c2::u32 raw.color.primaries = 0
c2::u32 raw.color.range = 2
c2::u32 raw.color.transfer = 0
c2::u32 raw.max-size.height = 240
c2::u32 raw.max-size.width = 320
c2::u32 raw.pixel-format.value = 35
c2::i32 raw.rotation.flip = 0
c2::i32 raw.rotation.value = 0
c2::u32 raw.sar.height = 1
c2::u32 raw.sar.width = 1
c2::u32 raw.size.height = 240
c2::u32 raw.size.width = 536
c2::u32 ra
W/CCodec: failed to configure c2 params
E/MediaCodec: Codec reported err 0xffffffea, actionCode 0, while in state 3
D/SurfaceUtils: disconnecting from surface 0x7645de8010, reason disconnectFromSurface
E/MediaCodec: configure failed with err 0xffffffea, resetting...
I/MediaCodec: Codec shutdown complete
D/CCodec: allocate(c2.android.avc.decoder)
I/CCodec: Created component [c2.android.avc.decoder]
D/CCodecConfig: read media type: video/avc
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.max-count.values
extent() != 1 for single value type: output.subscribed-indices.values
extent() != 1 for single value type: input.buffers.allocator-ids.values
extent() != 1 for single value type: output.buffers.allocator-ids.values
extent() != 1 for single value type: algo.buffers.allocator-ids.values
extent() != 1 for single value type: output.buffers.pool-ids.values
extent() != 1 for single value type: algo.buffers.pool-ids.values
D/ReflectedParamUpdater: ignored struct field coded.color-format.locations
I/frameRate: 2
I/whichPartOfFrame: 0
I/s_frame_serial: 41
I/frame_packet_body: 46
D/CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
ignoring local param raw.color (0xd2001809) as it is already supported
D/ReflectedParamUpdater: ignored struct field raw.hdr-static-info.mastering
I/CCodecConfig: query failed after returning 12 values (BAD_INDEX)
D/CCodecConfig: c2 config is Dict {
c2::u32 coded.pl.level = 20496
c2::u32 coded.pl.profile = 20481
c2::u32 coded.vui.color.matrix = 0
c2::u32 coded.vui.color.primaries = 0
c2::u32 coded.vui.color.range = 2
c2::u32 coded.vui.color.transfer = 0
c2::u32 default.color.matrix = 0
c2::u32 default.color.primaries = 0
c2::u32 default.color.range = 0
c2::u32 default.color.transfer = 0
c2::u32 input.buffers.max-size.value = 57600
c2::u32 input.delay.value = 0
string input.media-type.value = "video/avc"
c2::u32 output.delay.value = 8
string output.media-type.value = "video/raw"
c2::u32 raw.color.matrix = 0
c2::u32 raw.color.primaries = 0
c2::u32 raw.color.range = 2
c2::u32 raw.color.transfer = 0
c2::u32 raw.max-size.height = 240
c2::u32 raw.max-size.width = 320
c2::u32 raw.pixel-format.value = 35
c2::i32 raw.rotation.flip = 0
c2::i32 raw.rotation.value = 0
c2::u32 raw.sar.height = 1
c2::u32 raw.sar.width = 1
c2::u32 raw.size.height = 240
c2::u32 raw.size.width = 320
c2::u32 ra
W/ColorUtils: expected specified color aspects (2:0:0:0)
D/PlayerThread3->Run: IA surface=Surface(name=null)/#0x68f7d48
W/System.err: java.lang.IllegalArgumentException
at android.media.MediaCodec.native_configure(Native Method)
W/System.err: at android.media.MediaCodec.configure(MediaCodec.java:2023)
at android.media.MediaCodec.configure(MediaCodec.java:1951)
at au.com.FreedomVMS.iFreedomVMSpro.live.ShowFragment$PlayerThread3.run(ShowFragment.java:5789)
I/debug: decoder32
I/.iFreedomVMSpr: Compiler allocated 15MB to compile void au.com.FreedomVMS.iFreedomVMSpro.live.ShowFragment.handleSocket1(int, byte, java.lang.String, int, java.lang.String, java.lang.String)
I/frameRate: 2
I/whichPartOfFrame: 1
I/s_frame_serial: 42
I/frame_packet_body: 10240
Simples, problem solved. Surface dimensions, width and height, have to be multiples of 16 under Android 10. The earlier versions of Android tested against don't appear to be worried by this constraint.
MediaMuxer has been driving me mad for two days & nights now :-(
The situation: I receive a H264 encoded 1280x720 video stream via UDP.
The h264 stream contains NALU 1 - slice and NALU 5 - keyframe (5 is always preceded by NALU 7 - SPS and NALU 8 - PPS).
This stream appears to be stable 30fps with at least one NALU 5 keyframe per second. Bitrate is variable but less than 4Mbps.
MediaCodec sucessfully decodes the stream and renders it in a surface view so that part works well.
But now I need to save the H.264 into a local mpg file.
I set up a MediaMuxer with all MediaFormat information that I have, and feed it with the sample data from the stream.
Each sample contains one frame (NALU 1 or 5), and the first data sent to MediaMuxer is a keyframe (NALU 5). The presentation time is calculated based on framenumber and framerate.
All involved methods are called from the same thread.
But the mpg file is never created. As you can see in the output below the data in the ByteBuffer does start with NALU headers followed by varying size of data. MediaMuxer seems to "see" frames in the data as it counts the frames.
So what is wrong here?
Minimum API is 21, and I have tested with a Samsung Galaxy S4 running stock Android 5 and a couple of devices running Lineageos Oreo and Nougat.
Here is the code to setup the MediaMuxer:
void setupMuxer(File f) throws IOException {
if (DEBUG) Log.d(TAG, "Setup Muxer: " + f.getAbsolutePath() +" can write: " + f.canWrite());
MediaFormat format = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, decoderWidth, decoderHeight);
format.setInteger(MediaFormat.KEY_BIT_RATE, 4000000);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 29);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
format.setByteBuffer("csd-0", ByteBuffer.wrap(sps)); // sps and pps have been retrieved from the stream's NAL 7/8
format.setByteBuffer("csd-1", ByteBuffer.wrap(pps));
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 1920 * 1080);
muxer = new MediaMuxer(f.getPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
videoTrack = muxer.addTrack(format);
muxer.start();
}
This method is called for each (complete) NALU 1 and NALU 5:
void muxFrame(ByteBuffer buf, int frame) {
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
bufferInfo.offset = buf.arrayOffset();
bufferInfo.size = buf.position() - bufferInfo.offset;
bufferInfo.flags = (buf.get(4) & 0x1f) == 5 ? MediaCodec.BUFFER_FLAG_KEY_FRAME : 0;
bufferInfo.presentationTimeUs = computePresentationTime(frame);
if (DEBUG)
Log.d(TAG, "muxFrame frame: " + frame + " size: " + bufferInfo.size + " NAL: " + (buf.get(4) & 0x1f) + " Flags: " + bufferInfo.flags + " PTS: " + bufferInfo.presentationTimeUs + " content: " + BitByteUtil.toByteString(buf.array(), buf.arrayOffset(), 8));
try {
muxer.writeSampleData(videoTrack, buf, bufferInfo);
} catch (Exception e) {
Log.w(TAG, "muxer failed", e);
} finally {
}
}
private static long computePresentationTime(int frameIndex) {
return 42 + frameIndex * 1000000 / FRAME_RATE;
}
Here is my output if MediaMuxer is stopped after it has consumed 100 NALUs.
05.651 D/VideoDecoderView: Setup Muxer: /storage/emulated/0/Pictures/test.mpg can write: true
05.656 I/MPEG4Writer: limits: 4294967295/0 bytes/us, bit rate: -1 bps and the estimated moov size 3317 bytes
06.263 D/VideoDecoderView: muxFrame frame: 2 size: 7257 NAL: 5 Flags: 1 PTS: 66708 content: 0:000 1:000 2:000 3:001 4:101 5:184 6:000 7:015
06.264 I/MPEG4Writer: setStartTimestampUs: 66708
06.264 I/MPEG4Writer: Earliest track starting time: 66708
06.308 D/VideoDecoderView: muxFrame frame: 3 size: 8998 NAL: 1 Flags: 0 PTS: 100042 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:034 7:020
06.342 D/VideoDecoderView: muxFrame frame: 4 size: 13664 NAL: 1 Flags: 0 PTS: 133375 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:066 7:020
06.375 D/VideoDecoderView: muxFrame frame: 5 size: 13674 NAL: 1 Flags: 0 PTS: 166708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:098 7:020
06.409 D/VideoDecoderView: muxFrame frame: 6 size: 13772 NAL: 1 Flags: 0 PTS: 200042 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:130 7:020
06.483 D/VideoDecoderView: muxFrame frame: 7 size: 13707 NAL: 1 Flags: 0 PTS: 233375 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:162 7:020
06.520 D/VideoDecoderView: muxFrame frame: 8 size: 13778 NAL: 1 Flags: 0 PTS: 266708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:194 7:020
06.555 D/VideoDecoderView: muxFrame frame: 9 size: 13743 NAL: 1 Flags: 0 PTS: 300042 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:226 7:020
06.575 D/VideoDecoderView: muxFrame frame: 10 size: 7338 NAL: 5 Flags: 1 PTS: 333375 content: 0:000 1:000 2:000 3:001 4:101 5:184 6:000 7:015
06.593 D/VideoDecoderView: muxFrame frame: 11 size: 9059 NAL: 1 Flags: 0 PTS: 366708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:034 7:020
06.618 D/VideoDecoderView: muxFrame frame: 12 size: 13587 NAL: 1 Flags: 0 PTS: 400042 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:066 7:020
06.644 D/VideoDecoderView: muxFrame frame: 13 size: 13650 NAL: 1 Flags: 0 PTS: 433375 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:098 7:020
06.671 D/VideoDecoderView: muxFrame frame: 14 size: 13797 NAL: 1 Flags: 0 PTS: 466708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:130 7:020
.... [snip]
09.620 D/VideoDecoderView: muxFrame frame: 97 size: 7212 NAL: 5 Flags: 1 PTS: 3233375 content: 0:000 1:000 2:000 3:001 4:101 5:184 6:000 7:015
09.661 D/VideoDecoderView: muxFrame frame: 98 size: 8814 NAL: 1 Flags: 0 PTS: 3266708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:034 7:020
09.692 D/VideoDecoderView: muxFrame frame: 99 size: 13566 NAL: 1 Flags: 0 PTS: 3300042 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:066 7:020
09.737 D/VideoDecoderView: muxFrame frame: 100 size: 13733 NAL: 1 Flags: 0 PTS: 3333375 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:098 7:020
09.771 D/VideoDecoderView: muxFrame frame: 101 size: 13771 NAL: 1 Flags: 0 PTS: 3366708 content: 0:000 1:000 2:000 3:001 4:065 5:224 6:130 7:020
09.775 D/MPEG4Writer: Video track stopping. Stop source
09.775 I/MPEG4Writer: Received total/0-length (100/1) buffers and encoded 100 frames. - Video
09.775 D/MPEG4Writer: Video track source stopping
09.775 D/MPEG4Writer: Video track source stopped
09.775 D/MPEG4Writer: Video track stopped. Stop source
09.775 D/MPEG4Writer: Stopping writer thread
09.776 D/MPEG4Writer: 0 chunks are written in the last batch
09.779 D/MPEG4Writer: Writer thread stopped
09.780 I/MPEG4Writer: Ajust the moov start time from 66708 us -> 66708 us
09.780 D/MPEG4Writer: Video track stopping. Stop source
#greeble31: You are right. The first log entry clearly states "Pictures" and not "Videos".
I spent hours looking at this problem without noticing a simple cut&paste mistake in my preferences keys. How stupid is that!!?!
Note to myself: Coding two days & nights in a row is not heroic but just plain stupid.
My android app passes in an OpenGL texture2D to my OpenCL kernel, however the pixels values being read by my kernel are out of bounds (>255).
I create my OpenGL texture like this:
GLES20.glGenTextures ( 2, targetTex, 0 );
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, targetTex[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, image_width, image_height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
The texture is then rendered to by binding it with a FBO:
targetFramebuffer = IntBuffer.allocate(1);
GLES20.glGenFramebuffers(1, targetFramebuffer);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, targetFramebuffer.get(0));
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, targetTex[0], 0);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
I create the cl memory object like so:
mem_images[0] = clCreateFromGLTexture2D(m_clContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, in_tex, &err);
and this is my OpenCL kernel:
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST;
kernel void transfer_data(__read_only image2d_t input_image, __global float* debug) {
int2 pos;
uint4 pixel;
for (pos.y = get_global_id(1); pos.y < HEIGHT; pos.y += get_global_size(1)) {
for (pos.x = get_global_id(0); pos.x < WIDTH; pos.x += get_global_size(0)) {
pixel = read_imageui(input_image, sampler, pos);
debug[(pos.x + pos.y*WIDTH)*NUM_CHANNELS + 0] = pixel.x;
debug[(pos.x + pos.y*WIDTH)*NUM_CHANNELS + 1] = pixel.y;
debug[(pos.x + pos.y*WIDTH)*NUM_CHANNELS + 2] = pixel.z;
}
}
}
This is how I am enqueing the kernel:
local2Dsize[0] = 4;
local2Dsize[1] = 4;
global2Dsize[0] = clamp(image_width, 0, max_work_items[0]);
global2Dsize[1] = clamp(image_height, 0, max_work_items[1]);
global2Dsize[0] = ceil((float)global2Dsize[0]/(float)local2Dsize[0])*local2Dsize[0];
global2Dsize[1] = ceil((float)global2Dsize[1]/(float)local2Dsize[1])*local2Dsize[1];
twoDlocal_sizes["transfer_data"] = local2Dsize;
twoDglobal_sizes["transfer_data"] = global2Dsize;
kernels["transfer_data"] = clCreateKernel(m_program, "transfer_data", &err);
err = clSetKernelArg(kernels["transfer_data"], 0, sizeof(cl_mem), &mem_images[0]);
err |= clSetKernelArg(kernels["transfer_data"], 1, sizeof(cl_mem), &mems["image"]);
err = clEnqueueAcquireGLObjects(m_queue, 1, &mem_images[0], 0, 0, 0);
CHECK_ERROR_OCL(err, "acquiring GL objects", return false);
err = clEnqueueNDRangeKernel(m_queue, kernels["transfer_data"], 2, NULL, twoDglobal_sizes["transfer_data"], twoDlocal_sizes["transfer_data"], 0, NULL, NULL);
err = clFinish(m_queue);
err = clEnqueueReleaseGLObjects(m_queue, 1, &mem_images[0], 0, 0, 0);
CHECK_ERROR_OCL(err, "releasing GL objects", return false);
Now back on host when I print out these pixel values (from the array debug), they are way out of bounds and I don't understand why that is the case.
If you need more insight:
The overall aim of my project is to obtain camera frames in form of an OpenGL texture, process them using OpenCL and render the output back to the screen.
However the texture obtained from android camera can only be bound to GL_TEXTURE_EXTERNAL_OES (http://developer.android.com/reference/android/graphics/SurfaceTexture.html), and this is not a valid texture to create an OpenCL memory object from.
Therefore I am rendering the camera output to a GL_TEXTURE_2D and passing that to OpenCL.
I am sure that the pixels are being rendered to the texture correctly, because when I display the texture on the screen (without any OpenCL involved) it displays the image properly.
I did some debugging by creating a texture (as opposed to getting data from the camera) and passing that to opencl. So these are the mappings I get:
0 -> 0
1 -> 7172
2 -> 8196
3 -> 8710
4 -> 9220
5 -> 9477
6 -> 9734
7 -> 9991
8 -> 10244
9 -> 10372
10 -> 10501
11 -> 10629
12 -> 10758
13 -> 10886
14 -> 11015
15 -> 11143
16 -> 11268
17 -> 11332
18 -> 11396
19 -> 11460
20 -> 11525
21 -> 11589
22 -> 11653
23 -> 11717
24 -> 11782
25 -> 11846
26 -> 11910
27 -> 11974
28 -> 12039
29 -> 12103
30 -> 12167
31 -> 12231
32 -> 12292
33 -> 12324
34 -> 12356
35 -> 12388
36 -> 12420
37 -> 12452
38 -> 12484
39 -> 12516
40 -> 12549
41 -> 12581
42 -> 12613
43 -> 12645
44 -> 12677
45 -> 12709
46 -> 12741
47 -> 12773
48 -> 12806
49 -> 12838
50 -> 12870
51 -> 12902
52 -> 12934
53 -> 12966
54 -> 12998
55 -> 13030
56 -> 13063
57 -> 13095
58 -> 13127
59 -> 13159
60 -> 13191
61 -> 13223
62 -> 13255
63 -> 13287
64 -> 13316
65 -> 13332
66 -> 13348
67 -> 13364
68 -> 13380
69 -> 13396
70 -> 13412
71 -> 13428
72 -> 13444
73 -> 13460
74 -> 13476
75 -> 13492
76 -> 13508
77 -> 13524
78 -> 13540
79 -> 13556
80 -> 13573
81 -> 13589
82 -> 13605
83 -> 13621
84 -> 13637
85 -> 13653
86 -> 13669
87 -> 13685
88 -> 13701
89 -> 13717
90 -> 13733
91 -> 13749
92 -> 13765
93 -> 13781
94 -> 13797
95 -> 13813
96 -> 13830
97 -> 13846
98 -> 13862
99 -> 13878
100 -> 13894
101 -> 13910
102 -> 13926
103 -> 13942
104 -> 13958
105 -> 13974
106 -> 13990
107 -> 14006
108 -> 14022
109 -> 14038
110 -> 14054
111 -> 14070
112 -> 14087
113 -> 14103
114 -> 14119
115 -> 14135
116 -> 14151
117 -> 14167
118 -> 14183
119 -> 14199
120 -> 14215
121 -> 14231
122 -> 14247
123 -> 14263
124 -> 14279
125 -> 14295
126 -> 14311
127 -> 14327
128 -> 14340
129 -> 14348
130 -> 14356
131 -> 14364
132 -> 14372
133 -> 14380
134 -> 14388
135 -> 14396
136 -> 14404
137 -> 14412
138 -> 14420
139 -> 14428
140 -> 14436
141 -> 14444
142 -> 14452
143 -> 14460
144 -> 14468
145 -> 14476
146 -> 14484
147 -> 14492
148 -> 14500
149 -> 14508
150 -> 14516
151 -> 14524
152 -> 14532
153 -> 14540
154 -> 14548
155 -> 14556
156 -> 14564
157 -> 14572
158 -> 14580
159 -> 14588
160 -> 14597
161 -> 14605
162 -> 14613
163 -> 14621
164 -> 14629
165 -> 14637
166 -> 14645
167 -> 14653
168 -> 14661
169 -> 14669
170 -> 14677
171 -> 14685
172 -> 14693
173 -> 14701
174 -> 14709
175 -> 14717
176 -> 14725
177 -> 14733
178 -> 14741
179 -> 14749
180 -> 14757
181 -> 14765
182 -> 14773
183 -> 14781
184 -> 14789
185 -> 14797
186 -> 14805
187 -> 14813
188 -> 14821
189 -> 14829
190 -> 14837
191 -> 14845
192 -> 14854
193 -> 14862
194 -> 14870
195 -> 14878
196 -> 14886
197 -> 14894
198 -> 14902
199 -> 14910
200 -> 14918
201 -> 14926
202 -> 14934
203 -> 14942
204 -> 14950
205 -> 14958
206 -> 14966
207 -> 14974
208 -> 14982
209 -> 14990
210 -> 14998
211 -> 15006
212 -> 15014
213 -> 15022
214 -> 15030
215 -> 15038
216 -> 15046
217 -> 15054
218 -> 15062
219 -> 15070
220 -> 15078
221 -> 15086
222 -> 15094
223 -> 15102
224 -> 15111
225 -> 15119
226 -> 15127
227 -> 15135
228 -> 15143
229 -> 15151
230 -> 15159
231 -> 15167
232 -> 15175
233 -> 15183
234 -> 15191
235 -> 15199
236 -> 15207
237 -> 15215
238 -> 15223
239 -> 15231
240 -> 15239
241 -> 15247
242 -> 15255
243 -> 15263
244 -> 15271
245 -> 15279
246 -> 15287
247 -> 15295
248 -> 15303
249 -> 15311
250 -> 15319
251 -> 15327
252 -> 15335
253 -> 15343
254 -> 15351
255 -> 15359
On the left is the colour value that I input in the OpenGL texture and on the left is the corresponding value I get when I read the values in OpenCL.
The GL_UNSIGNED_BYTE texture is being mapped to OpenCL as CL_UNORM_INT8. You need to use read_imagef to read from these images rather than read_imageui. The values you are seeing when you use read_imageui are the raw bits of the internal floating point format.
You are not acquiring and releasing the GL objects before accessing them. This causes the kernel not to read to data in the GL internal buffer but a local CL copy of it.
Proper code: (BTW you should check those "err" values for errors)
local2Dsize[0] = 4;
local2Dsize[1] = 4;
global2Dsize[0] = clamp(image_width, 0, max_work_items[0]);
global2Dsize[1] = clamp(image_height, 0, max_work_items[1]);
global2Dsize[0] = ceil((float)global2Dsize[0]/(float)local2Dsize[0])*local2Dsize[0];
global2Dsize[1] = ceil((float)global2Dsize[1]/(float)local2Dsize[1])*local2Dsize[1];
twoDlocal_sizes["transfer_data"] = local2Dsize;
twoDglobal_sizes["transfer_data"] = global2Dsize;
kernels["transfer_data"] = clCreateKernel(m_program, "transfer_data", &err);
err = clSetKernelArg(kernels["transfer_data"], 0, sizeof(cl_mem), &mem_images[0]);
err |= clSetKernelArg(kernels["transfer_data"], 1, sizeof(cl_mem), &mems["image"]);
err = clEnqueueAcquireGLObjects(m_queue, 1, mem_images, NULL, NULL, NULL);
err = clEnqueueNDRangeKernel(m_queue, kernels["transfer_data"], 2, NULL, twoDglobal_sizes["transfer_data"], twoDlocal_sizes["transfer_data"], 0, NULL, NULL);
err = clEnqueueReleaseGLObjects (m_queue, 1, mem_images, NULL, NULL, NULL);
err = clFinish(m_queue);
Okay so I think it's a bug in the OpenCL implementation.
With a bit of help from Wolfram Alpha, I created a function to reverse the above mappings and obtain values in the range of 0 and 255.
float GL_to_CL(uint val) {
if (val >= 14340) return round(0.1245790*val - 1658.44); //>=128
if (val >= 13316) return round(0.0622869*val - 765.408); //>=64
if (val >= 12292) return round(0.0311424*val - 350.800); //>=32
if (val >= 11268) return round(0.0155702*val - 159.443); //>=16
float v = (float) val;
return round(0.0000000000000125922*pow(v,4.f) - 0.00000000026729*pow(v,3.f) + 0.00000198135*pow(v,2.f) - 0.00496681*v - 0.0000808829);
}
So the GL_to_CL() is a combination of 4 linear functions and a Quartic function.
I tried creating just a single function using polynomial interpolation, however the degree of the polynomial was too large and therefore more computationally expensive to solve than the combination of the 5 functions proposed above.
Another alternate is to use a 15k sized array to achieve constant time, however that would require me uploading roughly 15k Bytes to GPU's global memory.
Considering I am using the kernels to do image processing, I would be slightly pushing it.
Also accessing from global memory in OpenCL is often more expensive than performing some simple calculations.