akanchi / mpegts

A simple implementation of mpegts(including muxer and demuxer)
MIT License
25 stars 17 forks source link

simplebuffer append #5

Closed andersc closed 4 years ago

andersc commented 4 years ago

When appending bytes

void SimpleBuffer::append(const char* bytes, int size)
{
    if (size <= 0)
        return;

    _data.insert(_data.end(), bytes, bytes + size);
    _pos += size;
}

pos will be size if pos is 0 That means that ->

bool SimpleBuffer::empty()
{
    return _pos >= (int)_data.size();
}

Empty will be true (but it should not be) .. Or am I missing something?

akanchi commented 4 years ago

When appending bytes

void SimpleBuffer::append(const char* bytes, int size)
{
    if (size <= 0)
        return;

    _data.insert(_data.end(), bytes, bytes + size);
    _pos += size;
}

pos will be size if pos is 0 That means that ->

bool SimpleBuffer::empty()
{
    return _pos >= (int)_data.size();
}

Empty will be true (but it should not be) .. Or am I missing something?

There is a bug here. Maybe you can skip(-size) temporarily to avoid this problem.

andersc commented 4 years ago

The problem for me is that it's used in the demuxer

int MpegTsDemuxer::decode(SimpleBuffer *in, TsFrame *&out)
{
    while (!in->empty()) {

meaning it will never parse any bytes.. I just removed the line _pos += size; in my fork but that might cause other problems I'm unaware of.

akanchi commented 4 years ago

When appending/writing bytes, do not change pos, pos should only be used to read buffer.