replace fprintf uses with dav1d_log()

parent c98bbeb3
Pipeline #4162 passed with stages
in 5 minutes and 32 seconds
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "src/decode.h" #include "src/decode.h"
#include "src/dequant_tables.h" #include "src/dequant_tables.h"
#include "src/env.h" #include "src/env.h"
#include "src/log.h"
#include "src/qm.h" #include "src/qm.h"
#include "src/recon.h" #include "src/recon.h"
#include "src/ref.h" #include "src/ref.h"
...@@ -3089,7 +3090,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3089,7 +3090,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
#endif #endif
#undef assign_bitdepth_case #undef assign_bitdepth_case
default: default:
fprintf(stderr, "Compiled without support for %d-bit decoding\n", dav1d_log(c, "Compiled without support for %d-bit decoding\n",
8 + 2 * f->seq_hdr->hbd); 8 + 2 * f->seq_hdr->hbd);
res = -ENOPROTOOPT; res = -ENOPROTOOPT;
goto error; goto error;
...@@ -3184,7 +3185,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3184,7 +3185,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
c->n_tile_data = 0; c->n_tile_data = 0;
// allocate frame // allocate frame
res = dav1d_thread_picture_alloc(&f->sr_cur, f->frame_hdr->width[1], res = dav1d_thread_picture_alloc(c, &f->sr_cur, f->frame_hdr->width[1],
f->frame_hdr->height, f->frame_hdr->height,
f->seq_hdr, f->seq_hdr_ref, f->seq_hdr, f->seq_hdr_ref,
f->frame_hdr, f->frame_hdr_ref, f->frame_hdr, f->frame_hdr_ref,
...@@ -3194,7 +3195,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3194,7 +3195,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
if (res < 0) goto error; if (res < 0) goto error;
if (f->frame_hdr->super_res.enabled) { if (f->frame_hdr->super_res.enabled) {
res = dav1d_picture_alloc_copy(&f->cur, f->frame_hdr->width[0], &f->sr_cur.p); res = dav1d_picture_alloc_copy(c, &f->cur, f->frame_hdr->width[0], &f->sr_cur.p);
if (res < 0) goto error; if (res < 0) goto error;
} else { } else {
dav1d_picture_ref(&f->cur, &f->sr_cur.p); dav1d_picture_ref(&f->cur, &f->sr_cur.p);
......
...@@ -176,9 +176,9 @@ error: ...@@ -176,9 +176,9 @@ error:
dav1d_free_aligned(c->fc); dav1d_free_aligned(c->fc);
} }
if (c->n_fc > 1) free(c->frame_thread.out_delayed); if (c->n_fc > 1) free(c->frame_thread.out_delayed);
dav1d_log(c, "Failed to allocate memory: %s\n", strerror(errno));
dav1d_freep_aligned(c_out); dav1d_freep_aligned(c_out);
} }
fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
return -ENOMEM; return -ENOMEM;
} }
...@@ -259,7 +259,7 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out, ...@@ -259,7 +259,7 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out,
} }
// Apply film grain to a new copy of the image to avoid corrupting refs // Apply film grain to a new copy of the image to avoid corrupting refs
int res = dav1d_picture_alloc_copy(out, in->p.w, in); int res = dav1d_picture_alloc_copy(c, out, in->p.w, in);
if (res < 0) { if (res < 0) {
dav1d_picture_unref_internal(in); dav1d_picture_unref_internal(in);
dav1d_picture_unref_internal(out); dav1d_picture_unref_internal(out);
......
...@@ -281,7 +281,7 @@ static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb, ...@@ -281,7 +281,7 @@ static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb,
return 0; return 0;
error: error:
fprintf(stderr, "Error parsing sequence header\n"); dav1d_log(c, "Error parsing sequence header\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1118,7 +1118,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -1118,7 +1118,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
return 0; return 0;
error: error:
fprintf(stderr, "Error parsing frame header\n"); dav1d_log(c, "Error parsing frame header\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1142,11 +1142,12 @@ static void parse_tile_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -1142,11 +1142,12 @@ static void parse_tile_hdr(Dav1dContext *const c, GetBits *const gb) {
// Check that we haven't read more than obu_len bytes from the buffer // Check that we haven't read more than obu_len bytes from the buffer
// since init_bit_pos. // since init_bit_pos.
static int static int
check_for_overrun(GetBits *const gb, unsigned init_bit_pos, unsigned obu_len) check_for_overrun(Dav1dContext *const c, GetBits *const gb,
unsigned init_bit_pos, unsigned obu_len)
{ {
// Make sure we haven't actually read past the end of the gb buffer // Make sure we haven't actually read past the end of the gb buffer
if (gb->error) { if (gb->error) {
fprintf(stderr, "Overrun in OBU bit buffer\n"); dav1d_log(c, "Overrun in OBU bit buffer\n");
return 1; return 1;
} }
...@@ -1157,7 +1158,7 @@ check_for_overrun(GetBits *const gb, unsigned init_bit_pos, unsigned obu_len) ...@@ -1157,7 +1158,7 @@ check_for_overrun(GetBits *const gb, unsigned init_bit_pos, unsigned obu_len)
assert (init_bit_pos <= pos); assert (init_bit_pos <= pos);
if (pos - init_bit_pos > 8 * obu_len) { if (pos - init_bit_pos > 8 * obu_len) {
fprintf(stderr, "Overrun in OBU bit buffer into next OBU\n"); dav1d_log(c, "Overrun in OBU bit buffer into next OBU\n");
return 1; return 1;
} }
...@@ -1238,7 +1239,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1238,7 +1239,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
dav1d_ref_dec(&ref); dav1d_ref_dec(&ref);
return res; return res;
} }
if (check_for_overrun(&gb, init_bit_pos, len)) { if (check_for_overrun(c, &gb, init_bit_pos, len)) {
dav1d_ref_dec(&ref); dav1d_ref_dec(&ref);
return -EINVAL; return -EINVAL;
} }
...@@ -1291,7 +1292,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1291,7 +1292,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
// This is actually a frame header OBU so read the // This is actually a frame header OBU so read the
// trailing bit and check for overrun. // trailing bit and check for overrun.
dav1d_get_bits(&gb, 1); dav1d_get_bits(&gb, 1);
if (check_for_overrun(&gb, init_bit_pos, len)) { if (check_for_overrun(c, &gb, init_bit_pos, len)) {
c->frame_hdr = NULL; c->frame_hdr = NULL;
return -EINVAL; return -EINVAL;
} }
...@@ -1323,7 +1324,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1323,7 +1324,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
parse_tile_hdr(c, &gb); parse_tile_hdr(c, &gb);
// Align to the next byte boundary and check for overrun. // Align to the next byte boundary and check for overrun.
dav1d_bytealign_get_bits(&gb); dav1d_bytealign_get_bits(&gb);
if (check_for_overrun(&gb, init_bit_pos, len)) if (check_for_overrun(c, &gb, init_bit_pos, len))
return -EINVAL; return -EINVAL;
// The current bit position is a multiple of 8 (because we // The current bit position is a multiple of 8 (because we
// just aligned it) and less than 8*pkt_bytelen because // just aligned it) and less than 8*pkt_bytelen because
...@@ -1355,7 +1356,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1355,7 +1356,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
// ignore OBUs we don't care about // ignore OBUs we don't care about
break; break;
default: default:
fprintf(stderr, "Unknown OBU type %d of size %u\n", type, len); dav1d_log(c, "Unknown OBU type %d of size %u\n", type, len);
return -EINVAL; return -EINVAL;
} }
...@@ -1426,6 +1427,6 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1426,6 +1427,6 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
return len + init_byte_pos; return len + init_byte_pos;
error: error:
fprintf(stderr, "Error parsing OBU data\n"); dav1d_log(c, "Error parsing OBU data\n");
return -EINVAL; return -EINVAL;
} }
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "common/mem.h" #include "common/mem.h"
#include "common/validate.h" #include "common/validate.h"
#include "src/log.h"
#include "src/picture.h" #include "src/picture.h"
#include "src/ref.h" #include "src/ref.h"
#include "src/thread.h" #include "src/thread.h"
...@@ -59,8 +60,6 @@ int default_picture_allocator(Dav1dPicture *const p, void *cookie) { ...@@ -59,8 +60,6 @@ int default_picture_allocator(Dav1dPicture *const p, void *cookie) {
uint8_t *data = dav1d_alloc_aligned(pic_size, 32); uint8_t *data = dav1d_alloc_aligned(pic_size, 32);
if (data == NULL) { if (data == NULL) {
fprintf(stderr, "Failed to allocate memory of size %zu: %s\n",
pic_size, strerror(errno));
return -1; return -1;
} }
...@@ -97,7 +96,7 @@ static void free_buffer(const uint8_t *const data, void *const user_data) { ...@@ -97,7 +96,7 @@ static void free_buffer(const uint8_t *const data, void *const user_data) {
free(pic_ctx); free(pic_ctx);
} }
static int picture_alloc_with_edges(Dav1dPicture *const p, static int picture_alloc_with_edges(Dav1dContext *const c, Dav1dPicture *const p,
const int w, const int h, const int w, const int h,
Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref, Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref, Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
...@@ -106,7 +105,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p, ...@@ -106,7 +105,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p,
const size_t extra, void **const extra_ptr) const size_t extra, void **const extra_ptr)
{ {
if (p->data[0]) { if (p->data[0]) {
fprintf(stderr, "Picture already allocated!\n"); dav1d_log(c, "Picture already allocated!\n");
return -1; return -1;
} }
assert(bpc > 0 && bpc <= 16); assert(bpc > 0 && bpc <= 16);
...@@ -135,7 +134,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p, ...@@ -135,7 +134,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p,
if (!(p->ref = dav1d_ref_wrap(p->data[0], free_buffer, pic_ctx))) { if (!(p->ref = dav1d_ref_wrap(p->data[0], free_buffer, pic_ctx))) {
p_allocator->release_picture_callback(p, p_allocator->cookie); p_allocator->release_picture_callback(p, p_allocator->cookie);
free(pic_ctx); free(pic_ctx);
fprintf(stderr, "Failed to wrap picture: %s\n", strerror(errno)); dav1d_log(c, "Failed to wrap picture: %s\n", strerror(errno));
return -ENOMEM; return -ENOMEM;
} }
...@@ -153,7 +152,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p, ...@@ -153,7 +152,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p,
return 0; return 0;
} }
int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p, int dav1d_thread_picture_alloc(Dav1dContext *const c, Dav1dThreadPicture *const p,
const int w, const int h, const int w, const int h,
Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref, Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref, Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
...@@ -164,7 +163,7 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p, ...@@ -164,7 +163,7 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
p->t = t; p->t = t;
const int res = const int res =
picture_alloc_with_edges(&p->p, w, h, picture_alloc_with_edges(c, &p->p, w, h,
seq_hdr, seq_hdr_ref, seq_hdr, seq_hdr_ref,
frame_hdr, frame_hdr_ref, frame_hdr, frame_hdr_ref,
bpc, props, p_allocator, bpc, props, p_allocator,
...@@ -180,11 +179,11 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p, ...@@ -180,11 +179,11 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
return res; return res;
} }
int dav1d_picture_alloc_copy(Dav1dPicture *const dst, const int w, int dav1d_picture_alloc_copy(Dav1dContext *const c, Dav1dPicture *const dst, const int w,
const Dav1dPicture *const src) const Dav1dPicture *const src)
{ {
struct pic_ctx_context *const pic_ctx = src->ref->user_data; struct pic_ctx_context *const pic_ctx = src->ref->user_data;
const int res = picture_alloc_with_edges(dst, w, src->p.h, const int res = picture_alloc_with_edges(c, dst, w, src->p.h,
src->seq_hdr, src->seq_hdr_ref, src->seq_hdr, src->seq_hdr_ref,
src->frame_hdr, src->frame_hdr_ref, src->frame_hdr, src->frame_hdr_ref,
src->p.bpc, &src->m, &pic_ctx->allocator, src->p.bpc, &src->m, &pic_ctx->allocator,
......
...@@ -55,7 +55,7 @@ typedef struct Dav1dThreadPicture { ...@@ -55,7 +55,7 @@ typedef struct Dav1dThreadPicture {
/* /*
* Allocate a picture with custom border size. * Allocate a picture with custom border size.
*/ */
int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h, int dav1d_thread_picture_alloc(Dav1dContext *c, Dav1dThreadPicture *p, int w, int h,
Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref, Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref, Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
int bpc, const Dav1dDataProps *props, int bpc, const Dav1dDataProps *props,
...@@ -69,7 +69,7 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h, ...@@ -69,7 +69,7 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h,
* For the more typical use case of allocating a new image of the same * For the more typical use case of allocating a new image of the same
* dimensions, use src->p.w as width. * dimensions, use src->p.w as width.
*/ */
int dav1d_picture_alloc_copy(Dav1dPicture *dst, const int w, int dav1d_picture_alloc_copy(Dav1dContext *c, Dav1dPicture *dst, const int w,
const Dav1dPicture *src); const Dav1dPicture *src);
/** /**
......
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