17 #include <boost/preprocessor.hpp> 24 this->zerolatency = zerolatency;
31 return "JPEG_RTP_Stream";
33 return "H264_RTP_Stream";
36 #define GST_LOAD_ELEMENT_OR_DIE(stream,element) \ 39 stream.element = gst_element_factory_make(BOOST_PP_STRINGIZE(element), NULL); \ 42 fprintf(stderr,"Could not open " BOOST_PP_STRINGIZE(element)"\n"); \ 49 this->minport = minport;
50 this->maxport = maxport;
51 tStream defaultstream;
52 defaultstream.is_used =
false;
53 streams.resize(maxport-minport,defaultstream);
75 for (nr = 0; nr < streams.size(); nr++)
76 if (!streams[nr].is_used)
78 if (nr < streams.size())
84 g_object_set (G_OBJECT (streams[nr].appsrc),
"caps",
85 gst_caps_new_simple (
"video/x-raw",
86 "format", G_TYPE_STRING,
"RGBx",
87 "bpp", G_TYPE_INT, 32,
88 "depth", G_TYPE_INT, 32,
91 "framerate", GST_TYPE_FRACTION, 0, 1,
93 g_object_set (G_OBJECT (streams[nr].appsrc),
97 "format", GST_FORMAT_TIME, NULL);
103 g_object_set (G_OBJECT (streams[nr].capsfilter),
"caps",
104 gst_caps_new_simple (
"video/x-raw",
105 "format", G_TYPE_STRING,
"I420",
110 g_object_set(G_OBJECT(streams[nr].rtpjpegpay),
116 size_t bitrate_heuristic = (size_t) (
123 g_object_set (G_OBJECT (streams[nr].x264enc),
124 "tune", zerolatency ? 0x00000004 : 0x00000000,
127 "bitrate", bitrate_heuristic,
129 "byte-stream", 1, NULL);
132 g_object_set(G_OBJECT(streams[nr].rtph264pay),
133 "config-interval", 10,
138 g_object_set(G_OBJECT(streams[nr].udpsink),
139 "host", message->
target.c_str(),
140 "port", nr+minport, NULL);
144 streams[nr].pipeline = gst_pipeline_new( NULL );
145 streams[nr].bin = gst_bin_new( NULL );
148 gst_bin_add_many(GST_BIN(streams[nr].bin), streams[nr].appsrc, streams[nr].videoconvert, streams[nr].capsfilter, streams[nr].jpegenc, streams[nr].rtpjpegpay, streams[nr].udpsink, NULL);
149 gst_bin_add(GST_BIN(streams[nr].pipeline), streams[nr].bin);
150 success = gst_element_link_many(streams[nr].appsrc, streams[nr].videoconvert, streams[nr].capsfilter, streams[nr].jpegenc, streams[nr].rtpjpegpay, streams[nr].udpsink, NULL);
154 gst_bin_add_many(GST_BIN(streams[nr].bin), streams[nr].appsrc, streams[nr].videoconvert, streams[nr].x264enc, streams[nr].rtph264pay, streams[nr].udpsink, NULL);
155 gst_bin_add(GST_BIN(streams[nr].pipeline), streams[nr].bin);
156 success = gst_element_link_many(streams[nr].appsrc, streams[nr].videoconvert, streams[nr].x264enc, streams[nr].rtph264pay, streams[nr].udpsink, NULL);
160 fprintf(stderr,
"RTPImageConnector: Could not link elements for rtp stream.\n");
163 streams[nr].is_used =
true;
164 streams[nr].group = message->
group;
166 streams[nr].url = message->
target;
167 char* register_message = (
char*)malloc(128);
169 sprintf(register_message,
"v=0\nm=video %i RTP/AVP 96\nc=IN IP4 %s\na=rtpmap:96 JPEG/90000\n",nr+minport,url.c_str());
171 sprintf(register_message,
"v=0\nm=video %i RTP/AVP 96\nc=IN IP4 %s\na=rtpmap:96 H264/90000\n",nr+minport,url.c_str());
174 printf(
"RTIPImageConnector: Openend JPEG Stream at port %i\n",minport+nr);
176 printf(
"RTIPImageConnector: Openend H264 Stream at port %i\n",minport+nr);
177 if (gst_element_set_state(GST_ELEMENT(streams[nr].pipeline), GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
178 printf(
"RTIPImageConnector: Could not play stream!\n");
182 fprintf(stderr,
"RTPImageConnector: No free port!\n");
187 for (nr = 0; nr < streams.size(); nr++)
191 if (nr < streams.size() && streams[nr].is_used)
193 gst_app_src_end_of_stream( (GstAppSrc*)streams[nr].appsrc );
194 gst_element_set_state(streams[nr].pipeline, GST_STATE_NULL);
195 gst_object_unref(GST_OBJECT(streams[nr].pipeline));
196 streams[nr].is_used =
false;
197 printf(
"RTIPImageConnector: Closed Stream\n");
203 for (nr = 0; nr < streams.size(); nr++)
204 if (streams[nr].is_used && streams[nr].group == message->
group)
206 uint64_t val = gst_app_src_get_current_level_bytes( (GstAppSrc*)streams[nr].appsrc );
210 GstBuffer *buffer = gst_buffer_new_wrapped_full (GstMemoryFlags(0), message->
image->
buffer, streams[nr].group->getVideoBufferSize(), 0, streams[nr].group->getVideoBufferSize(), (gpointer)(message->
image),
suicideNotify);
211 if (gst_app_src_push_buffer( (GstAppSrc*)streams[nr].appsrc, buffer) != GST_FLOW_OK)
212 printf(
"RTIPImageConnector: Error while sending buffer\n");
223 for (nr = 0; nr < streams.size(); nr++)
224 if (streams[nr].is_used)
226 gst_app_src_end_of_stream( (GstAppSrc*)streams[nr].appsrc );
227 gst_element_set_state(streams[nr].pipeline, GST_STATE_NULL);
228 gst_object_unref(GST_OBJECT(streams[nr].pipeline));
229 streams[nr].is_used =
false;
ImageBufferContainer * clientGetMessage()
errorCode clientSendMessage(ImageBufferContainer *message)
void suicideNotify(gpointer data)
InsituConnectorGroup * group
RTPImageConnector(std::string url, bool zerolatency=false, bool raw=false)
errorCode init(int minport, int maxport)
#define GST_LOAD_ELEMENT_OR_DIE(stream, element)
int getFramebufferHeight()
int getFramebufferWidth()