Changeset 127 for CoolStreaming


Ignore:
Timestamp:
Jan 16, 2011, 3:08:56 PM (13 years ago)
Author:
george
Message:
  • Přidáno: Kódování a dekódování dynamického čísla. Použita kombinace rekurzivní délky a absolutní binární hodnoty s virtuální nejvyšší jedničkou.
Location:
CoolStreaming
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/Demo/DynNumber/DynNumberDemo.lpi

    r126 r127  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="14">
     41    <Units Count="15">
    4242      <Unit0>
    4343        <Filename Value="DynNumberDemo.lpr"/>
    4444        <IsPartOfProject Value="True"/>
    4545        <UnitName Value="DynNumberDemo"/>
    46         <EditorIndex Value="1"/>
    4746        <WindowIndex Value="0"/>
    4847        <TopLine Value="1"/>
    4948        <CursorPos X="41" Y="19"/>
    50         <UsageCount Value="36"/>
    51         <Loaded Value="True"/>
     49        <UsageCount Value="39"/>
    5250      </Unit0>
    5351      <Unit1>
     
    6058        <EditorIndex Value="0"/>
    6159        <WindowIndex Value="0"/>
    62         <TopLine Value="67"/>
    63         <CursorPos X="23" Y="89"/>
    64         <UsageCount Value="36"/>
     60        <TopLine Value="39"/>
     61        <CursorPos X="24" Y="53"/>
     62        <UsageCount Value="39"/>
    6563        <Loaded Value="True"/>
    6664        <LoadedDesigner Value="True"/>
     
    6967        <Filename Value="..\..\UDynNumber.pas"/>
    7068        <UnitName Value="UDynNumber"/>
    71         <EditorIndex Value="2"/>
     69        <EditorIndex Value="1"/>
    7270        <WindowIndex Value="0"/>
    7371        <TopLine Value="11"/>
    74         <CursorPos X="49" Y="26"/>
    75         <UsageCount Value="18"/>
     72        <CursorPos X="8" Y="14"/>
     73        <UsageCount Value="20"/>
    7674        <Loaded Value="True"/>
    7775      </Unit2>
     
    7977        <Filename Value="..\..\UBitStream.pas"/>
    8078        <UnitName Value="UBitStream"/>
    81         <EditorIndex Value="5"/>
    82         <WindowIndex Value="0"/>
    83         <TopLine Value="17"/>
    84         <CursorPos X="49" Y="33"/>
    85         <UsageCount Value="18"/>
     79        <EditorIndex Value="4"/>
     80        <WindowIndex Value="0"/>
     81        <TopLine Value="37"/>
     82        <CursorPos X="14" Y="53"/>
     83        <UsageCount Value="20"/>
    8684        <Loaded Value="True"/>
    8785      </Unit3>
     
    8987        <Filename Value="..\..\UBufferedFileStream.pas"/>
    9088        <UnitName Value="UBufferedFileStream"/>
    91         <EditorIndex Value="3"/>
     89        <EditorIndex Value="2"/>
    9290        <WindowIndex Value="0"/>
    9391        <TopLine Value="38"/>
    9492        <CursorPos X="30" Y="54"/>
    95         <UsageCount Value="18"/>
     93        <UsageCount Value="20"/>
    9694        <Loaded Value="True"/>
    9795      </Unit4>
    9896      <Unit5>
    9997        <Filename Value="..\..\..\..\..\..\..\..\usr\share\fpcsrc\2.4.0\rtl\objpas\classes\classesh.inc"/>
    100         <EditorIndex Value="4"/>
     98        <EditorIndex Value="3"/>
    10199        <WindowIndex Value="0"/>
    102100        <TopLine Value="773"/>
    103101        <CursorPos X="17" Y="789"/>
    104         <UsageCount Value="18"/>
     102        <UsageCount Value="20"/>
    105103        <Loaded Value="True"/>
    106104      </Unit5>
     
    163161        <UsageCount Value="10"/>
    164162      </Unit13>
     163      <Unit14>
     164        <Filename Value="..\..\..\..\..\..\..\..\usr\share\fpcsrc\2.4.0\rtl\inc\mathh.inc"/>
     165        <WindowIndex Value="0"/>
     166        <TopLine Value="62"/>
     167        <CursorPos X="14" Y="78"/>
     168        <UsageCount Value="11"/>
     169      </Unit14>
    165170    </Units>
    166     <JumpHistory Count="29" HistoryIndex="28">
     171    <JumpHistory Count="30" HistoryIndex="29">
    167172      <Position1>
    168173        <Filename Value="UMainForm.pas"/>
    169         <Caret Line="101" Column="1" TopLine="87"/>
     174        <Caret Line="56" Column="1" TopLine="39"/>
    170175      </Position1>
    171176      <Position2>
    172         <Filename Value="UMainForm.pas"/>
    173         <Caret Line="102" Column="1" TopLine="87"/>
     177        <Filename Value="..\..\UDynNumber.pas"/>
     178        <Caret Line="31" Column="1" TopLine="21"/>
    174179      </Position2>
    175180      <Position3>
    176         <Filename Value="UMainForm.pas"/>
    177         <Caret Line="103" Column="1" TopLine="87"/>
     181        <Filename Value="..\..\UDynNumber.pas"/>
     182        <Caret Line="32" Column="1" TopLine="21"/>
    178183      </Position3>
    179184      <Position4>
    180         <Filename Value="UMainForm.pas"/>
    181         <Caret Line="104" Column="1" TopLine="87"/>
     185        <Filename Value="..\..\UDynNumber.pas"/>
     186        <Caret Line="33" Column="1" TopLine="21"/>
    182187      </Position4>
    183188      <Position5>
    184         <Filename Value="UMainForm.pas"/>
    185         <Caret Line="105" Column="1" TopLine="87"/>
     189        <Filename Value="..\..\UDynNumber.pas"/>
     190        <Caret Line="34" Column="1" TopLine="21"/>
    186191      </Position5>
    187192      <Position6>
    188         <Filename Value="UMainForm.pas"/>
    189         <Caret Line="106" Column="1" TopLine="87"/>
     193        <Filename Value="..\..\UDynNumber.pas"/>
     194        <Caret Line="31" Column="1" TopLine="21"/>
    190195      </Position6>
    191196      <Position7>
    192         <Filename Value="UMainForm.pas"/>
    193         <Caret Line="79" Column="1" TopLine="63"/>
     197        <Filename Value="..\..\UDynNumber.pas"/>
     198        <Caret Line="32" Column="1" TopLine="21"/>
    194199      </Position7>
    195200      <Position8>
    196         <Filename Value="UMainForm.pas"/>
    197         <Caret Line="94" Column="1" TopLine="77"/>
     201        <Filename Value="..\..\UDynNumber.pas"/>
     202        <Caret Line="35" Column="1" TopLine="21"/>
    198203      </Position8>
    199204      <Position9>
    200         <Filename Value="UMainForm.pas"/>
    201         <Caret Line="96" Column="1" TopLine="77"/>
     205        <Filename Value="..\..\UDynNumber.pas"/>
     206        <Caret Line="36" Column="1" TopLine="21"/>
    202207      </Position9>
    203208      <Position10>
    204         <Filename Value="UMainForm.pas"/>
    205         <Caret Line="97" Column="1" TopLine="77"/>
     209        <Filename Value="..\..\UDynNumber.pas"/>
     210        <Caret Line="37" Column="1" TopLine="21"/>
    206211      </Position10>
    207212      <Position11>
    208         <Filename Value="UMainForm.pas"/>
    209         <Caret Line="99" Column="1" TopLine="87"/>
     213        <Filename Value="..\..\UDynNumber.pas"/>
     214        <Caret Line="38" Column="1" TopLine="21"/>
    210215      </Position11>
    211216      <Position12>
    212         <Filename Value="UMainForm.pas"/>
    213         <Caret Line="81" Column="15" TopLine="63"/>
     217        <Filename Value="..\..\UDynNumber.pas"/>
     218        <Caret Line="36" Column="1" TopLine="21"/>
    214219      </Position12>
    215220      <Position13>
    216         <Filename Value="UMainForm.pas"/>
    217         <Caret Line="80" Column="15" TopLine="62"/>
     221        <Filename Value="..\..\UDynNumber.pas"/>
     222        <Caret Line="37" Column="1" TopLine="21"/>
    218223      </Position13>
    219224      <Position14>
    220         <Filename Value="UMainForm.pas"/>
    221         <Caret Line="81" Column="15" TopLine="63"/>
     225        <Filename Value="..\..\UBitStream.pas"/>
     226        <Caret Line="164" Column="1" TopLine="149"/>
    222227      </Position14>
    223228      <Position15>
    224         <Filename Value="UMainForm.pas"/>
    225         <Caret Line="48" Column="15" TopLine="32"/>
     229        <Filename Value="..\..\UBitStream.pas"/>
     230        <Caret Line="246" Column="1" TopLine="230"/>
    226231      </Position15>
    227232      <Position16>
    228         <Filename Value="UMainForm.pas"/>
    229         <Caret Line="122" Column="17" TopLine="102"/>
     233        <Filename Value="..\..\UBitStream.pas"/>
     234        <Caret Line="249" Column="1" TopLine="230"/>
    230235      </Position16>
    231236      <Position17>
    232         <Filename Value="UMainForm.pas"/>
    233         <Caret Line="78" Column="33" TopLine="78"/>
     237        <Filename Value="..\..\UBitStream.pas"/>
     238        <Caret Line="250" Column="1" TopLine="230"/>
    234239      </Position17>
    235240      <Position18>
    236         <Filename Value="UMainForm.pas"/>
    237         <Caret Line="93" Column="19" TopLine="77"/>
     241        <Filename Value="..\..\UBitStream.pas"/>
     242        <Caret Line="251" Column="1" TopLine="230"/>
    238243      </Position18>
    239244      <Position19>
    240245        <Filename Value="..\..\UBitStream.pas"/>
    241         <Caret Line="38" Column="51" TopLine="22"/>
     246        <Caret Line="252" Column="1" TopLine="230"/>
    242247      </Position19>
    243248      <Position20>
    244249        <Filename Value="..\..\UBitStream.pas"/>
    245         <Caret Line="162" Column="33" TopLine="142"/>
     250        <Caret Line="253" Column="1" TopLine="230"/>
    246251      </Position20>
    247252      <Position21>
    248253        <Filename Value="..\..\UBitStream.pas"/>
    249         <Caret Line="38" Column="41" TopLine="22"/>
     254        <Caret Line="254" Column="1" TopLine="230"/>
    250255      </Position21>
    251256      <Position22>
    252257        <Filename Value="..\..\UBitStream.pas"/>
    253         <Caret Line="157" Column="48" TopLine="141"/>
     258        <Caret Line="255" Column="1" TopLine="230"/>
    254259      </Position22>
    255260      <Position23>
    256         <Filename Value="UMainForm.pas"/>
    257         <Caret Line="93" Column="19" TopLine="77"/>
     261        <Filename Value="..\..\UBitStream.pas"/>
     262        <Caret Line="257" Column="1" TopLine="230"/>
    258263      </Position23>
    259264      <Position24>
    260         <Filename Value="UMainForm.pas"/>
    261         <Caret Line="105" Column="16" TopLine="75"/>
     265        <Filename Value="..\..\UBitStream.pas"/>
     266        <Caret Line="258" Column="1" TopLine="231"/>
    262267      </Position24>
    263268      <Position25>
    264         <Filename Value="UMainForm.pas"/>
    265         <Caret Line="91" Column="24" TopLine="75"/>
     269        <Filename Value="..\..\UBitStream.pas"/>
     270        <Caret Line="241" Column="1" TopLine="231"/>
    266271      </Position25>
    267272      <Position26>
    268         <Filename Value="UMainForm.pas"/>
    269         <Caret Line="99" Column="80" TopLine="84"/>
     273        <Filename Value="..\..\UBitStream.pas"/>
     274        <Caret Line="242" Column="1" TopLine="231"/>
    270275      </Position26>
    271276      <Position27>
    272         <Filename Value="UMainForm.pas"/>
    273         <Caret Line="92" Column="14" TopLine="82"/>
     277        <Filename Value="..\..\UBitStream.pas"/>
     278        <Caret Line="243" Column="1" TopLine="231"/>
    274279      </Position27>
    275280      <Position28>
    276         <Filename Value="UMainForm.pas"/>
    277         <Caret Line="105" Column="37" TopLine="89"/>
     281        <Filename Value="..\..\UBitStream.pas"/>
     282        <Caret Line="193" Column="1" TopLine="177"/>
    278283      </Position28>
    279284      <Position29>
    280         <Filename Value="UMainForm.pas"/>
    281         <Caret Line="106" Column="61" TopLine="89"/>
     285        <Filename Value="..\..\UBitStream.pas"/>
     286        <Caret Line="194" Column="1" TopLine="177"/>
    282287      </Position29>
     288      <Position30>
     289        <Filename Value="..\..\UBitStream.pas"/>
     290        <Caret Line="53" Column="14" TopLine="37"/>
     291      </Position30>
    283292    </JumpHistory>
    284293  </ProjectOptions>
  • CoolStreaming/Demo/DynNumber/UMainForm.pas

    r126 r127  
    5151    ListView1.BeginUpdate;
    5252    ListView1.Clear;
    53     for I := 0 to 16 do begin
     53    for I := 0 to 10000 do begin
    5454      N.Stream.Size := 0;
    5555      N.Write(I);
     
    6060      NewItem := ListView1.Items.Add;
    6161      NewItem.Caption := IntToStr(I);
    62       NewItem.SubItems.Add('');
     62      J := Floor(Log2(I)) + 1;
     63      NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100));
    6364      NewItem.SubItems.Add(Line);
    6465    end;
     
    7273var
    7374  I: Integer;
     75  II: Integer;
    7476  Count: Integer;
    7577  Parts: array of Integer;
     
    8082  NewItem: TListItem;
    8183  N: TDynamicNumber;
     84const
     85  Step = 1;
    8286begin
    8387  Count := 1;
     
    8791    ListView1.BeginUpdate;
    8892    ListView1.Clear;
    89     for I := 0 to 1000 do begin
    90 
     93    for II := 0 to 20000 do begin
     94      I := II * Step;
    9195    // Write
    9296    N.Stream.Size := 0;
     
    104108    NewItem.Caption := IntToStr(I);
    105109    J := Floor(Log2(I)) + 1;
    106     NewItem.SubItems.Add(FloatToStr(1 - (J / N.Stream.Size)));
     110    NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100));
    107111    Line := '';
    108112    N.Stream.Position := 0;
     
    112116
    113117    // Increment value
     118    for J := 0 to Step - 1 do begin
    114119    PartIndex := Count - 1;
    115120    repeat
    116121      Parts[PartIndex] := Parts[PartIndex] + 1;
    117       if PartIndex > 0 then MaxValue := 1 shl (Parts[PartIndex - 1] + 1)
     122      if PartIndex > 0 then MaxValue := 1 shl (Parts[PartIndex - 1] + 1 + PartIndex)
    118123        else MaxValue := 2;
    119124      if Parts[PartIndex] >= MaxValue then begin
     
    129134      end else Break;
    130135    until False;
     136    end;
    131137    end;
    132138  finally
  • CoolStreaming/UDynNumber.pas

    r126 r127  
    66
    77uses
    8   Classes, SysUtils, UBitStream;
     8  Classes, SysUtils, UBitStream, Math;
    99
    1010type
     
    2626procedure TDynamicNumber.Write(Value: QWord);
    2727var
    28   C: Integer;
    29   Parts: array of Integer;
     28  Bit: Byte;
     29  Length: Integer;
    3030begin
    31   C := 0;
    32   for C := 0 to Value do
    33     Stream.WriteBit(True);
    34   Stream.WriteBit(False);
     31  Length := Floor(Log2(Value)) + 1;
     32  if Length > 1 then begin
     33    Stream.WriteNumber(1, 1);
     34    Write(Length - 2);
     35  end else Stream.WriteNumber(0, 1);
     36  if Length > 1 then Length := Length - 1;
     37  Stream.WriteNumber(Value, Length);
    3538end;
    3639
    3740function TDynamicNumber.Read: QWord;
     41var
     42  Bit: Byte;
     43  Length: Integer;
    3844begin
    39 
     45  Bit := Stream.ReadNumber(1);
     46  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);
    4050end;
    4151
Note: See TracChangeset for help on using the changeset viewer.