Merge remote-tracking branch 'upstream/3.4' into merge-3.4
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 5 Nov 2020 18:59:10 +0000 (18:59 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 5 Nov 2020 18:59:10 +0000 (18:59 +0000)
1  2 
modules/videoio/src/cap_mfx_reader.cpp
modules/videoio/src/cap_mfx_reader.hpp
modules/videoio/test/test_mfx.cpp

@@@ -6,7 -6,6 +6,7 @@@
  #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;
@@@ -112,6 -111,7 +112,7 @@@ VideoCapture_IntelMFX::VideoCapture_Int
          return;
      }
  
+     frameSize = Size(params.mfx.FrameInfo.CropW, params.mfx.FrameInfo.CropH);
      good = true;
  }
  
@@@ -127,10 -127,23 +128,23 @@@ VideoCapture_IntelMFX::~VideoCapture_In
      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)
@@@ -265,8 -278,3 +279,8 @@@ int VideoCapture_IntelMFX::getCaptureDo
  }
  
  //==================================================================================================
 +
 +cv::Ptr<IVideoCapture> cv::create_MFX_capture(const std::string &filename)
 +{
 +    return cv::makePtr<VideoCapture_IntelMFX>(filename);
 +}
@@@ -19,13 -19,13 +19,13 @@@ class VideoCapture_IntelMFX : public cv
  {
  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;
@@@ -34,6 -34,7 +34,7 @@@
      MFXVideoDECODE *decoder;
      SurfacePool *pool;
      void *outSurface;
+     cv::Size frameSize;
      bool good;
  };
  
@@@ -4,13 -4,12 +4,13 @@@
  
  #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;
@@@ -84,13 -80,10 +84,13 @@@ inline int fourccByExt(const String &ex
  //==================================================================================================
  
  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