FFmpeg
ffv1_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 "avcodec.h"
20 #include "ffv1.h"
21 #include "rangecoder.h"
22 
23 typedef struct FFV1ParseContext {
25  int got_first;
27 
29  AVCodecContext *avctx,
30  const uint8_t **poutbuf, int *poutbuf_size,
31  const uint8_t *buf, int buf_size)
32 {
33  FFV1ParseContext *p = s->priv_data;
34  FFV1Context *f = &p->f;
35  RangeCoder c;
36  uint8_t keystate = 128;
37 
38  *poutbuf = buf;
39  *poutbuf_size = buf_size;
40 
41  if (!p->got_first) {
42  int ret = ff_ffv1_common_init(avctx, f);
43  p->got_first = 1;
44  if (ret < 0)
45  return buf_size;
46 
47  if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0)
48  return buf_size;
49  }
50 
51  ff_init_range_decoder(&c, buf, buf_size);
52  ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
53 
54  f->avctx = avctx;
55  s->key_frame = get_rac(&c, &keystate);
56  s->pict_type = AV_PICTURE_TYPE_I;
57  s->field_order = AV_FIELD_UNKNOWN;
58  s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
59 
60  if (s->key_frame) {
61  uint8_t state[CONTEXT_SIZE];
62  memset(state, 128, sizeof(state));
64  }
65 
66  s->width = f->width;
67  s->height = f->height;
68  s->format = f->pix_fmt;
69 
70  return buf_size;
71 }
72 
74 {
75  FFV1ParseContext *p = s->priv_data;
76 
77  p->f.avctx = NULL;
78  ff_ffv1_close(&p->f);
79 }
80 
83  .priv_data_size = sizeof(FFV1ParseContext),
84  .parser_parse = parse,
85  .parser_close = close,
86 };
FFV1ParseContext::f
FFV1Context f
Definition: ffv1_parser.c:24
FFV1ParseContext::got_first
int got_first
Definition: ffv1_parser.c:25
AV_PICTURE_STRUCTURE_UNKNOWN
@ AV_PICTURE_STRUCTURE_UNKNOWN
unknown
Definition: avcodec.h:2761
rangecoder.h
ff_ffv1_read_extra_header
int ff_ffv1_read_extra_header(FFV1Context *f)
Definition: ffv1_parse.c:70
state
static struct @472 state
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
AV_FIELD_UNKNOWN
@ AV_FIELD_UNKNOWN
Definition: defs.h:201
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
s
#define s(width, name)
Definition: cbs_vp9.c:198
NULL
#define NULL
Definition: coverity.c:32
parse
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: ffv1_parser.c:28
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_init_range_decoder
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
Definition: rangecoder.c:53
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:85
ff_ffv1_parser
const AVCodecParser ff_ffv1_parser
Definition: ffv1_parser.c:81
f
f
Definition: af_crystalizer.c:122
AVCodecParser::codec_ids
int codec_ids[7]
Definition: avcodec.h:2927
ff_build_rac_states
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
Definition: rangecoder.c:68
FFV1ParseContext
Definition: ffv1_parser.c:23
ff_ffv1_common_init
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
Definition: ffv1.c:36
ffv1.h
get_rac
static int get_rac(RangeCoder *c, uint8_t *const state)
Definition: rangecoder.h:118
avcodec.h
FFV1Context::avctx
AVCodecContext * avctx
Definition: ffv1.h:112
AVCodecParserContext
Definition: avcodec.h:2767
ret
ret
Definition: filter_design.txt:187
close
static void close(AVCodecParserContext *s)
Definition: ffv1_parser.c:73
ff_ffv1_close
av_cold void ff_ffv1_close(FFV1Context *s)
Definition: ffv1.c:227
AVCodecContext
main external API structure.
Definition: avcodec.h:451
ff_ffv1_parse_header
int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
Definition: ffv1_parse.c:201
FFV1Context
Definition: ffv1.h:110
AVCodecParser
Definition: avcodec.h:2926
RangeCoder
Definition: mss3.c:63