Skip to content

Commit 644a1fa

Browse files
youennfrobert-jenner
authored andcommitted
Potential 'overflow' issue commited to upstream libwebrtc
rdar://159773684 Reviewed by Jean-Yves Avenard. Cherry-picking of webmproject/libvpx@ba9dad1 * Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/test/encode_api_test.cc: * Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_bitstream.c: * Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_encodeframe.c: (choose_partitioning): * Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_pickmode.c: (vp9_pick_intra_mode): Originally-landed-as: 297297.446@safari-7622-branch (010e247). rdar://164213400 Canonical link: https://commits.webkit.org/302917@main
1 parent 4ec6fc4 commit 644a1fa

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/test/encode_api_test.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,43 @@ TEST(EncodeAPI, Buganizer331108922BitDepth8) {
17431743
encoder.Encode(/*key_frame=*/false);
17441744
}
17451745

1746+
// Encode some frames, flip from BEST_QUALITY to REALTIME after 2 frames.
1747+
// This test is taken from the code snippet in issue:441668134.
1748+
TEST(EncodeAPI, Buganizer441668134) {
1749+
// Get VP9 encoder interface.
1750+
vpx_codec_iface_t *iface = vpx_codec_vp9_cx();
1751+
// Initialize encoder configuration with default values.
1752+
vpx_codec_enc_cfg_t cfg;
1753+
ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK);
1754+
cfg.g_lag_in_frames = 0;
1755+
cfg.rc_max_quantizer = 0;
1756+
unsigned long init_flags = 0;
1757+
vpx_codec_ctx_t ctx;
1758+
ASSERT_EQ(vpx_codec_enc_init(&ctx, iface, &cfg, init_flags), VPX_CODEC_OK);
1759+
ASSERT_EQ(vpx_codec_control_(&ctx, VP8E_SET_CPUUSED, 9), 0);
1760+
ASSERT_EQ(vpx_codec_control_(&ctx, VP9E_SET_DELTA_Q_UV, -15), 0);
1761+
// Image allocation.
1762+
vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
1763+
vpx_image_t *img = vpx_img_alloc(NULL, img_fmt, cfg.g_w, cfg.g_h, 32);
1764+
for (unsigned int y = 0; y < img->d_h; y++) {
1765+
for (unsigned int x = 0; x < img->d_w; x++) {
1766+
img->planes[0][y * img->stride[0] + x] = ((x ^ y) * 127) & 0xFF;
1767+
}
1768+
}
1769+
// Encode some frames.
1770+
int num_frames = 6;
1771+
static constexpr int kChoices[6] = { 1, 1, 0, 0, 0, 0 };
1772+
for (int frame = 0; frame < num_frames; frame++) {
1773+
vpx_enc_deadline_t deadline = VPX_DL_REALTIME;
1774+
uint8_t dl_choice = kChoices[frame];
1775+
if (dl_choice == 1) deadline = VPX_DL_BEST_QUALITY;
1776+
// Encode frame.
1777+
ASSERT_EQ(vpx_codec_encode(&ctx, img, frame, 1, 0, deadline), VPX_CODEC_OK);
1778+
}
1779+
vpx_img_free(img);
1780+
vpx_codec_destroy(&ctx);
1781+
}
1782+
17461783
#if CONFIG_VP9_HIGHBITDEPTH
17471784
TEST(EncodeAPI, Buganizer329674887RowMT0BitDepth12) {
17481785
VP9Encoder encoder(8, 0, VPX_BITS_12, VPX_IMG_FMT_I444);

Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_bitstream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static const struct vp9_token inter_mode_encodings[INTER_MODES] = {
5656

5757
static void write_intra_mode(vpx_writer *w, PREDICTION_MODE mode,
5858
const vpx_prob *probs) {
59+
assert(!is_inter_mode(mode));
5960
vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]);
6061
}
6162

Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_encodeframe.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,13 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
13011301
is_key_frame = 1;
13021302
}
13031303

1304-
// Always use 4x4 partition for key frame.
1305-
const int use_4x4_partition = frame_is_intra_only(cm);
1304+
// Allow for sub8x8 (4x4) partition on key frames, but only for hybrid mode
1305+
// (i.e., sf->nonrd_keyframe = 0), where for small blocks rd intra pickmode
1306+
// (vp9_rd_pick_intra_mode_sb) is used. The nonrd intra pickmode
1307+
// (vp9_pick_intra_mode) does not currently support sub8x8 blocks. This causes
1308+
// the issue: 44166813. Assert is added in vp9_pick_intra_mode to check this.
1309+
const int use_4x4_partition =
1310+
frame_is_intra_only(cm) && !cpi->sf.nonrd_keyframe;
13061311
const int low_res = (cm->width <= 352 && cm->height <= 288);
13071312
int variance4x4downsample[16];
13081313
int segment_id;

Source/ThirdParty/libwebrtc/Source/third_party/libvpx/source/libvpx/vp9/encoder/vp9_pickmode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
11791179
const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
11801180
const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
11811181
bmode_costs = cpi->y_mode_costs[A][L];
1182+
assert(bsize >= BLOCK_8X8);
11821183

11831184
(void)ctx;
11841185
vp9_rd_cost_reset(&best_rdc);

0 commit comments

Comments
 (0)