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