2018-10-31 09:36:12 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-31 09:36:12 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2018-10-31 09:36:12 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
2018-10-31 09:36:12 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "RtpCodec.h"
|
|
|
|
|
|
|
|
|
|
namespace mediakit{
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, size_t len, bool mark, uint32_t stamp) {
|
|
|
|
|
uint16_t payload_len = (uint16_t)(len + 12);
|
|
|
|
|
uint32_t ts = htonl((_ui32SampleRate / 1000) * stamp);
|
2018-10-31 09:36:12 +08:00
|
|
|
|
uint16_t sq = htons(_ui16Sequence);
|
|
|
|
|
uint32_t sc = htonl(_ui32Ssrc);
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
auto rtp_ptr = ResourcePoolHelper<RtpPacket>::obtainObj();
|
|
|
|
|
rtp_ptr->setCapacity(len + 16);
|
|
|
|
|
rtp_ptr->setSize(len + 16);
|
|
|
|
|
|
|
|
|
|
auto *rtp = (unsigned char *)rtp_ptr->data();
|
|
|
|
|
rtp[0] = '$';
|
|
|
|
|
rtp[1] = _ui8Interleaved;
|
|
|
|
|
rtp[2] = payload_len >> 8;
|
|
|
|
|
rtp[3] = payload_len & 0xFF;
|
|
|
|
|
rtp[4] = 0x80;
|
|
|
|
|
rtp[5] = (mark << 7) | _ui8PayloadType;
|
|
|
|
|
memcpy(&rtp[6], &sq, 2);
|
|
|
|
|
memcpy(&rtp[8], &ts, 4);
|
2018-10-31 09:36:12 +08:00
|
|
|
|
//ssrc
|
2021-01-17 18:31:50 +08:00
|
|
|
|
memcpy(&rtp[12], &sc, 4);
|
2019-09-06 15:16:22 +08:00
|
|
|
|
|
|
|
|
|
if(data){
|
2020-05-25 13:51:00 +08:00
|
|
|
|
//payload
|
2021-01-17 18:31:50 +08:00
|
|
|
|
memcpy(&rtp[16], data, len);
|
2019-09-06 15:16:22 +08:00
|
|
|
|
}
|
2018-10-31 09:36:12 +08:00
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
rtp_ptr->PT = _ui8PayloadType;
|
|
|
|
|
rtp_ptr->interleaved = _ui8Interleaved;
|
|
|
|
|
rtp_ptr->mark = mark;
|
|
|
|
|
rtp_ptr->sequence = _ui16Sequence;
|
|
|
|
|
rtp_ptr->timeStamp = stamp;
|
|
|
|
|
rtp_ptr->ssrc = _ui32Ssrc;
|
|
|
|
|
rtp_ptr->type = type;
|
|
|
|
|
rtp_ptr->offset = 16;
|
2018-10-31 09:36:12 +08:00
|
|
|
|
_ui16Sequence++;
|
2021-01-17 18:31:50 +08:00
|
|
|
|
_ui32TimeStamp = stamp;
|
|
|
|
|
return rtp_ptr;
|
2018-10-31 09:36:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//namespace mediakit
|
|
|
|
|
|
|
|
|
|
|