android - RTMP adaptive bitrate algorithm -


i searched online there little information this.

i have live broadcasting app send encoded h264 video frames , aac audio chunks resulting camera & mic using android mediacodec sdk, on rtmp stack.

my live streams 720p , aim great quality 2500kbps. requires network connection means 4g if use data plan.

problem greatest connection there low peaks , congestion, there moments network cant hold such heavy stream. because want offer high reliability, want include automatic adaptive bitrate on app image quality dropped in favor or reliability.

the thing -- how achieve automatic adaptation network conditions without losing frames? possible? i've used professional encoding devices cerevo , dont ever lose frames -- app awful dragging due p-frames being lost in network.

this have:

private long adaptbitrate(long idlenanos, frame frame) {         int bytes = frame.getsize();         long nownanos = system.nanotime();         if (nownanos - mlastnanos > 1000l * 1000 * 1000) {             double idle = (double) idlenanos / (double) (nownanos - mlastnanos);             float actualbitrate = newbitrate;              int size = mbuffer.size();             string s = "bitrate: " + actualbitrate / 1000                     + " kbps in-flight:" + bytes                     + " idle: " + idle;             if (size > max_buf_size && size > mlastsize) {                 log.i(tag, "adaptbitrate: dropping bitrate");                 newbitrate = (int) ((double) actualbitrate * bitrate_drop_multiplier);                 if (newbitrate < min_bitrate) {                     newbitrate = min_bitrate;                 }                 s += "   late => " + newbitrate;                 mrtmphandler.requestbitrate(newbitrate);             } else if (size <= 2 && idle > idle_threshold) {                 midleframes++;                 if(midleframes >= min_idle_frames){                     log.i(tag, "adaptbitrate: raising bitrate");                     newbitrate = (int) ((double) newbitrate * bitrate_raise_multiplier);                     if (newbitrate > max_bitrate) {                         newbitrate = max_bitrate;                     }                     s += "   idle => " + newbitrate;                     mrtmphandler.requestbitrate(newbitrate);                     midleframes = 0;                 }             }             debugthread(log.verbose, s);             mlastnanos = system.nanotime();             mlastsize = size;             idlenanos = 0;         }         return idlenanos;     } 

so if buffer exceeding threshold, lower bitrate. if app spending time waiting new frame, number of consecutive frames, raise bitrate.

no matter how cautious threshold values, losing important information , stream breaks until next keyframe arrives (2 secs). seems network can hold bitrate (stable @ 1500kbps, instance) image still have dragging though frame lost in way. network conditions, smooth.

how these streaming devices handle these situations? looks great them, no dragging or skipped frames @ all...


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -