File size: 3,646 Bytes
dffe123 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#ifdef HAVE_ONEVPL
#include <algorithm>
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#include "streaming/onevpl/engine/processing_engine_base.hpp"
#include "streaming/onevpl/accelerators/accel_policy_interface.hpp"
#include "logger.hpp"
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
ProcessingEngineBase::ProcessingEngineBase(std::unique_ptr<VPLAccelerationPolicy>&& accel) :
acceleration_policy(std::move(accel)) {
}
ProcessingEngineBase::~ProcessingEngineBase() {
GAPI_LOG_INFO(nullptr, "destroyed, elapsed sessions count: " << sessions.size());
sessions.clear();
}
ProcessingEngineBase::ExecutionStatus ProcessingEngineBase::process(mfxSession session) {
auto sess_it = sessions.find(session);
if (sess_it == sessions.end()) {
return ExecutionStatus::SessionNotFound;
}
session_ptr processing_session = sess_it->second;
ExecutionData& exec_data = execution_table[session];
GAPI_LOG_DEBUG(nullptr, "[" << session << "] start op id: " << exec_data.op_id);
ExecutionStatus status = execute_op(pipeline.at(exec_data.op_id), *processing_session);
size_t old_op_id = exec_data.op_id++;
if (exec_data.op_id == pipeline.size())
{
exec_data.op_id = 0;
}
cv::util::suppress_unused_warning(old_op_id);
GAPI_LOG_DEBUG(nullptr, "[" << session << "] finish op id: " << old_op_id <<
", " << processing_session->error_code_to_str() <<
", " << ProcessingEngineBase::status_to_string(status) <<
", next op id: " << exec_data.op_id);
if (status == ExecutionStatus::Failed) {
GAPI_LOG_WARNING(nullptr, "Operation for session: " << session <<
", " << ProcessingEngineBase::status_to_string(status) <<
" - remove it");
sessions.erase(sess_it);
execution_table.erase(session);
}
if (status == ExecutionStatus::Processed) {
GAPI_LOG_INFO(nullptr, "Processed [" << session << "]");
sessions.erase(sess_it);
execution_table.erase(session);
}
return status;
}
const char* ProcessingEngineBase::status_to_string(ExecutionStatus status)
{
switch(status) {
case ExecutionStatus::Continue: return "CONTINUE";
case ExecutionStatus::Processed: return "PROCESSED";
case ExecutionStatus::SessionNotFound: return "NOT_FOUND_SESSION";
case ExecutionStatus::Failed: return "FAILED";
default:
return "UNKNOWN";
}
}
ProcessingEngineBase::ExecutionStatus ProcessingEngineBase::execute_op(operation_t& op, EngineSession& sess)
{
return op(sess);
}
size_t ProcessingEngineBase::get_ready_frames_count() const
{
return ready_frames.size();
}
void ProcessingEngineBase::get_frame(Data &data)
{
data = ready_frames.front();
ready_frames.pop();
GAPI_LOG_DEBUG(nullptr, " elapsed ready frames count: " << ready_frames.size());
}
const VPLAccelerationPolicy* ProcessingEngineBase::get_accel() const {
return acceleration_policy.get();
}
VPLAccelerationPolicy* ProcessingEngineBase::get_accel() {
return const_cast<VPLAccelerationPolicy*>(static_cast<const ProcessingEngineBase*>(this)->get_accel());
}
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // HAVE_ONEVPL
|