Changeset 129 for CoolStreaming


Ignore:
Timestamp:
Jan 17, 2011, 6:55:36 AM (14 years ago)
Author:
george
Message:
Location:
CoolStreaming/Demo/BitStream
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/Demo/BitStream/BitStreamTest.lpi

    r122 r129  
    4242      </Item2>
    4343    </RequiredPackages>
    44     <Units Count="5">
     44    <Units Count="6">
    4545      <Unit0>
    4646        <Filename Value="BitStreamTest.lpr"/>
    4747        <IsPartOfProject Value="True"/>
    4848        <UnitName Value="BitStreamTest"/>
    49         <EditorIndex Value="1"/>
     49        <EditorIndex Value="2"/>
    5050        <WindowIndex Value="0"/>
    5151        <TopLine Value="1"/>
     
    6464        <EditorIndex Value="0"/>
    6565        <WindowIndex Value="0"/>
    66         <TopLine Value="1"/>
    67         <CursorPos X="3" Y="18"/>
     66        <TopLine Value="132"/>
     67        <CursorPos X="1" Y="150"/>
    6868        <UsageCount Value="20"/>
    6969        <Loaded Value="True"/>
     
    8383        <Filename Value="E:\Programy\Lazarus\lcl\controls.pp"/>
    8484        <UnitName Value="Controls"/>
    85         <EditorIndex Value="2"/>
     85        <EditorIndex Value="3"/>
    8686        <WindowIndex Value="0"/>
    8787        <TopLine Value="1207"/>
     
    9898        <UsageCount Value="10"/>
    9999      </Unit4>
     100      <Unit5>
     101        <Filename Value="E:\Programy\Lazarus\fpc\2.4.3\source\rtl\objpas\sysutils\sysutilh.inc"/>
     102        <EditorIndex Value="1"/>
     103        <WindowIndex Value="0"/>
     104        <TopLine Value="84"/>
     105        <CursorPos X="79" Y="89"/>
     106        <UsageCount Value="10"/>
     107        <Loaded Value="True"/>
     108      </Unit5>
    100109    </Units>
    101     <JumpHistory Count="30" HistoryIndex="28">
     110    <JumpHistory Count="30" HistoryIndex="29">
    102111      <Position1>
    103112        <Filename Value="UMainForm.pas"/>
    104         <Caret Line="95" Column="1" TopLine="85"/>
     113        <Caret Line="99" Column="1" TopLine="85"/>
    105114      </Position1>
    106115      <Position2>
    107116        <Filename Value="UMainForm.pas"/>
    108         <Caret Line="98" Column="1" TopLine="85"/>
     117        <Caret Line="101" Column="1" TopLine="85"/>
    109118      </Position2>
    110119      <Position3>
    111120        <Filename Value="UMainForm.pas"/>
    112         <Caret Line="99" Column="1" TopLine="85"/>
     121        <Caret Line="94" Column="1" TopLine="85"/>
    113122      </Position3>
    114123      <Position4>
    115124        <Filename Value="UMainForm.pas"/>
    116         <Caret Line="92" Column="13" TopLine="85"/>
     125        <Caret Line="95" Column="1" TopLine="85"/>
    117126      </Position4>
    118127      <Position5>
    119128        <Filename Value="UMainForm.pas"/>
    120         <Caret Line="99" Column="1" TopLine="85"/>
     129        <Caret Line="98" Column="1" TopLine="85"/>
    121130      </Position5>
    122131      <Position6>
    123132        <Filename Value="UMainForm.pas"/>
    124         <Caret Line="101" Column="1" TopLine="85"/>
     133        <Caret Line="99" Column="1" TopLine="85"/>
    125134      </Position6>
    126135      <Position7>
    127136        <Filename Value="UMainForm.pas"/>
    128         <Caret Line="94" Column="1" TopLine="85"/>
     137        <Caret Line="101" Column="1" TopLine="85"/>
    129138      </Position7>
    130139      <Position8>
    131140        <Filename Value="UMainForm.pas"/>
    132         <Caret Line="95" Column="1" TopLine="85"/>
     141        <Caret Line="94" Column="1" TopLine="85"/>
    133142      </Position8>
    134143      <Position9>
    135144        <Filename Value="UMainForm.pas"/>
    136         <Caret Line="98" Column="1" TopLine="85"/>
     145        <Caret Line="95" Column="1" TopLine="85"/>
    137146      </Position9>
    138147      <Position10>
     
    142151      <Position11>
    143152        <Filename Value="UMainForm.pas"/>
    144         <Caret Line="101" Column="1" TopLine="85"/>
     153        <Caret Line="119" Column="27" TopLine="109"/>
    145154      </Position11>
    146155      <Position12>
    147156        <Filename Value="UMainForm.pas"/>
    148         <Caret Line="94" Column="1" TopLine="85"/>
     157        <Caret Line="99" Column="32" TopLine="78"/>
    149158      </Position12>
    150159      <Position13>
    151160        <Filename Value="UMainForm.pas"/>
    152         <Caret Line="95" Column="1" TopLine="85"/>
     161        <Caret Line="98" Column="29" TopLine="78"/>
    153162      </Position13>
    154163      <Position14>
    155164        <Filename Value="UMainForm.pas"/>
    156         <Caret Line="99" Column="1" TopLine="85"/>
     165        <Caret Line="102" Column="14" TopLine="78"/>
    157166      </Position14>
    158167      <Position15>
    159         <Filename Value="UMainForm.pas"/>
    160         <Caret Line="119" Column="27" TopLine="109"/>
     168        <Filename Value="BitStreamTest.lpr"/>
     169        <Caret Line="19" Column="1" TopLine="1"/>
    161170      </Position15>
    162171      <Position16>
    163172        <Filename Value="UMainForm.pas"/>
    164         <Caret Line="99" Column="32" TopLine="78"/>
     173        <Caret Line="101" Column="12" TopLine="85"/>
    165174      </Position16>
    166175      <Position17>
    167176        <Filename Value="UMainForm.pas"/>
    168         <Caret Line="98" Column="29" TopLine="78"/>
     177        <Caret Line="111" Column="49" TopLine="111"/>
    169178      </Position17>
    170179      <Position18>
    171180        <Filename Value="UMainForm.pas"/>
    172         <Caret Line="102" Column="14" TopLine="78"/>
     181        <Caret Line="24" Column="59" TopLine="23"/>
    173182      </Position18>
    174183      <Position19>
    175         <Filename Value="BitStreamTest.lpr"/>
    176         <Caret Line="19" Column="1" TopLine="1"/>
     184        <Filename Value="UMainForm.pas"/>
     185        <Caret Line="58" Column="21" TopLine="45"/>
    177186      </Position19>
    178187      <Position20>
    179188        <Filename Value="UMainForm.pas"/>
    180         <Caret Line="101" Column="12" TopLine="85"/>
     189        <Caret Line="72" Column="9" TopLine="59"/>
    181190      </Position20>
    182191      <Position21>
    183         <Filename Value="UMainForm.pas"/>
    184         <Caret Line="111" Column="49" TopLine="111"/>
     192        <Filename Value="BitStreamTest.lpr"/>
     193        <Caret Line="19" Column="1" TopLine="1"/>
    185194      </Position21>
    186195      <Position22>
    187         <Filename Value="UMainForm.pas"/>
    188         <Caret Line="24" Column="59" TopLine="23"/>
     196        <Filename Value="BitStreamTest.lpr"/>
     197        <Caret Line="18" Column="29" TopLine="1"/>
    189198      </Position22>
    190199      <Position23>
    191200        <Filename Value="UMainForm.pas"/>
    192         <Caret Line="58" Column="21" TopLine="45"/>
     201        <Caret Line="89" Column="23" TopLine="80"/>
    193202      </Position23>
    194203      <Position24>
    195204        <Filename Value="UMainForm.pas"/>
    196         <Caret Line="72" Column="9" TopLine="59"/>
     205        <Caret Line="15" Column="1" TopLine="3"/>
    197206      </Position24>
    198207      <Position25>
    199         <Filename Value="BitStreamTest.lpr"/>
    200         <Caret Line="19" Column="1" TopLine="1"/>
     208        <Filename Value="UMainForm.pas"/>
     209        <Caret Line="56" Column="11" TopLine="44"/>
    201210      </Position25>
    202211      <Position26>
    203         <Filename Value="BitStreamTest.lpr"/>
    204         <Caret Line="18" Column="29" TopLine="1"/>
     212        <Filename Value="UMainForm.pas"/>
     213        <Caret Line="76" Column="3" TopLine="69"/>
    205214      </Position26>
    206215      <Position27>
    207216        <Filename Value="UMainForm.pas"/>
    208         <Caret Line="89" Column="23" TopLine="80"/>
     217        <Caret Line="15" Column="7" TopLine="3"/>
    209218      </Position27>
    210219      <Position28>
    211220        <Filename Value="UMainForm.pas"/>
    212         <Caret Line="15" Column="1" TopLine="3"/>
     221        <Caret Line="11" Column="1" TopLine="1"/>
    213222      </Position28>
    214223      <Position29>
    215224        <Filename Value="UMainForm.pas"/>
    216         <Caret Line="56" Column="11" TopLine="44"/>
     225        <Caret Line="124" Column="53" TopLine="112"/>
    217226      </Position29>
    218227      <Position30>
    219228        <Filename Value="UMainForm.pas"/>
    220         <Caret Line="22" Column="15" TopLine="10"/>
     229        <Caret Line="143" Column="50" TopLine="131"/>
    221230      </Position30>
    222231    </JumpHistory>
  • CoolStreaming/Demo/BitStream/UMainForm.pas

    r122 r129  
    99  UBitStream;
    1010
    11 const
    12   Symbols: array[0..1] of Char = ('.', '#');
    13 
    1411type
    15   TByteArray = array of Byte;
    16 
     12  TArrayOfByte = array of Byte;
    1713
    1814  { TMainForm }
     
    2319  private
    2420    procedure PrintBitStream(Stream: TBitStream; StringList: TStrings);
    25     procedure PrintData(Data: TByteArray; Count: Integer; StringList: TStrings);
     21    procedure PrintData(Data: TArrayOfByte; Count: Integer; StringList: TStrings);
    2622    procedure PrintStream(Stream: TStream; StringList: TStrings);
    27     { private declarations }
    2823  public
    29     { public declarations }
    3024  end;
    3125
     
    4842  WindowState := wsMaximized;
    4943
    50   with Memo1, Lines do begin
    51   BitStream := TMemoryBitStream.Create;
    52   BitStream2 := TMemoryBitStream.Create;
    53   SetLength(Buffer, 4);
    54   Buffer[0] := $12;
    55   Buffer[1] := $34;
    56   Buffer[2] := $56;
    57   Buffer[3] := $78;
    58   Add('Source data:');
    59   PrintData(Buffer, Length(Buffer) * 8, Lines);
     44  with Memo1, Lines do try
     45    BeginUpdate;
     46    BitStream := TMemoryBitStream.Create;
     47    BitStream2 := TMemoryBitStream.Create;
     48    SetLength(Buffer, 4);
     49    Buffer[0] := $12;
     50    Buffer[1] := $34;
     51    Buffer[2] := $56;
     52    Buffer[3] := $78;
     53    Add('Source data:');
     54    PrintData(Buffer, Length(Buffer) * 8, Lines);
    6055
    61   BitStream.Write(Buffer[0], 28);
    62   Add('Write data to stream:');
    63   PrintBitStream(BitStream, Lines);
    64   // Write second bit array after first which lead to store data as shifted
    65   BitStream.Write(Buffer[0], 28);
    66   Add('Append shifted data to stream:');
    67   PrintBitStream(BitStream, Lines);
     56    BitStream.Write(Buffer[0], 28);
     57    Add('Write data to stream:');
     58    PrintBitStream(BitStream, Lines);
     59    // Write second bit array after first which lead to store data as shifted
     60    BitStream.Write(Buffer[0], 28);
     61    Add('Append shifted data to stream:');
     62    PrintBitStream(BitStream, Lines);
    6863
    69   // Read test of sub bit array
    70   BitStream.Position := 1;
    71   BitStream.Read(Buffer[0], 32);
    72   Add('Read bit data part:');
    73   PrintData(Buffer, Length(Buffer) * 8, Lines);
     64    // Read test of sub bit array
     65    BitStream.Position := 1;
     66    BitStream.Read(Buffer[0], 32);
     67    Add('Read bit data part:');
     68    PrintData(Buffer, Length(Buffer) * 8, Lines);
    7469
    75  (* // Test stream copy
    76   Add('Copy bit block to another stream:');
    77   for I := 0 to BitStream.Size do begin
    78     BitStream.Position := I;
    79     BitStream2.Size := 0;
    80     BitStream2.CopyFrom(BitStream, BitStream.Size);
    81     PrintBitStream(BitStream2, Lines);
    82   end;
    83   for I := 0 to BitStream.Size do begin
    84     BitStream.Position := 0;
    85     BitStream2.Size := 0;
    86     BitStream2.Position := I;
    87     BitStream2.CopyFrom(BitStream, BitStream.Size);
    88     PrintBitStream(BitStream2, Lines);
    89   end;  *)
    90 
    91   Add('Bit copy of substreams');
    92   SetLength(Buffer, 1000);
    93   for Y := 1 to BitStream.Size do begin
    94     Add('Size: ' + IntToStr(Y));
    95     for I := 0 to BitStream.Size - Y do begin
     70   (* // Test stream copy
     71    Add('Copy bit block to another stream:');
     72    for I := 0 to BitStream.Size do begin
    9673      BitStream.Position := I;
    9774      BitStream2.Size := 0;
    98       //BitStream2.CopyFrom(BitStream, Y);
    99       //PrintBitStream(BitStream2, Lines);
    100       SetLength(Buffer, 1000);
    101       C := BitStream.Read(Buffer[0], Y);
    102       SetLength(Buffer, C div 8 + 1);
    103       PrintData(Buffer, C, Lines);
     75      BitStream2.CopyFrom(BitStream, BitStream.Size);
     76      PrintBitStream(BitStream2, Lines);
    10477    end;
    105     Add('');
    106   end;
     78    for I := 0 to BitStream.Size do begin
     79      BitStream.Position := 0;
     80      BitStream2.Size := 0;
     81      BitStream2.Position := I;
     82      BitStream2.CopyFrom(BitStream, BitStream.Size);
     83      PrintBitStream(BitStream2, Lines);
     84    end;  *)
    10785
    108   BitStream.Destroy;
    109   BitStream2.Destroy;
     86    Add('Bit copy of substreams');
     87    SetLength(Buffer, 1000);
     88    for Y := 1 to BitStream.Size do begin
     89      Add('Size: ' + IntToStr(Y));
     90      for I := 0 to BitStream.Size - Y do begin
     91        BitStream.Position := I;
     92        BitStream2.Size := 0;
     93        //BitStream2.CopyFrom(BitStream, Y);
     94        //PrintBitStream(BitStream2, Lines);
     95        SetLength(Buffer, 1000);
     96        C := BitStream.Read(Buffer[0], Y);
     97        SetLength(Buffer, C div 8 + 1);
     98        PrintData(Buffer, C, Lines);
     99      end;
     100      Add('');
     101    end;
     102  finally
     103    BitStream.Free;
     104    BitStream2.Free;
     105    EndUpdate;
    110106  end;
    111107end;
    112108
    113 procedure TMainForm.PrintData(Data: TByteArray; Count: Integer; StringList: TStrings);
     109procedure TMainForm.PrintData(Data: TArrayOfByte; Count: Integer; StringList: TStrings);
    114110var
    115111  I: Integer;
     
    124120    for B := 0 to 7 do begin
    125121      if ((I * 8) + B) >= Count then Break;
    126       Line := Line + Symbols[(OneByte shr B) and 1];
     122      Line := Line + IntToStr((OneByte shr B) and 1);
    127123    end;
    128124  end;
     
    143139    Data := Stream.ReadByte;
    144140    for B := 0 to 7 do
    145       Line := Line + Symbols[(Data shr B) and 1];
     141      Line := Line + IntToStr((Data shr B) and 1);
    146142  end;
    147143  StringList.Add(Line);
     
    150146
    151147procedure TMainForm.PrintBitStream(Stream: TBitStream; StringList: TStrings);
    152 var
    153   I: Integer;
    154   Line: string;
    155148begin
    156   Stream.Position := 0;
    157   for I := 0 to Stream.Size - 1 do
    158     Line := Line + Symbols[Integer(Stream.ReadBit)];
    159   StringList.Add(Line);
    160   //StringList.Add('');
     149  StringList.Add(Stream.AsString);
    161150end;
    162151
Note: See TracChangeset for help on using the changeset viewer.