[fix] check the return value is DAV1D_ERR(EAGAIN) or not for method dav1d_get_picture() and dav1d_send_data()

This commit is contained in:
dijunkun
2024-08-20 17:09:55 +08:00
parent 949aa804e7
commit 6ae12771c2

View File

@@ -60,9 +60,11 @@ int Dav1dAv1Decoder::Init() {
Dav1dSettings s; Dav1dSettings s;
dav1d_default_settings(&s); dav1d_default_settings(&s);
s.n_threads = std::max(2, 4); s.n_threads = std::max(2, 8);
s.max_frame_delay = 1; // For low latency decoding. s.max_frame_delay = 1; // For low latency decoding.
s.all_layers = 0; // Don't output a frame for every spatial layer. s.all_layers = 0; // Don't output a frame for every spatial layer.
// Limit max frame size to avoid OOM'ing fuzzers. crbug.com/325284120.
s.frame_size_limit = 16384 * 16384;
s.operating_point = 31; // Decode all operating points. s.operating_point = 31; // Decode all operating points.
int ret = dav1d_open(&context_, &s); int ret = dav1d_open(&context_, &s);
@@ -115,19 +117,30 @@ int Dav1dAv1Decoder::Decode(
/*user_data=*/nullptr); /*user_data=*/nullptr);
if (int decode_res = dav1d_send_data(context_, &dav1d_data)) { if (int decode_res = dav1d_send_data(context_, &dav1d_data)) {
LOG_ERROR("Dav1dAv1Decoder::Decode decoding failed with error code {}", // On EAGAIN, dav1d can not consume more data and
decode_res); // dav1d_get_picture needs to be called first, which
// will happen below, so just keep going in that case
return -1; // and do not error out.
if (decode_res != DAV1D_ERR(EAGAIN)) {
LOG_ERROR("Dav1dAv1Decoder::Decode decoding failed with error code {}",
decode_res);
return -1;
}
} }
std::shared_ptr<ScopedDav1dPicture> scoped_dav1d_picture( std::shared_ptr<ScopedDav1dPicture> scoped_dav1d_picture(
new ScopedDav1dPicture{}); new ScopedDav1dPicture{});
Dav1dPicture &dav1d_picture = scoped_dav1d_picture->Picture(); Dav1dPicture &dav1d_picture = scoped_dav1d_picture->Picture();
if (int get_picture_res = dav1d_get_picture(context_, &dav1d_picture)) { if (int get_picture_res = dav1d_get_picture(context_, &dav1d_picture)) {
LOG_ERROR("Dav1dDecoder::Decode getting picture failed with error code {}", // On EAGAIN, it means dav1d has not enough data to decode
get_picture_res); // therefore this is not a decoding error but just means
return -1; // we need to feed it more data, which happens in the next
// run of the decoder loop.
if (get_picture_res == DAV1D_ERR(EAGAIN)) {
return -2;
} else {
return -1;
}
} }
if (dav1d_picture.p.bpc != 8) { if (dav1d_picture.p.bpc != 8) {