3535
3636#define ENABLE_VAAPI 0
3737
38- #if IS_FFMPEG_3_2
38+ #if HAVE_HW_ACCEL
3939#pragma message "You are compiling with experimental hardware decode"
4040#else
4141#pragma message "You are compiling only with software decode"
4242#endif
4343
44- #if IS_FFMPEG_3_2
44+ #if HAVE_HW_ACCEL
4545#define MAX_SUPPORTED_WIDTH 1950
4646#define MAX_SUPPORTED_HEIGHT 1100
4747
@@ -71,14 +71,14 @@ typedef struct VAAPIDecodeContext {
7171 enum AVPixelFormat surface_format;
7272 int surface_count;
7373 } VAAPIDecodeContext;
74- #endif
75- #endif
74+ #endif // ENABLE_VAAPI
75+ #endif // HAVE_HW_ACCEL
7676
7777
7878using namespace openshot ;
7979
8080int hw_de_on = 0 ;
81- #if IS_FFMPEG_3_2
81+ #if HAVE_HW_ACCEL
8282 AVPixelFormat hw_de_av_pix_fmt_global = AV_PIX_FMT_NONE;
8383 AVHWDeviceType hw_de_av_device_type_global = AV_HWDEVICE_TYPE_NONE;
8484#endif
@@ -153,7 +153,7 @@ bool AudioLocation::is_near(AudioLocation location, int samples_per_frame, int64
153153 return false ;
154154}
155155
156- #if IS_FFMPEG_3_2
156+ #if HAVE_HW_ACCEL
157157
158158// Get hardware pix format
159159static enum AVPixelFormat get_hw_dec_format (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
@@ -234,7 +234,7 @@ int FFmpegReader::IsHardwareDecodeSupported(int codecid)
234234 }
235235 return ret;
236236}
237- #endif
237+ #endif // HAVE_HW_ACCEL
238238
239239void FFmpegReader::Open () {
240240 // Open reader if not already open
@@ -287,7 +287,7 @@ void FFmpegReader::Open() {
287287 // If hw accel is selected but hardware cannot handle repeat with software decoding
288288 do {
289289 pCodecCtx = AV_GET_CODEC_CONTEXT (pStream, pCodec);
290- #if IS_FFMPEG_3_2
290+ #if HAVE_HW_ACCEL
291291 if (hw_de_on && (retry_decode_open==2 )) {
292292 // Up to here no decision is made if hardware or software decode
293293 hw_de_supported = IsHardwareDecodeSupported (pCodecCtx->codec_id );
@@ -304,7 +304,7 @@ void FFmpegReader::Open() {
304304
305305 // Init options
306306 av_dict_set (&opts, " strict" , " experimental" , 0 );
307- #if IS_FFMPEG_3_2
307+ #if HAVE_HW_ACCEL
308308 if (hw_de_on && hw_de_supported) {
309309 // Open Hardware Acceleration
310310 int i_decoder_hw = 0 ;
@@ -433,13 +433,13 @@ void FFmpegReader::Open() {
433433 throw InvalidCodec (" Hardware device create failed." , path);
434434 }
435435 }
436- #endif
436+ #endif // HAVE_HW_ACCEL
437437
438438 // Open video codec
439439 if (avcodec_open2 (pCodecCtx, pCodec, &opts) < 0 )
440440 throw InvalidCodec (" A video codec was found, but could not be opened." , path);
441441
442- #if IS_FFMPEG_3_2
442+ #if HAVE_HW_ACCEL
443443 if (hw_de_on && hw_de_supported) {
444444 AVHWFramesConstraints *constraints = NULL ;
445445 void *hwconfig = NULL ;
@@ -449,7 +449,7 @@ void FFmpegReader::Open() {
449449#if ENABLE_VAAPI
450450 ((AVVAAPIHWConfig *)hwconfig)->config_id = ((VAAPIDecodeContext *)(pCodecCtx->priv_data ))->va_config ;
451451 constraints = av_hwdevice_get_hwframe_constraints (hw_device_ctx,hwconfig);
452- #endif
452+ #endif // ENABLE_VAAPI
453453 if (constraints) {
454454 if (pCodecCtx->coded_width < constraints->min_width ||
455455 pCodecCtx->coded_height < constraints->min_height ||
@@ -506,7 +506,7 @@ void FFmpegReader::Open() {
506506 }
507507#else
508508 retry_decode_open = 0 ;
509- #endif
509+ #endif // HAVE_HW_ACCEL
510510 } while (retry_decode_open); // retry_decode_open
511511 // Free options
512512 av_dict_free (&opts);
@@ -592,14 +592,14 @@ void FFmpegReader::Close() {
592592 if (info.has_video ) {
593593 avcodec_flush_buffers (pCodecCtx);
594594 AV_FREE_CONTEXT (pCodecCtx);
595- #if IS_FFMPEG_3_2
595+ #if HAVE_HW_ACCEL
596596 if (hw_de_on) {
597597 if (hw_device_ctx) {
598598 av_buffer_unref (&hw_device_ctx);
599599 hw_device_ctx = NULL ;
600600 }
601601 }
602- #endif
602+ #endif // HAVE_HW_ACCEL
603603 }
604604 if (info.has_audio ) {
605605 avcodec_flush_buffers (aCodecCtx);
@@ -1100,19 +1100,22 @@ bool FFmpegReader::GetAVFrame() {
11001100
11011101 ret = avcodec_send_packet (pCodecCtx, packet);
11021102
1103+ #if HAVE_HW_ACCEL
11031104 // Get the format from the variables set in get_hw_dec_format
11041105 hw_de_av_pix_fmt = hw_de_av_pix_fmt_global;
11051106 hw_de_av_device_type = hw_de_av_device_type_global;
1106-
1107+ # endif // HAVE_HW_ACCEL
11071108 if (ret < 0 || ret == AVERROR (EAGAIN) || ret == AVERROR_EOF) {
11081109 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::GetAVFrame (Packet not sent)" );
11091110 }
11101111 else {
11111112 AVFrame *next_frame2;
1113+ #if HAVE_HW_ACCEL
11121114 if (hw_de_on && hw_de_supported) {
11131115 next_frame2 = AV_ALLOCATE_FRAME ();
11141116 }
11151117 else
1118+ #endif // HAVE_HW_ACCEL
11161119 {
11171120 next_frame2 = next_frame;
11181121 }
@@ -1125,6 +1128,7 @@ bool FFmpegReader::GetAVFrame() {
11251128 if (ret != 0 ) {
11261129 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::GetAVFrame (invalid return frame received)" );
11271130 }
1131+ #if HAVE_HW_ACCEL
11281132 if (hw_de_on && hw_de_supported) {
11291133 int err;
11301134 if (next_frame2->format == hw_de_av_pix_fmt) {
@@ -1138,6 +1142,7 @@ bool FFmpegReader::GetAVFrame() {
11381142 }
11391143 }
11401144 else
1145+ #endif // HAVE_HW_ACCEL
11411146 { // No hardware acceleration used -> no copy from GPU memory needed
11421147 next_frame = next_frame2;
11431148 }
@@ -1151,9 +1156,11 @@ bool FFmpegReader::GetAVFrame() {
11511156 (AVPixelFormat)(pStream->codecpar ->format ), info.width , info.height );
11521157 }
11531158 }
1159+ #if HAVE_HW_ACCEL
11541160 if (hw_de_on && hw_de_supported) {
11551161 AV_FREE_FRAME (&next_frame2);
11561162 }
1163+ #endif // HAVE_HW_ACCEL
11571164 }
11581165#else
11591166 avcodec_decode_video2 (pCodecCtx, next_frame, &frameFinished, packet);
@@ -1169,7 +1176,7 @@ bool FFmpegReader::GetAVFrame() {
11691176 av_picture_copy ((AVPicture *) pFrame, (AVPicture *) next_frame, pCodecCtx->pix_fmt , info.width ,
11701177 info.height );
11711178 }
1172- #endif
1179+ #endif // IS_FFMPEG_3_2
11731180 }
11741181
11751182 // deallocate the frame
0 commit comments