StreamReceiver.cpp
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package TabletTeleoperation::ArmarXObjects::StreamReceiver
19  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "StreamReceiver.h"
26 
27 #include <Image/ByteImage.h>
29 
30 extern "C" {
31 #include <gst/gst.h>
32 #include <gst/app/gstappsink.h>
33 #include <gst/app/gstappsrc.h>
34 #include <gst/app/gstappbuffer.h>
35 #include <glib.h>
36 #include <glib-object.h>
37 }
38 
39 using namespace armarx;
40 using namespace Stream;
41 
42 
43 #define VP8DECODE_ELEMENT " vp8dec ! "
44 #define RTPVP8_ELEMENT "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)VP8-DRAFT-IETF-01, payload=(int)96 ! " \
45  "rtpvp8depay ! "
46 // "gstrtpjitterbuffer latency=500 drop-on-latency=true ! "
47 
48 #define H264DECODE_ELEMENT " ffdec_h264 ! "
49 #define RTPH264_ELEMENT "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96 ! " \
50  "rtph264depay ! "
51 // "gstrtpjitterbuffer latency=500 drop-on-latency=true ! "
52 
54 {
55  pCombinedDecodedImage = NULL;
56  usingProxy(getProperty<std::string>("UsedStreamProvider").getValue());
57  usingTopic("ImageStream");
58  numberImages = 0;
59  gst_init(NULL, NULL);
60 
61 
62 
63  avcodec_register_all();
64  av_init_packet(&m_packet);
65  m_decoder = avcodec_find_decoder(AV_CODEC_ID_H264);
66  if (!m_decoder)
67  {
68  ARMARX_ERROR << ("Can't find H264 decoder!");
69  }
70  m_decoderContext = avcodec_alloc_context3(m_decoder);
71 
72  if (m_decoder->capabilities & CODEC_CAP_TRUNCATED)
73  {
74  m_decoderContext->flags |= CODEC_FLAG_TRUNCATED;
75  }
76 
77 
78  //we can receive truncated frames
79  m_decoderContext->flags2 |= CODEC_FLAG2_CHUNKS;
80  m_decoderContext->thread_count = 4;//TODO: random value. May be changing can make decoding faster
81 
82  AVDictionary* dictionary = nullptr;
83  if (avcodec_open2(m_decoderContext, m_decoder, &dictionary) < 0)
84  {
85  ARMARX_ERROR << "Could not open decoder";
86  }
87  ARMARX_INFO << "H264 Decoder successfully opened";
88  m_picture = avcodec_alloc_frame();
89 
90 }
91 
92 //unused function
93 //static gboolean
94 //sink_event_handler(GstPad* pad,
95 // GstEvent* event)
96 //{
97 // gboolean ret;
98 
99 // switch (GST_EVENT_TYPE(event))
100 // {
101 // case GST_EVENT_QOS:
102 // ARMARX_DEBUG_S << "QOS event";
103 // ret = gst_pad_event_default(pad, event);
104 // break;
105 
106 // default:
107 // /* just call the default handler */
108 // ret = gst_pad_event_default(pad, event);
109 // break;
110 // }
111 
112 // return ret;
113 //}
114 
115 
117 {
118  ScopedLock lock(decodedImageMutex);
119  ppDecodedImages = new CByteImage*[numberImages];
120 
121  streamProvider = getProxy<Stream::StreamProviderPrx>(getProperty<std::string>("UsedStreamProvider").getValue());
122  codec = streamProvider->getCodecType();
123  numberImages = streamProvider->getNumberOfImages();
124  int imgWidth, imgHeight, imgType;
125  streamProvider->getImageInformation(imgWidth, imgHeight, imgType);
126  ARMARX_INFO << "Images: " << numberImages;
127  for (int i = 0; i < numberImages ; i++)
128  {
129  ppDecodedImages[i] = new CByteImage(imgWidth, imgHeight, CByteImage::eRGB24);
130  }
131  pCombinedDecodedImage = new CByteImage(imgWidth, imgHeight * numberImages, CByteImage::eRGB24);
132  return;
133 
134  // put dummy string names
135  // for (int i = 0; i < numberImages ; i++)
136  // {
137  // std::stringstream ss;
138  // ss << "Camera" << i;
139  // ARMARX_WARNING << "Creating dummy stream name for image " << ss.str();
140  // streamSources[ss.str()].reset(new StreamElements(ss.str(), i, streamProvider));
141  // streamSources[ss.str()]->streamName = ss.str();
142 
143  // }
144 
145  // /*
146  // std::string sourcesStr = getProperty<std::string>("UsedSources").getValue();
147  // std::vector<std::string> sources;
148  // boost::split(sources,
149  // sourcesStr,
150  // boost::is_any_of("\t ,"),
151  // boost::token_compress_on);
152  // for(unsigned int i=0; i< sources.size(); i++){
153  // if(sources[i].empty())
154  // continue;
155  // ARMARX_DEBUG << "Creating stream for " << sources[i];
156  // ARMARX_WARNING << "xxCreating stream for " << sources[i];
157  // streamSources[sources[i]].reset(new StreamElements( sources[i], streamProvider));
158  // streamSources[sources[i]]->streamName = sources[i];
159 
160  // }
161  // */
162 
163  // std::string camPipelineString = "appsrc name=dec ! ";
164 
165  // switch (codec)
166  // {
167  // case Stream::eVP8:
168  // ARMARX_INFO << "Selected Codec: VP8";
169  // camPipelineString += RTPVP8_ELEMENT
170  // VP8DECODE_ELEMENT;
171  // break;
172 
173  // case Stream::eH264:
174  // ARMARX_INFO << "Selected Codec: H264";
175  // camPipelineString += RTPH264_ELEMENT
176  // H264DECODE_ELEMENT;
177  // break;
178 
179  // default:
180  // throw armarx::LocalException("Codec not yet supported");
181  // }
182 
183  // camPipelineString +=
184  // // " tee name=t ! "
185  // // " queue !"
186  // // " fpsdisplaysink t. ! "
187  // " queue !"
188  // " ffmpegcolorspace ! "
189  // " video/x-raw-rgb,bpp=24,depth=24,endianness=4321,red_mask=16711680,green_mask=65280,blue_mask=255 ! "
190  // " appsink name=raw drop=true max-buffers=100";
191 
192 
193  // start = IceUtil::Time::now();
194  // transferredBits = 0;
195 
196 
197  // StreamSourceMap::iterator it = streamSources.begin();
198 
199  // for (; it != streamSources.end(); it++)
200  // {
201 
202  // StreamElementsPtr elem = it->second;
203 
204  // elem->pipeline = gst_parse_launch(
205  // camPipelineString.c_str()
206  // , NULL
207  // );
208 
209  // if (!elem->pipeline)
210  // {
211  // ARMARX_ERROR << "pipeline is ZERO";
212  // terminate();
213  // return;
214  // }
215 
216  // // get the appsrc
217  // elem->appsrc = gst_bin_get_by_name(GST_BIN(elem->pipeline), "dec");
218 
219  // elem->appsink = gst_bin_get_by_name(GST_BIN(elem->pipeline), "raw");
220 
221  // // set the pipeline to playing state.
222  // gst_element_set_state(elem->pipeline, GST_STATE_PLAYING);
223 
224  // elem->taskReceive = new PeriodicTask<StreamElements>(elem.get(), &StreamReceiver::StreamElements::receive, 1);
225  //// elem->taskReceive->start();
226  // ARMARX_INFO << it->first << " pipeline created";
227 
228  // }
229 
230  // taskSave = new PeriodicTask<StreamReceiver>(this, &StreamReceiver::store, 5, false, "StreamConverterToIVT");
231  // taskSave->start();
232 
233 }
234 
235 
237 {
238  // ARMARX_IMPORTANT << "onDisconnectComponent";
239  StreamSourceMap::iterator it = streamSources.begin();
240 
241  for (; it != streamSources.end(); it++)
242  {
243  gst_element_send_event(it->second->pipeline, gst_event_new_eos());
244  gst_element_send_event(it->second->appsink, gst_event_new_eos());
245  gst_element_set_state(it->second->appsink, GST_STATE_NULL);
246 
247  if (it->second->taskReceive)
248  {
249  it->second->taskReceive->stop();
250  }
251  }
252 
253  // ScopedLock lock(pipelineMutex);
254  // ARMARX_IMPORTANT << "stopping tasks";
255  if (taskSave)
256  {
257  taskSave->stop();
258  }
259 
260  // ARMARX_IMPORTANT << "taskSave stopped";
261 
262  it = streamSources.begin();
263 
264  for (; it != streamSources.end(); it++)
265  {
266 
267  // ARMARX_INFO << "Stopping : " << it->first;
268  gst_element_set_state(it->second->pipeline, GST_STATE_NULL);
269  gst_element_set_state(it->second->appsink, GST_STATE_NULL);
270  g_object_unref(it->second->pipeline);
271  it->second->pipeline = NULL;
272  // ARMARX_INFO << it->first << " stopped ";
273  }
274 
275  it = streamSources.begin();
276 
277  for (; it != streamSources.end(); it++)
278  {
279 
280  try
281  {
282  if (streamProvider)
283  {
284  streamProvider->stopCapture();
285  }
286 
287  }
288  catch (Ice::NotRegisteredException& e)
289  {
290  ARMARX_DEBUG << "no proxy available";
291  continue;
292  }
293  catch (Ice::ConnectionRefusedException& e)
294  {
295  ARMARX_DEBUG << "no proxy available";
296  continue;
297  }
298 
299  // ARMARX_INFO << it->first << "remote stopped ";
300 
301 
302  }
303  delete pCombinedDecodedImage;
304  pCombinedDecodedImage = nullptr;
305  if (ppDecodedImages)
306  {
307  for (int i = 0; i < numberImages ; i++)
308  {
309  delete ppDecodedImages[i];
310  }
311 
312  delete[] ppDecodedImages;
313  ppDecodedImages = nullptr;
314  }
315 
316 
317  ARMARX_IMPORTANT << "onDisconnectComponent DONE";
318 }
319 
320 
322 {
323 
324 }
325 
326 StreamReceiver::StreamElementsPtr StreamReceiver::getStreamElements(std::string streamName)
327 {
328  StreamSourceMap::iterator it = streamSources.find(streamName);
329 
330  if (it == streamSources.end())
331  {
332  throw armarx::LocalException("No Stream registered under the name: '") << streamName << "'";
333  }
334 
335  return it->second;
336 }
337 
338 void StreamReceiver::getImageFormat(StreamElementsPtr elem, int& height, int& width)
339 {
340  GstPad* pad = gst_element_get_static_pad(elem->appsink, "sink");
341 
342  if (!pad)
343  {
344  ARMARX_WARNING << "Could not get pad";
345  return;
346  }
347 
348  GstCaps* caps = gst_pad_get_negotiated_caps(pad);
349 
350  if (!caps)
351  {
352  ARMARX_WARNING << "Could not get caps";
353  return;
354  }
355 
356  GstStructure* s = gst_caps_get_structure(caps, 0);
357  gst_structure_get_int(s, "width", &width);
358  gst_structure_get_int(s, "height", &height);
359 
360  gst_caps_unref(caps);
361  gst_object_unref(pad);
362 }
363 
364 void StreamReceiver::reportNewStreamData(const DataChunk& chunk, const Ice::Current&)
365 {
366  ScopedLock lock(streamDecodeMutex);
367  m_packet.size = chunk.size();
368  m_packet.data = const_cast<Ice::Byte*>(chunk.data());
369  // ARMARX_INFO << "H264Decoder: received encoded frame with framesize " << enc_frame.size();
370 
371  while (m_packet.size > 0)
372  {
373  int got_picture;
374  int len = avcodec_decode_video2(m_decoderContext, m_picture, &got_picture, &m_packet);
375  if (len < 0)
376  {
377  std::string err("Decoding error");
378  ARMARX_INFO << err;
379  return;
380  }
381  if (got_picture)
382  {
383  ARMARX_INFO << deactivateSpam(1) << "H264Decoder: frame decoded!";
384  // std::vector<unsigned char> result;
385  // this->storePicture(result);
386 
387  if (m_picture->format == AV_PIX_FMT_YUV420P)
388  {
389  static SwsContext* m_swsCtx = NULL;
390  // QImage frame_img = QImage(width, height, QImage::Format_RGB888);
391  m_swsCtx = sws_getCachedContext(m_swsCtx, m_picture->width,
392  m_picture->height, AV_PIX_FMT_YUV420P,
393  m_picture->width, m_picture->height,
394  AV_PIX_FMT_RGB24, SWS_GAUSS,
395  NULL, NULL, NULL);
396  ScopedLock lock(decodedImageMutex);
397 
398  uint8_t* dstSlice[] = { pCombinedDecodedImage->pixels };
399  int dstStride = m_picture->width * 3;
400  if (sws_scale(m_swsCtx, m_picture->data, m_picture->linesize,
401  0, m_picture->height, dstSlice, &dstStride) != m_picture->height)
402  {
403  ARMARX_INFO << "SCALING FAILED!";
404  return;
405  }
406  for (int i = 0; i < numberImages; ++i)
407  {
408  size_t imageByteSize = ppDecodedImages[i]->width * ppDecodedImages[i]->height * ppDecodedImages[i]->bytesPerPixel;
409  // if(ppInputImages[i]->type != CByteImage::eRGB24)
410  // {
411  // ::ImageProcessor::ConvertImage(imageProviderInfo, eRgb,)
412  // }
413  memcpy(ppDecodedImages[i]->pixels, pCombinedDecodedImage->pixels + i * imageByteSize, imageByteSize);
414  }
415  // ARMARX_INFO << "New decoded image!";
416  }
417  else
418  {
419  ARMARX_INFO << "Other format: " << m_picture->format;
420  }
421 
422  // emit newDecodedFrame(frame_img);
423  // }
424  // else if (m_picture->format == PIX_FMT_RGB32)
425  // {
426  // QImage img = QImage(result.data(), m_picture->width, m_picture->height, QImage::Format_RGB32);
427  // ARMARX_INFO << "New decoded image!";
428  // emit newDecodedFrame(img);
429  // }
430  // else if (m_picture->format == AV_PIX_FMT_RGB24)
431  // {
432  // QImage img = QImage(result.data(), m_picture->width, m_picture->height, QImage::Format_RGB888);
433  // ARMARX_INFO << "New decoded image!";
434  // emit newDecodedFrame(img);
435  // }
436  // else
437  // {
438  // std::string err = std::string( "Unsupported pixel format! Can't create QImage!");
439  // ARMARX_INFO << err;
440  // emit criticalError( err );
441  // return false;
442  // }
443  }
444  m_packet.size -= len;
445  m_packet.data += len;
446  }
447 
448 }
449 
450 
451 
452 
453 void StreamReceiver::getImages(std::vector<CByteImage*>& imagesOut)
454 {
455 
456 
457  ARMARX_DEBUG << deactivateSpam(3) << "FPS: " << 1 / (IceUtil::Time::now() - lastReceiveTimestamp).toSecondsDouble();
458  lastReceiveTimestamp = IceUtil::Time::now();
459 
460  if (getState() < eManagedIceObjectStarted)
461  {
462  return;
463  }
464  ScopedLock lock2(decodedImageMutex);
465  for (int i = 0; i < numberImages && i < (int)imagesOut.size(); ++i)
466  {
467 
468  memcpy(imagesOut.at(i)->pixels, ppDecodedImages[i]->pixels, ppDecodedImages[i]->width * ppDecodedImages[i]->height * ppDecodedImages[i]->bytesPerPixel);
469  }
470  return;
471 
472  ScopedLock lock(pipelineMutex);
473  int i = 0;
474  StreamSourceMap::iterator it = streamSources.begin();
475 
476  for (; it != streamSources.end(); it++, i++)
477  {
478  // ARMARX_IMPORTANT << "Waiting for Buffer";
479 
480  CByteImage* image = imagesOut.at(i);
481 
482  if (!image)
483  {
484  continue;
485  }
486 
487  if (!image->m_bOwnMemory)
488  {
489  throw armarx::LocalException("Output images need to have there own memory");
490  }
491 
492  StreamElementsPtr elem = it->second;
493 
494 
495  if (!elem->appsink || !elem->pipeline)
496  {
497  continue;
498  }
499 
500  GstState state;
501 
502  if (gst_element_get_state(elem->appsink, &state, NULL, 1000000000) == GST_STATE_CHANGE_FAILURE || state != GST_STATE_PLAYING)
503  {
504  ARMARX_ERROR << deactivateSpam(5) << "state of appsink for " << elem->streamName << " not playing state: " << state << " - skipping" << std::endl;
505  continue;
506  }
507 
508  GstBuffer* buffer = gst_app_sink_pull_buffer(GST_APP_SINK(elem->appsink));
509 
510  if (!buffer)
511  {
512  ARMARX_DEBUG << "Received Buffer is empty";
513  return;
514  }
515 
516  // ARMARX_IMPORTANT << "got Buffer";
517 
518  int width;
519  int height;
520  getImageFormat(elem, height, width);
521 
522  // g_object_get(caps, "width", &width);
523  // g_object_get(caps, "height", &height);
524  // ARMARX_INFO_S << "width: " << width;
525  // CByteImage image(width, height, CByteImage::eRGB24);
526  int buf_size = GST_BUFFER_SIZE(buffer);
527 
528  if (width * height * 3 != buf_size)
529  {
530  ARMARX_WARNING << "Invalid buffer size: actual " << buf_size << " vs. expected " << width* height * 3;
531  }
532  else
533  {
534  memcpy(image->pixels, GST_BUFFER_DATA(buffer), width * height * 3);
535  }
536 
537  // std::stringstream str;
538  // str << "/tmp/images/snap" << std::setfill('0') << std::setw(3) << imageNumber++ << ".bmp";
539  // // ARMARX_DEBUG << "Storing image";
540  // image.SaveToFile(str.str().c_str());
541 
542  gst_buffer_unref(buffer);
543 
544  }
545 
546 }
547 
549 {
550  // return streamSources.size();
551  return numberImages;
552 }
553 
554 void StreamReceiver::getImageInformation(int& imageWidth, int& imageHeight, int& imageType)
555 {
556  streamProvider->getImageInformation(imageWidth, imageHeight, imageType);
557 }
558 
559 void StreamReceiver::receive()
560 {
561 
562  // ScopedLock lock(pipelineMutex);
563 
564  // Stream::DataChunk c ;
565  // try{
566  // c = streamProvider->getChunk("Camera");
567  // }
568  // catch(Ice::NotRegisteredException &e)
569  // {
570  // ARMARX_DEBUG << "no proxy available";
571  // return;
572  // }
573  // catch(Ice::ConnectionRefusedException &e)
574  // {
575  // ARMARX_DEBUG << "no proxy available";
576  // return;
577  // }
578  // unsigned char* dataChunk = new unsigned char[c.size()];
579  // memcpy(dataChunk, &c[0], c.size());
580 
581  // //std::cout << "\r\033[K" << std::flush;
582 
583  // if(c.size() == 0)
584  // {
585  // ARMARX_DEBUG << "No Data received";
586  // return;
587  // }
588  // ARMARX_DEBUG << "Feeding chunk of size " << c.size() << std::endl;
589  // GstFlowReturn ret;
590  // GstBuffer *buffer;
591  // buffer = gst_app_buffer_new(dataChunk, c.size(), g_free, dataChunk);
592  // GST_BUFFER_TIMESTAMP (buffer) = (IceUtil::Time::now()- start).toMilliSeconds();
593  // ret = gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer);
594 
595  // if (ret == GST_FLOW_UNEXPECTED) {
596  // ARMARX_DEBUG << std::endl << "Stream ended (received EOS)" ;
597  // return;
598  // } else if (ret != GST_FLOW_OK) {
599  // ARMARX_DEBUG << std::endl << "error while feeding chunk of size: " << gst_flow_get_name(ret) ;
600  // return;
601  // }
602 
603 
604 
605 }
606 
607 
608 StreamReceiver::StreamElements::StreamElements(std::string streamName, int streamID, StreamProviderPrx streamProvider)
609 {
610  this->streamName = streamName;
611  this-> streamProvider = streamProvider;
612  receivedIndex = 0;
613  realPosition = 0;
614  this->streamID = streamID;
615 
616 }
617 
618 void StreamReceiver::StreamElements::receive()
619 {
620 
621  // // ScopedLock lock(pipelineMutex);
622 
623  // Stream::GstBufferWrapper wrap;
624 
625  // try
626  // {
627  // //wrap = streamProvider->getGstBuffer(streamName);
628  // wrap = streamProvider->getEncodedImagesFromBuffer(streamID, receivedIndex, realPosition);
629  // receivedIndex = realPosition;
630  // receivedIndex++;
631  // //ARMARX_DEBUG_S << " r " << receivedIndex << " p: " << realPosition << " s: " << wrap.data.size();
632 
633  // }
634  // catch (Ice::NotRegisteredException& e)
635  // {
636  // ARMARX_DEBUG_S << "no proxy available";
637  // return;
638  // }
639  // catch (Ice::ConnectionRefusedException& e)
640  // {
641  // ARMARX_DEBUG_S << "no proxy available";
642  // return;
643  // }
644 
645  // unsigned char* dataChunk = new unsigned char[wrap.data.size()];
646  // memcpy(dataChunk, &wrap.data[0], wrap.data.size());
647 
648  // //std::cout << "\r\033[K" << std::flush;
649 
650  // if (wrap.data.size() == 0)
651  // {
652  // ARMARX_DEBUG_S << "No Data received";
653  // return;
654  // }
655 
656  // // ARMARX_DEBUG << "Feeding chunk of size " << wrap.data.size() << std::endl;
657  // GstFlowReturn ret;
658  // GstBuffer* buffer;
659  // buffer = gst_app_buffer_new(dataChunk, wrap.data.size(), g_free, dataChunk);
660  // GST_BUFFER_TIMESTAMP(buffer) = wrap.timestamp;
661  // GST_BUFFER_DURATION(buffer) = wrap.duration;
662  // ret = gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer);
663 
664  // if (ret == GST_FLOW_UNEXPECTED)
665  // {
666  // ARMARX_DEBUG_S << std::endl << "Stream ended (received EOS)" ;
667  // return;
668  // }
669  // else if (ret != GST_FLOW_OK)
670  // {
671  // ARMARX_DEBUG_S << std::endl << "error while feeding chunk of size: " << gst_flow_get_name(ret) ;
672  // return;
673  // }
674 
675  // // bandwidth_kbps = 0.001 * wrap.data.size() * 24 * 8;
676  // // ARMARX_VERBOSE << "kbps: " << bandwidth_kbps;
677  // // transferredBits += wrap.data.size() * 8;
678  // // ARMARX_INFO << "Avg bandwidth: " << 0.001*transferredBits/(IceUtil::Time::now() - start).toSecondsDouble() << " kbps";
679 }
680 
681 
682 void StreamReceiver::store()
683 {
684  // ImageMap images;
685  // CByteImage image(640,480, CByteImage::eRGB24);
686  // CByteImage image2(640,480, CByteImage::eRGB24);
687  // images["Camera"] = &image;
688  // images["Camera2"] = &image2;
689  // getImages(images);
690 
691  // // ARMARX_DEBUG << "FPS: " << 1/(IceUtil::Time::now() -lastReceiveTimestamp).toSecondsDouble();
692  // lastReceiveTimestamp = IceUtil::Time::now();
693 
694  // ScopedLock lock(pipelineMutex);
695 
696  // // ARMARX_IMPORTANT << "Waiting for Buffer";
697  // GstBuffer* buffer = gst_app_sink_pull_buffer(GST_APP_SINK(this->appsink));
698  // if(!buffer)
699  // {
700  // ARMARX_DEBUG << "Received Buffer is empty";
701  // return;
702  // }
703  // // ARMARX_IMPORTANT << "got Buffer";
704 
705  // int width = 640;
706  // int height = 480;
707  // CByteImage image(width, height, CByteImage::eRGB24);
708  // size_t buf_size = GST_BUFFER_SIZE(buffer);
709  // if( width*height*3 != buf_size){
710  // ARMARX_WARNING << "Invalid buffer size: actual " << buf_size << " vs. expected " << width*height*3;
711  // gst_buffer_unref (buffer);
712  // return;
713  // }
714  // // ARMARX_DEBUG << "copying data";
715  // memcpy(image.pixels, GST_BUFFER_DATA(buffer), width*height*3);
716 
717  // std::stringstream str;
718  // str << "/tmp/images/snap" << std::setfill('0') << std::setw(3) << imageNumber++ << ".bmp";
719  // // ARMARX_DEBUG << "Storing image";
720  // image.SaveToFile(str.str().c_str());
721 
722  // gst_buffer_unref (buffer);
723 }
armarx::StreamReceiver::onExitComponent
virtual void onExitComponent()
Definition: StreamReceiver.cpp:321
armarx::StreamReceiver::getImageInformation
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType)
Definition: StreamReceiver.cpp:554
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::StreamReceiver::getImages
void getImages(std::vector< CByteImage * > &imagesOut)
getImages retreives the next buffered images for all streams.
Definition: StreamReceiver.cpp:453
armarx::ScopedLock
Mutex::scoped_lock ScopedLock
Definition: Synchronization.h:132
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::StreamReceiver::getNumberOfImages
int getNumberOfImages()
getNumberOfImages can be called after the component was initialized.
Definition: StreamReceiver.cpp:548
Stream
Definition: StreamProviderI.cpp:39
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::StreamReceiver::reportNewStreamData
void reportNewStreamData(const Stream::DataChunk &chunk, const Ice::Current &)
Definition: StreamReceiver.cpp:364
StreamReceiver.h
armarx::StreamReceiver::onConnectComponent
virtual void onConnectComponent()
Definition: StreamReceiver.cpp:116
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
ImageUtil.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::StreamReceiver::onDisconnectComponent
virtual void onDisconnectComponent()
Definition: StreamReceiver.cpp:236
armarx::StreamReceiver::onInitComponent
virtual void onInitComponent()
Definition: StreamReceiver.cpp:53
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28