Changeset 128 for CoolStreaming
- Timestamp:
- Jan 16, 2011, 4:31:02 PM (14 years ago)
- Location:
- CoolStreaming
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/Demo/DynNumber/DynNumberDemo.lpi
r127 r128 39 39 </Item2> 40 40 </RequiredPackages> 41 <Units Count="1 5">41 <Units Count="16"> 42 42 <Unit0> 43 43 <Filename Value="DynNumberDemo.lpr"/> … … 47 47 <TopLine Value="1"/> 48 48 <CursorPos X="41" Y="19"/> 49 <UsageCount Value=" 39"/>49 <UsageCount Value="42"/> 50 50 </Unit0> 51 51 <Unit1> … … 58 58 <EditorIndex Value="0"/> 59 59 <WindowIndex Value="0"/> 60 <TopLine Value=" 39"/>61 <CursorPos X=" 24" Y="53"/>62 <UsageCount Value=" 39"/>60 <TopLine Value="50"/> 61 <CursorPos X="34" Y="61"/> 62 <UsageCount Value="42"/> 63 63 <Loaded Value="True"/> 64 64 <LoadedDesigner Value="True"/> … … 67 67 <Filename Value="..\..\UDynNumber.pas"/> 68 68 <UnitName Value="UDynNumber"/> 69 <EditorIndex Value=" 1"/>70 <WindowIndex Value="0"/> 71 <TopLine Value="1 1"/>72 <CursorPos X=" 8" Y="14"/>73 <UsageCount Value="2 0"/>69 <EditorIndex Value="2"/> 70 <WindowIndex Value="0"/> 71 <TopLine Value="1"/> 72 <CursorPos X="17" Y="10"/> 73 <UsageCount Value="21"/> 74 74 <Loaded Value="True"/> 75 75 </Unit2> … … 79 79 <EditorIndex Value="4"/> 80 80 <WindowIndex Value="0"/> 81 <TopLine Value=" 37"/>82 <CursorPos X=" 14" Y="53"/>83 <UsageCount Value="2 0"/>81 <TopLine Value="21"/> 82 <CursorPos X="35" Y="29"/> 83 <UsageCount Value="21"/> 84 84 <Loaded Value="True"/> 85 85 </Unit3> … … 87 87 <Filename Value="..\..\UBufferedFileStream.pas"/> 88 88 <UnitName Value="UBufferedFileStream"/> 89 <EditorIndex Value="2"/>90 89 <WindowIndex Value="0"/> 91 90 <TopLine Value="38"/> 92 91 <CursorPos X="30" Y="54"/> 93 92 <UsageCount Value="20"/> 94 <Loaded Value="True"/>95 93 </Unit4> 96 94 <Unit5> … … 100 98 <TopLine Value="773"/> 101 99 <CursorPos X="17" Y="789"/> 102 <UsageCount Value="2 0"/>100 <UsageCount Value="21"/> 103 101 <Loaded Value="True"/> 104 102 </Unit5> … … 168 166 <UsageCount Value="11"/> 169 167 </Unit14> 168 <Unit15> 169 <Filename Value="..\..\..\..\..\lazarus\lcl\include\control.inc"/> 170 <EditorIndex Value="1"/> 171 <WindowIndex Value="0"/> 172 <TopLine Value="2784"/> 173 <CursorPos X="1" Y="2808"/> 174 <UsageCount Value="10"/> 175 <Loaded Value="True"/> 176 </Unit15> 170 177 </Units> 171 178 <JumpHistory Count="30" HistoryIndex="29"> 172 179 <Position1> 173 <Filename Value=" UMainForm.pas"/>174 <Caret Line=" 56" Column="1" TopLine="39"/>180 <Filename Value="..\..\UDynNumber.pas"/> 181 <Caret Line="47" Column="1" TopLine="31"/> 175 182 </Position1> 176 183 <Position2> 177 184 <Filename Value="..\..\UDynNumber.pas"/> 178 <Caret Line=" 31" Column="1" TopLine="21"/>185 <Caret Line="48" Column="1" TopLine="31"/> 179 186 </Position2> 180 187 <Position3> 181 188 <Filename Value="..\..\UDynNumber.pas"/> 182 <Caret Line=" 32" Column="1" TopLine="21"/>189 <Caret Line="49" Column="1" TopLine="31"/> 183 190 </Position3> 184 191 <Position4> 185 192 <Filename Value="..\..\UDynNumber.pas"/> 186 <Caret Line=" 33" Column="1" TopLine="21"/>193 <Caret Line="60" Column="1" TopLine="43"/> 187 194 </Position4> 188 195 <Position5> 189 196 <Filename Value="..\..\UDynNumber.pas"/> 190 <Caret Line=" 34" Column="1" TopLine="21"/>197 <Caret Line="61" Column="1" TopLine="43"/> 191 198 </Position5> 192 199 <Position6> 193 200 <Filename Value="..\..\UDynNumber.pas"/> 194 <Caret Line=" 31" Column="1" TopLine="21"/>201 <Caret Line="62" Column="1" TopLine="43"/> 195 202 </Position6> 196 203 <Position7> 197 204 <Filename Value="..\..\UDynNumber.pas"/> 198 <Caret Line=" 32" Column="1" TopLine="21"/>205 <Caret Line="64" Column="1" TopLine="43"/> 199 206 </Position7> 200 207 <Position8> 201 208 <Filename Value="..\..\UDynNumber.pas"/> 202 <Caret Line=" 35" Column="1" TopLine="21"/>209 <Caret Line="65" Column="1" TopLine="43"/> 203 210 </Position8> 204 211 <Position9> 205 212 <Filename Value="..\..\UDynNumber.pas"/> 206 <Caret Line=" 36" Column="1" TopLine="21"/>213 <Caret Line="66" Column="1" TopLine="43"/> 207 214 </Position9> 208 215 <Position10> 209 216 <Filename Value="..\..\UDynNumber.pas"/> 210 <Caret Line=" 37" Column="1" TopLine="21"/>217 <Caret Line="67" Column="1" TopLine="43"/> 211 218 </Position10> 212 219 <Position11> 213 220 <Filename Value="..\..\UDynNumber.pas"/> 214 <Caret Line=" 38" Column="1" TopLine="21"/>221 <Caret Line="50" Column="1" TopLine="43"/> 215 222 </Position11> 216 223 <Position12> 217 224 <Filename Value="..\..\UDynNumber.pas"/> 218 <Caret Line=" 36" Column="1" TopLine="21"/>225 <Caret Line="51" Column="1" TopLine="43"/> 219 226 </Position12> 220 227 <Position13> 221 228 <Filename Value="..\..\UDynNumber.pas"/> 222 <Caret Line=" 37" Column="1" TopLine="21"/>229 <Caret Line="52" Column="1" TopLine="43"/> 223 230 </Position13> 224 231 <Position14> 225 <Filename Value="..\..\U BitStream.pas"/>226 <Caret Line=" 164" Column="1" TopLine="149"/>232 <Filename Value="..\..\UDynNumber.pas"/> 233 <Caret Line="53" Column="2" TopLine="40"/> 227 234 </Position14> 228 235 <Position15> 229 <Filename Value="..\..\U BitStream.pas"/>230 <Caret Line=" 246" Column="1" TopLine="230"/>236 <Filename Value="..\..\UDynNumber.pas"/> 237 <Caret Line="47" Column="1" TopLine="40"/> 231 238 </Position15> 232 239 <Position16> 233 <Filename Value="..\..\U BitStream.pas"/>234 <Caret Line=" 249" Column="1" TopLine="230"/>240 <Filename Value="..\..\UDynNumber.pas"/> 241 <Caret Line="48" Column="1" TopLine="40"/> 235 242 </Position16> 236 243 <Position17> 237 <Filename Value="..\..\U BitStream.pas"/>238 <Caret Line=" 250" Column="1" TopLine="230"/>244 <Filename Value="..\..\UDynNumber.pas"/> 245 <Caret Line="49" Column="1" TopLine="40"/> 239 246 </Position17> 240 247 <Position18> 241 <Filename Value="..\..\U BitStream.pas"/>242 <Caret Line=" 251" Column="1" TopLine="230"/>248 <Filename Value="..\..\UDynNumber.pas"/> 249 <Caret Line="60" Column="1" TopLine="40"/> 243 250 </Position18> 244 251 <Position19> 245 <Filename Value="..\..\U BitStream.pas"/>246 <Caret Line=" 252" Column="1" TopLine="230"/>252 <Filename Value="..\..\UDynNumber.pas"/> 253 <Caret Line="61" Column="1" TopLine="40"/> 247 254 </Position19> 248 255 <Position20> 249 <Filename Value="..\..\U BitStream.pas"/>250 <Caret Line=" 253" Column="1" TopLine="230"/>256 <Filename Value="..\..\UDynNumber.pas"/> 257 <Caret Line="62" Column="1" TopLine="40"/> 251 258 </Position20> 252 259 <Position21> 253 <Filename Value="..\..\U BitStream.pas"/>254 <Caret Line=" 254" Column="1" TopLine="230"/>260 <Filename Value="..\..\UDynNumber.pas"/> 261 <Caret Line="64" Column="1" TopLine="40"/> 255 262 </Position21> 256 263 <Position22> 257 <Filename Value="..\..\U BitStream.pas"/>258 <Caret Line=" 255" Column="1" TopLine="230"/>264 <Filename Value="..\..\UDynNumber.pas"/> 265 <Caret Line="65" Column="1" TopLine="40"/> 259 266 </Position22> 260 267 <Position23> 261 <Filename Value="..\..\U BitStream.pas"/>262 <Caret Line=" 257" Column="1" TopLine="230"/>268 <Filename Value="..\..\UDynNumber.pas"/> 269 <Caret Line="66" Column="1" TopLine="40"/> 263 270 </Position23> 264 271 <Position24> 265 <Filename Value="..\..\U BitStream.pas"/>266 <Caret Line=" 258" Column="1" TopLine="231"/>272 <Filename Value="..\..\UDynNumber.pas"/> 273 <Caret Line="67" Column="1" TopLine="40"/> 267 274 </Position24> 268 275 <Position25> 269 <Filename Value="..\..\U BitStream.pas"/>270 <Caret Line=" 241" Column="1" TopLine="231"/>276 <Filename Value="..\..\UDynNumber.pas"/> 277 <Caret Line="50" Column="1" TopLine="40"/> 271 278 </Position25> 272 279 <Position26> 273 <Filename Value="..\..\U BitStream.pas"/>274 <Caret Line=" 242" Column="1" TopLine="231"/>280 <Filename Value="..\..\UDynNumber.pas"/> 281 <Caret Line="51" Column="1" TopLine="40"/> 275 282 </Position26> 276 283 <Position27> 277 <Filename Value="..\..\U BitStream.pas"/>278 <Caret Line=" 243" Column="1" TopLine="231"/>284 <Filename Value="..\..\UDynNumber.pas"/> 285 <Caret Line="65" Column="30" TopLine="39"/> 279 286 </Position27> 280 287 <Position28> 281 288 <Filename Value="..\..\UBitStream.pas"/> 282 <Caret Line="1 93" Column="1" TopLine="177"/>289 <Caret Line="162" Column="5" TopLine="150"/> 283 290 </Position28> 284 291 <Position29> 285 292 <Filename Value="..\..\UBitStream.pas"/> 286 <Caret Line="1 94" Column="1" TopLine="177"/>293 <Caret Line="163" Column="31" TopLine="150"/> 287 294 </Position29> 288 295 <Position30> 289 296 <Filename Value="..\..\UBitStream.pas"/> 290 <Caret Line=" 53" Column="14" TopLine="37"/>297 <Caret Line="161" Column="14" TopLine="146"/> 291 298 </Position30> 292 299 </JumpHistory> -
CoolStreaming/Demo/DynNumber/UMainForm.lfm
r126 r128 3 3 Height = 495 4 4 Top = 114 5 Width = 5505 Width = 669 6 6 Caption = 'DynNumber Demo' 7 7 ClientHeight = 495 8 ClientWidth = 5508 ClientWidth = 669 9 9 OnCreate = FormCreate 10 10 OnDestroy = FormDestroy 11 11 LCLVersion = '0.9.31' 12 object Edit1: TEdit12 object PageControl1: TPageControl 13 13 Left = 8 14 Height = 480 15 Top = 8 16 Width = 656 17 ActivePage = TabSheet2 18 Anchors = [akTop, akLeft, akRight, akBottom] 19 TabIndex = 1 20 TabOrder = 0 21 object TabSheet1: TTabSheet 22 Caption = 'Generator' 23 ClientHeight = 449 24 ClientWidth = 652 25 object Button1: TButton 26 Left = 11 27 Height = 25 28 Top = 10 29 Width = 75 30 Caption = 'Generate' 31 OnClick = Button1Click 32 TabOrder = 0 33 end 34 object Button2: TButton 35 Left = 374 36 Height = 25 37 Top = 11 38 Width = 75 39 Caption = 'test' 40 OnClick = Button2Click 41 TabOrder = 1 42 end 43 object SpinEdit1: TSpinEdit 44 Left = 99 45 Height = 25 46 Top = 10 47 Width = 106 48 MaxValue = 100000000 49 TabOrder = 2 50 Value = 10000 51 end 52 object ListView1: TListView 53 Left = 11 54 Height = 400 55 Top = 43 56 Width = 635 57 Anchors = [akTop, akLeft, akRight, akBottom] 58 Columns = < 59 item 60 Caption = 'Number' 61 Width = 70 62 end 63 item 64 Caption = 'Overhead' 65 Width = 70 66 end 67 item 68 Caption = 'Value' 69 Width = 494 70 end> 71 TabOrder = 3 72 ViewStyle = vsReport 73 end 74 end 75 object TabSheet2: TTabSheet 76 Caption = 'Encoder' 77 ClientHeight = 449 78 ClientWidth = 652 79 object Edit1: TEdit 80 Left = 8 81 Height = 25 82 Top = 8 83 Width = 638 84 Anchors = [akTop, akLeft, akRight] 85 TabOrder = 0 86 Text = '1' 87 end 88 object Button3: TButton 89 Left = 8 90 Height = 25 91 Top = 42 92 Width = 142 93 Caption = 'Encode' 94 OnClick = Button3Click 95 TabOrder = 1 96 end 97 object Edit2: TEdit 98 Left = 6 99 Height = 25 100 Top = 75 101 Width = 638 102 Anchors = [akTop, akLeft, akRight] 103 TabOrder = 2 104 Text = '1' 105 end 106 object Button4: TButton 107 Left = 8 108 Height = 25 109 Top = 107 110 Width = 142 111 Caption = 'Decode' 112 OnClick = Button4Click 113 TabOrder = 3 114 end 115 end 116 end 117 object Edit3: TEdit 118 Left = 16 14 119 Height = 25 15 Top = 8 16 Width = 320 17 TabOrder = 0 120 Top = 176 121 Width = 638 122 Anchors = [akTop, akLeft, akRight] 123 TabOrder = 1 18 124 Text = '1' 19 125 end 20 object Button1: TButton21 Left = 33622 Height = 2523 Top = 524 Width = 7525 Caption = 'Encode'26 OnClick = Button1Click27 TabOrder = 128 end29 object Button2: TButton30 Left = 41631 Height = 2532 Top = 733 Width = 7534 Caption = 'Generate'35 OnClick = Button2Click36 TabOrder = 237 end38 object ListView1: TListView39 Left = 840 Height = 44841 Top = 4042 Width = 53643 Anchors = [akTop, akLeft, akRight, akBottom]44 Columns = <45 item46 Caption = 'Number'47 Width = 7048 end49 item50 Caption = 'Overhead'51 Width = 7052 end53 item54 Caption = 'Value'55 Width = 37556 end>57 TabOrder = 358 ViewStyle = vsReport59 end60 126 end -
CoolStreaming/Demo/DynNumber/UMainForm.pas
r127 r128 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, UDynNumber, Math;9 ComCtrls, Spin, UDynNumber, Math; 10 10 11 11 type … … 16 16 Button1: TButton; 17 17 Button2: TButton; 18 Button3: TButton; 19 Button4: TButton; 18 20 Edit1: TEdit; 21 Edit2: TEdit; 22 Edit3: TEdit; 19 23 ListView1: TListView; 24 PageControl1: TPageControl; 25 SpinEdit1: TSpinEdit; 26 TabSheet1: TTabSheet; 27 TabSheet2: TTabSheet; 20 28 procedure Button1Click(Sender: TObject); 21 29 procedure Button2Click(Sender: TObject); 30 procedure Button3Click(Sender: TObject); 31 procedure Button4Click(Sender: TObject); 22 32 procedure FormCreate(Sender: TObject); 23 33 procedure FormDestroy(Sender: TObject); 24 34 private 25 { private declarations }26 35 public 27 36 DynamicNumber: TDynamicNumber; … … 44 53 Parts: array of Integer; 45 54 N: TDynamicNumber; 46 Line: string;47 55 NewItem: TListItem; 48 56 begin … … 51 59 ListView1.BeginUpdate; 52 60 ListView1.Clear; 53 for I := 0 to 10000do begin61 for I := 0 to SpinEdit1.Value do begin 54 62 N.Stream.Size := 0; 55 N.Write(I); 56 Line := ''; 57 N.Stream.Position := 0; 58 for J := 0 to N.Stream.Size - 1 do 59 Line := Line + IntToStr(Integer(N.Stream.ReadBit)); 63 N.WriteNumber(I); 60 64 NewItem := ListView1.Items.Add; 61 65 NewItem.Caption := IntToStr(I); 62 66 J := Floor(Log2(I)) + 1; 63 67 NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100)); 64 NewItem.SubItems.Add( Line);68 NewItem.SubItems.Add(N.Stream.AsString); 65 69 end; 66 70 finally … … 79 83 MaxValue: Integer; 80 84 J: Integer; 81 Line: string;82 85 NewItem: TListItem; 83 86 N: TDynamicNumber; … … 91 94 ListView1.BeginUpdate; 92 95 ListView1.Clear; 93 for II := 0 to 20000do begin96 for II := 0 to SpinEdit1.Value do begin 94 97 I := II * Step; 95 98 // Write … … 109 112 J := Floor(Log2(I)) + 1; 110 113 NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100)); 111 Line := ''; 112 N.Stream.Position := 0; 113 for J := 0 to N.Stream.Size - 1 do 114 Line := Line + IntToStr(Integer(N.Stream.ReadBit)); 115 NewItem.SubItems.Add(Line); 114 NewItem.SubItems.Add(N.Stream.AsString); 116 115 117 116 // Increment value … … 142 141 end; 143 142 143 procedure TMainForm.Button3Click(Sender: TObject); 144 var 145 N: TDynamicNumber; 146 begin 147 try 148 N := TDynamicNumber.Create; 149 N.Stream.Size := 0; 150 N.WriteNumber(StrToInt64(Edit1.Text)); 151 N.Stream.Position := 0; 152 Edit2.Text := N.Stream.AsString; 153 finally 154 N.Free; 155 end; 156 end; 157 158 procedure TMainForm.Button4Click(Sender: TObject); 159 var 160 N: TDynamicNumber; 161 begin 162 try 163 N := TDynamicNumber.Create; 164 N.Stream.AsString := Edit2.Text; 165 Edit3.Text := IntToStr(N.ReadNumber); 166 finally 167 N.Free; 168 end; 169 end; 170 144 171 procedure TMainForm.FormCreate(Sender: TObject); 145 172 begin -
CoolStreaming/UBitStream.pas
r126 r128 28 28 function CopyFrom(Source: TBitStream; Count: LongInt): LongInt; 29 29 function Write(const Buffer; Count: Longint): Longint; virtual; 30 function GetString: string; 31 procedure SetString(const AValue: string); 30 32 procedure ReadBuffer(var Buffer; Count: Longint); 31 33 procedure WriteBuffer(const Buffer; Count: Longint); … … 38 40 function ReadNumber(Count: Byte): QWord; 39 41 procedure WriteNumber(AValue: QWord; Count: Byte); 42 property AsString: string read GetString write SetString; 40 43 end; 41 44 … … 158 161 begin 159 162 Read(Result, Count); 163 Result := Result and ((QWord(1) shl Count) - 1); 160 164 end; 161 165 … … 163 167 begin 164 168 Write(AValue, Count); 169 end; 170 171 function TBitStream.GetString: string; 172 var 173 I: Integer; 174 begin 175 Result := ''; 176 Position := 0; 177 for I := 0 to Size - 1 do 178 Result := Result + IntToStr(Integer(ReadBit)); 179 end; 180 181 procedure TBitStream.SetString(const AValue: string); 182 var 183 I: Integer; 184 begin 185 Size := 0; 186 for I := 1 to Length(AValue) do 187 WriteBit(Boolean(StrToInt(AValue[I]))); 188 Position := 0; 165 189 end; 166 190 … … 204 228 Data: Byte; 205 229 begin 206 if Count < 0then230 if (Count < 0) or (Count > (Size - Position)) then 207 231 raise EReadError.Create(SReadError); 208 232 -
CoolStreaming/UDynNumber.pas
r127 r128 14 14 TDynamicNumber = class 15 15 Stream: TBitStream; 16 procedure Write (Value: QWord);17 function Read : QWord;16 procedure WriteNumber(Value: QWord); 17 function ReadNumber: QWord; 18 18 constructor Create; 19 19 destructor Destroy; override; 20 private 21 function ReadNumber2: QWord; 20 22 end; 21 23 … … 24 26 { TDynamicNumber } 25 27 26 procedure TDynamicNumber.Write (Value: QWord);28 procedure TDynamicNumber.WriteNumber(Value: QWord); 27 29 var 28 Bit: Byte;29 30 Length: Integer; 30 31 begin … … 32 33 if Length > 1 then begin 33 34 Stream.WriteNumber(1, 1); 34 Write (Length - 2);35 WriteNumber(Length - 2); 35 36 end else Stream.WriteNumber(0, 1); 36 37 if Length > 1 then Length := Length - 1; … … 38 39 end; 39 40 40 function TDynamicNumber.Read : QWord;41 function TDynamicNumber.ReadNumber: QWord; 41 42 var 42 43 Bit: Byte; 43 44 Length: Integer; 44 45 begin 46 Length := 0; 45 47 Bit := Stream.ReadNumber(1); 46 48 if Bit = 0 then Length := 1 47 else Length := Read + 2; 48 Result := Stream.ReadNumber(Length); 49 if Length > 0 then Result := Result or (1 shl Length); 49 else Length := ReadNumber2 + 2; 50 if Length > 1 then Result := Stream.ReadNumber(Length - 1) 51 else Result := Stream.ReadNumber(Length); 52 if Length > 1 then Result := Result or (QWord(1) shl (Length - 1)); 53 end; 54 55 function TDynamicNumber.ReadNumber2: QWord; 56 var 57 Bit: Byte; 58 Length: Integer; 59 begin 60 Length := 0; 61 Bit := Stream.ReadNumber(1); 62 if Bit = 0 then Length := 1 63 else Length := ReadNumber + 2; 64 if Length > 1 then Result := Stream.ReadNumber(Length - 1) 65 else Result := Stream.ReadNumber(Length); 66 if Length > 1 then Result := Result or (QWord(1) shl (Length - 1)); 50 67 end; 51 68
Note:
See TracChangeset
for help on using the changeset viewer.