FFmpeg
Loading...
Searching...
No Matches
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
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
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition apv_parser.c:92
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
@ AV_FIELD_PROGRESSIVE
Definition defs.h:213
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
Definition avcodec.h:2614
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
#define AV_RL24(x)
#define AV_RL16(p)
frame_type
#define FFALIGN(x, a)
Definition macros.h:78
int profile
Definition mxfenc.c:2299
#define PARSER_CODEC_LIST(...)
const FFCodecParser ff_vp8_parser
Definition vp8_parser.c:77
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
main external API structure.
Definition avcodec.h:443
int profile
profile
Definition avcodec.h:1636
#define av_log(a,...)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
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