| 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 "h264-nal-packer.h" |
| 22 |
#include "h264-nal-unpacker.h" |
| 23 |
#include "h264-utils.h" |
| 24 |
|
| 25 |
#include "mediastreamer2/rfc3984.h" |
| 26 |
|
| 27 |
//================================================== |
| 28 |
// C wrapper implementation |
| 29 |
//================================================== |
| 30 |
|
| 31 |
struct _Rfc3984Context { |
| 32 |
mediastreamer::H264NalPacker packer; |
| 33 |
mediastreamer::H264NalUnpacker unpacker; |
| 34 |
mediastreamer::H264FrameAnalyser analyser; |
| 35 |
|
| 36 |
_Rfc3984Context(MSFactory *factory) : packer(ms_factory_get_payload_max_size(factory)) { |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
extern "C" { |
| 41 |
|
| 42 |
Rfc3984Context *rfc3984_new_with_factory(MSFactory *factory) { |
| 43 |
return new _Rfc3984Context(factory); |
| 44 |
} |
| 45 |
|
| 46 |
void rfc3984_destroy(Rfc3984Context *ctx) { |
| 47 |
delete ctx; |
| 48 |
} |
| 49 |
|
| 50 |
void rfc3984_set_mode(Rfc3984Context *ctx, int mode) { |
| 51 |
if (mode < 0 || mode > 1) { |
| 52 |
ms_error("invalid RFC3984 packetization mode [%d]", mode); |
| 53 |
return; |
| 54 |
} |
| 55 |
ctx->packer.setPacketizationMode(mode == 0 ? mediastreamer::NalPacker::SingleNalUnitMode |
| 56 |
: mediastreamer::NalPacker::NonInterleavedMode); |
| 57 |
} |
| 58 |
|
| 59 |
void rfc3984_enable_stap_a(Rfc3984Context *ctx, bool_t yesno) { |
| 60 |
ctx->packer.enableAggregation(!!yesno); |
| 61 |
} |
| 62 |
|
| 63 |
void rfc3984_pack(Rfc3984Context *ctx, MSQueue *naluq, MSQueue *rtpq, uint32_t ts) { |
| 64 |
ctx->packer.pack(naluq, rtpq, ts); |
| 65 |
} |
| 66 |
|
| 67 |
void rfc3984_unpack_out_of_band_sps_pps(Rfc3984Context *ctx, mblk_t *sps, mblk_t *pps) { |
| 68 |
ctx->unpacker.setOutOfBandSpsPps(sps, pps); |
| 69 |
} |
| 70 |
|
| 71 |
unsigned int rfc3984_unpack2(Rfc3984Context *ctx, mblk_t *im, MSQueue *naluq) { |
| 72 |
MSQueue q; |
| 73 |
ms_queue_init(&q); |
| 74 |
unsigned int status = ctx->unpacker.unpack(im, &q).toUInt(); |
| 75 |
if (status & Rfc3984FrameAvailable) { |
| 76 |
status |= ctx->analyser.analyse(&q).toUInt(); |
| 77 |
while (mblk_t *m = ms_queue_get(&q)) { |
| 78 |
ms_queue_put(naluq, m); |
| 79 |
} |
| 80 |
} |
| 81 |
return status; |
| 82 |
} |
| 83 |
|
| 84 |
} // extern "C" |