Commit d9e4ad3f authored by Alexander Reshetnikov's avatar Alexander Reshetnikov

Code style refactoring for ffmpeg wrappers

parent 3514042b
...@@ -316,13 +316,13 @@ bool CvCapture_FFMPEG::reopen() ...@@ -316,13 +316,13 @@ bool CvCapture_FFMPEG::reopen()
} }
#ifndef AVSEEK_FLAG_FRAME #ifndef AVSEEK_FLAG_FRAME
#define AVSEEK_FLAG_FRAME 0 #define AVSEEK_FLAG_FRAME 0
#endif #endif
#ifndef AVSEEK_FLAG_ANY #ifndef AVSEEK_FLAG_ANY
#define AVSEEK_FLAG_ANY 1 #define AVSEEK_FLAG_ANY 1
#endif #endif
#ifndef SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER #ifndef SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER
#define SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER 25 #define SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER 25
#endif #endif
bool CvCapture_FFMPEG::open( const char* _filename ) bool CvCapture_FFMPEG::open( const char* _filename )
...@@ -358,9 +358,9 @@ bool CvCapture_FFMPEG::open( const char* _filename ) ...@@ -358,9 +358,9 @@ bool CvCapture_FFMPEG::open( const char* _filename )
avcodec_thread_init(enc, get_number_of_cpus()); avcodec_thread_init(enc, get_number_of_cpus());
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0) #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
#endif #endif
if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) { if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) {
AVCodec *codec = avcodec_find_decoder(enc->codec_id); AVCodec *codec = avcodec_find_decoder(enc->codec_id);
...@@ -406,7 +406,7 @@ bool CvCapture_FFMPEG::open( const char* _filename ) ...@@ -406,7 +406,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
int flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD; int flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD;
av_seek_frame(ic, video_stream, ts, flags); av_seek_frame(ic, video_stream, ts, flags);
} }
exit_func: exit_func:
if( !valid ) if( !valid )
close(); close();
...@@ -452,15 +452,15 @@ bool CvCapture_FFMPEG::grabFrame() ...@@ -452,15 +452,15 @@ bool CvCapture_FFMPEG::grabFrame()
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet); avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
#else #else
#if LIBAVFORMAT_BUILD > 4628 #if LIBAVFORMAT_BUILD > 4628
avcodec_decode_video(video_st->codec, avcodec_decode_video(video_st->codec,
picture, &got_picture, picture, &got_picture,
packet.data, packet.size); packet.data, packet.size);
#else #else
avcodec_decode_video(&video_st->codec, avcodec_decode_video(&video_st->codec,
picture, &got_picture, picture, &got_picture,
packet.data, packet.size); packet.data, packet.size);
#endif #endif
#endif #endif
if (got_picture) { if (got_picture) {
...@@ -959,9 +959,9 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_ ...@@ -959,9 +959,9 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
AVPacket pkt; AVPacket pkt;
av_init_packet(&pkt); av_init_packet(&pkt);
#ifndef PKT_FLAG_KEY #ifndef PKT_FLAG_KEY
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY #define PKT_FLAG_KEY AV_PKT_FLAG_KEY
#endif #endif
pkt.flags |= PKT_FLAG_KEY; pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= video_st->index; pkt.stream_index= video_st->index;
...@@ -1067,7 +1067,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int ...@@ -1067,7 +1067,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
} }
// check if buffer sizes match, i.e. image has expected format (size, channels, bitdepth, alignment) // check if buffer sizes match, i.e. image has expected format (size, channels, bitdepth, alignment)
/*#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(37<<8)+0) /*#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(37<<8)+0)
assert (image->imageSize == avpicture_get_size( (PixelFormat)input_pix_fmt, image->width, image->height )); assert (image->imageSize == avpicture_get_size( (PixelFormat)input_pix_fmt, image->width, image->height ));
#else #else
assert (image->imageSize == avpicture_get_size( input_pix_fmt, image->width, image->height )); assert (image->imageSize == avpicture_get_size( input_pix_fmt, image->width, image->height ));
...@@ -1186,12 +1186,12 @@ void CvVideoWriter_FFMPEG::close() ...@@ -1186,12 +1186,12 @@ void CvVideoWriter_FFMPEG::close()
} }
init(); init();
} }
/// Create a video writer object that uses FFMPEG /// Create a video writer object that uses FFMPEG
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
double fps, int width, int height, bool is_color ) double fps, int width, int height, bool is_color )
{ {
CodecID codec_id = CODEC_ID_NONE; CodecID codec_id = CODEC_ID_NONE;
int err, codec_pix_fmt, bitrate_scale = 64; int err, codec_pix_fmt, bitrate_scale = 64;
...@@ -1361,12 +1361,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, ...@@ -1361,12 +1361,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
av_write_header( oc ); av_write_header( oc );
return true; return true;
} }
CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename ) CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
{ {
CvCapture_FFMPEG* capture = (CvCapture_FFMPEG*)malloc(sizeof(*capture)); CvCapture_FFMPEG* capture = (CvCapture_FFMPEG*)malloc(sizeof(*capture));
capture->init(); capture->init();
if( capture->open( filename )) if( capture->open( filename ))
...@@ -1374,44 +1374,44 @@ CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename ) ...@@ -1374,44 +1374,44 @@ CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
capture->close(); capture->close();
free(capture); free(capture);
return 0; return 0;
} }
void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture) void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture)
{ {
if( capture && *capture ) if( capture && *capture )
{ {
(*capture)->close(); (*capture)->close();
free(*capture); free(*capture);
*capture = 0; *capture = 0;
} }
} }
int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value) int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value)
{ {
return capture->setProperty(prop_id, value); return capture->setProperty(prop_id, value);
} }
double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id) double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id)
{ {
return capture->getProperty(prop_id); return capture->getProperty(prop_id);
} }
int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture) int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture)
{ {
return capture->grabFrame(); return capture->grabFrame();
} }
int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn) int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn)
{ {
return capture->retrieveFrame(0, data, step, width, height, cn); return capture->retrieveFrame(0, data, step, width, height, cn);
} }
CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps, CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps,
int width, int height, int isColor ) int width, int height, int isColor )
{ {
CvVideoWriter_FFMPEG* writer = (CvVideoWriter_FFMPEG*)malloc(sizeof(*writer)); CvVideoWriter_FFMPEG* writer = (CvVideoWriter_FFMPEG*)malloc(sizeof(*writer));
writer->init(); writer->init();
if( writer->open( filename, fourcc, fps, width, height, isColor != 0 )) if( writer->open( filename, fourcc, fps, width, height, isColor != 0 ))
...@@ -1419,24 +1419,24 @@ CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int four ...@@ -1419,24 +1419,24 @@ CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int four
writer->close(); writer->close();
free(writer); free(writer);
return 0; return 0;
} }
void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer ) void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer )
{ {
if( writer && *writer ) if( writer && *writer )
{ {
(*writer)->close(); (*writer)->close();
free(*writer); free(*writer);
*writer = 0; *writer = 0;
} }
} }
int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer, int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer,
const unsigned char* data, int step, const unsigned char* data, int step,
int width, int height, int cn, int origin) int width, int height, int cn, int origin)
{ {
return writer->writeFrame(data, step, width, height, cn, origin); return writer->writeFrame(data, step, width, height, cn, origin);
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment