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();
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();
Clock * clock
By means of this member access to the clock is given.
Mutex mutual exclusion lock.
void lock()
Lock this mutex.
void unlock()
Unlock the mutex.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
void set_name(const char *format,...)
Set name of thread.
void wakeup()
Wake up thread.
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
void set_coalesce_wakeups(bool coalesce=true)
Set wakeup coalescing.
void mark_start()
Mark start of loop.
void wait_systime()
Wait until minimum loop time has been reached in real time.
Wait until a given condition holds.
void wait()
Wait for the condition forever.
void wake_all()
Wake up all waiting threads.
virtual ~Subscriber()
Destructor.
virtual void handle_buffer(std::shared_ptr< Buffer > buffer)=0
Notification if a new buffer is available.
void add_subscriber(Subscriber *subscriber)
Add a subscriber.
virtual void loop()
Code to execute in the thread.
std::shared_ptr< Buffer > wait_for_next_frame()
Blocks caller until new thread is available.
virtual ~WebviewJpegStreamProducer()
Destructor.
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
void remove_subscriber(Subscriber *subscriber)
Remove a subscriber.
WebviewJpegStreamProducer(const std::string &image_id, unsigned int quality, float fps, bool vflip)
Constructor.
virtual void compress()
Compress image.
virtual size_t compressed_size()
Get compressed size.
virtual bool supports_vflip()
Check if image compressor can do vflip during compress.
virtual size_t recommended_compressed_buffer_size()
Get the recommended size for the compressed buffer.
virtual void set_image_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer to compress.
virtual void set_compression_destination(ImageCompressor::CompressionDestination cd)
Set compression destination.
virtual void set_destination_buffer(unsigned char *buf, unsigned int buf_size)
Set destination buffer (if compressing to memory).
virtual void set_vflip(bool enable)
Enable or disable vflipping.
virtual void set_image_dimensions(unsigned int width, unsigned int height)
Set dimensions of image to compress.
virtual unsigned int pixel_width()
Width of image in pixels.
virtual void lock_for_read()
Lock image for reading.
virtual colorspace_t colorspace()
Colorspace of returned image.
virtual void dispose_buffer()
Dispose current buffer.
virtual void unlock()
Unlock buffer.
virtual void capture()
Capture an image.
virtual unsigned char * buffer()
Get access to current image buffer.
virtual unsigned int pixel_height()
Height of image in pixels.
Fawkes library namespace.