uvgRTP: H264 Failed to flush the message queue

I see the same issue with RTP_FORMAT_H264, both with master and 2.3.0. However when I change it to H265 the problem goes away. This is really frustrating as I really like the API and easy of use, but looking at a bunch of h.264 issues reported here I can say claiming this library supports h.264 is a very bold statement - it should come with (alpha) disclaimer.

The problem is really easy to repro and it happens on both macOS and Ubuntu 22.04, and it looks like some sort of memory corruption issue when a big frame is being fragmented. Here’s the test app (forwarding RTP from one port to another):

uvgrtp::context ctx;
uvgrtp::session *sess = ctx.create_session("127.0.0.1");
uvgrtp::media_stream *stream = sess->create_stream(8890, 8891, RTP_FORMAT_H264, RTP_NO_FLAGS);

while (true) {
    uvgrtp::frame::rtp_frame* frame = stream->pull_frame(1000);
    if (frame) {
        auto ret = stream->push_frame(frame->payload, frame->payload_len, RTP_COPY);
        std::cout << frame->payload_len << " bytes, res: " << ret << std::endl;
    }
}

and the output is (see how the error pops up on a large NALU)

[uvgRTP][ERROR][::flush_queue] Failed to flush the message queue: 14
29564 bytes, res: -5
9 bytes, res: 0
4400 bytes, res: 0
9 bytes, res: 0
3189 bytes, res: 0
12 bytes, res: 0
9 bytes, res: 0

Commented by @witaly-iwanow in https://github.com/ultravideo/uvgRTP/issues/201#issuecomment-1773673366

I tried to debug sendmmsg calls and I could see it fragments a NALU into something like 1200+1200+1200+…+300 byte chunks - all good at this point, but after that there are 20-30 tiny packets with apparently bogus destination address it tries to send out

Link https://github.com/ultravideo/uvgRTP/issues/201#issuecomment-1773674705

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hello,

This issue should be fixed by the new release 3.1.0. If you run into any further problems, feel free to open a new issue on the topic!

I did some more debugging based on the reproducible failure above and got a bit closer to the root cause. The issue seems to be caused in uvgrtp::formats::h264::fu_division: https://github.com/ultravideo/uvgRTP/blob/ecf65ba5b0a0d67ebfd71d023e1f9c62eb48274d/src/formats/h264.cc#L161-L164 Only the first three elements of the buffer vector are used, however the buffer vector is not cleared for multiple invocations of fu_division, so if the packet contains multiple NALus that need to be fragmented, there will be extra data in buffers when they are later passed to enqueue (containing nullptr entries).