MythTV  master
mythcodecid.cpp
Go to the documentation of this file.
1 #include "mythcodecid.h"
2 #include "mythlogging.h"
3 
4 extern "C"
5 {
6 #include "libavcodec/avcodec.h"
7 }
8 
9 QString toString(MythCodecID codecid)
10 {
11  switch (codecid)
12  {
13  case kCodec_NONE:
14  return "None";
15 
16  case kCodec_NUV_RTjpeg:
17  return "NUV RTjpeg";
18  case kCodec_NUV_MPEG4:
19  return "NUV MPEG4";
20 
21  case kCodec_MPEG1:
22  return "MPEG1";
23  case kCodec_MPEG2:
24  return "MPEG2";
25  case kCodec_H263:
26  return "H.263";
27  case kCodec_MPEG4:
28  return "MPEG4";
29  case kCodec_H264:
30  return "H.264";
31  case kCodec_VC1:
32  return "VC-1";
33  case kCodec_WMV3:
34  return "WMV3";
35  case kCodec_VP8:
36  return "VP8";
37  case kCodec_VP9:
38  return "VP9";
39  case kCodec_HEVC:
40  return "HEVC";
41 
42  case kCodec_MPEG1_VDPAU:
43  return "MPEG1 VDPAU";
44  case kCodec_MPEG2_VDPAU:
45  return "MPEG2 VDPAU";
46  case kCodec_H263_VDPAU:
47  return "H.263 VDPAU";
48  case kCodec_MPEG4_VDPAU:
49  return "MPEG4 VDPAU";
50  case kCodec_H264_VDPAU:
51  return "H.264 VDPAU";
52  case kCodec_VC1_VDPAU:
53  return "VC1 VDPAU";
54  case kCodec_WMV3_VDPAU:
55  return "WMV3 VDPAU";
56  case kCodec_VP8_VDPAU:
57  return "VP8 VDPAU";
58  case kCodec_VP9_VDPAU:
59  return "VP9 VDPAU";
60  case kCodec_HEVC_VDPAU:
61  return "HEVC VDPAU";
62 
63  case kCodec_MPEG1_VAAPI:
64  return "MPEG1 VAAPI";
65  case kCodec_MPEG2_VAAPI:
66  return "MPEG2 VAAPI";
67  case kCodec_H263_VAAPI:
68  return "H.263 VAAPI";
69  case kCodec_MPEG4_VAAPI:
70  return "MPEG4 VAAPI";
71  case kCodec_H264_VAAPI:
72  return "H.264 VAAPI";
73  case kCodec_VC1_VAAPI:
74  return "VC1 VAAPI";
75  case kCodec_WMV3_VAAPI:
76  return "WMV3 VAAPI";
77  case kCodec_VP8_VAAPI:
78  return "VP8 VAAPI";
79  case kCodec_VP9_VAAPI:
80  return "VP9 VAAPI";
81  case kCodec_HEVC_VAAPI:
82  return "HEVC VAAPI";
83 
84  case kCodec_MPEG1_DXVA2:
85  return "MPEG1 DXVA2";
86  case kCodec_MPEG2_DXVA2:
87  return "MPEG2 DXVA2";
88  case kCodec_H263_DXVA2:
89  return "H.263 DXVA2";
90  case kCodec_MPEG4_DXVA2:
91  return "MPEG4 DXVA2";
92  case kCodec_H264_DXVA2:
93  return "H.264 DXVA2";
94  case kCodec_VC1_DXVA2:
95  return "VC1 DXVA2";
96  case kCodec_WMV3_DXVA2:
97  return "WMV3 DXVA2";
98  case kCodec_VP8_DXVA2:
99  return "VP8 DXVA2";
100  case kCodec_VP9_DXVA2:
101  return "VP9 DXVA2";
102  case kCodec_HEVC_DXVA2:
103  return "HEVC DXVA2";
104 
106  return "MPEG1 MEDIACODEC";
108  return "MPEG2 MEDIACODEC";
110  return "H.263 MEDIACODEC";
112  return "MPEG4 MEDIACODEC";
114  return "H.264 MEDIACODEC";
116  return "VC1 MEDIACODEC";
118  return "WMV3 MEDIACODEC";
120  return "VP8 MEDIACODEC";
122  return "VP9 MEDIACODEC";
124  return "HEVC MEDIACODEC";
125 
126  case kCodec_MPEG1_VAAPI2:
127  return "MPEG1 VAAPI2";
128  case kCodec_MPEG2_VAAPI2:
129  return "MPEG2 VAAPI2";
130  case kCodec_H263_VAAPI2:
131  return "H.263 VAAPI2";
132  case kCodec_MPEG4_VAAPI2:
133  return "MPEG4 VAAPI2";
134  case kCodec_H264_VAAPI2:
135  return "H.264 VAAPI2";
136  case kCodec_VC1_VAAPI2:
137  return "VC1 VAAPI2";
138  case kCodec_WMV3_VAAPI2:
139  return "WMV3 VAAPI2";
140  case kCodec_VP8_VAAPI2:
141  return "VP8 VAAPI2";
142  case kCodec_VP9_VAAPI2:
143  return "VP9 VAAPI2";
144  case kCodec_HEVC_VAAPI2:
145  return "HEVC VAAPI2";
146 
147  case kCodec_MPEG1_NVDEC:
148  return "MPEG1 NVDEC";
149  case kCodec_MPEG2_NVDEC:
150  return "MPEG2 NVDEC";
151  case kCodec_H263_NVDEC:
152  return "H.263 NVDEC";
153  case kCodec_MPEG4_NVDEC:
154  return "MPEG4 NVDEC";
155  case kCodec_H264_NVDEC:
156  return "H.264 NVDEC";
157  case kCodec_VC1_NVDEC:
158  return "VC1 NVDEC";
159  case kCodec_WMV3_NVDEC:
160  return "WMV3 NVDEC";
161  case kCodec_VP8_NVDEC:
162  return "VP8 NVDEC";
163  case kCodec_VP9_NVDEC:
164  return "VP9 NVDEC";
165  case kCodec_HEVC_NVDEC:
166  return "HEVC NVDEC";
167 
168  default:
169  break;
170  }
171 
172  return QString("Unknown(%1)").arg(codecid);
173 }
174 
175 AVCodecID myth2av_codecid(MythCodecID codec_id, bool &vdpau)
176 {
177  vdpau = false;
178  AVCodecID ret = AV_CODEC_ID_NONE;
179  switch (codec_id)
180  {
181  case kCodec_NONE:
182  case kCodec_NUV_MPEG4:
183  case kCodec_NUV_RTjpeg:
184  ret = AV_CODEC_ID_NONE;
185  break;
186 
187  case kCodec_MPEG1:
188  ret = AV_CODEC_ID_MPEG1VIDEO;
189  break;
190  case kCodec_MPEG2:
191  ret = AV_CODEC_ID_MPEG2VIDEO;
192  break;
193  case kCodec_H263:
194  ret = AV_CODEC_ID_H263;
195  break;
196  case kCodec_MPEG4:
197  ret = AV_CODEC_ID_MPEG4;
198  break;
199  case kCodec_H264:
200  ret = AV_CODEC_ID_H264;
201  break;
202  case kCodec_VP8:
203  ret = AV_CODEC_ID_VP8;
204  break;
205  case kCodec_VP9:
206  ret = AV_CODEC_ID_VP9;
207  break;
208  case kCodec_HEVC:
209  ret = AV_CODEC_ID_HEVC;
210  break;
211 
212  case kCodec_VC1:
213  ret = AV_CODEC_ID_VC1;
214  break;
215  case kCodec_WMV3:
216  ret = AV_CODEC_ID_WMV3;
217  break;
218 
219  case kCodec_MPEG1_VDPAU:
220  ret = AV_CODEC_ID_MPEG1VIDEO;
221  vdpau = true;
222  break;
223  case kCodec_MPEG2_VDPAU:
224  ret = AV_CODEC_ID_MPEG2VIDEO;
225  vdpau = true;
226  break;
227  case kCodec_H263_VDPAU:
228  LOG(VB_GENERAL, LOG_ERR,
229  "Error: VDPAU H.263 not supported by ffmpeg");
230  break;
231  case kCodec_MPEG4_VDPAU:
232  ret = AV_CODEC_ID_MPEG4;
233  break;
234 
235  case kCodec_H264_VDPAU:
236  ret = AV_CODEC_ID_H264;
237  vdpau = true;
238  break;
239  case kCodec_VC1_VDPAU:
240  ret = AV_CODEC_ID_VC1;
241  vdpau = true;
242  break;
243  case kCodec_WMV3_VDPAU:
244  ret = AV_CODEC_ID_WMV3;
245  vdpau = true;
246  break;
247  case kCodec_VP8_VDPAU:
248  ret = AV_CODEC_ID_VP8;
249  break;
250  case kCodec_VP9_VDPAU:
251  ret = AV_CODEC_ID_VP9;
252  break;
253  case kCodec_HEVC_VDPAU:
254  ret = AV_CODEC_ID_HEVC;
255  break;
256 
257  case kCodec_MPEG1_VAAPI:
258  ret = AV_CODEC_ID_MPEG1VIDEO;
259  break;
260  case kCodec_MPEG2_VAAPI:
261  ret = AV_CODEC_ID_MPEG2VIDEO;
262  break;
263  case kCodec_H263_VAAPI:
264  ret = AV_CODEC_ID_H263;
265  break;
266  case kCodec_MPEG4_VAAPI:
267  ret = AV_CODEC_ID_MPEG4;
268  break;
269  case kCodec_H264_VAAPI:
270  ret = AV_CODEC_ID_H264;
271  break;
272  case kCodec_VC1_VAAPI:
273  ret = AV_CODEC_ID_VC1;
274  break;
275  case kCodec_WMV3_VAAPI:
276  ret = AV_CODEC_ID_WMV3;
277  break;
278  case kCodec_VP8_VAAPI:
279  ret = AV_CODEC_ID_VP8;
280  break;
281  case kCodec_VP9_VAAPI:
282  ret = AV_CODEC_ID_VP9;
283  break;
284  case kCodec_HEVC_VAAPI:
285  ret = AV_CODEC_ID_HEVC;
286  break;
287 
288  case kCodec_MPEG1_DXVA2:
289  ret = AV_CODEC_ID_MPEG1VIDEO;
290  break;
291  case kCodec_MPEG2_DXVA2:
292  ret = AV_CODEC_ID_MPEG2VIDEO;
293  break;
294  case kCodec_H263_DXVA2:
295  ret = AV_CODEC_ID_H263;
296  break;
297  case kCodec_MPEG4_DXVA2:
298  ret = AV_CODEC_ID_MPEG4;
299  break;
300  case kCodec_H264_DXVA2:
301  ret = AV_CODEC_ID_H264;
302  break;
303  case kCodec_VC1_DXVA2:
304  ret = AV_CODEC_ID_VC1;
305  break;
306  case kCodec_WMV3_DXVA2:
307  ret = AV_CODEC_ID_WMV3;
308  break;
309  case kCodec_VP8_DXVA2:
310  ret = AV_CODEC_ID_VP8;
311  break;
312  case kCodec_VP9_DXVA2:
313  ret = AV_CODEC_ID_VP9;
314  break;
315  case kCodec_HEVC_DXVA2:
316  ret = AV_CODEC_ID_HEVC;
317  break;
318 
320  ret = AV_CODEC_ID_MPEG1VIDEO;
321  break;
323  ret = AV_CODEC_ID_MPEG2VIDEO;
324  break;
326  ret = AV_CODEC_ID_H263;
327  break;
329  ret = AV_CODEC_ID_MPEG4;
330  break;
332  ret = AV_CODEC_ID_H264;
333  break;
335  ret = AV_CODEC_ID_VC1;
336  break;
338  ret = AV_CODEC_ID_WMV3;
339  break;
341  ret = AV_CODEC_ID_VP8;
342  break;
344  ret = AV_CODEC_ID_VP9;
345  break;
347  ret = AV_CODEC_ID_HEVC;
348  break;
349 
350  case kCodec_MPEG1_VAAPI2:
351  ret = AV_CODEC_ID_MPEG1VIDEO;
352  break;
353  case kCodec_MPEG2_VAAPI2:
354  ret = AV_CODEC_ID_MPEG2VIDEO;
355  break;
356  case kCodec_H263_VAAPI2:
357  ret = AV_CODEC_ID_H263;
358  break;
359  case kCodec_MPEG4_VAAPI2:
360  ret = AV_CODEC_ID_MPEG4;
361  break;
362  case kCodec_H264_VAAPI2:
363  ret = AV_CODEC_ID_H264;
364  break;
365  case kCodec_VC1_VAAPI2:
366  ret = AV_CODEC_ID_VC1;
367  break;
368  case kCodec_WMV3_VAAPI2:
369  ret = AV_CODEC_ID_WMV3;
370  break;
371  case kCodec_VP8_VAAPI2:
372  ret = AV_CODEC_ID_VP8;
373  break;
374  case kCodec_VP9_VAAPI2:
375  ret = AV_CODEC_ID_VP9;
376  break;
377  case kCodec_HEVC_VAAPI2:
378  ret = AV_CODEC_ID_HEVC;
379  break;
380 
381  case kCodec_MPEG1_NVDEC:
382  ret = AV_CODEC_ID_MPEG1VIDEO;
383  break;
384  case kCodec_MPEG2_NVDEC:
385  ret = AV_CODEC_ID_MPEG2VIDEO;
386  break;
387  case kCodec_H263_NVDEC:
388  ret = AV_CODEC_ID_H263;
389  break;
390  case kCodec_MPEG4_NVDEC:
391  ret = AV_CODEC_ID_MPEG4;
392  break;
393  case kCodec_H264_NVDEC:
394  ret = AV_CODEC_ID_H264;
395  break;
396  case kCodec_VC1_NVDEC:
397  ret = AV_CODEC_ID_VC1;
398  break;
399  case kCodec_WMV3_NVDEC:
400  ret = AV_CODEC_ID_WMV3;
401  break;
402  case kCodec_VP8_NVDEC:
403  ret = AV_CODEC_ID_VP8;
404  break;
405  case kCodec_VP9_NVDEC:
406  ret = AV_CODEC_ID_VP9;
407  break;
408  case kCodec_HEVC_NVDEC:
409  ret = AV_CODEC_ID_HEVC;
410  break;
411 
412  default:
413  LOG(VB_GENERAL, LOG_ERR,
414  QString("Error: MythCodecID %1 has not been "
415  "added to myth2av_codecid").arg(codec_id));
416  break;
417  } // switch(codec_id)
418  return ret;
419 }
420 
421 int mpeg_version(int codec_id)
422 {
423  switch (codec_id)
424  {
425  case AV_CODEC_ID_MPEG1VIDEO:
426  return 1;
427  case AV_CODEC_ID_MPEG2VIDEO:
428  return 2;
429  case AV_CODEC_ID_H263:
430  return 3;
431  case AV_CODEC_ID_MPEG4:
432  return 4;
433  case AV_CODEC_ID_H264:
434  return 5;
435  case AV_CODEC_ID_VC1:
436  return 6;
437  case AV_CODEC_ID_WMV3:
438  return 7;
439  case AV_CODEC_ID_VP8:
440  return 8;
441  case AV_CODEC_ID_VP9:
442  return 9;
443  case AV_CODEC_ID_HEVC:
444  return 10;
445  default:
446  break;
447  }
448  return 0;
449 }
450 
452 {
453  switch (codecid)
454  {
455  case kCodec_NUV_RTjpeg:
456  return "RTjpeg";
457 
458  case kCodec_MPEG1:
459  case kCodec_MPEG1_VDPAU:
460  case kCodec_MPEG1_VAAPI:
461  case kCodec_MPEG1_DXVA2:
463  case kCodec_MPEG1_VAAPI2:
464  case kCodec_MPEG1_NVDEC:
465  case kCodec_MPEG2:
466  case kCodec_MPEG2_VDPAU:
467  case kCodec_MPEG2_VAAPI:
468  case kCodec_MPEG2_DXVA2:
470  case kCodec_MPEG2_VAAPI2:
471  case kCodec_MPEG2_NVDEC:
472  return "MPEG-2";
473 
474  case kCodec_H263:
475  case kCodec_H263_VDPAU:
476  case kCodec_H263_VAAPI:
477  case kCodec_H263_DXVA2:
479  case kCodec_H263_VAAPI2:
480  case kCodec_H263_NVDEC:
481  return "H.263";
482 
483  case kCodec_NUV_MPEG4:
484  case kCodec_MPEG4:
485  case kCodec_MPEG4_VDPAU:
486  case kCodec_MPEG4_VAAPI:
487  case kCodec_MPEG4_DXVA2:
489  case kCodec_MPEG4_VAAPI2:
490  case kCodec_MPEG4_NVDEC:
491  return "MPEG-4";
492 
493  case kCodec_H264:
494  case kCodec_H264_VDPAU:
495  case kCodec_H264_VAAPI:
496  case kCodec_H264_DXVA2:
498  case kCodec_H264_VAAPI2:
499  case kCodec_H264_NVDEC:
500  return "H.264";
501 
502  case kCodec_VC1:
503  case kCodec_VC1_VDPAU:
504  case kCodec_VC1_VAAPI:
505  case kCodec_VC1_DXVA2:
507  case kCodec_VC1_VAAPI2:
508  case kCodec_VC1_NVDEC:
509  return "VC-1";
510 
511  case kCodec_WMV3:
512  case kCodec_WMV3_VDPAU:
513  case kCodec_WMV3_VAAPI:
514  case kCodec_WMV3_DXVA2:
516  case kCodec_WMV3_VAAPI2:
517  case kCodec_WMV3_NVDEC:
518  return "WMV3";
519 
520  case kCodec_VP8:
521  case kCodec_VP8_VDPAU:
522  case kCodec_VP8_VAAPI:
523  case kCodec_VP8_DXVA2:
525  case kCodec_VP8_VAAPI2:
526  case kCodec_VP8_NVDEC:
527  return "VP8";
528 
529  case kCodec_VP9:
530  case kCodec_VP9_VDPAU:
531  case kCodec_VP9_VAAPI:
532  case kCodec_VP9_DXVA2:
534  case kCodec_VP9_VAAPI2:
535  case kCodec_VP9_NVDEC:
536  return "VP8";
537 
538  case kCodec_HEVC:
539  case kCodec_HEVC_VDPAU:
540  case kCodec_HEVC_VAAPI:
541  case kCodec_HEVC_DXVA2:
543  case kCodec_HEVC_VAAPI2:
544  case kCodec_HEVC_NVDEC:
545  return "HEVC";
546 
547  case kCodec_NONE:
548  case kCodec_NORMAL_END:
549  case kCodec_VDPAU_END:
550  case kCodec_VAAPI_END:
551  case kCodec_DXVA2_END:
553  case kCodec_VAAPI2_END:
554  case kCodec_NVDEC_END:
555  return QString();
556  }
557 
558  return QString();
559 }
560 
561 QString get_decoder_name(MythCodecID codec_id)
562 {
563  if (codec_is_vdpau(codec_id))
564  return "vdpau";
565 
566  if (codec_is_vaapi(codec_id))
567  return "vaapi";
568 
569  if (codec_is_dxva2(codec_id))
570  return "dxva2";
571 
572  if (codec_is_mediacodec(codec_id))
573  return "mediacodec";
574 
575  if (codec_is_vaapi2(codec_id))
576  return "vaapi2";
577 
578  if (codec_is_nvdec(codec_id))
579  return "nvdec";
580 
581  return "ffmpeg";
582 }
QString get_decoder_name(MythCodecID codec_id)
MythCodecID
Definition: mythcodecid.h:10
#define codec_is_vdpau(id)
Definition: mythcodecid.h:129
#define codec_is_vaapi(id)
Definition: mythcodecid.h:134
int mpeg_version(int codec_id)
#define codec_is_dxva2(id)
Definition: mythcodecid.h:138
#define codec_is_mediacodec(id)
Definition: mythcodecid.h:144
AVCodecID myth2av_codecid(MythCodecID codec_id, bool &vdpau)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
#define codec_is_vaapi2(id)
Definition: mythcodecid.h:146
#define codec_is_nvdec(id)
Definition: mythcodecid.h:148
QString get_encoding_type(MythCodecID codecid)
QString toString(MythCodecID codecid)
Definition: mythcodecid.cpp:9