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  default:
148  break;
149  }
150 
151  return QString("Unknown(%1)").arg(codecid);
152 }
153 
154 int myth2av_codecid(MythCodecID codec_id, bool &vdpau)
155 {
156  vdpau = false;
157  AVCodecID ret = AV_CODEC_ID_NONE;
158  switch (codec_id)
159  {
160  case kCodec_NONE:
161  case kCodec_NUV_MPEG4:
162  case kCodec_NUV_RTjpeg:
163  ret = AV_CODEC_ID_NONE;
164  break;
165 
166  case kCodec_MPEG1:
167  ret = AV_CODEC_ID_MPEG1VIDEO;
168  break;
169  case kCodec_MPEG2:
170  ret = AV_CODEC_ID_MPEG2VIDEO;
171  break;
172  case kCodec_H263:
173  ret = AV_CODEC_ID_H263;
174  break;
175  case kCodec_MPEG4:
176  ret = AV_CODEC_ID_MPEG4;
177  break;
178  case kCodec_H264:
179  ret = AV_CODEC_ID_H264;
180  break;
181  case kCodec_VP8:
182  ret = AV_CODEC_ID_VP8;
183  break;
184  case kCodec_VP9:
185  ret = AV_CODEC_ID_VP9;
186  break;
187  case kCodec_HEVC:
188  ret = AV_CODEC_ID_HEVC;
189  break;
190 
191  case kCodec_VC1:
192  ret = AV_CODEC_ID_VC1;
193  break;
194  case kCodec_WMV3:
195  ret = AV_CODEC_ID_WMV3;
196  break;
197 
198  case kCodec_MPEG1_VDPAU:
199  ret = AV_CODEC_ID_MPEG1VIDEO;
200  vdpau = true;
201  break;
202  case kCodec_MPEG2_VDPAU:
203  ret = AV_CODEC_ID_MPEG2VIDEO;
204  vdpau = true;
205  break;
206  case kCodec_H263_VDPAU:
207  LOG(VB_GENERAL, LOG_ERR,
208  "Error: VDPAU H.263 not supported by ffmpeg");
209  break;
210  case kCodec_MPEG4_VDPAU:
211  ret = AV_CODEC_ID_MPEG4;
212  break;
213 
214  case kCodec_H264_VDPAU:
215  ret = AV_CODEC_ID_H264;
216  vdpau = true;
217  break;
218  case kCodec_VC1_VDPAU:
219  ret = AV_CODEC_ID_VC1;
220  vdpau = true;
221  break;
222  case kCodec_WMV3_VDPAU:
223  ret = AV_CODEC_ID_WMV3;
224  vdpau = true;
225  break;
226  case kCodec_VP8_VDPAU:
227  ret = AV_CODEC_ID_VP8;
228  break;
229  case kCodec_VP9_VDPAU:
230  ret = AV_CODEC_ID_VP9;
231  break;
232  case kCodec_HEVC_VDPAU:
233  ret = AV_CODEC_ID_HEVC;
234  break;
235 
236  case kCodec_MPEG1_VAAPI:
237  ret = AV_CODEC_ID_MPEG1VIDEO;
238  break;
239  case kCodec_MPEG2_VAAPI:
240  ret = AV_CODEC_ID_MPEG2VIDEO;
241  break;
242  case kCodec_H263_VAAPI:
243  ret = AV_CODEC_ID_H263;
244  break;
245  case kCodec_MPEG4_VAAPI:
246  ret = AV_CODEC_ID_MPEG4;
247  break;
248  case kCodec_H264_VAAPI:
249  ret = AV_CODEC_ID_H264;
250  break;
251  case kCodec_VC1_VAAPI:
252  ret = AV_CODEC_ID_VC1;
253  break;
254  case kCodec_WMV3_VAAPI:
255  ret = AV_CODEC_ID_WMV3;
256  break;
257  case kCodec_VP8_VAAPI:
258  ret = AV_CODEC_ID_VP8;
259  break;
260  case kCodec_VP9_VAAPI:
261  ret = AV_CODEC_ID_VP9;
262  break;
263  case kCodec_HEVC_VAAPI:
264  ret = AV_CODEC_ID_HEVC;
265  break;
266 
267  case kCodec_MPEG1_DXVA2:
268  ret = AV_CODEC_ID_MPEG1VIDEO;
269  break;
270  case kCodec_MPEG2_DXVA2:
271  ret = AV_CODEC_ID_MPEG2VIDEO;
272  break;
273  case kCodec_H263_DXVA2:
274  ret = AV_CODEC_ID_H263;
275  break;
276  case kCodec_MPEG4_DXVA2:
277  ret = AV_CODEC_ID_MPEG4;
278  break;
279  case kCodec_H264_DXVA2:
280  ret = AV_CODEC_ID_H264;
281  break;
282  case kCodec_VC1_DXVA2:
283  ret = AV_CODEC_ID_VC1;
284  break;
285  case kCodec_WMV3_DXVA2:
286  ret = AV_CODEC_ID_WMV3;
287  break;
288  case kCodec_VP8_DXVA2:
289  ret = AV_CODEC_ID_VP8;
290  break;
291  case kCodec_VP9_DXVA2:
292  ret = AV_CODEC_ID_VP9;
293  break;
294  case kCodec_HEVC_DXVA2:
295  ret = AV_CODEC_ID_HEVC;
296  break;
297 
299  ret = AV_CODEC_ID_MPEG1VIDEO;
300  break;
302  ret = AV_CODEC_ID_MPEG2VIDEO;
303  break;
305  ret = AV_CODEC_ID_H263;
306  break;
308  ret = AV_CODEC_ID_MPEG4;
309  break;
311  ret = AV_CODEC_ID_H264;
312  break;
314  ret = AV_CODEC_ID_VC1;
315  break;
317  ret = AV_CODEC_ID_WMV3;
318  break;
320  ret = AV_CODEC_ID_VP8;
321  break;
323  ret = AV_CODEC_ID_VP9;
324  break;
326  ret = AV_CODEC_ID_HEVC;
327  break;
328 
329  case kCodec_MPEG1_VAAPI2:
330  ret = AV_CODEC_ID_MPEG1VIDEO;
331  break;
332  case kCodec_MPEG2_VAAPI2:
333  ret = AV_CODEC_ID_MPEG2VIDEO;
334  break;
335  case kCodec_H263_VAAPI2:
336  ret = AV_CODEC_ID_H263;
337  break;
338  case kCodec_MPEG4_VAAPI2:
339  ret = AV_CODEC_ID_MPEG4;
340  break;
341  case kCodec_H264_VAAPI2:
342  ret = AV_CODEC_ID_H264;
343  break;
344  case kCodec_VC1_VAAPI2:
345  ret = AV_CODEC_ID_VC1;
346  break;
347  case kCodec_WMV3_VAAPI2:
348  ret = AV_CODEC_ID_WMV3;
349  break;
350  case kCodec_VP8_VAAPI2:
351  ret = AV_CODEC_ID_VP8;
352  break;
353  case kCodec_VP9_VAAPI2:
354  ret = AV_CODEC_ID_VP9;
355  break;
356  case kCodec_HEVC_VAAPI2:
357  ret = AV_CODEC_ID_HEVC;
358  break;
359 
360  default:
361  LOG(VB_GENERAL, LOG_ERR,
362  QString("Error: MythCodecID %1 has not been "
363  "added to myth2av_codecid").arg(codec_id));
364  break;
365  } // switch(codec_id)
366  return ret;
367 }
368 
369 int mpeg_version(int codec_id)
370 {
371  switch (codec_id)
372  {
373  case AV_CODEC_ID_MPEG1VIDEO:
374  return 1;
375  case AV_CODEC_ID_MPEG2VIDEO:
376  return 2;
377  case AV_CODEC_ID_H263:
378  return 3;
379  case AV_CODEC_ID_MPEG4:
380  return 4;
381  case AV_CODEC_ID_H264:
382  return 5;
383  case AV_CODEC_ID_VC1:
384  return 6;
385  case AV_CODEC_ID_WMV3:
386  return 7;
387  case AV_CODEC_ID_VP8:
388  return 8;
389  case AV_CODEC_ID_VP9:
390  return 9;
391  case AV_CODEC_ID_HEVC:
392  return 10;
393  default:
394  break;
395  }
396  return 0;
397 }
398 
400 {
401  switch (codecid)
402  {
403  case kCodec_NUV_RTjpeg:
404  return "RTjpeg";
405 
406  case kCodec_MPEG1:
407  case kCodec_MPEG1_VDPAU:
408  case kCodec_MPEG1_VAAPI:
409  case kCodec_MPEG1_DXVA2:
411  case kCodec_MPEG1_VAAPI2:
412  case kCodec_MPEG2:
413  case kCodec_MPEG2_VDPAU:
414  case kCodec_MPEG2_VAAPI:
415  case kCodec_MPEG2_DXVA2:
417  case kCodec_MPEG2_VAAPI2:
418  return "MPEG-2";
419 
420  case kCodec_H263:
421  case kCodec_H263_VDPAU:
422  case kCodec_H263_VAAPI:
423  case kCodec_H263_DXVA2:
425  case kCodec_H263_VAAPI2:
426  return "H.263";
427 
428  case kCodec_NUV_MPEG4:
429  case kCodec_MPEG4:
430  case kCodec_MPEG4_VDPAU:
431  case kCodec_MPEG4_VAAPI:
432  case kCodec_MPEG4_DXVA2:
434  case kCodec_MPEG4_VAAPI2:
435  return "MPEG-4";
436 
437  case kCodec_H264:
438  case kCodec_H264_VDPAU:
439  case kCodec_H264_VAAPI:
440  case kCodec_H264_DXVA2:
442  case kCodec_H264_VAAPI2:
443  return "H.264";
444 
445  case kCodec_VC1:
446  case kCodec_VC1_VDPAU:
447  case kCodec_VC1_VAAPI:
448  case kCodec_VC1_DXVA2:
450  case kCodec_VC1_VAAPI2:
451  return "VC-1";
452 
453  case kCodec_WMV3:
454  case kCodec_WMV3_VDPAU:
455  case kCodec_WMV3_VAAPI:
456  case kCodec_WMV3_DXVA2:
458  case kCodec_WMV3_VAAPI2:
459  return "WMV3";
460 
461  case kCodec_VP8:
462  case kCodec_VP8_VDPAU:
463  case kCodec_VP8_VAAPI:
464  case kCodec_VP8_DXVA2:
466  case kCodec_VP8_VAAPI2:
467  return "VP8";
468 
469  case kCodec_VP9:
470  case kCodec_VP9_VDPAU:
471  case kCodec_VP9_VAAPI:
472  case kCodec_VP9_DXVA2:
474  case kCodec_VP9_VAAPI2:
475  return "VP8";
476 
477  case kCodec_HEVC:
478  case kCodec_HEVC_VDPAU:
479  case kCodec_HEVC_VAAPI:
480  case kCodec_HEVC_DXVA2:
482  case kCodec_HEVC_VAAPI2:
483  return "HEVC";
484 
485  case kCodec_NONE:
486  case kCodec_NORMAL_END:
487  case kCodec_VDPAU_END:
488  case kCodec_VAAPI_END:
489  case kCodec_DXVA2_END:
491  case kCodec_VAAPI2_END:
492  return QString();
493  }
494 
495  return QString();
496 }
497 
498 QString get_decoder_name(MythCodecID codec_id)
499 {
500  if (codec_is_vdpau(codec_id))
501  return "vdpau";
502 
503  if (codec_is_vaapi(codec_id))
504  return "vaapi";
505 
506  if (codec_is_dxva2(codec_id))
507  return "dxva2";
508 
509  if (codec_is_mediacodec(codec_id))
510  return "mediacodec";
511 
512  if (codec_is_vaapi2(codec_id))
513  return "vaapi2";
514 
515  return "ffmpeg";
516 }
QString get_decoder_name(MythCodecID codec_id)
MythCodecID
Definition: mythcodecid.h:10
#define codec_is_vdpau(id)
Definition: mythcodecid.h:114
#define codec_is_vaapi(id)
Definition: mythcodecid.h:119
int mpeg_version(int codec_id)
#define codec_is_dxva2(id)
Definition: mythcodecid.h:123
#define codec_is_mediacodec(id)
Definition: mythcodecid.h:129
int myth2av_codecid(MythCodecID codec_id, bool &vdpau)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
#define codec_is_vaapi2(id)
Definition: mythcodecid.h:131
QString get_encoding_type(MythCodecID codecid)
QString toString(MythCodecID codecid)
Definition: mythcodecid.cpp:9