EXPECT_EQ (status, ML_ERROR_STREAMS_PIPE);
}
+#define wait_for_start(handle, state, status) \
+do {\
+ int counter = 0;\
+ while ((state == ML_PIPELINE_STATE_PAUSED || \
+ state == ML_PIPELINE_STATE_READY) && counter < 20) {\
+ g_usleep (50000);\
+ counter ++;\
+ status = ml_pipeline_get_state (handle, &state);\
+ EXPECT_EQ (status, ML_ERROR_NONE);\
+ }\
+} while (0)\
+
/**
* @brief Test NNStreamer pipeline construct & destruct
*/
EXPECT_NE (state, ML_PIPELINE_STATE_UNKNOWN);
EXPECT_NE (state, ML_PIPELINE_STATE_NULL);
- g_usleep (150000); /* 50ms is good for general systems, but not enough for emulators to start gst pipeline. Let a few frames flow. */
+ g_usleep (50000); /* 50ms is good for general systems, but not enough for emulators to start gst pipeline. Let a few frames flow. */
status = ml_pipeline_get_state (handle, &state);
EXPECT_EQ (status, ML_ERROR_NONE);
+ wait_for_start (handle, state, status);
EXPECT_EQ (state, ML_PIPELINE_STATE_PLAYING);
status = ml_pipeline_stop (handle);
EXPECT_NE (state, ML_PIPELINE_STATE_UNKNOWN);
EXPECT_NE (state, ML_PIPELINE_STATE_NULL);
- g_usleep (150000); /* 50ms is good for general systems, but not enough for emulators to start gst pipeline. Let a few frames flow. */
+ g_usleep (50000); /* 50ms is good for general systems, but not enough for emulators to start gst pipeline. Let a few frames flow. */
status = ml_pipeline_get_state (handle, &state);
EXPECT_EQ (status, ML_ERROR_NONE);
+ wait_for_start (handle, state, status);
EXPECT_EQ (state, ML_PIPELINE_STATE_PLAYING);
status = ml_pipeline_stop (handle);
status = ml_pipeline_start (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
+ g_usleep (50000); /* 50ms. Wait for the pipeline stgart. */
status = ml_pipeline_get_state (handle, &state);
EXPECT_EQ (status, ML_ERROR_NONE); /* At this moment, it can be READY, PAUSED, or PLAYING */
EXPECT_NE (state, ML_PIPELINE_STATE_UNKNOWN);
EXPECT_NE (state, ML_PIPELINE_STATE_NULL);
- g_usleep (150000); /* 150ms. Let a few frames flow. */
+ wait_for_start (handle, state, status);
status = ml_pipeline_stop (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
g_free (pipeline);
}
+G_LOCK_DEFINE_STATIC(callback_lock);
/**
* @brief A tensor-sink callback for sink handle in a pipeline
*/
if (fp == NULL)
return;
+ G_LOCK(callback_lock);
ml_tensors_info_get_count (info, &num);
for (i = 0; i < num; i++) {
if (status == ML_ERROR_NONE)
fwrite (data_ptr, data_size, 1, fp);
}
+ G_UNLOCK(callback_lock);
fclose (fp);
}
{
guint *count = (guint *) user_data;
+ G_LOCK(callback_lock);
*count = *count + 1;
+ G_UNLOCK(callback_lock);
}
/**
{
TestPipeState *pipe_state;
+ G_LOCK(callback_lock);
pipe_state = (TestPipeState *) user_data;
switch (state) {
default:
break;
}
+ G_UNLOCK(callback_lock);
}
/**
ml_pipeline_switch_h switchhandle;
ml_pipeline_sink_h sinkhandle;
ml_pipeline_switch_e type;
+ ml_pipeline_state_e state;
gchar *pipeline;
int status;
guint *count_sink;
pipeline = g_strdup ("input-selector name=ins ! tensor_converter ! tensor_sink name=sinkx "
"videotestsrc is-live=true ! videoconvert ! ins.sink_0 "
- "videotestsrc num-buffers=3 ! videoconvert ! ins.sink_1");
+ "videotestsrc num-buffers=3 is-live=true ! videoconvert ! ins.sink_1");
count_sink = (guint *) g_malloc (sizeof (guint));
*count_sink = 0;
status = ml_pipeline_start (handle);
EXPECT_EQ (status, ML_ERROR_NONE);
+ g_usleep (50000);
+ status = ml_pipeline_get_state (handle, &state);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ wait_for_start (handle, state, status);
+
g_usleep (300000); /* 300ms. Let a few frames flow. */
status = ml_pipeline_stop (handle);