mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Improve CPU decoder frame latency when rendering speed is less than decoding speed
This commit is contained in:
parent
dc64bfeba2
commit
fa85a0a0bd
@ -69,9 +69,6 @@ int nv_avc_init(int width, int height, int perf_lvl, int thread_count) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show frames even before a reference frame
|
|
||||||
decoder_ctx->flags2 |= CODEC_FLAG2_SHOW_ALL;
|
|
||||||
|
|
||||||
if (perf_lvl & DISABLE_LOOP_FILTER) {
|
if (perf_lvl & DISABLE_LOOP_FILTER) {
|
||||||
// Skip the loop filter for performance reasons
|
// Skip the loop filter for performance reasons
|
||||||
decoder_ctx->skip_loop_filter = AVDISCARD_ALL;
|
decoder_ctx->skip_loop_filter = AVDISCARD_ALL;
|
||||||
@ -370,17 +367,20 @@ int nv_avc_decode(unsigned char* indata, int inlen) {
|
|||||||
|
|
||||||
// Only copy the picture at the end of decoding the packet
|
// Only copy the picture at the end of decoding the packet
|
||||||
if (got_pic) {
|
if (got_pic) {
|
||||||
|
// Clone the current decode frame outside of the mutex
|
||||||
|
AVFrame* new_frame = av_frame_clone(dec_frame);
|
||||||
|
AVFrame* old_frame;
|
||||||
|
|
||||||
|
// Swap it in under lock
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
|
old_frame = yuv_frame;
|
||||||
// Only clone this frame if the last frame was taken.
|
yuv_frame = new_frame;
|
||||||
// This saves on extra copies for frames that don't get
|
|
||||||
// rendered.
|
|
||||||
if (yuv_frame == NULL) {
|
|
||||||
// Clone a new frame
|
|
||||||
yuv_frame = av_frame_clone(dec_frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
|
|
||||||
|
// Free the old frame outside of the mutex
|
||||||
|
if (old_frame != NULL) {
|
||||||
|
av_frame_free(&old_frame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err < 0 ? err : 0;
|
return err < 0 ? err : 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user