Author Topic: BASS Android - problem with play long files  (Read 1066 times)

kenumir

  • Posts: 5
BASS Android - problem with play long files
« on: 31 Aug '15 - 12:37 »
I'm working with downloaded AAC radio streams files (without ICY tags data). When I try to play large file (~800MB = 15h, AAC) with "BASS_StreamCreateFile" method it takes long time to init player (60+secs) but with smaller file (~400MB = 8h, AAC) playback starts quickly and everything works fine. Also I have problems with getting correct lenght of file (time) - "BASS_ChannelGetLength" returns(43202.44390022676 = 12:00:02) but file is ~15h long. With "BASS_StreamCreateFileUser" my app crashes.

Error log:
Code: [Select]
08-31 12:19:13.889    1711-1810/? D/WidgetsModel﹕ com.google.android.googlequicksearchbox is filtered and not added to the widget tray.
08-31 12:19:13.899     794-1731/? D/WifiService﹕ acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@5e31290}
08-31 12:19:13.903     794-1187/? D/wifi﹕ Initialized common fields 10000, 16, 100, 10
08-31 12:19:13.903     794-1187/? D/wifi﹕ bucket[0] = 2:3:10000:2
08-31 12:19:14.422  29908-29908/com.hv.bassplayer A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x109 in tid 29908 (m.hv.bassplayer)
08-31 12:19:14.433      203-776/? D/audio_hw_primary﹕ out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
08-31 12:19:14.439     794-1280/? D/WifiService﹕ releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@5e31290}
08-31 12:19:14.473      203-776/? D/AudioFlinger﹕ mixer(0xb4180000) throttle end: throttle time(4)
08-31 12:19:14.531      200-200/? A/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-31 12:19:14.531      200-200/? A/DEBUG﹕ Build fingerprint: 'google/hammerhead/hammerhead:6.0/MPA44I/2172151:user/release-keys'
08-31 12:19:14.531      200-200/? A/DEBUG﹕ Revision: '0'
08-31 12:19:14.531      200-200/? A/DEBUG﹕ ABI: 'arm'
08-31 12:19:14.531      200-200/? A/DEBUG﹕ pid: 29908, tid: 29908, name: m.hv.bassplayer  >>> com.hv.bassplayer <<<
08-31 12:19:14.531      200-200/? A/DEBUG﹕ signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x109
08-31 12:19:14.550      200-200/? A/DEBUG﹕ r0 aeed9898  r1 00000109  r2 000005f8  r3 00000008
08-31 12:19:14.551      200-200/? A/DEBUG﹕ r4 00000000  r5 00000000  r6 aeeeb838  r7 00000600
08-31 12:19:14.551      200-200/? A/DEBUG﹕ r8 aeeeb780  r9 aeed9898  sl ffffffff  fp be98bd10
08-31 12:19:14.551      200-200/? A/DEBUG﹕ ip 00000000  sp be98bca8  lr b398e59b  pc b6ca164a  cpsr 600d0030
08-31 12:19:14.591      200-200/? A/DEBUG﹕ backtrace:
08-31 12:19:14.592      200-200/? A/DEBUG﹕ #00 pc 0001764a  /system/lib/libc.so (__memcpy_base+65)
08-31 12:19:14.592      200-200/? A/DEBUG﹕ #01 pc 00017597  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so
08-31 12:19:14.592      200-200/? A/DEBUG﹕ #02 pc 000025e7  /data/app/com.hv.bassplayer-2/lib/arm/libbass_aac.so
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #03 pc 00022a8f  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #04 pc 0002300d  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #05 pc 00021fdb  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #06 pc 00022023  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #07 pc 00024d8b  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so (BASS_ChannelPlay+172)
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #08 pc 00024df7  /data/app/com.hv.bassplayer-2/lib/arm/libbass.so (Java_com_un4seen_bass_BASS_BASS_1ChannelPlay+6)
08-31 12:19:14.593      200-200/? A/DEBUG﹕ #09 pc 005117dd  /data/app/com.hv.bassplayer-2/oat/arm/base.odex (boolean com.un4seen.bass.BASS.BASS_ChannelPlay(int, boolean)+88)
08-31 12:19:14.594      200-200/? A/DEBUG﹕ #10 pc 00497539  /data/app/com.hv.bassplayer-2/oat/arm/base.odex (void com.hv.bassplayer.NewPlayerTestsActivity$BPlayer.play()+108)
08-31 12:19:14.594      200-200/? A/DEBUG﹕ #11 pc 00696457  /data/app/com.hv.bassplayer-2/oat/arm/base.odex (void com.hv.bassplayer.NewPlayerTestsActivity.handlePlayer(android.view.View)+338)
08-31 12:19:14.594      200-200/? A/DEBUG﹕ #12 pc 000e6331  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
08-31 12:19:14.594      200-200/? A/DEBUG﹕ #13 pc 004023b5  /system/lib/libart.so (art_quick_invoke_stub+188)
08-31 12:19:14.594      200-200/? A/DEBUG﹕ #14 pc 007fe044  [stack]
08-31 12:19:15.175      200-200/? A/DEBUG﹕ Tombstone written to: /data/tombstones/tombstone_00
08-31 12:19:15.175      200-200/? E/DEBUG﹕ AM write failed: Broken pipe

My BASS_StreamCreateFileUser looks this:
Code: [Select]
final File f = new File(Environment.getExternalStorageDirectory(), "stream.mp3");
final FileInputStream mFileInputStream = new FileInputStream(f);
final int handle = BASS.BASS_StreamCreateFileUser(BASS.STREAMFILE_BUFFER, 0, new BASS.BASS_FILEPROCS() {
@Override
public void FILECLOSEPROC(Object user) {
try {
mFileInputStream.close();
} catch (IOException ignore) {
}
}
@Override
public long FILELENPROC(Object user) { return f.length(); }
@Override
public int FILEREADPROC(ByteBuffer buffer, int length, Object user) {
byte b[]=new byte[length];
int r=0;
try {
r=mFileInputStream.read(b);
} catch (IOException e) {
}
if (r<=0) return 0;
buffer.put(b, 0, r);
return r;
}
@Override
public boolean FILESEEKPROC(long offset, Object user) {
try {
mFileInputStream.getChannel().position(offset);
return true;
} catch (IOException e) {
if (Console.isEnabled())
Console.loge("getFileTimeFast.FILESEEKPROC: " + e.toString(), e);
}
return false;
}
}, user);
BASS.BASS_ChannelPlay(handle, false);

What is wrong? BASS is not supporting large files?

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS Android - problem with play long files
« Reply #1 on: 31 Aug '15 - 14:03 »
By default, the BASS_AAC add-on will pre-scan ADTS AAC files to build a seek table and get the length. With a large file, that could take a while. It can be disabled via the BASS_CONFIG_AAC_PRESCAN option...

Code: [Select]
BASS.BASS_SetConfig(BASS_AAC.BASS_CONFIG_AAC_PRESCAN, 0);

In that case, seeking and the length will be approximate. If you want to enable pre-scanning on certain files, you can use the BASS_STREAM_PRESCAN flag in those BASS_StreamCreateFile calls.

Regarding the crash, are you only getting that when using BASS_StreamCreateFileUser (not BASS_StreamCreateFile/URL), and if so, only when using the STREAMFILE_BUFFER file system?

kenumir

  • Posts: 5
Re: BASS Android - problem with play long files
« Reply #2 on: 31 Aug '15 - 14:18 »
BASS_AAC.BASS_CONFIG_AAC_PRESCAN setting helped us indeed.

Yes, crash happens only when we use BASS_StreamCreateFileUser

BTW: in the nearest future I will contact in order to buy a library for the commercial app.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS Android - problem with play long files
« Reply #3 on: 31 Aug '15 - 17:37 »
To investigate what's causing the crash, please upload the file (stream.mp3) that you're testing with to produce it here:

   ftp.un4seen.com/incoming/

kenumir

  • Posts: 5
Re: BASS Android - problem with play long files
« Reply #4 on: 1 Sep '15 - 08:04 »
I just uploaded the file + example (Android Studio). I will be grateful for your help.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS Android - problem with play long files
« Reply #5 on: 1 Sep '15 - 16:46 »
I seem to be unable to reproduce the crash in the log you posted above, but I am able to get Android to kill the app soon after starting playback. Android gives no information about that, but presumably it's because it has run out of memory. By default, BASS will allocate a buffer to hold the entire file when the STREAMFILE_BUFFER system is used. Adding the BASS_STREAM_BLOCK flag to the BASS_StreamCreateFileUser call tells BASS to only keep a small part of the file in memory (determined by the BASS_CONFIG_NET_BUFFER setting), and indeed doing that prevents the app being killed here. Does the BASS_STREAM_BLOCK flag prevent the crash for you too?

kenumir

  • Posts: 5
Re: BASS Android - problem with play long files
« Reply #6 on: 2 Sep '15 - 08:07 »
Yes, BASS_STREAM_BLOCK prevents crash, but with this flag it's not possible to seek and get file length. I just noticed that on Jiayu G3 I get a low memory warning (from system). Crash occurred also on Nexus 5, Nexus 6 and Samsung S6.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS Android - problem with play long files
« Reply #7 on: 2 Sep '15 - 16:00 »
If seeking is needed, perhaps you could use the unbuffered STREAMFILE_NOBUFFER system instead? That's the same system as used by BASS_StreamCreateFie, which will allow seeking without holding the entire file in memory. If you would still like to have some file buffering then (eg. if you're reading the file from slow storage media), the BASS_ASYNCFILE flag can be used in the BASS_StreamCreateFileUser call.

kenumir

  • Posts: 5
Re: BASS Android - problem with play long files
« Reply #8 on: 7 Sep '15 - 12:15 »
After testing on a few devices we decided to use:
Code: [Select]
BASS.BASS_SetConfig(BASS_AAC.BASS_CONFIG_AAC_PRESCAN, 0);
« Last Edit: 8 Sep '15 - 07:44 by kenumir »