#include "opencv2/core/base.hpp"
#include "cap_mfx_common.hpp"
#include "opencv2/imgproc/hal/hal.hpp"
+#include "cap_interface.hpp"
using namespace cv;
using namespace std;
return;
}
+ frameSize = Size(params.mfx.FrameInfo.CropW, params.mfx.FrameInfo.CropH);
good = true;
}
cleanup(deviceHandler);
}
- double VideoCapture_IntelMFX::getProperty(int) const
+ double VideoCapture_IntelMFX::getProperty(int prop) const
{
- MSG(cerr << "MFX: getProperty() is not implemented" << endl);
- return 0;
+ if (!good)
+ {
+ MSG(cerr << "MFX: can not call getProperty(), backend has not been initialized" << endl);
+ return 0;
+ }
+ switch (prop)
+ {
+ case CAP_PROP_FRAME_WIDTH:
+ return frameSize.width;
+ case CAP_PROP_FRAME_HEIGHT:
+ return frameSize.height;
+ default:
+ MSG(cerr << "MFX: unsupported property" << endl);
+ return 0;
+ }
}
bool VideoCapture_IntelMFX::setProperty(int, double)
}
//==================================================================================================
+
+cv::Ptr<IVideoCapture> cv::create_MFX_capture(const std::string &filename)
+{
+ return cv::makePtr<VideoCapture_IntelMFX>(filename);
+}
{
public:
VideoCapture_IntelMFX(const cv::String &filename);
- virtual ~VideoCapture_IntelMFX();
- virtual double getProperty(int) const CV_OVERRIDE;
- virtual bool setProperty(int, double) CV_OVERRIDE;
- virtual bool grabFrame() CV_OVERRIDE;
- virtual bool retrieveFrame(int, cv::OutputArray out) CV_OVERRIDE;
- virtual bool isOpened() const CV_OVERRIDE;
- virtual int getCaptureDomain() CV_OVERRIDE;
+ ~VideoCapture_IntelMFX();
+ double getProperty(int) const CV_OVERRIDE;
+ bool setProperty(int, double) CV_OVERRIDE;
+ bool grabFrame() CV_OVERRIDE;
+ bool retrieveFrame(int, cv::OutputArray out) CV_OVERRIDE;
+ bool isOpened() const CV_OVERRIDE;
+ int getCaptureDomain() CV_OVERRIDE;
private:
MFXVideoSession *session;
Plugin *plugin;
MFXVideoDECODE *decoder;
SurfacePool *pool;
void *outSurface;
+ cv::Size frameSize;
bool good;
};
#include "test_precomp.hpp"
-#ifdef HAVE_MFX
-
namespace opencv_test { namespace {
-TEST(Videoio_MFX, read_invalid)
+TEST(videoio_mfx, read_invalid)
{
+ if (!videoio_registry::hasBackend(CAP_INTEL_MFX))
+ throw SkipTestException("MediaSDK backend was not found");
+
VideoCapture cap;
ASSERT_NO_THROW(cap.open("nonexistent-file", CAP_INTEL_MFX));
ASSERT_FALSE(cap.isOpened());
ASSERT_TRUE(img.empty());
}
-TEST(Videoio_MFX, write_invalid)
+TEST(videoio_mfx, write_invalid)
{
+ if (!videoio_registry::hasBackend(CAP_INTEL_MFX))
+ throw SkipTestException("MediaSDK backend was not found");
+
const string filename = cv::tempfile(".264");
VideoWriter writer;
bool res = true;
//==================================================================================================
typedef tuple<Size, double, const char *> Size_FPS_Ext;
-typedef testing::TestWithParam< Size_FPS_Ext > Videoio_MFX;
+typedef testing::TestWithParam< Size_FPS_Ext > videoio_mfx;
-TEST_P(Videoio_MFX, read_write_raw)
+TEST_P(videoio_mfx, read_write_raw)
{
+ if (!videoio_registry::hasBackend(CAP_INTEL_MFX))
+ throw SkipTestException("MediaSDK backend was not found");
+
const Size FRAME_SIZE = get<0>(GetParam());
const double FPS = get<1>(GetParam());
const char *ext = get<2>(GetParam());
VideoCapture cap;
cap.open(filename, CAP_INTEL_MFX);
ASSERT_TRUE(cap.isOpened());
+ EXPECT_EQ(FRAME_SIZE.width, cap.get(CAP_PROP_FRAME_WIDTH));
+ EXPECT_EQ(FRAME_SIZE.height, cap.get(CAP_PROP_FRAME_HEIGHT));
for (int i = 0; i < FRAME_COUNT; ++i)
{
ASSERT_TRUE(cap.read(frame));
remove(filename.c_str());
}
-INSTANTIATE_TEST_CASE_P(videoio, Videoio_MFX,
+inline static std::string videoio_mfx_name_printer(const testing::TestParamInfo<videoio_mfx::ParamType>& info)
+{
+ std::ostringstream out;
+ const Size sz = get<0>(info.param);
+ const std::string ext = get<2>(info.param);
+ out << sz.width << "x" << sz.height << "x" << get<1>(info.param) << "x" << ext.substr(1, ext.size() - 1);
+ return out.str();
+}
+
+INSTANTIATE_TEST_CASE_P(videoio, videoio_mfx,
testing::Combine(
testing::Values(Size(640, 480), Size(638, 478), Size(636, 476), Size(1920, 1080)),
testing::Values(1, 30, 100),
- testing::Values(".mpeg2", ".264", ".265")));
+ testing::Values(".mpeg2", ".264", ".265")),
+ videoio_mfx_name_printer);
}} // namespace
-
-#endif