@@ -146,25 +146,10 @@ static void jpegxs_worker_send(state_video_compress_jpegxs *s) {
146146 while (true ) {
147147 auto frame = s->in_queue .pop ();
148148
149- if (!frame) { // poison pill received
150- unique_lock<mutex> lock (s->mtx );
151- if (s->configured_consumer ) { // pass it further
152- lock.unlock ();
153- svt_jpeg_xs_frame_t enc_input;
154- svt_jpeg_xs_frame_pool_get (s->frame_pool , &enc_input, /* blocking*/ 1 );
155- enc_input.user_prv_ctx_ptr = JXS_POISON_PILL;
156- SvtJxsErrorType_t err = svt_jpeg_xs_encoder_send_picture (
157- &s->encoder , &enc_input,
158- /* blocking*/ 1 );
159- assert (err == SvtJxsErrorNone);
160- } else { // the encoder has not bee configured yet
161- s->stop_consumer = true ;
162- lock.unlock ();
163- s->cv_configured_consumer .notify_one ();
164- }
149+ if (!frame) { // poison pill received - process after the loop
165150 break ;
166151 }
167-
152+
168153 struct video_desc desc = video_desc_from_frame (frame.get ());
169154 if (!video_desc_eq_excl_param (desc, saved_desc, PARAM_INTERLACING)) {
170155 s->mtx .lock ();
@@ -216,6 +201,23 @@ static void jpegxs_worker_send(state_video_compress_jpegxs *s) {
216201 continue ;
217202 }
218203 }
204+
205+ // process poison pill
206+ unique_lock<mutex> lock (s->mtx );
207+ if (s->configured_consumer ) { // pass it further
208+ lock.unlock ();
209+ svt_jpeg_xs_frame_t enc_input;
210+ svt_jpeg_xs_frame_pool_get (s->frame_pool , &enc_input, /* blocking*/ 1 );
211+ enc_input.user_prv_ctx_ptr = JXS_POISON_PILL;
212+ SvtJxsErrorType_t err = svt_jpeg_xs_encoder_send_picture (
213+ &s->encoder , &enc_input,
214+ /* blocking*/ 1 );
215+ assert (err == SvtJxsErrorNone);
216+ } else { // the encoder has not bee configured yet
217+ s->stop_consumer = true ;
218+ lock.unlock ();
219+ s->cv_configured_consumer .notify_one ();
220+ }
219221}
220222
221223ColourFormat subsampling_to_jpegxs (int ug_subs) {
0 commit comments