Skip to content

Commit ae1fb8c

Browse files
authored
Merge pull request opencv#26224 from mshabunin:cpp-videoio-backport
C-API cleanup: backport videoio changes from 5.x
2 parents 783fe72 + 305b57e commit ae1fb8c

26 files changed

+1438
-1966
lines changed

modules/core/include/opencv2/core/cvdef.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,17 @@ typedef hfloat float16_t;
928928
}
929929
#endif
930930

931+
/** @brief Constructs the 'fourcc' code, used in video codecs and many other places.
932+
Simply call it with 4 chars like `CV_FOURCC('I', 'Y', 'U', 'V')`
933+
*/
934+
CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4)
935+
{
936+
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24);
937+
}
938+
939+
//! Macro to construct the fourcc code of the codec. Same as CV_FOURCC()
940+
#define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24))
941+
931942
//! @}
932943

933944
#ifndef __cplusplus

modules/dnn/include/opencv2/dnn/shape_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define OPENCV_DNN_DNN_SHAPE_UTILS_HPP
4444

4545
#include <opencv2/dnn/dnn.hpp>
46-
#include <opencv2/core/types_c.h> // CV_MAX_DIM
46+
#include <opencv2/core/cvdef.h> // CV_MAX_DIM
4747
#include <iostream>
4848
#include <ostream>
4949
#include <sstream>

modules/videoio/include/opencv2/videoio/container_avi.private.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
# error this is a private header which should not be used from outside of the OpenCV library
1010
#endif
1111

12-
#include "opencv2/core/cvdef.h"
13-
#include "opencv2/videoio/videoio_c.h"
12+
#include "opencv2/core/types.hpp"
1413
#include <deque>
14+
#include <vector>
15+
#include <string>
16+
#include <memory>
1517

1618
namespace cv
1719
{
@@ -80,8 +82,8 @@ class CV_EXPORTS AVIReadContainer
8082
public:
8183
AVIReadContainer();
8284

83-
void initStream(const String& filename);
84-
void initStream(Ptr<VideoInputStream> m_file_stream_);
85+
void initStream(const std::string& filename);
86+
void initStream(std::shared_ptr<VideoInputStream> m_file_stream_);
8587

8688
void close();
8789
//stores founded frames in m_frame_list which can be accessed via getFrames
@@ -121,7 +123,7 @@ class CV_EXPORTS AVIReadContainer
121123

122124
void printError(RiffChunk& chunk, unsigned int expected_fourcc);
123125

124-
Ptr<VideoInputStream> m_file_stream;
126+
std::shared_ptr<VideoInputStream> m_file_stream;
125127
unsigned int m_stream_id;
126128
unsigned long long int m_movi_start;
127129
unsigned long long int m_movi_end;
@@ -150,7 +152,7 @@ class CV_EXPORTS AVIWriteContainer
150152
AVIWriteContainer();
151153
~AVIWriteContainer();
152154

153-
bool initContainer(const String& filename, double fps, Size size, bool iscolor);
155+
bool initContainer(const std::string& filename, double fps, cv::Size size, bool iscolor);
154156
void startWriteAVI(int stream_count);
155157
void writeStreamHeader(Codecs codec_);
156158
void startWriteChunk(uint32_t fourcc);
@@ -180,7 +182,7 @@ class CV_EXPORTS AVIWriteContainer
180182
void jflushStream(unsigned currval, int bitIdx);
181183

182184
private:
183-
Ptr<BitStream> strm;
185+
std::shared_ptr<BitStream> strm;
184186
int outfps;
185187
int width, height, channels;
186188
size_t moviPointer;

modules/videoio/include/opencv2/videoio/legacy/constants_c.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef OPENCV_VIDEOIO_LEGACY_CONSTANTS_H
66
#define OPENCV_VIDEOIO_LEGACY_CONSTANTS_H
77

8+
#include "opencv2/core/cvdef.h"
9+
810
enum
911
{
1012
CV_CAP_ANY =0, // autodetect
@@ -410,22 +412,6 @@ enum
410412
CV_CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode.
411413
};
412414

413-
//! Macro to construct the fourcc code of the codec. Same as CV_FOURCC()
414-
#define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24))
415-
416-
/** @brief Constructs the fourcc code of the codec function
417-
418-
Simply call it with 4 chars fourcc code like `CV_FOURCC('I', 'Y', 'U', 'V')`
419-
420-
List of codes can be obtained at [Video Codecs by FOURCC](https://fourcc.org/codecs.php) page.
421-
FFMPEG backend with MP4 container natively uses other values as fourcc code:
422-
see [ObjectType](http://mp4ra.org/#/codecs).
423-
*/
424-
CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4)
425-
{
426-
return CV_FOURCC_MACRO(c1, c2, c3, c4);
427-
}
428-
429415
//! (Windows only) Open Codec Selection Dialog
430416
#define CV_FOURCC_PROMPT -1
431417
//! (Linux only) Use default codec for specified filename

modules/videoio/src/cap_android_camera.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,17 @@ class AndroidCameraCapture : public IVideoCapture
403403
double getProperty(int property_id) const CV_OVERRIDE
404404
{
405405
switch (property_id) {
406-
case CV_CAP_PROP_FRAME_WIDTH:
406+
case CAP_PROP_FRAME_WIDTH:
407407
return isOpened() ? frameWidth : desiredWidth;
408-
case CV_CAP_PROP_FRAME_HEIGHT:
408+
case CAP_PROP_FRAME_HEIGHT:
409409
return isOpened() ? frameHeight : desiredHeight;
410410
case CAP_PROP_AUTO_EXPOSURE:
411411
return autoExposure ? 1 : 0;
412-
case CV_CAP_PROP_EXPOSURE:
412+
case CAP_PROP_EXPOSURE:
413413
return exposureTime;
414-
case CV_CAP_PROP_ISO_SPEED:
414+
case CAP_PROP_ISO_SPEED:
415415
return sensitivity;
416-
case CV_CAP_PROP_FOURCC:
416+
case CAP_PROP_FOURCC:
417417
return fourCC;
418418
default:
419419
break;
@@ -425,7 +425,7 @@ class AndroidCameraCapture : public IVideoCapture
425425
bool setProperty(int property_id, double value) CV_OVERRIDE
426426
{
427427
switch (property_id) {
428-
case CV_CAP_PROP_FRAME_WIDTH:
428+
case CAP_PROP_FRAME_WIDTH:
429429
desiredWidth = value;
430430
settingWidth = true;
431431
if (settingWidth && settingHeight) {
@@ -434,7 +434,7 @@ class AndroidCameraCapture : public IVideoCapture
434434
settingHeight = false;
435435
}
436436
return true;
437-
case CV_CAP_PROP_FRAME_HEIGHT:
437+
case CAP_PROP_FRAME_HEIGHT:
438438
desiredHeight = value;
439439
settingHeight = true;
440440
if (settingWidth && settingHeight) {
@@ -443,7 +443,7 @@ class AndroidCameraCapture : public IVideoCapture
443443
settingHeight = false;
444444
}
445445
return true;
446-
case CV_CAP_PROP_FOURCC:
446+
case CAP_PROP_FOURCC:
447447
{
448448
uint32_t newFourCC = cvRound(value);
449449
if (fourCC == newFourCC) {
@@ -485,18 +485,18 @@ class AndroidCameraCapture : public IVideoCapture
485485
return status == ACAMERA_OK;
486486
}
487487
return true;
488-
case CV_CAP_PROP_EXPOSURE:
488+
case CAP_PROP_EXPOSURE:
489489
if (isOpened() && exposureRange.Supported()) {
490490
exposureTime = (int64_t)value;
491-
LOGI("Setting CV_CAP_PROP_EXPOSURE will have no effect unless CAP_PROP_AUTO_EXPOSURE is off");
491+
LOGI("Setting CAP_PROP_EXPOSURE will have no effect unless CAP_PROP_AUTO_EXPOSURE is off");
492492
camera_status_t status = ACaptureRequest_setEntry_i64(captureRequest.get(), ACAMERA_SENSOR_EXPOSURE_TIME, 1, &exposureTime);
493493
return status == ACAMERA_OK;
494494
}
495495
return false;
496-
case CV_CAP_PROP_ISO_SPEED:
496+
case CAP_PROP_ISO_SPEED:
497497
if (isOpened() && sensitivityRange.Supported()) {
498498
sensitivity = (int32_t)value;
499-
LOGI("Setting CV_CAP_PROP_ISO_SPEED will have no effect unless CAP_PROP_AUTO_EXPOSURE is off");
499+
LOGI("Setting CAP_PROP_ISO_SPEED will have no effect unless CAP_PROP_AUTO_EXPOSURE is off");
500500
camera_status_t status = ACaptureRequest_setEntry_i32(captureRequest.get(), ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity);
501501
return status == ACAMERA_OK;
502502
}

modules/videoio/src/cap_android_mediandk.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,16 @@ class AndroidMediaNdkCapture : public IVideoCapture
182182
{
183183
switch (property_id)
184184
{
185-
case CV_CAP_PROP_FRAME_WIDTH:
185+
case CAP_PROP_FRAME_WIDTH:
186186
return (( videoOrientationAuto &&
187187
(cv::ROTATE_90_CLOCKWISE == videoRotationCode || cv::ROTATE_90_COUNTERCLOCKWISE == videoRotationCode))
188188
? videoHeight : videoWidth);
189-
case CV_CAP_PROP_FRAME_HEIGHT:
189+
case CAP_PROP_FRAME_HEIGHT:
190190
return (( videoOrientationAuto &&
191191
(cv::ROTATE_90_CLOCKWISE == videoRotationCode || cv::ROTATE_90_COUNTERCLOCKWISE == videoRotationCode))
192192
? videoWidth : videoHeight);
193-
case CV_CAP_PROP_FPS: return videoFrameRate;
194-
case CV_CAP_PROP_FRAME_COUNT: return videoFrameCount;
193+
case CAP_PROP_FPS: return videoFrameRate;
194+
case CAP_PROP_FRAME_COUNT: return videoFrameCount;
195195
case CAP_PROP_ORIENTATION_META: return videoRotation;
196196
case CAP_PROP_ORIENTATION_AUTO: return videoOrientationAuto ? 1 : 0;
197197
}
@@ -661,7 +661,7 @@ const AndroidMediaNdkVideoWriter::FourCCInfo AndroidMediaNdkVideoWriter::FOURCC_
661661
{ CV_FOURCC('H', '2', '6', '5'), "video/hevc", AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 },
662662
{ CV_FOURCC('H', '2', '6', '3'), "video/3gpp", AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 },
663663
{ CV_FOURCC('M', 'P', '4', 'V'), "video/mp4v-es", AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 },
664-
{ 0, NULL },
664+
{ 0, NULL, AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 },
665665
};
666666

667667

0 commit comments

Comments
 (0)