Line data Source code
1 : /*
2 : * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program 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
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 : */
17 : #pragma once
18 :
19 : extern "C" {
20 : #include <libavcodec/avcodec.h>
21 : }
22 :
23 : namespace jami {
24 :
25 : /**
26 : * Attempt to find standalone AVCodec decoder using AVCodecID,
27 : * or fallback to the default decoder.
28 : */
29 : inline const AVCodec*
30 323 : findDecoder(const enum AVCodecID codec_id)
31 : {
32 : const char* codec_name;
33 323 : switch (codec_id) {
34 : #if 0 && defined(__ANDROID__) && defined(ENABLE_HWACCEL)
35 : case AV_CODEC_ID_MPEG4:
36 : codec_name = "mpeg4_mediacodec"; break;
37 : case AV_CODEC_ID_H264:
38 : codec_name = "h264_mediacodec"; break;
39 : case AV_CODEC_ID_HEVC:
40 : codec_name = "hevc_mediacodec"; break;
41 : case AV_CODEC_ID_VP8:
42 : codec_name = "vp8_mediacodec"; break;
43 : case AV_CODEC_ID_VP9:
44 : codec_name = "vp9_mediacodec"; break;
45 : #endif
46 180 : case AV_CODEC_ID_OPUS:
47 180 : codec_name = "libopus";
48 180 : break;
49 143 : default:
50 143 : codec_name = nullptr;
51 : }
52 323 : const AVCodec* codec = nullptr;
53 323 : if (codec_name)
54 180 : codec = avcodec_find_decoder_by_name(codec_name);
55 323 : if (not codec)
56 143 : codec = avcodec_find_decoder(codec_id);
57 323 : return codec;
58 : }
59 :
60 : } // namespace jami
|