Skip to content

Commit

Permalink
videoio: refactor AVFoundation code integration
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Sep 9, 2016
1 parent 0882936 commit f85e33f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 98 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down Expand Up @@ -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) )
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 11 additions & 19 deletions cmake/OpenCVFindLibsVideo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -302,26 +302,18 @@ if(WIN32)
endif()
endif(WIN32)

# --- Apple AV Foundation (iOS) ---
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)
if(APPLE)
if(WITH_AVFOUNDATION)
set(HAVE_AVFOUNDATION YES)
endif()
if(NOT IOS)
if(WITH_QUICKTIME)
set(HAVE_QUICKTIME YES)
elseif(WITH_QTKIT)
set(HAVE_QTKIT YES)
endif()
endif()
endif()
endif(APPLE)

# --- Intel Perceptual Computing SDK ---
if(WITH_INTELPERC)
Expand Down
3 changes: 0 additions & 3 deletions cmake/templates/cvconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
/* AVFoundation video libraries */
#cmakedefine HAVE_AVFOUNDATION

/* AVFoundation (Mac) video libraries */
#cmakedefine HAVE_AVFOUNDATION_MAC

/* V4L capturing support */
#cmakedefine HAVE_CAMV4L

Expand Down
13 changes: 7 additions & 6 deletions modules/videoio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ if(HAVE_GIGE_API)
endif(HAVE_GIGE_API)

if(HAVE_AVFOUNDATION)
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)
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")
if(IOS)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
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)
Expand Down
57 changes: 28 additions & 29 deletions modules/videoio/include/opencv2/videoio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,34 @@ To enable/disable APIs, you have to:
2. rebuild OpenCV itself
*/
enum VideoCaptureAPIs {
CAP_ANY = 0, //!< Auto detect
CAP_VFW = 200, //!< Video For Windows (platform native)
CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l
CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L
CAP_FIREWIRE = 300, //!< IEEE 1394 drivers
CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_QT = 500, //!< QuickTime
CAP_UNICAP = 600, //!< Unicap drivers
CAP_DSHOW = 700, //!< DirectShow (via videoInput)
CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK
CAP_OPENNI = 900, //!< OpenNI (for Kinect)
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_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK
CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput)
CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation
CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK
CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect)
CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors)
CAP_GPHOTO2 = 1700, //!< gPhoto2 connection
CAP_GSTREAMER = 1800, //!< GStreamer
CAP_FFMPEG = 1900, //!< FFMPEG
CAP_IMAGES = 2000 //!< OpenCV Image Sequence (e.g. img_%02d.jpg)
CAP_ANY = 0, //!< Auto detect
CAP_VFW = 200, //!< Video For Windows (platform native)
CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l
CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L
CAP_FIREWIRE = 300, //!< IEEE 1394 drivers
CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_QT = 500, //!< QuickTime
CAP_UNICAP = 600, //!< Unicap drivers
CAP_DSHOW = 700, //!< DirectShow (via videoInput)
CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK
CAP_OPENNI = 900, //!< OpenNI (for Kinect)
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 (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
CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK
CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect)
CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors)
CAP_GPHOTO2 = 1700, //!< gPhoto2 connection
CAP_GSTREAMER = 1800, //!< GStreamer
CAP_FFMPEG = 1900, //!< FFMPEG
CAP_IMAGES = 2000 //!< OpenCV Image Sequence (e.g. img_%02d.jpg)
};

//! generic properties (based on DC1394 properties)
Expand Down
1 change: 0 additions & 1 deletion modules/videoio/include/opencv2/videoio/videoio_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 0 additions & 16 deletions modules/videoio/src/cap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions modules/videoio/src/cap_avfoundation_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,18 @@ - (IplImage*)getOutput;

/*****************************************************************************
*
* 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;
Expand All @@ -203,7 +203,7 @@ - (IplImage*)getOutput;
/****************** 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())
Expand All @@ -212,17 +212,17 @@ - (IplImage*)getOutput;
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 ****************************/
Expand Down Expand Up @@ -1087,14 +1087,14 @@ -(int) updateImage {

/*****************************************************************************
*
* 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) {

Expand Down Expand Up @@ -1222,7 +1222,7 @@ -(int) updateImage {
}


CvVideoWriter_AVFoundation_Mac::~CvVideoWriter_AVFoundation_Mac() {
CvVideoWriter_AVFoundation::~CvVideoWriter_AVFoundation() {
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];

[mMovieWriterInput markAsFinished];
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions modules/videoio/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f85e33f

Please sign in to comment.