* commit '8747926': vorbis_parser: use a dedicated AVClass for logging Conflicts: libavcodec/vorbis_parser.c
Unified · Split
| @@ -25,34 +25,42 @@ · 24 unmodified lines | ||
| 25 | 25 | * Determines the duration for each packet. |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | +#include "libavutil/log.h" | |
| 29 | + | |
| 28 | 30 | #include "get_bits.h" |
| 29 | 31 | #include "parser.h" |
| 30 | 32 | #include "xiph.h" |
| 31 | 33 | #include "vorbis_parser.h" |
| 32 | 34 | |
| 33 | −static int parse_id_header(AVCodecContext *avctx, VorbisParseContext *s, | |
| 35 | +static const AVClass vorbis_parser_class = { | |
| 36 | + .class_name = "Vorbis parser", | |
| 37 | + .item_name = av_default_item_name, | |
| 38 | + .version = LIBAVUTIL_VERSION_INT, | |
| 39 | +}; | |
| 40 | + | |
| 41 | +static int parse_id_header(VorbisParseContext *s, | |
| 34 | 42 | const uint8_t *buf, int buf_size) |
| 35 | 43 | { |
| 36 | 44 | /* Id header should be 30 bytes */ |
| 37 | 45 | if (buf_size < 30) { |
| 38 | − av_log(avctx, AV_LOG_ERROR, "Id header is too short\n"); | |
| 46 | + av_log(s, AV_LOG_ERROR, "Id header is too short\n"); | |
| 39 | 47 | return AVERROR_INVALIDDATA; |
| 40 | 48 | } |
| 41 | 49 | |
| 42 | 50 | /* make sure this is the Id header */ |
| 43 | 51 | if (buf[0] != 1) { |
| 44 | − av_log(avctx, AV_LOG_ERROR, "Wrong packet type in Id header\n"); | |
| 52 | + av_log(s, AV_LOG_ERROR, "Wrong packet type in Id header\n"); | |
| 45 | 53 | return AVERROR_INVALIDDATA; |
| 46 | 54 | } |
| 47 | 55 | |
| 48 | 56 | /* check for header signature */ |
| 49 | 57 | if (memcmp(&buf[1], "vorbis", 6)) { |
| 50 | − av_log(avctx, AV_LOG_ERROR, "Invalid packet signature in Id header\n"); | |
| 58 | + av_log(s, AV_LOG_ERROR, "Invalid packet signature in Id header\n"); | |
| 51 | 59 | return AVERROR_INVALIDDATA; |
| 52 | 60 | } |
| 53 | 61 | |
| 54 | 62 | if (!(buf[29] & 0x1)) { |
| 55 | − av_log(avctx, AV_LOG_ERROR, "Invalid framing bit in Id header\n"); | |
| 63 | + av_log(s, AV_LOG_ERROR, "Invalid framing bit in Id header\n"); | |
| 56 | 64 | return AVERROR_INVALIDDATA; |
| 57 | 65 | } |
| 58 | 66 | |
| @@ -62,7 +70,7 @@ static int parse_id_header(AVCodecContext *avctx, VorbisParseContext *s, · 3 unmodified lines | ||
| 62 | 70 | return 0; |
| 63 | 71 | } |
| 64 | 72 | |
| 65 | −static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, | |
| 73 | +static int parse_setup_header(VorbisParseContext *s, | |
| 66 | 74 | const uint8_t *buf, int buf_size) |
| 67 | 75 | { |
| 68 | 76 | GetBitContext gb, gb0; |
| @@ -72,25 +80,25 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 3 unmodified lines | ||
| 72 | 80 | |
| 73 | 81 | /* avoid overread */ |
| 74 | 82 | if (buf_size < 7) { |
| 75 | − av_log(avctx, AV_LOG_ERROR, "Setup header is too short\n"); | |
| 83 | + av_log(s, AV_LOG_ERROR, "Setup header is too short\n"); | |
| 76 | 84 | return AVERROR_INVALIDDATA; |
| 77 | 85 | } |
| 78 | 86 | |
| 79 | 87 | /* make sure this is the Setup header */ |
| 80 | 88 | if (buf[0] != 5) { |
| 81 | − av_log(avctx, AV_LOG_ERROR, "Wrong packet type in Setup header\n"); | |
| 89 | + av_log(s, AV_LOG_ERROR, "Wrong packet type in Setup header\n"); | |
| 82 | 90 | return AVERROR_INVALIDDATA; |
| 83 | 91 | } |
| 84 | 92 | |
| 85 | 93 | /* check for header signature */ |
| 86 | 94 | if (memcmp(&buf[1], "vorbis", 6)) { |
| 87 | − av_log(avctx, AV_LOG_ERROR, "Invalid packet signature in Setup header\n"); | |
| 95 | + av_log(s, AV_LOG_ERROR, "Invalid packet signature in Setup header\n"); | |
| 88 | 96 | return AVERROR_INVALIDDATA; |
| 89 | 97 | } |
| 90 | 98 | |
| 91 | 99 | /* reverse bytes so we can easily read backwards with get_bits() */ |
| 92 | 100 | if (!(rev_buf = av_malloc(buf_size))) { |
| 93 | − av_log(avctx, AV_LOG_ERROR, "Out of memory\n"); | |
| 101 | + av_log(s, AV_LOG_ERROR, "Out of memory\n"); | |
| 94 | 102 | return AVERROR(ENOMEM); |
| 95 | 103 | } |
| 96 | 104 | for (i = 0; i < buf_size; i++) |
| @@ -105,7 +113,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 8 unmodified lines | ||
| 105 | 113 | } |
| 106 | 114 | } |
| 107 | 115 | if (!got_framing_bit) { |
| 108 | − av_log(avctx, AV_LOG_ERROR, "Invalid Setup header\n"); | |
| 116 | + av_log(s, AV_LOG_ERROR, "Invalid Setup header\n"); | |
| 109 | 117 | ret = AVERROR_INVALIDDATA; |
| 110 | 118 | goto bad_header; |
| 111 | 119 | } |
| @@ -132,7 +140,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 20 unmodified lines | ||
| 132 | 140 | } |
| 133 | 141 | } |
| 134 | 142 | if (!got_mode_header) { |
| 135 | − av_log(avctx, AV_LOG_ERROR, "Invalid Setup header\n"); | |
| 143 | + av_log(s, AV_LOG_ERROR, "Invalid Setup header\n"); | |
| 136 | 144 | ret = AVERROR_INVALIDDATA; |
| 137 | 145 | goto bad_header; |
| 138 | 146 | } |
| @@ -141,7 +149,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 2 unmodified lines | ||
| 141 | 149 | * we may need to approach this the long way and parse the whole Setup |
| 142 | 150 | * header, but I hope very much that it never comes to that. */ |
| 143 | 151 | if (last_mode_count > 2) { |
| 144 | − avpriv_request_sample(avctx, | |
| 152 | + avpriv_request_sample(s, | |
| 145 | 153 | "%d modes (either a false positive or a " |
| 146 | 154 | "sample from an unknown encoder)", |
| 147 | 155 | last_mode_count); |
| @@ -149,7 +157,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 1 unmodified line | ||
| 149 | 157 | /* We're limiting the mode count to 63 so that we know that the previous |
| 150 | 158 | * block flag will be in the first packet byte. */ |
| 151 | 159 | if (last_mode_count > 63) { |
| 152 | − av_log(avctx, AV_LOG_ERROR, "Unsupported mode count: %d\n", | |
| 160 | + av_log(s, AV_LOG_ERROR, "Unsupported mode count: %d\n", | |
| 153 | 161 | last_mode_count); |
| 154 | 162 | ret = AVERROR_INVALIDDATA; |
| 155 | 163 | goto bad_header; |
| @@ -179,20 +187,20 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s) · 23 unmodified lines | ||
| 179 | 187 | int header_len[3]; |
| 180 | 188 | int ret; |
| 181 | 189 | |
| 182 | − s->avctx = avctx; | |
| 190 | + s->class = &vorbis_parser_class; | |
| 183 | 191 | s->extradata_parsed = 1; |
| 184 | 192 | |
| 185 | 193 | if ((ret = avpriv_split_xiph_headers(avctx->extradata, |
| 186 | 194 | avctx->extradata_size, 30, |
| 187 | 195 | header_start, header_len)) < 0) { |
| 188 | − av_log(avctx, AV_LOG_ERROR, "Extradata corrupt.\n"); | |
| 196 | + av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); | |
| 189 | 197 | return ret; |
| 190 | 198 | } |
| 191 | 199 | |
| 192 | − if ((ret = parse_id_header(avctx, s, header_start[0], header_len[0])) < 0) | |
| 200 | + if ((ret = parse_id_header(s, header_start[0], header_len[0])) < 0) | |
| 193 | 201 | return ret; |
| 194 | 202 | |
| 195 | − if ((ret = parse_setup_header(avctx, s, header_start[2], header_len[2])) < 0) | |
| 203 | + if ((ret = parse_setup_header(s, header_start[2], header_len[2])) < 0) | |
| 196 | 204 | return ret; |
| 197 | 205 | |
| 198 | 206 | s->valid_extradata = 1; |
| @@ -227,7 +235,7 @@ int avpriv_vorbis_parse_frame_flags(VorbisParseContext *s, const uint8_t *buf, · 28 unmodified lines | ||
| 227 | 235 | return 0; |
| 228 | 236 | |
| 229 | 237 | bad_packet: |
| 230 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid packet\n"); | |
| 238 | + av_log(s, AV_LOG_ERROR, "Invalid packet\n"); | |
| 231 | 239 | return AVERROR_INVALIDDATA; |
| 232 | 240 | } |
| 233 | 241 | if (s->mode_count == 1) |
| @@ -235,7 +243,7 @@ bad_packet: · 1 unmodified line | ||
| 235 | 243 | else |
| 236 | 244 | mode = (buf[0] & s->mode_mask) >> 1; |
| 237 | 245 | if (mode >= s->mode_count) { |
| 238 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid mode in packet\n"); | |
| 246 | + av_log(s, AV_LOG_ERROR, "Invalid mode in packet\n"); | |
| 239 | 247 | return AVERROR_INVALIDDATA; |
| 240 | 248 | } |
| 241 | 249 | if(s->mode_blocksize[mode]){ |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | ||
| 31 | 31 | #include "avcodec.h" |
| 32 | 32 | |
| 33 | 33 | typedef struct VorbisParseContext { |
| 34 | − AVCodecContext *avctx; ///< codec context | |
| 34 | + const AVClass *class; | |
| 35 | 35 | int extradata_parsed; ///< we have attempted to parse extradata |
| 36 | 36 | int valid_extradata; ///< extradata is valid, so we can calculate duration |
| 37 | 37 | int blocksize[2]; ///< short and long window sizes |