Skip to content

Commit deae5df

Browse files
committed
vcomp/jpegxs: process the poison pill outside loop
Move processing outside to the main jpegxs_worker_send() loop to make it shorter. One level of indention removed as a consequence.
1 parent 44302a9 commit deae5df

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/video_compress/jpegxs.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

221223
ColourFormat subsampling_to_jpegxs(int ug_subs) {

0 commit comments

Comments
 (0)