running = false;
should_quit = true;
any_frames_to_be_encoded.notify_all();
+ any_frames_encoding.notify_all();
encoder_thread.join();
if (va_dpy != nullptr) {
va_receiver_thread.join();
} else {
// Encode synchronously, in the same thread.
vector<uint8_t> jpeg = encode_jpeg_libjpeg(qf);
- write_mjpeg_packet(qf.pts, qf.card_index, jpeg);
+ write_mjpeg_packet(qf.pts, qf.card_index, jpeg.data(), jpeg.size());
}
}
free(tmp_cr);
}
-void MJPEGEncoder::write_mjpeg_packet(int64_t pts, unsigned card_index, const vector<uint8_t> &jpeg)
+void MJPEGEncoder::write_mjpeg_packet(int64_t pts, unsigned card_index, const uint8_t *jpeg, size_t jpeg_size)
{
AVPacket pkt;
memset(&pkt, 0, sizeof(pkt));
pkt.buf = nullptr;
- pkt.data = const_cast<uint8_t *>(&jpeg[0]);
- pkt.size = jpeg.size();
+ pkt.data = const_cast<uint8_t *>(jpeg);
+ pkt.size = jpeg_size;
pkt.stream_index = card_index;
pkt.flags = AV_PKT_FLAG_KEY;
AVRational time_base = avctx->streams[pkt.stream_index]->time_base;
va_status = vaMapBuffer(va_dpy->va_dpy, qf.resources.data_buffer, (void **)&segment);
CHECK_VASTATUS(va_status, "vaMapBuffer");
- const char *coded_buf = reinterpret_cast<char *>(segment->buf);
- vector<uint8_t> jpeg(coded_buf, coded_buf + segment->size);
+ const uint8_t *coded_buf = reinterpret_cast<uint8_t *>(segment->buf);
+ write_mjpeg_packet(qf.pts, qf.card_index, coded_buf, segment->size);
va_status = vaUnmapBuffer(va_dpy->va_dpy, qf.resources.data_buffer);
CHECK_VASTATUS(va_status, "vaUnmapBuffer");
-
- write_mjpeg_packet(qf.pts, qf.card_index, jpeg);
}
}