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