Commit 3cbc26f3 authored by Marco's avatar Marco

vp9-resize: Fix an issue with external dynamic resize.

External dynamic resize with swapping width and height was
not handled properly.
Fix is to re-init loop-filter under certain condtions.

Modify unittest to test this case.
Without this change test will fail.

Relates to: https://bugs.chromium.org/p/webm/issues/detail?id=1140

Change-Id: I7d81ca7fe0783b3bc103a52a7b7cf073a96be26e
parent 34d12d11
...@@ -90,74 +90,178 @@ struct FrameInfo { ...@@ -90,74 +90,178 @@ struct FrameInfo {
unsigned int h; unsigned int h;
}; };
unsigned int ScaleForFrameNumber(unsigned int frame, unsigned int val) { void ScaleForFrameNumber(unsigned int frame,
if (frame < 10) unsigned int initial_w,
return val; unsigned int initial_h,
if (frame < 20) unsigned int *w,
return val * 3 / 4; unsigned int *h,
if (frame < 30) int flag_codec) {
return val / 2; if (frame < 10) {
if (frame < 40) *w = initial_w;
return val; *h = initial_h;
if (frame < 50) return;
return val * 3 / 4; }
if (frame < 60) if (frame < 20) {
return val / 2; *w = initial_w * 3 / 4;
if (frame < 70) *h = initial_h * 3 / 4;
return val * 3 / 4; return;
if (frame < 80) }
return val; if (frame < 30) {
if (frame < 90) *w = initial_w / 2;
return val * 3 / 4; *h = initial_h / 2;
if (frame < 100) return;
return val / 2; }
if (frame < 110) if (frame < 40) {
return val * 3 / 4; *w = initial_w;
if (frame < 120) *h = initial_h;
return val; return;
if (frame < 130) }
return val * 3 / 4; if (frame < 50) {
if (frame < 140) *w = initial_w * 3 / 4;
return val / 2; *h = initial_h * 3 / 4;
if (frame < 150) return;
return val * 3 / 4; }
if (frame < 160) if (frame < 60) {
return val; *w = initial_w / 2;
if (frame < 170) *h = initial_h / 2;
return val / 2; return;
if (frame < 180) }
return val * 3 / 4; if (frame < 70) {
if (frame < 190) *w = initial_w;
return val; *h = initial_h;
if (frame < 200) return;
return val * 3 / 4; }
if (frame < 210) if (frame < 80) {
return val / 2; *w = initial_w * 3 / 4;
if (frame < 220) *h = initial_h * 3 / 4;
return val * 3 / 4; return;
if (frame < 230) }
return val; if (frame < 90) {
if (frame < 240) *w = initial_w / 2;
return val / 2; *h = initial_h / 2;
if (frame < 250) return;
return val * 3 / 4; }
return val; if (frame < 100) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 110) {
*w = initial_w;
*h = initial_h;
return;
}
if (frame < 120) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 130) {
*w = initial_w / 2;
*h = initial_h / 2;
return;
}
if (frame < 140) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 150) {
*w = initial_w;
*h = initial_h;
return;
}
if (frame < 160) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 170) {
*w = initial_w / 2;
*h = initial_h / 2;
return;
}
if (frame < 180) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 190) {
*w = initial_w;
*h = initial_h;
return;
}
if (frame < 200) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 210) {
*w = initial_w / 2;
*h = initial_h / 2;
return;
}
if (frame < 220) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 230) {
*w = initial_w;
*h = initial_h;
return;
}
if (frame < 240) {
*w = initial_w * 3 / 4;
*h = initial_h * 3 / 4;
return;
}
if (frame < 250) {
*w = initial_w / 2;
*h = initial_h / 2;
return;
}
if (frame < 260) {
*w = initial_w;
*h = initial_h;
return;
}
// Go down very low.
if (frame < 270) {
*w = initial_w / 4;
*h = initial_h / 4;
return;
}
if (flag_codec == 1) {
// Cases that only works for VP9.
// For VP9: Swap width and height of original.
if (frame < 320) {
*w = initial_h;
*h = initial_w;
return;
}
}
*w = initial_w;
*h = initial_h;
} }
class ResizingVideoSource : public ::libvpx_test::DummyVideoSource { class ResizingVideoSource : public ::libvpx_test::DummyVideoSource {
public: public:
ResizingVideoSource() { ResizingVideoSource() {
SetSize(kInitialWidth, kInitialHeight); SetSize(kInitialWidth, kInitialHeight);
limit_ = 300; limit_ = 350;
} }
int flag_codec_;
virtual ~ResizingVideoSource() {} virtual ~ResizingVideoSource() {}
protected: protected:
virtual void Next() { virtual void Next() {
++frame_; ++frame_;
SetSize(ScaleForFrameNumber(frame_, kInitialWidth), unsigned int width;
ScaleForFrameNumber(frame_, kInitialHeight)); unsigned int height;
ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, &width, &height,
flag_codec_);
SetSize(width, height);
FillFrame(); FillFrame();
} }
}; };
...@@ -184,15 +288,17 @@ class ResizeTest : public ::libvpx_test::EncoderTest, ...@@ -184,15 +288,17 @@ class ResizeTest : public ::libvpx_test::EncoderTest,
TEST_P(ResizeTest, TestExternalResizeWorks) { TEST_P(ResizeTest, TestExternalResizeWorks) {
ResizingVideoSource video; ResizingVideoSource video;
video.flag_codec_ = 0;
cfg_.g_lag_in_frames = 0; cfg_.g_lag_in_frames = 0;
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
info != frame_info_list_.end(); ++info) { info != frame_info_list_.end(); ++info) {
const unsigned int frame = static_cast<unsigned>(info->pts); const unsigned int frame = static_cast<unsigned>(info->pts);
const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); unsigned int expected_w;
const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); unsigned int expected_h;
ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
&expected_w, &expected_h, 0);
EXPECT_EQ(expected_w, info->w) EXPECT_EQ(expected_w, info->w)
<< "Frame " << frame << " had unexpected width"; << "Frame " << frame << " had unexpected width";
EXPECT_EQ(expected_h, info->h) EXPECT_EQ(expected_h, info->h)
...@@ -386,6 +492,7 @@ class ResizeRealtimeTest : public ::libvpx_test::EncoderTest, ...@@ -386,6 +492,7 @@ class ResizeRealtimeTest : public ::libvpx_test::EncoderTest,
TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) { TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) {
ResizingVideoSource video; ResizingVideoSource video;
video.flag_codec_ = 1;
DefaultConfig(); DefaultConfig();
// Disable internal resize for this test. // Disable internal resize for this test.
cfg_.rc_resize_allowed = 0; cfg_.rc_resize_allowed = 0;
...@@ -395,9 +502,10 @@ TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) { ...@@ -395,9 +502,10 @@ TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) {
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
info != frame_info_list_.end(); ++info) { info != frame_info_list_.end(); ++info) {
const unsigned int frame = static_cast<unsigned>(info->pts); const unsigned int frame = static_cast<unsigned>(info->pts);
const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); unsigned int expected_w;
const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); unsigned int expected_h;
ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
&expected_w, &expected_h, 1);
EXPECT_EQ(expected_w, info->w) EXPECT_EQ(expected_w, info->w)
<< "Frame " << frame << " had unexpected width"; << "Frame " << frame << " had unexpected width";
EXPECT_EQ(expected_h, info->h) EXPECT_EQ(expected_h, info->h)
......
...@@ -119,6 +119,20 @@ void vp9_free_context_buffers(VP9_COMMON *cm) { ...@@ -119,6 +119,20 @@ void vp9_free_context_buffers(VP9_COMMON *cm) {
cm->lf.lfm = NULL; cm->lf.lfm = NULL;
} }
int vp9_alloc_loop_filter(VP9_COMMON *cm) {
vpx_free(cm->lf.lfm);
// Each lfm holds bit masks for all the 8x8 blocks in a 64x64 region. The
// stride and rows are rounded up / truncated to a multiple of 8.
cm->lf.lfm_stride = (cm->mi_cols + (MI_BLOCK_SIZE - 1)) >> 3;
cm->lf.lfm = (LOOP_FILTER_MASK *)vpx_calloc(
((cm->mi_rows + (MI_BLOCK_SIZE - 1)) >> 3) * cm->lf.lfm_stride,
sizeof(*cm->lf.lfm));
if (!cm->lf.lfm)
return 1;
return 0;
}
int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
int new_mi_size; int new_mi_size;
...@@ -151,15 +165,8 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { ...@@ -151,15 +165,8 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
cm->above_context_alloc_cols = cm->mi_cols; cm->above_context_alloc_cols = cm->mi_cols;
} }
vpx_free(cm->lf.lfm); if (vp9_alloc_loop_filter(cm))
goto fail;
// Each lfm holds bit masks for all the 8x8 blocks in a 64x64 region. The
// stride and rows are rounded up / truncated to a multiple of 8.
cm->lf.lfm_stride = (cm->mi_cols + (MI_BLOCK_SIZE - 1)) >> 3;
cm->lf.lfm = (LOOP_FILTER_MASK *)vpx_calloc(
((cm->mi_rows + (MI_BLOCK_SIZE - 1)) >> 3) * cm->lf.lfm_stride,
sizeof(*cm->lf.lfm));
if (!cm->lf.lfm) goto fail;
return 0; return 0;
......
...@@ -23,6 +23,7 @@ struct BufferPool; ...@@ -23,6 +23,7 @@ struct BufferPool;
void vp9_remove_common(struct VP9Common *cm); void vp9_remove_common(struct VP9Common *cm);
int vp9_alloc_loop_filter(struct VP9Common *cm);
int vp9_alloc_context_buffers(struct VP9Common *cm, int width, int height); int vp9_alloc_context_buffers(struct VP9Common *cm, int width, int height);
void vp9_init_context_buffers(struct VP9Common *cm); void vp9_init_context_buffers(struct VP9Common *cm);
void vp9_free_context_buffers(struct VP9Common *cm); void vp9_free_context_buffers(struct VP9Common *cm);
......
...@@ -1538,8 +1538,12 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { ...@@ -1538,8 +1538,12 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
realloc_segmentation_maps(cpi); realloc_segmentation_maps(cpi);
cpi->initial_width = cpi->initial_height = 0; cpi->initial_width = cpi->initial_height = 0;
cpi->external_resize = 0; cpi->external_resize = 0;
} else if (cm->mi_alloc_size == new_mi_size &&
(cpi->oxcf.width > last_w || cpi->oxcf.height > last_h)) {
vp9_alloc_loop_filter(cm);
} }
} }
update_frame_size(cpi); update_frame_size(cpi);
if ((last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) && if ((last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) &&
......
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