[FFmpeg-cvslog] avcodec: Don't log to private context
Andreas Rheinhardt
git at videolan.org
Sat Mar 8 02:14:41 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Mar 5 01:27:29 2025 +0100| [39286d97f259a9b9666520ff1f9bdff6561f7e3c] | committer: Andreas Rheinhardt
avcodec: Don't log to private context
While it is save for these codecs (they all have private contexts),
it is customary to always use the AVCodecContext for logging.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=39286d97f259a9b9666520ff1f9bdff6561f7e3c
---
libavcodec/ccaption_dec.c | 21 ++++++++++++---------
libavcodec/dvdsubdec.c | 34 +++++++++++++++++-----------------
libavcodec/h264_refs.c | 2 +-
libavcodec/h264_slice.c | 2 +-
libavcodec/j2kenc.c | 2 +-
libavcodec/motion_est.c | 4 ++--
libavcodec/mpegvideo_enc.c | 2 +-
libavcodec/msmpeg4enc.c | 2 +-
libavcodec/ratecontrol.c | 12 ++++++------
libavcodec/x86/mpegvideoenc_template.c | 2 +-
10 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index d8b992bb94..01bdc4d537 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -253,6 +253,7 @@ struct Screen {
typedef struct CCaptionSubContext {
AVClass *class;
+ void *logctx;
int real_time;
int real_time_latency_msec;
int data_field;
@@ -280,6 +281,8 @@ static av_cold int init_decoder(AVCodecContext *avctx)
{
CCaptionSubContext *ctx = avctx->priv_data;
+ ctx->logctx = avctx;
+
av_bprint_init(&ctx->buffer[0], 0, AV_BPRINT_SIZE_UNLIMITED);
av_bprint_init(&ctx->buffer[1], 0, AV_BPRINT_SIZE_UNLIMITED);
/* taking by default roll up to 2 */
@@ -359,7 +362,7 @@ static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
return;
}
else {
- av_log(ctx, AV_LOG_WARNING, "Data ignored due to columns exceeding screen width\n");
+ av_log(ctx->logctx, AV_LOG_WARNING, "Data ignored due to columns exceeding screen width\n");
return;
}
}
@@ -649,7 +652,7 @@ static void handle_pac(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
int indent, i;
if (row_map[index] <= 0) {
- av_log(ctx, AV_LOG_DEBUG, "Invalid pac index encountered\n");
+ av_log(ctx->logctx, AV_LOG_DEBUG, "Invalid pac index encountered\n");
return;
}
@@ -749,9 +752,9 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo)
ctx->screen_touched = 1;
if (lo)
- ff_dlog(ctx, "(%c,%c)\n", hi, lo);
+ ff_dlog(ctx->logctx, "(%c,%c)\n", hi, lo);
else
- ff_dlog(ctx, "(%c)\n", hi);
+ ff_dlog(ctx->logctx, "(%c)\n", hi);
}
static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
@@ -803,7 +806,7 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
break;
case 0x2d:
/* carriage return */
- ff_dlog(ctx, "carriage return\n");
+ ff_dlog(ctx->logctx, "carriage return\n");
if (!ctx->real_time)
ret = capture_screen(ctx);
roll_up(ctx);
@@ -820,11 +823,11 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
break;
case 0x2f:
/* end of caption */
- ff_dlog(ctx, "handle_eoc\n");
+ ff_dlog(ctx->logctx, "handle_eoc\n");
ret = handle_eoc(ctx);
break;
default:
- ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
+ ff_dlog(ctx->logctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
break;
}
} else if (hi >= 0x11 && hi <= 0x13) {
@@ -842,7 +845,7 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
}
} else {
/* Ignoring all other non data code */
- ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
+ ff_dlog(ctx->logctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
}
return ret;
@@ -888,7 +891,7 @@ static int decode(AVCodecContext *avctx, AVSubtitle *sub,
update_time(ctx, in_time);
if (ctx->buffer[bidx].str[0] || ctx->real_time) {
- ff_dlog(ctx, "cdp writing data (%s)\n", ctx->buffer[bidx].str);
+ ff_dlog(avctx, "cdp writing data (%s)\n", ctx->buffer[bidx].str);
start_time = ctx->buffer_time[0];
sub->pts = start_time;
end_time = ctx->buffer_time[1];
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index f8769353a0..78658f7d2f 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -217,8 +217,8 @@ static void reset_rects(AVSubtitle *sub_header)
#define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
-static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
- const uint8_t *buf, int buf_size)
+static int decode_dvd_subtitles(void *logctx, DVDSubContext *ctx,
+ AVSubtitle *sub_header, const uint8_t *buf, int buf_size)
{
int cmd_pos, pos, cmd, x1, y1, x2, y2, next_cmd_pos;
int big_offsets, offset_size, is_8bit = 0;
@@ -248,7 +248,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
if (cmd_pos < 0 || cmd_pos > buf_size - 2 - offset_size) {
if (cmd_pos > size) {
- av_log(ctx, AV_LOG_ERROR, "Discarding invalid packet\n");
+ av_log(logctx, AV_LOG_ERROR, "Discarding invalid packet\n");
return 0;
}
return AVERROR(EAGAIN);
@@ -257,7 +257,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
date = AV_RB16(buf + cmd_pos);
next_cmd_pos = READ_OFFSET(buf + cmd_pos + 2);
- ff_dlog(NULL, "cmd_pos=0x%04x next=0x%04x date=%d\n",
+ ff_dlog(logctx, "cmd_pos=0x%04x next=0x%04x date=%d\n",
cmd_pos, next_cmd_pos, date);
pos = cmd_pos + 2 + offset_size;
offset1 = -1;
@@ -265,7 +265,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
x1 = y1 = x2 = y2 = 0;
while (pos < buf_size) {
cmd = buf[pos++];
- ff_dlog(NULL, "cmd=%02x\n", cmd);
+ ff_dlog(logctx, "cmd=%02x\n", cmd);
switch(cmd) {
case 0x00:
/* menu subpicture */
@@ -298,7 +298,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
alpha[1] = buf[pos + 1] >> 4;
alpha[0] = buf[pos + 1] & 0x0f;
pos += 2;
- ff_dlog(NULL, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
+ ff_dlog(logctx, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
break;
case 0x05:
case 0x85:
@@ -310,7 +310,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
if (cmd & 0x80)
is_8bit = 1;
- ff_dlog(NULL, "x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
+ ff_dlog(logctx, "x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
pos += 6;
break;
case 0x06:
@@ -318,7 +318,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
goto fail;
offset1 = AV_RB16(buf + pos);
offset2 = AV_RB16(buf + pos + 2);
- ff_dlog(NULL, "offset1=0x%04"PRIx64" offset2=0x%04"PRIx64"\n", offset1, offset2);
+ ff_dlog(logctx, "offset1=0x%04"PRIx64" offset2=0x%04"PRIx64"\n", offset1, offset2);
pos += 4;
break;
case 0x86:
@@ -326,7 +326,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
goto fail;
offset1 = AV_RB32(buf + pos);
offset2 = AV_RB32(buf + pos + 4);
- ff_dlog(NULL, "offset1=0x%04"PRIx64" offset2=0x%04"PRIx64"\n", offset1, offset2);
+ ff_dlog(logctx, "offset1=0x%04"PRIx64" offset2=0x%04"PRIx64"\n", offset1, offset2);
pos += 8;
break;
@@ -349,7 +349,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
case 0xff:
goto the_end;
default:
- ff_dlog(NULL, "unrecognised subpicture command 0x%x\n", cmd);
+ ff_dlog(logctx, "unrecognised subpicture command 0x%x\n", cmd);
goto the_end;
}
}
@@ -412,7 +412,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
}
}
if (next_cmd_pos < cmd_pos) {
- av_log(ctx, AV_LOG_ERROR, "Invalid command offset\n");
+ av_log(logctx, AV_LOG_ERROR, "Invalid command offset\n");
break;
}
if (next_cmd_pos == cmd_pos)
@@ -535,7 +535,7 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub,
appended = 1;
}
- is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);
+ is_menu = decode_dvd_subtitles(avctx, ctx, sub, buf, buf_size);
if (is_menu == AVERROR(EAGAIN)) {
*data_size = 0;
return appended ? 0 : append_to_cached_buf(avctx, buf, buf_size);
@@ -560,7 +560,7 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub,
return buf_size;
}
-static int parse_ifo_palette(DVDSubContext *ctx, char *p)
+static int parse_ifo_palette(void *logctx, DVDSubContext *ctx, char *p)
{
FILE *ifo;
char ifostr[12];
@@ -572,11 +572,11 @@ static int parse_ifo_palette(DVDSubContext *ctx, char *p)
ctx->has_palette = 0;
if ((ifo = avpriv_fopen_utf8(p, "r")) == NULL) {
- av_log(ctx, AV_LOG_WARNING, "Unable to open IFO file \"%s\": %s\n", p, av_err2str(AVERROR(errno)));
+ av_log(logctx, AV_LOG_WARNING, "Unable to open IFO file \"%s\": %s\n", p, av_err2str(AVERROR(errno)));
return AVERROR_EOF;
}
if (fread(ifostr, 12, 1, ifo) != 1 || memcmp(ifostr, "DVDVIDEO-VTS", 12)) {
- av_log(ctx, AV_LOG_WARNING, "\"%s\" is not a proper IFO file\n", p);
+ av_log(logctx, AV_LOG_WARNING, "\"%s\" is not a proper IFO file\n", p);
ret = AVERROR_INVALIDDATA;
goto end;
}
@@ -612,7 +612,7 @@ static int parse_ifo_palette(DVDSubContext *ctx, char *p)
}
}
if (ctx->has_palette == 0) {
- av_log(ctx, AV_LOG_WARNING, "Failed to read palette from IFO file \"%s\"\n", p);
+ av_log(logctx, AV_LOG_WARNING, "Failed to read palette from IFO file \"%s\"\n", p);
ret = AVERROR_INVALIDDATA;
}
end:
@@ -670,7 +670,7 @@ static av_cold int dvdsub_init(AVCodecContext *avctx)
return ret;
if (ctx->ifo_str)
- parse_ifo_palette(ctx, ctx->ifo_str);
+ parse_ifo_palette(avctx, ctx, ctx->ifo_str);
if (ctx->palette_str) {
ctx->has_palette = 1;
ff_dvdsub_parse_palette(ctx->palette, ctx->palette_str);
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 5eb2855065..050ca92292 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -409,7 +409,7 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl)
if (h->default_ref[list2].parent && !h->default_ref[list2].parent->gray
&& !(!FIELD_PICTURE(h) && (h->default_ref[list2].reference&3) != 3)) {
sl->ref_list[list][index] = h->default_ref[list2];
- av_log(h, AV_LOG_DEBUG, "replacement of gray gap frame\n");
+ av_log(h->avctx, AV_LOG_DEBUG, "replacement of gray gap frame\n");
break;
}
}
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index cb22b76730..726a56d004 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -2100,7 +2100,7 @@ int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)
if (ret < 0)
return ret;
} else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == H264_NAL_IDR_SLICE) {
- av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n");
+ av_log(h->avctx, AV_LOG_WARNING, "Broken frame packetizing\n");
ret = ff_h264_field_end(h, h->slice_ctx, 1);
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 60cc0f3093..b7a213af34 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1726,7 +1726,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
s->avctx = avctx;
av_log(s->avctx, AV_LOG_DEBUG, "init\n");
if (parse_layer_rates(s)) {
- av_log(s, AV_LOG_WARNING, "Layer rates invalid. Encoding with 1 layer based on quality metric.\n");
+ av_log(avctx, AV_LOG_WARNING, "Layer rates invalid. Encoding with 1 layer based on quality metric.\n");
s->nlayers = 1;
s->layer_rates[0] = 0;
s->compression_rate_enc = 0;
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 4940da21f3..f7c8305847 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -1526,11 +1526,11 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
c->skip=0;
bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) +
2 * c->mb_penalty_factor;
- ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
+ ff_dlog(s->avctx, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
c->skip=0;
fbmin= bidir_refine(s, mb_x, mb_y) + c->mb_penalty_factor;
- ff_dlog(s, "%d %d %d %d\n", dmin, fmin, bmin, fbmin);
+ ff_dlog(s->avctx, "%d %d %d %d\n", dmin, fmin, bmin, fbmin);
if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
//FIXME mb type penalty
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4aeefcaf8d..493a3edde6 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3750,7 +3750,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt)
s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
if (s->msmpeg4_version >= MSMP4_V3)
s->no_rounding=1;
- ff_dlog(s, "Scene change detected, encoding as I Frame %"PRId64" %"PRId64"\n",
+ ff_dlog(s->avctx, "Scene change detected, encoding as I Frame %"PRId64" %"PRId64"\n",
s->mb_var_sum, s->mc_mb_var_sum);
}
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 26b896bee3..89f4533d05 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -236,7 +236,7 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s)
s->per_mb_rl_table = 0;
if (s->msmpeg4_version == MSMP4_WMV1)
s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
- ff_dlog(s, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
+ ff_dlog(s->avctx, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
s->inter_intra_pred, s->width, s->height);
if (s->pict_type == AV_PICTURE_TYPE_I) {
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 08e8cadacd..f5e0b70a9a 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -232,7 +232,7 @@ static double modify_qscale(MpegEncContext *s, const RateControlEntry *rce,
}
}
}
- ff_dlog(s, "q:%f max:%f min:%f size:%f index:%f agr:%f\n",
+ ff_dlog(s->avctx, "q:%f max:%f min:%f size:%f index:%f agr:%f\n",
q, max_rate, min_rate, buffer_size, rcc->buffer_index,
rcc->buffer_aggressivity);
if (rcc->qsquish == 0.0 || qmin == qmax) {
@@ -461,7 +461,7 @@ static int init_pass2(MpegEncContext *s)
/* check bitrate calculations and print info */
qscale_sum = 0.0;
for (i = 0; i < rcc->num_entries; i++) {
- ff_dlog(s, "[lavc rc] entry[%d].new_qscale = %.3f qp = %.3f\n",
+ ff_dlog(s->avctx, "[lavc rc] entry[%d].new_qscale = %.3f qp = %.3f\n",
i,
rcc->entry[i].new_qscale,
rcc->entry[i].new_qscale / FF_QP2LAMBDA);
@@ -725,7 +725,7 @@ int ff_vbv_update(MpegEncContext *s, int frame_size)
const double min_rate = s->avctx->rc_min_rate / fps;
const double max_rate = s->avctx->rc_max_rate / fps;
- ff_dlog(s, "%d %f %d %f %f\n",
+ ff_dlog(s->avctx, "%d %f %d %f %f\n",
buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);
if (buffer_size) {
@@ -941,7 +941,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
av_assert0(picture_number >= 0);
if (picture_number >= rcc->num_entries) {
- av_log(s, AV_LOG_ERROR, "Input is longer than 2-pass log file\n");
+ av_log(s->avctx, AV_LOG_ERROR, "Input is longer than 2-pass log file\n");
return -1;
}
rce = &rcc->entry[picture_number];
@@ -964,7 +964,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
else
wanted_bits_double = s->bit_rate * (double)dts_pic->f->pts / fps;
if (wanted_bits_double > INT64_MAX) {
- av_log(s, AV_LOG_WARNING, "Bits exceed 64bit range\n");
+ av_log(s->avctx, AV_LOG_WARNING, "Bits exceed 64bit range\n");
wanted_bits = INT64_MAX;
} else
wanted_bits = (int64_t)wanted_bits_double;
@@ -983,7 +983,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
av_assert0(pict_type == rce->new_pict_type);
q = rce->new_qscale / br_compensation;
- ff_dlog(s, "%f %f %f last:%d var:%"PRId64" type:%d//\n", q, rce->new_qscale,
+ ff_dlog(s->avctx, "%f %f %f last:%d var:%"PRId64" type:%d//\n", q, rce->new_qscale,
br_compensation, s->frame_bits, var, pict_type);
} else {
rce->pict_type =
diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c
index 4096d6391f..f937c7166b 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -401,7 +401,7 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
block[0x3D] = temp_block[0x2F]; block[0x3E] = temp_block[0x37];
block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
} else {
- av_log(s, AV_LOG_DEBUG, "s->idsp.perm_type: %d\n",
+ av_log(s->avctx, AV_LOG_DEBUG, "s->idsp.perm_type: %d\n",
(int)s->idsp.perm_type);
av_assert0(s->idsp.perm_type == FF_IDCT_PERM_NONE ||
s->idsp.perm_type == FF_IDCT_PERM_LIBMPEG2 ||
More information about the ffmpeg-cvslog
mailing list