} while (0)
#define SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
+#define SAFE_STR(str) (str) ? str : "null"
#define SOURCES_MAX 8
} webrtc_ini_s;
typedef struct _webrtc_gst_src_s {
- int source_id;
+ unsigned int source_id;
GstElement *bin;
} webrtc_gst_src_s;
typedef struct _webrtc_gst_s {
GstElement *pipeline;
+ GstElement *webrtcbin;
GstBus *bus;
guint bus_watcher;
webrtc_gst_src_s *audiosrc[SOURCES_MAX];
int _ini_load(webrtc_s *webrtc);
int _gst_init(webrtc_s *webrtc);
int _gst_build_pipeline(webrtc_s *webrtc);
+void _gst_destroy_pipeline(webrtc_s *webrtc);
#ifdef __cplusplus
}
return TRUE;
}
+static GstElement *__element_create(const char *factory_name, const char *name)
+{
+ GstElement *element = NULL;
+
+ RET_VAL_IF(!factory_name, NULL, "factory name is NULL");
+
+ element = gst_element_factory_make(factory_name, name);
+ RET_VAL_IF(!element, NULL, "element is NULL [%s]", factory_name);
+
+ LOG_DEBUG("created element [%s, %s]", factory_name, SAFE_STR(name));
+
+ return element;
+}
+
int _ini_load(webrtc_s *webrtc)
{
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
int _gst_build_pipeline(webrtc_s *webrtc)
{
- int ret = WEBRTC_ERROR_NONE;
-
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
webrtc->gst.pipeline = gst_pipeline_new("native-webrtc-pipeline");
RET_VAL_IF(webrtc->gst.pipeline == NULL, WEBRTC_ERROR_INVALID_OPERATION, "pipeline is NULL");
- webrtc->gst.bus = gst_pipeline_get_bus(GST_PIPELINE(webrtc->gst.pipeline));
- RET_VAL_IF(webrtc->gst.bus == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bus is NULL");
+ if (!(webrtc->gst.bus = gst_pipeline_get_bus(GST_PIPELINE(webrtc->gst.pipeline)))) {
+ LOG_ERROR("failed to gst_pipeline_get_bus()");
+ goto error;
+ }
+
+ if ((webrtc->gst.bus_watcher = gst_bus_add_watch(webrtc->gst.bus, (GstBusFunc) __bus_watch_cb, webrtc)) == 0) {
+ LOG_ERROR("failed to gst_bus_add_watch()");
+ goto error;
+ }
+
+ if (!(webrtc->gst.webrtcbin = __element_create("webrtcbin", NULL))) {
+ LOG_ERROR("failed to create webrtcbin");
+ goto error;
+ }
+
+ if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), webrtc->gst.webrtcbin)) {
+ LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_ELEMENT_NAME(webrtc->gst.pipeline));
+ goto error;
+ }
- webrtc->gst.bus_watcher = gst_bus_add_watch(webrtc->gst.bus, (GstBusFunc) __bus_watch_cb, webrtc);
+ return WEBRTC_ERROR_NONE;
+
+error:
+ _gst_destroy_pipeline(webrtc);
+ return WEBRTC_ERROR_INVALID_OPERATION;
+}
- /* FIXME : initial bin setting */
+void _gst_destroy_pipeline(webrtc_s *webrtc)
+{
+ if (!webrtc)
+ return;
- return ret;
+ if (webrtc->gst.bus_watcher > 0) {
+ gst_bus_remove_watch(webrtc->gst.bus);
+ webrtc->gst.bus_watcher = 0;
+ }
+ if (webrtc->gst.bus) {
+ gst_object_unref(webrtc->gst.bus);
+ webrtc->gst.bus = NULL;
+ }
+ if (webrtc->gst.webrtcbin) {
+ gst_bin_remove(GST_BIN(webrtc->gst.pipeline), webrtc->gst.webrtcbin);
+ webrtc->gst.webrtcbin = NULL;
+ }
+ if (webrtc->gst.pipeline) {
+ gst_object_unref(webrtc->gst.pipeline);
+ webrtc->gst.pipeline = NULL;
+ }
}
+