24 #ifndef DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
25 #define DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H
30 #include <cuda_runtime_api.h>
32 #undef DS_CAN_FPS_INTERVAL
33 #define DS_CAN_FPS_INTERVAL 30
45 cudaGetDevice(&curDev);
46 struct cudaDeviceProp gpuProp;
47 cudaGetDeviceProperties(&gpuProp, curDev);
48 _isdGPU = (gpuProp.integrated ? false :
true);
58 return ErrCode::kGood;
65 gst_bin_add(GST_BIN(
pipeline()), ele.
copy()), ErrCode::kGst,
"add element failed");
74 std::unique_lock<std::mutex> locker(
mutex());
86 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
89 LOG_WARNING(
"set pipeline state to GST_STATE_NULL failed");
91 GstState end = GST_STATE_NULL;
93 if (!
isGood(c) || end != GST_STATE_NULL) {
94 LOG_WARNING(
"waiting for pipeline state to null failed, force to quit");
98 c =
setState(each.get(), GST_STATE_NULL);
107 std::unique_lock<std::mutex> locker(
mutex());
113 GstState state = GST_STATE_NULL;
114 GstState pending = GST_STATE_NULL;
115 GstStateChangeReturn ret = gst_element_get_state(
116 GST_ELEMENT(
pipeline()), &state, &pending,
117 (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
121 while (ret == GST_STATE_CHANGE_FAILURE && times++ < 3) {
122 ret = gst_element_get_state(GST_ELEMENT(
pipeline()), &state, &pending, 0);
124 if (ret == GST_STATE_CHANGE_FAILURE) {
127 if (state == GST_STATE_PLAYING || pending == GST_STATE_PLAYING) {
135 std::unique_lock<std::mutex> locker(
mutex());
143 std::unique_lock<std::mutex> locker(
mutex());
146 locker, std::chrono::milliseconds(100), [
this]() {
return _mainStopped; });
159 std::unique_lock<std::mutex> locker(
mutex());
162 _mainLoopThread = std::make_unique<std::thread>([
this, cb = std::move(loopQuitCb)]() {
165 std::unique_lock<std::mutex> locker(
mutex());
176 gst_bus_remove_watch(
bus());
187 gst_element_send_event(GST_ELEMENT(
pipeline()), gst_event_new_eos()), ErrCode::kGst,
189 return ErrCode::kGood;
198 virtual bool busCall(GstMessage* msg) = 0;
210 GstStateChangeReturn ret = gst_element_set_state(ele, state);
212 ret != GST_STATE_CHANGE_FAILURE, ErrCode::kGst,
"element set state: %d failed", state);
213 return ErrCode::kGood;
218 GstElement* ele, GstState* state, GstState* pending =
nullptr,
size_t timeout = 0)
221 GstStateChangeReturn ret = gst_element_get_state(
222 ele, state, pending, (timeout ? timeout * 1000000 : GST_CLOCK_TIME_NONE));
224 case GST_STATE_CHANGE_FAILURE:
225 return ErrCode::kGst;
226 case GST_STATE_CHANGE_SUCCESS:
227 case GST_STATE_CHANGE_NO_PREROLL:
228 return ErrCode::kGood;
230 return ErrCode::kUnknown;
232 return ErrCode::kGood;
235 static gboolean
sBusCall(GstBus*
bus, GstMessage* msg, gpointer data)
239 return ctx->busCall(msg);
285 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
287 GstPad* pad, GstPadProbeInfo* info, gpointer udata);
290 bool busCall(GstMessage* msg)
final;
296 gst::ElePtr createSourceBin(
const std::string& uri);
303 std::function<void(
GstBuffer* buf)> _outputCallback =
nullptr;
304 uint64_t _appsrcFrameIdx = 0;
309 #endif // DS_APP_DEEPSTREAM_CAN_CONTEXT_PRIV_H