13 #ifndef DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
14 #define DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
19 #include <cuda_runtime_api.h>
21 #undef DS_CAN_FPS_INTERVAL
22 #define DS_CAN_FPS_INTERVAL 30
34 cudaGetDevice(&curDev);
35 struct cudaDeviceProp gpuProp;
36 cudaGetDeviceProperties(&gpuProp, curDev);
37 _isdGPU = (gpuProp.integrated ? false :
true);
47 return ErrCode::kGood;
54 gst_bin_add(GST_BIN(
pipeline()), ele.
copy()), ErrCode::kGst,
"add element failed");
63 std::unique_lock<std::mutex> locker(
mutex());
75 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
78 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
80 GstState end = GST_STATE_NULL;
82 if (!
isGood(c) || end != GST_STATE_NULL) {
83 LOG_WARNING(
"waiting for pipeline state to null failed, force to quit");
87 c =
setState(each.get(), GST_STATE_NULL);
96 std::unique_lock<std::mutex> locker(
mutex());
102 GstState state = GST_STATE_NULL;
103 GstState pending = GST_STATE_NULL;
104 GstStateChangeReturn ret = gst_element_get_state(
105 GST_ELEMENT(
pipeline()), &state, &pending,
106 (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
110 while (ret == GST_STATE_CHANGE_FAILURE && times++ < 3) {
111 ret = gst_element_get_state(GST_ELEMENT(
pipeline()), &state, &pending, 0);
113 if (ret == GST_STATE_CHANGE_FAILURE) {
116 if (state == GST_STATE_PLAYING || pending == GST_STATE_PLAYING) {
124 std::unique_lock<std::mutex> locker(
mutex());
132 std::unique_lock<std::mutex> locker(
mutex());
135 locker, std::chrono::milliseconds(100), [
this]() {
return _mainStopped; });
148 std::unique_lock<std::mutex> locker(
mutex());
151 _mainLoopThread = std::make_unique<std::thread>([
this, cb = std::move(loopQuitCb)]() {
154 std::unique_lock<std::mutex> locker(
mutex());
165 gst_bus_remove_watch(
bus());
176 gst_element_send_event(GST_ELEMENT(
pipeline()), gst_event_new_eos()), ErrCode::kGst,
178 return ErrCode::kGood;
187 virtual bool busCall(GstMessage* msg) = 0;
199 GstStateChangeReturn ret = gst_element_set_state(ele, state);
201 ret != GST_STATE_CHANGE_FAILURE, ErrCode::kGst,
"element set state: %d failed", state);
202 return ErrCode::kGood;
207 GstElement* ele, GstState* state, GstState* pending =
nullptr,
size_t timeout = 0)
210 GstStateChangeReturn ret = gst_element_get_state(
211 ele, state, pending, (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
213 case GST_STATE_CHANGE_FAILURE:
214 return ErrCode::kGst;
215 case GST_STATE_CHANGE_SUCCESS:
216 case GST_STATE_CHANGE_NO_PREROLL:
217 return ErrCode::kGood;
219 return ErrCode::kUnknown;
221 return ErrCode::kGood;
224 static gboolean
sBusCall(GstBus*
bus, GstMessage* msg, gpointer data)
228 return ctx->busCall(msg);
274 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
276 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
279 bool busCall(GstMessage* msg)
final;
285 gst::ElePtr createSourceBin(
const std::string& uri);
292 std::function<void(
GstBuffer* buf)> _outputCallback =
nullptr;
293 uint64_t _appsrcFrameIdx = 0;
298 #endif // DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H