Debian Codegraph @

src/videofilters/h26x/media-codec-decoder.h

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 #pragma once
22
23 #include <memory>
24 #include <vector>
25
26 #include "h26x-decoder.h"
27 #include "h26x-utils.h"
28 #include "media/NdkMediaCodec.h"
29 #include "mediastreamer2/msvideo.h"
30
31 namespace mediastreamer {
32
33 class MediaCodecDecoder : public H26xDecoder {
34 public:
35 virtual ~MediaCodecDecoder();
36
37 void waitForKeyFrame() override {
38 _needKeyFrame = true;
39 }
40
41 bool feed(MSQueue *encodedFrame, uint64_t timestamp) override;
42 Status fetch(mblk_t *&frame) override;
43
44 protected:
45 class BufferFlag {
46 public:
47 static const uint32_t None = 0;
48 static const uint32_t KeyFrame = 1;
49 static const uint32_t CodecConfig = 1 << 1;
50 static const uint32_t EndOfStream = 1 << 2;
51 static const uint32_t PartialFrame = 1 << 3;
52 };
53
54 MediaCodecDecoder(const std::string &mime);
55 virtual bool setParameterSets(MSQueue *parameterSet, uint64_t timestamp);
56 AMediaFormat *createFormat(bool withLowLatency) const;
57 void startImpl();
58 void stopImpl() noexcept;
59 void resetImpl() noexcept;
60 bool feed(MSQueue *encodedFrame, uint64_t timestamp, bool isPs);
61 bool isKeyFrame(const MSQueue *frame) const;
62 static std::string codecInfoToString(ssize_t codecStatusCode);
63
64 AMediaCodec *_impl = nullptr;
65 AMediaFormat *_format = nullptr;
66 MSYuvBufAllocator *_bufAllocator = nullptr;
67 std::unique_ptr<H26xNaluHeader> _naluHeader;
68 std::unique_ptr<H26xParameterSetsStore> _psStore;
69 int _pendingFrames = 0;
70 int32_t _curWidth = 0, _curHeight = 0;
71 bool _needKeyFrame = true;
72 bool _needParameters = true;
73
74 static const unsigned int _timeoutUs = 0;
75 };
76
77 } // namespace mediastreamer