Commit 131cab7c authored by hkuang's avatar hkuang

Add error handling when running out of free frame buffers.

Change-Id: If28b59b9521204a6e3aecedcf75932d76a752567
parent 129a25c7
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "./vpx_config.h" #include "./vpx_config.h"
#include "vpx/internal/vpx_codec_internal.h" #include "vpx/internal/vpx_codec_internal.h"
#include "./vp9_rtcd.h" #include "./vp9_rtcd.h"
#include "vp9/common/vp9_alloccommon.h"
#include "vp9/common/vp9_loopfilter.h" #include "vp9/common/vp9_loopfilter.h"
#include "vp9/common/vp9_entropymv.h" #include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_entropy.h"
...@@ -305,8 +306,13 @@ static INLINE int get_free_fb(VP9_COMMON *cm) { ...@@ -305,8 +306,13 @@ static INLINE int get_free_fb(VP9_COMMON *cm) {
if (frame_bufs[i].ref_count == 0) if (frame_bufs[i].ref_count == 0)
break; break;
assert(i < FRAME_BUFFERS); if (i != FRAME_BUFFERS) {
frame_bufs[i].ref_count = 1; frame_bufs[i].ref_count = 1;
} else {
// Reset i to be INVALID_IDX to indicate no free buffer found.
i = INVALID_IDX;
}
unlock_buffer_pool(cm->buffer_pool); unlock_buffer_pool(cm->buffer_pool);
return i; return i;
} }
......
...@@ -212,6 +212,9 @@ vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm, ...@@ -212,6 +212,9 @@ vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
// Find an empty frame buffer. // Find an empty frame buffer.
const int free_fb = get_free_fb(cm); const int free_fb = get_free_fb(cm);
if (cm->new_fb_idx == INVALID_IDX)
return VPX_CODEC_MEM_ERROR;
// Decrease ref_count since it will be increased again in // Decrease ref_count since it will be increased again in
// ref_cnt_fb() below. // ref_cnt_fb() below.
--frame_bufs[free_fb].ref_count; --frame_bufs[free_fb].ref_count;
...@@ -299,7 +302,10 @@ int vp9_receive_compressed_data(VP9Decoder *pbi, ...@@ -299,7 +302,10 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
&& frame_bufs[cm->new_fb_idx].ref_count == 0) && frame_bufs[cm->new_fb_idx].ref_count == 0)
pool->release_fb_cb(pool->cb_priv, pool->release_fb_cb(pool->cb_priv,
&frame_bufs[cm->new_fb_idx].raw_frame_buffer); &frame_bufs[cm->new_fb_idx].raw_frame_buffer);
// Find a free frame buffer. Return error if can not find any.
cm->new_fb_idx = get_free_fb(cm); cm->new_fb_idx = get_free_fb(cm);
if (cm->new_fb_idx == INVALID_IDX)
return VPX_CODEC_MEM_ERROR;
// Assign a MV array to the frame buffer. // Assign a MV array to the frame buffer.
cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
......
...@@ -2714,7 +2714,10 @@ void vp9_scale_references(VP9_COMP *cpi) { ...@@ -2714,7 +2714,10 @@ void vp9_scale_references(VP9_COMP *cpi) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
const int new_fb = get_free_fb(cm); const int new_fb = get_free_fb(cm);
RefCntBuffer *const new_fb_ptr = &pool->frame_bufs[new_fb]; RefCntBuffer *new_fb_ptr = NULL;
if (cm->new_fb_idx == INVALID_IDX)
return;
new_fb_ptr = &pool->frame_bufs[new_fb];
cm->cur_frame = &pool->frame_bufs[new_fb]; cm->cur_frame = &pool->frame_bufs[new_fb];
vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf, vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf,
cm->width, cm->height, cm->width, cm->height,
...@@ -2726,7 +2729,10 @@ void vp9_scale_references(VP9_COMP *cpi) { ...@@ -2726,7 +2729,10 @@ void vp9_scale_references(VP9_COMP *cpi) {
#else #else
if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
const int new_fb = get_free_fb(cm); const int new_fb = get_free_fb(cm);
RefCntBuffer *const new_fb_ptr = &pool->frame_bufs[new_fb]; RefCntBuffer *new_fb_ptr = NULL;
if (cm->new_fb_idx == INVALID_IDX)
return;
new_fb_ptr = &pool->frame_bufs[new_fb];
vp9_realloc_frame_buffer(&new_fb_ptr->buf, vp9_realloc_frame_buffer(&new_fb_ptr->buf,
cm->width, cm->height, cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y, cm->subsampling_x, cm->subsampling_y,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment