bilibili / ijkplayer

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.
GNU General Public License v2.0
32.43k stars 8.11k forks source link

Endless preparing on network streams #492

Closed NikmanSergey closed 8 years ago

NikmanSergey commented 8 years ago

Hi! Thanks for the Great library! I have endless preparing on network streams issue. It happens often and after it happened any other network streams hangs on preparing state. Local files still plays OK. You need to restart app to it work again. Tested on different devices. Here is the log when preparing hangs:

D/IJKMEDIA? IjkMediaPlayer_setDataSourceAndHeaders
V/IJKMEDIA? setDataSource: path http://192.168.1.1:10020/udp/239.1.103.2:44328
D/IJKMEDIA? ijkmp_set_data_source(url="http://192.168.1.1:10020/udp/239.1.103.2:44328")
D/IJKMEDIA? ijkmp_set_data_source(url="http://192.168.1.1:10020/udp/239.1.103.2:44328")=0
D/IJKMEDIA? IjkMediaPlayer_prepareAsync
D/IJKMEDIA? ijkmp_prepare_async()
I/IJKMEDIA? ===== options =====
I/IJKMEDIA? player-opts : mediacodec                   = 1
I/IJKMEDIA? player-opts : opensles                     = 0
I/IJKMEDIA? player-opts : framedrop                    = 12
player-opts : start-on-prepared            = 0
format-opts : ijkinject-opaque             = 546309242
I/IJKMEDIA? format-opts : http-detect-range-support    = 0
format-opts : user-agent                   = xxx
I/IJKMEDIA? codec-opts  : skip_loop_filter             = 48
I/IJKMEDIA? ===================
I/IJKMEDIA? SDL_RunThread: [27566] ff_msg_loop
D/IJKMEDIA? message_loop
ijkmp_prepare_async()=0
FFP_MSG_FLUSH:
SDL_RunThread: [27567] ff_vout
ffpipenode_create_video_output_from_android_mediacodec()
SDL_RunThread: [27568] ff_read
D/IJKMEDIA? IjkMediaPlayer_native_finalize
D/IJKMEDIA? IjkMediaPlayer_release
----------------<Preparing process hangs here>----------------

Log when releasing this player:

D/PlayerIjk? Player releasing
D/IJKMEDIA? IjkMediaPlayer_reset
D/IJKMEDIA? IjkMediaPlayer_release
D/IJKMEDIA? ijkmp_set_android_surface(surface=0x0)
D/IJKMEDIA? ffpipeline_set_surface()
D/IJKMEDIA? ijkmp_set_android_surface(surface=0x0)=void
D/IJKMEDIA? ijkmp_shutdown_l()
D/IJKMEDIA? message_loop exit
E/IJKMEDIA? Option http-detect-range-support not found.
W/IJKMEDIA? http://192.168.1.1:10020/udp/239.1.103.2:44328: could not find codec parameters
D/IJKMEDIA? ijkmp_shutdown_l()=void
D/IJKMEDIA? IjkMediaPlayer_native_setup
I/IJKMEDIA? av_version_info: ff2.8--ijk0.3.3--dev0.3.3--rc1
D/IJKMEDIA? ffpipeline_create_from_android()
D/IJKMEDIA? ijkmp_set_inject_opaque(0x1d800556)
D/IJKMEDIA? ijkmp_set_option_int(ijkinject-opaque, 494929238)
D/IJKMEDIA? ijkmp_set_option_int()=void
D/IJKMEDIA? ijkmp_set_inject_opaque()=void
D/IJKMEDIA? ijkmp_android_set_mediacodec_select_callback()
D/IJKMEDIA? ffpipeline_set_mediacodec_select_callback
D/IJKMEDIA? ijkmp_android_set_mediacodec_select_callback()=void
D/IJKMEDIA? ijkmp_dec_ref(): ref=0
D/IJKMEDIA? ijkmp_shutdown_l()
D/IJKMEDIA? ijkmp_shutdown_l()=void
D/IJKMEDIA? IjkMediaPlayer_release
D/IJKMEDIA? ijkmp_set_android_surface(surface=0x0)
D/IJKMEDIA? ffpipeline_set_surface()
D/IJKMEDIA? ijkmp_set_android_surface(surface=0x0)=void
D/IJKMEDIA? ijkmp_shutdown_l()
D/IJKMEDIA? ijkmp_shutdown_l()=void
D/IJKMEDIA? ijkmp_dec_ref(): ref=0
D/IJKMEDIA? ijkmp_shutdown_l()
D/IJKMEDIA? ijkmp_shutdown_l()=void
D/PlayerIjk? Player release finished

Thank you for any help!

bbcallen commented 8 years ago

try set "timeout" in microseconds.

andyjmzheng commented 8 years ago

@NikmanSergey how to set the user-agent in the code.?

thansk

NikmanSergey commented 8 years ago

@andyjmzheng, You can find it by using serach in repositiry 'user-agent': ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "user-agent", "xxx");

andyjmzheng commented 8 years ago

in my project not have the function ijkMediaPlayer.setOption. so i can not set . i want to ask you a question. wo git java code from the github .why my code not have the set url page??@NikmanSergey

qazmoon commented 8 years ago

@andyjmzheng 你这个菜鸟是来捣乱的么?

NikmanSergey commented 8 years ago

@bbcallen, setting "timeout" to 10000 did not help.

After ~20 minutes of playback buffering incrementally becames slower. Until it's completely hangs on buffering stage. It seems, that some network connection remains alive after releasing IjkMediaPlayer. As long as, all other app networking things like loading images becomes very-very slow. Local files still plays OK - so it is networking problem. How can be sure that all network connections closed when releasing player? I do like this:

// Release previous video
mp.stop();
mp.reset();
mp.release();

// Create new instance for next video playback
mp = new IjkMediaPlayer();

Please, help!!! Maybe I can add some debuging prints. It's very important stability issue. Thanks!

qazmoon commented 8 years ago

@NikmanSergey Now is the Mid Autumn Festival and National Day holiday, to wait until October 8th to come back。^_^

bbcallen commented 8 years ago

I am not working on httplive recently. Have a look at libavformat/network.c libavformat/tcp.c libavformat/http.c libavformat/httplive.c

NikmanSergey commented 8 years ago

@bbcallen, I've found that this bug was introduced in k0.4.0 version! k0.3.3 version do not have this issue. It occurs only when playing HLS streams. By monitoring live network connections on my router during HLS playback I see adding new connections every ~6 sec. When connections number grows up to ~100, Android OS do prevent adding new network connections for this app. Stopping and releasing player do not close this connections. So, it can't play any network streams before app restarting.

Also, I could solve the issue by rollback this commit: https://github.com/Bilibili/ijkplayer/commit/2518e04fe59877ff47e799368b6ad550b155c3dd I guess, the bug somewhere in ffmpeg n2.8 (ff2.8--ijk0.3.3--dev0.3.3--rc1). Will this bug be removed at next ffmpeg 2.8 updates? Can you help me find it? Thanks a lot!!!

NikmanSergey commented 8 years ago

@bbcallen, The bug is in hls.c module. Using this file from previous ffmpeg (ijk-r0.2.4-dev) version or from the latest FFMpeg repository works OK. Thanks!