GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/codec2utils.h Lines: 0 7 0.0 %
Date: 2020-11-28 20:53:16 Branches: 0 0 - %

Line Branch Exec Source
1
/*
2
 * codec2 utility functions
3
 * Copyright (c) 2017 Tomas Härdin
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
#ifndef AVCODEC_CODEC2UTILS_H
23
#define AVCODEC_CODEC2UTILS_H
24
25
#include <stdint.h>
26
27
#include "version.h"
28
29
//Highest mode we're willing to use.
30
//Don't want to let users accidentally produce files that can't be decoded in the future.
31
//CODEC2_MODE_WB (9) is experimental/unstable as of 2017-11-23.
32
#define CODEC2_MODE_MAX 8 //CODEC2_MODE_700C
33
34
//Used by both codec2raw demuxer and libcodec2 encoder.
35
//The integers match the values in codec2.h, so "3200" -> CODEC2_MODE_3000 = 0 and so on.
36
//It is possible that we're linked to a version of libcodec2 that lacks some of these modes.
37
//For example Debian stretch ships with libcodec2.so.0.4 which lacks CODEC2_MODE_700C.
38
#define CODEC2_AVOPTIONS(desc, classname, min_val, default_val, option_flags) \
39
    { "mode", desc, offsetof(classname, mode), AV_OPT_TYPE_INT, {.i64 = default_val}, min_val, CODEC2_MODE_MAX, .flags=option_flags, .unit="codec2_mode"},\
40
    { "3200", "3200", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, .flags=option_flags, .unit="codec2_mode"},\
41
    { "2400", "2400", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, .flags=option_flags, .unit="codec2_mode"},\
42
    { "1600", "1600", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, .flags=option_flags, .unit="codec2_mode"},\
43
    { "1400", "1400", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, .flags=option_flags, .unit="codec2_mode"},\
44
    { "1300", "1300", 0, AV_OPT_TYPE_CONST, {.i64 = 4}, .flags=option_flags, .unit="codec2_mode"},\
45
    { "1200", "1200", 0, AV_OPT_TYPE_CONST, {.i64 = 5}, .flags=option_flags, .unit="codec2_mode"},\
46
    { "700",  "700",  0, AV_OPT_TYPE_CONST, {.i64 = 6}, .flags=option_flags, .unit="codec2_mode"},\
47
    { "700B", "700B", 0, AV_OPT_TYPE_CONST, {.i64 = 7}, .flags=option_flags, .unit="codec2_mode"},\
48
    { "700C", "700C", 0, AV_OPT_TYPE_CONST, {.i64 = 8}, .flags=option_flags, .unit="codec2_mode"}
49
50
#if LIBAVCODEC_VERSION_MAJOR < 59
51
//The three following functions are here to avoid needing libavformat/codec2.c to depend on libcodec2
52
53
//Computes bitrate from mode, with frames rounded up to the nearest octet.
54
//So 700 bit/s (28 bits/frame) becomes 800 bits/s (32 bits/frame).
55
//logctx is used for av_log()
56
//Returns <0 if mode is invalid
57
int avpriv_codec2_mode_bit_rate(void *logctx, int mode);
58
59
//Mimics codec2_samples_per_frame()
60
int avpriv_codec2_mode_frame_size(void *logctx, int mode);
61
62
//Mimics (codec2_bits_per_frame()+7)/8
63
int avpriv_codec2_mode_block_align(void *logctx, int mode);
64
#endif
65
66
#define CODEC2_EXTRADATA_SIZE 4
67
68
//Used in codec2raw demuxer and libcodec2 encoder
69
static inline void codec2_make_extradata(uint8_t *ptr, int mode) {
70
    //version 0.8 as of 2017-12-23 (r3386)
71
    ptr[0] = 0;     //major
72
    ptr[1] = 8;     //minor
73
    ptr[2] = mode;  //mode
74
    ptr[3] = 0;     //flags
75
}
76
77
static inline uint8_t codec2_mode_from_extradata(uint8_t *ptr) {
78
    return ptr[2];
79
}
80
81
#endif /* AVCODEC_CODEC2UTILS_H */