FFmpeg
vp8_parser.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/intreadwrite.h"
20 
21 #include "avcodec.h"
22 #include "parser_internal.h"
23 
25  AVCodecContext *avctx,
26  const uint8_t **poutbuf, int *poutbuf_size,
27  const uint8_t *buf, int buf_size)
28 {
29  unsigned int frame_type;
30  unsigned int profile;
31 
32  *poutbuf = buf;
33  *poutbuf_size = buf_size;
34 
35  if (buf_size < 3)
36  return buf_size;
37 
38  frame_type = buf[0] & 1;
39  profile = (buf[0] >> 1) & 7;
40  if (profile > 3) {
41  av_log(avctx, AV_LOG_ERROR, "Invalid profile %u.\n", profile);
42  return buf_size;
43  }
44 
45  avctx->profile = profile;
46  s->key_frame = frame_type == 0;
48  s->format = AV_PIX_FMT_YUV420P;
49  s->field_order = AV_FIELD_PROGRESSIVE;
50  s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
51 
52  if (frame_type == 0) {
53  unsigned int sync_code;
54  unsigned int width, height;
55 
56  if (buf_size < 10)
57  return buf_size;
58 
59  sync_code = AV_RL24(buf + 3);
60  if (sync_code != 0x2a019d) {
61  av_log(avctx, AV_LOG_ERROR, "Invalid sync code %06x.\n", sync_code);
62  return buf_size;
63  }
64 
65  width = AV_RL16(buf + 6) & 0x3fff;
66  height = AV_RL16(buf + 8) & 0x3fff;
67 
68  s->width = width;
69  s->height = height;
70  s->coded_width = FFALIGN(width, 16);
71  s->coded_height = FFALIGN(height, 16);
72  }
73 
74  return buf_size;
75 }
76 
79  .parse = parse,
80 };
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: defs.h:213
parser_internal.h
parse
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: vp8_parser.c:24
AV_PICTURE_STRUCTURE_FRAME
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
Definition: avcodec.h:2572
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
height
#define height
Definition: dsp.h:89
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:93
FFCodecParser
Definition: parser_internal.h:29
frame_type
frame_type
Definition: jpeg2000_parser.c:32
ff_vp8_parser
const FFCodecParser ff_vp8_parser
Definition: vp8_parser.c:77
profile
int profile
Definition: mxfenc.c:2297
PARSER_CODEC_LIST
#define PARSER_CODEC_LIST(...)
Definition: parser_internal.h:76
avcodec.h
AVCodecParserContext
Definition: avcodec.h:2575
AVCodecContext
main external API structure.
Definition: avcodec.h:431
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1618
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:279
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
width
#define width
Definition: dsp.h:89