Debian Codegraph @

src/videofilters/av1/encoder/av1-encoder.h

raw
1 /*
2 * Copyright (c) 2010-2023 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 #pragma once
22
23 #include <condition_variable>
24 #include <mutex>
25 #include <thread>
26
27 #include <aom/aom_encoder.h>
28 #include <aom/aomcx.h>
29
30 #include "mediastreamer2/msqueue.h"
31 #include "video-encoder.h"
32
33 namespace mediastreamer {
34
35 class Av1Encoder : public VideoEncoder {
36 public:
37 explicit Av1Encoder(MSFactory *factory);
38 virtual ~Av1Encoder();
39
40 MSVideoSize getVideoSize() const override {
41 return mVsize;
42 };
43 void setVideoSize(const MSVideoSize &vsize) override;
44
45 float getFps() const override {
46 return mFps;
47 };
48 void setFps(float fps) override;
49
50 int getBitrate() const override {
51 return mBitrate;
52 };
53 void setBitrate(int bitrate) override;
54
55 bool isRunning() override {
56 return mIsRunning;
57 };
58
59 void configure(bool avpfEnabled);
60
61 void start() override;
62 void stop() override;
63
64 void feed(mblk_t *rawData, uint64_t time, bool requestIFrame) override;
65 bool fetch(MSQueue *encodedData) override;
66
67 void flush();
68
69 protected:
70 void encoderThread();
71
72 MSFactory *mFactory;
73
74 aom_codec_iface_t *mEncoder = nullptr;
75 aom_codec_enc_cfg_t mConfig;
76 aom_codec_ctx_t mCodec;
77
78 MSVideoSize mVsize = MS_VIDEO_SIZE_CIF;
79 float mFps = 0;
80 int mBitrate = 0;
81 bool mIsRunning = false;
82 bool mIframeRequested = false;
83
84 unsigned int mFrameCount = 0;
85
86 // IN frames
87 MSQueue mToEncode;
88 std::mutex mToEncodeMutex;
89 std::condition_variable mToEncodeCondition;
90 bool mFramesAvailable = false;
91
92 // OUT frames
93 MSQueue mEncodedFrames;
94 std::mutex mEncodedFramesMutex;
95
96 std::mutex mCodecMutex;
97
98 std::thread mEncodeThread{};
99 };
100
101 } // namespace mediastreamer