Changeset 249 for CoolStreaming
- Timestamp:
- May 30, 2011, 7:02:15 AM (14 years ago)
- Location:
- CoolStreaming
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/Demo/BitStream/BitStreamTest.lpi
r129 r249 42 42 </Item2> 43 43 </RequiredPackages> 44 <Units Count=" 6">44 <Units Count="8"> 45 45 <Unit0> 46 46 <Filename Value="BitStreamTest.lpr"/> 47 47 <IsPartOfProject Value="True"/> 48 48 <UnitName Value="BitStreamTest"/> 49 <EditorIndex Value=" 2"/>49 <EditorIndex Value="3"/> 50 50 <WindowIndex Value="0"/> 51 51 <TopLine Value="1"/> 52 52 <CursorPos X="32" Y="15"/> 53 <UsageCount Value="2 0"/>53 <UsageCount Value="23"/> 54 54 <Loaded Value="True"/> 55 55 <DefaultSyntaxHighlighter Value="Delphi"/> … … 61 61 <ResourceBaseClass Value="Form"/> 62 62 <UnitName Value="UMainForm"/> 63 <IsVisibleTab Value="True"/>64 63 <EditorIndex Value="0"/> 65 64 <WindowIndex Value="0"/> 66 <TopLine Value="1 32"/>67 <CursorPos X=" 1" Y="150"/>68 <UsageCount Value="2 0"/>65 <TopLine Value="123"/> 66 <CursorPos X="25" Y="138"/> 67 <UsageCount Value="23"/> 69 68 <Loaded Value="True"/> 70 69 <LoadedDesigner Value="True"/> … … 83 82 <Filename Value="E:\Programy\Lazarus\lcl\controls.pp"/> 84 83 <UnitName Value="Controls"/> 85 <EditorIndex Value="3"/>86 84 <WindowIndex Value="0"/> 87 85 <TopLine Value="1207"/> 88 86 <CursorPos X="14" Y="1220"/> 89 87 <UsageCount Value="10"/> 90 <Loaded Value="True"/>91 88 </Unit3> 92 89 <Unit4> … … 100 97 <Unit5> 101 98 <Filename Value="E:\Programy\Lazarus\fpc\2.4.3\source\rtl\objpas\sysutils\sysutilh.inc"/> 102 <EditorIndex Value="1"/>103 99 <WindowIndex Value="0"/> 104 100 <TopLine Value="84"/> 105 101 <CursorPos X="79" Y="89"/> 106 102 <UsageCount Value="10"/> 107 <Loaded Value="True"/>108 103 </Unit5> 104 <Unit6> 105 <Filename Value="..\..\UBitStream.pas"/> 106 <UnitName Value="UBitStream"/> 107 <IsVisibleTab Value="True"/> 108 <EditorIndex Value="1"/> 109 <WindowIndex Value="0"/> 110 <TopLine Value="244"/> 111 <CursorPos X="7" Y="263"/> 112 <UsageCount Value="11"/> 113 <Loaded Value="True"/> 114 </Unit6> 115 <Unit7> 116 <Filename Value="H:\0.9.30_2.4.2\fpc\2.4.2\source\rtl\objpas\classes\classesh.inc"/> 117 <EditorIndex Value="2"/> 118 <WindowIndex Value="0"/> 119 <TopLine Value="779"/> 120 <CursorPos X="14" Y="792"/> 121 <UsageCount Value="11"/> 122 <Loaded Value="True"/> 123 </Unit7> 109 124 </Units> 110 125 <JumpHistory Count="30" HistoryIndex="29"> 111 126 <Position1> 112 <Filename Value=" UMainForm.pas"/>113 <Caret Line=" 99" Column="1" TopLine="85"/>127 <Filename Value="..\..\UBitStream.pas"/> 128 <Caret Line="293" Column="1" TopLine="275"/> 114 129 </Position1> 115 130 <Position2> 116 <Filename Value=" UMainForm.pas"/>117 <Caret Line=" 101" Column="1" TopLine="85"/>131 <Filename Value="..\..\UBitStream.pas"/> 132 <Caret Line="294" Column="1" TopLine="275"/> 118 133 </Position2> 119 134 <Position3> 120 <Filename Value=" UMainForm.pas"/>121 <Caret Line=" 94" Column="1" TopLine="85"/>135 <Filename Value="..\..\UBitStream.pas"/> 136 <Caret Line="295" Column="1" TopLine="275"/> 122 137 </Position3> 123 138 <Position4> 124 <Filename Value=" UMainForm.pas"/>125 <Caret Line=" 95" Column="1" TopLine="85"/>139 <Filename Value="..\..\UBitStream.pas"/> 140 <Caret Line="296" Column="1" TopLine="275"/> 126 141 </Position4> 127 142 <Position5> 128 <Filename Value=" UMainForm.pas"/>129 <Caret Line=" 98" Column="1" TopLine="85"/>143 <Filename Value="..\..\UBitStream.pas"/> 144 <Caret Line="297" Column="1" TopLine="276"/> 130 145 </Position5> 131 146 <Position6> 132 <Filename Value=" UMainForm.pas"/>133 <Caret Line=" 99" Column="1" TopLine="85"/>147 <Filename Value="..\..\UBitStream.pas"/> 148 <Caret Line="298" Column="33" TopLine="287"/> 134 149 </Position6> 135 150 <Position7> 136 151 <Filename Value="UMainForm.pas"/> 137 <Caret Line="1 01" Column="1" TopLine="85"/>152 <Caret Line="183" Column="1" TopLine="169"/> 138 153 </Position7> 139 154 <Position8> 140 <Filename Value=" UMainForm.pas"/>141 <Caret Line=" 94" Column="1" TopLine="85"/>155 <Filename Value="..\..\UBitStream.pas"/> 156 <Caret Line="288" Column="1" TopLine="283"/> 142 157 </Position8> 143 158 <Position9> 144 <Filename Value=" UMainForm.pas"/>145 <Caret Line=" 95" Column="1" TopLine="85"/>159 <Filename Value="..\..\UBitStream.pas"/> 160 <Caret Line="291" Column="1" TopLine="283"/> 146 161 </Position9> 147 162 <Position10> 148 <Filename Value=" UMainForm.pas"/>149 <Caret Line=" 99" Column="1" TopLine="85"/>163 <Filename Value="..\..\UBitStream.pas"/> 164 <Caret Line="292" Column="1" TopLine="283"/> 150 165 </Position10> 151 166 <Position11> 152 <Filename Value=" UMainForm.pas"/>153 <Caret Line=" 119" Column="27" TopLine="109"/>167 <Filename Value="..\..\UBitStream.pas"/> 168 <Caret Line="293" Column="1" TopLine="283"/> 154 169 </Position11> 155 170 <Position12> 156 <Filename Value=" UMainForm.pas"/>157 <Caret Line=" 99" Column="32" TopLine="78"/>171 <Filename Value="..\..\UBitStream.pas"/> 172 <Caret Line="294" Column="1" TopLine="283"/> 158 173 </Position12> 159 174 <Position13> 160 <Filename Value=" UMainForm.pas"/>161 <Caret Line=" 98" Column="29" TopLine="78"/>175 <Filename Value="..\..\UBitStream.pas"/> 176 <Caret Line="295" Column="1" TopLine="283"/> 162 177 </Position13> 163 178 <Position14> 164 <Filename Value=" UMainForm.pas"/>165 <Caret Line=" 102" Column="14" TopLine="78"/>179 <Filename Value="..\..\UBitStream.pas"/> 180 <Caret Line="296" Column="1" TopLine="283"/> 166 181 </Position14> 167 182 <Position15> 168 <Filename Value=" BitStreamTest.lpr"/>169 <Caret Line=" 19" Column="1" TopLine="1"/>183 <Filename Value="..\..\UBitStream.pas"/> 184 <Caret Line="297" Column="1" TopLine="283"/> 170 185 </Position15> 171 186 <Position16> 172 <Filename Value=" UMainForm.pas"/>173 <Caret Line=" 101" Column="12" TopLine="85"/>187 <Filename Value="..\..\UBitStream.pas"/> 188 <Caret Line="298" Column="1" TopLine="283"/> 174 189 </Position16> 175 190 <Position17> 176 <Filename Value=" UMainForm.pas"/>177 <Caret Line=" 111" Column="49" TopLine="111"/>191 <Filename Value="..\..\UBitStream.pas"/> 192 <Caret Line="299" Column="1" TopLine="283"/> 178 193 </Position17> 179 194 <Position18> 180 <Filename Value=" UMainForm.pas"/>181 <Caret Line=" 24" Column="59" TopLine="23"/>195 <Filename Value="..\..\UBitStream.pas"/> 196 <Caret Line="300" Column="1" TopLine="286"/> 182 197 </Position18> 183 198 <Position19> 184 <Filename Value=" UMainForm.pas"/>185 <Caret Line=" 58" Column="21" TopLine="45"/>199 <Filename Value="..\..\UBitStream.pas"/> 200 <Caret Line="303" Column="1" TopLine="286"/> 186 201 </Position19> 187 202 <Position20> 188 <Filename Value=" UMainForm.pas"/>189 <Caret Line=" 72" Column="9" TopLine="59"/>203 <Filename Value="..\..\UBitStream.pas"/> 204 <Caret Line="306" Column="1" TopLine="286"/> 190 205 </Position20> 191 206 <Position21> 192 <Filename Value=" BitStreamTest.lpr"/>193 <Caret Line=" 19" Column="1" TopLine="1"/>207 <Filename Value="..\..\UBitStream.pas"/> 208 <Caret Line="312" Column="1" TopLine="299"/> 194 209 </Position21> 195 210 <Position22> 196 <Filename Value=" BitStreamTest.lpr"/>197 <Caret Line=" 18" Column="29" TopLine="1"/>211 <Filename Value="..\..\UBitStream.pas"/> 212 <Caret Line="313" Column="1" TopLine="299"/> 198 213 </Position22> 199 214 <Position23> 200 <Filename Value=" UMainForm.pas"/>201 <Caret Line=" 89" Column="23" TopLine="80"/>215 <Filename Value="..\..\UBitStream.pas"/> 216 <Caret Line="315" Column="1" TopLine="299"/> 202 217 </Position23> 203 218 <Position24> 204 <Filename Value=" UMainForm.pas"/>205 <Caret Line=" 15" Column="1" TopLine="3"/>219 <Filename Value="..\..\UBitStream.pas"/> 220 <Caret Line="316" Column="1" TopLine="299"/> 206 221 </Position24> 207 222 <Position25> 208 <Filename Value=" UMainForm.pas"/>209 <Caret Line=" 56" Column="11" TopLine="44"/>223 <Filename Value="..\..\UBitStream.pas"/> 224 <Caret Line="298" Column="14" TopLine="287"/> 210 225 </Position25> 211 226 <Position26> 212 227 <Filename Value="UMainForm.pas"/> 213 <Caret Line=" 76" Column="3" TopLine="69"/>228 <Caret Line="192" Column="14" TopLine="179"/> 214 229 </Position26> 215 230 <Position27> 216 231 <Filename Value="UMainForm.pas"/> 217 <Caret Line="1 5" Column="7" TopLine="3"/>232 <Caret Line="197" Column="1" TopLine="179"/> 218 233 </Position27> 219 234 <Position28> 220 235 <Filename Value="UMainForm.pas"/> 221 <Caret Line="1 1" Column="1" TopLine="1"/>236 <Caret Line="190" Column="1" TopLine="167"/> 222 237 </Position28> 223 238 <Position29> 224 239 <Filename Value="UMainForm.pas"/> 225 <Caret Line="1 24" Column="53" TopLine="112"/>240 <Caret Line="191" Column="44" TopLine="155"/> 226 241 </Position29> 227 242 <Position30> 228 243 <Filename Value="UMainForm.pas"/> 229 <Caret Line="1 43" Column="50" TopLine="131"/>244 <Caret Line="138" Column="25" TopLine="123"/> 230 245 </Position30> 231 246 </JumpHistory> -
CoolStreaming/Demo/BitStream/UMainForm.lfm
r122 r249 8 8 ClientWidth = 613 9 9 OnShow = FormShow 10 LCLVersion = '0.9.3 1'10 LCLVersion = '0.9.30' 11 11 object Memo1: TMemo 12 Left = 713 Height = 3 7214 Top = 812 Left = 8 13 Height = 364 14 Top = 40 15 15 Width = 599 16 16 Anchors = [akTop, akLeft, akRight, akBottom] … … 20 20 TabOrder = 0 21 21 end 22 object Button1: TButton 23 Left = 9 24 Height = 25 25 Top = 7 26 Width = 75 27 Caption = 'Base test' 28 OnClick = Button1Click 29 TabOrder = 1 30 end 31 object Button2: TButton 32 Left = 93 33 Height = 25 34 Top = 7 35 Width = 75 36 Caption = 'Read test' 37 OnClick = Button2Click 38 TabOrder = 2 39 end 40 object Button3: TButton 41 Left = 176 42 Height = 25 43 Top = 7 44 Width = 75 45 Caption = 'Write test' 46 OnClick = Button3Click 47 TabOrder = 3 48 end 22 49 end -
CoolStreaming/Demo/BitStream/UMainForm.pas
r129 r249 15 15 16 16 TMainForm = class(TForm) 17 Button1: TButton; 18 Button2: TButton; 19 Button3: TButton; 17 20 Memo1: TMemo; 21 procedure Button1Click(Sender: TObject); 22 procedure Button2Click(Sender: TObject); 23 procedure Button3Click(Sender: TObject); 18 24 procedure FormShow(Sender: TObject); 19 25 private … … 32 38 33 39 procedure TMainForm.FormShow(Sender: TObject); 40 begin 41 WindowState := wsMaximized; 42 end; 43 44 procedure TMainForm.Button1Click(Sender: TObject); 34 45 var 35 46 BitStream: TMemoryBitStream; … … 40 51 C: Integer; 41 52 begin 42 WindowState := wsMaximized;43 44 53 with Memo1, Lines do try 45 54 BeginUpdate; … … 47 56 BitStream2 := TMemoryBitStream.Create; 48 57 SetLength(Buffer, 4); 49 Buffer[0] := $ 12;50 Buffer[1] := $ 34;51 Buffer[2] := $ 56;52 Buffer[3] := $ 78;58 Buffer[0] := $21; 59 Buffer[1] := $43; 60 Buffer[2] := $65; 61 Buffer[3] := $87; 53 62 Add('Source data:'); 54 63 PrintData(Buffer, Length(Buffer) * 8, Lines); 55 64 56 BitStream.Write(Buffer[0], 28);65 BitStream.Write(Buffer[0], Length(Buffer) * 8); 57 66 Add('Write data to stream:'); 58 67 PrintBitStream(BitStream, Lines); 68 59 69 // Write second bit array after first which lead to store data as shifted 60 BitStream.Write(Buffer[0], 28);70 BitStream.Write(Buffer[0], Length(Buffer) * 8); 61 71 Add('Append shifted data to stream:'); 62 72 PrintBitStream(BitStream, Lines); … … 83 93 PrintBitStream(BitStream2, Lines); 84 94 end; *) 95 finally 96 BitStream.Free; 97 BitStream2.Free; 98 EndUpdate; 99 end; 100 end; 101 102 procedure TMainForm.Button2Click(Sender: TObject); 103 var 104 BitStream: TMemoryBitStream; 105 BitStream2: TMemoryBitStream; 106 Buffer: array of Byte; 107 I: Integer; 108 Y: Integer; 109 C: Integer; 110 begin 111 with Memo1, Lines do try 112 BeginUpdate; 113 BitStream := TMemoryBitStream.Create; 114 BitStream2 := TMemoryBitStream.Create; 115 116 SetLength(Buffer, 4); 117 Buffer[0] := $21; 118 Buffer[1] := $43; 119 Buffer[2] := $65; 120 Buffer[3] := $87; 121 Add('Source data:'); 122 PrintData(Buffer, Length(Buffer) * 8, Lines); 123 124 BitStream.Write(Buffer[0], Length(Buffer) * 8); 125 Add('Write data to stream:'); 126 PrintBitStream(BitStream, Lines); 85 127 86 128 Add('Bit copy of substreams'); … … 107 149 end; 108 150 151 procedure TMainForm.Button3Click(Sender: TObject); 152 var 153 BitStream: TMemoryBitStream; 154 BitStream2: TMemoryBitStream; 155 Buffer: array of Byte; 156 I: Integer; 157 Y: Integer; 158 C: Integer; 159 begin 160 with Memo1, Lines do try 161 BeginUpdate; 162 BitStream := TMemoryBitStream.Create; 163 BitStream2 := TMemoryBitStream.Create; 164 165 SetLength(Buffer, 5); 166 Buffer[0] := $10; 167 Buffer[1] := $32; 168 Buffer[2] := $54; 169 Buffer[3] := $76; 170 Buffer[4] := $98; 171 Add('Source data:'); 172 PrintData(Buffer, Length(Buffer) * 8, Lines); 173 174 Add('Bit copy of substreams'); 175 BitStream.Size := Length(Buffer) * 8; 176 SetLength(Buffer, 1000); 177 for Y := 0 to BitStream.Size do begin 178 Add('Size: ' + IntToStr(Y)); 179 for I := 0 to BitStream.Size - Y do begin 180 BitStream.Position := 0; 181 for C := 0 to BitStream.Size - 1 do 182 BitStream.WriteBit(True); 183 BitStream.Position := I; 184 C := BitStream.Write(Buffer[0], Y); 185 PrintBitStream(BitStream, Lines); 186 end; 187 Add(''); 188 end; 189 190 Add('Bit copy of substreams'); 191 SetLength(Buffer, 1000); 192 for Y := 0 to BitStream.Size do begin 193 Add('Size: ' + IntToStr(Y)); 194 for I := 0 to BitStream.Size - Y do begin 195 BitStream.Position := 0; 196 for C := 0 to BitStream.Size - 1 do 197 BitStream.WriteBit(False); 198 BitStream.Position := I; 199 C := BitStream.Write(Buffer[0], Y); 200 PrintBitStream(BitStream, Lines); 201 end; 202 Add(''); 203 end; 204 finally 205 BitStream.Free; 206 BitStream2.Free; 207 EndUpdate; 208 end; 209 end; 210 109 211 procedure TMainForm.PrintData(Data: TArrayOfByte; Count: Integer; StringList: TStrings); 110 212 var -
CoolStreaming/UBitStream.pas
r247 r249 228 228 end; 229 229 230 function TMemoryBitStream.WriteToByte(var Data: Byte; NewData, Pos,Count:Byte):Byte;230 function TMemoryBitStream.WriteToByte(var Data: Byte; NewData, Pos, Count: Byte) :Byte; 231 231 begin 232 232 Data := Byte(Data and not (((1 shl Count) - 1) shl Pos) // Make zero space for new data … … 260 260 TBytes(Buffer)[I] := TBytes(Buffer)[I] or 261 261 ((Integer(Data) and ((1 shl PosInByte) - 1)) shl (8 - PosInByte)); 262 //if (I = (ByteCount - 1)) and (PosInByte > 0) then263 //TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1);262 if (I = (ByteCount - 1)) and (PosInByte > 0) then 263 TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1); 264 264 end; 265 265 Inc(FPosition, Count); … … 268 268 end; 269 269 270 function TMemoryBitStream.Write(const Buffer; Count:Longint):Longint;270 function TMemoryBitStream.Write(const Buffer; Count: Longint): Longint; 271 271 var 272 272 ByteCount: LongInt; 273 273 BitCount: LongInt; 274 WriteBitCount: Integer; 275 RestBitCount: Integer; 276 NextRestBitCount: Integer; 274 277 I: LongInt; 275 278 BytePos: Byte; … … 286 289 raise EWriteError.Create(SWriteError); 287 290 291 RestBitCount := 0; 292 NextRestBitCount := 0; 288 293 BitCount := Count; 289 294 ByteCount := Ceil(Count / 8); 295 Stream.Position := Trunc(FPosition / 8); 290 296 BytePos := FPosition mod 8; 291 Stream.Position := Trunc(FPosition / 8); 292 if Stream.Position < Stream.Size then begin 293 Data := Stream.ReadByte; 294 Stream.Position := Stream.Position - 1; 295 end else Data := 0; 296 for I := 0 to ByteCount - 1 do begin 297 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I], BytePos, Min(8 - BytePos, BitCount))); 297 I := 0; 298 while (I < ByteCount) or (RestBitCount > 0) do begin 299 WriteBitCount := Min(8 - BytePos, BitCount); 300 if (Stream.Position < Stream.Size) and (WriteBitCount < 8) then begin 301 Data := Stream.ReadByte; 302 Stream.Position := Stream.Position - 1; 303 end else Data := 0; 304 305 // Write rest of previous source byte to target 306 if RestBitCount > 0 then begin 307 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I - 1] shr (8 - BytePos), 0, RestBitCount)); 308 WriteBitCount := Min(8 - BytePos, BitCount); 309 end; 310 311 // Write part up to one byte from source to target 312 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I], BytePos, WriteBitCount)); 298 313 Stream.WriteByte(Data); 299 Data := 0; 300 if (BitCount > 0) and (BytePos > 0) then begin 301 if (I = (ByteCount - 1)) and (Stream.Position < Stream.Size) then begin 302 Data := Stream.ReadByte; 303 Stream.Position := Stream.Position - 1; 304 end; 305 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I] shr (8 - BytePos), 0, Min(BytePos, BitCount))); 306 if I = (ByteCount - 1) then 307 Stream.WriteByte(Data); 308 end; 314 315 RestBitCount := Min(8 - WriteBitCount, BitCount); 316 Inc(I); 309 317 end; 310 318 Inc(FPosition, Count);
Note:
See TracChangeset
for help on using the changeset viewer.