staticint fuzz_vpx_img_read(vpx_image_t *img, const uint8_t *data,
size_t size) { int plane; // TODO: wtc - Need to clamp the sample values so that they are in range // For example, if the bit depth is 10, the sample values must be <= 1023.
assert(img->bit_depth == 8); const size_t bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
if (size == 0) return0;
size_t used = 0; for (plane = 0; plane < 3; ++plane) { unsignedchar *buf = img->planes[plane]; constint stride = img->stride[plane]; int w = vpx_img_plane_width(img, plane); constint h = vpx_img_plane_height(img, plane); int y;
// Assuming that for nv12 we read all chroma data at once if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; // Fixing NV12 chroma width if it is odd if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = (w + 1) & ~1;
for (y = 0; y < h; ++y) {
size_t nb = bytespp * w; if (nb > size - used) {
nb = size - used;
}
memcpy(buf, data, nb);
memset(buf + nb, 0, bytespp * w - nb);
buf += stride;
data += nb;
used += nb;
}
}
return used;
}
staticint encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, int frame_index, int flags, FILE *out,
vpx_enc_deadline_t quality) { int got_pkts = 0;
vpx_codec_iter_t iter = nullptr; const vpx_codec_cx_pkt_t *pkt = nullptr; const vpx_codec_err_t res =
vpx_codec_encode(codec, img, frame_index, 1, flags, quality); if (res != VPX_CODEC_OK) return0;
if (vpx_codec_enc_init(&codec, VPXC_INTERFACE(ENCODER), &cfg, 0)) { return0;
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 1)) { goto fail;
}
nalloc_start(data, size); // We may want to add more config options (for more complex encoders as seen // in the examples) in the future while still maintaining the same format (so // that generated corpus is still valid). So we reserve FUZZ_HDR_SZ=32 bytes // for this even if we just use one byte so far.
data += FUZZ_HDR_SZ;
size -= FUZZ_HDR_SZ;
// Encode frames. for (int i = 0; i < max_frames; ++i) { int flags = 0;
size_t size_read = fuzz_vpx_img_read(&raw, data, size); if (size_read == 0) break;
data += size_read;
size -= size_read; if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
flags |= VPX_EFLAG_FORCE_KF;
encode_frame(&codec, &raw, frame_count++, flags, out, quality);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.