Changeset 291
- Timestamp:
- Nov 4, 2011, 11:46:15 AM (13 years ago)
- Location:
- CoolStreaming
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/CoolStreaming.lpk
r250 r291 1 1 <?xml version="1.0"?> 2 2 <CONFIG> 3 <Package Version=" 3">3 <Package Version="4"> 4 4 <PathDelim Value="\"/> 5 5 <Name Value="CoolStreaming"/> 6 <AddToProjectUsesSection Value="True"/> 6 7 <Author Value="Chronos"/> 7 8 <CompilerOptions> 8 <Version Value=" 9"/>9 <Version Value="10"/> 9 10 <PathDelim Value="\"/> 10 11 <SearchPaths> 11 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 12 13 </SearchPaths> 14 <Linking> 15 <Debugging> 16 <GenerateDebugInfo Value="True"/> 17 <DebugInfoType Value="dsAuto"/> 18 </Debugging> 19 </Linking> 13 20 <Other> 14 21 <CompilerPath Value="$(CompPath)"/> … … 49 56 </Files> 50 57 <Type Value="RunAndDesignTime"/> 51 <RequiredPkgs Count=" 3">58 <RequiredPkgs Count="4"> 52 59 <Item1> 53 <PackageName Value=" LCL"/>60 <PackageName Value="Common"/> 54 61 </Item1> 55 62 <Item2> 56 <PackageName Value=" TemplateGenerics"/>63 <PackageName Value="LCL"/> 57 64 </Item2> 58 65 <Item3> 66 <PackageName Value="TemplateGenerics"/> 67 </Item3> 68 <Item4> 59 69 <PackageName Value="FCL"/> 60 70 <MinVersion Major="1" Valid="True"/> 61 </Item 3>71 </Item4> 62 72 </RequiredPkgs> 63 73 <UsageOptions> -
CoolStreaming/UBitStream.pas
r249 r291 8 8 9 9 uses 10 Classes, SysUtils, RtlConsts, Math ;10 Classes, SysUtils, RtlConsts, Math, UMemory; 11 11 12 12 type … … 47 47 TMemoryBitStream = class(TBitStream) 48 48 private 49 F Stream: TMemoryStream;49 FMemory: TPositionMemory; 50 50 FPosition: LongInt; 51 51 FSize: LongInt; … … 61 61 constructor Create; 62 62 destructor Destroy; override; 63 property Stream: TMemoryStream read FStream;63 property Memory: TPositionMemory read FMemory; 64 64 end; 65 65 … … 175 175 function TBitStream.ReadNumber(Count: Byte): QWord; 176 176 begin 177 Result := 0; 177 178 Read(Result, Count); 178 179 Result := Result and ((QWord(1) shl Count) - 1); … … 224 225 begin 225 226 FSize := AValue; 226 Stream.Size := Ceil(AValue / 8);227 FMemory.Size := Ceil(AValue / 8); 227 228 if FPosition > FSize then FPosition := FSize; 228 229 end; … … 251 252 ByteCount := Ceil(Count / 8); 252 253 PosInByte := FPosition mod 8; 253 Stream.Position := Trunc(FPosition / 8);254 Data := Stream.ReadByte; // Read first byte254 FMemory.Position := Trunc(FPosition / 8); 255 Data := FMemory.ReadByte; // Read first byte 255 256 for I := 0 to ByteCount - 1 do begin 256 257 TBytes(Buffer)[I] := (Data shr PosInByte) and ((1 shl (8 - PosInByte)) - 1); 257 if (I < ByteCount) and (Stream.Position < Stream.Size) then 258 Data := Stream.ReadByte else Data := 0; 258 if (I < ByteCount) and (FMemory.Position < FMemory.Size) then begin 259 Data := FMemory.ReadByte; 260 end else Data := 0; 259 261 if PosInByte > 0 then 260 262 TBytes(Buffer)[I] := TBytes(Buffer)[I] or … … 293 295 BitCount := Count; 294 296 ByteCount := Ceil(Count / 8); 295 Stream.Position := Trunc(FPosition / 8);297 FMemory.Position := Trunc(FPosition / 8); 296 298 BytePos := FPosition mod 8; 297 299 I := 0; 298 300 while (I < ByteCount) or (RestBitCount > 0) do begin 299 301 WriteBitCount := Min(8 - BytePos, BitCount); 300 if ( Stream.Position < Stream.Size) and (WriteBitCount < 8) then begin301 Data := Stream.ReadByte;302 Stream.Position := Stream.Position - 1;302 if (FMemory.Position < FMemory.Size) and (WriteBitCount < 8) then begin 303 Data := FMemory.ReadByte; 304 FMemory.Position := FMemory.Position - 1; 303 305 end else Data := 0; 304 306 … … 311 313 // Write part up to one byte from source to target 312 314 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I], BytePos, WriteBitCount)); 313 Stream.WriteByte(Data);315 FMemory.WriteByte(Data); 314 316 315 317 RestBitCount := Min(8 - WriteBitCount, BitCount); … … 334 336 constructor TMemoryBitStream.Create; 335 337 begin 336 F Stream := TMemoryStream.Create;338 FMemory := TPositionMemory.Create; 337 339 FPosition := 0; 338 340 FSize := 0; … … 341 343 destructor TMemoryBitStream.Destroy; 342 344 begin 343 F Stream.Free;345 FMemory.Free; 344 346 inherited Destroy; 345 347 end; -
CoolStreaming/UStreamHelper.pas
r269 r291 39 39 function ReadCardinal: Cardinal; 40 40 function ReadInt64: Int64; 41 function ReadString : string;41 function ReadString(Length: Integer): string; 42 42 function ReadShortString: string; 43 43 function ReadAnsiString: string; … … 73 73 begin 74 74 FStream.ReadBuffer(StringLength, SizeOf(StringLength)); 75 SetLength(Result, StringLength); 76 if StringLength > 0 then begin 77 FStream.ReadBuffer(Result[1], StringLength); 78 end; 75 Result := ReadString(StringLength); 79 76 end; 80 77 … … 119 116 end; 120 117 121 function TStreamHelper.ReadString :string;122 begin 123 SetLength(Result, FStream.Size - FStream.Position);124 if (FStream.Size - FStream.Position) > 0 then125 FStream.Read(Result[1], FStream.Size - FStream.Position)126 118 function TStreamHelper.ReadString(Length: Integer): string; 119 begin 120 if Length > 0 then begin 121 SetLength(Result, Length); 122 FStream.Read(Result[1], Length); 123 end else Result := ''; 127 124 end; 128 125 … … 132 129 begin 133 130 FStream.ReadBuffer(Count, 1); 134 SetLength(Result, Count); 135 FStream.ReadBuffer(Result[1], Count); 131 Result := ReadString(Count); 136 132 end; 137 133
Note:
See TracChangeset
for help on using the changeset viewer.