On Fri Jun 30 04:01:38 2023 +0000, Ziqing Hui wrote:
I tried the unlinking/linking stream decodebin approach. However, it's really complex to implement that, because changing pipeline dynamically needs to consider a lot of stuff (eg. renegotiate caps, seek to restart pipeline, flush previous buffers). Also, buffer loss happens because of the pipeline changes. Instead, adding a probe is quite simple and easy to implement.
Using a probe means that the samples will get fed into the decodebin
anyway, which ends up just wasting CPU on decoding. We can prevent the buffer from going into stream decodebin by return GST_PAD_PROBE_DROP or GST_PAD_PROBE_HANDLED in probe.
Consider the following code:
``` foo() { [...] reader_OpenStream(); reader_SetReadStreamSamples(TRUE); reader_GetNextSample(reader); [...] } ```
After OpenStream, the decoding thread in our pipeline is already started. So before SetReadStreamSamples, there is posibility that a uncompressed frame, which is the first frame, is already in our stream->buffer. If we detach the stream decodebin in SetReadStreamSamples, the compressed buffer we grab in GetNextSample is the second frame, unless we seek to where we want to be.
Adding a probe to grab compressed buffer will avoid this problem, because we always record the compressed buffer even if the stream is not set to output compressed. We don't have buffer loss when changing from uncompressed state to compressed state.