| 121 | } |
| 122 | |
| 123 | void CaptureRTSPFrame::onTrigger(const std::shared_ptr<core::ProcessContext> &context, |
| 124 | const std::shared_ptr<core::ProcessSession> &session) { |
| 125 | |
| 126 | std::unique_lock<std::mutex> lock(mutex_, std::try_to_lock); |
| 127 | if (!lock.owns_lock()) { |
| 128 | logger_->log_info("Cannot process due to an unfinished onTrigger"); |
| 129 | context->yield(); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | try { |
| 134 | video_capture_.open(rtsp_url_); |
| 135 | video_backend_driver_ = video_capture_.getBackendName(); |
| 136 | } catch (const cv::Exception &e) { |
| 137 | logger_->log_error("Unable to open RTSP stream: %s", e.what()); |
| 138 | context->yield(); |
| 139 | return; |
| 140 | } catch (...) { |
| 141 | logger_->log_error("Unable to open RTSP stream: unhandled exception"); |
| 142 | context->yield(); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | auto flow_file = session->create(); |
| 147 | cv::Mat frame; |
| 148 | // retrieve a frame of your source |
| 149 | if (video_capture_.read(frame)) { |
| 150 | if (!frame.empty()) { |
| 151 | CaptureRTSPFrameWriteCallback write_cb(frame, image_encoding_); |
| 152 | |
| 153 | auto t = std::time(nullptr); |
| 154 | auto tm = *std::localtime(&t); |
| 155 | |
| 156 | std::ostringstream oss; |
| 157 | oss << std::put_time(&tm, "%d-%m-%Y %H-%M-%S"); |
| 158 | auto filename = oss.str(); |
| 159 | filename.append(image_encoding_); |
| 160 | |
| 161 | session->putAttribute(flow_file, "filename", filename); |
| 162 | session->putAttribute(flow_file, "video.backend.driver", video_backend_driver_); |
| 163 | |
| 164 | session->write(flow_file, &write_cb); |
| 165 | session->transfer(flow_file, Success); |
| 166 | logger_->log_info("A frame is captured"); |
| 167 | } else { |
| 168 | logger_->log_error("Empty Mat frame received from capture"); |
| 169 | session->transfer(flow_file, Failure); |
| 170 | } |
| 171 | } else { |
| 172 | logger_->log_error("Unable to read from capture handle on RTSP stream"); |
| 173 | session->transfer(flow_file, Failure); |
| 174 | } |
| 175 | |
| 176 | } |
| 177 | |
| 178 | void CaptureRTSPFrame::notifyStop() { |
| 179 | } |
nothing calls this directly
no test coverage detected