| 1 |
#ifndef CVD_INC_SERVERPUSHJPEGBUFFER_H |
| 2 |
#define CVD_INC_SERVERPUSHJPEGBUFFER_H |
| 3 |
#include <cvd/localvideobuffer.h> |
| 4 |
#include <cvd/serverpushjpegframe.h> |
| 5 |
#include <cvd/timer.h> |
| 6 |
#include <iostream> |
| 7 |
|
| 8 |
namespace CVD |
| 9 |
{ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
template <class C> |
| 37 |
class ServerPushJpegBuffer : public LocalVideoBuffer<C> |
| 38 |
{ |
| 39 |
public: |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
ServerPushJpegBuffer(std::istream& i, bool warnings_ = 0, int eat_frames = 0) |
| 47 |
: LocalVideoBuffer<C>(VideoBufferType::Live) |
| 48 |
, is(i) |
| 49 |
, warnings(warnings_) |
| 50 |
{ |
| 51 |
std::string tmp; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
for(int junk = 0; junk < eat_frames; junk++) |
| 56 |
gimme_an_image(tmp); |
| 57 |
|
| 58 |
|
| 59 |
Image<C> c = gimme_an_image(tmp); |
| 60 |
s = c.size(); |
| 61 |
} |
| 62 |
|
| 63 |
virtual ImageRef size() |
| 64 |
{ |
| 65 |
return s; |
| 66 |
} |
| 67 |
|
| 68 |
LocalVideoFrame<C>* get_frame() |
| 69 |
{ |
| 70 |
Image<C> c; |
| 71 |
std::string data; |
| 72 |
|
| 73 |
loop: |
| 74 |
c = gimme_an_image(data); |
| 75 |
|
| 76 |
if(c.size() != s) |
| 77 |
{ |
| 78 |
if(warnings) |
| 79 |
std::cerr << "ServerPushJpegBuffer: video frame is " << c.size() << " not " << s << std::endl; |
| 80 |
goto loop; |
| 81 |
} |
| 82 |
|
| 83 |
return new ServerPushJpegFrame<C>(get_time_of_day(), std::move(c), data); |
| 84 |
} |
| 85 |
|
| 86 |
void put_frame(VideoFrame<C>* f) |
| 87 |
{ |
| 88 |
LocalVideoFrame<C>* g = dynamic_cast<LocalVideoFrame<C>*>(f); |
| 89 |
|
| 90 |
if(g == NULL) |
| 91 |
throw CVD::Exceptions::VideoBuffer::BadPutFrame(); |
| 92 |
else |
| 93 |
delete g; |
| 94 |
} |
| 95 |
|
| 96 |
bool frame_pending() |
| 97 |
{ |
| 98 |
return 1; |
| 99 |
} |
| 100 |
|
| 101 |
void seek_to(double) {}; |
| 102 |
|
| 103 |
|
| 104 |
double frame_rate() |
| 105 |
{ |
| 106 |
return 30; |
| 107 |
} |
| 108 |
|
| 109 |
private: |
| 110 |
std::istream& is; |
| 111 |
ImageRef s; |
| 112 |
bool warnings; |
| 113 |
|
| 114 |
Image<C> gimme_an_image(std::string& data) |
| 115 |
{ |
| 116 |
|
| 117 |
std::string line; |
| 118 |
|
| 119 |
int length; |
| 120 |
getline(is, line); |
| 121 |
getline(is, line); |
| 122 |
is >> line; |
| 123 |
is >> length; |
| 124 |
getline(is, line); |
| 125 |
getline(is, line); |
| 126 |
|
| 127 |
data.resize(length); |
| 128 |
is.read(&data[0], length); |
| 129 |
|
| 130 |
std::istringstream ss(data); |
| 131 |
|
| 132 |
Image<C> c = img_load(ss); |
| 133 |
|
| 134 |
is.get(); |
| 135 |
is.get(); |
| 136 |
|
| 137 |
return c; |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
} |
| 142 |
#endif |