ref: 4d0c2039469c99c4f98f3d0f951603b1f0de1548
parent: c98bbeb3cf7ec6bd2545fdb8704dae87fe7cc117
author: James Almer <[email protected]>
date: Sat Jan 26 13:08:00 EST 2019
replace fprintf uses with dav1d_log()
--- a/src/decode.c
+++ b/src/decode.c
@@ -42,6 +42,7 @@
#include "src/decode.h"
#include "src/dequant_tables.h"
#include "src/env.h"
+#include "src/log.h"
#include "src/qm.h"
#include "src/recon.h"
#include "src/ref.h"
@@ -3089,7 +3090,7 @@
#endif
#undef assign_bitdepth_case
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);
res = -ENOPROTOOPT;
goto error;
@@ -3184,7 +3185,7 @@
c->n_tile_data = 0;
// 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->seq_hdr, f->seq_hdr_ref,
f->frame_hdr, f->frame_hdr_ref,
@@ -3194,7 +3195,7 @@
if (res < 0) goto error;
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;
} else {
dav1d_picture_ref(&f->cur, &f->sr_cur.p);
--- a/src/lib.c
+++ b/src/lib.c
@@ -176,9 +176,9 @@
dav1d_free_aligned(c->fc);
}
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);
}
- fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
return -ENOMEM;
}
@@ -259,7 +259,7 @@
}
// 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) {
dav1d_picture_unref_internal(in);
dav1d_picture_unref_internal(out);
--- a/src/obu.c
+++ b/src/obu.c
@@ -281,7 +281,7 @@
return 0;
error:
- fprintf(stderr, "Error parsing sequence header\n");
+ dav1d_log(c, "Error parsing sequence header\n");
return -EINVAL;
}
@@ -1118,7 +1118,7 @@
return 0;
error:
- fprintf(stderr, "Error parsing frame header\n");
+ dav1d_log(c, "Error parsing frame header\n");
return -EINVAL;
}
@@ -1142,11 +1142,12 @@
// Check that we haven't read more than obu_len bytes from the buffer
// since init_bit_pos.
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
if (gb->error) {
- fprintf(stderr, "Overrun in OBU bit buffer\n");
+ dav1d_log(c, "Overrun in OBU bit buffer\n");
return 1;
}
@@ -1157,7 +1158,7 @@
assert (init_bit_pos <= pos);
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;
}
@@ -1238,7 +1239,7 @@
dav1d_ref_dec(&ref);
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);
return -EINVAL;
}
@@ -1291,7 +1292,7 @@
// This is actually a frame header OBU so read the
// trailing bit and check for overrun.
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;
return -EINVAL;
}
@@ -1323,7 +1324,7 @@
parse_tile_hdr(c, &gb);
// Align to the next byte boundary and check for overrun.
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;
// The current bit position is a multiple of 8 (because we
// just aligned it) and less than 8*pkt_bytelen because
@@ -1355,7 +1356,7 @@
// ignore OBUs we don't care about
break;
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;
}
@@ -1426,6 +1427,6 @@
return len + init_byte_pos;
error:
- fprintf(stderr, "Error parsing OBU data\n");
+ dav1d_log(c, "Error parsing OBU data\n");
return -EINVAL;
}
--- a/src/picture.c
+++ b/src/picture.c
@@ -38,6 +38,7 @@
#include "common/mem.h"
#include "common/validate.h"
+#include "src/log.h"
#include "src/picture.h"
#include "src/ref.h"
#include "src/thread.h"
@@ -59,8 +60,6 @@
uint8_t *data = dav1d_alloc_aligned(pic_size, 32);
if (data == NULL) {
- fprintf(stderr, "Failed to allocate memory of size %zu: %s\n",
- pic_size, strerror(errno));
return -1;
}
@@ -97,7 +96,7 @@
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,
Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
@@ -106,7 +105,7 @@
const size_t extra, void **const extra_ptr)
{
if (p->data[0]) {
- fprintf(stderr, "Picture already allocated!\n");
+ dav1d_log(c, "Picture already allocated!\n");
return -1;
}
assert(bpc > 0 && bpc <= 16);
@@ -135,7 +134,7 @@
if (!(p->ref = dav1d_ref_wrap(p->data[0], free_buffer, pic_ctx))) {
p_allocator->release_picture_callback(p, p_allocator->cookie);
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;
}
@@ -153,7 +152,7 @@
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,
Dav1dSequenceHeader *seq_hdr, Dav1dRef *seq_hdr_ref,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
@@ -164,7 +163,7 @@
p->t = t;
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,
frame_hdr, frame_hdr_ref,
bpc, props, p_allocator,
@@ -180,11 +179,11 @@
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)
{
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->frame_hdr, src->frame_hdr_ref,
src->p.bpc, &src->m, &pic_ctx->allocator,
--- a/src/picture.h
+++ b/src/picture.h
@@ -55,7 +55,7 @@
/*
* 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,
Dav1dFrameHeader *frame_hdr, Dav1dRef *frame_hdr_ref,
int bpc, const Dav1dDataProps *props,
@@ -69,7 +69,7 @@
* For the more typical use case of allocating a new image of the same
* 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);
/**