History

Merge commit '8747926'

* commit '8747926': vorbis_parser: use a dedicated AVClass for logging Conflicts: libavcodec/vorbis_parser.c

Michael Niedermayer committed 12 years ago

Commit a0617022 parents 8176638 87479262 files · +29 −21Browse files

Unified · Split

2 files
  1. libavcodec/vorbis_parser.c +28 −20
  2. libavcodec/vorbis_parser.h +1 −1
libavcodec/vorbis_parser.c+28−20
@@ -25,34 +25,42 @@ · 24 unmodified lines
2525 * Determines the duration for each packet.
2626 */
2727
28+#include "libavutil/log.h"
29+
2830 #include "get_bits.h"
2931 #include "parser.h"
3032 #include "xiph.h"
3133 #include "vorbis_parser.h"
3234
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,
3442 const uint8_t *buf, int buf_size)
3543 {
3644 /* Id header should be 30 bytes */
3745 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");
3947 return AVERROR_INVALIDDATA;
4048 }
4149
4250 /* make sure this is the Id header */
4351 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");
4553 return AVERROR_INVALIDDATA;
4654 }
4755
4856 /* check for header signature */
4957 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");
5159 return AVERROR_INVALIDDATA;
5260 }
5361
5462 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");
5664 return AVERROR_INVALIDDATA;
5765 }
5866
@@ -62,7 +70,7 @@ static int parse_id_header(AVCodecContext *avctx, VorbisParseContext *s, · 3 unmodified lines
6270 return 0;
6371 }
6472
65−static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s,
73+static int parse_setup_header(VorbisParseContext *s,
6674 const uint8_t *buf, int buf_size)
6775 {
6876 GetBitContext gb, gb0;
@@ -72,25 +80,25 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 3 unmodified lines
7280
7381 /* avoid overread */
7482 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");
7684 return AVERROR_INVALIDDATA;
7785 }
7886
7987 /* make sure this is the Setup header */
8088 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");
8290 return AVERROR_INVALIDDATA;
8391 }
8492
8593 /* check for header signature */
8694 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");
8896 return AVERROR_INVALIDDATA;
8997 }
9098
9199 /* reverse bytes so we can easily read backwards with get_bits() */
92100 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");
94102 return AVERROR(ENOMEM);
95103 }
96104 for (i = 0; i < buf_size; i++)
@@ -105,7 +113,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 8 unmodified lines
105113 }
106114 }
107115 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");
109117 ret = AVERROR_INVALIDDATA;
110118 goto bad_header;
111119 }
@@ -132,7 +140,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 20 unmodified lines
132140 }
133141 }
134142 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");
136144 ret = AVERROR_INVALIDDATA;
137145 goto bad_header;
138146 }
@@ -141,7 +149,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 2 unmodified lines
141149 * we may need to approach this the long way and parse the whole Setup
142150 * header, but I hope very much that it never comes to that. */
143151 if (last_mode_count > 2) {
144− avpriv_request_sample(avctx,
152+ avpriv_request_sample(s,
145153 "%d modes (either a false positive or a "
146154 "sample from an unknown encoder)",
147155 last_mode_count);
@@ -149,7 +157,7 @@ static int parse_setup_header(AVCodecContext *avctx, VorbisParseContext *s, · 1 unmodified line
149157 /* We're limiting the mode count to 63 so that we know that the previous
150158 * block flag will be in the first packet byte. */
151159 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",
153161 last_mode_count);
154162 ret = AVERROR_INVALIDDATA;
155163 goto bad_header;
@@ -179,20 +187,20 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s) · 23 unmodified lines
179187 int header_len[3];
180188 int ret;
181189
182− s->avctx = avctx;
190+ s->class = &vorbis_parser_class;
183191 s->extradata_parsed = 1;
184192
185193 if ((ret = avpriv_split_xiph_headers(avctx->extradata,
186194 avctx->extradata_size, 30,
187195 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");
189197 return ret;
190198 }
191199
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)
193201 return ret;
194202
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)
196204 return ret;
197205
198206 s->valid_extradata = 1;
@@ -227,7 +235,7 @@ int avpriv_vorbis_parse_frame_flags(VorbisParseContext *s, const uint8_t *buf, · 28 unmodified lines
227235 return 0;
228236
229237 bad_packet:
230− av_log(s->avctx, AV_LOG_ERROR, "Invalid packet\n");
238+ av_log(s, AV_LOG_ERROR, "Invalid packet\n");
231239 return AVERROR_INVALIDDATA;
232240 }
233241 if (s->mode_count == 1)
@@ -235,7 +243,7 @@ bad_packet: · 1 unmodified line
235243 else
236244 mode = (buf[0] & s->mode_mask) >> 1;
237245 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");
239247 return AVERROR_INVALIDDATA;
240248 }
241249 if(s->mode_blocksize[mode]){
libavcodec/vorbis_parser.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
3131 #include "avcodec.h"
3232
3333 typedef struct VorbisParseContext {
34− AVCodecContext *avctx; ///< codec context
34+ const AVClass *class;
3535 int extradata_parsed; ///< we have attempted to parse extradata
3636 int valid_extradata; ///< extradata is valid, so we can calculate duration
3737 int blocksize[2]; ///< short and long window sizes

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