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();
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();
void lock()
Lock this mutex.
std::shared_ptr< Buffer > wait_for_next_frame()
Blocks caller until new thread is available.
virtual void dispose_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 size_t recommended_compressed_buffer_size()
virtual unsigned int pixel_height()
void wakeup()
Wake up thread.
WebviewJpegStreamProducer(const std::string &image_id, unsigned int quality, float fps, bool vflip)
Constructor.
void unlock()
Unlock the mutex.
virtual void finalize()
Finalize the thread.
void wait()
Wait for the condition forever.
virtual void set_destination_buffer(unsigned char *buf, unsigned int buf_size)
void set_coalesce_wakeups(bool coalesce=true)
Set wakeup coalescing.
virtual void unlock()
Unlock buffer.
virtual colorspace_t colorspace()
operate in wait-for-wakeup mode
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()
virtual unsigned int pixel_width()
void wait_systime()
Wait until minimum loop time has been reached in real time.
virtual unsigned char * buffer()
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