FFmpeg  4.3
ffv1dec_template.c
Go to the documentation of this file.
1 /*
2  * FFV1 decoder template
3  *
4  * Copyright (c) 2003-2016 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
24  TYPE *sample[2],
25  int plane_index, int bits)
26 {
27  PlaneContext *const p = &s->plane[plane_index];
28  RangeCoder *const c = &s->c;
29  int x;
30  int run_count = 0;
31  int run_mode = 0;
32  int run_index = s->run_index;
33 
34  if (is_input_end(s))
35  return AVERROR_INVALIDDATA;
36 
37  if (s->slice_coding_mode == 1) {
38  int i;
39  for (x = 0; x < w; x++) {
40  int v = 0;
41  for (i=0; i<bits; i++) {
42  uint8_t state = 128;
43  v += v + get_rac(c, &state);
44  }
45  sample[1][x] = v;
46  }
47  return 0;
48  }
49 
50  for (x = 0; x < w; x++) {
51  int diff, context, sign;
52 
53  if (!(x & 1023)) {
54  if (is_input_end(s))
55  return AVERROR_INVALIDDATA;
56  }
57 
58  context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
59  if (context < 0) {
60  context = -context;
61  sign = 1;
62  } else
63  sign = 0;
64 
65  av_assert2(context < p->context_count);
66 
67  if (s->ac != AC_GOLOMB_RICE) {
69  } else {
70  if (context == 0 && run_mode == 0)
71  run_mode = 1;
72 
73  if (run_mode) {
74  if (run_count == 0 && run_mode == 1) {
75  if (get_bits1(&s->gb)) {
76  run_count = 1 << ff_log2_run[run_index];
77  if (x + run_count <= w)
78  run_index++;
79  } else {
81  run_count = get_bits(&s->gb, ff_log2_run[run_index]);
82  else
83  run_count = 0;
84  if (run_index)
85  run_index--;
86  run_mode = 2;
87  }
88  }
89  if (sample[1][x - 1] == sample[0][x - 1]) {
90  while (run_count > 1 && w-x > 1) {
91  sample[1][x] = sample[0][x];
92  x++;
93  run_count--;
94  }
95  } else {
96  while (run_count > 1 && w-x > 1) {
97  sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
98  x++;
99  run_count--;
100  }
101  }
102  run_count--;
103  if (run_count < 0) {
104  run_mode = 0;
105  run_count = 0;
106  diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
107  bits);
108  if (diff >= 0)
109  diff++;
110  } else
111  diff = 0;
112  } else
113  diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
114 
115  ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
116  run_count, run_index, run_mode, x, get_bits_count(&s->gb));
117  }
118 
119  if (sign)
120  diff = -(unsigned)diff;
121 
122  sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
123  }
124  s->run_index = run_index;
125  return 0;
126 }
127 
128 static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4])
129 {
130  int x, y, p;
131  TYPE *sample[4][2];
132  int lbd = s->avctx->bits_per_raw_sample <= 8;
133  int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
134  int offset = 1 << bits;
135  int transparency = s->transparency;
136 
137  for (x = 0; x < 4; x++) {
138  sample[x][0] = RENAME(s->sample_buffer) + x * 2 * (w + 6) + 3;
139  sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
140  }
141 
142  s->run_index = 0;
143 
144  memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer)));
145 
146  for (y = 0; y < h; y++) {
147  for (p = 0; p < 3 + transparency; p++) {
148  int ret;
149  TYPE *temp = sample[p][0]; // FIXME: try a normal buffer
150 
151  sample[p][0] = sample[p][1];
152  sample[p][1] = temp;
153 
154  sample[p][1][-1]= sample[p][0][0 ];
155  sample[p][0][ w]= sample[p][0][w-1];
156  if (lbd && s->slice_coding_mode == 0)
157  ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
158  else
159  ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
160  if (ret < 0)
161  return ret;
162  }
163  for (x = 0; x < w; x++) {
164  int g = sample[0][1][x];
165  int b = sample[1][1][x];
166  int r = sample[2][1][x];
167  int a = sample[3][1][x];
168 
169  if (s->slice_coding_mode != 1) {
170  b -= offset;
171  r -= offset;
172  g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
173  b += g;
174  r += g;
175  }
176 
177  if (lbd)
178  *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
179  else if (sizeof(TYPE) == 4 || transparency) {
180  *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
181  *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
182  *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
183  if (transparency)
184  *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a;
185  } else {
186  *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
187  *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
188  *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
189  }
190  }
191  }
192  return 0;
193 }
stride
int stride
Definition: mace.c:144
is_input_end
static int is_input_end(FFV1Context *s)
Definition: ffv1dec.c:95
FFV1Context::context_count
int context_count[MAX_QUANT_TABLES]
Definition: ffv1.h:105
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
b
#define b
Definition: input.c:41
PlaneContext::state
uint8_t(* state)[CONTEXT_SIZE]
Definition: ffv1.h:71
decode_line
static av_always_inline int RENAME() decode_line(FFV1Context *s, int w, TYPE *sample[2], int plane_index, int bits)
Definition: ffv1dec_template.c:23
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
get_symbol_inline
static av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, int is_signed)
Definition: ffv1dec.c:41
s
#define s(width, name)
Definition: cbs_vp9.c:257
g
const char * g
Definition: vf_curves.c:115
bits
uint8_t bits
Definition: vp3data.h:202
get_vlc_symbol
static int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits)
Definition: ffv1dec.c:70
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
PlaneContext::vlc_state
VlcState * vlc_state
Definition: ffv1.h:72
AC_GOLOMB_RICE
#define AC_GOLOMB_RICE
Definition: ffv1.h:55
ff_log2_run
const uint8_t ff_log2_run[41]
Definition: bitstream.c:39
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
src
#define src
Definition: vp8dsp.c:254
TYPE
#define TYPE
Definition: ffv1.h:195
PlaneContext
Definition: ffv1.h:67
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_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
sample
#define sample
Definition: flacdsp_template.c:44
state
static struct @314 state
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
r
#define r
Definition: input.c:40
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
predict
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec.c:174
RENAME
#define RENAME(name)
Definition: ffv1.h:196
av_always_inline
#define av_always_inline
Definition: attributes.h:49
SUINT
#define SUINT
Definition: dct32_template.c:30
uint8_t
uint8_t
Definition: audio_convert.c:194
get_rac
static int get_rac(RangeCoder *c, uint8_t *const state)
Definition: rangecoder.h:136
ret
ret
Definition: filter_design.txt:187
w
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o w
Definition: fate.txt:150
decode_rgb_frame
static int RENAME() decode_rgb_frame(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4])
Definition: ffv1dec_template.c:128
temp
else temp
Definition: vf_mcdeint.c:256
FFV1Context
Definition: ffv1.h:78
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
FFV1Context::transparency
int transparency
Definition: ffv1.h:91
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
h
h
Definition: vp9dsp_template.c:2038
RangeCoder
Definition: mss3.c:61
FFV1Context::run_index
int run_index
Definition: ffv1.h:108
get_context
static int RENAME() get_context(PlaneContext *p, TYPE *src, TYPE *last, TYPE *last2)
Definition: ffv1_template.c:32