FFmpeg
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
libavcodec
vp9_parser.c
Go to the documentation of this file.
1
/*
2
* VP9 compatible video decoder
3
*
4
* Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5
* Copyright (C) 2013 Clément Bœsch <u pkh me>
6
*
7
* This file is part of FFmpeg.
8
*
9
* FFmpeg is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
13
*
14
* FFmpeg is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
18
*
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with FFmpeg; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
*/
23
24
#include "
libavutil/intreadwrite.h
"
25
#include "
parser.h
"
26
27
typedef
struct
VP9ParseContext
{
28
int
n_frames
;
// 1-8
29
int
size
[8];
30
int64_t
pts
;
31
}
VP9ParseContext
;
32
33
static
void
parse_frame
(
AVCodecParserContext
*ctx,
const
uint8_t
*
buf
,
int
size
)
34
{
35
VP9ParseContext
*
s
= ctx->
priv_data
;
36
37
if
(buf[0] & 0x4) {
38
ctx->
pict_type
=
AV_PICTURE_TYPE_P
;
39
ctx->
key_frame
= 0;
40
}
else
{
41
ctx->
pict_type
=
AV_PICTURE_TYPE_I
;
42
ctx->
key_frame
= 1;
43
}
44
45
if
(buf[0] & 0x2) {
46
if
(ctx->
pts
==
AV_NOPTS_VALUE
)
47
ctx->
pts
= s->
pts
;
48
s->
pts
=
AV_NOPTS_VALUE
;
49
}
else
{
50
s->
pts
= ctx->
pts
;
51
ctx->
pts
=
AV_NOPTS_VALUE
;
52
}
53
}
54
55
static
int
parse
(
AVCodecParserContext
*ctx,
56
AVCodecContext
*avctx,
57
const
uint8_t
**out_data,
int
*out_size,
58
const
uint8_t
*
data
,
int
size
)
59
{
60
VP9ParseContext
*
s
= ctx->
priv_data
;
61
int
full_size =
size
;
62
int
marker;
63
64
if
(size <= 0) {
65
*out_size = 0;
66
*out_data =
data
;
67
68
return
0;
69
}
70
71
if
(s->
n_frames
> 0) {
72
*out_data =
data
;
73
*out_size = s->
size
[--s->
n_frames
];
74
parse_frame
(ctx, *out_data, *out_size);
75
76
return
s->
n_frames
> 0 ? *out_size : size
/* i.e. include idx tail */
;
77
}
78
79
marker = data[size - 1];
80
if
((marker & 0xe0) == 0xc0) {
81
int
nbytes = 1 + ((marker >> 3) & 0x3);
82
int
n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;
83
84
if
(size >= idx_sz && data[size - idx_sz] == marker) {
85
const
uint8_t
*idx = data + size + 1 - idx_sz;
86
int
first = 1;
87
88
switch
(nbytes) {
89
#define case_n(a, rd) \
90
case a: \
91
while (n_frames--) { \
92
unsigned sz = rd; \
93
idx += a; \
94
if (sz > size) { \
95
s->n_frames = 0; \
96
*out_size = size; \
97
*out_data = data; \
98
av_log(avctx, AV_LOG_ERROR, \
99
"Superframe packet size too big: %u > %d\n", \
100
sz, size); \
101
return full_size; \
102
} \
103
if (first) { \
104
first = 0; \
105
*out_data = data; \
106
*out_size = sz; \
107
s->n_frames = n_frames; \
108
} else { \
109
s->size[n_frames] = sz; \
110
} \
111
data += sz; \
112
size -= sz; \
113
} \
114
parse_frame(ctx, *out_data, *out_size); \
115
return *out_size
116
117
case_n
(1, *idx);
118
case_n
(2,
AV_RL16
(idx));
119
case_n
(3,
AV_RL24
(idx));
120
case_n
(4,
AV_RL32
(idx));
121
}
122
}
123
}
124
125
*out_data =
data
;
126
*out_size =
size
;
127
parse_frame
(ctx, data, size);
128
129
return
size
;
130
}
131
132
AVCodecParser
ff_vp9_parser
= {
133
.
codec_ids
= {
AV_CODEC_ID_VP9
},
134
.priv_data_size =
sizeof
(
VP9ParseContext
),
135
.parser_parse =
parse
,
136
};
ff_vp9_parser
AVCodecParser ff_vp9_parser
Definition:
vp9_parser.c:132
AV_CODEC_ID_VP9
Definition:
avcodec.h:276
s
const char * s
Definition:
avisynth_c.h:631
data
ptrdiff_t const GLvoid * data
Definition:
opengl_enc.c:101
AVCodecParser::codec_ids
int codec_ids[5]
Definition:
avcodec.h:4426
parse
static int parse(AVCodecParserContext *ctx, AVCodecContext *avctx, const uint8_t **out_data, int *out_size, const uint8_t *data, int size)
Definition:
vp9_parser.c:55
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:85
parse_frame
static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size)
Definition:
vp9_parser.c:33
uint8_t
uint8_t
Definition:
audio_convert.c:194
VP9ParseContext
Definition:
vp9_parser.c:27
size
ptrdiff_t size
Definition:
opengl_enc.c:101
parser.h
AVCodecParserContext::pict_type
int pict_type
Definition:
avcodec.h:4255
AVCodecParserContext::priv_data
void * priv_data
Definition:
avcodec.h:4248
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition:
bytestream.h:85
AVCodecParser
Definition:
avcodec.h:4425
AV_PICTURE_TYPE_I
Intra.
Definition:
avutil.h:267
intreadwrite.h
AVCodecParserContext
Definition:
avcodec.h:4247
AVCodecContext
main external API structure.
Definition:
avcodec.h:1241
case_n
#define case_n(a, rd)
VP9ParseContext::pts
int64_t pts
Definition:
vp9_parser.c:30
buf
void * buf
Definition:
avisynth_c.h:553
VP9ParseContext::n_frames
int n_frames
Definition:
vp9_parser.c:28
VP9ParseContext::size
int size[8]
Definition:
vp9_parser.c:29
AVCodecParserContext::pts
int64_t pts
Definition:
avcodec.h:4266
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition:
bytestream.h:85
AVCodecParserContext::key_frame
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
Definition:
avcodec.h:4296
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition:
avutil.h:241
AV_PICTURE_TYPE_P
Predicted.
Definition:
avutil.h:268
Generated on Wed Jun 10 2015 01:56:51 for FFmpeg by
1.8.6