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

potential concurrency issue in encoder #130

Open
bmegli opened this issue Mar 20, 2023 · 2 comments
Open

potential concurrency issue in encoder #130

bmegli opened this issue Mar 20, 2023 · 2 comments

Comments

@bmegli
Copy link

bmegli commented Mar 20, 2023

Short Description

  • User's FFmpeg encode2
  • Nvidia's DQThread through capture plane callback

Are accessing same data without thread synchronization.

@bmegli
Copy link
Author

bmegli commented Mar 20, 2023

Long Description

Dequeue Thread

Dequeue thread working through encoder_capture_plane_dq_callback

jetson-ffmpeg/nvmpi_enc.cpp

Lines 354 to 356 in 2006718

ctx->enc->capture_plane.setDQThreadCallback(encoder_capture_plane_dq_callback);
ctx->enc->capture_plane.startDQThread(ctx);

Touching packet_pools

ctx->packet_pools->push(ctx->buf_index);

User's Thread through FFmpeg

FFmpeg encode2

+ .encode2 = nvmpi_encode_frame, \

tapping into nvmpi_encode_frame

+ if(nvmpi_encoder_get_packet(nvmpi_context->ctx,&packet)<0)

Tapping into packet_pools

packet_index= ctx->packet_pools->front();

Consequence

Two threads may access at least packet_pools concurrently (push, pop, front, consuming the data)

@bmegli
Copy link
Author

bmegli commented Mar 20, 2023

This currently doesn't have much impact due to other side effect of jetson-ffmpeg implementation.

More on that in other issue.

Keylost added a commit to Keylost/jetson-ffmpeg that referenced this issue Mar 27, 2023
[*] fixed handling of errors returned in encode2 API
[*] fixed copying of frames to nvbuffer with alignment in the encoder
[+] added memory preallocation for packets to avoid unnecessary copying of the output buffer
[+] enabled max_perf option for the encoder as a workaround to avoid frame rate drops even in MAXN mode (jp5.1)
[*] changed encoder output_plane memory type from userptr to mmap
w3sip pushed a commit to w3sip/jetson-ffmpeg that referenced this issue Mar 31, 2023
[*] fixed handling of errors returned in encode2 API
[*] fixed copying of frames to nvbuffer with alignment in the encoder
[+] added memory preallocation for packets to avoid unnecessary copying of the output buffer
[+] enabled max_perf option for the encoder as a workaround to avoid frame rate drops even in MAXN mode (jp5.1)
[*] changed encoder output_plane memory type from userptr to mmap
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