History

avcodec/flac_parse: Use void* instead of AVCodecContext* as logctx

It more directly shows that ff_flac_decode_frame_header() does not modify the AVCodecContext given to it at all; and it would not be allowed to do so, given that it is used by the parser when it is still unknown whether said frame header is even valid.

Andreas Rheinhardt committed 3 years ago

Commit 7a9bc091 parent 3ea73bc2 files · +11 −11Browse files

Unified · Split

2 files
  1. libavcodec/flac.c +9 −9
  2. libavcodec/flac_parse.h +2 −2
libavcodec/flac.c+9−9
@@ -48,14 +48,14 @@ static int64_t get_utf8(GetBitContext *gb) · 47 unmodified lines
4848 return val;
4949 }
5050
51−int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
51+int ff_flac_decode_frame_header(void *logctx, GetBitContext *gb,
5252 FLACFrameInfo *fi, int log_level_offset)
5353 {
5454 int bs_code, sr_code, bps_code;
5555
5656 /* frame sync code */
5757 if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {
58− av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n");
58+ av_log(logctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n");
5959 return AVERROR_INVALIDDATA;
6060 }
6161
@@ -75,7 +75,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 13 unmodified lines
7575 fi->channels = 2;
7676 fi->ch_mode -= FLAC_MAX_CHANNELS - 1;
7777 } else {
78− av_log(avctx, AV_LOG_ERROR + log_level_offset,
78+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
7979 "invalid channel mode: %d\n", fi->ch_mode);
8080 return AVERROR_INVALIDDATA;
8181 }
@@ -83,7 +83,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 1 unmodified line
8383 /* bits per sample */
8484 bps_code = get_bits(gb, 3);
8585 if (bps_code == 3) {
86− av_log(avctx, AV_LOG_ERROR + log_level_offset,
86+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
8787 "invalid sample size code (%d)\n",
8888 bps_code);
8989 return AVERROR_INVALIDDATA;
@@ -92,7 +92,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 2 unmodified lines
9292
9393 /* reserved bit */
9494 if (get_bits1(gb)) {
95− av_log(avctx, AV_LOG_ERROR + log_level_offset,
95+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
9696 "broken stream, invalid padding\n");
9797 return AVERROR_INVALIDDATA;
9898 }
@@ -100,14 +100,14 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 1 unmodified line
100100 /* sample or frame count */
101101 fi->frame_or_sample_num = get_utf8(gb);
102102 if (fi->frame_or_sample_num < 0) {
103− av_log(avctx, AV_LOG_ERROR + log_level_offset,
103+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
104104 "sample/frame number invalid; utf8 fscked\n");
105105 return AVERROR_INVALIDDATA;
106106 }
107107
108108 /* blocksize */
109109 if (bs_code == 0) {
110− av_log(avctx, AV_LOG_ERROR + log_level_offset,
110+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
111111 "reserved blocksize code: 0\n");
112112 return AVERROR_INVALIDDATA;
113113 } else if (bs_code == 6) {
@@ -128,7 +128,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 14 unmodified lines
128128 } else if (sr_code == 14) {
129129 fi->samplerate = get_bits(gb, 16) * 10;
130130 } else {
131− av_log(avctx, AV_LOG_ERROR + log_level_offset,
131+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
132132 "illegal sample rate code %d\n",
133133 sr_code);
134134 return AVERROR_INVALIDDATA;
@@ -138,7 +138,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 3 unmodified lines
138138 skip_bits(gb, 8);
139139 if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,
140140 get_bits_count(gb)/8)) {
141− av_log(avctx, AV_LOG_ERROR + log_level_offset,
141+ av_log(logctx, AV_LOG_ERROR + log_level_offset,
142142 "header crc mismatch\n");
143143 return AVERROR_INVALIDDATA;
144144 }
libavcodec/flac_parse.h+2−2
@@ -75,13 +75,13 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx, · 74 unmodified lines
7575
7676 /**
7777 * Validate and decode a frame header.
78− * @param avctx AVCodecContext to use as av_log() context
78+ * @param logctx context for logging
7979 * @param gb GetBitContext from which to read frame header
8080 * @param[out] fi frame information
8181 * @param log_level_offset log level offset. can be used to silence error messages.
8282 * @return non-zero on error, 0 if ok
8383 */
84−int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
84+int ff_flac_decode_frame_header(void *logctx, GetBitContext *gb,
8585 FLACFrameInfo *fi, int log_level_offset);
8686
8787 void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t