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> 28 #include <fvcams/shmem.h> 29 #include <fvutils/compression/jpeg_compressor.h> 30 #include <fvutils/color/conversions.h> 31 #include <utils/time/wait.h> 50 WebviewJpegStreamProducer::Buffer::Buffer(
unsigned char *data,
size_t size)
51 : data_(data), size_(size)
90 unsigned int quality,
float fps,
bool vflip)
95 set_name(
"WebviewJpegStreamProducer[%s]", image_id.c_str());
97 last_buf_mutex_ =
new Mutex();
101 image_id_ = image_id;
109 delete last_buf_mutex_;
110 delete last_buf_waitcond_;
121 subs_.push_back(subscriber);
135 subs_.remove(subscriber);
148 while (! last_buf_) {
149 last_buf_waitcond_->
wait();
160 jpeg_->set_compression_destination(ImageCompressor::COMP_DEST_MEM);
161 if (jpeg_->supports_vflip()) jpeg_->set_vflip(vflip_);
163 in_buffer_ = malloc_buffer(YUV422_PLANAR,
165 jpeg_->set_image_buffer(YUV422_PLANAR, in_buffer_);
167 long int loop_time = (
long int)roundf((1. / fps_) * 1000000.);
174 last_buf_mutex_->
lock();
176 last_buf_mutex_->
unlock();
181 unsigned char *buffer = (
unsigned char *)malloc(size);
186 firevision::convert(cam_->
colorspace(), YUV422_PLANAR,
187 cam_->
buffer(), in_buffer_,
195 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) > 40600 196 for (
auto &s : subs_) {
199 for (si = subs_.begin(); si != subs_.end(); ++si) {
204 bool go_on = ! subs_.empty();
207 last_buf_mutex_->
lock();
208 last_buf_ = shared_buf;
210 last_buf_mutex_->
unlock();
virtual unsigned int pixel_width()
Width of image in pixels.
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().
Image buffer passed to stream subscribers.
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 void handle_buffer(RefPtr< Buffer > buffer)=0
Notification if a new buffer is available.
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.
RefPtr<> is a reference-counting shared smartpointer.
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.
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.
RefPtr< Buffer > wait_for_next_frame()
Blocks caller until new thread is available.