videoio: refactor AVFoundation code integration

pull/7266/head
Alexander Alekhin 8 years ago
parent 0882936707
commit f85e33f4af
  1. 15
      CMakeLists.txt
  2. 12
      cmake/OpenCVFindLibsVideo.cmake
  3. 3
      cmake/templates/cvconfig.h.in
  4. 5
      modules/videoio/CMakeLists.txt
  5. 3
      modules/videoio/include/opencv2/videoio.hpp
  6. 1
      modules/videoio/include/opencv2/videoio/videoio_c.h
  7. 16
      modules/videoio/src/cap.cpp
  8. 28
      modules/videoio/src/cap_avfoundation_mac.mm
  9. 4
      modules/videoio/src/precomp.hpp

@ -169,8 +169,7 @@ OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF)
# Optional 3rd party components
# ===================================================
OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS)" ON IF IOS)
OCV_OPTION(WITH_AVFOUNDATION_MAC "Use AVFoundation for Video I/O (Mac)" ON IF (NOT IOS AND APPLE) )
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON IF APPLE)
OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa" OFF IF APPLE )
OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON IF (ARM OR AARCH64) AND NOT IOS AND NOT (CMAKE_VERSION VERSION_LESS "2.8.11"))
OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING) )
@ -199,7 +198,8 @@ OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF
OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON IF WIN32 AND NOT WINRT)
OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O insted of QTKit" OFF IF APPLE )
OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O" OFF IF APPLE )
OCV_OPTION(WITH_QTKIT "Use QTKit Video I/O backend" OFF IF APPLE )
OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF IF (NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_OPENMP "Include OpenMP support" OFF)
OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF IF (WIN32 AND NOT WINRT) )
@ -1110,10 +1110,13 @@ if(DEFINED WITH_GIGEAPI)
endif(DEFINED WITH_GIGEAPI)
if(DEFINED APPLE)
status(" AVFoundation:" HAVE_AVFOUNDATION THEN YES ELSE NO)
if(WITH_QUICKTIME OR HAVE_QUICKTIME)
status(" QuickTime:" HAVE_QUICKTIME THEN YES ELSE NO)
status(" QTKit:" HAVE_QTKIT THEN YES ELSE NO)
status(" AVFoundation:" WITH_AVFOUNDATION THEN YES ELSE NO)
status(" AVFoundationMac:" WITH_AVFOUNDATION_MAC THEN YES ELSE NO)
endif()
if(WITH_QTKIT OR HAVE_QTKIT)
status(" QTKit:" HAVE_QTKIT THEN "YES (deprecated)" ELSE NO)
endif()
endif(DEFINED APPLE)
if(DEFINED WITH_UNICAP)

@ -302,26 +302,18 @@ if(WIN32)
endif()
endif(WIN32)
# --- Apple AV Foundation (iOS) ---
if(APPLE)
if(WITH_AVFOUNDATION)
set(HAVE_AVFOUNDATION YES)
endif()
# --- Apple AV Foundation (Mac) ---
if(WITH_AVFOUNDATION_MAC)
set(HAVE_AVFOUNDATION_MAC YES)
endif()
# --- QuickTime, Apple AV Foundation (Mac) ---
if(NOT IOS)
if(WITH_QUICKTIME)
set(HAVE_QUICKTIME YES)
elseif(WITH_QTKIT)
set(HAVE_QTKIT YES)
elseif(APPLE AND CMAKE_COMPILER_IS_CLANGCXX)
set(HAVE_AVFOUNDATION_MAC YES)
endif()
endif()
endif(APPLE)
# --- Intel Perceptual Computing SDK ---
if(WITH_INTELPERC)

@ -16,9 +16,6 @@
/* AVFoundation video libraries */
#cmakedefine HAVE_AVFOUNDATION
/* AVFoundation (Mac) video libraries */
#cmakedefine HAVE_AVFOUNDATION_MAC
/* V4L capturing support */
#cmakedefine HAVE_CAMV4L

@ -168,13 +168,14 @@ if(HAVE_GIGE_API)
endif(HAVE_GIGE_API)
if(HAVE_AVFOUNDATION)
if(IOS)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
endif()
if(HAVE_AVFOUNDATION_MAC)
else()
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation_mac.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework Cocoa" "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore")
endif()
endif()
if(HAVE_QUICKTIME)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_qt.cpp)

@ -99,8 +99,7 @@ enum VideoCaptureAPIs {
CAP_OPENNI_ASUS = 910, //!< OpenNI (for Asus Xtion)
CAP_ANDROID = 1000, //!< Android - not used
CAP_XIAPI = 1100, //!< XIMEA Camera API
CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS
CAP_AVFOUNDATION_MAC = 1210, //!< AVFoundation framework for macOS
CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS (OS X Lion will have the same API)
CAP_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK
CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput)
CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation

@ -108,7 +108,6 @@ enum
CV_CAP_XIAPI =1100, // XIMEA Camera API
CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
CV_CAP_AVFOUNDATION_MAC = 1210, // AVFoundation framework for Mac
CV_CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK

@ -266,12 +266,6 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
if (pref) break;
#endif
#ifdef HAVE_AVFOUNDATION_MAC
case CV_CAP_AVFOUNDATION_MAC:
TRY_OPEN(capture, cvCreateCameraCapture_AVFoundation_Mac(index))
if (pref) break;
#endif
#ifdef HAVE_GIGE_API
case CV_CAP_GIGANETIX:
TRY_OPEN(capture, cvCreateCameraCapture_Giganetix(index))
@ -340,12 +334,6 @@ CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, in
if (apiPreference) break;
#endif
#ifdef HAVE_AVFOUNDATION_MAC
case CV_CAP_AVFOUNDATION_MAC:
TRY_OPEN(result, cvCreateFileCapture_AVFoundation_Mac(filename))
if (apiPreference) break;
#endif
#ifdef HAVE_OPENNI
case CV_CAP_OPENNI:
TRY_OPEN(result, cvCreateFileCapture_OpenNI (filename))
@ -403,10 +391,6 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color))
#endif
#ifdef HAVE_AVFOUNDATION_MAC
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation_Mac(filename, fourcc, fps, frameSize, is_color))
#endif
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
TRY_OPEN(result, cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color))
#endif

@ -171,18 +171,18 @@ private:
/*****************************************************************************
*
* CvVideoWriter_AVFoundation_Mac Declaration.
* CvVideoWriter_AVFoundation Declaration.
*
* CvVideoWriter_AVFoundation_Mac is the instantiation of a video output class.
* CvVideoWriter_AVFoundation is the instantiation of a video output class.
*
*****************************************************************************/
class CvVideoWriter_AVFoundation_Mac : public CvVideoWriter {
class CvVideoWriter_AVFoundation : public CvVideoWriter {
public:
CvVideoWriter_AVFoundation_Mac(const char* filename, int fourcc,
CvVideoWriter_AVFoundation(const char* filename, int fourcc,
double fps, CvSize frame_size,
int is_color=1);
~CvVideoWriter_AVFoundation_Mac();
~CvVideoWriter_AVFoundation();
bool writeFrame(const IplImage* image);
private:
IplImage* argbimage;
@ -203,7 +203,7 @@ class CvVideoWriter_AVFoundation_Mac : public CvVideoWriter {
/****************** Implementation of interface functions ********************/
CvCapture* cvCreateFileCapture_AVFoundation_Mac(const char* filename) {
CvCapture* cvCreateFileCapture_AVFoundation(const char* filename) {
CvCaptureFile *retval = new CvCaptureFile(filename);
if(retval->didStart())
@ -212,17 +212,17 @@ CvCapture* cvCreateFileCapture_AVFoundation_Mac(const char* filename) {
return NULL;
}
CvCapture* cvCreateCameraCapture_AVFoundation_Mac(int index ) {
CvCapture* cvCreateCameraCapture_AVFoundation(int index ) {
CvCapture* retval = new CvCaptureCAM(index);
if (!((CvCaptureCAM *)retval)->didStart())
cvReleaseCapture(&retval);
return retval;
}
CvVideoWriter* cvCreateVideoWriter_AVFoundation_Mac(const char* filename, int fourcc,
CvVideoWriter* cvCreateVideoWriter_AVFoundation(const char* filename, int fourcc,
double fps, CvSize frame_size,
int is_color) {
return new CvVideoWriter_AVFoundation_Mac(filename, fourcc, fps, frame_size,is_color);
return new CvVideoWriter_AVFoundation(filename, fourcc, fps, frame_size,is_color);
}
/********************** Implementation of Classes ****************************/
@ -1087,14 +1087,14 @@ bool CvCaptureFile::setProperty(int property_id, double value) {
/*****************************************************************************
*
* CvVideoWriter_AVFoundation_Mac Implementation.
* CvVideoWriter_AVFoundation Implementation.
*
* CvVideoWriter_AVFoundation_Mac is the instantiation of a video output class.
* CvVideoWriter_AVFoundation is the instantiation of a video output class.
*
*****************************************************************************/
CvVideoWriter_AVFoundation_Mac::CvVideoWriter_AVFoundation_Mac(const char* filename, int fourcc,
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(const char* filename, int fourcc,
double fps, CvSize frame_size,
int is_color) {
@ -1222,7 +1222,7 @@ CvVideoWriter_AVFoundation_Mac::CvVideoWriter_AVFoundation_Mac(const char* filen
}
CvVideoWriter_AVFoundation_Mac::~CvVideoWriter_AVFoundation_Mac() {
CvVideoWriter_AVFoundation::~CvVideoWriter_AVFoundation() {
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
[mMovieWriterInput markAsFinished];
@ -1243,7 +1243,7 @@ static void releaseCallback( void *releaseRefCon, const void * ) {
CFRelease((CFDataRef)releaseRefCon);
}
bool CvVideoWriter_AVFoundation_Mac::writeFrame(const IplImage* iplimage) {
bool CvVideoWriter_AVFoundation::writeFrame(const IplImage* iplimage) {
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
// writer status check

@ -127,7 +127,6 @@ CvCapture* cvCreateFileCapture_OpenNI( const char* filename );
CvCapture* cvCreateCameraCapture_Android( int index );
CvCapture* cvCreateCameraCapture_XIMEA( int index );
CvCapture* cvCreateCameraCapture_AVFoundation(int index);
CvCapture* cvCreateCameraCapture_AVFoundation_Mac(int index);
CvCapture* cvCreateFileCapture_Images(const char* filename);
CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
@ -156,9 +155,6 @@ CvVideoWriter* cvCreateVideoWriter_QT ( const char* filename, int fourcc,
CvCapture* cvCreateFileCapture_AVFoundation (const char * filename);
CvVideoWriter* cvCreateVideoWriter_AVFoundation( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color );
CvCapture* cvCreateFileCapture_AVFoundation_Mac(const char * filename);
CvVideoWriter* cvCreateVideoWriter_AVFoundation_Mac( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color );
CvCapture * cvCreateCameraCapture_Unicap (const int index);

Loading…
Cancel
Save