22 #include "jpeg_stream_producer.h" 24 #include <core/threading/mutex.h> 25 #include <core/threading/mutex_locker.h> 26 #include <core/threading/wait_condition.h> 27 #include <fvcams/shmem.h> 28 #include <fvutils/color/conversions.h> 29 #include <fvutils/compression/jpeg_compressor.h> 30 #include <utils/time/wait.h> 34 using namespace firevision;
46 WebviewJpegStreamProducer::Buffer::Buffer(
unsigned char *data,
size_t size)
47 : data_(data), size_(size)
92 set_name(
"WebviewJpegStreamProducer[%s]", image_id.c_str());
94 last_buf_mutex_ =
new Mutex();
106 delete last_buf_mutex_;
107 delete last_buf_waitcond_;
118 subs_.push_back(subscriber);
132 subs_.remove(subscriber);
139 std::shared_ptr<WebviewJpegStreamProducer::Buffer>
145 last_buf_waitcond_->
wait();
156 jpeg_->set_compression_destination(ImageCompressor::COMP_DEST_MEM);
157 if (jpeg_->supports_vflip())
158 jpeg_->set_vflip(vflip_);
161 jpeg_->set_image_buffer(YUV422_PLANAR, in_buffer_);
163 long int loop_time = (
long int)roundf((1. / fps_) * 1000000.);
170 last_buf_mutex_->
lock();
172 last_buf_mutex_->
unlock();
177 unsigned char *buffer = (
unsigned char *)malloc(size);
192 std::shared_ptr<Buffer> shared_buf = std::make_shared<Buffer>(buffer, jpeg_->
compressed_size());
194 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) > 40600 195 for (
auto &s : subs_) {
198 for (si = subs_.begin(); si != subs_.end(); ++si) {
203 bool go_on = !subs_.empty();
206 last_buf_mutex_->
lock();
207 last_buf_ = shared_buf;
209 last_buf_mutex_->
unlock();
virtual unsigned int pixel_width()
Width of image in pixels.
virtual void handle_buffer(std::shared_ptr< Buffer > buffer)=0
Notification if a new buffer is available.
virtual ~Subscriber()
Destructor.
Wait until a given condition holds.
WebviewJpegStreamProducer(const std::string &image_id, unsigned int quality, float fps, bool vflip)
Constructor.
virtual void finalize()
Finalize the thread.
Fawkes library namespace.
virtual size_t compressed_size()
Get compressed size.
void unlock()
Unlock the mutex.
void wake_all()
Wake up all waiting threads.
virtual void compress()
Compress image.
virtual void loop()
Code to execute in the thread.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
virtual void unlock()
Unlock buffer.
virtual void capture()
Capture an image.
void wait_systime()
Wait until minimum loop time has been reached in real time.
Clock * clock
By means of this member access to the clock is given.
virtual void dispose_buffer()
Dispose current buffer.
void wakeup()
Wake up thread.
void set_name(const char *format,...)
Set name of thread.
virtual colorspace_t colorspace()
Colorspace of returned image.
virtual void set_destination_buffer(unsigned char *buf, unsigned int buf_size)
Set destination buffer (if compressing to memory).
void set_coalesce_wakeups(bool coalesce=true)
Set wakeup coalescing.
void wait()
Wait for the condition forever.
virtual unsigned char * buffer()
Get access to current image buffer.
void mark_start()
Mark start of loop.
void remove_subscriber(Subscriber *subscriber)
Remove a subscriber.
virtual ~WebviewJpegStreamProducer()
Destructor.
void lock()
Lock this mutex.
virtual unsigned int pixel_height()
Height of image in pixels.
std::shared_ptr< Buffer > wait_for_next_frame()
Blocks caller until new thread is available.
virtual size_t recommended_compressed_buffer_size()
Get the recommended size for the compressed buffer.
virtual void init()
Initialize the thread.
operate in wait-for-wakeup mode
Mutex mutual exclusion lock.
virtual void lock_for_read()
Lock image for reading.
void add_subscriber(Subscriber *subscriber)
Add a subscriber.