Fawkes API  Fawkes Development Version
jpeg_stream_producer.h
1 
2 /***************************************************************************
3  * jpeg_stream_producer.h - Camera image stream producer
4  *
5  * Created: Thu Feb 06 12:48:34 2014
6  * Copyright 2006-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef _PLUGINS_WEBVIEW_JPEG_STREAM_PRODUCER_H_
23 #define _PLUGINS_WEBVIEW_JPEG_STREAM_PRODUCER_H_
24 
25 #include <aspect/clock.h>
26 #include <core/threading/thread.h>
27 #include <core/utils/lock_list.h>
28 
29 #include <memory>
30 #include <string>
31 
32 namespace firevision {
33 class SharedMemoryCamera;
34 class JpegImageCompressor;
35 } // namespace firevision
36 
37 namespace fawkes {
38 
39 class TimeWait;
40 class Mutex;
41 class WaitCondition;
42 
44 {
45 public:
46  class Buffer
47  {
48  public:
49  Buffer(unsigned char *data, size_t size);
50  ~Buffer();
51 
52  /** Get data buffer.
53  * @return data buffer */
54  const unsigned char *
55  data() const
56  {
57  return data_;
58  }
59 
60  /** Get buffer size.
61  * @return b uffer size. */
62  size_t
63  size() const
64  {
65  return size_;
66  }
67 
68  private:
69  unsigned char *data_;
70  size_t size_;
71  };
72 
73  class Subscriber
74  {
75  public:
76  virtual ~Subscriber();
77  virtual void handle_buffer(std::shared_ptr<Buffer> buffer) = 0;
78  };
79 
80 public:
81  WebviewJpegStreamProducer(const std::string &image_id,
82  unsigned int quality,
83  float fps,
84  bool vflip);
86 
87  void add_subscriber(Subscriber *subscriber);
88  void remove_subscriber(Subscriber *subscriber);
89  std::shared_ptr<Buffer> wait_for_next_frame();
90 
91  virtual void init();
92  virtual void loop();
93  virtual void finalize();
94 
95 private:
96  std::string image_id_;
97  unsigned int quality_;
98  float fps_;
99  bool vflip_;
100  unsigned char *in_buffer_;
101 
102  TimeWait *timewait_;
103 
107 
108  std::shared_ptr<Buffer> last_buf_;
109  fawkes::Mutex * last_buf_mutex_;
110  fawkes::WaitCondition * last_buf_waitcond_;
111 };
112 
113 } // end namespace fawkes
114 
115 #endif
fawkes::WebviewJpegStreamProducer::wait_for_next_frame
std::shared_ptr< Buffer > wait_for_next_frame()
Blocks caller until new thread is available.
Definition: jpeg_stream_producer.cpp:139
fawkes::WebviewJpegStreamProducer::Subscriber::~Subscriber
virtual ~Subscriber()
Destructor.
Definition: jpeg_stream_producer.cpp:65
fawkes::WebviewJpegStreamProducer::loop
virtual void loop()
Code to execute in the thread.
Definition: jpeg_stream_producer.cpp:167
fawkes::WebviewJpegStreamProducer::Buffer::~Buffer
~Buffer()
Destructor.
Definition: jpeg_stream_producer.cpp:51
fawkes::Mutex
Definition: mutex.h:36
fawkes::WaitCondition
Definition: wait_condition.h:40
firevision::JpegImageCompressor
Definition: jpeg_compressor.h:35
firevision::SharedMemoryCamera
Definition: shmem.h:39
fawkes::WebviewJpegStreamProducer::WebviewJpegStreamProducer
WebviewJpegStreamProducer(const std::string &image_id, unsigned int quality, float fps, bool vflip)
Constructor.
Definition: jpeg_stream_producer.cpp:83
fawkes::LockList
Definition: thread.h:42
fawkes::WebviewJpegStreamProducer::Subscriber
Definition: jpeg_stream_producer.h:72
fawkes::WebviewJpegStreamProducer
Definition: jpeg_stream_producer.h:42
fawkes::WebviewJpegStreamProducer::finalize
virtual void finalize()
Finalize the thread.
Definition: jpeg_stream_producer.cpp:217
fawkes::WebviewJpegStreamProducer::Buffer::data
const unsigned char * data() const
Get data buffer.
Definition: jpeg_stream_producer.h:54
fawkes
fawkes::WebviewJpegStreamProducer::Buffer
Definition: jpeg_stream_producer.h:45
fawkes::WebviewJpegStreamProducer::Buffer::Buffer
Buffer(unsigned char *data, size_t size)
Constructor.
Definition: jpeg_stream_producer.cpp:45
fawkes::WebviewJpegStreamProducer::init
virtual void init()
Initialize the thread.
Definition: jpeg_stream_producer.cpp:150
fawkes::WebviewJpegStreamProducer::add_subscriber
void add_subscriber(Subscriber *subscriber)
Add a subscriber.
Definition: jpeg_stream_producer.cpp:114
fawkes::Thread
Definition: thread.h:44
fawkes::TimeWait
Definition: wait.h:36
fawkes::WebviewJpegStreamProducer::Buffer::size
size_t size() const
Get buffer size.
Definition: jpeg_stream_producer.h:62
fawkes::ClockAspect
Definition: clock.h:38
fawkes::WebviewJpegStreamProducer::remove_subscriber
void remove_subscriber(Subscriber *subscriber)
Remove a subscriber.
Definition: jpeg_stream_producer.cpp:128
fawkes::WebviewJpegStreamProducer::~WebviewJpegStreamProducer
virtual ~WebviewJpegStreamProducer()
Destructor.
Definition: jpeg_stream_producer.cpp:103
fawkes::WebviewJpegStreamProducer::Subscriber::handle_buffer
virtual void handle_buffer(std::shared_ptr< Buffer > buffer)=0