public ChannelStreamer(Protocol protocol, Media.File file, byte[] key, MusicStream output) { if (key.Length != (128 / 8)) { output.AllAvailable = true; throw new InvalidDataException("Encryption key for channel must be 128-bit."); } _cipher.BlockSize = 128; _cipher.KeySize = 128; _key = key; _cipher.Mode = CipherMode.ECB; //CTR not available _cipher.Padding = PaddingMode.None; _output = output; _file = file; _protocol = protocol; _channelLength = 160 * 1024 * 5 / 8; /* 160 kbit * 5 seconds. */ /* Send first substream request. */ string hash = this._cache.Hash(this._file, this._channelOffset, this._channelLength); if (this._cache != null && this._cache.Contains("substream", hash)) { this._cache.Load("substream", hash, this); } else { try { this._protocol.SendSubstreamRequest(this, this._file, this._channelOffset, this._channelLength); } catch (ProtocolException) { return; } } }
public string Hash(Media.File file, int offset, int length) { return file.Id + "/" + offset + "-" + length; }