}
if (elem->handle_id > 0) {
+ /* no need to connect signal to sink element */
ml_logw ("Sink callback is already registered.");
- ret = ML_ERROR_NONE;
- goto unlock_return;
- }
-
- /* set callback for new data */
- if (elem->type == ML_PIPELINE_ELEMENT_SINK) {
- /* tensor_sink */
- g_object_set (G_OBJECT (elem->element), "emit-signal", (gboolean) TRUE,
- NULL);
- elem->handle_id =
- g_signal_connect (elem->element, "new-data", G_CALLBACK (cb_sink_event),
- elem);
} else {
- /* appsink */
- g_object_set (G_OBJECT (elem->element), "emit-signals", (gboolean) TRUE,
- NULL);
- elem->handle_id =
- g_signal_connect (elem->element, "new-sample",
- G_CALLBACK (cb_appsink_new_sample), elem);
- }
+ /* set callback for new data */
+ if (elem->type == ML_PIPELINE_ELEMENT_SINK) {
+ /* tensor_sink */
+ g_object_set (G_OBJECT (elem->element), "emit-signal", (gboolean) TRUE, NULL);
+ elem->handle_id = g_signal_connect (elem->element, "new-data",
+ G_CALLBACK (cb_sink_event), elem);
+ } else {
+ /* appsink */
+ g_object_set (G_OBJECT (elem->element), "emit-signals", (gboolean) TRUE, NULL);
+ elem->handle_id = g_signal_connect (elem->element, "new-sample",
+ G_CALLBACK (cb_appsink_new_sample), elem);
+ }
- if (elem->handle_id == 0) {
- ml_loge ("Failed to connect a signal to the element [%s].", sink_name);
- ret = ML_ERROR_STREAMS_PIPE;
- goto unlock_return;
+ if (elem->handle_id == 0) {
+ ml_loge ("Failed to connect a signal to the element [%s].", sink_name);
+ ret = ML_ERROR_STREAMS_PIPE;
+ goto unlock_return;
+ }
}
sink = *h = g_new0 (ml_pipeline_sink, 1);
} else {
if (!elem->is_media_stream) {
ml_logw
- ("Cannot find caps. The pipeline is not yet negotiated for src element [%s].",
- elem->name);
+ ("Cannot find caps. The pipeline is not yet negotiated for src element [%s].",
+ elem->name);
gst_object_unref (elem->src);
elem->src = NULL;
ret = ML_ERROR_TRY_AGAIN;
goto destroy_data;
}
- if (!elem->is_media_stream){
+ if (!elem->is_media_stream) {
if (elem->tensors_info.num_tensors != _data->num_tensors) {
ml_loge
("The src push of [%s] cannot be handled because the number of tensors in a frame mismatches. %u != %u",
EXPECT_EQ (status, ML_ERROR_NONE);
status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_dm01, file2, &sinkhandle);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle != NULL);
status = ml_pipeline_start (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_count, count_sink, &sinkhandle);
EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle != NULL);
status = ml_pipeline_start (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
/**
* @brief Test NNStreamer pipeline sink
+ */
+TEST (nnstreamer_capi_sink, register_duplicated)
+{
+ ml_pipeline_h handle;
+ ml_pipeline_sink_h sinkhandle0, sinkhandle1;
+ gchar *pipeline;
+ int status;
+ guint *count_sink0, *count_sink1;
+ TestPipeState *pipe_state;
+
+ /* pipeline with appsink */
+ pipeline = g_strdup ("videotestsrc num-buffers=3 ! videoconvert ! tensor_converter ! appsink name=sinkx");
+
+ count_sink0 = (guint *) g_malloc (sizeof (guint));
+ ASSERT_TRUE (count_sink0 != NULL);
+ *count_sink0 = 0;
+
+ count_sink1 = (guint *) g_malloc (sizeof (guint));
+ ASSERT_TRUE (count_sink1 != NULL);
+ *count_sink1 = 0;
+
+ pipe_state = (TestPipeState *) g_new0 (TestPipeState, 1);
+ ASSERT_TRUE (pipe_state != NULL);
+
+ status = ml_pipeline_construct (pipeline, test_pipe_state_callback, pipe_state, &handle);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_count, count_sink0, &sinkhandle0);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle0 != NULL);
+
+ status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_count, count_sink1, &sinkhandle1);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle1 != NULL);
+
+ status = ml_pipeline_start (handle);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ g_usleep (100000); /* 100ms. Let a few frames flow. */
+
+ status = ml_pipeline_sink_unregister (sinkhandle0);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_pipeline_sink_unregister (sinkhandle1);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_pipeline_destroy (handle);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_TRUE (*count_sink0 > 0U);
+ EXPECT_TRUE (*count_sink1 > 0U);
+ EXPECT_TRUE (pipe_state->paused);
+ EXPECT_TRUE (pipe_state->playing);
+
+ g_free (pipeline);
+ g_free (count_sink0);
+ g_free (count_sink1);
+ g_free (pipe_state);
+}
+
+/**
+ * @brief Test NNStreamer pipeline sink
* @detail Failure case to register callback with invalid param.
*/
TEST (nnstreamer_capi_sink, failure_01_n)
status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_count, count_sink, &sinkhandle);
EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle != NULL);
status = ml_pipeline_start (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
status = ml_pipeline_sink_register (handle, "sinkx", test_sink_callback_count, count_sink, &sinkhandle);
EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle != NULL);
status = ml_pipeline_switch_select (switchhandle, "sink_1");
EXPECT_EQ (status, ML_ERROR_NONE);
status = ml_pipeline_sink_register (handle, "sink0", test_sink_callback_count, count_sink0, &sinkhandle0);
EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle0 != NULL);
status = ml_pipeline_sink_register (handle, "sink1", test_sink_callback_count, count_sink1, &sinkhandle1);
EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (sinkhandle1 != NULL);
status = ml_pipeline_switch_select (switchhandle, "src_1");
EXPECT_EQ (status, ML_ERROR_NONE);