Debian Codegraph @

src/videofilters/h26x/media-codec-h265-encoder.cpp

raw
1 /*
2 * Copyright (c) 2010-2022 Belledonne Communications SARL.
3 *
4 * This file is part of mediastreamer2
5 * (see https://gitlab.linphone.org/BC/public/mediastreamer2).
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program 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
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "filter-wrapper/encoding-filter-wrapper.h"
22 #include "h26x-encoder-filter.h"
23 #include "media-codec-encoder.h"
24
25 #define MS_MEDIACODECH265_CONF(required_bitrate, bitrate_limit, resolution, fps, ncpus) \
26 { \
27 required_bitrate, bitrate_limit, {MS_VIDEO_SIZE_##resolution##_W, MS_VIDEO_SIZE_##resolution##_H}, fps, ncpus, \
28 nullptr \
29 }
30
31 static const MSVideoConfiguration _media_codec_h265_conf_list[] = {
32 /*
33 * Formats above 720P are disabled. Indeed, there are not supported in baseline profile of H264, and it was observed
34 * that when we ask a MediaCodec to output a 1080P stream with baseline profile, we get interoperability issues:
35 * the remote decoder decodes it improperly, even on iOS.
36 * TODO: enable use of higher profiles to use formats above 720P.
37 */
38 #if 0
39 MS_MEDIACODECH265_CONF(2048000, 5000000, UXGA, 25, 2),
40 MS_MEDIACODECH265_CONF(1500000, 3000000, SXGA_MINUS, 25, 2),
41 #endif
42 MS_MEDIACODECH265_CONF(1024000, 2048000, 720P, 30, 2), MS_MEDIACODECH265_CONF(850000, 2048000, XGA, 25, 2),
43 MS_MEDIACODECH265_CONF(750000, 1500000, SVGA, 30, 2), MS_MEDIACODECH265_CONF(600000, 3000000, VGA, 30, 2),
44 MS_MEDIACODECH265_CONF(400000, 800000, VGA, 15, 2), MS_MEDIACODECH265_CONF(128000, 512000, CIF, 15, 1),
45 MS_MEDIACODECH265_CONF(100000, 380000, QVGA, 15, 1), MS_MEDIACODECH265_CONF(0, 170000, QCIF, 10, 1),
46 };
47
48 namespace mediastreamer {
49
50 class MediaCodecH265Encoder : public MediaCodecEncoder {
51 public:
52 MediaCodecH265Encoder() : MediaCodecEncoder("video/hevc") {
53 }
54 };
55
56 class MediaCodecH265EncoderFilterImpl : public H26xEncoderFilter {
57 public:
58 MediaCodecH265EncoderFilterImpl(MSFilter *f)
59 : H26xEncoderFilter(f, new MediaCodecH265Encoder(), _media_codec_h265_conf_list) {
60 SoundDeviceDescription *info = ms_devices_info_get_sound_device_description(f->factory->devices_info);
61 auto &encoder = static_cast<MediaCodecEncoder &>(*_encoder);
62 encoder.enableOutbufferDequeueLimit(!!(info->flags & DEVICE_MCH265_LIMIT_DEQUEUE_OF_OUTPUT_BUFFERS));
63 }
64 };
65
66 } // namespace mediastreamer
67
68 using namespace mediastreamer;
69
70 MS_ENCODING_FILTER_WRAPPER_METHODS_DECLARATION(MediaCodecH265Encoder);
71 MS_ENCODING_FILTER_WRAPPER_DESCRIPTION_DECLARATION(MediaCodecH265Encoder,
72 MS_MEDIACODEC_H265_ENC_ID,
73 "A H265 encoder based on MediaCodec API.",
74 "H265",
75 MS_FILTER_IS_PUMP | MS_FILTER_IS_HW_ACCELERATED);