18 #ifndef DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
19 #define DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
24 #include <cuda_runtime_api.h>
26 #undef DS_CAN_FPS_INTERVAL
27 #define DS_CAN_FPS_INTERVAL 30
39 cudaGetDevice(&curDev);
40 struct cudaDeviceProp gpuProp;
41 cudaGetDeviceProperties(&gpuProp, curDev);
42 _isdGPU = (gpuProp.integrated ? false :
true);
52 return ErrCode::kGood;
59 gst_bin_add(GST_BIN(
pipeline()), ele.
copy()), ErrCode::kGst,
"add element failed");
68 std::unique_lock<std::mutex> locker(
mutex());
80 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
83 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
85 GstState end = GST_STATE_NULL;
87 if (!
isGood(c) || end != GST_STATE_NULL) {
88 LOG_WARNING(
"waiting for pipeline state to null failed, force to quit");
92 c =
setState(each.get(), GST_STATE_NULL);
101 std::unique_lock<std::mutex> locker(
mutex());
107 GstState state = GST_STATE_NULL;
108 GstState pending = GST_STATE_NULL;
109 GstStateChangeReturn ret = gst_element_get_state(
110 GST_ELEMENT(
pipeline()), &state, &pending,
111 (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
116 if (ret != GST_STATE_CHANGE_FAILURE)
break;
117 ret = gst_element_get_state(GST_ELEMENT(
pipeline()), &state, &pending, 0);
120 if (ret == GST_STATE_CHANGE_FAILURE) {
123 if (state == GST_STATE_PLAYING || pending == GST_STATE_PLAYING) {
131 std::unique_lock<std::mutex> locker(
mutex());
139 std::unique_lock<std::mutex> locker(
mutex());
142 locker, std::chrono::milliseconds(100), [
this]() {
return _mainStopped; });
155 std::unique_lock<std::mutex> locker(
mutex());
158 _mainLoopThread = std::make_unique<std::thread>([
this, cb = std::move(loopQuitCb)]() {
161 std::unique_lock<std::mutex> locker(
mutex());
172 gst_bus_remove_watch(
bus());
183 gst_element_send_event(GST_ELEMENT(
pipeline()), gst_event_new_eos()), ErrCode::kGst,
185 return ErrCode::kGood;
194 virtual bool busCall(GstMessage* msg) = 0;
206 GstStateChangeReturn ret = gst_element_set_state(ele, state);
208 ret != GST_STATE_CHANGE_FAILURE, ErrCode::kGst,
"element set state: %d failed", state);
209 return ErrCode::kGood;
214 GstElement* ele, GstState* state, GstState* pending =
nullptr,
size_t timeout = 0)
217 GstStateChangeReturn ret = gst_element_get_state(
218 ele, state, pending, (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
220 case GST_STATE_CHANGE_FAILURE:
221 return ErrCode::kGst;
222 case GST_STATE_CHANGE_SUCCESS:
223 case GST_STATE_CHANGE_NO_PREROLL:
224 return ErrCode::kGood;
226 return ErrCode::kUnknown;
228 return ErrCode::kGood;
231 static gboolean
sBusCall(GstBus*
bus, GstMessage* msg, gpointer data)
235 return ctx->busCall(msg);
281 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
283 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
286 bool busCall(GstMessage* msg)
final;
292 gst::ElePtr createSourceBin(
const std::string& uri);
299 std::function<void(
GstBuffer* buf)> _outputCallback =
nullptr;
300 uint64_t _appsrcFrameIdx = 0;
305 #endif // DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H