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 
24  AVCodecContext *avctx,
25  const uint8_t **poutbuf, int *poutbuf_size,
26  const uint8_t *buf, int buf_size)
27 {
28  unsigned int frame_type;
29  unsigned int profile;
30 
31  *poutbuf = buf;
32  *poutbuf_size = buf_size;
33 
34  if (buf_size < 3)
35  return buf_size;
36 
37  frame_type = buf[0] & 1;
38  profile = (buf[0] >> 1) & 7;
39  if (profile > 3) {
40  av_log(avctx, AV_LOG_ERROR, "Invalid profile %u.\n", profile);
41  return buf_size;
42  }
43 
44  avctx->profile = profile;
45  s->key_frame = frame_type == 0;
47  s->format = AV_PIX_FMT_YUV420P;
48  s->field_order = AV_FIELD_PROGRESSIVE;
49  s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
50 
51  if (frame_type == 0) {
52  unsigned int sync_code;
53  unsigned int width, height;
54 
55  if (buf_size < 10)
56  return buf_size;
57 
58  sync_code = AV_RL24(buf + 3);
59  if (sync_code != 0x2a019d) {
60  av_log(avctx, AV_LOG_ERROR, "Invalid sync code %06x.\n", sync_code);
61  return buf_size;
62  }
63 
64  width = AV_RL16(buf + 6) & 0x3fff;
65  height = AV_RL16(buf + 8) & 0x3fff;
66 
67  s->width = width;
68  s->height = height;
69  s->coded_width = FFALIGN(width, 16);
70  s->coded_height = FFALIGN(height, 16);
71  }
72 
73  return buf_size;
74 }
75 
78  .parser_parse = parse,
79 };
profile
mfxU16 profile
Definition: qsvenc.c:45
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:23
AV_PICTURE_STRUCTURE_FRAME
@ AV_PICTURE_STRUCTURE_FRAME
Definition: avcodec.h:3350
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
width
#define width
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
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:90
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:66
AVCodecParser::codec_ids
int codec_ids[5]
Definition: avcodec.h:3521
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:89
height
#define height
frame_type
frame_type
Definition: jpeg2000_parser.c:31
uint8_t
uint8_t
Definition: audio_convert.c:194
avcodec.h
AVCodecParserContext
Definition: avcodec.h:3353
AVCodecContext
main external API structure.
Definition: avcodec.h:526
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1859
ff_vp8_parser
AVCodecParser ff_vp8_parser
Definition: vp8_parser.c:76
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
AVCodecParser
Definition: avcodec.h:3520
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:189
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28