Debian Codegraph @

src/videofilters/h26x/nal-unpacker.h

raw symbols SCIP
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
25 #include <ortp/str_utils.h>
26
27 #include "mediastreamer2/msqueue.h"
28
29 namespace mediastreamer {
30
31 class NalUnpacker {
32 public:
33 struct Status {
34 bool frameAvailable = false;
35 bool frameCorrupted = false;
36 bool isKeyFrame = false;
37
38 Status &operator|=(const Status &s2);
39 unsigned int toUInt() const;
40 };
41
42 class FuAggregatorInterface {
43 public:
44 virtual ~FuAggregatorInterface() {
45 if (_m) freemsg(_m);
46 }
47 virtual mblk_t *feed(mblk_t *packet) = 0;
48 virtual bool isAggregating() const = 0;
49 virtual void reset() = 0;
50 virtual mblk_t *completeAggregation() = 0;
51
52 protected:
53 mblk_t *_m = nullptr;
54 };
55
56 class ApSpliterInterface {
57 public:
58 ApSpliterInterface() {
59 ms_queue_init(&_q);
60 }
61 virtual ~ApSpliterInterface() {
62 ms_queue_flush(&_q);
63 }
64 virtual void feed(mblk_t *packet) = 0;
65 virtual MSQueue *getNalus() = 0;
66
67 protected:
68 MSQueue _q;
69 };
70
71 NalUnpacker(FuAggregatorInterface *aggregator, ApSpliterInterface *spliter);
72 virtual ~NalUnpacker() {
73 ms_queue_flush(&_q);
74 }
75
76 /**
77 * Process incoming rtp data and output NALUs, whenever possible.
78 * @param ctx the Rfc3984Context object
79 * @param im a new H264 packet to process
80 * @param naluq a MSQueue into which a frame ready to be decoded will be output, in the form of a sequence of NAL
81 *units.
82 * @return a bitmask of Rfc3984Status values.
83 * The return value is a bitmask of the #Rfc3984Status enum.
84 **/
85 MS2_PUBLIC Status unpack(mblk_t *im, MSQueue *out);
86 void reset();
87
88 protected:
89 enum class PacketType { SingleNalUnit, AggregationPacket, FragmentationUnit };
90
91 virtual Status outputFrame(MSQueue *out, const Status &flags);
92 virtual void storeNal(mblk_t *nal);
93
94 virtual PacketType getNaluType(const mblk_t *nalu) const = 0;
95
96 MSQueue _q;
97 Status _status;
98 uint32_t _lastTs = 0x943FEA43;
99 bool _initializedRefCSeq = false;
100 uint16_t _refCSeq = 0;
101 std::unique_ptr<FuAggregatorInterface> _fuAggregator;
102 std::unique_ptr<ApSpliterInterface> _apSpliter;
103 };
104
105 } // namespace mediastreamer