Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoTransmitter.cpp
1 #ifdef WIN32
2 # pragma warning (disable: 4251) // STL MAP DLL warning noise (JW)
3 #endif
4 
5 #include "VideoTransmitter.hh"
6 
7 using namespace BIAS;
8 using namespace std;
9 
11 {
12  port_ = D_CS_DEFAULT_PORT;
13  targetAddress_ = "";
14 
15  jpeg_ = -1; // no compression
16  compressionColor_=true;
17  useUDP_ = false;
18 
20  useUDP_ = false;
21 
22  msgSize_=0;
23  Initialized_ = false;
24 }
25 
27 {
28 }
29 
30 
31 int VideoTransmitter::Init(int port) {
32  if (port!=port_)
33  port_=port;
34  cout <<"Initializing VideoTransmitter on port:"<<port_<<endl;
35 
36  #ifdef BIAS_HAVE_LIBJPEG
37  if (jpeg_ > 0) {
38  if (Compressor_.Init() < 0) {
39  BIASERR("Could not initialize JPEG-compression!!!");
40  return -1;
41  }
42  }
43 #else //BIAS_HAVE_LIBJPEG
44  if (jpeg_ > 0) {
45  BIASERR("Compression mode not available without LIBJPEG!");
46  }
47 #endif //BIAS_HAVE_LIBJPEG
48  if (useUDP_){
49  // Transmitter_.Connect(TargetAddress_->c_str(),*SendPort_);
50  } else {
52  }
53 
54  server_.SetKeepAll(false);
55  Initialized_ = true;
56  return 0;
57 }
58 
59 
61  if (! Initialized_) {
62  BIASERR("VideoTransmitter not initialized");
63  return -1;
64  }
65  if (server_.GetConnections()<=0)
66  {
68  return 1;
69  }
70 
71 
72  //if (useUDP_) Transmitter_.SetThrottle(*UDPServerThrottle_);
73  if (jpeg_ > 0) {
74 #ifdef BIAS_HAVE_LIBJPEG
75  // compress here --->> add parameter for jpeg-quality ???
76  if (compressionColor_) {
77  if (image.GetColorModel() != ImageBase::CM_RGB) {
79  ImageConvert::ToRGB(image, temp);
81  } else {
82  Compressor_.Compress(image,jpeg_);
83  }
84  } else {
85  if (image.GetColorModel() != ImageBase::CM_Grey) {
87  ImageConvert::ToGrey(image, temp);
89  } else {
90  Compressor_.Compress(image,jpeg_);
91  }
92  }
93  void *data = NULL;
94  long length;
95  Compressor_.GetCompressedData(data,length);
96  if (useUDP_){
97  // Transmitter_.Send(&Header_, (unsigned char*) data);
98  } else {
99  server_.SendMsg("JPEG_IMAGE", (char*)data, length);
100  }
101  msgSize_=length;
102 #else //BIAS_HAVE_LIBJPEG
103  BIASERR("LIBJPEG not configured --> no compression available !!!");
104  return -1;
105 #endif //BIAS_HAVE_LIBJPEG
106  } else {
107  if (useUDP_){
108  // Transmitter_.Send(&Header_, SendImage_.GetImageData());
109  } else {
110  stringstream dataToSend;
111  dataToSend<<image;
112  msgSize_= dataToSend.str().length();
113  server_.SendMsg("BIAS_IMAGE",(char*)&(dataToSend.str()[0]), msgSize_);
114  }
115  }
116 
117  return 0;
118 }
119 
120 
gray values, 1 channel
Definition: ImageBase.hh:130
void GetCompressedData(void *&data, long &length)
Get pointer to memory where to find compressed data and its length in byte.
int GetConnections()
returns the number of connected commPartners
Definition: CScommBase.hh:179
void WaitForConnections(unsigned int port=D_CS_DEFAULT_PORT)
Init function, returns instantly and enables the server to accept connections on the given port ...
int Compress(BIAS::Image< unsigned char > &srcImg, int quality=60)
Start compression for given BIAS::Image into buffer.
int Init(int port=D_CS_DEFAULT_PORT)
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void SetKeepAll(bool on)
If not threaded you can set this true to keep all received data.
Definition: CScommBase.hh:101
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
int Init(long size=10485760)
Initialize object with standard values and limit shared memory area to given size (in byte...
int Process(BIAS::Image< unsigned char > &image)
int SendMsg(const std::string &msgName, std::vector< float > &floatData)
sends msg msgName to all connected commPartners.
Definition: CScommBase.cpp:358
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey