msac.h 2.46 KB
Newer Older
1
/*
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
2 3 4
 * Copyright © 2018, VideoLAN and dav1d authors
 * Copyright © 2018, Two Orioles, LLC
 * All rights reserved.
5
 *
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 27 28 29 30 31 32 33
 */

#ifndef __DAV1D_SRC_MSAC_H__
#define __DAV1D_SRC_MSAC_H__

#include <stdint.h>
#include <stdlib.h>

Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
34 35 36
/* Using uint32_t should be faster on 32 bit systems, in theory, maybe */
typedef uint64_t ec_win;

37
typedef struct MsacContext {
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
38 39 40
    const uint8_t *buf_pos;
    const uint8_t *buf_end;
    ec_win dif;
41
    uint16_t rng;
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
42
    int cnt;
43
    int allow_update_cdf;
44 45
} MsacContext;

Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
46 47 48
#define EC_PROB_SHIFT 6
#define EC_BOOL_EPROB 256

49
void msac_init(MsacContext *c, const uint8_t *data, size_t sz, int disable_cdf_update_flag);
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
50
unsigned msac_decode_symbol(MsacContext *s, const uint16_t *cdf,
51
                            const unsigned n_symbols);
52 53
unsigned msac_decode_symbol_adapt(MsacContext *s, uint16_t *cdf,
                                  const unsigned n_symbols);
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
54
unsigned msac_decode_bool(MsacContext *s, unsigned f);
55
unsigned msac_decode_bool_adapt(MsacContext *s, uint16_t *cdf);
56
unsigned msac_decode_bools(MsacContext *c, unsigned l);
Rostislav Pehlivanov's avatar
Rostislav Pehlivanov committed
57
int msac_decode_subexp(MsacContext *c, int ref, int n, unsigned k);
58 59 60
int msac_decode_uniform(MsacContext *c, unsigned n);

#endif /* __DAV1D_SRC_MSAC_H__ */