summaryrefslogtreecommitdiffstats
path: root/src/librtmp-1-v2.4.patch
blob: d02921189ca644af460ee7f6cce8794d0693c028 (plain)
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
From 272a91d06d71c2a326996f62797ed9ab42f69859 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Wed, 30 Jun 2010 22:34:59 +0000
Subject: [PATCH 01/34] zlib dependency is only when CRYPTO is enabled

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@536 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile          |    9 +++++----
 librtmp/hashswf.c |    4 ++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 7470eb4..c7767b4 100644
--- a/Makefile
+++ b/Makefile
@@ -11,9 +11,10 @@ SYS=posix
 CRYPTO=OPENSSL
 #CRYPTO=POLARSSL
 #CRYPTO=GNUTLS
-LIB_GNUTLS=-lgnutls -lgcrypt
-LIB_OPENSSL=-lssl -lcrypto
-LIB_POLARSSL=-lpolarssl
+LIBZ=-lz
+LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ)
+LIB_OPENSSL=-lssl -lcrypto$ (LIBZ)
+LIB_POLARSSL=-lpolarssl $(LIBZ)
 CRYPTO_LIB=$(LIB_$(CRYPTO))
 DEF_=-DNO_CRYPTO
 CRYPTO_DEF=$(DEF_$(CRYPTO))
@@ -33,7 +34,7 @@ MANDIR=$(DESTDIR)$(mandir)
 
 LIBS_posix=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
-LIBS=$(CRYPTO_LIB) -lz $(LIBS_$(SYS)) $(XLIBS)
+LIBS=$(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
 
 THREADLIB_posix=-lpthread
 THREADLIB_mingw=
diff --git a/librtmp/hashswf.c b/librtmp/hashswf.c
index 06d2bbb..277f21c 100644
--- a/librtmp/hashswf.c
+++ b/librtmp/hashswf.c
@@ -66,10 +66,10 @@
 extern void RTMP_TLS_Init();
 extern TLS_CTX RTMP_TLS_ctx;
 
-#endif /* CRYPTO */
-
 #include <zlib.h>
 
+#endif /* CRYPTO */
+
 #define	AGENT	"Mozilla/5.0"
 
 HTTPResult
-- 
1.7.10.4


From 6556b9f9328acb1199dc1cc3f22fa82c86b51c8a Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 1 Jul 2010 12:00:43 +0000
Subject: [PATCH 02/34] Fix typo

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@537 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c7767b4..1fcdd78 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ CRYPTO=OPENSSL
 #CRYPTO=GNUTLS
 LIBZ=-lz
 LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ)
-LIB_OPENSSL=-lssl -lcrypto$ (LIBZ)
+LIB_OPENSSL=-lssl -lcrypto $(LIBZ)
 LIB_POLARSSL=-lpolarssl $(LIBZ)
 CRYPTO_LIB=$(LIB_$(CRYPTO))
 DEF_=-DNO_CRYPTO
-- 
1.7.10.4


From 8a5901c8a74280c898deb4ebf1a2f5d6f68bce42 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Sat, 3 Jul 2010 10:25:48 +0000
Subject: [PATCH 03/34] Document the escape coding used for special characters
 in values

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@538 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/librtmp.3 |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/librtmp/librtmp.3 b/librtmp/librtmp.3
index 055b52b..a5a7558 100644
--- a/librtmp/librtmp.3
+++ b/librtmp/librtmp.3
@@ -57,14 +57,19 @@ The session handle is freed using
 .BR RTMP_Free ().
 
 All data is transferred using FLV format. The basic session requires
-an RTMP URL. Additional options may be specified by appending
-space-separated key=value pairs to the URL. The RTMP URL format
-is of the form
+an RTMP URL.  The RTMP URL format is of the form
 .nf
   rtmp[t][e|s]://hostname[:port][/app[/playpath]]
 .fi
 
 Plain rtmp, as well as tunneled and encrypted sessions are supported.
+
+Additional options may be specified by appending space-separated
+key=value pairs to the URL. Special characters in values may need
+to be escaped to prevent misinterpretation by the option parser.
+The escape encoding uses a backslash followed by two hexadecimal digits
+representing the ASCII value of the character. E.g., spaces must
+be escaped as \fB\\20\fP and backslashes must be escaped as \fB\\5c\fP.
 .SH OPTIONS
 .SS "Network Parameters"
 These options define how to connect to the media server.
-- 
1.7.10.4


From c41568f57bec297581e8508a7e6a3d1e470dc81d Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Sat, 3 Jul 2010 10:28:57 +0000
Subject: [PATCH 04/34] Update from prev commit

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@539 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/librtmp.3      |    2 +-
 librtmp/librtmp.3.html |   13 +++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/librtmp/librtmp.3 b/librtmp/librtmp.3
index a5a7558..66197d5 100644
--- a/librtmp/librtmp.3
+++ b/librtmp/librtmp.3
@@ -1,4 +1,4 @@
-.TH LIBRTMP 3 "2010-05-29" "RTMPDump v2.2e"
+.TH LIBRTMP 3 "2010-07-03" "RTMPDump v2.3"
 .\" Copyright 2010 Howard Chu.
 .\" Copying permitted according to the GNU General Public License V2.
 .SH NAME
diff --git a/librtmp/librtmp.3.html b/librtmp/librtmp.3.html
index daf636f..e5e6f4b 100644
--- a/librtmp/librtmp.3.html
+++ b/librtmp/librtmp.3.html
@@ -6,7 +6,7 @@
 <tr><td>LIBRTMP(3)<td align="center"><td align="right">LIBRTMP(3)
 </thead>
 <tfoot>
-<tr><td>RTMPDump v2.2e<td align="center">2010-05-29<td align="right">LIBRTMP(3)
+<tr><td>RTMPDump v2.3<td align="center">2010-07-03<td align="right">LIBRTMP(3)
 </tfoot>
 <tbody><tr><td colspan="3"><br><br><ul>
 <!-- Copyright 2010 Howard Chu.
@@ -75,14 +75,19 @@ The session handle is freed using
 <b>RTMP_Free</b>().
 <p>
 All data is transferred using FLV format. The basic session requires
-an RTMP URL. Additional options may be specified by appending
-space-separated key=value pairs to the URL. The RTMP URL format
-is of the form
+an RTMP URL.  The RTMP URL format is of the form
 <pre>
   rtmp[t][e|s]://hostname[:port][/app[/playpath]]
 </pre>
 <p>
 Plain rtmp, as well as tunneled and encrypted sessions are supported.
+<p>
+Additional options may be specified by appending space-separated
+key=value pairs to the URL. Special characters in values may need
+to be escaped to prevent misinterpretation by the option parser.
+The escape encoding uses a backslash followed by two hexadecimal digits
+representing the ASCII value of the character. E.g., spaces must
+be escaped as <b>\20</b> and backslashes must be escaped as <b>\5c</b>.
 </ul>
 
 <h3>OPTIONS</h3><ul>
-- 
1.7.10.4


From f1c4f0ed07659cbeae4ffaa78ca8cce7500afa58 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 5 Jul 2010 20:07:39 +0000
Subject: [PATCH 05/34] Hide strtime()

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@541 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/hashswf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/librtmp/hashswf.c b/librtmp/hashswf.c
index 277f21c..23e754b 100644
--- a/librtmp/hashswf.c
+++ b/librtmp/hashswf.c
@@ -435,7 +435,7 @@ make_unix_time(char *s)
 /* Convert a Unix time to a network time string
  * Weekday, DD-MMM-YYYY HH:MM:SS GMT
  */
-void
+static void
 strtime(time_t * t, char *s)
 {
   struct tm *tm;
-- 
1.7.10.4


From da78eba764eda23fb3bf9aa91bd6c5fee1839932 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 5 Jul 2010 20:16:55 +0000
Subject: [PATCH 06/34] Remove obsolete XBOX defs

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@542 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp_sys.h |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/librtmp/rtmp_sys.h b/librtmp/rtmp_sys.h
index 0874cbe..6a3f215 100644
--- a/librtmp/rtmp_sys.h
+++ b/librtmp/rtmp_sys.h
@@ -24,17 +24,14 @@
 
 #ifdef _WIN32
 
-#ifdef _XBOX
-#include <xtl.h>
-#include <winsockx.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+
+#ifdef _MSC_VER	/* MSVC */
 #define snprintf _snprintf
 #define strcasecmp stricmp
 #define strncasecmp strnicmp
 #define vsnprintf _vsnprintf
-
-#else /* !_XBOX */
-#include <winsock2.h>
-#include <ws2tcpip.h>
 #endif
 
 #define GetSockError()	WSAGetLastError()
-- 
1.7.10.4


From eef87483b92036a1631c98c9c85dc3cae66411ee Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 5 Jul 2010 20:17:16 +0000
Subject: [PATCH 07/34] Update XBOX/XBMC support

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@543 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/hashswf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/librtmp/hashswf.c b/librtmp/hashswf.c
index 23e754b..3c56b69 100644
--- a/librtmp/hashswf.c
+++ b/librtmp/hashswf.c
@@ -466,7 +466,7 @@ RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
 
   date[0] = '\0';
 #ifdef _WIN32
-#ifdef _XBOX
+#ifdef XBMC4XBOX
   hpre.av_val = "Q:";
   hpre.av_len = 2;
   home.av_val = "\\UserData";
-- 
1.7.10.4


From 24f7e724fc10d737a0f14c7741711b6b542c9d45 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 8 Jul 2010 10:38:33 +0000
Subject: [PATCH 08/34] Don't link explicitly against static library

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@544 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 1fcdd78..741e438 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ MANDIR=$(DESTDIR)$(mandir)
 
 LIBS_posix=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
-LIBS=$(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
+LIBS=-L librtmp -lrtmp $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
 
 THREADLIB_posix=-lpthread
 THREADLIB_mingw=
@@ -48,9 +48,11 @@ EXT_posix=
 EXT_mingw=.exe
 EXT=$(EXT_$(SYS))
 
-all:	$(LIBRTMP) progs
+PROGS=rtmpdump rtmpgw rtmpsrv rtmpsuck
 
-progs:	rtmpdump rtmpgw rtmpsrv rtmpsuck
+all:	$(LIBRTMP) $(PROGS)
+
+$(PROGS): $(LIBRTMP)
 
 install:	progs
 	-mkdir -p $(BINDIR) $(SBINDIR) $(MANDIR)/man1 $(MANDIR)/man8
@@ -69,20 +71,17 @@ FORCE:
 $(LIBRTMP): FORCE
 	@cd librtmp; $(MAKE) all
 
-# note: $^ is GNU Make's equivalent to BSD $>
-# we use both since either make will ignore the one it doesn't recognize
-
-rtmpdump: rtmpdump.o $(LIBRTMP)
-	$(CC) $(LDFLAGS) $^ $> -o $@$(EXT) $(LIBS)
+rtmpdump: rtmpdump.o
+	$(CC) $(LDFLAGS) -o $@$(EXT) $@.o $(LIBS)
 
-rtmpsrv: rtmpsrv.o thread.o $(LIBRTMP)
-	$(CC) $(LDFLAGS) $^ $> -o $@$(EXT) $(SLIBS)
+rtmpsrv: rtmpsrv.o thread.o
+	$(CC) $(LDFLAGS) -o $@$(EXT) $@.o thread.o $(SLIBS)
 
-rtmpsuck: rtmpsuck.o thread.o $(LIBRTMP)
-	$(CC) $(LDFLAGS) $^ $> -o $@$(EXT) $(SLIBS)
+rtmpsuck: rtmpsuck.o thread.o
+	$(CC) $(LDFLAGS) -o $@$(EXT) $@.o thread.o $(SLIBS)
 
-rtmpgw: rtmpgw.o thread.o $(LIBRTMP)
-	$(CC) $(LDFLAGS) $^ $> -o $@$(EXT) $(SLIBS)
+rtmpgw: rtmpgw.o thread.o
+	$(CC) $(LDFLAGS) -o $@$(EXT) $@.o thread.o $(SLIBS)
 
 rtmpgw.o: rtmpgw.c $(INCRTMP) Makefile
 rtmpdump.o: rtmpdump.c $(INCRTMP) Makefile
-- 
1.7.10.4


From 5a3d6003a9745595583015c5b3b24e7bea818790 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 8 Jul 2010 11:11:47 +0000
Subject: [PATCH 09/34] Fix install target

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@545 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 741e438..75628dd 100644
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ all:	$(LIBRTMP) $(PROGS)
 
 $(PROGS): $(LIBRTMP)
 
-install:	progs
+install:	$(PROGS)
 	-mkdir -p $(BINDIR) $(SBINDIR) $(MANDIR)/man1 $(MANDIR)/man8
 	cp rtmpdump$(EXT) $(BINDIR)
 	cp rtmpgw$(EXT) rtmpsrv$(EXT) rtmpsuck$(EXT) $(SBINDIR)
-- 
1.7.10.4


From 2340f0e27cd21d624d5f915fc42182750be6fca6 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 12 Jul 2010 08:20:04 +0000
Subject: [PATCH 10/34] MacOSX/Darwin shared library flags

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@546 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile         |    3 +++
 README           |    6 +++++-
 librtmp/Makefile |   11 ++++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 75628dd..fda3c74 100644
--- a/Makefile
+++ b/Makefile
@@ -33,10 +33,12 @@ SBINDIR=$(DESTDIR)$(sbindir)
 MANDIR=$(DESTDIR)$(mandir)
 
 LIBS_posix=
+LIBS_darwin=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
 LIBS=-L librtmp -lrtmp $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
 
 THREADLIB_posix=-lpthread
+THREADLIB_darwin=-lpthread
 THREADLIB_mingw=
 THREADLIB=$(THREADLIB_$(SYS))
 SLIBS=$(THREADLIB) $(LIBS)
@@ -45,6 +47,7 @@ LIBRTMP=librtmp/librtmp.a
 INCRTMP=librtmp/rtmp_sys.h librtmp/rtmp.h librtmp/log.h librtmp/amf.h
 
 EXT_posix=
+EXT_darwin=
 EXT_mingw=.exe
 EXT=$(EXT_$(SYS))
 
diff --git a/README b/README
index 6607a1d..5689853 100644
--- a/README
+++ b/README
@@ -10,7 +10,11 @@ To compile type "make" with SYS=<platform name>, e.g.
 
   $ make SYS=posix
 
-for Linux, MacOSX, Unix, etc. or
+for Linux, Unix, etc. or
+
+  $ make SYS=darwin
+
+for MacOSX or
 
   $ make SYS=mingw
 
diff --git a/librtmp/Makefile b/librtmp/Makefile
index 6774db7..2fd5869 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -17,6 +17,7 @@ REQ_GNUTLS=gnutls
 REQ_OPENSSL=libssl,libcrypto
 LIBZ=-lz
 LIBS_posix=
+LIBS_darwin=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
 LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ)
 LIB_OPENSSL=-lssl -lcrypto $(LIBZ)
@@ -26,9 +27,16 @@ CRYPTO_REQ=$(REQ_$(CRYPTO))
 CRYPTO_DEF=$(DEF_$(CRYPTO))
 
 SO_posix=so.0
+SO_darwin=so.0
 SO_mingw=dll
 SO_EXT=$(SO_$(SYS))
 
+SO_LDFLAGS_posix=-shared -Wl,-soname,$@
+SO_LDFLAGS_darwin=-bundle -flat_namespace -undefined suppress -fno-common \
+	-headerpad_max_install_names
+SO_LDFLAGS_mingw=
+SO_LDFLAGS=$(SO_LDFLAGS_$(SYS))
+
 SHARED=yes
 SODEF_yes=-fPIC
 SOLIB_yes=librtmp.$(SO_EXT)
@@ -40,6 +48,7 @@ SO_INST=$(SOINST_$(SHARED))
 DEF=-DRTMPDUMP_VERSION=\"$(VERSION)\" $(CRYPTO_DEF) $(XDEF)
 OPT=-O2
 CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
+LDFLAGS=$(XLDFLAGS)
 
 incdir=$(prefix)/include/librtmp
 bindir=$(prefix)/bin
@@ -61,7 +70,7 @@ librtmp.a: $(OBJS)
 	$(AR) rs $@ $?
 
 librtmp.$(SO_EXT): $(OBJS)
-	$(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $^ $> $(CRYPTO_LIB)
+	$(CC) $(SO_LDFLAGS) $(LDFLAGS) -o $@ $^ $> $(CRYPTO_LIB)
 	ln -sf $@ librtmp.so
 
 log.o: log.c log.h Makefile
-- 
1.7.10.4


From 13798268e10fc8c56eecf5fce297375f7fca1526 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 9 Aug 2010 21:46:31 +0000
Subject: [PATCH 11/34] Fixes for Darwin - use dylib, not bundle for shared
 lib

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@547 400ebc74-4327-4243-bc38-086b20814532
---
 Makefile         |    2 +-
 librtmp/Makefile |   17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index fda3c74..c322e9a 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ MANDIR=$(DESTDIR)$(mandir)
 LIBS_posix=
 LIBS_darwin=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
-LIBS=-L librtmp -lrtmp $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
+LIBS=-Llibrtmp -lrtmp $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
 
 THREADLIB_posix=-lpthread
 THREADLIB_darwin=-lpthread
diff --git a/librtmp/Makefile b/librtmp/Makefile
index 2fd5869..a4bf67e 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -26,13 +26,14 @@ CRYPTO_LIB=$(LIB_$(CRYPTO)) $(LIBS_$(SYS))
 CRYPTO_REQ=$(REQ_$(CRYPTO))
 CRYPTO_DEF=$(DEF_$(CRYPTO))
 
-SO_posix=so.0
-SO_darwin=so.0
+SO_VERSION=0
+SO_posix=so.$(SO_VERSION)
+SO_darwin=$(SO_VERSION).dylib
 SO_mingw=dll
 SO_EXT=$(SO_$(SYS))
 
 SO_LDFLAGS_posix=-shared -Wl,-soname,$@
-SO_LDFLAGS_darwin=-bundle -flat_namespace -undefined suppress -fno-common \
+SO_LDFLAGS_darwin=-dynamiclib -flat_namespace -undefined suppress -fno-common \
 	-headerpad_max_install_names
 SO_LDFLAGS_mingw=
 SO_LDFLAGS=$(SO_LDFLAGS_$(SYS))
@@ -92,9 +93,13 @@ install_base:	librtmp.a librtmp.pc
 	cp librtmp.pc $(LIBDIR)/pkgconfig
 	cp librtmp.3 $(MANDIR)/man3
 
-install_so.0:	librtmp.so.0
-	cp librtmp.so.0 $(LIBDIR)
-	cd $(LIBDIR); ln -sf librtmp.so.0 librtmp.so
+install_so.$(SO_VERSION):	librtmp.$(SO_EXT)
+	cp librtmp.$(SO_EXT) $(LIBDIR)
+	cd $(LIBDIR); ln -sf librtmp.$(SO_EXT) librtmp.so
+
+install_$(SO_VERSION).dylib:	librtmp.$(SO_EXT)
+	cp librtmp.$(SO_EXT) $(LIBDIR)
+	cd $(LIBDIR); ln -sf librtmp.$(SO_EXT) librtmp.dylib
 
 install_dll:	librtmp.dll
 	cp librtmp.dll $(BINDIR)
-- 
1.7.10.4


From eb806247dc8eab25d8a675a4f633d3feaf2b2045 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Tue, 10 Aug 2010 06:41:50 +0000
Subject: [PATCH 12/34] More dynlib tweaks

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@548 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/Makefile |   48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/librtmp/Makefile b/librtmp/Makefile
index a4bf67e..6a1b08b 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -2,6 +2,15 @@ VERSION=v2.3
 
 prefix=/usr/local
 
+incdir=$(prefix)/include/librtmp
+bindir=$(prefix)/bin
+libdir=$(prefix)/lib
+mandir=$(prefix)/man
+BINDIR=$(DESTDIR)$(bindir)
+INCDIR=$(DESTDIR)$(incdir)
+LIBDIR=$(DESTDIR)$(libdir)
+MANDIR=$(DESTDIR)$(mandir)
+
 CC=$(CROSS_COMPILE)gcc
 LD=$(CROSS_COMPILE)ld
 AR=$(CROSS_COMPILE)ar
@@ -27,11 +36,20 @@ CRYPTO_REQ=$(REQ_$(CRYPTO))
 CRYPTO_DEF=$(DEF_$(CRYPTO))
 
 SO_VERSION=0
-SO_posix=so.$(SO_VERSION)
-SO_darwin=$(SO_VERSION).dylib
+SOX_posix=so
+SOX_darwin=dylib
+SOX_mingw=so	# useless
+SOX=$(SOX_$(SYS))
+SO_posix=$(SOX).$(SO_VERSION)
+SO_darwin=$(SO_VERSION).$(SOX)
 SO_mingw=dll
 SO_EXT=$(SO_$(SYS))
 
+SODIR_posix=$(LIBDIR)
+SODIR_darwin=$(LIBDIR)
+SODIR_mingw=$(BINDIR)
+SODIR=$(SODIR_$(SYS))
+
 SO_LDFLAGS_posix=-shared -Wl,-soname,$@
 SO_LDFLAGS_darwin=-dynamiclib -flat_namespace -undefined suppress -fno-common \
 	-headerpad_max_install_names
@@ -41,7 +59,7 @@ SO_LDFLAGS=$(SO_LDFLAGS_$(SYS))
 SHARED=yes
 SODEF_yes=-fPIC
 SOLIB_yes=librtmp.$(SO_EXT)
-SOINST_yes=install_$(SO_EXT)
+SOINST_yes=install_so
 SO_DEF=$(SODEF_$(SHARED))
 SO_LIB=$(SOLIB_$(SHARED))
 SO_INST=$(SOINST_$(SHARED))
@@ -51,28 +69,20 @@ OPT=-O2
 CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
 LDFLAGS=$(XLDFLAGS)
 
-incdir=$(prefix)/include/librtmp
-bindir=$(prefix)/bin
-libdir=$(prefix)/lib
-mandir=$(prefix)/man
-BINDIR=$(DESTDIR)$(bindir)
-INCDIR=$(DESTDIR)$(incdir)
-LIBDIR=$(DESTDIR)$(libdir)
-MANDIR=$(DESTDIR)$(mandir)
 
 OBJS=rtmp.o log.o amf.o hashswf.o parseurl.o
 
 all:	librtmp.a $(SO_LIB)
 
 clean:
-	rm -f *.o *.a *.so *.$(SO_EXT)
+	rm -f *.o *.a *.$(SOX) *.$(SO_EXT)
 
 librtmp.a: $(OBJS)
 	$(AR) rs $@ $?
 
 librtmp.$(SO_EXT): $(OBJS)
 	$(CC) $(SO_LDFLAGS) $(LDFLAGS) -o $@ $^ $> $(CRYPTO_LIB)
-	ln -sf $@ librtmp.so
+	ln -sf $@ librtmp.$(SOX)
 
 log.o: log.c log.h Makefile
 rtmp.o: rtmp.c rtmp.h rtmp_sys.h handshake.h dh.h log.h amf.h Makefile
@@ -93,13 +103,7 @@ install_base:	librtmp.a librtmp.pc
 	cp librtmp.pc $(LIBDIR)/pkgconfig
 	cp librtmp.3 $(MANDIR)/man3
 
-install_so.$(SO_VERSION):	librtmp.$(SO_EXT)
-	cp librtmp.$(SO_EXT) $(LIBDIR)
-	cd $(LIBDIR); ln -sf librtmp.$(SO_EXT) librtmp.so
-
-install_$(SO_VERSION).dylib:	librtmp.$(SO_EXT)
-	cp librtmp.$(SO_EXT) $(LIBDIR)
-	cd $(LIBDIR); ln -sf librtmp.$(SO_EXT) librtmp.dylib
+install_so:	librtmp.$(SO_EXT)
+	cp librtmp.$(SO_EXT) $(SODIR)
+	cd $(SODIR); ln -sf librtmp.$(SO_EXT) librtmp.$(SOX)
 
-install_dll:	librtmp.dll
-	cp librtmp.dll $(BINDIR)
-- 
1.7.10.4


From 08bdebed5423602d195fa981b3f2663e62820677 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Fri, 13 Aug 2010 20:05:35 +0000
Subject: [PATCH 13/34] Substitute libdir in pkgconfig file

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@549 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/Makefile      |    3 ++-
 librtmp/librtmp.pc.in |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/librtmp/Makefile b/librtmp/Makefile
index 6a1b08b..7cba62a 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -91,7 +91,8 @@ hashswf.o: hashswf.c http.h rtmp.h rtmp_sys.h Makefile
 parseurl.o: parseurl.c rtmp.h rtmp_sys.h log.h Makefile
 
 librtmp.pc: librtmp.pc.in Makefile
-	sed -e "s;@prefix@;$(prefix);" -e "s;@VERSION@;$(VERSION);" \
+	sed -e "s;@prefix@;$(prefix);" -e "s;@libdir@;$(libdir);" \
+		-e "s;@VERSION@;$(VERSION);" \
 		-e "s;@CRYPTO_REQ@;$(CRYPTO_REQ);" librtmp.pc.in > $@
 
 install:	install_base $(SO_INST)
diff --git a/librtmp/librtmp.pc.in b/librtmp/librtmp.pc.in
index d58e269..70bd268 100644
--- a/librtmp/librtmp.pc.in
+++ b/librtmp/librtmp.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
+libdir=@libdir@
 incdir=${prefix}/include
 
 Name: librtmp
-- 
1.7.10.4


From 59ca19036ed45667b08d98f09e4d4a7a727b77b3 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Fri, 13 Aug 2010 20:34:58 +0000
Subject: [PATCH 14/34] Less case-sensitive check for Content-length: header

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@550 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index f152648..5c678fd 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -3664,11 +3664,15 @@ HTTP_read(RTMP *r, int fill)
     return -1;
   if (strncmp(r->m_sb.sb_start, "HTTP/1.1 200 ", 13))
     return -1;
-  ptr = strstr(r->m_sb.sb_start, "Content-Length:");
+  ptr = r->m_sb.sb_start + sizeof("HTTP/1.1 200");
+  while ((ptr = strstr(ptr, "Content-"))) {
+    if (!strncasecmp(ptr+8, "length:", 7)) break;
+    ptr += 8;
+  }
   if (!ptr)
     return -1;
   hlen = atoi(ptr+16);
-  ptr = strstr(ptr, "\r\n\r\n");
+  ptr = strstr(ptr+16, "\r\n\r\n");
   if (!ptr)
     return -1;
   ptr += 4;
-- 
1.7.10.4


From 8afb3681407a0a83dcb1fec449b83854da440738 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Fri, 8 Oct 2010 07:45:54 +0000
Subject: [PATCH 15/34] Log error message for unsupported SWF Verification
 types

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@551 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 5c678fd..3e4e00a 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -2789,11 +2789,17 @@ HandleCtrl(RTMP *r, const RTMPPacket *packet)
   if (nType == 0x1A)
     {
       RTMP_Log(RTMP_LOGDEBUG, "%s, SWFVerification ping received: ", __FUNCTION__);
+      if (packet->m_nBodySize > 2 && packet->m_body[2] > 0x01)
+	{
+	  RTMP_Log(RTMP_LOGERROR,
+            "%s: SWFVerification Type %d request not supported! Patches welcome...",
+	    __FUNCTION__, packet->m_body[2]);
+	}
 #ifdef CRYPTO
       /*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */
 
       /* respond with HMAC SHA256 of decompressed SWF, key is the 30byte player key, also the last 30 bytes of the server handshake are applied */
-      if (r->Link.SWFSize)
+      else if (r->Link.SWFSize)
 	{
 	  RTMP_SendCtrl(r, 0x1B, 0, 0);
 	}
-- 
1.7.10.4


From 9ca7e22d94c6e07e8ef05acbf636809a5914f50c Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Tue, 26 Oct 2010 23:51:10 +0000
Subject: [PATCH 16/34] Timeout fix from Antti Ajanki

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@552 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    3 +++
 rtmpdump.c     |    2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 3e4e00a..db882dc 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -1019,6 +1019,9 @@ RTMP_ToggleStream(RTMP *r)
 
   if (!r->m_pausing)
     {
+      if (RTMP_IsTimedout(r) && r->m_read.status == RTMP_READ_EOF)
+        r->m_read.status = 0;
+
       res = RTMP_SendPause(r, TRUE, r->m_pauseStamp);
       if (!res)
 	return res;
diff --git a/rtmpdump.c b/rtmpdump.c
index 7aa19ab..c1cd95b 100644
--- a/rtmpdump.c
+++ b/rtmpdump.c
@@ -583,7 +583,7 @@ Download(RTMP * rtmp,		// connected RTMP object
 #endif
 
     }
-  while (!RTMP_ctrlC && nRead > -1 && RTMP_IsConnected(rtmp));
+  while (!RTMP_ctrlC && nRead > -1 && RTMP_IsConnected(rtmp) && !RTMP_IsTimedout(rtmp));
   free(buffer);
   if (nRead < 0)
     nRead = rtmp->m_read.status;
-- 
1.7.10.4


From 1379a2c0d22f238d97970a7e7420287a9bd794de Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Fri, 24 Dec 2010 22:35:35 +0000
Subject: [PATCH 17/34] Fix infinite loop on Error/Close

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@554 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index db882dc..e6e8ed8 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -3395,10 +3395,10 @@ RTMP_Close(RTMP *r)
     {
       if (r->m_stream_id > 0)
         {
-          if ((r->Link.protocol & RTMP_FEATURE_WRITE))
-	    SendFCUnpublish(r);
 	  i = r->m_stream_id;
 	  r->m_stream_id = 0;
+          if ((r->Link.protocol & RTMP_FEATURE_WRITE))
+	    SendFCUnpublish(r);
 	  SendDeleteStream(r, i);
 	}
       if (r->m_clientID.av_val)
-- 
1.7.10.4


From 8c713f4c5c8e72369b48d15772e19d1c9ebd5a19 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Fri, 25 Feb 2011 05:51:40 +0000
Subject: [PATCH 18/34] Fix FLV timestamps during resume

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@557 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index e6e8ed8..e2925a7 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -4083,7 +4083,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	  /* grab first timestamp and see if it needs fixing */
 	  nTimeStamp = AMF_DecodeInt24(packetBody + 4);
 	  nTimeStamp |= (packetBody[7] << 24);
-	  delta = packet.m_nTimeStamp - nTimeStamp;
+	  delta = packet.m_nTimeStamp - nTimeStamp + r->m_read.nResumeTS;
 
 	  while (pos + 11 < nPacketLen)
 	    {
-- 
1.7.10.4


From bca1ef01727cac659f7ac171c791490efe4e48d6 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 10 Mar 2011 14:30:06 +0000
Subject: [PATCH 19/34] Add Libs.private to pkgconfig for Windows

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@558 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/Makefile      |    6 ++++--
 librtmp/librtmp.pc.in |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/librtmp/Makefile b/librtmp/Makefile
index 7cba62a..87618af 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -31,7 +31,8 @@ LIBS_mingw=-lws2_32 -lwinmm -lgdi32
 LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ)
 LIB_OPENSSL=-lssl -lcrypto $(LIBZ)
 LIB_POLARSSL=-lpolarssl $(LIBZ)
-CRYPTO_LIB=$(LIB_$(CRYPTO)) $(LIBS_$(SYS))
+PRIVATE_LIBS=$(LIBS_$(SYS))
+CRYPTO_LIB=$(LIB_$(CRYPTO)) $(PRIVATE_LIBS)
 CRYPTO_REQ=$(REQ_$(CRYPTO))
 CRYPTO_DEF=$(DEF_$(CRYPTO))
 
@@ -93,7 +94,8 @@ parseurl.o: parseurl.c rtmp.h rtmp_sys.h log.h Makefile
 librtmp.pc: librtmp.pc.in Makefile
 	sed -e "s;@prefix@;$(prefix);" -e "s;@libdir@;$(libdir);" \
 		-e "s;@VERSION@;$(VERSION);" \
-		-e "s;@CRYPTO_REQ@;$(CRYPTO_REQ);" librtmp.pc.in > $@
+		-e "s;@CRYPTO_REQ@;$(CRYPTO_REQ);" \
+		-e "s;@PRIVATE_LIBS@;$(PRIVATE_LIBS));" librtmp.pc.in > $@
 
 install:	install_base $(SO_INST)
 
diff --git a/librtmp/librtmp.pc.in b/librtmp/librtmp.pc.in
index 70bd268..5933ca1 100644
--- a/librtmp/librtmp.pc.in
+++ b/librtmp/librtmp.pc.in
@@ -9,4 +9,5 @@ Version: @VERSION@
 Requires: @CRYPTO_REQ@
 URL: http://rtmpdump.mplayerhq.hu
 Libs: -L${libdir} -lrtmp -lz
+Libs.private; @PRIVATE_LIBS@
 Cflags: -I${incdir}
-- 
1.7.10.4


From 25447a0f675cc6e9eefc8eb420ad3a2725be8ab1 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 10 Mar 2011 14:33:32 +0000
Subject: [PATCH 20/34] Fix typos in prev commit

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@559 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/Makefile      |    2 +-
 librtmp/librtmp.pc.in |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/librtmp/Makefile b/librtmp/Makefile
index 87618af..1ea31a0 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -95,7 +95,7 @@ librtmp.pc: librtmp.pc.in Makefile
 	sed -e "s;@prefix@;$(prefix);" -e "s;@libdir@;$(libdir);" \
 		-e "s;@VERSION@;$(VERSION);" \
 		-e "s;@CRYPTO_REQ@;$(CRYPTO_REQ);" \
-		-e "s;@PRIVATE_LIBS@;$(PRIVATE_LIBS));" librtmp.pc.in > $@
+		-e "s;@PRIVATE_LIBS@;$(PRIVATE_LIBS);" librtmp.pc.in > $@
 
 install:	install_base $(SO_INST)
 
diff --git a/librtmp/librtmp.pc.in b/librtmp/librtmp.pc.in
index 5933ca1..a82beca 100644
--- a/librtmp/librtmp.pc.in
+++ b/librtmp/librtmp.pc.in
@@ -9,5 +9,5 @@ Version: @VERSION@
 Requires: @CRYPTO_REQ@
 URL: http://rtmpdump.mplayerhq.hu
 Libs: -L${libdir} -lrtmp -lz
-Libs.private; @PRIVATE_LIBS@
+Libs.private: @PRIVATE_LIBS@
 Cflags: -I${incdir}
-- 
1.7.10.4


From 0a219ffeeb0094111fd00c509fce3ddd6eba2de2 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Mon, 14 Mar 2011 06:48:09 +0000
Subject: [PATCH 21/34] Bump up play command buffer sizes

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@560 400ebc74-4327-4243-bc38-086b20814532
---
 rtmpsrv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rtmpsrv.c b/rtmpsrv.c
index f2af85b..4d5699f 100644
--- a/rtmpsrv.c
+++ b/rtmpsrv.c
@@ -266,7 +266,7 @@ static int
 SendPlayStart(RTMP *r)
 {
   RTMPPacket packet;
-  char pbuf[384], *pend = pbuf+sizeof(pbuf);
+  char pbuf[512], *pend = pbuf+sizeof(pbuf);
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
@@ -298,7 +298,7 @@ static int
 SendPlayStop(RTMP *r)
 {
   RTMPPacket packet;
-  char pbuf[384], *pend = pbuf+sizeof(pbuf);
+  char pbuf[512], *pend = pbuf+sizeof(pbuf);
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
-- 
1.7.10.4


From a1bcab1da064cca8a534d26970333220b57a72f0 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Wed, 16 Mar 2011 12:11:21 +0000
Subject: [PATCH 22/34] Fix rtmpt read hangs

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@561 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index e2925a7..3042c7f 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -877,7 +877,13 @@ RTMP_Connect1(RTMP *r, RTMPPacket *cp)
       r->m_clientID.av_val = NULL;
       r->m_clientID.av_len = 0;
       HTTP_Post(r, RTMPT_OPEN, "", 1);
-      HTTP_read(r, 1);
+      if (HTTP_read(r, 1) != 0)
+	{
+	  r->m_msgCounter = 0;
+	  RTMP_Log(RTMP_LOGDEBUG, "%s, Could not connect for handshake", __FUNCTION__);
+	  RTMP_Close(r);
+	  return 0;
+	}
       r->m_msgCounter = 0;
     }
   RTMP_Log(RTMP_LOGDEBUG, "%s, ... connected, handshaking", __FUNCTION__);
@@ -1284,7 +1290,12 @@ ReadN(RTMP *r, char *buffer, int n)
 		      return 0;
 		    }
 		}
-	      HTTP_read(r, 0);
+	      if (HTTP_read(r, 0) == -1)
+		{
+		  RTMP_Log(RTMP_LOGDEBUG, "%s, No valid HTTP response found", __FUNCTION__);
+		  RTMP_Close(r);
+		  return 0;
+		}
 	    }
 	  if (r->m_resplen && !r->m_sb.sb_size)
 	    RTMPSockBuf_Fill(&r->m_sb);
@@ -3670,7 +3681,7 @@ HTTP_read(RTMP *r, int fill)
   if (fill)
     RTMPSockBuf_Fill(&r->m_sb);
   if (r->m_sb.sb_size < 144)
-    return -1;
+    return -2;
   if (strncmp(r->m_sb.sb_start, "HTTP/1.1 200 ", 13))
     return -1;
   ptr = r->m_sb.sb_start + sizeof("HTTP/1.1 200");
-- 
1.7.10.4


From aa2825fbb1d1f70652d558a730baed28149ebbdd Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Sat, 19 Mar 2011 23:32:53 +0000
Subject: [PATCH 23/34] Drop back on the handshake version, avoid rtmpe 9

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@562 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/handshake.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/librtmp/handshake.h b/librtmp/handshake.h
index 958579a..d4d2913 100644
--- a/librtmp/handshake.h
+++ b/librtmp/handshake.h
@@ -400,8 +400,10 @@ HandShake(RTMP * r, int FP9HandShake)
       /* set version to at least 9.0.115.0 */
       if (encrypted)
 	{
-	  clientsig[4] = 128;
-	  clientsig[6] = 3;
+/* 	  clientsig[4] = 128;
+	  clientsig[6] = 3; */
+	  clientsig[4] = 0x7c;
+	  clientsig[6] = 0x2;
 	}
       else
         {
-- 
1.7.10.4


From ac1843db901184bef349615e3b67d7d2fcebdb7f Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Tue, 22 Mar 2011 15:13:18 +0000
Subject: [PATCH 24/34] Fix prev commit

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@563 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/handshake.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/librtmp/handshake.h b/librtmp/handshake.h
index d4d2913..b172dbf 100644
--- a/librtmp/handshake.h
+++ b/librtmp/handshake.h
@@ -402,8 +402,8 @@ HandShake(RTMP * r, int FP9HandShake)
 	{
 /* 	  clientsig[4] = 128;
 	  clientsig[6] = 3; */
-	  clientsig[4] = 0x7c;
-	  clientsig[6] = 0x2;
+	  clientsig[4] = 9;
+	  clientsig[6] = 0x7c;
 	}
       else
         {
-- 
1.7.10.4


From 495e1e64106f10a7a1c15f0e2f870a02aa90605c Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 7 Apr 2011 19:07:31 +0000
Subject: [PATCH 25/34] Handle Play.PublishNotify like Play.Start

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@566 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 3042c7f..286b6ae 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -2282,6 +2282,8 @@ static const AVal av_NetStream_Play_Complete = AVC("NetStream.Play.Complete");
 static const AVal av_NetStream_Play_Stop = AVC("NetStream.Play.Stop");
 static const AVal av_NetStream_Seek_Notify = AVC("NetStream.Seek.Notify");
 static const AVal av_NetStream_Pause_Notify = AVC("NetStream.Pause.Notify");
+static const AVal av_NetStream_Play_PublishNotify =
+AVC("NetStream.Play.PublishNotify");
 static const AVal av_NetStream_Play_UnpublishNotify =
 AVC("NetStream.Play.UnpublishNotify");
 static const AVal av_NetStream_Publish_Start = AVC("NetStream.Publish.Start");
@@ -2449,7 +2451,8 @@ HandleInvoke(RTMP *r, const char *body, unsigned int nBodySize)
 	  RTMP_Log(RTMP_LOGERROR, "Closing connection: %s", code.av_val);
 	}
 
-      else if (AVMATCH(&code, &av_NetStream_Play_Start))
+      else if (AVMATCH(&code, &av_NetStream_Play_Start)
+           || AVMATCH(&code, &av_NetStream_Play_PublishNotify))
 	{
 	  int i;
 	  r->m_bPlaying = TRUE;
-- 
1.7.10.4


From 041cf3f2c927b26dc4b27b5e802fbb89362ea3e2 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 7 Apr 2011 19:11:13 +0000
Subject: [PATCH 26/34] Handle multiple sessions at once (ugly)

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@567 400ebc74-4327-4243-bc38-086b20814532
---
 rtmpsuck.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/rtmpsuck.c b/rtmpsuck.c
index ce6d879..3293e8b 100644
--- a/rtmpsuck.c
+++ b/rtmpsuck.c
@@ -718,15 +718,15 @@ controlServerThread(void *unused)
   TFRET();
 }
 
-void doServe(STREAMING_SERVER * server,	// server socket and state (our listening socket)
-  int sockfd	// client connection socket
-  )
+TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
 {
+  STREAMING_SERVER *server = arg;
   RTMPPacket pc = { 0 }, ps = { 0 };
   RTMPChunk rk = { 0 };
   char *buf = NULL;
   unsigned int buflen = 131072;
   int paused = FALSE;
+  int sockfd = server->socket;
 
   // timeout for http requests
   fd_set rfds;
@@ -990,7 +990,7 @@ quit:
   if (server->state == STREAMING_IN_PROGRESS)
     server->state = STREAMING_ACCEPTING;
 
-  return;
+  TFRET();
 }
 
 TFTYPE
@@ -1003,6 +1003,7 @@ serverThread(void *arg)
     {
       struct sockaddr_in addr;
       socklen_t addrlen = sizeof(struct sockaddr_in);
+      STREAMING_SERVER *srv2 = malloc(sizeof(STREAMING_SERVER));
       int sockfd =
 	accept(server->socket, (struct sockaddr *) &addr, &addrlen);
 
@@ -1020,8 +1021,10 @@ serverThread(void *arg)
 	  RTMP_Log(RTMP_LOGDEBUG, "%s: accepted connection from %s\n", __FUNCTION__,
 	      inet_ntoa(addr.sin_addr));
 #endif
+	  *srv2 = *server;
+	  srv2->socket = sockfd;
 	  /* Create a new thread and transfer the control to that */
-	  doServe(server, sockfd);
+	  ThreadCreate(doServe, srv2);
 	  RTMP_Log(RTMP_LOGDEBUG, "%s: processed request\n", __FUNCTION__);
 	}
       else
-- 
1.7.10.4


From 6155179b296f9749f713bb9bf47e9ca1fdb1a201 Mon Sep 17 00:00:00 2001
From: hyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Date: Thu, 7 Apr 2011 19:33:28 +0000
Subject: [PATCH 27/34] Use symbolic constants for packet types. From Peter
 Miller @ opensource.org.au

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@568 400ebc74-4327-4243-bc38-086b20814532
---
 librtmp/rtmp.c |  132 ++++++++++++++++++++++++++++++--------------------------
 librtmp/rtmp.h |   26 +++++++++--
 rtmpsrv.c      |    8 ++--
 rtmpsuck.c     |  112 ++++++++++++++++++++++++++---------------------
 4 files changed, 161 insertions(+), 117 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 286b6ae..5ef3ae9 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -1103,32 +1103,32 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
   int bHasMediaPacket = 0;
   switch (packet->m_packetType)
     {
-    case 0x01:
+    case RTMP_PACKET_TYPE_CHUNK_SIZE:
       /* chunk size */
       HandleChangeChunkSize(r, packet);
       break;
 
-    case 0x03:
+    case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
       /* bytes read report */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: bytes read report", __FUNCTION__);
       break;
 
-    case 0x04:
+    case RTMP_PACKET_TYPE_CONTROL:
       /* ctrl */
       HandleCtrl(r, packet);
       break;
 
-    case 0x05:
+    case RTMP_PACKET_TYPE_SERVER_BW:
       /* server bw */
       HandleServerBW(r, packet);
       break;
 
-    case 0x06:
+    case RTMP_PACKET_TYPE_CLIENT_BW:
       /* client bw */
       HandleClientBW(r, packet);
       break;
 
-    case 0x08:
+    case RTMP_PACKET_TYPE_AUDIO:
       /* audio data */
       /*RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize); */
       HandleAudio(r, packet);
@@ -1139,7 +1139,7 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
 	r->m_mediaStamp = packet->m_nTimeStamp;
       break;
 
-    case 0x09:
+    case RTMP_PACKET_TYPE_VIDEO:
       /* video data */
       /*RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize); */
       HandleVideo(r, packet);
@@ -1150,19 +1150,22 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
 	r->m_mediaStamp = packet->m_nTimeStamp;
       break;
 
-    case 0x0F:			/* flex stream send */
+    case RTMP_PACKET_TYPE_FLEX_STREAM_SEND:
+      /* flex stream send */
       RTMP_Log(RTMP_LOGDEBUG,
 	  "%s, flex stream send, size %lu bytes, not supported, ignoring",
 	  __FUNCTION__, packet->m_nBodySize);
       break;
 
-    case 0x10:			/* flex shared object */
+    case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT:
+      /* flex shared object */
       RTMP_Log(RTMP_LOGDEBUG,
 	  "%s, flex shared object, size %lu bytes, not supported, ignoring",
 	  __FUNCTION__, packet->m_nBodySize);
       break;
 
-    case 0x11:			/* flex message */
+    case RTMP_PACKET_TYPE_FLEX_MESSAGE:
+      /* flex message */
       {
 	RTMP_Log(RTMP_LOGDEBUG,
 	    "%s, flex message, size %lu bytes, not fully supported",
@@ -1185,7 +1188,7 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
 	  bHasMediaPacket = 2;
 	break;
       }
-    case 0x12:
+    case RTMP_PACKET_TYPE_INFO:
       /* metadata (notify) */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: notify %lu bytes", __FUNCTION__,
 	  packet->m_nBodySize);
@@ -1193,12 +1196,12 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
 	bHasMediaPacket = 1;
       break;
 
-    case 0x13:
+    case RTMP_PACKET_TYPE_SHARED_OBJECT:
       RTMP_Log(RTMP_LOGDEBUG, "%s, shared object, not supported, ignoring",
 	  __FUNCTION__);
       break;
 
-    case 0x14:
+    case RTMP_PACKET_TYPE_INVOKE:
       /* invoke */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__,
 	  packet->m_nBodySize);
@@ -1208,7 +1211,7 @@ RTMP_ClientPacket(RTMP *r, RTMPPacket *packet)
 	bHasMediaPacket = 2;
       break;
 
-    case 0x16:
+    case RTMP_PACKET_TYPE_FLASH_VIDEO:
       {
 	/* go through FLV packets and handle metadata packets */
 	unsigned int pos = 0;
@@ -1448,7 +1451,7 @@ SendConnectPacket(RTMP *r, RTMPPacket *cp)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1559,7 +1562,7 @@ SendBGHasStream(RTMP *r, double dId, AVal *playpath)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1591,7 +1594,7 @@ RTMP_SendCreateStream(RTMP *r)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1617,7 +1620,7 @@ SendFCSubscribe(RTMP *r, AVal *subscribepath)
   char *enc;
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1649,7 +1652,7 @@ SendReleaseStream(RTMP *r)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1679,7 +1682,7 @@ SendFCPublish(RTMP *r)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1709,7 +1712,7 @@ SendFCUnpublish(RTMP *r)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1741,7 +1744,7 @@ SendPublish(RTMP *r)
 
   packet.m_nChannel = 0x04;	/* source channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = r->m_stream_id;
   packet.m_hasAbsTimestamp = 0;
@@ -1776,7 +1779,7 @@ SendDeleteStream(RTMP *r, double dStreamId)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1805,7 +1808,7 @@ RTMP_SendPause(RTMP *r, int DoPause, int iTime)
 
   packet.m_nChannel = 0x08;	/* video channel */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* invoke */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1842,7 +1845,7 @@ RTMP_SendSeek(RTMP *r, int iTime)
 
   packet.m_nChannel = 0x08;	/* video channel */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* invoke */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1870,7 +1873,7 @@ RTMP_SendServerBW(RTMP *r)
 
   packet.m_nChannel = 0x02;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x05;	/* Server BW */
+  packet.m_packetType = RTMP_PACKET_TYPE_SERVER_BW;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1890,7 +1893,7 @@ RTMP_SendClientBW(RTMP *r)
 
   packet.m_nChannel = 0x02;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x06;	/* Client BW */
+  packet.m_packetType = RTMP_PACKET_TYPE_CLIENT_BW;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1911,7 +1914,7 @@ SendBytesReceived(RTMP *r)
 
   packet.m_nChannel = 0x02;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x03;	/* bytes in */
+  packet.m_packetType = RTMP_PACKET_TYPE_BYTES_READ_REPORT;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1937,7 +1940,7 @@ SendCheckBW(RTMP *r)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;	/* RTMP_GetTime(); */
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1965,7 +1968,7 @@ SendCheckBWResult(RTMP *r, double txn)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0x16 * r->m_nBWCheckCounter;	/* temp inc value. till we figure it out. */
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -1994,7 +1997,7 @@ SendPong(RTMP *r, double txn)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0x16 * r->m_nBWCheckCounter;	/* temp inc value. till we figure it out. */
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -2021,7 +2024,7 @@ SendPlay(RTMP *r)
 
   packet.m_nChannel = 0x08;	/* we make 8 our stream channel */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = r->m_stream_id;	/*0x01000000; */
   packet.m_hasAbsTimestamp = 0;
@@ -2089,7 +2092,7 @@ SendPlaylist(RTMP *r)
 
   packet.m_nChannel = 0x08;	/* we make 8 our stream channel */
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
-  packet.m_packetType = 0x14;	/* INVOKE */
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = r->m_stream_id;	/*0x01000000; */
   packet.m_hasAbsTimestamp = 0;
@@ -2127,7 +2130,7 @@ SendSecureTokenResponse(RTMP *r, AVal *resp)
 
   packet.m_nChannel = 0x03;	/* control channel (invoke) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x14;
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -2174,7 +2177,7 @@ RTMP_SendCtrl(RTMP *r, short nType, unsigned int nObject, unsigned int nTime)
 
   packet.m_nChannel = 0x02;	/* control channel (ping) */
   packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
-  packet.m_packetType = 0x04;	/* ctrl */
+  packet.m_packetType = RTMP_PACKET_TYPE_CONTROL;
   packet.m_nTimeStamp = 0;	/* RTMP_GetTime(); */
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -3372,7 +3375,7 @@ RTMP_SendPacket(RTMP *r, RTMPPacket *packet, int queue)
     }
 
   /* we invoked a remote method */
-  if (packet->m_packetType == 0x14)
+  if (packet->m_packetType == RTMP_PACKET_TYPE_INVOKE)
     {
       AVal method;
       char *ptr;
@@ -3748,8 +3751,8 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
       char *packetBody = packet.m_body;
       unsigned int nPacketLen = packet.m_nBodySize;
 
-      /* Return -3 if this was completed nicely with invoke message
-       * Play.Stop or Play.Complete
+      /* Return RTMP_READ_COMPLETE if this was completed nicely with
+       * invoke message Play.Stop or Play.Complete
        */
       if (rtnGetNextMediaPacket == 2)
 	{
@@ -3760,17 +3763,17 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	  break;
 	}
 
-      r->m_read.dataType |= (((packet.m_packetType == 0x08) << 2) |
-			     (packet.m_packetType == 0x09));
+      r->m_read.dataType |= (((packet.m_packetType == RTMP_PACKET_TYPE_AUDIO) << 2) |
+			     (packet.m_packetType == RTMP_PACKET_TYPE_VIDEO));
 
-      if (packet.m_packetType == 0x09 && nPacketLen <= 5)
+      if (packet.m_packetType == RTMP_PACKET_TYPE_VIDEO && nPacketLen <= 5)
 	{
 	  RTMP_Log(RTMP_LOGDEBUG, "ignoring too small video packet: size: %d",
 	      nPacketLen);
 	  ret = RTMP_READ_IGNORE;
 	  break;
 	}
-      if (packet.m_packetType == 0x08 && nPacketLen <= 1)
+      if (packet.m_packetType == RTMP_PACKET_TYPE_AUDIO && nPacketLen <= 1)
 	{
 	  RTMP_Log(RTMP_LOGDEBUG, "ignoring too small audio packet: size: %d",
 	      nPacketLen);
@@ -3787,7 +3790,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
       RTMP_Log(RTMP_LOGDEBUG, "type: %02X, size: %d, TS: %d ms, abs TS: %d",
 	  packet.m_packetType, nPacketLen, packet.m_nTimeStamp,
 	  packet.m_hasAbsTimestamp);
-      if (packet.m_packetType == 0x09)
+      if (packet.m_packetType == RTMP_PACKET_TYPE_VIDEO)
 	RTMP_Log(RTMP_LOGDEBUG, "frametype: %02X", (*packetBody & 0xf0));
 #endif
 
@@ -3797,7 +3800,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	  if (packet.m_nTimeStamp == 0)
 	    {
 	      if (r->m_read.nMetaHeaderSize > 0
-		  && packet.m_packetType == 0x12)
+		  && packet.m_packetType == RTMP_PACKET_TYPE_INFO)
 		{
 		  AMFObject metaObj;
 		  int nRes =
@@ -3858,7 +3861,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 		   * in the first FLV stream chunk and we have to compare
 		   * it and filter it out !!
 		   */
-		  if (packet.m_packetType == 0x16)
+		  if (packet.m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO)
 		    {
 		      /* basically we have to find the keyframe with the
 		       * correct TS being nResumeTS
@@ -3970,7 +3973,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	   * (seeking might put us somewhere before it)
 	   */
 	  if (!(r->m_read.flags & RTMP_READ_GOTKF) &&
-	  	packet.m_packetType != 0x16)
+	  	packet.m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO)
 	    {
 	      RTMP_Log(RTMP_LOGWARNING,
 		  "Stream does not start with requested frame, ignoring data... ");
@@ -3983,7 +3986,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	    }
 	  /* ok, do the same for FLV streams */
 	  if (!(r->m_read.flags & RTMP_READ_GOTFLVK) &&
-	  	packet.m_packetType == 0x16)
+	  	packet.m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO)
 	    {
 	      RTMP_Log(RTMP_LOGWARNING,
 		  "Stream does not start with requested FLV frame, ignoring data... ");
@@ -4002,9 +4005,11 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	   * the preceding if clause)
 	   */
 	  if (!(r->m_read.flags & RTMP_READ_NO_IGNORE) &&
-	  	packet.m_packetType != 0x16)
-	    {			/* exclude type 0x16 (FLV) since it can
-				 * contain several FLV packets */
+	  	packet.m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO)
+	    {
+              /* exclude type RTMP_PACKET_TYPE_FLASH_VIDEO since it can
+               * contain several FLV packets
+               */
 	      if (packet.m_nTimeStamp == 0)
 		{
 		  ret = RTMP_READ_IGNORE;
@@ -4020,9 +4025,10 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 
       /* calculate packet size and allocate slop buffer if necessary */
       size = nPacketLen +
-	((packet.m_packetType == 0x08 || packet.m_packetType == 0x09
-	  || packet.m_packetType == 0x12) ? 11 : 0) +
-	(packet.m_packetType != 0x16 ? 4 : 0);
+	((packet.m_packetType == RTMP_PACKET_TYPE_AUDIO
+          || packet.m_packetType == RTMP_PACKET_TYPE_VIDEO
+	  || packet.m_packetType == RTMP_PACKET_TYPE_INFO) ? 11 : 0) +
+	(packet.m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO ? 4 : 0);
 
       if (size + 4 > buflen)
 	{
@@ -4048,8 +4054,9 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 
       /* audio (0x08), video (0x09) or metadata (0x12) packets :
        * construct 11 byte header then add rtmp packet's data */
-      if (packet.m_packetType == 0x08 || packet.m_packetType == 0x09
-	  || packet.m_packetType == 0x12)
+      if (packet.m_packetType == RTMP_PACKET_TYPE_AUDIO
+          || packet.m_packetType == RTMP_PACKET_TYPE_VIDEO
+	  || packet.m_packetType == RTMP_PACKET_TYPE_INFO)
 	{
 	  nTimeStamp = r->m_read.nResumeTS + packet.m_nTimeStamp;
 	  prevTagSize = 11 + nPacketLen;
@@ -4059,7 +4066,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	  ptr = AMF_EncodeInt24(ptr, pend, nPacketLen);
 
 #if 0
-	    if(packet.m_packetType == 0x09) { /* video */
+	    if(packet.m_packetType == RTMP_PACKET_TYPE_VIDEO) {
 
 	     /* H264 fix: */
 	     if((packetBody[0] & 0x0f) == 7) { /* CodecId = H264 */
@@ -4089,7 +4096,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
       len = nPacketLen;
 
       /* correct tagSize and obtain timestamp if we have an FLV stream */
-      if (packet.m_packetType == 0x16)
+      if (packet.m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO)
 	{
 	  unsigned int pos = 0;
 	  int delta;
@@ -4167,7 +4174,7 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 	}
       ptr += len;
 
-      if (packet.m_packetType != 0x16)
+      if (packet.m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO)
 	{
 	  /* FLV tag packets contain their own prevTagSize */
 	  AMF_EncodeInt32(ptr, pend, prevTagSize);
@@ -4352,11 +4359,12 @@ RTMP_Write(RTMP *r, const char *buf, int size)
 	  buf += 3;
 	  s2 -= 11;
 
-	  if (((pkt->m_packetType == 0x08 || pkt->m_packetType == 0x09) &&
-	    !pkt->m_nTimeStamp) || pkt->m_packetType == 0x12)
+	  if (((pkt->m_packetType == RTMP_PACKET_TYPE_AUDIO
+                || pkt->m_packetType == RTMP_PACKET_TYPE_VIDEO) &&
+            !pkt->m_nTimeStamp) || pkt->m_packetType == RTMP_PACKET_TYPE_INFO)
 	    {
 	      pkt->m_headerType = RTMP_PACKET_SIZE_LARGE;
-	      if (pkt->m_packetType == 0x12)
+	      if (pkt->m_packetType == RTMP_PACKET_TYPE_INFO)
 		pkt->m_nBodySize += 16;
 	    }
 	  else
@@ -4371,7 +4379,7 @@ RTMP_Write(RTMP *r, const char *buf, int size)
 	    }
 	  enc = pkt->m_body;
 	  pend = enc + pkt->m_nBodySize;
-	  if (pkt->m_packetType == 0x12)
+	  if (pkt->m_packetType == RTMP_PACKET_TYPE_INFO)
 	    {
 	      enc = AMF_EncodeString(enc, pend, &av_setDataFrame);
 	      pkt->m_nBytesRead = enc - pkt->m_body;
diff --git a/librtmp/rtmp.h b/librtmp/rtmp.h
index de0b795..1ece207 100644
--- a/librtmp/rtmp.h
+++ b/librtmp/rtmp.h
@@ -71,9 +71,29 @@ extern "C"
 
   uint32_t RTMP_GetTime(void);
 
-#define RTMP_PACKET_TYPE_AUDIO 0x08
-#define RTMP_PACKET_TYPE_VIDEO 0x09
-#define RTMP_PACKET_TYPE_INFO  0x12
+/*      RTMP_PACKET_TYPE_...                0x00 */
+#define RTMP_PACKET_TYPE_CHUNK_SIZE         0x01
+/*      RTMP_PACKET_TYPE_...                0x02 */
+#define RTMP_PACKET_TYPE_BYTES_READ_REPORT  0x03
+#define RTMP_PACKET_TYPE_CONTROL            0x04
+#define RTMP_PACKET_TYPE_SERVER_BW          0x05
+#define RTMP_PACKET_TYPE_CLIENT_BW          0x06
+/*      RTMP_PACKET_TYPE_...                0x07 */
+#define RTMP_PACKET_TYPE_AUDIO              0x08
+#define RTMP_PACKET_TYPE_VIDEO              0x09
+/*      RTMP_PACKET_TYPE_...                0x0A */
+/*      RTMP_PACKET_TYPE_...                0x0B */
+/*      RTMP_PACKET_TYPE_...                0x0C */
+/*      RTMP_PACKET_TYPE_...                0x0D */
+/*      RTMP_PACKET_TYPE_...                0x0E */
+#define RTMP_PACKET_TYPE_FLEX_STREAM_SEND   0x0F
+#define RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT 0x10
+#define RTMP_PACKET_TYPE_FLEX_MESSAGE       0x11
+#define RTMP_PACKET_TYPE_INFO               0x12
+#define RTMP_PACKET_TYPE_SHARED_OBJECT      0x13
+#define RTMP_PACKET_TYPE_INVOKE             0x14
+/*      RTMP_PACKET_TYPE_...                0x15 */
+#define RTMP_PACKET_TYPE_FLASH_VIDEO        0x16
 
 #define RTMP_MAX_HEADER_SIZE 18
 
diff --git a/rtmpsrv.c b/rtmpsrv.c
index 4d5699f..f1b6c66 100644
--- a/rtmpsrv.c
+++ b/rtmpsrv.c
@@ -175,7 +175,7 @@ SendConnectResult(RTMP *r, double txn)
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
-  packet.m_packetType = 0x14;   // INVOKE
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -236,7 +236,7 @@ SendResultNumber(RTMP *r, double txn, double ID)
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
-  packet.m_packetType = 0x14;   // INVOKE
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -270,7 +270,7 @@ SendPlayStart(RTMP *r)
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
-  packet.m_packetType = 0x14;   // INVOKE
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
@@ -302,7 +302,7 @@ SendPlayStop(RTMP *r)
 
   packet.m_nChannel = 0x03;     // control channel (invoke)
   packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
-  packet.m_packetType = 0x14;   // INVOKE
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
   packet.m_nTimeStamp = 0;
   packet.m_nInfoField2 = 0;
   packet.m_hasAbsTimestamp = 0;
diff --git a/rtmpsuck.c b/rtmpsuck.c
index 3293e8b..661e64b 100644
--- a/rtmpsuck.c
+++ b/rtmpsuck.c
@@ -461,67 +461,71 @@ ServePacket(STREAMING_SERVER *server, int which, RTMPPacket *packet)
 
   switch (packet->m_packetType)
     {
-    case 0x01:
+    case RTMP_PACKET_TYPE_CHUNK_SIZE:
       // chunk size
 //      HandleChangeChunkSize(r, packet);
       break;
 
-    case 0x03:
+    case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
       // bytes read report
       break;
 
-    case 0x04:
+    case RTMP_PACKET_TYPE_CONTROL:
       // ctrl
 //      HandleCtrl(r, packet);
       break;
 
-    case 0x05:
+    case RTMP_PACKET_TYPE_SERVER_BW:
       // server bw
 //      HandleServerBW(r, packet);
       break;
 
-    case 0x06:
+    case RTMP_PACKET_TYPE_CLIENT_BW:
       // client bw
  //     HandleClientBW(r, packet);
       break;
 
-    case 0x08:
+    case RTMP_PACKET_TYPE_AUDIO:
       // audio data
       //RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize);
       break;
 
-    case 0x09:
+    case RTMP_PACKET_TYPE_VIDEO:
       // video data
       //RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize);
       break;
 
-    case 0x0F:			// flex stream send
+    case RTMP_PACKET_TYPE_FLEX_STREAM_SEND:
+      // flex stream send
       break;
 
-    case 0x10:			// flex shared object
+    case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT:
+      // flex shared object
       break;
 
-    case 0x11:			// flex message
+    case RTMP_PACKET_TYPE_FLEX_MESSAGE:
+      // flex message
       {
 	ret = ServeInvoke(server, which, packet, packet->m_body + 1);
 	break;
       }
-    case 0x12:
+    case RTMP_PACKET_TYPE_INFO:
       // metadata (notify)
       break;
 
-    case 0x13:
+    case RTMP_PACKET_TYPE_SHARED_OBJECT:
       /* shared object */
       break;
 
-    case 0x14:
+    case RTMP_PACKET_TYPE_INVOKE:
       // invoke
       ret = ServeInvoke(server, which, packet, packet->m_body);
       break;
 
-    case 0x16:
+    case RTMP_PACKET_TYPE_FLASH_VIDEO:
       /* flv */
 	break;
+
     default:
       RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__,
 	  packet->m_packetType);
@@ -547,21 +551,21 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
       unsigned int nPacketLen = packet->m_nBodySize;
 
       // skip video info/command packets
-      if (packet->m_packetType == 0x09 &&
+      if (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO &&
 	  nPacketLen == 2 && ((*packetBody & 0xf0) == 0x50))
 	{
 	  ret = 0;
 	  break;
 	}
 
-      if (packet->m_packetType == 0x09 && nPacketLen <= 5)
+      if (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO && nPacketLen <= 5)
 	{
 	  RTMP_Log(RTMP_LOGWARNING, "ignoring too small video packet: size: %d",
 	      nPacketLen);
 	  ret = 0;
 	  break;
 	}
-      if (packet->m_packetType == 0x08 && nPacketLen <= 1)
+      if (packet->m_packetType == RTMP_PACKET_TYPE_AUDIO && nPacketLen <= 1)
 	{
 	  RTMP_Log(RTMP_LOGWARNING, "ignoring too small audio packet: size: %d",
 	      nPacketLen);
@@ -571,19 +575,22 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
 #ifdef _DEBUG
       RTMP_Log(RTMP_LOGDEBUG, "type: %02X, size: %d, TS: %d ms", packet->m_packetType,
 	  nPacketLen, packet->m_nTimeStamp);
-      if (packet->m_packetType == 0x09)
+      if (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO)
 	RTMP_Log(RTMP_LOGDEBUG, "frametype: %02X", (*packetBody & 0xf0));
 #endif
 
       // calculate packet size and reallocate buffer if necessary
       unsigned int size = nPacketLen
 	+
-	((packet->m_packetType == 0x08 || packet->m_packetType == 0x09
-	  || packet->m_packetType == 0x12) ? 11 : 0) + (packet->m_packetType !=
-						       0x16 ? 4 : 0);
+	((packet->m_packetType == RTMP_PACKET_TYPE_AUDIO
+          || packet->m_packetType == RTMP_PACKET_TYPE_VIDEO
+	  || packet->m_packetType == RTMP_PACKET_TYPE_INFO) ? 11 : 0)
+        + (packet->m_packetType != 0x16 ? 4 : 0);
 
       if (size + 4 > len)
-	{			// the extra 4 is for the case of an FLV stream without a last prevTagSize (we need extra 4 bytes to append it)
+	{
+          /* The extra 4 is for the case of an FLV stream without a last
+           * prevTagSize (we need extra 4 bytes to append it).  */
 	  *buf = (char *) realloc(*buf, size + 4);
 	  if (*buf == 0)
 	    {
@@ -594,13 +601,15 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
 	}
       char *ptr = *buf, *pend = ptr + size+4;
 
-      // audio (0x08), video (0x09) or metadata (0x12) packets :
-      // construct 11 byte header then add rtmp packet's data
-      if (packet->m_packetType == 0x08 || packet->m_packetType == 0x09
-	  || packet->m_packetType == 0x12)
+      /* audio (RTMP_PACKET_TYPE_AUDIO), video (RTMP_PACKET_TYPE_VIDEO)
+       * or metadata (RTMP_PACKET_TYPE_INFO) packets: construct 11 byte
+       * header then add rtmp packet's data.  */
+      if (packet->m_packetType == RTMP_PACKET_TYPE_AUDIO
+          || packet->m_packetType == RTMP_PACKET_TYPE_VIDEO
+	  || packet->m_packetType == RTMP_PACKET_TYPE_INFO)
 	{
 	  // set data type
-	  //*dataType |= (((packet->m_packetType == 0x08)<<2)|(packet->m_packetType == 0x09));
+	  //*dataType |= (((packet->m_packetType == RTMP_PACKET_TYPE_AUDIO)<<2)|(packet->m_packetType == RTMP_PACKET_TYPE_VIDEO));
 
 	  (*nTimeStamp) = packet->m_nTimeStamp;
 	  prevTagSize = 11 + nPacketLen;
@@ -619,7 +628,7 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
       unsigned int len = nPacketLen;
 
       // correct tagSize and obtain timestamp if we have an FLV stream
-      if (packet->m_packetType == 0x16)
+      if (packet->m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO)
 	{
 	  unsigned int pos = 0;
 
@@ -629,8 +638,11 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
 	      *nTimeStamp = AMF_DecodeInt24(packetBody + pos + 4);
 	      *nTimeStamp |= (packetBody[pos + 7] << 24);
 
-	      // set data type
-	      //*dataType |= (((*(packetBody+pos) == 0x08)<<2)|(*(packetBody+pos) == 0x09));
+#if 0
+	      /* set data type */
+	      *dataType |= (((*(packetBody+pos) == RTMP_PACKET_TYPE_AUDIO) << 2)
+                            | (*(packetBody+pos) == RTMP_PACKET_TYPE_VIDEO));
+#endif
 
 	      if (pos + 11 + dataSize + 4 > nPacketLen)
 		{
@@ -680,7 +692,7 @@ WriteStream(char **buf,	// target pointer, maybe preallocated
 	}
       ptr += len;
 
-      if (packet->m_packetType != 0x16)
+      if (packet->m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO)
 	{			// FLV tag packets contain their own prevTagSize
 	  AMF_EncodeInt32(ptr, pend, prevTagSize);
 	  //ptr += 4;
@@ -828,7 +840,7 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
             if (RTMPPacket_IsReady(&ps))
               {
                 /* change chunk size */
-                if (ps.m_packetType == 0x01)
+                if (ps.m_packetType == RTMP_PACKET_TYPE_CHUNK_SIZE)
                   {
                     if (ps.m_nBodySize >= 4)
                       {
@@ -839,7 +851,7 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
                       }
                   }
                 /* bytes received */
-                else if (ps.m_packetType == 0x03)
+                else if (ps.m_packetType == RTMP_PACKET_TYPE_BYTES_READ_REPORT)
                   {
                     if (ps.m_nBodySize >= 4)
                       {
@@ -849,7 +861,7 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
                       }
                   }
                 /* ctrl */
-                else if (ps.m_packetType == 0x04)
+                else if (ps.m_packetType == RTMP_PACKET_TYPE_CONTROL)
                   {
                     short nType = AMF_DecodeInt16(ps.m_body);
                     /* UpdateBufferMS */
@@ -875,13 +887,16 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
                           }
                       }
                   }
-                else if (ps.m_packetType == 0x11 || ps.m_packetType == 0x14)
-                  if (ServePacket(server, 0, &ps) && server->f_cur)
-                    {
-                      fclose(server->f_cur->f_file);
-                      server->f_cur->f_file = NULL;
-                      server->f_cur = NULL;
-                    }
+                else if (ps.m_packetType == RTMP_PACKET_TYPE_FLEX_MESSAGE
+                         || ps.m_packetType == RTMP_PACKET_TYPE_INVOKE)
+                  {
+                    if (ServePacket(server, 0, &ps) && server->f_cur)
+                      {
+                        fclose(server->f_cur->f_file);
+                        server->f_cur->f_file = NULL;
+                        server->f_cur = NULL;
+                      }
+                  }
                 RTMP_SendPacket(&server->rc, &ps, FALSE);
                 RTMPPacket_Free(&ps);
                 break;
@@ -902,7 +917,7 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
                       server->rc.m_pausing = 0;
                     }
                   /* change chunk size */
-                  if (pc.m_packetType == 0x01)
+                  if (pc.m_packetType == RTMP_PACKET_TYPE_CHUNK_SIZE)
                     {
                       if (pc.m_nBodySize >= 4)
                         {
@@ -912,7 +927,7 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
                           server->rs.m_outChunkSize = server->rc.m_inChunkSize;
                         }
                     }
-                  else if (pc.m_packetType == 0x04)
+                  else if (pc.m_packetType == RTMP_PACKET_TYPE_CONTROL)
                     {
                       short nType = AMF_DecodeInt16(pc.m_body);
                       /* SWFverification */
@@ -929,17 +944,18 @@ TFTYPE doServe(void *arg)	// server socket and state (our listening socket)
 #endif
                     }
                   else if (server->f_cur && (
-                       pc.m_packetType == 0x08 ||
-                       pc.m_packetType == 0x09 ||
-                       pc.m_packetType == 0x12 ||
-                       pc.m_packetType == 0x16) &&
+                       pc.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
+                       pc.m_packetType == RTMP_PACKET_TYPE_VIDEO ||
+                       pc.m_packetType == RTMP_PACKET_TYPE_INFO ||
+                       pc.m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO) &&
                        RTMP_ClientPacket(&server->rc, &pc))
                     {
                       int len = WriteStream(&buf, &buflen, &server->stamp, &pc);
                       if (len > 0 && fwrite(buf, 1, len, server->f_cur->f_file) != len)
                         goto cleanup;
                     }
-                  else if ( pc.m_packetType == 0x11 || pc.m_packetType == 0x14)
+                  else if (pc.m_packetType == RTMP_PACKET_TYPE_FLEX_MESSAGE ||
+                           pc.m_packetType == RTMP_PACKET_TYPE_INVOKE)
                     {
                       if (ServePacket(server, 1, &pc) && server->f_cur)
                         {
-- 
1.7.10.4


From e09abc08504988e5c286ffc9c92da3ba76f95a20 Mon Sep 17 00:00:00 2001
From: Compn <tempn@twmi.rr.com>
Date: Tue, 5 Jul 2011 09:48:23 -0400
Subject: [PATCH 28/34] add -shared to mingw ldflags, fixes compilation error
 patch by Martin Storsjo

---
 librtmp/Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/librtmp/Makefile b/librtmp/Makefile
index 1ea31a0..785e869 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -54,7 +54,7 @@ SODIR=$(SODIR_$(SYS))
 SO_LDFLAGS_posix=-shared -Wl,-soname,$@
 SO_LDFLAGS_darwin=-dynamiclib -flat_namespace -undefined suppress -fno-common \
 	-headerpad_max_install_names
-SO_LDFLAGS_mingw=
+SO_LDFLAGS_mingw=-shared
 SO_LDFLAGS=$(SO_LDFLAGS_$(SYS))
 
 SHARED=yes
-- 
1.7.10.4


From 0e9b4917c1163227c48cd83e081aa972ed7d3111 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 14:41:11 -0700
Subject: [PATCH 29/34] Revert "Drop back on the handshake version, avoid
 rtmpe 9"

This reverts commit aa2825fbb1d1f70652d558a730baed28149ebbdd.

Conflicts:

	librtmp/handshake.h
---
 librtmp/handshake.h |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/librtmp/handshake.h b/librtmp/handshake.h
index b172dbf..958579a 100644
--- a/librtmp/handshake.h
+++ b/librtmp/handshake.h
@@ -400,10 +400,8 @@ HandShake(RTMP * r, int FP9HandShake)
       /* set version to at least 9.0.115.0 */
       if (encrypted)
 	{
-/* 	  clientsig[4] = 128;
-	  clientsig[6] = 3; */
-	  clientsig[4] = 9;
-	  clientsig[6] = 0x7c;
+	  clientsig[4] = 128;
+	  clientsig[6] = 3;
 	}
       else
         {
-- 
1.7.10.4


From d1f14b147e03aa17c968b96d6573320410a5252c Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 16:12:39 -0700
Subject: [PATCH 30/34] Add RTMPE type 9 handshake signature

---
 librtmp/handshake.h |  349 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 336 insertions(+), 13 deletions(-)

diff --git a/librtmp/handshake.h b/librtmp/handshake.h
index 958579a..98bf3c8 100644
--- a/librtmp/handshake.h
+++ b/librtmp/handshake.h
@@ -358,6 +358,337 @@ static void rtmpe8_sig(uint8_t *in, uint8_t *out, int keyid)
   out[7] = v1;
 }
 
+/* RTMPE type 9 uses Blowfish on the regular signature
+ * http://en.wikipedia.org/wiki/Blowfish_(cipher)
+ */
+#define	BF_ROUNDS	16
+typedef struct bf_key {
+	uint32_t s[4][256];
+	uint32_t p[BF_ROUNDS+2];
+} bf_key;
+
+static const uint32_t bf_sinit[][256] = {
+
+  /* S-Box 0 */
+  { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
+    0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+    0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
+    0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+    0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e,
+    0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+    0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6,
+    0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+    0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c,
+    0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+    0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1,
+    0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+    0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a,
+    0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+    0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176,
+    0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+    0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706,
+    0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+    0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b,
+    0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+    0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c,
+    0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+    0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a,
+    0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+    0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760,
+    0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+    0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8,
+    0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+    0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33,
+    0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+    0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0,
+    0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+    0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777,
+    0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+    0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705,
+    0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+    0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e,
+    0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+    0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9,
+    0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+    0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f,
+    0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+    0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, },
+
+  /* S-Box 1 */
+  { 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
+    0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+    0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65,
+    0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+    0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9,
+    0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+    0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d,
+    0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+    0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc,
+    0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+    0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908,
+    0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+    0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124,
+    0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+    0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908,
+    0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+    0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b,
+    0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+    0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa,
+    0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+    0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d,
+    0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+    0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5,
+    0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+    0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96,
+    0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+    0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca,
+    0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+    0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77,
+    0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+    0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054,
+    0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+    0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea,
+    0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+    0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646,
+    0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+    0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea,
+    0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+    0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e,
+    0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+    0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
+    0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+    0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, },
+
+  /* S-Box 2 */
+  { 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7,
+    0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+    0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
+    0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+    0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4,
+    0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+    0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec,
+    0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+    0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332,
+    0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+    0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58,
+    0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+    0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22,
+    0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+    0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60,
+    0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+    0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99,
+    0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+    0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74,
+    0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+    0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3,
+    0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+    0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979,
+    0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+    0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa,
+    0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+    0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086,
+    0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+    0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24,
+    0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+    0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84,
+    0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+    0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09,
+    0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+    0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe,
+    0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+    0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0,
+    0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+    0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188,
+    0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+    0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
+    0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+    0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, },
+
+  /* S-Box 3 */
+  { 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
+    0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+    0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
+    0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+    0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a,
+    0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+    0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1,
+    0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+    0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797,
+    0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+    0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6,
+    0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+    0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba,
+    0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+    0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5,
+    0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+    0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce,
+    0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+    0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd,
+    0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+    0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb,
+    0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+    0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc,
+    0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+    0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc,
+    0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+    0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a,
+    0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+    0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a,
+    0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+    0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b,
+    0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+    0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e,
+    0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+    0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623,
+    0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+    0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a,
+    0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+    0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3,
+    0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+    0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
+    0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+    0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6, },
+};
+
+static const uint32_t bf_pinit[] = {
+  /* P-Box */
+  0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
+  0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+  0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b,
+};
+
+#define KEYBYTES	24
+
+static const unsigned char rtmpe9_keys[16][KEYBYTES] = {
+ { 0x79, 0x34, 0x77, 0x4c, 0x67, 0xd1, 0x38, 0x3a, 0xdf, 0xb3, 0x56, 0xbe,
+   0x8b, 0x7b, 0xd0, 0x24, 0x38, 0xe0, 0x73, 0x58, 0x41, 0x5d, 0x69, 0x67, },
+ { 0x46, 0xf6, 0xb4, 0xcc, 0x01, 0x93, 0xe3, 0xa1, 0x9e, 0x7d, 0x3c, 0x65,
+   0x55, 0x86, 0xfd, 0x09, 0x8f, 0xf7, 0xb3, 0xc4, 0x6f, 0x41, 0xca, 0x5c, },
+ { 0x1a, 0xe7, 0xe2, 0xf3, 0xf9, 0x14, 0x79, 0x94, 0xc0, 0xd3, 0x97, 0x43,
+   0x08, 0x7b, 0xb3, 0x84, 0x43, 0x2f, 0x9d, 0x84, 0x3f, 0x21, 0x01, 0x9b, },
+ { 0xd3, 0xe3, 0x54, 0xb0, 0xf7, 0x1d, 0xf6, 0x2b, 0x5a, 0x43, 0x4d, 0x04,
+   0x83, 0x64, 0x3e, 0x0d, 0x59, 0x2f, 0x61, 0xcb, 0xb1, 0x6a, 0x59, 0x0d, },
+ { 0xc8, 0xc1, 0xe9, 0xb8, 0x16, 0x56, 0x99, 0x21, 0x7b, 0x5b, 0x36, 0xb7,
+   0xb5, 0x9b, 0xdf, 0x06, 0x49, 0x2c, 0x97, 0xf5, 0x95, 0x48, 0x85, 0x7e, },
+ { 0xeb, 0xe5, 0xe6, 0x2e, 0xa4, 0xba, 0xd4, 0x2c, 0xf2, 0x16, 0xe0, 0x8f,
+   0x66, 0x23, 0xa9, 0x43, 0x41, 0xce, 0x38, 0x14, 0x84, 0x95, 0x00, 0x53, },
+ { 0x66, 0xdb, 0x90, 0xf0, 0x3b, 0x4f, 0xf5, 0x6f, 0xe4, 0x9c, 0x20, 0x89,
+   0x35, 0x5e, 0xd2, 0xb2, 0xc3, 0x9e, 0x9f, 0x7f, 0x63, 0xb2, 0x28, 0x81, },
+ { 0xbb, 0x20, 0xac, 0xed, 0x2a, 0x04, 0x6a, 0x19, 0x94, 0x98, 0x9b, 0xc8,
+   0xff, 0xcd, 0x93, 0xef, 0xc6, 0x0d, 0x56, 0xa7, 0xeb, 0x13, 0xd9, 0x30, },
+ { 0xbc, 0xf2, 0x43, 0x82, 0x09, 0x40, 0x8a, 0x87, 0x25, 0x43, 0x6d, 0xe6,
+   0xbb, 0xa4, 0xb9, 0x44, 0x58, 0x3f, 0x21, 0x7c, 0x99, 0xbb, 0x3f, 0x24, },
+ { 0xec, 0x1a, 0xaa, 0xcd, 0xce, 0xbd, 0x53, 0x11, 0xd2, 0xfb, 0x83, 0xb6,
+   0xc3, 0xba, 0xab, 0x4f, 0x62, 0x79, 0xe8, 0x65, 0xa9, 0x92, 0x28, 0x76, },
+ { 0xc6, 0x0c, 0x30, 0x03, 0x91, 0x18, 0x2d, 0x7b, 0x79, 0xda, 0xe1, 0xd5,
+   0x64, 0x77, 0x9a, 0x12, 0xc5, 0xb1, 0xd7, 0x91, 0x4f, 0x96, 0x4c, 0xa3, },
+ { 0xd7, 0x7c, 0x2a, 0xbf, 0xa6, 0xe7, 0x85, 0x7c, 0x45, 0xad, 0xff, 0x12,
+   0x94, 0xd8, 0xde, 0xa4, 0x5c, 0x3d, 0x79, 0xa4, 0x44, 0x02, 0x5d, 0x22, },
+ { 0x16, 0x19, 0x0d, 0x81, 0x6a, 0x4c, 0xc7, 0xf8, 0xb8, 0xf9, 0x4e, 0xcd,
+   0x2c, 0x9e, 0x90, 0x84, 0xb2, 0x08, 0x25, 0x60, 0xe1, 0x1e, 0xae, 0x18, },
+ { 0xe9, 0x7c, 0x58, 0x26, 0x1b, 0x51, 0x9e, 0x49, 0x82, 0x60, 0x61, 0xfc,
+   0xa0, 0xa0, 0x1b, 0xcd, 0xf5, 0x05, 0xd6, 0xa6, 0x6d, 0x07, 0x88, 0xa3, },
+ { 0x2b, 0x97, 0x11, 0x8b, 0xd9, 0x4e, 0xd9, 0xdf, 0x20, 0xe3, 0x9c, 0x10,
+   0xe6, 0xa1, 0x35, 0x21, 0x11, 0xf9, 0x13, 0x0d, 0x0b, 0x24, 0x65, 0xb2, },
+ { 0x53, 0x6a, 0x4c, 0x54, 0xac, 0x8b, 0x9b, 0xb8, 0x97, 0x29, 0xfc, 0x60,
+   0x2c, 0x5b, 0x3a, 0x85, 0x68, 0xb5, 0xaa, 0x6a, 0x44, 0xcd, 0x3f, 0xa7, },
+};
+
+#define	BF_ENC(X,S) \
+	(((S[0][X>>24] + S[1][X>>16 & 0xff]) ^ S[2][(X>>8) & 0xff]) + S[3][X & 0xff])
+
+static void bf_enc(uint32_t *x, bf_key *key)
+{
+  uint32_t  Xl;
+  uint32_t  Xr;
+  uint32_t  temp;
+  int	i;
+
+  Xl = x[0];
+  Xr = x[1];
+
+  for (i = 0; i < BF_ROUNDS; ++i) {
+    Xl ^= key->p[i];
+    Xr ^= BF_ENC(Xl,key->s);
+
+    temp = Xl;
+    Xl = Xr;
+    Xr = temp;
+  }
+
+  Xl ^= key->p[BF_ROUNDS];
+  Xr ^= key->p[BF_ROUNDS + 1];
+
+  x[0] = Xr;
+  x[1] = Xl;
+}
+
+static void bf_setkey(const unsigned char *kp, int keybytes, bf_key *key)
+{
+  int          i;
+  int          j;
+  int          k;
+  uint32_t  data;
+  uint32_t  d[2];
+
+  memcpy(key->p, bf_pinit, sizeof(key->p));
+  memcpy(key->s, bf_sinit, sizeof(key->s));
+
+  j = 0;
+  for (i = 0; i < BF_ROUNDS + 2; ++i) {
+    data = 0x00000000;
+	for (k = 0; k < 4; ++k) {
+	  data = (data << 8) | kp[j];
+	  j = j + 1;
+	  if (j >= keybytes) {
+	    j = 0;
+	  }
+	}
+	key->p[i] ^= data;
+  }
+
+  d[0] = 0x00000000;
+  d[1] = 0x00000000;
+
+  for (i = 0; i < BF_ROUNDS + 2; i += 2) {
+    bf_enc(d, key);
+
+	key->p[i] = d[0];
+	key->p[i + 1] = d[1];
+  }
+
+  for (i = 0; i < 4; ++i) {
+	for (j = 0; j < 256; j += 2) {
+
+	  bf_enc(d, key);
+
+	  key->s[i][j] = d[0];
+	  key->s[i][j + 1] = d[1];
+	}
+  }
+}
+
+static void rtmpe9_sig(uint8_t *in, uint8_t *out, int keyid)
+{
+  uint32_t d[2];
+  bf_key key;
+
+  bf_setkey(rtmpe9_keys[keyid], KEYBYTES, &key);
+
+  /* input is little-endian */
+  d[0] = in[0] | (in[1] << 8) | (in[2] << 16) | (in[3] << 24);
+  d[1] = in[4] | (in[5] << 8) | (in[6] << 16) | (in[7] << 24);
+  bf_enc(d, &key);
+  out[0] = d[0] & 0xff;
+  out[1] = (d[0] >> 8) & 0xff;
+  out[2] = (d[0] >> 16) & 0xff;
+  out[3] = (d[0] >> 24) & 0xff;
+  out[4] = d[1] & 0xff;
+  out[5] = (d[1] >> 8) & 0xff;
+  out[6] = (d[1] >> 16) & 0xff;
+  out[7] = (d[1] >> 24) & 0xff;
+}
+
 static int
 HandShake(RTMP * r, int FP9HandShake)
 {
@@ -605,8 +936,7 @@ HandShake(RTMP * r, int FP9HandShake)
           for (i=0; i<SHA256_DIGEST_LENGTH; i+=8)
 	    rtmpe8_sig(sig+i, sig+i, dptr[i] % 15);
         }
-#if 0
-      else if (type == 9))
+      else if (type == 9)
         {
 	  uint8_t *dptr = digestResp;
 	  uint8_t *sig = signatureResp;
@@ -615,7 +945,6 @@ HandShake(RTMP * r, int FP9HandShake)
             rtmpe9_sig(sig+i, sig+i, dptr[i] % 15);
         }
 #endif
-#endif
       RTMP_Log(RTMP_LOGDEBUG, "%s: Client signature calculated:", __FUNCTION__);
       RTMP_LogHex(RTMP_LOGDEBUG, signatureResp, SHA256_DIGEST_LENGTH);
     }
@@ -680,7 +1009,6 @@ HandShake(RTMP * r, int FP9HandShake)
           for (i=0; i<SHA256_DIGEST_LENGTH; i+=8)
 	    rtmpe8_sig(sig+i, sig+i, dptr[i] % 15);
         }
-#if 0
       else if (type == 9)
         {
 	  uint8_t *dptr = digest;
@@ -690,7 +1018,6 @@ HandShake(RTMP * r, int FP9HandShake)
             rtmpe9_sig(sig+i, sig+i, dptr[i] % 15);
         }
 #endif
-#endif
       RTMP_Log(RTMP_LOGDEBUG, "%s: Signature calculated:", __FUNCTION__);
       RTMP_LogHex(RTMP_LOGDEBUG, signature, SHA256_DIGEST_LENGTH);
       if (memcmp
@@ -964,8 +1291,7 @@ SHandShake(RTMP * r)
           for (i=0; i<SHA256_DIGEST_LENGTH; i+=8)
 	    rtmpe8_sig(sig+i, sig+i, dptr[i] % 15);
         }
-#if 0
-      else if (type == 9))
+      else if (type == 9)
         {
 	  uint8_t *dptr = digestResp;
 	  uint8_t *sig = signatureResp;
@@ -974,7 +1300,6 @@ SHandShake(RTMP * r)
             rtmpe9_sig(sig+i, sig+i, dptr[i] % 15);
         }
 #endif
-#endif
 
       /* some info output */
       RTMP_Log(RTMP_LOGDEBUG,
@@ -1030,17 +1355,15 @@ SHandShake(RTMP * r)
           for (i=0; i<SHA256_DIGEST_LENGTH; i+=8)
 	    rtmpe8_sig(sig+i, sig+i, dptr[i] % 15);
         }
-#if 0
-      else if (type == 9))
+      else if (type == 9)
         {
-	  uint8_t *dptr = digestResp;
-	  uint8_t *sig = signatureResp;
+	  uint8_t *dptr = digest;
+	  uint8_t *sig = signature;
 	  /* encrypt signatureResp */
           for (i=0; i<SHA256_DIGEST_LENGTH; i+=8)
             rtmpe9_sig(sig+i, sig+i, dptr[i] % 15);
         }
 #endif
-#endif
 
       /* show some information */
       RTMP_Log(RTMP_LOGDEBUG, "%s: Digest key: ", __FUNCTION__);
-- 
1.7.10.4


From be0590a86af80df528e3556b86f110ad4b5cbb27 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 16:41:28 -0700
Subject: [PATCH 31/34] Add LIB_RTMP macro

Allows changing to static linking on the cmd line
---
 Makefile |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c322e9a..1597be8 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,8 @@ MANDIR=$(DESTDIR)$(mandir)
 LIBS_posix=
 LIBS_darwin=
 LIBS_mingw=-lws2_32 -lwinmm -lgdi32
-LIBS=-Llibrtmp -lrtmp $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
+LIB_RTMP=-Llibrtmp -lrtmp
+LIBS=$(LIB_RTMP) $(CRYPTO_LIB) $(LIBS_$(SYS)) $(XLIBS)
 
 THREADLIB_posix=-lpthread
 THREADLIB_darwin=-lpthread
-- 
1.7.10.4


From 4028a5aa7f72cac44a62b4aac596ff3c82e6e019 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 17:19:25 -0700
Subject: [PATCH 32/34] Additional credit for RTMPE 9 keys

---
 README |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/README b/README
index 5689853..865c6c4 100644
--- a/README
+++ b/README
@@ -1,7 +1,8 @@
-RTMP Dump v2.3
+RTMP Dump v2.4
 (C) 2009 Andrej Stepanchuk
-(C) 2009-2010 Howard Chu
+(C) 2009-2011 Howard Chu
 (C) 2010 2a665470ced7adb7156fcef47f8199a6371c117b8a79e399a2771e0b36384090
+(C) 2011 33ae1ce77301f4b4494faaa5f609f3c48b9dcf82
 License: GPLv2
 librtmp license: LGPLv2.1
 http://rtmpdump.mplayerhq.hu/
-- 
1.7.10.4


From 3121324046e4ca1934e7e28293fc8326475d5053 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 17:22:43 -0700
Subject: [PATCH 33/34] Version bump

---
 Makefile         |    2 +-
 librtmp/Makefile |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 1597be8..6ef5742 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=v2.3
+VERSION=v2.4
 
 prefix=/usr/local
 
diff --git a/librtmp/Makefile b/librtmp/Makefile
index 785e869..d61e7a4 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -1,4 +1,4 @@
-VERSION=v2.3
+VERSION=v2.4
 
 prefix=/usr/local
 
-- 
1.7.10.4


From c28f1bab7822de97353849e7787b59e50bbb1428 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@symas.com>
Date: Mon, 11 Jul 2011 17:24:33 -0700
Subject: [PATCH 34/34] v2.4 changes

---
 ChangeLog |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f57c580..fb2319f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,12 @@
 RTMPDump
 Copyright 2008-2009 Andrej Stepanchuk; Distributed under the GPL v2
-Copyright 2009-2010 Howard Chu
+Copyright 2009-2011 Howard Chu
 Copyright 2009 The Flvstreamer Team
 http://rtmpdump.mplayerhq.hu/
 
+11 July 2011, v2.4
+- add RTMPE type 9 handshake support
+
 30 June 2010, v2.3
 - fix RC4 cleanup for GnuTLS/gcrypt
 - declare RTMP_Write buf as const
-- 
1.7.10.4