libktorrent  2.2.0
streamingchunkselector.h
1 /***************************************************************************
2  * Copyright (C) 2010 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef BT_STREAMINGCHUNKSELECTOR_H
22 #define BT_STREAMINGCHUNKSELECTOR_H
23 
24 #include <ktorrent_export.h>
25 #include <set>
26 #include <download/chunkselector.h>
27 
28 
29 namespace bt
30 {
36  class KTORRENT_EXPORT StreamingChunkSelector : public bt::ChunkSelector
37  {
38  public:
40  ~StreamingChunkSelector() override;
41 
42  void init(ChunkManager* cman, Downloader* downer, PeerManager* pman) override;
43  bool select(bt::PieceDownloader* pd, bt::Uint32& chunk) override;
44  void dataChecked(const bt::BitSet& ok_chunks, Uint32 from, Uint32 to) override;
45  void reincluded(bt::Uint32 from, bt::Uint32 to) override;
46  void reinsert(bt::Uint32 chunk) override;
47  bool selectRange(bt::Uint32& from, bt::Uint32& to, bt::Uint32 max_len) override;
48 
50  Uint32 criticialWindowSize() const {return critical_window_size;}
51 
58  void setSequentialRange(bt::Uint32 from, bt::Uint32 to);
59 
61  void setCursor(bt::Uint32 chunk);
62 
63  private:
64  void updateRange();
65  void initRange();
66  bool selectFromPreview(bt::PieceDownloader* pd, bt::Uint32& chunk);
67 
68  private:
69  bt::Uint32 range_start;
70  bt::Uint32 range_end;
71  bt::Uint32 cursor;
72  bt::Uint32 critical_window_size;
73  std::list<Uint32> range;
74  std::set<Uint32> preview_chunks;
75  };
76 
77 }
78 
79 #endif // BT_STREAMINGCHUNKSELECTOR_H
bt::StreamingChunkSelector::setCursor
void setCursor(bt::Uint32 chunk)
Set the cursor location.
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:37
bt::StreamingChunkSelector::selectRange
bool selectRange(bt::Uint32 &from, bt::Uint32 &to, bt::Uint32 max_len) override
bt::ChunkManager
Definition: chunkmanager.h:61
bt::StreamingChunkSelector
Definition: streamingchunkselector.h:37
bt::PieceDownloader
Definition: piecedownloader.h:38
bt::PeerManager
Manages all the Peers.
Definition: peermanager.h:67
bt::Downloader
Manages the downloading.
Definition: downloader.h:68
bt::ChunkSelector
Definition: chunkselector.h:43
bt::StreamingChunkSelector::reinsert
void reinsert(bt::Uint32 chunk) override
bt::StreamingChunkSelector::dataChecked
void dataChecked(const bt::BitSet &ok_chunks, Uint32 from, Uint32 to) override
bt::StreamingChunkSelector::init
void init(ChunkManager *cman, Downloader *downer, PeerManager *pman) override
bt::StreamingChunkSelector::criticialWindowSize
Uint32 criticialWindowSize() const
Get the critical window size in chunks.
Definition: streamingchunkselector.h:50
bt::StreamingChunkSelector::select
bool select(bt::PieceDownloader *pd, bt::Uint32 &chunk) override
bt::StreamingChunkSelector::setSequentialRange
void setSequentialRange(bt::Uint32 from, bt::Uint32 to)
bt::StreamingChunkSelector::reincluded
void reincluded(bt::Uint32 from, bt::Uint32 to) override