0
|
1 /*
|
|
2 * PWPlib: PWP Video Phormat
|
|
3 *
|
|
4 * not very functional yet :)
|
|
5 *
|
|
6 */
|
|
7
|
|
8 #include "config.h"
|
|
9
|
|
10 #ifdef DRIVE_PVP
|
|
11
|
|
12 #include <stdlib.h>
|
|
13 #include <stdio.h>
|
|
14 #include <string.h>
|
|
15
|
|
16 #include "pwplib.h"
|
|
17
|
|
18 void pvp_calcframe(u8*s,int lgtnew,int flags)
|
|
19 {
|
|
20
|
|
21 static int lgt=0;
|
|
22 static u8*prev=NULL;
|
|
23
|
|
24 TEMPMALL(u8,buf,lgtnew*2),*d=buf;
|
|
25
|
|
26 int accum=0;
|
|
27
|
|
28 if(lgtnew!=lgt)
|
|
29 {
|
|
30 if(prev!=NULL)free(prev);
|
|
31 lgt=lgtnew;
|
|
32 prev=malloc(lgt*sizeof(u8));
|
|
33 flags|=1;
|
|
34 }
|
|
35
|
|
36 if(flags&1)memset(s,0,lgt*sizeof(u8)); /* support other consts as well? */
|
|
37
|
|
38 {int i=0,skip=0;
|
|
39 for(;i<lgt;i++)
|
|
40 {
|
|
41 if(s[i]!=prev[i])
|
|
42 {
|
|
43 while(skip>0)
|
|
44 {
|
|
45 if(skip<128){*d++=128|((skip-1)&127);skip=0;}
|
|
46 else {*d++=128|127;skip-=128;}
|
|
47 }
|
|
48
|
|
49 {u8*cntp=d;
|
|
50 int gap=0;
|
|
51
|
|
52 while(gap<2 && i<lgt && (d-cntp<126))
|
|
53 {
|
|
54 d++;
|
|
55 *d=s[i];
|
|
56
|
|
57 if(s[i]==prev[i])gap++;
|
|
58 else gap=0;
|
|
59 i++;
|
|
60 }
|
|
61 d[1]=s[i];
|
|
62 d[2]=s[i+1];
|
|
63 d+=2-gap;skip+=gap-1;i--;
|
|
64 *cntp=(d-cntp-1)&127;
|
|
65 }
|
|
66 }
|
|
67 else skip++;
|
|
68 }}
|
|
69 memcpy(prev,s,sizeof(u8)*lgt);
|
|
70
|
|
71 /* header */
|
|
72
|
|
73 {u8 head[6];
|
|
74 head[0]='p';head[1]='V';head[2]='P';
|
|
75 if(flags&1)head[3]='R';else head[3]='r';
|
|
76 head[4]=(d-buf)&255;
|
|
77 head[5]=(d-buf)>>8;
|
|
78 write(1,head,6);
|
|
79 }
|
|
80
|
|
81 write(1,buf,d-buf);
|
|
82
|
|
83 TEMPFREE(buf);
|
|
84 }
|
|
85
|
|
86
|
|
87
|
|
88 /*
|
|
89 pvp (pwp video phormat) stream:
|
|
90
|
|
91 for each frame:
|
|
92 'pVP' signature (used by synch routines etc)
|
|
93 u8 frame type
|
|
94 u16 frame length, in bytes
|
|
95
|
|
96 r-frame (lossless rasterdata)
|
|
97
|
|
98 stored: changes to the previous display frame, rle+huffman compression?
|
|
99
|
|
100 time delta to the previous frame (in second/256's)
|
|
101
|
|
102 index=0;
|
|
103
|
|
104 command
|
|
105 - 1xxxxxxx skip 0..127 bytes
|
|
106 - 0xxxxxxx 0..127 bytes of data follow
|
|
107
|
|
108 R-frame (lossless raster keyframe)
|
|
109
|
|
110 stored as delta to a constant (zero) table
|
|
111
|
|
112 i/I-frames == like r/R but for ibm char/attribute-pair screendump
|
|
113
|
|
114 we need some kind of compression for the lossless frames.
|
|
115
|
|
116 we also need a low-bandwidth lossy compression for longer movies and
|
|
117 tv streams.
|
|
118
|
|
119 g-frame (gsm audio in 8kHz) for moviez
|
|
120
|
|
121 b-frame (beep audio)
|
|
122 (B-frame == update everything? write a B-frame when every channel
|
|
123 changes or when above given threshold)
|
|
124
|
|
125 length of output (in second/256's)
|
|
126 chan# (8bit), freq(16bit), vol(8bit), pulsestat(8bit)
|
|
127
|
|
128 c-frame (commentary)
|
|
129
|
|
130 first byte==importance level (signed byte, 0==for names, copyrights etc)
|
|
131 rest==ascii string
|
|
132
|
|
133 may also contain things like stupid irclog, subtitles, textual
|
|
134 descriptions of the video etc
|
|
135
|
|
136 */
|
|
137
|
|
138 void pvp_sound(int ch,int note,int vol,int ratio)
|
|
139 {
|
|
140
|
|
141 }
|
|
142
|
|
143 void pvp_loopflush()
|
|
144 {
|
|
145 /*
|
|
146 timer_counter();
|
|
147 pwplib.player();
|
|
148
|
|
149 save b-frames
|
|
150 */
|
|
151 }
|
|
152
|
|
153 void pvp_dump_rast()
|
|
154 {
|
|
155 if(pwplib.setup[SETUP_LOSSY])
|
|
156 conv_losestuff(pwplib.videobuf.d,
|
|
157 pwplib.videobuf.height*pwplib.videobuf.width,1);
|
|
158
|
|
159 pvp_calcframe(pwplib.videobuf.d,
|
|
160 pwplib.videobuf.width*pwplib.videobuf.height,0);
|
|
161 }
|
|
162
|
|
163 void pvp_dump_ibm()
|
|
164 {
|
|
165 pvp_calcframe(pwplib.videobuf.d,
|
|
166 pwplib.videobuf.width*pwplib.videobuf.height*2,0);
|
|
167 }
|
|
168
|
|
169 void pvp_init()
|
|
170 {
|
|
171 pwplib.videobuf.height=50;
|
|
172 pwplib.videobuf.width=80;
|
|
173
|
|
174 pwplib.dump_attr=&pvp_dump_ibm;
|
|
175 pwplib.dump_rast=&pvp_dump_rast;
|
|
176 pwplib.sound=pvp_sound;
|
|
177 pwplib.loopflush=&pvp_loopflush;
|
|
178 }
|
|
179
|
|
180 #endif
|