[Libav-user] RTP data stream

Yury Kisliak fas.ysk at gmail.com
Fri Jan 11 18:18:31 EET 2019


Hi ! Is there any example/pseudocode  how to create RTP stream
with custom binary data ?
My code looks like:

bool init_data_stream() {
ConfigReader *cfg = ConfigReader::getInstance();
int nRet = avformat_alloc_output_context2(&m_pDataOC, nullptr, "rtp",
cfg->dataUrl);
if((m_pDataOC == nullptr) || (nRet != 0)) {
return false;
}

m_osData = new OutputStream();
m_osData->st = avformat_new_stream(m_pDataOC, nullptr);
m_osData->st->time_base    = { 1, 1000 };
m_osData->st->r_frame_rate = frame_rate;
m_osData->st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
m_osData->st->codecpar->codec_id    = AV_CODEC_ID_MPEG2TS;

av_dump_format(m_pDataOC, 0, cfg->dataUrl, 1);

AVDictionary* options = 0;
nRet = avio_open2(&m_pDataOC->pb, cfg->dataUrl, AVIO_FLAG_WRITE, nullptr,
&options);
if(nRet != 0) {
return false;
}

nRet = avformat_write_header(m_pDataOC, nullptr);

if(nRet < 0) {
m_osData = nullptr;
return false;
}

return true;
}

then

uint8_t sendData(uint8_t *pDataBuf, const size_t &size) {
uint8_t nResD = 0;
if(pDataBuf && size && m_osData) {
AVPacket pkt = { 0 };
av_init_packet(&pkt);
nResD = av_packet_from_data(&pkt, pDataBuf, size);
pkt.pts = av_rescale_q(m_osData->next_pts++, frame_rate,
m_osData->st->time_base);
pkt.duration = av_rescale_q(1, frame_rate, m_osData->st->time_base);
nResD = av_interleaved_write_frame(m_pDataOC, &pkt); // <- CRASH
av_packet_unref(&pkt);
}
return  nResD;
}

Thanks.


--
theFast
*fas.ysk at gmail.com <fas.ysk at gmail.com>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190111/e1551daf/attachment.html>


More information about the Libav-user mailing list