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 <core/threading/thread.h>
26 #include <core/utils/refptr.h>
27 #include <core/utils/lock_list.h>
28 #include <aspect/clock.h>
29 
30 #include <string>
31 
32 namespace firevision {
33  class SharedMemoryCamera;
34  class JpegImageCompressor;
35 }
36 
37 
38 namespace fawkes {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 class TimeWait;
44 class Mutex;
45 class WaitCondition;
46 
48 : public fawkes::Thread,
49  public fawkes::ClockAspect
50 {
51  public:
52  class Buffer {
53  public:
54  Buffer(unsigned char *data, size_t size);
55  ~Buffer();
56 
57  /** Get data buffer.
58  * @return data buffer */
59  const unsigned char * data() const
60  { return data_; }
61 
62  /** Get buffer size.
63  * @return b uffer size. */
64  size_t size() const
65  { return size_; }
66 
67  private:
68  unsigned char *data_;
69  size_t size_;
70  };
71 
72  class Subscriber {
73  public:
74  virtual ~Subscriber();
75  virtual void handle_buffer(RefPtr<Buffer> buffer) throw() = 0;
76  };
77 
78  public:
79  WebviewJpegStreamProducer(const std::string & image_id,
80  unsigned int quality, float fps, bool vflip);
81  virtual ~WebviewJpegStreamProducer();
82 
83  void add_subscriber(Subscriber *subscriber);
84  void remove_subscriber(Subscriber *subscriber);
85  RefPtr<Buffer> wait_for_next_frame();
86 
87  virtual void init();
88  virtual void loop();
89  virtual void finalize();
90 
91  private:
92  std::string image_id_;
93  unsigned int quality_;
94  float fps_;
95  bool vflip_;
96  unsigned char *in_buffer_;
97 
98  TimeWait *timewait_;
99 
103 
104  RefPtr<Buffer> last_buf_;
105  fawkes::Mutex *last_buf_mutex_;
106  fawkes::WaitCondition *last_buf_waitcond_;
107 };
108 
109 } // end namespace fawkes
110 
111 #endif
Wait until a given condition holds.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Image buffer passed to stream subscribers.
const unsigned char * data() const
Get data buffer.
Jpeg image compressor.
size_t size() const
Get buffer size.
List with a lock.
Definition: thread.h:40
Shared memory camera.
Definition: shmem.h:38
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49
Mutex mutual exclusion lock.
Definition: mutex.h:32
Time wait utility.
Definition: wait.h:32