File indexing completed on 2024-11-24 04:31:17
0001 /* 0002 SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef BT_STREAMINGCHUNKSELECTOR_H 0008 #define BT_STREAMINGCHUNKSELECTOR_H 0009 0010 #include <download/chunkselector.h> 0011 #include <ktorrent_export.h> 0012 #include <set> 0013 0014 namespace bt 0015 { 0016 /** 0017 ChunkSelector which supports streaming mode. 0018 It has a range of chunks which are to be downloaded sequentially. And it has a cursor, to support jumping around 0019 in the stream. 0020 */ 0021 class KTORRENT_EXPORT StreamingChunkSelector : public bt::ChunkSelector 0022 { 0023 public: 0024 StreamingChunkSelector(); 0025 ~StreamingChunkSelector() override; 0026 0027 void init(ChunkManager *cman, Downloader *downer, PeerManager *pman) override; 0028 bool select(bt::PieceDownloader *pd, bt::Uint32 &chunk) override; 0029 void dataChecked(const bt::BitSet &ok_chunks, Uint32 from, Uint32 to) override; 0030 void reincluded(bt::Uint32 from, bt::Uint32 to) override; 0031 void reinsert(bt::Uint32 chunk) override; 0032 bool selectRange(bt::Uint32 &from, bt::Uint32 &to, bt::Uint32 max_len) override; 0033 0034 /// Get the critical window size in chunks 0035 Uint32 criticialWindowSize() const 0036 { 0037 return critical_window_size; 0038 } 0039 0040 /** 0041 Set the range to be downloaded sequentially. 0042 The cursor will be initialized to the first of the range. 0043 @param from Start of range 0044 @param to End of range 0045 */ 0046 void setSequentialRange(bt::Uint32 from, bt::Uint32 to); 0047 0048 /// Set the cursor location 0049 void setCursor(bt::Uint32 chunk); 0050 0051 private: 0052 void updateRange(); 0053 void initRange(); 0054 bool selectFromPreview(bt::PieceDownloader *pd, bt::Uint32 &chunk); 0055 0056 private: 0057 bt::Uint32 range_start; 0058 bt::Uint32 range_end; 0059 bt::Uint32 cursor; 0060 bt::Uint32 critical_window_size; 0061 std::list<Uint32> range; 0062 std::set<Uint32> preview_chunks; 0063 }; 0064 0065 } 0066 0067 #endif // BT_STREAMINGCHUNKSELECTOR_H