# An Adaptive Buffering Scheme for P2P Live and Time-Shifted Streaming
## 3 Adaptive Buffering Scheme
### Determining the Ratio of Caching and Prefetching Areas  
In our proposed P2P live and time-shifted streaming system, a super peer provides necessary information to peers in its group so that they can determine their ratios of the caching and prefetching areas. Figure 3 represents the buffermap information of several peers belonging to group \(j\) according to their relative playback positions. \(T_{earliest,j}\) and \(T_{latest,j}\) represents the current playback time positions of the earliest peer (i.e., the one closest to the live broadcasting time) and the latest peer in group \(j\), respectively. Table 1 summarizes the symbols used in this paper. Figure 3: Ratio of caching and prefetching areas according to peers’ relative playback position within group \(j\). Figure 2: Peer group management according to peers’ playback periods. Peers must receive necessary chunks from neighbors before a deadline for each chunk to avoid playback interruption. For example, as shown in Figure 3, \(P_{i+1}\) receives chunks from \(P_{i}\), \(P_{i+2}\), and \(P_{i+3}\) (whose buffering periods overlap with its own), and transmits its stored chunks requested by other peers. We can see that there is no peer that requires data that have been already played back by \(P_{i}\) (whose current playback time position is \(T_{latest,j}\)), since all the other peers in group \(j\) have also already played them back. Therefore, \(P_{i}\) does not need to cache data that have been already played back (i.e., those prior to its current playback time position) for other peers within group \(j\). In other words, the peer whose playback time position is latest in a group does not need to cache any data. On the contrary, \(P_{i+k}\) whose current playback position is \(T_{latest,j}\) tends to transmit the largest amount of data to other peers in group \(j\), because none of the other peers have played them back yet (i.e., because playback positions of the other peers in the group are all later than its own). This means that \(P_{i+k}\)'s buffering period is likely to overlap most with those of other peers. To improve the performance of all peers in the same group, it is therefore advantageous to use most of its buffer area excluding the minimum area for prefetching as caching area to provide data to other peers, as shown in Figure 3.  
\[R_{cache,i}=\left(\frac{T_{i}-T_{latest,j}}{T_{earliest,j}-T_{latest,j}} \right)\times\alpha \tag{1}\]  
Therefore, the ratio of caching and prefetching areas in the buffer of each peer is adaptively determined according to its relative playback position within its group, as shown in Equation (1). By increasing the ratio of the caching area as the playback position of a peer moves earlier in time and increasing the ratio of the prefetching area as its playback position moves later, we can significantly increase the overlapping buffered data among peers in a group. To this end, we first estimate how early the playback position of \(P_{i}\) is within group \(j\) by calculating the difference between its own playback position (i.e., \(T_{i}\)) and the latest playback position in group \(j\) (i.e., \(T_{latest,j}\)). To determine the ratio of the caching area of \(P_{i}\)'s buffer (i.e., \(R_{cache,i}\)) proportional to the above result value (i.e., \(T_{i}-T_{latest,i}\)), we divide the value by the entire period calculated by subtracting \(T_{latest,j}\) from \(T_{earliest,j}\). In order to ensure that the earliest peer whose current playback position is \(T_{earliest,j}\) can obtain the minimum prefetching area, we also multiply (\((T_{i}-T_{latest,j})/(T_{earliest,j}-T_{latest,j})\)) by parameter \(\alpha\) to limit the \(R_{cache,i}\) up to \(\alpha\), as shown in Equation (1). \[R_{prefetch,i}=1-R_{cache,i} \tag{2}\]  
Since the prefetching area of \(P_{i}\)'s buffer is the remaining portion excluding the caching area, \(R_{prefetch,i}\) is calculated by using Equation (2).