1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
|
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* This file:
* Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#ifdef HAVE_FFMPEG_UNINSTALLED
#include <avcodec.h>
#else
#include <libavcodec/avcodec.h>
#endif
#include <string.h>
#include "gstffmpeg.h"
#include "gstffmpegcodecmap.h"
#include <gst/pbutils/codec-utils.h>
/*
* Read a palette from a caps.
*/
static void
gst_ffmpeg_get_palette (const GstCaps * caps, AVCodecContext * context)
{
GstStructure *str = gst_caps_get_structure (caps, 0);
const GValue *palette_v;
const GstBuffer *palette;
/* do we have a palette? */
if ((palette_v = gst_structure_get_value (str, "palette_data")) && context) {
palette = gst_value_get_buffer (palette_v);
if (GST_BUFFER_SIZE (palette) >= AVPALETTE_SIZE) {
if (context->palctrl)
av_free (context->palctrl);
context->palctrl = av_malloc (sizeof (AVPaletteControl));
context->palctrl->palette_changed = 1;
memcpy (context->palctrl->palette, GST_BUFFER_DATA (palette),
AVPALETTE_SIZE);
}
}
}
static void
gst_ffmpeg_set_palette (GstCaps * caps, AVCodecContext * context)
{
if (context->palctrl) {
GstBuffer *palette = gst_buffer_new_and_alloc (AVPALETTE_SIZE);
memcpy (GST_BUFFER_DATA (palette), context->palctrl->palette,
AVPALETTE_SIZE);
gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, palette, NULL);
}
}
/* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
static const struct
{
guint64 ff;
GstAudioChannelPosition gst;
} _ff_to_gst_layout[] = {
{
CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE}, {
CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
CH_FRONT_RIGHT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
};
static GstAudioChannelPosition *
gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
{
guint nchannels = 0, i, j;
GstAudioChannelPosition *pos = NULL;
gboolean none_layout = FALSE;
for (i = 0; i < 64; i++) {
if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
nchannels++;
}
}
if (channel_layout == 0) {
nchannels = channels;
none_layout = TRUE;
}
if (nchannels != channels) {
GST_ERROR ("Number of channels is different (%u != %u)", channels,
nchannels);
return NULL;
}
pos = g_new (GstAudioChannelPosition, nchannels);
for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
pos[j++] = _ff_to_gst_layout[i].gst;
if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
none_layout = TRUE;
}
}
if (j != nchannels) {
GST_WARNING ("Unknown channels in channel layout - assuming NONE layout");
none_layout = TRUE;
}
if (!none_layout && !gst_audio_check_channel_positions (pos, nchannels)) {
GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
" - assuming NONE layout", channel_layout);
none_layout = TRUE;
}
if (none_layout) {
if (nchannels == 1) {
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
} else if (nchannels == 2) {
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
} else if (channel_layout == 0) {
g_free (pos);
pos = NULL;
} else {
for (i = 0; i < nchannels; i++)
pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
}
}
if (nchannels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER) {
GST_DEBUG ("mono common case; won't set channel positions");
g_free (pos);
pos = NULL;
} else if (nchannels == 2 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
&& pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT) {
GST_DEBUG ("stereo common case; won't set channel positions");
g_free (pos);
pos = NULL;
}
return pos;
}
/* this macro makes a caps width fixed or unfixed width/height
* properties depending on whether we've got a context.
*
* See below for why we use this.
*
* We should actually do this stuff at the end, like in riff-media.c,
* but I'm too lazy today. Maybe later.
*/
static GstCaps *
gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
const char *mimetype, const char *fieldname, ...)
{
GstStructure *structure = NULL;
GstCaps *caps = NULL;
va_list var_args;
gint i;
GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
/* fixed, non probing context */
if (context != NULL && context->width != -1) {
gint num, denom;
caps = gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, context->width,
"height", G_TYPE_INT, context->height, NULL);
num = context->time_base.den / context->ticks_per_frame;
denom = context->time_base.num;
if (!denom) {
GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
denom = 1;
}
if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
num = 0;
denom = 1;
}
GST_LOG ("setting framerate: %d/%d", num, denom);
gst_caps_set_simple (caps,
"framerate", GST_TYPE_FRACTION, num, denom, NULL);
} else {
/* so we are after restricted caps in this case */
switch (codec_id) {
case CODEC_ID_H261:
{
caps = gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, 352,
"height", G_TYPE_INT, 288,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_append (caps, gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, 176,
"height", G_TYPE_INT, 144,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
break;
}
case CODEC_ID_H263:
{
/* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
* because we want automatic negotiation to go as close to 320x240 as
* possible. */
const static gint widths[] = { 352, 704, 176, 1408, 128 };
const static gint heights[] = { 288, 576, 144, 1152, 96 };
GstCaps *temp;
gint n_sizes = G_N_ELEMENTS (widths);
caps = gst_caps_new_empty ();
for (i = 0; i < n_sizes; i++) {
temp = gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, widths[i],
"height", G_TYPE_INT, heights[i],
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_append (caps, temp);
}
break;
}
case CODEC_ID_DVVIDEO:
{
static struct
{
guint32 csp;
gint width, height;
gint par_n, par_d;
gint framerate_n, framerate_d;
} profiles[] = {
{
GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
};
GstCaps *temp;
gint n_sizes = G_N_ELEMENTS (profiles);
caps = gst_caps_new_empty ();
for (i = 0; i < n_sizes; i++) {
temp = gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, profiles[i].width,
"height", G_TYPE_INT, profiles[i].height,
"framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
profiles[i].par_n, profiles[i].par_d, NULL);
gst_caps_append (caps, temp);
}
break;
}
case CODEC_ID_DNXHD:
{
caps = gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, 1920,
"height", G_TYPE_INT, 1080,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_append (caps, gst_caps_new_simple (mimetype,
"width", G_TYPE_INT, 1280,
"height", G_TYPE_INT, 720,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
break;
}
default:
break;
}
}
/* no fixed caps or special restrictions applied;
* default unfixed setting */
if (!caps) {
GST_DEBUG ("Creating default caps");
caps = gst_caps_new_simple (mimetype,
"width", GST_TYPE_INT_RANGE, 16, 4096,
"height", GST_TYPE_INT_RANGE, 16, 4096,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
}
for (i = 0; i < gst_caps_get_size (caps); i++) {
va_start (var_args, fieldname);
structure = gst_caps_get_structure (caps, i);
gst_structure_set_valist (structure, fieldname, var_args);
va_end (var_args);
}
return caps;
}
/* same for audio - now with channels/sample rate
*/
static GstCaps *
gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
const char *mimetype, const char *fieldname, ...)
{
GstCaps *caps = NULL;
GstStructure *structure = NULL;
gint i;
va_list var_args;
/* fixed, non-probing context */
if (context != NULL && context->channels != -1) {
GstAudioChannelPosition *pos;
guint64 channel_layout = context->channel_layout;
if (channel_layout == 0) {
const guint64 default_channel_set[] = {
0, 0, CH_LAYOUT_SURROUND, CH_LAYOUT_QUAD, CH_LAYOUT_5POINT0,
CH_LAYOUT_5POINT1, 0, CH_LAYOUT_7POINT1
};
switch (codec_id) {
case CODEC_ID_EAC3:
case CODEC_ID_AC3:
case CODEC_ID_DTS:
if (context->channels > 0
&& context->channels < G_N_ELEMENTS (default_channel_set))
channel_layout = default_channel_set[context->channels - 1];
break;
default:
break;
}
}
caps = gst_caps_new_simple (mimetype,
"rate", G_TYPE_INT, context->sample_rate,
"channels", G_TYPE_INT, context->channels, NULL);
pos = gst_ff_channel_layout_to_gst (channel_layout, context->channels);
if (pos != NULL) {
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
g_free (pos);
}
} else {
gint maxchannels = 2;
const gint *rates = NULL;
gint n_rates = 0;
/* so we must be after restricted caps in this case */
switch (codec_id) {
case CODEC_ID_AAC:
case CODEC_ID_AAC_LATM:
case CODEC_ID_DTS:
maxchannels = 6;
break;
case CODEC_ID_MP2:
{
const static gint l_rates[] =
{ 48000, 44100, 32000, 24000, 22050, 16000 };
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
case CODEC_ID_EAC3:
case CODEC_ID_AC3:
{
const static gint l_rates[] = { 48000, 44100, 32000 };
maxchannels = 6;
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
case CODEC_ID_ADPCM_G722:
{
const static gint l_rates[] = { 16000 };
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
maxchannels = 1;
break;
}
case CODEC_ID_ADPCM_G726:
{
const static gint l_rates[] = { 8000 };
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
maxchannels = 1;
break;
}
case CODEC_ID_ADPCM_SWF:
{
const static gint l_rates[] = { 11025, 22050, 44100 };
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
case CODEC_ID_ROQ_DPCM:
{
const static gint l_rates[] = { 22050 };
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
case CODEC_ID_AMR_NB:
{
const static gint l_rates[] = { 8000 };
maxchannels = 1;
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
case CODEC_ID_AMR_WB:
{
const static gint l_rates[] = { 16000 };
maxchannels = 1;
n_rates = G_N_ELEMENTS (l_rates);
rates = l_rates;
break;
}
default:
break;
}
/* TODO: handle context->channel_layouts here to set
* the list of channel layouts supported by the encoder.
* Unfortunately no encoder uses this yet....
*/
/* regardless of encode/decode, open up channels if applicable */
/* Until decoders/encoders expose the maximum number of channels
* they support, we whitelist them here. */
switch (codec_id) {
case CODEC_ID_WMAPRO:
case CODEC_ID_TRUEHD:
maxchannels = 8;
break;
default:
break;
}
if (maxchannels == 1)
caps = gst_caps_new_simple (mimetype,
"channels", G_TYPE_INT, maxchannels, NULL);
else
caps = gst_caps_new_simple (mimetype,
"channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
if (n_rates) {
GValue list = { 0, };
GstStructure *structure;
g_value_init (&list, GST_TYPE_LIST);
for (i = 0; i < n_rates; i++) {
GValue v = { 0, };
g_value_init (&v, G_TYPE_INT);
g_value_set_int (&v, rates[i]);
gst_value_list_append_value (&list, &v);
g_value_unset (&v);
}
structure = gst_caps_get_structure (caps, 0);
gst_structure_set_value (structure, "rate", &list);
g_value_unset (&list);
} else
gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
}
for (i = 0; i < gst_caps_get_size (caps); i++) {
va_start (var_args, fieldname);
structure = gst_caps_get_structure (caps, i);
gst_structure_set_valist (structure, fieldname, var_args);
va_end (var_args);
}
return caps;
}
/* Convert a FFMPEG codec ID and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* CodecID is primarily meant for compressed data GstCaps!
*
* encode is a special parameter. gstffmpegdec will say
* FALSE, gstffmpegenc will say TRUE. The output caps
* depends on this, in such a way that it will be very
* specific, defined, fixed and correct caps for encoders,
* yet very wide, "forgiving" caps for decoders. Example
* for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
* but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
* rate=x,channels=x.
*/
GstCaps *
gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
AVCodecContext * context, gboolean encode)
{
GstCaps *caps = NULL;
gboolean buildcaps = FALSE;
GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
switch (codec_id) {
case CODEC_ID_MPEG1VIDEO:
/* FIXME: bitrate */
caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
"mpegversion", G_TYPE_INT, 1,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
break;
case CODEC_ID_MPEG2VIDEO:
if (encode) {
/* FIXME: bitrate */
caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
"mpegversion", G_TYPE_INT, 2,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
} else {
/* decode both MPEG-1 and MPEG-2; width/height/fps are all in
* the MPEG video stream headers, so may be omitted from caps. */
caps = gst_caps_new_simple ("video/mpeg",
"mpegversion", GST_TYPE_INT_RANGE, 1, 2,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
}
break;
case CODEC_ID_MPEG2VIDEO_XVMC:
/* this is a special ID - don't need it in GStreamer, I think */
break;
case CODEC_ID_H263:
if (encode) {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
"variant", G_TYPE_STRING, "itu",
"h263version", G_TYPE_STRING, "h263", NULL);
} else {
/* don't pass codec_id, we can decode other variants with the H263
* decoder that don't have specific size requirements
*/
caps = gst_ff_vid_caps_new (context, CODEC_ID_NONE, "video/x-h263",
"variant", G_TYPE_STRING, "itu", NULL);
}
break;
case CODEC_ID_H263P:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
"variant", G_TYPE_STRING, "itu",
"h263version", G_TYPE_STRING, "h263p", NULL);
if (encode && context) {
gst_caps_set_simple (caps,
"annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
"annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
"annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
"annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
NULL);
}
break;
case CODEC_ID_H263I:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-intel-h263",
"variant", G_TYPE_STRING, "intel", NULL);
break;
case CODEC_ID_H261:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h261", NULL);
break;
case CODEC_ID_RV10:
case CODEC_ID_RV20:
case CODEC_ID_RV30:
case CODEC_ID_RV40:
{
gint version;
switch (codec_id) {
case CODEC_ID_RV40:
version = 4;
break;
case CODEC_ID_RV30:
version = 3;
break;
case CODEC_ID_RV20:
version = 2;
break;
default:
version = 1;
break;
}
/* FIXME: context->sub_id must be filled in during decoding */
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-pn-realvideo",
"systemstream", G_TYPE_BOOLEAN, FALSE,
"rmversion", G_TYPE_INT, version, NULL);
if (context) {
gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
if (context->extradata_size >= 8) {
gst_caps_set_simple (caps,
"subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
NULL);
}
}
}
break;
case CODEC_ID_MP1:
/* FIXME: bitrate */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
"mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_MP2:
/* FIXME: bitrate */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
"mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
break;
case CODEC_ID_MP3:
if (encode) {
/* FIXME: bitrate */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
"mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
} else {
/* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
* in the MPEG audio header, so may be omitted from caps. */
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 1,
"layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
}
break;
case CODEC_ID_MUSEPACK7:
caps =
gst_ff_aud_caps_new (context, codec_id,
"audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
NULL);
break;
case CODEC_ID_MUSEPACK8:
caps =
gst_ff_aud_caps_new (context, codec_id,
"audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
NULL);
break;
case CODEC_ID_AC3:
/* FIXME: bitrate */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-ac3", NULL);
break;
case CODEC_ID_EAC3:
/* FIXME: bitrate */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-eac3", NULL);
break;
case CODEC_ID_TRUEHD:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-true-hd", NULL);
break;
case CODEC_ID_ATRAC1:
caps =
gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac1",
NULL);
break;
case CODEC_ID_ATRAC3:
caps =
gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac3",
NULL);
break;
case CODEC_ID_DTS:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dts", NULL);
break;
case CODEC_ID_APE:
caps =
gst_ff_aud_caps_new (context, codec_id, "audio/x-ffmpeg-parsed-ape",
NULL);
if (context) {
gst_caps_set_simple (caps,
"depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
}
break;
case CODEC_ID_MLP:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mlp", NULL);
break;
case CODEC_ID_IMC:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-imc", NULL);
break;
/* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
* is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
* sp5x is, but it's apparently something JPEG... We don't separate
* between those in GStreamer. Should we (at least between MJPEG,
* MJPEG-B and sp5x decoding...)? */
case CODEC_ID_MJPEG:
case CODEC_ID_LJPEG:
caps = gst_ff_vid_caps_new (context, codec_id, "image/jpeg", NULL);
break;
case CODEC_ID_SP5X:
caps = gst_ff_vid_caps_new (context, codec_id, "video/sp5x", NULL);
break;
case CODEC_ID_MJPEGB:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mjpeg-b", NULL);
break;
case CODEC_ID_MPEG4:
if (encode && context != NULL) {
/* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
* the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
switch (context->codec_tag) {
case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-divx",
"divxversion", G_TYPE_INT, 5, NULL);
break;
case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
default:
/* FIXME: bitrate */
caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
"systemstream", G_TYPE_BOOLEAN, FALSE,
"mpegversion", G_TYPE_INT, 4, NULL);
break;
}
} else {
/* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
"mpegversion", G_TYPE_INT, 4,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
if (encode) {
gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
"video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
} else {
gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
"video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
NULL));
gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
"video/x-xvid", NULL));
gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
"video/x-3ivx", NULL));
}
}
break;
case CODEC_ID_RAWVIDEO:
caps =
gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
encode);
break;
case CODEC_ID_MSMPEG4V1:
case CODEC_ID_MSMPEG4V2:
case CODEC_ID_MSMPEG4V3:
{
gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
/* encode-FIXME: bitrate */
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msmpeg",
"msmpegversion", G_TYPE_INT, version, NULL);
if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
"video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
}
}
break;
case CODEC_ID_WMV1:
case CODEC_ID_WMV2:
{
gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
"wmvversion", G_TYPE_INT, version, NULL);
}
break;
case CODEC_ID_FLV1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-flash-video",
"flvversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_SVQ1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
"svqversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_SVQ3:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
"svqversion", G_TYPE_INT, 3, NULL);
break;
case CODEC_ID_DVAUDIO:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dv", NULL);
break;
case CODEC_ID_DVVIDEO:
{
if (encode && context) {
guint32 fourcc;
switch (context->pix_fmt) {
case PIX_FMT_YUYV422:
fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
break;
case PIX_FMT_YUV420P:
fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
break;
case PIX_FMT_YUVA420P:
fourcc = GST_MAKE_FOURCC ('A', '4', '2', '0');
break;
case PIX_FMT_YUV411P:
fourcc = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
break;
case PIX_FMT_YUV422P:
fourcc = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
break;
case PIX_FMT_YUV410P:
fourcc = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
break;
default:
GST_WARNING
("Couldnt' find fourcc for pixfmt %d, defaulting to I420",
context->pix_fmt);
fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
break;
}
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
"systemstream", G_TYPE_BOOLEAN, FALSE,
"format", GST_TYPE_FOURCC, fourcc, NULL);
} else {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
}
}
break;
case CODEC_ID_WMAV1:
case CODEC_ID_WMAV2:
{
gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
if (context) {
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
"wmaversion", G_TYPE_INT, version,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
} else {
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
"wmaversion", G_TYPE_INT, version,
"block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
"bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
}
}
break;
case CODEC_ID_WMAPRO:
{
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
"wmaversion", G_TYPE_INT, 3, NULL);
break;
}
case CODEC_ID_WMAVOICE:
{
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wms", NULL);
break;
}
case CODEC_ID_MACE3:
case CODEC_ID_MACE6:
{
gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mace",
"maceversion", G_TYPE_INT, version, NULL);
}
break;
case CODEC_ID_HUFFYUV:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-huffyuv", NULL);
if (context) {
gst_caps_set_simple (caps,
"bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
}
break;
case CODEC_ID_CYUV:
caps =
gst_ff_vid_caps_new (context, codec_id, "video/x-compressed-yuv",
NULL);
break;
case CODEC_ID_H264:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h264", NULL);
break;
case CODEC_ID_INDEO5:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
"indeoversion", G_TYPE_INT, 5, NULL);
break;
case CODEC_ID_INDEO3:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
"indeoversion", G_TYPE_INT, 3, NULL);
break;
case CODEC_ID_INDEO2:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
"indeoversion", G_TYPE_INT, 2, NULL);
break;
case CODEC_ID_FLASHSV:
caps =
gst_ff_vid_caps_new (context, codec_id, "video/x-flash-screen", NULL);
break;
case CODEC_ID_VP3:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp3", NULL);
break;
case CODEC_ID_VP5:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp5", NULL);
break;
case CODEC_ID_VP6:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6", NULL);
break;
case CODEC_ID_VP6F:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-flash", NULL);
break;
case CODEC_ID_VP6A:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-alpha", NULL);
break;
case CODEC_ID_VP8:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp8", NULL);
break;
case CODEC_ID_THEORA:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-theora", NULL);
break;
case CODEC_ID_AAC:
{
caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg", NULL);
if (!encode) {
GValue arr = { 0, };
GValue item = { 0, };
g_value_init (&arr, GST_TYPE_LIST);
g_value_init (&item, G_TYPE_INT);
g_value_set_int (&item, 2);
gst_value_list_append_value (&arr, &item);
g_value_set_int (&item, 4);
gst_value_list_append_value (&arr, &item);
g_value_unset (&item);
gst_caps_set_value (caps, "mpegversion", &arr);
g_value_unset (&arr);
g_value_init (&arr, GST_TYPE_LIST);
g_value_init (&item, G_TYPE_STRING);
g_value_set_string (&item, "raw");
gst_value_list_append_value (&arr, &item);
g_value_set_string (&item, "adts");
gst_value_list_append_value (&arr, &item);
g_value_set_string (&item, "adif");
gst_value_list_append_value (&arr, &item);
g_value_unset (&item);
gst_caps_set_value (caps, "stream-format", &arr);
g_value_unset (&arr);
} else {
gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
"stream-format", G_TYPE_STRING, "raw",
"base-profile", G_TYPE_STRING, "lc", NULL);
if (context && context->extradata_size > 0)
gst_codec_utils_aac_caps_set_level_and_profile (caps,
context->extradata, context->extradata_size);
}
break;
}
case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
"mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
NULL);
break;
case CODEC_ID_ASV1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
"asusversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_ASV2:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
"asusversion", G_TYPE_INT, 2, NULL);
break;
case CODEC_ID_FFV1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ffv",
"ffvversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_4XM:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-4xm", NULL);
break;
case CODEC_ID_XAN_WC3:
case CODEC_ID_XAN_WC4:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-xan",
"wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
break;
case CODEC_ID_CLJR:
caps =
gst_ff_vid_caps_new (context, codec_id,
"video/x-cirrus-logic-accupak", NULL);
break;
case CODEC_ID_FRAPS:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-fraps", NULL);
break;
case CODEC_ID_MDEC:
case CODEC_ID_ROQ:
case CODEC_ID_INTERPLAY_VIDEO:
buildcaps = TRUE;
break;
case CODEC_ID_VCR1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ati-vcr",
"vcrversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_RPZA:
caps =
gst_ff_vid_caps_new (context, codec_id, "video/x-apple-video", NULL);
break;
case CODEC_ID_CINEPAK:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-cinepak", NULL);
break;
/* WS_VQA belogns here (order) */
case CODEC_ID_MSRLE:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
"layout", G_TYPE_STRING, "microsoft", NULL);
if (context) {
gst_caps_set_simple (caps,
"depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
} else {
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
}
break;
case CODEC_ID_QTRLE:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
"layout", G_TYPE_STRING, "quicktime", NULL);
if (context) {
gst_caps_set_simple (caps,
"depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
} else {
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
}
break;
case CODEC_ID_MSVIDEO1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msvideocodec",
"msvideoversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_WMV3:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
"wmvversion", G_TYPE_INT, 3, NULL);
break;
case CODEC_ID_VC1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
"wmvversion", G_TYPE_INT, 3, "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('W', 'V', 'C', '1'), NULL);
break;
case CODEC_ID_QDM2:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-qdm2", NULL);
break;
case CODEC_ID_MSZH:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mszh", NULL);
break;
case CODEC_ID_ZLIB:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zlib", NULL);
break;
case CODEC_ID_TRUEMOTION1:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
"trueversion", G_TYPE_INT, 1, NULL);
break;
case CODEC_ID_TRUEMOTION2:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
"trueversion", G_TYPE_INT, 2, NULL);
break;
case CODEC_ID_ULTI:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ultimotion",
NULL);
break;
case CODEC_ID_TSCC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-camtasia", NULL);
if (context) {
gst_caps_set_simple (caps,
"depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
} else {
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
}
break;
case CODEC_ID_KMVC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-kmvc", NULL);
break;
case CODEC_ID_NUV:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-nuv", NULL);
break;
case CODEC_ID_GIF:
caps = gst_ff_vid_caps_new (context, codec_id, "image/gif", NULL);
break;
case CODEC_ID_PNG:
caps = gst_ff_vid_caps_new (context, codec_id, "image/png", NULL);
break;
case CODEC_ID_PPM:
caps = gst_ff_vid_caps_new (context, codec_id, "image/ppm", NULL);
break;
case CODEC_ID_PBM:
caps = gst_ff_vid_caps_new (context, codec_id, "image/pbm", NULL);
break;
case CODEC_ID_PAM:
caps =
gst_ff_vid_caps_new (context, codec_id, "image/x-portable-anymap",
NULL);
break;
case CODEC_ID_PGM:
caps =
gst_ff_vid_caps_new (context, codec_id, "image/x-portable-graymap",
NULL);
break;
case CODEC_ID_PCX:
caps = gst_ff_vid_caps_new (context, codec_id, "image/x-pcx", NULL);
break;
case CODEC_ID_SGI:
caps = gst_ff_vid_caps_new (context, codec_id, "image/x-sgi", NULL);
break;
case CODEC_ID_TARGA:
caps = gst_ff_vid_caps_new (context, codec_id, "image/x-tga", NULL);
break;
case CODEC_ID_TIFF:
caps = gst_ff_vid_caps_new (context, codec_id, "image/tiff", NULL);
break;
case CODEC_ID_SUNRAST:
caps =
gst_ff_vid_caps_new (context, codec_id, "image/x-sun-raster", NULL);
break;
case CODEC_ID_SMC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-smc", NULL);
break;
case CODEC_ID_QDRAW:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-qdrw", NULL);
break;
case CODEC_ID_DNXHD:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dnxhd", NULL);
break;
case CODEC_ID_MIMIC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mimic", NULL);
break;
case CODEC_ID_VMNC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vmnc", NULL);
break;
case CODEC_ID_TRUESPEECH:
caps =
gst_ff_aud_caps_new (context, codec_id, "audio/x-truespeech", NULL);
break;
case CODEC_ID_QCELP:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/qcelp", NULL);
break;
case CODEC_ID_AMV:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-amv", NULL);
break;
case CODEC_ID_AASC:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-aasc", NULL);
break;
case CODEC_ID_LOCO:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-loco", NULL);
break;
case CODEC_ID_ZMBV:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zmbv", NULL);
break;
case CODEC_ID_LAGARITH:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-lagarith", NULL);
break;
case CODEC_ID_CSCD:
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-camstudio", NULL);
if (context) {
gst_caps_set_simple (caps,
"depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
} else {
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
}
break;
case CODEC_ID_WS_VQA:
case CODEC_ID_IDCIN:
case CODEC_ID_8BPS:
case CODEC_ID_FLIC:
case CODEC_ID_VMDVIDEO:
case CODEC_ID_VMDAUDIO:
case CODEC_ID_SONIC:
case CODEC_ID_SONIC_LS:
case CODEC_ID_SNOW:
case CODEC_ID_VIXL:
case CODEC_ID_QPEG:
case CODEC_ID_PGMYUV:
case CODEC_ID_FFVHUFF:
case CODEC_ID_WNV1:
case CODEC_ID_MP3ADU:
case CODEC_ID_MP3ON4:
case CODEC_ID_WESTWOOD_SND1:
case CODEC_ID_MMVIDEO:
case CODEC_ID_AVS:
case CODEC_ID_CAVS:
buildcaps = TRUE;
break;
/* weird quasi-codecs for the demuxers only */
case CODEC_ID_PCM_S16LE:
case CODEC_ID_PCM_S16BE:
case CODEC_ID_PCM_U16LE:
case CODEC_ID_PCM_U16BE:
case CODEC_ID_PCM_S8:
case CODEC_ID_PCM_U8:
{
gint width = 0, depth = 0, endianness = 0;
gboolean signedness = FALSE; /* blabla */
switch (codec_id) {
case CODEC_ID_PCM_S16LE:
width = 16;
depth = 16;
endianness = G_LITTLE_ENDIAN;
signedness = TRUE;
break;
case CODEC_ID_PCM_S16BE:
width = 16;
depth = 16;
endianness = G_BIG_ENDIAN;
signedness = TRUE;
break;
case CODEC_ID_PCM_U16LE:
width = 16;
depth = 16;
endianness = G_LITTLE_ENDIAN;
signedness = FALSE;
break;
case CODEC_ID_PCM_U16BE:
width = 16;
depth = 16;
endianness = G_BIG_ENDIAN;
signedness = FALSE;
break;
case CODEC_ID_PCM_S8:
width = 8;
depth = 8;
endianness = G_BYTE_ORDER;
signedness = TRUE;
break;
case CODEC_ID_PCM_U8:
width = 8;
depth = 8;
endianness = G_BYTE_ORDER;
signedness = FALSE;
break;
default:
g_assert (0); /* don't worry, we never get here */
break;
}
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
"width", G_TYPE_INT, width,
"depth", G_TYPE_INT, depth,
"endianness", G_TYPE_INT, endianness,
"signed", G_TYPE_BOOLEAN, signedness, NULL);
}
break;
case CODEC_ID_PCM_MULAW:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mulaw", NULL);
break;
case CODEC_ID_PCM_ALAW:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alaw", NULL);
break;
case CODEC_ID_ADPCM_G722:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/G722", NULL);
if (context)
gst_caps_set_simple (caps,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
break;
case CODEC_ID_ADPCM_G726:
{
/* the G726 decoder can also handle G721 */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
"layout", G_TYPE_STRING, "g726", NULL);
if (context)
gst_caps_set_simple (caps,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
if (!encode) {
gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
"layout", G_TYPE_STRING, "g721",
"channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
}
break;
}
case CODEC_ID_ADPCM_IMA_QT:
case CODEC_ID_ADPCM_IMA_WAV:
case CODEC_ID_ADPCM_IMA_DK3:
case CODEC_ID_ADPCM_IMA_DK4:
case CODEC_ID_ADPCM_IMA_WS:
case CODEC_ID_ADPCM_IMA_SMJPEG:
case CODEC_ID_ADPCM_IMA_AMV:
case CODEC_ID_ADPCM_IMA_ISS:
case CODEC_ID_ADPCM_IMA_EA_EACS:
case CODEC_ID_ADPCM_IMA_EA_SEAD:
case CODEC_ID_ADPCM_MS:
case CODEC_ID_ADPCM_4XM:
case CODEC_ID_ADPCM_XA:
case CODEC_ID_ADPCM_ADX:
case CODEC_ID_ADPCM_EA:
case CODEC_ID_ADPCM_CT:
case CODEC_ID_ADPCM_SWF:
case CODEC_ID_ADPCM_YAMAHA:
case CODEC_ID_ADPCM_SBPRO_2:
case CODEC_ID_ADPCM_SBPRO_3:
case CODEC_ID_ADPCM_SBPRO_4:
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_EA_R3:
case CODEC_ID_ADPCM_EA_MAXIS_XA:
case CODEC_ID_ADPCM_EA_XAS:
case CODEC_ID_ADPCM_THP:
{
const gchar *layout = NULL;
switch (codec_id) {
case CODEC_ID_ADPCM_IMA_QT:
layout = "quicktime";
break;
case CODEC_ID_ADPCM_IMA_WAV:
layout = "dvi";
break;
case CODEC_ID_ADPCM_IMA_DK3:
layout = "dk3";
break;
case CODEC_ID_ADPCM_IMA_DK4:
layout = "dk4";
break;
case CODEC_ID_ADPCM_IMA_WS:
layout = "westwood";
break;
case CODEC_ID_ADPCM_IMA_SMJPEG:
layout = "smjpeg";
break;
case CODEC_ID_ADPCM_IMA_AMV:
layout = "amv";
break;
case CODEC_ID_ADPCM_IMA_ISS:
layout = "iss";
break;
case CODEC_ID_ADPCM_IMA_EA_EACS:
layout = "ea-eacs";
break;
case CODEC_ID_ADPCM_IMA_EA_SEAD:
layout = "ea-sead";
break;
case CODEC_ID_ADPCM_MS:
layout = "microsoft";
break;
case CODEC_ID_ADPCM_4XM:
layout = "4xm";
break;
case CODEC_ID_ADPCM_XA:
layout = "xa";
break;
case CODEC_ID_ADPCM_ADX:
layout = "adx";
break;
case CODEC_ID_ADPCM_EA:
layout = "ea";
break;
case CODEC_ID_ADPCM_CT:
layout = "ct";
break;
case CODEC_ID_ADPCM_SWF:
layout = "swf";
break;
case CODEC_ID_ADPCM_YAMAHA:
layout = "yamaha";
break;
case CODEC_ID_ADPCM_SBPRO_2:
layout = "sbpro2";
break;
case CODEC_ID_ADPCM_SBPRO_3:
layout = "sbpro3";
break;
case CODEC_ID_ADPCM_SBPRO_4:
layout = "sbpro4";
break;
case CODEC_ID_ADPCM_EA_R1:
layout = "ea-r1";
break;
case CODEC_ID_ADPCM_EA_R2:
layout = "ea-r3";
break;
case CODEC_ID_ADPCM_EA_R3:
layout = "ea-r3";
break;
case CODEC_ID_ADPCM_EA_MAXIS_XA:
layout = "ea-maxis-xa";
break;
case CODEC_ID_ADPCM_EA_XAS:
layout = "ea-xas";
break;
case CODEC_ID_ADPCM_THP:
layout = "thp";
break;
default:
g_assert (0); /* don't worry, we never get here */
break;
}
/* FIXME: someone please check whether we need additional properties
* in this caps definition. */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
"layout", G_TYPE_STRING, layout, NULL);
if (context)
gst_caps_set_simple (caps,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
}
break;
case CODEC_ID_AMR_NB:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR", NULL);
break;
case CODEC_ID_AMR_WB:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR-WB", NULL);
break;
case CODEC_ID_GSM:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-gsm", NULL);
break;
case CODEC_ID_GSM_MS:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/ms-gsm", NULL);
break;
case CODEC_ID_NELLYMOSER:
caps =
gst_ff_aud_caps_new (context, codec_id, "audio/x-nellymoser", NULL);
break;
case CODEC_ID_SIPR:
{
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-sipro", NULL);
if (context) {
gst_caps_set_simple (caps,
"leaf_size", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
}
}
break;
case CODEC_ID_RA_144:
case CODEC_ID_RA_288:
case CODEC_ID_COOK:
{
gint version = 0;
switch (codec_id) {
case CODEC_ID_RA_144:
version = 1;
break;
case CODEC_ID_RA_288:
version = 2;
break;
case CODEC_ID_COOK:
version = 8;
break;
default:
break;
}
/* FIXME: properties? */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-pn-realaudio",
"raversion", G_TYPE_INT, version, NULL);
if (context) {
gst_caps_set_simple (caps,
"leaf_size", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
}
}
break;
case CODEC_ID_ROQ_DPCM:
case CODEC_ID_INTERPLAY_DPCM:
case CODEC_ID_XAN_DPCM:
case CODEC_ID_SOL_DPCM:
{
const gchar *layout = NULL;
switch (codec_id) {
case CODEC_ID_ROQ_DPCM:
layout = "roq";
break;
case CODEC_ID_INTERPLAY_DPCM:
layout = "interplay";
break;
case CODEC_ID_XAN_DPCM:
layout = "xan";
break;
case CODEC_ID_SOL_DPCM:
layout = "sol";
break;
default:
g_assert (0); /* don't worry, we never get here */
break;
}
/* FIXME: someone please check whether we need additional properties
* in this caps definition. */
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dpcm",
"layout", G_TYPE_STRING, layout, NULL);
if (context)
gst_caps_set_simple (caps,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
}
break;
case CODEC_ID_SHORTEN:
caps = gst_caps_new_simple ("audio/x-shorten", NULL);
break;
case CODEC_ID_ALAC:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alac", NULL);
if (context) {
gst_caps_set_simple (caps,
"samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
}
break;
case CODEC_ID_FLAC:
/* Note that ffmpeg has no encoder yet, but just for safety. In the
* encoder case, we want to add things like samplerate, channels... */
if (!encode) {
caps = gst_caps_new_simple ("audio/x-flac", NULL);
}
break;
case CODEC_ID_DVD_SUBTITLE:
case CODEC_ID_DVB_SUBTITLE:
caps = NULL;
break;
case CODEC_ID_BMP:
caps = gst_caps_new_simple ("image/bmp", NULL);
break;
case CODEC_ID_TTA:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-tta", NULL);
if (context) {
gst_caps_set_simple (caps,
"samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
}
break;
case CODEC_ID_TWINVQ:
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-twin-vq", NULL);
break;
default:
GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
break;
}
if (buildcaps) {
AVCodec *codec;
if ((codec = avcodec_find_decoder (codec_id)) ||
(codec = avcodec_find_encoder (codec_id))) {
gchar *mime = NULL;
GST_LOG ("Could not create stream format caps for %s", codec->name);
switch (codec->type) {
case AVMEDIA_TYPE_VIDEO:
mime = g_strdup_printf ("video/x-gst_ff-%s", codec->name);
caps = gst_ff_vid_caps_new (context, codec_id, mime, NULL);
g_free (mime);
break;
case AVMEDIA_TYPE_AUDIO:
mime = g_strdup_printf ("audio/x-gst_ff-%s", codec->name);
caps = gst_ff_aud_caps_new (context, codec_id, mime, NULL);
if (context)
gst_caps_set_simple (caps,
"block_align", G_TYPE_INT, context->block_align,
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
g_free (mime);
break;
default:
break;
}
}
}
if (caps != NULL) {
/* set private data */
if (context && context->extradata_size > 0) {
GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
memcpy (GST_BUFFER_DATA (data), context->extradata,
context->extradata_size);
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
gst_buffer_unref (data);
}
/* palette */
if (context) {
gst_ffmpeg_set_palette (caps, context);
}
GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
} else {
GST_LOG ("No caps found for codec_id=%d", codec_id);
}
return caps;
}
/* Convert a FFMPEG Pixel Format and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* See below for usefullness
*/
GstCaps *
gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
enum CodecID codec_id)
{
GstCaps *caps = NULL;
int bpp = 0, depth = 0, endianness = 0;
gulong g_mask = 0, r_mask = 0, b_mask = 0, a_mask = 0;
guint32 fmt = 0;
switch (pix_fmt) {
case PIX_FMT_YUVJ420P:
case PIX_FMT_YUV420P:
fmt = GST_MAKE_FOURCC ('I', '4', '2', '0');
break;
case PIX_FMT_YUVA420P:
fmt = GST_MAKE_FOURCC ('A', '4', '2', '0');
break;
case PIX_FMT_YUYV422:
fmt = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
break;
case PIX_FMT_RGB24:
bpp = depth = 24;
endianness = G_BIG_ENDIAN;
r_mask = 0xff0000;
g_mask = 0x00ff00;
b_mask = 0x0000ff;
break;
case PIX_FMT_BGR24:
bpp = depth = 24;
endianness = G_BIG_ENDIAN;
r_mask = 0x0000ff;
g_mask = 0x00ff00;
b_mask = 0xff0000;
break;
case PIX_FMT_YUVJ422P:
case PIX_FMT_YUV422P:
fmt = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
break;
case PIX_FMT_YUVJ444P:
case PIX_FMT_YUV444P:
fmt = GST_MAKE_FOURCC ('Y', '4', '4', '4');
break;
case PIX_FMT_RGB32:
bpp = 32;
depth = 32;
endianness = G_BIG_ENDIAN;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
r_mask = 0x00ff0000;
g_mask = 0x0000ff00;
b_mask = 0x000000ff;
a_mask = 0xff000000;
#else
r_mask = 0x0000ff00;
g_mask = 0x00ff0000;
b_mask = 0xff000000;
a_mask = 0x000000ff;
#endif
break;
case PIX_FMT_YUV410P:
fmt = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
break;
case PIX_FMT_YUV411P:
fmt = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
break;
case PIX_FMT_RGB565:
bpp = depth = 16;
endianness = G_BYTE_ORDER;
r_mask = 0xf800;
g_mask = 0x07e0;
b_mask = 0x001f;
break;
case PIX_FMT_RGB555:
bpp = 16;
depth = 15;
endianness = G_BYTE_ORDER;
r_mask = 0x7c00;
g_mask = 0x03e0;
b_mask = 0x001f;
break;
case PIX_FMT_PAL8:
bpp = depth = 8;
endianness = G_BYTE_ORDER;
break;
case PIX_FMT_GRAY8:
bpp = depth = 8;
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-gray",
"bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
break;
default:
/* give up ... */
break;
}
if (caps == NULL) {
if (bpp != 0) {
if (r_mask != 0) {
if (a_mask) {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"red_mask", G_TYPE_INT, r_mask,
"green_mask", G_TYPE_INT, g_mask,
"blue_mask", G_TYPE_INT, b_mask,
"alpha_mask", G_TYPE_INT, a_mask,
"endianness", G_TYPE_INT, endianness, NULL);
} else {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"red_mask", G_TYPE_INT, r_mask,
"green_mask", G_TYPE_INT, g_mask,
"blue_mask", G_TYPE_INT, b_mask,
"endianness", G_TYPE_INT, endianness, NULL);
}
} else {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"endianness", G_TYPE_INT, endianness, NULL);
if (caps && context) {
gst_ffmpeg_set_palette (caps, context);
}
}
} else if (fmt) {
caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-yuv",
"format", GST_TYPE_FOURCC, fmt, NULL);
}
}
if (caps != NULL) {
GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
} else {
GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
}
return caps;
}
/* Convert a FFMPEG Sample Format and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* See below for usefullness
*/
static GstCaps *
gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt,
AVCodecContext * context, enum CodecID codec_id)
{
GstCaps *caps = NULL;
int bpp = 0;
gboolean integer = TRUE;
gboolean signedness = FALSE;
switch (sample_fmt) {
case SAMPLE_FMT_S16:
signedness = TRUE;
bpp = 16;
break;
case SAMPLE_FMT_S32:
signedness = TRUE;
bpp = 32;
break;
case SAMPLE_FMT_FLT:
integer = FALSE;
bpp = 32;
break;
case SAMPLE_FMT_DBL:
integer = FALSE;
bpp = 64;
break;
default:
/* .. */
break;
}
if (bpp) {
if (integer) {
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
"signed", G_TYPE_BOOLEAN, signedness,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
} else {
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-float",
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"width", G_TYPE_INT, bpp, NULL);
}
}
if (caps != NULL) {
GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
} else {
GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
}
return caps;
}
GstCaps *
gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
enum CodecID codec_id, gboolean encode, AVCodec * codec)
{
GstCaps *caps = NULL;
GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
context, codec_id, encode, codec);
if (codec)
GST_DEBUG ("sample_fmts:%p, samplerates:%p",
codec->sample_fmts, codec->supported_samplerates);
if (context) {
/* Specific codec context */
caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
} else if (codec && codec->sample_fmts) {
GstCaps *temp;
int i;
caps = gst_caps_new_empty ();
for (i = 0; codec->sample_fmts[i] != -1; i++) {
temp =
gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
if (temp != NULL)
gst_caps_append (caps, temp);
}
} else {
GstCaps *temp;
enum SampleFormat i;
AVCodecContext ctx = { 0, };
ctx.channels = -1;
caps = gst_caps_new_empty ();
for (i = 0; i <= SAMPLE_FMT_DBL; i++) {
temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
if (temp != NULL) {
gst_caps_append (caps, temp);
}
}
}
return caps;
}
GstCaps *
gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
enum CodecID codec_id, gboolean encode, AVCodec * codec)
{
GstCaps *caps;
GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
context, codec_id, encode, codec);
if (context) {
caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
} else {
GstCaps *temp;
enum PixelFormat i;
AVCodecContext ctx = { 0, };
caps = gst_caps_new_empty ();
for (i = 0; i < PIX_FMT_NB; i++) {
ctx.width = -1;
ctx.pix_fmt = i;
temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
if (temp != NULL) {
gst_caps_append (caps, temp);
}
}
}
return caps;
}
/* Convert a FFMPEG codec Type and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* AVMediaType is primarily meant for uncompressed data GstCaps!
*/
GstCaps *
gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
AVCodecContext * context, enum CodecID codec_id, gboolean encode)
{
GstCaps *caps;
switch (codec_type) {
case AVMEDIA_TYPE_VIDEO:
caps =
gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
break;
case AVMEDIA_TYPE_AUDIO:
caps =
gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
break;
default:
caps = NULL;
break;
}
return caps;
}
/* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
* and other audio properties in a AVCodecContext.
*
* For usefullness, see below
*/
static void
gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
AVCodecContext * context, gboolean raw)
{
GstStructure *structure;
gint depth = 0, width = 0, endianness = 0;
gboolean signedness = FALSE;
const gchar *name;
g_return_if_fail (gst_caps_get_size (caps) == 1);
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "channels", &context->channels);
gst_structure_get_int (structure, "rate", &context->sample_rate);
gst_structure_get_int (structure, "block_align", &context->block_align);
gst_structure_get_int (structure, "bitrate", &context->bit_rate);
if (!raw)
return;
name = gst_structure_get_name (structure);
if (!strcmp (name, "audio/x-raw-float")) {
/* FLOAT */
if (gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "endianness", &endianness)) {
if (endianness == G_BYTE_ORDER) {
if (width == 32)
context->sample_fmt = SAMPLE_FMT_FLT;
else if (width == 64)
context->sample_fmt = SAMPLE_FMT_DBL;
}
}
} else {
/* INT */
if (gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "depth", &depth) &&
gst_structure_get_boolean (structure, "signed", &signedness) &&
gst_structure_get_int (structure, "endianness", &endianness)) {
if ((endianness == G_BYTE_ORDER) && (signedness == TRUE)) {
if ((width == 16) && (depth == 16))
context->sample_fmt = SAMPLE_FMT_S16;
else if ((width == 32) && (depth == 32))
context->sample_fmt = SAMPLE_FMT_S32;
}
}
}
}
/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
* and other video properties in a AVCodecContext.
*
* For usefullness, see below
*/
static void
gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
AVCodecContext * context, gboolean raw)
{
GstStructure *structure;
const GValue *fps;
const GValue *par = NULL;
GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
g_return_if_fail (gst_caps_get_size (caps) == 1);
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "width", &context->width);
gst_structure_get_int (structure, "height", &context->height);
gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
fps = gst_structure_get_value (structure, "framerate");
if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
/* somehow these seem mixed up.. */
context->time_base.den = gst_value_get_fraction_numerator (fps);
context->time_base.num = gst_value_get_fraction_denominator (fps);
context->ticks_per_frame = 1;
GST_DEBUG ("setting framerate %d/%d = %lf",
context->time_base.den, context->time_base.num,
1. * context->time_base.den / context->time_base.num);
}
par = gst_structure_get_value (structure, "pixel-aspect-ratio");
if (par && GST_VALUE_HOLDS_FRACTION (par)) {
context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
1. * context->sample_aspect_ratio.den /
context->sample_aspect_ratio.num);
}
if (!raw)
return;
g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
guint32 fourcc;
if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
switch (fourcc) {
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
context->pix_fmt = PIX_FMT_YUYV422;
break;
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
context->pix_fmt = PIX_FMT_YUV420P;
break;
case GST_MAKE_FOURCC ('A', '4', '2', '0'):
context->pix_fmt = PIX_FMT_YUVA420P;
break;
case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
context->pix_fmt = PIX_FMT_YUV411P;
break;
case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
context->pix_fmt = PIX_FMT_YUV422P;
break;
case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
context->pix_fmt = PIX_FMT_YUV410P;
break;
#if 0
case FIXME:
context->pix_fmt = PIX_FMT_YUV444P;
break;
#endif
}
}
} else if (strcmp (gst_structure_get_name (structure),
"video/x-raw-rgb") == 0) {
gint bpp = 0, rmask = 0, endianness = 0;
if (gst_structure_get_int (structure, "bpp", &bpp) &&
gst_structure_get_int (structure, "endianness", &endianness)) {
if (gst_structure_get_int (structure, "red_mask", &rmask)) {
switch (bpp) {
case 32:
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
if (rmask == 0x00ff0000)
#else
if (rmask == 0x0000ff00)
#endif
context->pix_fmt = PIX_FMT_RGB32;
break;
case 24:
if (rmask == 0x0000FF)
context->pix_fmt = PIX_FMT_BGR24;
else
context->pix_fmt = PIX_FMT_RGB24;
break;
case 16:
if (endianness == G_BYTE_ORDER)
context->pix_fmt = PIX_FMT_RGB565;
break;
case 15:
if (endianness == G_BYTE_ORDER)
context->pix_fmt = PIX_FMT_RGB555;
break;
default:
/* nothing */
break;
}
} else {
if (bpp == 8) {
context->pix_fmt = PIX_FMT_PAL8;
gst_ffmpeg_get_palette (caps, context);
}
}
}
} else if (strcmp (gst_structure_get_name (structure),
"video/x-raw-gray") == 0) {
gint bpp = 0;
if (gst_structure_get_int (structure, "bpp", &bpp)) {
switch (bpp) {
case 8:
context->pix_fmt = PIX_FMT_GRAY8;
break;
}
}
}
}
/* Convert a GstCaps and a FFMPEG codec Type to a
* AVCodecContext. If the context is ommitted, no fixed values
* for video/audio size will be included in the context
*
* AVMediaType is primarily meant for uncompressed data GstCaps!
*/
void
gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
const GstCaps * caps, AVCodecContext * context)
{
if (context == NULL)
return;
switch (type) {
case AVMEDIA_TYPE_VIDEO:
gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
break;
case AVMEDIA_TYPE_AUDIO:
gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
break;
default:
/* unknown */
break;
}
}
#if 0
static void
nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
{
guint8 *dstp = dst;
guint8 *srcp = src;
guint8 *end = src + size;
gint count = 0;
while (srcp < end) {
if (count == 2 && *srcp <= 0x03) {
GST_DEBUG ("added escape code");
*dstp++ = 0x03;
count = 0;
}
if (*srcp == 0)
count++;
else
count = 0;
GST_DEBUG ("copy %02x, count %d", *srcp, count);
*dstp++ = *srcp++;
}
*destsize = dstp - dst;
}
/* copy the config, escaping NAL units as we iterate them, if something fails we
* copy everything and hope for the best. */
static void
copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
{
guint8 *dstp = dst;
guint8 *srcp = src;
gint cnt, i;
guint nalsize, esize;
/* check size */
if (size < 7)
goto full_copy;
/* check version */
if (*srcp != 1)
goto full_copy;
cnt = *(srcp + 5) & 0x1f; /* Number of sps */
GST_DEBUG ("num SPS %d", cnt);
memcpy (dstp, srcp, 6);
srcp += 6;
dstp += 6;
for (i = 0; i < cnt; i++) {
GST_DEBUG ("copy SPS %d", i);
nalsize = (srcp[0] << 8) | srcp[1];
nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
dstp[0] = esize >> 8;
dstp[1] = esize & 0xff;
dstp += esize + 2;
srcp += nalsize + 2;
}
cnt = *(dstp++) = *(srcp++); /* Number of pps */
GST_DEBUG ("num PPS %d", cnt);
for (i = 0; i < cnt; i++) {
GST_DEBUG ("copy PPS %d", i);
nalsize = (srcp[0] << 8) | srcp[1];
nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
dstp[0] = esize >> 8;
dstp[1] = esize & 0xff;
dstp += esize + 2;
srcp += nalsize + 2;
}
*destsize = dstp - dst;
return;
full_copy:
{
GST_DEBUG ("something unexpected, doing full copy");
memcpy (dst, src, size);
*destsize = size;
return;
}
}
#endif
/*
* caps_with_codecid () transforms a GstCaps for a known codec
* ID into a filled-in context.
* codec_data from caps will override possible extradata already in the context
*/
void
gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
{
GstStructure *str;
const GValue *value;
const GstBuffer *buf;
GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
codec_id, codec_type, caps, context);
if (!context || !gst_caps_get_size (caps))
return;
str = gst_caps_get_structure (caps, 0);
/* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
if ((value = gst_structure_get_value (str, "codec_data"))) {
guint size;
guint8 *data;
buf = GST_BUFFER_CAST (gst_value_get_mini_object (value));
size = GST_BUFFER_SIZE (buf);
data = GST_BUFFER_DATA (buf);
/* free the old one if it is there */
if (context->extradata)
av_free (context->extradata);
#if 0
if (codec_id == CODEC_ID_H264) {
guint extrasize;
GST_DEBUG ("copy, escaping codec_data %d", size);
/* ffmpeg h264 expects the codec_data to be escaped, there is no real
* reason for this but let's just escape it for now. Start by allocating
* enough space, x2 is more than enough.
*
* FIXME, we disabled escaping because some file already contain escaped
* codec_data and then we escape twice and fail. It's better to leave it
* as is, as that is what most players do. */
context->extradata =
av_mallocz (GST_ROUND_UP_16 (size * 2 +
FF_INPUT_BUFFER_PADDING_SIZE));
copy_config (context->extradata, data, size, &extrasize);
GST_DEBUG ("escaped size: %d", extrasize);
context->extradata_size = extrasize;
} else
#endif
{
/* allocate with enough padding */
GST_DEBUG ("copy codec_data");
context->extradata =
av_mallocz (GST_ROUND_UP_16 (size + FF_INPUT_BUFFER_PADDING_SIZE));
memcpy (context->extradata, data, size);
context->extradata_size = size;
}
/* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
if (codec_id == CODEC_ID_VC1 && size > 0 && data[0] == 0) {
context->extradata[0] = (guint8) size;
}
GST_DEBUG ("have codec data of size %d", size);
} else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
codec_id != CODEC_ID_FLAC) {
/* no extradata, alloc dummy with 0 sized, some codecs insist on reading
* extradata anyway which makes then segfault. */
context->extradata =
av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
context->extradata_size = 0;
GST_DEBUG ("no codec data");
}
switch (codec_id) {
case CODEC_ID_MPEG4:
{
const gchar *mime = gst_structure_get_name (str);
if (!strcmp (mime, "video/x-divx"))
context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
else if (!strcmp (mime, "video/x-xvid"))
context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
else if (!strcmp (mime, "video/x-3ivx"))
context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
else if (!strcmp (mime, "video/mpeg"))
context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
}
break;
case CODEC_ID_SVQ3:
/* FIXME: this is a workaround for older gst-plugins releases
* (<= 0.8.9). This should be removed at some point, because
* it causes wrong decoded frame order. */
if (!context->extradata) {
gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
guint16 flags;
if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
gst_structure_get_int (str, "low_delay", &low_delay) ||
gst_structure_get_int (str, "unknown_svq3_flag",
&unknown_svq3_flag)) {
context->extradata = (guint8 *) av_mallocz (0x64);
g_stpcpy ((gchar *) context->extradata, "SVQ3");
flags = 1 << 3;
flags |= low_delay;
flags = flags << 2;
flags |= unknown_svq3_flag;
flags = flags << 6;
flags |= halfpel_flag;
flags = flags << 1;
flags |= thirdpel_flag;
flags = flags << 3;
flags = GUINT16_FROM_LE (flags);
memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
context->extradata_size = 0x64;
}
}
break;
case CODEC_ID_MSRLE:
case CODEC_ID_QTRLE:
case CODEC_ID_TSCC:
case CODEC_ID_CSCD:
case CODEC_ID_APE:
{
gint depth;
if (gst_structure_get_int (str, "depth", &depth)) {
context->bits_per_coded_sample = depth;
} else {
GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
}
}
break;
case CODEC_ID_RV10:
case CODEC_ID_RV20:
case CODEC_ID_RV30:
case CODEC_ID_RV40:
{
gint format;
if (gst_structure_get_int (str, "format", &format))
context->sub_id = format;
break;
}
case CODEC_ID_COOK:
case CODEC_ID_RA_288:
case CODEC_ID_RA_144:
case CODEC_ID_SIPR:
{
gint leaf_size;
gint bitrate;
if (gst_structure_get_int (str, "leaf_size", &leaf_size))
context->block_align = leaf_size;
if (gst_structure_get_int (str, "bitrate", &bitrate))
context->bit_rate = bitrate;
}
case CODEC_ID_ALAC:
gst_structure_get_int (str, "samplesize",
&context->bits_per_coded_sample);
break;
case CODEC_ID_DVVIDEO:
{
guint32 fourcc;
if (gst_structure_get_fourcc (str, "format", &fourcc))
switch (fourcc) {
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
context->pix_fmt = PIX_FMT_YUYV422;
break;
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
context->pix_fmt = PIX_FMT_YUV420P;
break;
case GST_MAKE_FOURCC ('A', '4', '2', '0'):
context->pix_fmt = PIX_FMT_YUVA420P;
break;
case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
context->pix_fmt = PIX_FMT_YUV411P;
break;
case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
context->pix_fmt = PIX_FMT_YUV422P;
break;
case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
context->pix_fmt = PIX_FMT_YUV410P;
break;
default:
GST_WARNING ("couldn't convert fourcc %" GST_FOURCC_FORMAT
" to a pixel format", GST_FOURCC_ARGS (fourcc));
break;
}
break;
}
case CODEC_ID_H263P:
{
gboolean val;
if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
context->flags |= CODEC_FLAG_4MV;
else
context->flags &= ~CODEC_FLAG_4MV;
if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
(!gst_structure_get_boolean (str, "annex-t", &val) || val))
context->flags |= CODEC_FLAG_AC_PRED;
else
context->flags &= ~CODEC_FLAG_AC_PRED;
if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
context->flags |= CODEC_FLAG_LOOP_FILTER;
else
context->flags &= ~CODEC_FLAG_LOOP_FILTER;
break;
}
case CODEC_ID_ADPCM_G726:
{
const gchar *layout;
if ((layout = gst_structure_get_string (str, "layout"))) {
if (!strcmp (layout, "g721")) {
context->sample_rate = 8000;
context->channels = 1;
context->bit_rate = 32000;
}
}
break;
}
default:
break;
}
if (!gst_caps_is_fixed (caps))
return;
/* common properties (width, height, fps) */
switch (codec_type) {
case AVMEDIA_TYPE_VIDEO:
gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
gst_ffmpeg_get_palette (caps, context);
break;
case AVMEDIA_TYPE_AUDIO:
gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
break;
default:
break;
}
/* fixup of default settings */
switch (codec_id) {
case CODEC_ID_QCELP:
/* QCELP is always mono, no matter what the caps say */
context->channels = 1;
break;
default:
break;
}
}
/* _formatid_to_caps () is meant for muxers/demuxers, it
* transforms a name (ffmpeg way of ID'ing these, why don't
* they have unique numerical IDs?) to the corresponding
* caps belonging to that mux-format
*
* Note: we don't need any additional info because the caps
* isn't supposed to contain any useful info besides the
* media type anyway
*/
GstCaps *
gst_ffmpeg_formatid_to_caps (const gchar * format_name)
{
GstCaps *caps = NULL;
if (!strcmp (format_name, "mpeg")) {
caps = gst_caps_new_simple ("video/mpeg",
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
} else if (!strcmp (format_name, "mpegts")) {
caps = gst_caps_new_simple ("video/mpegts",
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
} else if (!strcmp (format_name, "rm")) {
caps = gst_caps_new_simple ("application/x-pn-realmedia",
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
} else if (!strcmp (format_name, "asf")) {
caps = gst_caps_new_simple ("video/x-ms-asf", NULL);
} else if (!strcmp (format_name, "avi")) {
caps = gst_caps_new_simple ("video/x-msvideo", NULL);
} else if (!strcmp (format_name, "wav")) {
caps = gst_caps_new_simple ("audio/x-wav", NULL);
} else if (!strcmp (format_name, "ape")) {
caps = gst_caps_new_simple ("application/x-ape", NULL);
} else if (!strcmp (format_name, "swf")) {
caps = gst_caps_new_simple ("application/x-shockwave-flash", NULL);
} else if (!strcmp (format_name, "au")) {
caps = gst_caps_new_simple ("audio/x-au", NULL);
} else if (!strcmp (format_name, "dv")) {
caps = gst_caps_new_simple ("video/x-dv",
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
} else if (!strcmp (format_name, "4xm")) {
caps = gst_caps_new_simple ("video/x-4xm", NULL);
} else if (!strcmp (format_name, "matroska")) {
caps = gst_caps_new_simple ("video/x-matroska", NULL);
} else if (!strcmp (format_name, "mp3")) {
caps = gst_caps_new_simple ("application/x-id3", NULL);
} else if (!strcmp (format_name, "flic")) {
caps = gst_caps_new_simple ("video/x-fli", NULL);
} else if (!strcmp (format_name, "flv")) {
caps = gst_caps_new_simple ("video/x-flv", NULL);
} else if (!strcmp (format_name, "tta")) {
caps = gst_caps_new_simple ("audio/x-ttafile", NULL);
} else if (!strcmp (format_name, "aiff")) {
caps = gst_caps_new_simple ("audio/x-aiff", NULL);
} else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
caps =
gst_caps_from_string
("application/x-3gp; video/quicktime; audio/x-m4a");
} else if (!strcmp (format_name, "mov")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
} else if (!strcmp (format_name, "mp4")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
} else if (!strcmp (format_name, "3gp")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
} else if (!strcmp (format_name, "3g2")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
} else if (!strcmp (format_name, "psp")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
} else if (!strcmp (format_name, "ipod")) {
caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
} else if (!strcmp (format_name, "aac")) {
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 4, NULL);
} else if (!strcmp (format_name, "gif")) {
caps = gst_caps_from_string ("image/gif");
} else if (!strcmp (format_name, "ogg")) {
caps = gst_caps_from_string ("application/ogg");
} else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
caps = gst_caps_from_string ("application/mxf");
} else if (!strcmp (format_name, "gxf")) {
caps = gst_caps_from_string ("application/gxf");
} else if (!strcmp (format_name, "yuv4mpegpipe")) {
caps = gst_caps_new_simple ("application/x-yuv4mpeg",
"y4mversion", G_TYPE_INT, 2, NULL);
} else if (!strcmp (format_name, "mpc")) {
caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
} else if (!strcmp (format_name, "vqf")) {
caps = gst_caps_from_string ("audio/x-vqf");
} else if (!strcmp (format_name, "nsv")) {
caps = gst_caps_from_string ("video/x-nsv");
} else if (!strcmp (format_name, "amr")) {
caps = gst_caps_from_string ("audio/x-amr-nb-sh");
} else if (!strcmp (format_name, "webm")) {
caps = gst_caps_from_string ("video/webm");
} else {
gchar *name;
GST_LOG ("Could not create stream format caps for %s", format_name);
name = g_strdup_printf ("application/x-gst_ff-%s", format_name);
caps = gst_caps_new_simple (name, NULL);
g_free (name);
}
return caps;
}
gboolean
gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
AVOutputFormat * plugin)
{
static enum CodecID tmp_vlist[] = {
CODEC_ID_NONE,
CODEC_ID_NONE
};
static enum CodecID tmp_alist[] = {
CODEC_ID_NONE,
CODEC_ID_NONE
};
GST_LOG ("format_name : %s", format_name);
if (!strcmp (format_name, "mp4")) {
static enum CodecID mp4_video_list[] = {
CODEC_ID_MPEG4, CODEC_ID_H264,
CODEC_ID_MJPEG,
CODEC_ID_NONE
};
static enum CodecID mp4_audio_list[] = {
CODEC_ID_AAC, CODEC_ID_MP3,
CODEC_ID_NONE
};
*video_codec_list = mp4_video_list;
*audio_codec_list = mp4_audio_list;
} else if (!strcmp (format_name, "mpeg")) {
static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
CODEC_ID_MPEG2VIDEO,
CODEC_ID_H264,
CODEC_ID_NONE
};
static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
CODEC_ID_MP2,
CODEC_ID_MP3,
CODEC_ID_NONE
};
*video_codec_list = mpeg_video_list;
*audio_codec_list = mpeg_audio_list;
} else if (!strcmp (format_name, "dvd")) {
static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
CODEC_ID_NONE
};
static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
CODEC_ID_AC3,
CODEC_ID_DTS,
CODEC_ID_PCM_S16BE,
CODEC_ID_NONE
};
*video_codec_list = mpeg_video_list;
*audio_codec_list = mpeg_audio_list;
} else if (!strcmp (format_name, "mpegts")) {
static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
CODEC_ID_MPEG2VIDEO,
CODEC_ID_H264,
CODEC_ID_NONE
};
static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
CODEC_ID_MP3,
CODEC_ID_AC3,
CODEC_ID_DTS,
CODEC_ID_AAC,
CODEC_ID_NONE
};
*video_codec_list = mpegts_video_list;
*audio_codec_list = mpegts_audio_list;
} else if (!strcmp (format_name, "vob")) {
static enum CodecID vob_video_list[] =
{ CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
CODEC_ID_DTS, CODEC_ID_NONE
};
*video_codec_list = vob_video_list;
*audio_codec_list = vob_audio_list;
} else if (!strcmp (format_name, "flv")) {
static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
*video_codec_list = flv_video_list;
*audio_codec_list = flv_audio_list;
} else if (!strcmp (format_name, "asf")) {
static enum CodecID asf_video_list[] =
{ CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
static enum CodecID asf_audio_list[] =
{ CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
*video_codec_list = asf_video_list;
*audio_codec_list = asf_audio_list;
} else if (!strcmp (format_name, "dv")) {
static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
*video_codec_list = dv_video_list;
*audio_codec_list = dv_audio_list;
} else if (!strcmp (format_name, "mov")) {
static enum CodecID mov_video_list[] = {
CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
CODEC_ID_H263, CODEC_ID_H263P,
CODEC_ID_H264, CODEC_ID_DVVIDEO,
CODEC_ID_MJPEG,
CODEC_ID_NONE
};
static enum CodecID mov_audio_list[] = {
CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
CODEC_ID_MP3, CODEC_ID_NONE
};
*video_codec_list = mov_video_list;
*audio_codec_list = mov_audio_list;
} else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
static enum CodecID tgp_video_list[] = {
CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
CODEC_ID_NONE
};
static enum CodecID tgp_audio_list[] = {
CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
CODEC_ID_AAC,
CODEC_ID_NONE
};
*video_codec_list = tgp_video_list;
*audio_codec_list = tgp_audio_list;
} else if (!strcmp (format_name, "mmf")) {
static enum CodecID mmf_audio_list[] = {
CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
};
*video_codec_list = NULL;
*audio_codec_list = mmf_audio_list;
} else if (!strcmp (format_name, "amr")) {
static enum CodecID amr_audio_list[] = {
CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
CODEC_ID_NONE
};
*video_codec_list = NULL;
*audio_codec_list = amr_audio_list;
} else if (!strcmp (format_name, "gif")) {
static enum CodecID gif_image_list[] = {
CODEC_ID_RAWVIDEO, CODEC_ID_NONE
};
*video_codec_list = gif_image_list;
*audio_codec_list = NULL;
} else if ((plugin->audio_codec != CODEC_ID_NONE) ||
(plugin->video_codec != CODEC_ID_NONE)) {
tmp_vlist[0] = plugin->video_codec;
tmp_alist[0] = plugin->audio_codec;
*video_codec_list = tmp_vlist;
*audio_codec_list = tmp_alist;
} else {
GST_LOG ("Format %s not found", format_name);
return FALSE;
}
return TRUE;
}
/* Convert a GstCaps to a FFMPEG codec ID. Size et all
* are omitted, that can be queried by the user itself,
* we're not eating the GstCaps or anything
* A pointer to an allocated context is also needed for
* optional extra info
*/
enum CodecID
gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
{
enum CodecID id = CODEC_ID_NONE;
const gchar *mimetype;
const GstStructure *structure;
gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
structure = gst_caps_get_structure (caps, 0);
mimetype = gst_structure_get_name (structure);
if (!strcmp (mimetype, "video/x-raw-rgb") ||
!strcmp (mimetype, "video/x-raw-yuv")) {
id = CODEC_ID_RAWVIDEO;
video = TRUE;
} else if (!strcmp (mimetype, "audio/x-raw-int")) {
gint depth, width, endianness;
gboolean signedness;
if (gst_structure_get_int (structure, "endianness", &endianness) &&
gst_structure_get_boolean (structure, "signed", &signedness) &&
gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "depth", &depth) && depth == width) {
switch (depth) {
case 8:
if (signedness) {
id = CODEC_ID_PCM_S8;
} else {
id = CODEC_ID_PCM_U8;
}
break;
case 16:
switch (endianness) {
case G_BIG_ENDIAN:
if (signedness) {
id = CODEC_ID_PCM_S16BE;
} else {
id = CODEC_ID_PCM_U16BE;
}
break;
case G_LITTLE_ENDIAN:
if (signedness) {
id = CODEC_ID_PCM_S16LE;
} else {
id = CODEC_ID_PCM_U16LE;
}
break;
}
break;
}
if (id != CODEC_ID_NONE)
audio = TRUE;
}
} else if (!strcmp (mimetype, "audio/x-mulaw")) {
id = CODEC_ID_PCM_MULAW;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-alaw")) {
id = CODEC_ID_PCM_ALAW;
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-dv")) {
gboolean sys_strm;
if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
!sys_strm) {
id = CODEC_ID_DVVIDEO;
video = TRUE;
}
} else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
id = CODEC_ID_DVAUDIO;
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-h263")) {
const gchar *h263version =
gst_structure_get_string (structure, "h263version");
if (h263version && !strcmp (h263version, "h263p"))
id = CODEC_ID_H263P;
else
id = CODEC_ID_H263;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-intel-h263")) {
id = CODEC_ID_H263I;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-h261")) {
id = CODEC_ID_H261;
video = TRUE;
} else if (!strcmp (mimetype, "video/mpeg")) {
gboolean sys_strm;
gint mpegversion;
if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
!sys_strm) {
switch (mpegversion) {
case 1:
id = CODEC_ID_MPEG1VIDEO;
break;
case 2:
id = CODEC_ID_MPEG2VIDEO;
break;
case 4:
id = CODEC_ID_MPEG4;
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "image/jpeg")) {
id = CODEC_ID_MJPEG; /* A... B... */
video = TRUE;
} else if (!strcmp (mimetype, "video/x-jpeg-b")) {
id = CODEC_ID_MJPEGB;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-wmv")) {
gint wmvversion = 0;
if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
switch (wmvversion) {
case 1:
id = CODEC_ID_WMV1;
break;
case 2:
id = CODEC_ID_WMV2;
break;
case 3:
{
guint32 fourcc;
/* WMV3 unless the fourcc exists and says otherwise */
id = CODEC_ID_WMV3;
if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
if ((fourcc == GST_MAKE_FOURCC ('W', 'V', 'C', '1')) ||
(fourcc == GST_MAKE_FOURCC ('W', 'M', 'V', 'A'))) {
id = CODEC_ID_VC1;
}
}
}
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "audio/x-vorbis")) {
id = CODEC_ID_VORBIS;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-qdm2")) {
id = CODEC_ID_QDM2;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/mpeg")) {
gint layer = 0;
gint mpegversion = 0;
if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
switch (mpegversion) {
case 2: /* ffmpeg uses faad for both... */
case 4:
id = CODEC_ID_AAC;
break;
case 1:
if (gst_structure_get_int (structure, "layer", &layer)) {
switch (layer) {
case 1:
id = CODEC_ID_MP1;
break;
case 2:
id = CODEC_ID_MP2;
break;
case 3:
id = CODEC_ID_MP3;
break;
}
}
}
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-musepack")) {
gint streamversion = -1;
if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
if (streamversion == 7)
id = CODEC_ID_MUSEPACK7;
} else {
id = CODEC_ID_MUSEPACK7;
}
} else if (!strcmp (mimetype, "audio/x-wma")) {
gint wmaversion = 0;
if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
switch (wmaversion) {
case 1:
id = CODEC_ID_WMAV1;
break;
case 2:
id = CODEC_ID_WMAV2;
break;
case 3:
id = CODEC_ID_WMAPRO;
break;
}
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-wms")) {
id = CODEC_ID_WMAVOICE;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-ac3")) {
id = CODEC_ID_AC3;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-eac3")) {
id = CODEC_ID_EAC3;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
!strcmp (mimetype, "audio/atrac3")) {
id = CODEC_ID_ATRAC3;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-dts")) {
id = CODEC_ID_DTS;
audio = TRUE;
} else if (!strcmp (mimetype, "application/x-ape")) {
id = CODEC_ID_APE;
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-msmpeg")) {
gint msmpegversion = 0;
if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
switch (msmpegversion) {
case 41:
id = CODEC_ID_MSMPEG4V1;
break;
case 42:
id = CODEC_ID_MSMPEG4V2;
break;
case 43:
id = CODEC_ID_MSMPEG4V3;
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "video/x-svq")) {
gint svqversion = 0;
if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
switch (svqversion) {
case 1:
id = CODEC_ID_SVQ1;
break;
case 3:
id = CODEC_ID_SVQ3;
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "video/x-huffyuv")) {
id = CODEC_ID_HUFFYUV;
video = TRUE;
} else if (!strcmp (mimetype, "audio/x-mace")) {
gint maceversion = 0;
if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
switch (maceversion) {
case 3:
id = CODEC_ID_MACE3;
break;
case 6:
id = CODEC_ID_MACE6;
break;
}
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-theora")) {
id = CODEC_ID_THEORA;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp3")) {
id = CODEC_ID_VP3;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp5")) {
id = CODEC_ID_VP5;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp6")) {
id = CODEC_ID_VP6;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp6-flash")) {
id = CODEC_ID_VP6F;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
id = CODEC_ID_VP6A;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-vp8")) {
id = CODEC_ID_VP8;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-flash-screen")) {
id = CODEC_ID_FLASHSV;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-indeo")) {
gint indeoversion = 0;
if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
switch (indeoversion) {
case 5:
id = CODEC_ID_INDEO5;
break;
case 3:
id = CODEC_ID_INDEO3;
break;
case 2:
id = CODEC_ID_INDEO2;
break;
}
if (id != CODEC_ID_NONE)
video = TRUE;
}
} else if (!strcmp (mimetype, "video/x-divx")) {
gint divxversion = 0;
if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
switch (divxversion) {
case 3:
id = CODEC_ID_MSMPEG4V3;
break;
case 4:
case 5:
id = CODEC_ID_MPEG4;
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "video/x-3ivx")) {
id = CODEC_ID_MPEG4;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-xvid")) {
id = CODEC_ID_MPEG4;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-ffv")) {
gint ffvversion = 0;
if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
ffvversion == 1) {
id = CODEC_ID_FFV1;
video = TRUE;
}
} else if (!strcmp (mimetype, "audio/x-adpcm")) {
const gchar *layout;
layout = gst_structure_get_string (structure, "layout");
if (layout == NULL) {
/* break */
} else if (!strcmp (layout, "quicktime")) {
id = CODEC_ID_ADPCM_IMA_QT;
} else if (!strcmp (layout, "microsoft")) {
id = CODEC_ID_ADPCM_MS;
} else if (!strcmp (layout, "dvi")) {
id = CODEC_ID_ADPCM_IMA_WAV;
} else if (!strcmp (layout, "4xm")) {
id = CODEC_ID_ADPCM_4XM;
} else if (!strcmp (layout, "smjpeg")) {
id = CODEC_ID_ADPCM_IMA_SMJPEG;
} else if (!strcmp (layout, "dk3")) {
id = CODEC_ID_ADPCM_IMA_DK3;
} else if (!strcmp (layout, "dk4")) {
id = CODEC_ID_ADPCM_IMA_DK4;
} else if (!strcmp (layout, "westwood")) {
id = CODEC_ID_ADPCM_IMA_WS;
} else if (!strcmp (layout, "iss")) {
id = CODEC_ID_ADPCM_IMA_ISS;
} else if (!strcmp (layout, "xa")) {
id = CODEC_ID_ADPCM_XA;
} else if (!strcmp (layout, "adx")) {
id = CODEC_ID_ADPCM_ADX;
} else if (!strcmp (layout, "ea")) {
id = CODEC_ID_ADPCM_EA;
} else if (!strcmp (layout, "g726")) {
id = CODEC_ID_ADPCM_G726;
} else if (!strcmp (layout, "g721")) {
id = CODEC_ID_ADPCM_G726;
} else if (!strcmp (layout, "ct")) {
id = CODEC_ID_ADPCM_CT;
} else if (!strcmp (layout, "swf")) {
id = CODEC_ID_ADPCM_SWF;
} else if (!strcmp (layout, "yamaha")) {
id = CODEC_ID_ADPCM_YAMAHA;
} else if (!strcmp (layout, "sbpro2")) {
id = CODEC_ID_ADPCM_SBPRO_2;
} else if (!strcmp (layout, "sbpro3")) {
id = CODEC_ID_ADPCM_SBPRO_3;
} else if (!strcmp (layout, "sbpro4")) {
id = CODEC_ID_ADPCM_SBPRO_4;
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-4xm")) {
id = CODEC_ID_4XM;
video = TRUE;
} else if (!strcmp (mimetype, "audio/x-dpcm")) {
const gchar *layout;
layout = gst_structure_get_string (structure, "layout");
if (!layout) {
/* .. */
} else if (!strcmp (layout, "roq")) {
id = CODEC_ID_ROQ_DPCM;
} else if (!strcmp (layout, "interplay")) {
id = CODEC_ID_INTERPLAY_DPCM;
} else if (!strcmp (layout, "xan")) {
id = CODEC_ID_XAN_DPCM;
} else if (!strcmp (layout, "sol")) {
id = CODEC_ID_SOL_DPCM;
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-flac")) {
id = CODEC_ID_FLAC;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-shorten")) {
id = CODEC_ID_SHORTEN;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-alac")) {
id = CODEC_ID_ALAC;
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-cinepak")) {
id = CODEC_ID_CINEPAK;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
gint rmversion;
if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
switch (rmversion) {
case 1:
id = CODEC_ID_RV10;
break;
case 2:
id = CODEC_ID_RV20;
break;
case 3:
id = CODEC_ID_RV30;
break;
case 4:
id = CODEC_ID_RV40;
break;
}
}
if (id != CODEC_ID_NONE)
video = TRUE;
} else if (!strcmp (mimetype, "audio/x-sipro")) {
id = CODEC_ID_SIPR;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
gint raversion;
if (gst_structure_get_int (structure, "raversion", &raversion)) {
switch (raversion) {
case 1:
id = CODEC_ID_RA_144;
break;
case 2:
id = CODEC_ID_RA_288;
break;
case 8:
id = CODEC_ID_COOK;
break;
}
}
if (id != CODEC_ID_NONE)
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-rle")) {
const gchar *layout;
if ((layout = gst_structure_get_string (structure, "layout"))) {
if (!strcmp (layout, "microsoft")) {
id = CODEC_ID_MSRLE;
video = TRUE;
}
}
} else if (!strcmp (mimetype, "video/x-xan")) {
gint wcversion = 0;
if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
switch (wcversion) {
case 3:
id = CODEC_ID_XAN_WC3;
video = TRUE;
break;
case 4:
id = CODEC_ID_XAN_WC4;
video = TRUE;
break;
default:
break;
}
}
} else if (!strcmp (mimetype, "audio/AMR")) {
audio = TRUE;
id = CODEC_ID_AMR_NB;
} else if (!strcmp (mimetype, "audio/AMR-WB")) {
id = CODEC_ID_AMR_WB;
audio = TRUE;
} else if (!strcmp (mimetype, "audio/qcelp")) {
id = CODEC_ID_QCELP;
audio = TRUE;
} else if (!strcmp (mimetype, "video/x-h264")) {
id = CODEC_ID_H264;
video = TRUE;
} else if (!strcmp (mimetype, "video/x-flash-video")) {
gint flvversion = 0;
if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
switch (flvversion) {
case 1:
id = CODEC_ID_FLV1;
video = TRUE;
break;
default:
break;
}
}
} else if (!strcmp (mimetype, "audio/x-nellymoser")) {
id = CODEC_ID_NELLYMOSER;
audio = TRUE;
} else if (!strncmp (mimetype, "audio/x-gst_ff-", 15)) {
gchar ext[16];
AVCodec *codec;
if (strlen (mimetype) <= 30 &&
sscanf (mimetype, "audio/x-gst_ff-%s", ext) == 1) {
if ((codec = avcodec_find_decoder_by_name (ext)) ||
(codec = avcodec_find_encoder_by_name (ext))) {
id = codec->id;
audio = TRUE;
}
}
} else if (!strncmp (mimetype, "video/x-gst_ff-", 15)) {
gchar ext[16];
AVCodec *codec;
if (strlen (mimetype) <= 30 &&
sscanf (mimetype, "video/x-gst_ff-%s", ext) == 1) {
if ((codec = avcodec_find_decoder_by_name (ext)) ||
(codec = avcodec_find_encoder_by_name (ext))) {
id = codec->id;
video = TRUE;
}
}
}
if (context != NULL) {
if (video == TRUE) {
context->codec_type = AVMEDIA_TYPE_VIDEO;
} else if (audio == TRUE) {
context->codec_type = AVMEDIA_TYPE_AUDIO;
} else {
context->codec_type = AVMEDIA_TYPE_UNKNOWN;
}
context->codec_id = id;
gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
}
if (id != CODEC_ID_NONE) {
GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
} else {
GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);
}
return id;
}
|