17 #include <boost/preprocessor.hpp> 26 heartbeat_image(NULL),
28 dummy_audio(dummy_audio)
35 return std::string(
"RTMPImageConnector(") + name + std::string(
")");
43 #define RTMP_LOAD_ELEMENT_OR_DIE(element) \ 46 element = gst_element_factory_make(BOOST_PP_STRINGIZE(element), NULL); \ 49 fprintf(stderr,"RTMPImageConnector: Could not open " BOOST_PP_STRINGIZE(element)"\n"); \ 57 if (clock_gettime(CLOCK_MONOTONIC_RAW,&ts) == 0)
58 return ts.tv_sec*1000 + ts.tv_nsec/1000000;
64 uint64_t val = gst_app_src_get_current_level_bytes( appsrc );
69 if (gst_app_src_push_buffer( appsrc, buffer) != GST_FLOW_OK)
70 printf(
"RTMPImageConnector: Error while sending buffer\n");
77 while (myself->heartbeat_finish ==
false)
80 if (myself->heartbeat_image)
82 pthread_mutex_lock(&myself->heartbeat_mutex);
85 addFrame( myself->heartbeat_image, (GstAppSrc*)(myself->appsrc), myself->group );
86 myself->heartbeat = now;
88 pthread_mutex_unlock(&myself->heartbeat_mutex);
96 pthread_mutex_init (&heartbeat_mutex, NULL);
97 heartbeat_finish =
false;
109 if (group == message->
group)
111 pthread_mutex_lock(&heartbeat_mutex);
114 heartbeat_image = NULL;
115 pthread_mutex_unlock(&heartbeat_mutex);
117 gst_app_src_end_of_stream( (GstAppSrc*)appsrc );
118 gst_element_set_state(pipeline, GST_STATE_NULL);
119 gst_object_unref(GST_OBJECT(pipeline));
120 printf(
"RTMPImageConnector: Closed Stream\n");
129 gboolean success = 1;
132 g_object_set (G_OBJECT (appsrc),
"caps",
133 gst_caps_new_simple (
"video/x-raw",
134 "format", G_TYPE_STRING,
"RGBx",
135 "bpp", G_TYPE_INT, 32,
136 "depth", G_TYPE_INT, 32,
139 "framerate", GST_TYPE_FRACTION, 0, 1,
142 g_object_set (G_OBJECT (appsrc),
148 "format", GST_FORMAT_TIME,
152 videorate_capsfilter = capsfilter;
154 g_object_set (G_OBJECT (videorate_capsfilter),
"caps",
155 gst_caps_new_simple (
"video/x-raw",
156 "framerate", GST_TYPE_FRACTION, 15, 1,
161 g_object_set (G_OBJECT (capsfilter),
"caps",
162 gst_caps_new_simple (
"video/x-raw",
163 "format", G_TYPE_STRING,
"I420",
167 g_object_set (G_OBJECT (x264enc),
178 g_object_set (G_OBJECT (flvmux),
183 sprintf(location,
"rtmp://%s/%s",base_url.c_str(),apikey.c_str());
185 g_object_set(G_OBJECT(rtmpsink),
186 "location", location, NULL);
192 g_object_set(G_OBJECT(audiotestsrc),
199 pipeline = gst_pipeline_new( NULL );
200 bin = gst_bin_new( NULL );
201 gst_bin_add_many(GST_BIN(bin), appsrc, videoconvert, capsfilter, x264enc, flvmux, rtmpsink, NULL);
203 gst_bin_add_many(GST_BIN(bin), audiotestsrc, voaacenc, NULL);
204 gst_bin_add(GST_BIN(pipeline), bin);
205 success = gst_element_link_many( appsrc, videoconvert, capsfilter, x264enc, flvmux, NULL);
207 success &= gst_element_link_many( audiotestsrc, voaacenc, flvmux, NULL);
208 success &= gst_element_link_many( flvmux, rtmpsink, NULL);
210 fprintf(stderr,
"RTMPImageConnector: Could not link elements for rtmp stream.\n");
211 if (gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
212 printf(
"RTMPImageConnector: Could not play stream!\n");
214 printf(
"RTMPImageConnector: Openend H264 Stream\n");
215 group = message->
group;
219 if (group == message->
group)
221 pthread_mutex_lock(&heartbeat_mutex);
226 heartbeat_image = message->
image;
227 heartbeat_image->
incref();
228 pthread_mutex_unlock(&heartbeat_mutex);
235 heartbeat_finish =
true;
236 pthread_join(heartbeat_thread,NULL);
237 pthread_mutex_destroy(&heartbeat_mutex);
ImageBufferContainer * clientGetMessage()
errorCode clientSendMessage(ImageBufferContainer *message)
void suicideNotify(gpointer data)
static void addFrame(ImageBuffer *image, GstAppSrc *appsrc, InsituConnectorGroup *group)
InsituConnectorGroup * group
static uint64_t getTicksMs()
#define RTMP_LOAD_ELEMENT_OR_DIE(element)
RTMPImageConnector(std::string name, std::string apikey, std::string base_url, int bitrate=400, bool dummy_audio=false)
static void * heartbeatFunction(void *ptr)
errorCode init(int minport, int maxport)
int getFramebufferHeight()
#define ISAAC_MAX_HEARTBEAT
int getFramebufferWidth()