Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JitterBufferPacket::data and data ownership #37

Open
Krzmbrzl opened this issue Nov 19, 2021 · 1 comment
Open

JitterBufferPacket::data and data ownership #37

Krzmbrzl opened this issue Nov 19, 2021 · 1 comment

Comments

@Krzmbrzl
Copy link

The JitterBufferPacket::data field currently has type char *:

char *data; /**< Data bytes contained in the packet */

However, from the documentation it is not clear, whether the JitterBuffer will take ownership of the pointer or not. From the code I found here

if (jitter->destroy)
{
jitter->packets[i].data = packet->data;
} else {
jitter->packets[i].data=(char*)speex_alloc(packet->len);
for (j=0;j<packet->len;j++)
jitter->packets[i].data[j]=packet->data[j];
}

it seems that it depends on whether JitterBuffer::destroy was set (via jitter-buffer_ctl) which I think could be translated as "If the caller has set up a special deleter for the jitter data, the JitterBuffer will take ownership of the contained data (in the sense that it calls that deleter on it once it is done with it) and otherwise it does not take ownership but instead copies the data to an internal buffer.

I think in the second scenario, it would be good for the overall semantics, if JitterBufferPacket::data would become const char * to indicate that it will not be modified. However, that probably causes issues with the first scenario and also with backwards compatibility.

So in the end, I think it should just be documented more explicitly what happens with the passed pointer and who is responsible for freeing it.

@Krzmbrzl
Copy link
Author

Just found this, which supports my findings:

/** Assign a function to destroy unused packet. When setting that, the jitter
buffer no longer copies packet data. */
#define JITTER_BUFFER_SET_DESTROY_CALLBACK 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant