* 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 | * Determines the duration for each packet. | 25 | * Determines the duration for each packet. |
| 26 | */ | 26 | */ |
| 27 | 27 | ||
| 28 | #include "libavutil/log.h" | ||
| 29 | |||
| 28 | #include "get_bits.h" | 30 | #include "get_bits.h" |
| 29 | #include "parser.h" | 31 | #include "parser.h" |
| 30 | #include "xiph.h" | 32 | #include "xiph.h" |
| 31 | #include "vorbis_parser.h" | 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 | const uint8_t *buf, int buf_size) | 42 | const uint8_t *buf, int buf_size) |
| 35 | { | 43 | { |
| 36 | /* Id header should be 30 bytes */ | 44 | /* Id header should be 30 bytes */ |
| 37 | if (buf_size < 30) { | 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 | return AVERROR_INVALIDDATA; | 47 | return AVERROR_INVALIDDATA; |
| 40 | } | 48 | } |
| 41 | 49 | ||
| 42 | /* make sure this is the Id header */ | 50 | /* make sure this is the Id header */ |
| 43 | if (buf[0] != 1) { | 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 | return AVERROR_INVALIDDATA; | 53 | return AVERROR_INVALIDDATA; |
| 46 | } | 54 | } |
| 47 | 55 | ||
| 48 | /* check for header signature */ | 56 | /* check for header signature */ |
| 49 | if (memcmp(&buf[1], "vorbis", 6)) { | 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 | return AVERROR_INVALIDDATA; | 59 | return AVERROR_INVALIDDATA; |
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | if (!(buf[29] & 0x1)) { | 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 | return AVERROR_INVALIDDATA; | 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 | return 0; | 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 | const uint8_t *buf, int buf_size) | 74 | const uint8_t *buf, int buf_size) |
| 67 | { | 75 | { |
| 68 | GetBitContext gb, gb0; | 76 | GetBitContext gb, gb0; |
| @@ -72,25 +80,25 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 3 unmodified lines | |||
| 72 | 80 | ||
| 73 | /* avoid overread */ | 81 | /* avoid overread */ |
| 74 | if (buf_size < 7) { | 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 | return AVERROR_INVALIDDATA; | 84 | return AVERROR_INVALIDDATA; |
| 77 | } | 85 | } |
| 78 | 86 | ||
| 79 | /* make sure this is the Setup header */ | 87 | /* make sure this is the Setup header */ |
| 80 | if (buf[0] != 5) { | 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 | return AVERROR_INVALIDDATA; | 90 | return AVERROR_INVALIDDATA; |
| 83 | } | 91 | } |
| 84 | 92 | ||
| 85 | /* check for header signature */ | 93 | /* check for header signature */ |
| 86 | if (memcmp(&buf[1], "vorbis", 6)) { | 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 | return AVERROR_INVALIDDATA; | 96 | return AVERROR_INVALIDDATA; |
| 89 | } | 97 | } |
| 90 | 98 | ||
| 91 | /* reverse bytes so we can easily read backwards with get_bits() */ | 99 | /* reverse bytes so we can easily read backwards with get_bits() */ |
| 92 | if (!(rev_buf = av_malloc(buf_size))) { | 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 | return AVERROR(ENOMEM); | 102 | return AVERROR(ENOMEM); |
| 95 | } | 103 | } |
| 96 | for (i = 0; i < buf_size; i++) | 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 | if (!got_framing_bit) { | 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 | ret = AVERROR_INVALIDDATA; | 117 | ret = AVERROR_INVALIDDATA; |
| 110 | goto bad_header; | 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 | if (!got_mode_header) { | 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 | ret = AVERROR_INVALIDDATA; | 144 | ret = AVERROR_INVALIDDATA; |
| 137 | goto bad_header; | 145 | goto bad_header; |
| 138 | } | 146 | } |
| @@ -141,7 +149,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 2 unmodified lines | |||
| 141 | * we may need to approach this the long way and parse the whole Setup | 149 | * we may need to approach this the long way and parse the whole Setup |
| 142 | * header, but I hope very much that it never comes to that. */ | 150 | * header, but I hope very much that it never comes to that. */ |
| 143 | if (last_mode_count > 2) { | 151 | if (last_mode_count > 2) { |
| 144 | avpriv_request_sample(avctx, | 152 | avpriv_request_sample(s, |
| 145 | "%d modes (either a false positive or a " | 153 | "%d modes (either a false positive or a " |
| 146 | "sample from an unknown encoder)", | 154 | "sample from an unknown encoder)", |
| 147 | last_mode_count); | 155 | last_mode_count); |
| @@ -149,7 +157,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 1 unmodified line | |||
| 149 | /* We're limiting the mode count to 63 so that we know that the previous | 157 | /* We're limiting the mode count to 63 so that we know that the previous |
| 150 | * block flag will be in the first packet byte. */ | 158 | * block flag will be in the first packet byte. */ |
| 151 | if (last_mode_count > 63) { | 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 | last_mode_count); | 161 | last_mode_count); |
| 154 | ret = AVERROR_INVALIDDATA; | 162 | ret = AVERROR_INVALIDDATA; |
| 155 | goto bad_header; | 163 | goto bad_header; |
| @@ -179,20 +187,20 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s) · 23 unmodified lines | |||
| 179 | int header_len[3]; | 187 | int header_len[3]; |
| 180 | int ret; | 188 | int ret; |
| 181 | 189 | ||
| 182 | s->avctx = avctx; | 190 | s->class = &vorbis_parser_class; |
| 183 | s->extradata_parsed = 1; | 191 | s->extradata_parsed = 1; |
| 184 | 192 | ||
| 185 | if ((ret = avpriv_split_xiph_headers(avctx->extradata, | 193 | if ((ret = avpriv_split_xiph_headers(avctx->extradata, |
| 186 | avctx->extradata_size, 30, | 194 | avctx->extradata_size, 30, |
| 187 | header_start, header_len)) < 0) { | 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 | return ret; | 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 | return ret; | 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 | return ret; | 204 | return ret; |
| 197 | 205 | ||
| 198 | s->valid_extradata = 1; | 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 | return 0; | 235 | return 0; |
| 228 | 236 | ||
| 229 | bad_packet: | 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 | return AVERROR_INVALIDDATA; | 239 | return AVERROR_INVALIDDATA; |
| 232 | } | 240 | } |
| 233 | if (s->mode_count == 1) | 241 | if (s->mode_count == 1) |
| @@ -235,7 +243,7 @@ bad_packet: · 1 unmodified line | |||
| 235 | else | 243 | else |
| 236 | mode = (buf[0] & s->mode_mask) >> 1; | 244 | mode = (buf[0] & s->mode_mask) >> 1; |
| 237 | if (mode >= s->mode_count) { | 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 | return AVERROR_INVALIDDATA; | 247 | return AVERROR_INVALIDDATA; |
| 240 | } | 248 | } |
| 241 | if(s->mode_blocksize[mode]){ | 249 | if(s->mode_blocksize[mode]){ |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | |||
| 31 | #include "avcodec.h" | 31 | #include "avcodec.h" |
| 32 | 32 | ||
| 33 | typedef struct VorbisParseContext { | 33 | typedef struct VorbisParseContext { |
| 34 | AVCodecContext *avctx; ///< codec context | 34 | const AVClass *class; |
| 35 | int extradata_parsed; ///< we have attempted to parse extradata | 35 | int extradata_parsed; ///< we have attempted to parse extradata |
| 36 | int valid_extradata; ///< extradata is valid, so we can calculate duration | 36 | int valid_extradata; ///< extradata is valid, so we can calculate duration |
| 37 | int blocksize[2]; ///< short and long window sizes | 37 | int blocksize[2]; ///< short and long window sizes |