@@ -152,145 +152,61 @@ bool AudioLocation::is_near(AudioLocation location, int samples_per_frame, int64
152152
153153#if IS_FFMPEG_3_2
154154
155- #if defined(__linux__)
156- static enum AVPixelFormat get_hw_dec_format_va (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
157- {
158- const enum AVPixelFormat *p;
159-
160- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
161- switch (*p) {
162- case AV_PIX_FMT_VAAPI:
163- hw_de_av_pix_fmt_global = AV_PIX_FMT_VAAPI;
164- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VAAPI;
165- return *p;
166- break ;
167- }
168- }
169- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_va (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
170- return AV_PIX_FMT_NONE;
171- }
172-
173- static enum AVPixelFormat get_hw_dec_format_cu (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
155+ // Get hardware pix format
156+ static enum AVPixelFormat get_hw_dec_format (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
174157{
175- const enum AVPixelFormat *p;
176-
177- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
178- switch (*p) {
179- case AV_PIX_FMT_CUDA:
180- hw_de_av_pix_fmt_global = AV_PIX_FMT_CUDA;
181- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_CUDA;
182- return *p;
183- break ;
184- }
185- }
186- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_cu (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
187- return AV_PIX_FMT_NONE;
188- }
189-
190- static enum AVPixelFormat get_hw_dec_format_vd (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
191- {
192- const enum AVPixelFormat *p;
158+ const enum AVPixelFormat *p;
193159
194- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
195- switch (*p) {
196- case AV_PIX_FMT_VDPAU:
197- hw_de_av_pix_fmt_global = AV_PIX_FMT_VDPAU;
198- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VDPAU;
199- return *p;
200- break ;
201- }
202- }
203- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_vd (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
204- return AV_PIX_FMT_NONE;
205- }
160+ for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
161+ switch (*p) {
162+ #if defined(__linux__)
163+ // Linux pix formats
164+ case AV_PIX_FMT_VAAPI:
165+ hw_de_av_pix_fmt_global = AV_PIX_FMT_VAAPI;
166+ hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VAAPI;
167+ return *p;
168+ break ;
169+ case AV_PIX_FMT_VDPAU:
170+ hw_de_av_pix_fmt_global = AV_PIX_FMT_VDPAU;
171+ hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VDPAU;
172+ return *p;
173+ break ;
206174#endif
207-
208175#if defined(_WIN32)
209- static enum AVPixelFormat get_hw_dec_format_dx (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
210- {
211- const enum AVPixelFormat *p;
212-
213- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
214- switch (*p) {
215- case AV_PIX_FMT_DXVA2_VLD:
216- hw_de_av_pix_fmt_global = AV_PIX_FMT_DXVA2_VLD;
217- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_DXVA2;
218- return *p;
219- break ;
220- }
221- }
222- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_dx (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
223- return AV_PIX_FMT_NONE;
224- }
225-
226- static enum AVPixelFormat get_hw_dec_format_d3 (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
227- {
228- const enum AVPixelFormat *p;
229-
230- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
231- switch (*p) {
232- case AV_PIX_FMT_D3D11:
233- hw_de_av_pix_fmt_global = AV_PIX_FMT_D3D11;
234- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_D3D11VA;
235- return *p;
236- break ;
237- }
238- }
239- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_d3 (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
240- return AV_PIX_FMT_NONE;
241- }
242-
243- static enum AVPixelFormat get_hw_dec_format_cu (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
244- {
245- const enum AVPixelFormat *p;
246-
247- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
248- switch (*p) {
249- case AV_PIX_FMT_CUDA:
250- hw_de_av_pix_fmt_global = AV_PIX_FMT_CUDA;
251- hw_de_av_device_type_global = AV_HWDEVICE_TYPE_CUDA;
252- return *p;
253- break ;
254- }
255- }
256- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_cu (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
257- return AV_PIX_FMT_NONE;
258- }
176+ // Windows pix formats
177+ case AV_PIX_FMT_DXVA2_VLD:
178+ hw_de_av_pix_fmt_global = AV_PIX_FMT_DXVA2_VLD;
179+ hw_de_av_device_type_global = AV_HWDEVICE_TYPE_DXVA2;
180+ return *p;
181+ break ;
182+ case AV_PIX_FMT_D3D11:
183+ hw_de_av_pix_fmt_global = AV_PIX_FMT_D3D11;
184+ hw_de_av_device_type_global = AV_HWDEVICE_TYPE_D3D11VA;
185+ return *p;
186+ break ;
259187#endif
260-
261188#if defined(__APPLE__)
262- static enum AVPixelFormat get_hw_dec_format_vt (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
263- {
264- const enum AVPixelFormat *p;
265-
266- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
267- switch (*p) {
268- case AV_PIX_FMT_VIDEOTOOLBOX:
189+ // Apple pix formats
190+ case AV_PIX_FMT_VIDEOTOOLBOX:
269191 hw_de_av_pix_fmt_global = AV_PIX_FMT_VIDEOTOOLBOX;
270192 hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
271193 return *p;
272194 break ;
273- }
274- }
275- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_vt (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
276- return AV_PIX_FMT_NONE;
277- }
278195#endif
279-
280- static enum AVPixelFormat get_hw_dec_format_qs (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
281- {
282- const enum AVPixelFormat *p;
283-
284- for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
285- switch (*p) {
196+ // Cross-platform pix formats
197+ case AV_PIX_FMT_CUDA:
198+ hw_de_av_pix_fmt_global = AV_PIX_FMT_CUDA;
199+ hw_de_av_device_type_global = AV_HWDEVICE_TYPE_CUDA;
200+ return *p;
201+ break ;
286202 case AV_PIX_FMT_QSV:
287203 hw_de_av_pix_fmt_global = AV_PIX_FMT_QSV;
288204 hw_de_av_device_type_global = AV_HWDEVICE_TYPE_QSV;
289205 return *p;
290206 break ;
291207 }
292208 }
293- ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format_qs (Unable to decode this file using hardware decode. )" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
209+ ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::get_hw_dec_format (Unable to decode this file using hardware decode)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
294210 return AV_PIX_FMT_NONE;
295211}
296212
@@ -304,15 +220,14 @@ int FFmpegReader::IsHardwareDecodeSupported(int codecid)
304220 case AV_CODEC_ID_WMV1:
305221 case AV_CODEC_ID_WMV2:
306222 case AV_CODEC_ID_WMV3:
307- ret = 1 ;
308- break ;
309- default :
310- ret = 0 ;
311- break ;
223+ ret = 1 ;
224+ break ;
225+ default :
226+ ret = 0 ;
227+ break ;
312228 }
313229 return ret;
314230}
315-
316231#endif
317232
318233void FFmpegReader::Open () {
@@ -393,76 +308,66 @@ void FFmpegReader::Open() {
393308 adapter_num = openshot::Settings::Instance ()->HW_DE_DEVICE_SET ;
394309 fprintf (stderr, " \n\n Decodiing Device Nr: %d\n " , adapter_num);
395310
311+ // Set hardware pix format (callback)
312+ pCodecCtx->get_format = get_hw_dec_format;
313+
396314 if (adapter_num < 3 && adapter_num >=0 ) {
397315#if defined(__linux__)
398- snprintf (adapter,sizeof (adapter)," /dev/dri/renderD%d" , adapter_num+128 );
399- adapter_ptr = adapter;
400- i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
401- switch (i_decoder_hw) {
402- case 1 :
403- hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI;
404- pCodecCtx->get_format = get_hw_dec_format_va;
405- break ;
406- case 2 :
407- hw_de_av_device_type = AV_HWDEVICE_TYPE_CUDA;
408- pCodecCtx->get_format = get_hw_dec_format_cu;
409- break ;
410- case 6 :
411- hw_de_av_device_type = AV_HWDEVICE_TYPE_VDPAU;
412- pCodecCtx->get_format = get_hw_dec_format_vd;
413- break ;
414- case 7 :
415- hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
416- pCodecCtx->get_format = get_hw_dec_format_qs;
417- break ;
418- default :
419- hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI;
420- pCodecCtx->get_format = get_hw_dec_format_va;
421- break ;
422- }
423-
424- #elif defined(_WIN32)
425- adapter_ptr = NULL ;
426- i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
427- switch (i_decoder_hw) {
316+ snprintf (adapter,sizeof (adapter)," /dev/dri/renderD%d" , adapter_num+128 );
317+ adapter_ptr = adapter;
318+ i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
319+ switch (i_decoder_hw) {
320+ case 1 :
321+ hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI;
322+ break ;
428323 case 2 :
429324 hw_de_av_device_type = AV_HWDEVICE_TYPE_CUDA;
430- pCodecCtx->get_format = get_hw_dec_format_cu;
431- break ;
432- case 3 :
433- hw_de_av_device_type = AV_HWDEVICE_TYPE_DXVA2;
434- pCodecCtx->get_format = get_hw_dec_format_dx;
435325 break ;
436- case 4 :
437- hw_de_av_device_type = AV_HWDEVICE_TYPE_D3D11VA;
438- pCodecCtx->get_format = get_hw_dec_format_d3;
326+ case 6 :
327+ hw_de_av_device_type = AV_HWDEVICE_TYPE_VDPAU;
439328 break ;
440329 case 7 :
441330 hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
442- pCodecCtx->get_format = get_hw_dec_format_qs;
443331 break ;
444332 default :
445- hw_de_av_device_type = AV_HWDEVICE_TYPE_DXVA2;
446- pCodecCtx->get_format = get_hw_dec_format_dx;
333+ hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI;
447334 break ;
448335 }
336+
337+ #elif defined(_WIN32)
338+ adapter_ptr = NULL ;
339+ i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
340+ switch (i_decoder_hw) {
341+ case 2 :
342+ hw_de_av_device_type = AV_HWDEVICE_TYPE_CUDA;
343+ break ;
344+ case 3 :
345+ hw_de_av_device_type = AV_HWDEVICE_TYPE_DXVA2;
346+ break ;
347+ case 4 :
348+ hw_de_av_device_type = AV_HWDEVICE_TYPE_D3D11VA;
349+ break ;
350+ case 7 :
351+ hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
352+ break ;
353+ default :
354+ hw_de_av_device_type = AV_HWDEVICE_TYPE_DXVA2;
355+ break ;
356+ }
449357#elif defined(__APPLE__)
450- adapter_ptr = NULL ;
451- i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
452- switch (i_decoder_hw) {
453- case 5 :
454- hw_de_av_device_type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
455- pCodecCtx->get_format = get_hw_dec_format_vt;
456- break ;
457- case 7 :
458- hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
459- pCodecCtx->get_format = get_hw_dec_format_qs;
460- break ;
461- default :
462- hw_de_av_device_type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
463- pCodecCtx->get_format = get_hw_dec_format_vt;
464- break ;
465- }
358+ adapter_ptr = NULL ;
359+ i_decoder_hw = openshot::Settings::Instance ()->HARDWARE_DECODER ;
360+ switch (i_decoder_hw) {
361+ case 5 :
362+ hw_de_av_device_type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
363+ break ;
364+ case 7 :
365+ hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
366+ break ;
367+ default :
368+ hw_de_av_device_type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
369+ break ;
370+ }
466371#endif
467372
468373 } else {
0 commit comments