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