test_microphone.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. // Usage: opencv_test_videoio --gtest_also_run_disabled_tests
  5. #include "test_precomp.hpp"
  6. namespace opencv_test { namespace {
  7. TEST(DISABLED_videoio_micro, basic)
  8. {
  9. int cursize = 0;
  10. int validSize = 0;
  11. Mat frame;
  12. std::vector<int> params { CAP_PROP_AUDIO_STREAM, 0, CAP_PROP_VIDEO_STREAM, -1 };
  13. VideoCapture cap(0, cv::CAP_MSMF, params);
  14. ASSERT_TRUE(cap.isOpened());
  15. int samplesPerSecond = (int)cap.get(cv::CAP_PROP_AUDIO_SAMPLES_PER_SECOND);
  16. const int audio_base_index = (int)cap.get(cv::CAP_PROP_AUDIO_BASE_INDEX);
  17. const double cvTickFreq = cv::getTickFrequency();
  18. int64 sysTimePrev = cv::getTickCount();
  19. int64 sysTimeCurr = cv::getTickCount();
  20. cout << "Audio would be captured for the next 10 seconds" << endl;
  21. while ((sysTimeCurr-sysTimePrev)/cvTickFreq < 10)
  22. {
  23. if (cap.grab())
  24. {
  25. ASSERT_TRUE(cap.retrieve(frame, audio_base_index));
  26. sysTimeCurr = cv::getTickCount();
  27. }
  28. }
  29. validSize = samplesPerSecond*(int)((sysTimeCurr-sysTimePrev)/cvTickFreq);
  30. cursize = (int)cap.get(cv::CAP_PROP_AUDIO_POS);
  31. ASSERT_LT(validSize - cursize, cursize*0.05);
  32. }
  33. }} // namespace