summaryrefslogtreecommitdiff
path: root/apps/plugins/bitmaps/native/clock_binary.128x128x16.bmp
blob: 55945b090b6d8f0c67e46f9f54247cbe2b532d1f (plain)
ofshex dumpascii
0000 42 4d 56 0d 00 00 00 00 00 00 36 00 00 00 28 00 00 00 14 00 00 00 38 00 00 00 01 00 18 00 00 00 BMV.......6...(.......8.........
0020 00 00 20 0d 00 00 13 0b 00 00 13 0b 00 00 00 00 00 00 00 00 00 00 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 ................................
0040 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0060 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0080 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
00a0 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
00c0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
00e0 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
0100 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0120 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e5 c7 b3 ba a4 96 88 7c 74 6c 65 ............................|tle
0140 60 5b 56 53 54 50 4d 62 5b 56 80 73 6b b5 9f 91 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 `[VSTPMb[V.sk...................
0160 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 c2 ab 9b 6f 68 63 40 40 40 37 37 37 2e 2e 2e 29 29 29 .................ohc@@@777...)))
0180 26 26 26 26 26 26 29 29 29 28 28 28 57 4f 4a c1 a8 98 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc &&&&&&)))(((WOJ.................
01a0 b9 e6 c8 b4 e6 c8 b4 ab 98 8c 4c 4b 4a 36 36 36 23 23 23 13 13 13 0b 0b 0b 07 07 07 05 05 05 07 ..........LKJ666###.............
01c0 07 07 0d 0d 0d 13 13 13 16 16 16 25 23 21 a2 8e 80 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 ...........%#!..................
01e0 b2 9e 90 41 41 41 2e 2e 2e 19 19 19 07 07 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...AAA..........................
0200 00 02 02 02 07 07 07 0d 0d 0d 10 10 10 a9 93 85 e6 c8 b4 e8 cc b9 e8 cc b9 d3 b8 a6 4b 48 47 2b ............................KHG+
0220 2b 2b 10 10 10 04 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ++..............................
0240 01 01 01 06 06 06 06 06 06 1c 18 16 d7 bb a8 e8 cc b9 e8 cc b9 87 7a 71 31 31 31 19 19 19 05 05 ......................zq111.....
0260 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................................
0280 01 01 02 02 02 00 00 00 74 65 5b e8 cc b9 d0 b7 a7 47 44 42 22 22 22 0a 0a 0a 00 00 00 00 00 00 ........te[......GDB""".........
02a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 ................................
02c0 01 00 00 00 1e 1a 17 d2 b8 a7 a5 94 87 2a 2a 2a 16 16 16 01 01 01 00 00 00 00 00 00 00 00 00 00 .............***................
02e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 01 00 00 00 ................................
0300 00 00 00 a1 8e 80 84 76 6e 20 20 20 0d 0d 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .......vn.......................
0320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7d ...............................}
0340 6d 64 75 69 61 1b 1b 1b 09 09 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 mduia...........................
0360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 70 62 59 7b 6e ...........................pbY{n
0380 65 16 16 16 07 07 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e...............................
03a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7b 6c 62 97 85 7a 10 10 10 .......................{lb..z...
03c0 06 06 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
03e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9e 8b 7e c5 ae 9f 17 15 13 05 05 05 00 .....................~..........
0400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
0420 00 00 00 00 00 00 00 00 00 00 00 00 19 16 14 ce b5 a5 e8 cc b9 59 4e 46 01 01 01 00 00 00 00 00 .....................YNF........
0440 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
0460 00 00 00 00 00 00 00 00 67 59 50 e8 cc b9 e8 cc b9 c6 ac 9b 0d 0b 0a 00 00 00 00 00 00 00 00 00 ........gYP.....................
0480 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
04a0 00 14 11 10 cc b1 a0 e8 cc b9 e8 cc b9 e6 c8 b4 94 81 74 00 00 00 00 00 00 00 00 00 00 00 00 00 ..................t.............
04c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 02 01 9f 8a 7c ...............................|
04e0 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 7f 6f 64 02 02 01 00 00 00 00 00 00 00 00 00 00 00 ................od..............
0500 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 05 05 8d 7a 6e e6 c8 b4 e6 c8 b4 e8 .......................zn.......
0520 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 a3 8e 80 2e 28 24 00 00 00 00 00 00 00 00 00 00 00 00 ..................($............
0540 00 00 00 00 00 00 00 00 00 00 00 00 32 2b 27 ab 95 86 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc ............2+'.................
0560 b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e1 c3 b0 98 85 77 51 47 40 24 1f 1c 13 10 0f 13 10 0f 24 ..................wQG@$........$
0580 1f 1c 54 49 42 9d 88 7b e3 c6 b2 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 ..TIB..{........................
05a0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e5 c7 b3 b9 a1 91 8c 7a 6d 70 61 58 71 62 58 8d 7a 6e bb a2 ...................zmpaXqbX.zn..
05c0 92 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 ................................
05e0 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0600 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0620 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
0640 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0660 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0680 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
06a0 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
06c0 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
06e0 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 ................................
0700 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0720 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc ................................
0740 b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
0760 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 ................................
0780 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
07a0 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 ................................
07c0 c8 b4 e6 c8 b4 e5 c7 b3 c2 ad 9e 94 88 80 72 6b 66 5c 57 54 56 53 50 6d 66 61 8b 7e 76 ba a3 95 ..............rkf\WTVSPmfa.~v...
07e0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 c9 b2 ................................
0800 a2 74 6c 68 2b 2b 2b 05 05 05 00 00 00 00 00 00 00 00 00 00 00 00 07 07 07 24 24 24 5e 55 50 c3 .tlh+++..................$$$^UP.
0820 aa 9a e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 b3 a1 94 45 44 43 00 00 00 ..........................EDC...
0840 0a 09 08 51 47 40 94 81 74 b4 9d 8d b8 a0 90 91 7e 72 4e 43 3d 07 06 06 04 04 04 22 20 1f a4 8f ...QG@..t.......~rNC=......"....
0860 81 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 b9 a5 98 34 34 34 00 00 00 4e 44 3d c1 a8 97 e6 ...................444...ND=....
0880 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 bc a3 93 45 3c 36 00 00 00 0e 0e 0e a9 93 85 ....................E<6.........
08a0 e6 c8 b4 e8 cc b9 e8 cc b9 d6 bc aa 49 47 45 00 00 00 68 5a 51 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ............IGE...hZQ...........
08c0 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e4 c6 b3 59 4e 46 01 01 01 1b 18 15 d7 bb a8 e8 ...................YNF..........
08e0 cc b9 e8 cc b9 8e 81 78 0c 0c 0c 2b 26 22 e1 c3 b0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 .......x...+&"..................
0900 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 db bf ac 1e 1a 17 00 00 00 74 65 5b e8 cc b9 d4 bb ........................te[.....
0920 ab 41 3e 3c 00 00 00 98 84 77 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 .A><.....w......................
0940 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 88 76 6a 03 03 03 1e 1a 17 d2 b8 a7 ac 9a 8e 18 18 18 ...............vj...............
0960 17 14 12 d9 bd aa e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0980 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 d3 b8 a5 20 1e 1c 00 00 00 a1 8e 80 8c 7e 75 08 08 08 48 3f 38 e6 .......................~u...H?8.
09a0 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
09c0 e6 c8 b4 e6 c8 b4 e6 c8 b4 51 49 44 00 00 00 7d 6d 64 7c 70 68 03 03 03 64 57 4e e6 c8 b4 e6 c8 .........QID...}md|ph...dWN.....
09e0 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
0a00 c8 b4 e6 c8 b4 71 65 5e 00 00 00 70 62 59 7f 72 69 04 04 04 4b 41 3b e6 c8 b4 e6 c8 b4 e6 c8 b4 .....qe^...pbY.ri...KA;.........
0a20 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0a40 b4 61 59 54 00 00 00 7b 6c 62 99 87 7c 0a 0a 0a 1c 18 16 dd c0 ad e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 .aYT...{lb..|...................
0a60 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 da bf ac 3a 38 36 .............................:86
0a80 00 00 00 9e 8b 7e c5 ae 9e 1f 1d 1c 00 00 00 a1 8c 7e e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 .....~...........~..............
0aa0 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 b0 9c 90 19 19 19 19 16 14 ce ................................
0ac0 b5 a5 e8 cc b9 5b 4f 47 07 07 07 33 2d 28 e4 c6 b3 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 .....[OG...3-(..................
0ae0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e2 c5 b2 5d 57 54 00 00 00 67 59 50 e8 cc b9 e8 cc ..................]WT...gYP.....
0b00 b9 c6 ac 9b 0d 0b 0a 04 04 04 74 66 5c e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ..........tf\...................
0b20 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 92 85 7c 0d 0d 0d 14 11 10 cc b1 a0 e8 cc b9 e8 cc b9 e6 c8 b4 .............|..................
0b40 94 81 74 00 00 00 0e 0e 0e 71 66 5e ce b4 a3 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ..t......qf^....................
0b60 b4 d4 ba a9 8a 7f 78 1f 1f 1f 02 02 01 9f 8a 7c e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 7f ......x........|................
0b80 6f 64 00 00 00 00 00 00 39 37 35 83 77 6f b7 a2 94 d2 b8 a6 d3 b9 a8 be a9 9b 92 86 7e 4a 48 47 od......975.wo..............~JHG
0ba0 05 05 05 05 05 04 8d 7a 6e e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 a3 8e .......zn.......................
0bc0 80 2e 28 24 00 00 00 00 00 00 10 10 10 25 25 24 2c 2c 2b 1f 1f 1f 00 00 00 00 00 00 32 2b 27 ab ..($.........%%$,,+.........2+'.
0be0 95 86 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e1 c3 b0 ................................
0c00 98 85 77 51 47 40 23 1f 1c 0f 0d 0c 10 0e 0d 24 1f 1c 54 49 42 9d 88 7b e3 c6 b2 e6 c8 b4 e6 c8 ..wQG@#........$..TIB..{........
0c20 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e5 c7 b3 b9 ................................
0c40 a1 91 8c 7a 6d 70 61 58 71 62 58 8d 7a 6e bb a2 92 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ...zmpaXqbX.zn..................
0c60 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0c80 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 ................................
0ca0 cc b9 e8 cc b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 ................................
0cc0 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc ................................
0ce0 b9 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 ................................
0d00 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 e8 cc b9 e6 c8 b4 ................................
0d20 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 ................................
0d40 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e6 c8 b4 e8 cc b9 ......................
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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Parser for MPEG streams
 *
 * Copyright (c) 2007 Michael Sevakis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "plugin.h"
#include "mpegplayer.h"

struct stream_parser str_parser SHAREDBSS_ATTR;

static void parser_init_state(void)
{
    str_parser.last_seek_time = 0;
    str_parser.format = STREAM_FMT_UNKNOWN;
    str_parser.start_pts = INVALID_TIMESTAMP;
    str_parser.end_pts = INVALID_TIMESTAMP;
    str_parser.flags = 0;
    str_parser.dims.w = 0;
    str_parser.dims.h = 0;
}

/* Place the stream in a state to begin parsing - sync will be performed
 * first */
void str_initialize(struct stream *str, off_t pos)
{
    /* Initial positions start here */
    str->hdr.win_left = str->hdr.win_right = pos;
    /* No packet */
    str->curr_packet = NULL;
    /* Pick up parsing from this point in the buffer */
    str->curr_packet_end = disk_buf_offset2ptr(pos);
    /* No flags */
    str->pkt_flags = 0;
    /* Sync first */
    str->state = SSTATE_SYNC;
}

/* Place the stream in an end of data state */
void str_end_of_stream(struct stream *str)
{
    /* Offsets that prevent this stream from being included in the
     * min left/max right window so that no buffering is triggered on
     * its behalf. Set right to the min first so a thread reading the
     * overall window gets doesn't see this as valid no matter what the
     * file length. */
    str->hdr.win_right = LONG_MIN;
    str->hdr.win_left = LONG_MAX;
    /* No packets */
    str->curr_packet = str->curr_packet_end = NULL;
    /* No flags */
    str->pkt_flags = 0;
    /* Fin */
    str->state = SSTATE_END;
}

/* Return a timestamp at address p+offset if the marker bits are in tact */
static inline uint32_t read_pts(uint8_t *p, off_t offset)
{
    return TS_CHECK_MARKERS(p, offset) ?
        TS_FROM_HEADER(p, offset) : INVALID_TIMESTAMP;
}

static inline bool validate_timestamp(uint32_t ts)
{
    return ts >= str_parser.start_pts && ts <= str_parser.end_pts;
}

/* Find a start code before or after a given position */
uint8_t * mpeg_parser_scan_start_code(struct stream_scan *sk, uint32_t code)
{
    stream_scan_normalize(sk);

    if (sk->dir < 0)
    {
        /* Reverse scan - start with at least the min needed */
        stream_scan_offset(sk, 4);
    }

    code &= 0xff; /* Only the low byte matters */

    while (sk->len >= 0 && sk->margin >= 4)
    {
        uint8_t *p;
        off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
        ssize_t len = disk_buf_getbuffer(4, &p, NULL, NULL);

        if (pos < 0 || len < 4)
            break;

        if (CMP_3_CONST(p, PACKET_START_CODE_PREFIX) && p[3] == code)
        {
            return p;
        }

        stream_scan_offset(sk, 1);
    }

    return NULL;
}

/* Find a PES packet header for any stream - return stream to which it
 * belongs */
unsigned mpeg_parser_scan_pes(struct stream_scan *sk)
{
    stream_scan_normalize(sk);

    if (sk->dir < 0)
    {
        /* Reverse scan - start with at least the min needed */
        stream_scan_offset(sk, 4);
    }

    while (sk->len >= 0 && sk->margin >= 4)
    {
        uint8_t *p;
        off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
        ssize_t len = disk_buf_getbuffer(4, &p, NULL, NULL);

        if (pos < 0 || len < 4)
            break;

        if (CMP_3_CONST(p, PACKET_START_CODE_PREFIX))
        {
            unsigned id = p[3];
            if (id >= 0xb9)
                return id;  /* PES header */
            /* else some video stream element */
        }

        stream_scan_offset(sk, 1);
    }

    return -1;
}

/* Return the first SCR found from the scan direction */
uint32_t mpeg_parser_scan_scr(struct stream_scan *sk)
{
    uint8_t *p = mpeg_parser_scan_start_code(sk, MPEG_STREAM_PACK_HEADER);

    if (p != NULL && sk->margin >= 9) /* 9 bytes total required */
    {
        sk->data = 9;

        if ((p[4] & 0xc0) == 0x40)      /* mpeg-2 */
        {
            /* Lookhead p+8 */
            if (MPEG2_CHECK_PACK_SCR_MARKERS(p, 4))
                return MPEG2_PACK_HEADER_SCR(p, 4);
        }
        else if ((p[4] & 0xf0) == 0x20) /* mpeg-1 */
        {
            /* Lookahead p+8 */
            if (TS_CHECK_MARKERS(p, 4))
                return TS_FROM_HEADER(p, 4);
        }
        /* Weird pack header */
        sk->data = 5;
    }

    return INVALID_TIMESTAMP;
}

uint32_t mpeg_parser_scan_pts(struct stream_scan *sk, unsigned id)
{
    stream_scan_normalize(sk);

    if (sk->dir < 0)
    {
        /* Reverse scan - start with at least the min needed */
        stream_scan_offset(sk, 4);
    }

    while (sk->len >= 0 && sk->margin >= 4)
    {
        uint8_t *p;
        off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
        ssize_t len = disk_buf_getbuffer(35, &p, NULL, NULL);

        if (pos < 0 || len < 4)
            break;

        if (CMP_3_CONST(p, PACKET_START_CODE_PREFIX) && p[3] == id)
        {
            uint8_t *h = p;

            if (sk->margin < 6)
            {
                /* Insufficient data */
            }
            else if ((h[6] & 0xc0) == 0x80) /* mpeg2 */
            {
                if (sk->margin >= 14 && (h[7] & 0x80) != 0x00)
                {
                    sk->data = 14;
                    return read_pts(h, 9);
                }
            }
            else                            /* mpeg1 */
            {
                ssize_t l = 7;
                ssize_t margin = sk->margin;

                /* Skip stuffing_byte */
                while (h[l - 1] == 0xff && ++l <= 23)
                    --margin;

                if ((h[l - 1] & 0xc0) == 0x40)
                {
                    /* Skip STD_buffer_scale and STD_buffer_size */
                    margin -= 2;
                    l += 2;
                }

                if (margin >= 4)
                {
                    /* header points to the mpeg1 pes header */
                    h += l;

                    if ((h[-1] & 0xe0) == 0x20)
                    {
                        sk->data = (h + 4) - p;
                        return read_pts(h, -1);
                    }
                }
            }
            /* No PTS present - keep searching for a matching PES header with
             * one */
        }

        stream_scan_offset(sk, 1);
    }

    return INVALID_TIMESTAMP;
}

static bool init_video_info(void)
{
    DEBUGF("Getting movie size\n");

    /* The decoder handles this in order to initialize its knowledge of the
     * movie parameters making seeking easier */
    str_send_msg(&video_str, STREAM_RESET, 0);
    if (str_send_msg(&video_str, VIDEO_GET_SIZE,
                     (intptr_t)&str_parser.dims) != 0)
    {
        return true;
    }

    DEBUGF("  failed\n");
    return false;
}

static void init_times(struct stream *str)
{
    int i;
    struct stream tmp_str;
    const ssize_t filesize = disk_buf_filesize();
    const ssize_t max_probe = MIN(512*1024, filesize);

    /* Simply find the first earliest timestamp - this will be the one
     * used when streaming anyway */
    DEBUGF("Finding start_pts: 0x%02x\n", str->id);

    tmp_str.id = str->id;
    tmp_str.hdr.pos = 0;
    tmp_str.hdr.limit = max_probe;

    str->start_pts = INVALID_TIMESTAMP;

    /* Probe many for video because of B-frames */
    for (i = STREAM_IS_VIDEO(str->id) ? 5 : 1; i > 0;)
    {
        switch (parser_get_next_data(&tmp_str, STREAM_PM_RANDOM_ACCESS))
        {
        case STREAM_DATA_END:
            break;
        case STREAM_OK:
            if (tmp_str.pkt_flags & PKT_HAS_TS)
            {
                if (tmp_str.pts < str->start_pts)
                   str->start_pts = tmp_str.pts;
                i--; /* Decrement timestamp counter */
            }
            continue;
        }

        break;
    }

    DEBUGF("  start:%u\n", (unsigned)str->start_pts);

    /* Use the decoder thread to perform a synchronized search - no
     * decoding should take place but just a simple run through timestamps
     * and durations as the decoder would see them. This should give the
     * precise time at the end of the last frame for the stream. */
    DEBUGF("Finding end_pts: 0x%02x\n", str->id);

    str->end_pts = INVALID_TIMESTAMP;

    if (str->start_pts != INVALID_TIMESTAMP)
    {
        str_parser.parms.sd.time = MAX_TIMESTAMP;
        str_parser.parms.sd.sk.pos = filesize - max_probe;
        str_parser.parms.sd.sk.len = max_probe;
        str_parser.parms.sd.sk.dir = SSCAN_FORWARD;

        str_send_msg(str, STREAM_RESET, 0);

        if (str_send_msg(str, STREAM_FIND_END_TIME,
                (intptr_t)&str_parser.parms.sd) == STREAM_PERFECT_MATCH)
        {
            str->end_pts = str_parser.parms.sd.time;
            DEBUGF("  end:%u\n", (unsigned)str->end_pts);
        }
    }

    /* End must be greater than start. If the start PTS is found, the end PTS
     * must be valid too. If the start PTS was invalid, then the end will never
     * be scanned above. */
    if (str->start_pts >= str->end_pts || str->end_pts == INVALID_TIMESTAMP)
    {
        str->start_pts = INVALID_TIMESTAMP;
        str->end_pts = INVALID_TIMESTAMP;
    }
}

/* Return the best-fit file offset of a timestamp in the PES where
 * timstamp <= time < next timestamp. Will try to return something reasonably
 * valid if best-fit could not be made. */
static off_t mpeg_parser_seek_PTS(uint32_t time, unsigned id)
{
    ssize_t pos_left = 0;
    ssize_t pos_right = disk_buf.filesize;
    ssize_t pos, pos_new;
    uint32_t time_left = str_parser.start_pts;
    uint32_t time_right = str_parser.end_pts;
    uint32_t pts = 0;
    uint32_t prevpts = 0;
    enum state_enum state = state0;
    struct stream_scan sk;

    /* Initial estimate taken from average bitrate - later interpolations are
     * taken similarly based on the remaining file interval */
    pos_new = muldiv_uint32(time - time_left, pos_right - pos_left,
                            time_right - time_left) + pos_left;

    /* return this estimated position if nothing better comes up */
    pos = pos_new;

    DEBUGF("Seeking stream 0x%02x\n", id);
    DEBUGF("$$ tl:%u t:%u ct:?? tr:%u\n   pl:%ld pn:%ld pr:%ld\n",
           (unsigned)time_left, (unsigned)time, (unsigned)time_right,
           pos_left, pos_new, pos_right);

    sk.dir = SSCAN_REVERSE;

    while (state < state9)
    {
        uint32_t currpts;
        sk.pos = pos_new;
        sk.len = (sk.dir < 0) ? pos_new - pos_left : pos_right - pos_new;

        currpts = mpeg_parser_scan_pts(&sk, id);

        if (currpts != INVALID_TIMESTAMP)
        {
            ssize_t pos_adj; /* Adjustment to over or under-estimate */

            /* Found a valid timestamp - see were it lies in relation to
             * target */
            if (currpts < time)
            {
                /* Time at current position is before seek time - move
                 * forward */
                if (currpts > pts)
                {
                    /* This is less than the desired time but greater than
                     * the currently seeked one; move the position up */
                    pts = currpts;
                    pos = sk.pos;
                }

                /* No next timestamp can be sooner */
                pos_left = sk.pos + sk.data;
                time_left = currpts;

                if (pos_right <= pos_left)
                    break; /* If the window disappeared - we're done */

                pos_new = muldiv_uint32(time - time_left,
                                        pos_right - pos_left,
                                        time_right - time_left);
                /* Point is ahead of us - fudge estimate a bit high */
                pos_adj = pos_new / 10;

                if (pos_adj > 512*1024)
                    pos_adj = 512*1024;

                pos_new += pos_left + pos_adj;

                if (pos_new >= pos_right)
                {
                    /* Estimate could push too far */
                    pos_new = pos_right;
                }

                state = state2; /* Last scan was early */
                sk.dir = SSCAN_REVERSE;
   
                DEBUGF(">> tl:%u t:%u ct:%u tr:%u\n   pl:%ld pn:%ld pr:%ld\n",
                       (unsigned)time_left, (unsigned)time, (unsigned)currpts,
                       (unsigned)time_right, pos_left, pos_new, pos_right);
            }
            else if (currpts > time)
            {
                /* Time at current position is past seek time - move
                   backward */
                pos_right = sk.pos;
                time_right = currpts;

                if (pos_right <= pos_left)
                    break; /* If the window disappeared - we're done */

                pos_new = muldiv_uint32(time - time_left,
                                        pos_right - pos_left,
                                        time_right - time_left);
                /* Overshot the seek point - fudge estimate a bit low */
                pos_adj = pos_new / 10;

                if (pos_adj > 512*1024)
                    pos_adj = 512*1024;

                pos_new += pos_left - pos_adj;

                state = state3; /* Last scan was late */
                sk.dir = SSCAN_REVERSE;

                DEBUGF("<< tl:%u t:%u ct:%u tr:%u\n   pl:%ld pn:%ld pr:%ld\n",
                       (unsigned)time_left, (unsigned)time, (unsigned)currpts,
                       (unsigned)time_right, pos_left, pos_new, pos_right);
            }
            else
            {
                /* Exact match - it happens */
                DEBUGF("|| tl:%u t:%u ct:%u tr:%u\n   pl:%ld pn:%ld pr:%ld\n",
                       (unsigned)time_left, (unsigned)time, (unsigned)currpts,
                       (unsigned)time_right, pos_left, pos_new, pos_right);
                pts = currpts;
                pos = sk.pos;
                state = state9;
            }
        }
        else
        {
            /* Nothing found */

            switch (state)
            {
            case state1:
                /* We already tried the bruteforce scan and failed again - no
                 * more stamps could possibly exist in the interval */
                DEBUGF("!! no timestamp 2x\n");
                break;
            case state0:
                /* Hardly likely except at very beginning - just do L->R scan
                 * to find something */
                DEBUGF("!! no timestamp on first probe: %ld\n", sk.pos);
            case state2:
            case state3:
                /* Could just be missing timestamps because the interval is
                 * narrowing down. A large block of data from another stream
                 * may also be in the midst of our chosen points which could
                 * cluster at either extreme end. If anything is there, this
                 * will find it. */
                pos_new = pos_left;
                sk.dir = SSCAN_FORWARD;
                DEBUGF("?? tl:%u t:%u ct:%u tr:%u\n   pl:%ld pn:%ld pr:%ld\n",
                       (unsigned)time_left, (unsigned)time, (unsigned)currpts,
                       (unsigned)time_right, pos_left, pos_new, pos_right);
                state = state1;
                break;
            default:
                DEBUGF("?? Invalid state: %d\n", state);
            }
        }

        /* Same timestamp twice = quit */
        if (currpts == prevpts)
        {
            DEBUGF("!! currpts == prevpts (stop)\n");
            state = state9;
        }

        prevpts = currpts;
    }

#if defined(DEBUG) || defined(SIMULATOR)
    /* The next pts after the seeked-to position should be greater -
     * most of the time - frames out of presentation order may muck it
     * up a slight bit */
    sk.pos = pos + 1;
    sk.len = disk_buf.filesize;
    sk.dir = SSCAN_FORWARD;

    uint32_t nextpts = mpeg_parser_scan_pts(&sk, id);
    DEBUGF("Seek pos:%ld pts:%u t:%u next pts:%u \n",
        pos, (unsigned)pts, (unsigned)time, (unsigned)nextpts);

    if (pts <= time && time < nextpts)
    {
        /* Smile - it worked */
        DEBUGF("  :) pts<=time<next pts\n");
    }
    else
    {
        /* See where things ended up */
        if (pts > time)
        {
            /* Hmm */
            DEBUGF("  :\\ pts>time\n");
        }
        if (pts >= nextpts)
        {
            /* Weird - probably because of encoded order & tends to be right
             * anyway if other criteria are met */
            DEBUGF("  :p pts>=next pts\n");
        }
        if (time >= nextpts)
        {
            /* Ugh */
            DEBUGF("  :( time>=nextpts\n");
        }
    }
#endif

    return pos;
}

static bool prepare_image(uint32_t time)
{
    struct stream_scan sk;
    int tries;
    int result;

    if (!str_send_msg(&video_str, STREAM_NEEDS_SYNC, time))
    {
        DEBUGF("Image was ready\n");
        return true; /* Should already have the image */
    }

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(true); /* No interference with trigger_cpu_boost */
#endif

    str_send_msg(&video_str, STREAM_RESET, 0);

    sk.pos = parser_can_seek() ?
                mpeg_parser_seek_PTS(time, video_str.id) : 0;
    sk.len = sk.pos;
    sk.dir = SSCAN_REVERSE;

    tries = 1;
try_again:

    if (mpeg_parser_scan_start_code(&sk, MPEG_START_GOP))
    {
        DEBUGF("GOP found at: %ld\n", sk.pos);

        unsigned id = mpeg_parser_scan_pes(&sk);

        if (id != video_str.id && sk.pos > 0)
        {
            /* Not part of our stream */
            DEBUGF("  wrong stream: 0x%02x\n", id);
            goto try_again;
        }

        /* This will hit the PES header since it's known to be there */
        uint32_t pts = mpeg_parser_scan_pts(&sk, id);

        if (pts == INVALID_TIMESTAMP || pts > time)
        {
            DEBUGF("  wrong timestamp: %u\n", (unsigned)pts);
            goto try_again;
        }
    }

    str_parser.parms.sd.time = time;
    str_parser.parms.sd.sk.pos = MAX(sk.pos, 0);
    str_parser.parms.sd.sk.len = 1024*1024;
    str_parser.parms.sd.sk.dir = SSCAN_FORWARD;

    DEBUGF("thumb pos:%ld len:%ld\n", str_parser.parms.sd.sk.pos,
           str_parser.parms.sd.sk.len);

    result = str_send_msg(&video_str, STREAM_SYNC,
                          (intptr_t)&str_parser.parms.sd);

    if (result != STREAM_PERFECT_MATCH)
    {
        /* Two tries should be all that is nescessary to find the exact frame
         * if the first GOP actually started later than the timestamp - the
         * GOP just prior must then start on or earlier. */
        if (++tries <= 2)
            goto try_again;
    }

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(false);
#endif

    return result > STREAM_OK;
}

static void prepare_audio(uint32_t time)
{
    off_t pos;

    if (!str_send_msg(&audio_str, STREAM_NEEDS_SYNC, time))
    {
        DEBUGF("Audio was ready\n");
        return;
    }

    pos = mpeg_parser_seek_PTS(time, audio_str.id);
    str_send_msg(&audio_str, STREAM_RESET, 0);

    str_parser.parms.sd.time = time;
    str_parser.parms.sd.sk.pos = pos;
    str_parser.parms.sd.sk.len = 1024*1024;
    str_parser.parms.sd.sk.dir = SSCAN_FORWARD;

    str_send_msg(&audio_str, STREAM_SYNC, (intptr_t)&str_parser.parms.sd);
}

/* This function demuxes the streams and gives the next stream data
 * pointer.
 *
 * STREAM_PM_STREAMING is for operation during playback. If the nescessary
 * data and worst-case lookahead margin is not available, the stream is
 * registered for notification when the data becomes available. If parsing
 * extends beyond the end of the file or the end of stream marker is reached,
 * STREAM_DATA_END is returned and the stream state changed to SSTATE_EOS.
 *
 * STREAM_PM_RANDOM_ACCESS is for operation when not playing such as seeking.
 * If the file cache misses for the current position + lookahead, it will be
 * loaded from disk. When the specified limit is reached, STREAM_DATA_END is
 * returned.
 *
 * The results from one mode may be used as input to the other. Random access
 * requires cooperation amongst threads to avoid evicting another stream's
 * data.
 */
static int parse_demux(struct stream *str, enum stream_parse_mode type)
{
    #define INC_BUF(offset) \
        ({ off_t _o = (offset);           \
           str->hdr.win_right += _o;      \
           if ((p += _o) >= disk_buf.end) \
                p -= disk_buf.size; })

    static const int mpeg1_skip_table[16] =
        { 0, 0, 4, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

    uint8_t *p = str->curr_packet_end;

    str->pkt_flags = 0;

    while (1)
    {
        uint8_t *header;
        unsigned id;
        ssize_t length, bytes;

        switch (type)
        {
        case STREAM_PM_STREAMING:
            /* Has the end been reached already? */
            switch (str->state)
            {
            case SSTATE_PARSE: /* Expected case first if no jumptable */
                /* Are we at the end of file? */
                if (str->hdr.win_left < disk_buf.filesize)
                    break;
                str_end_of_stream(str);
                return STREAM_DATA_END;

            case SSTATE_SYNC:
                /* Is sync at the end of file? */
                if (str->hdr.win_right < disk_buf.filesize)
                    break;
                str_end_of_stream(str);
                /* Fall-through */
            case SSTATE_END:
                return STREAM_DATA_END;
            }

            if (!disk_buf_is_data_ready(&str->hdr, MIN_BUFAHEAD))
            {
                /* This data range is not buffered yet - register stream to
                 * be notified when it becomes available. Stream is obliged
                 * to enter a TSTATE_DATA state if it must wait. */
                int res = str_next_data_not_ready(str);

                if (res != STREAM_OK)
                    return res;
            }
            break;
            /* STREAM_PM_STREAMING: */

        case STREAM_PM_RANDOM_ACCESS:
            str->hdr.pos = disk_buf_lseek(str->hdr.pos, SEEK_SET);

            if (str->hdr.pos < 0 || str->hdr.pos >= str->hdr.limit ||
                disk_buf_getbuffer(MIN_BUFAHEAD, &p, NULL, NULL) <= 0)
            {
                str_end_of_stream(str);
                return STREAM_DATA_END;
            }

            str->state = SSTATE_SYNC;
            str->hdr.win_left = str->hdr.pos;
            str->curr_packet = NULL;
            str->curr_packet_end = p;
            break;
            /* STREAM_PM_RANDOM_ACCESS: */
        }

        if (str->state == SSTATE_SYNC)
        {
            /* Scanning for start code */
            if (!CMP_3_CONST(p, PACKET_START_CODE_PREFIX))
            {
                INC_BUF(1);
                continue;
            }
        }

        /* Found a start code - enter parse state */
        str->state = SSTATE_PARSE;

        /* Pack header, skip it */
        if (CMP_4_CONST(p, PACK_START_CODE))
        {
            /* Max lookahead: 14 */
            if ((p[4] & 0xc0) == 0x40)      /* mpeg-2 */
            {
                /* Max delta: 14 + 7 = 21 */
                /* Skip pack header and any stuffing bytes*/
                bytes = 14 + (p[13] & 7);
            }
            else if ((p[4] & 0xf0) == 0x20) /* mpeg-1 */
            {
                bytes = 12;
            }
            else                            /* unknown - skip it */
            {
                DEBUGF("weird pack header!\n");
                bytes = 5;
            }

            INC_BUF(bytes);
        }

        /* System header, parse and skip it - 6 bytes + size */
        if (CMP_4_CONST(p, SYSTEM_HEADER_START_CODE))
        {
            /* Skip start code */
            /* Max Delta = 65535 + 6 = 65541 */
            bytes = 6 + ((p[4] << 8) | p[5]);
            INC_BUF(bytes);
        }

        /* Packet header, parse it */
        if (!CMP_3_CONST(p, PACKET_START_CODE_PREFIX))
        {
            /* Problem? Meh...probably not but just a corrupted section.
             * Try to resync the parser which will probably succeed. */
            DEBUGF("packet start code prefix not found: 0x%02x\n"
                   "  wl:%lu wr:%lu\n"
                   "  p:%p cp:%p cpe:%p\n"
                   "  dbs:%p dbe:%p dbt:%p\n",
                   str->id, str->hdr.win_left, str->hdr.win_right,
                   p, str->curr_packet, str->curr_packet_end,
                   disk_buf.start, disk_buf.end, disk_buf.tail);
            str->state = SSTATE_SYNC;
            INC_BUF(1); /* Next byte - this one's no good */
            continue;
        }

        /* We retrieve basic infos */
        /* Maximum packet length: 6 + 65535 = 65541 */
        id = p[3];
        length = ((p[4] << 8) | p[5]) + 6;

        if (id != str->id)
        {
            switch (id)
            {
            case MPEG_STREAM_PROGRAM_END:
                /* end of stream */
                str_end_of_stream(str);
                DEBUGF("MPEG program end: 0x%02x\n", str->id);
                return STREAM_DATA_END;
            case MPEG_STREAM_PACK_HEADER:
            case MPEG_STREAM_SYSTEM_HEADER:
                /* These shouldn't be here - no increment or resync
                 * since we'll pick it up above. */
                continue;
            default:
                /* It's not the packet we're looking for, skip it */
                INC_BUF(length);
                continue;
            }
        }

        /* Ok, it's our packet */
        header = p;

        if ((header[6] & 0xc0) == 0x80) /* mpeg2 */
        {
            /* Max Lookahead: 18         */
            /* Min length: 9             */
            /* Max length: 9 + 255 = 264 */
            length = 9 + header[8];

            /* header points to the mpeg2 pes header */
            if ((header[7] & 0x80) != 0)
            {
                /* header has a pts */
                uint32_t pts = read_pts(header, 9);

                if (pts != INVALID_TIMESTAMP)
                {
                    str->pts = pts;
#if 0
                   /* DTS isn't used for anything since things just get
                      decoded ASAP but keep the code around */
                    if (STREAM_IS_VIDEO(id))
                    {
                        /* Video stream - header may have a dts as well */
                        str->dts = pts;

                        if (header[7] & 0x40) != 0x00)
                        {
                            pts = read_pts(header, 14);
                            if (pts != INVALID_TIMESTAMP)
                                str->dts = pts;
                        }
                    }
#endif
                    str->pkt_flags |= PKT_HAS_TS;
                }
            }
        }
        else                            /* mpeg1 */
        {
            /* Max lookahead: 24 + 2 + 9 = 35 */
            /* Max len_skip: 24 + 2 = 26      */
            /* Min length: 7                  */
            /* Max length: 24 + 2 + 9 = 35    */
            off_t len_skip;
            uint8_t * ptsbuf;

            length = 7;

            while (header[length - 1] == 0xff)
            {
                if (++length > 23)
                {
                    DEBUGF("Too much stuffing" );
                    break;
                }
            }

            if ((header[length - 1] & 0xc0) == 0x40)
                length += 2;

            len_skip = length;
            length += mpeg1_skip_table[header[length - 1] >> 4];

            /* Header points to the mpeg1 pes header */
            ptsbuf = header + len_skip;

            if ((ptsbuf[-1] & 0xe0) == 0x20 && TS_CHECK_MARKERS(ptsbuf, -1))
            {
                /* header has a pts */
                uint32_t pts = read_pts(ptsbuf, -1);

                if (pts != INVALID_TIMESTAMP)
                {
                    str->pts = pts;
#if 0
                    /* DTS isn't used for anything since things just get
                       decoded ASAP but keep the code around */
                    if (STREAM_IS_VIDEO(id))
                    {
                        /* Video stream - header may have a dts as well */
                        str->dts = pts;

                        if (ptsbuf[-1] & 0xf0) == 0x30)
                        {
                            pts = read_pts(ptsbuf, 4);

                            if (pts != INVALID_TIMESTAMP)
                                str->dts = pts;
                        }
                    }
#endif
                    str->pkt_flags |= PKT_HAS_TS;
                }
            }
        }

        p += length;