# Network Coding for Efficient Video Multicast in Device-to-Device Communications
## 3 System Model
### Coding Scheme  
According to the principle of linear network coding, each destination node must obtain sufficient data slices to conduct a decoding operation. While in an unreliable network transmission environment, packet loss is inevitable. Therefore, we need to design encoding and decoding algorithms to improve this situation. We designed a coding scheme, which can improve the SDR through the re-encoding of data slices received by other destination nodes. When a destination node receives enough packets, it calculates the number of received packets that belong to the same video frame. The node conducts a re-encoding operation after receiving enough packets that belong to this video frame; then, the re-encoded packets will be sent out; next, the node conducts decoding operation. The surrounding nodes can recover the original data through the combination of encoded and re-encoded packets. Because complete packets are encoded, it can ensure the effectiveness of re-encoded packets. When there are many destination nodes, the decoding efficiency can be significantly improved. During the process in which the destination node is receiving the re-encoded packets from other destination nodes, it could not always be at a waiting state. After all the data belongs to the next frame arrives, the destination node immediately stops the decoding operation of the previous frame. To deal with different network conditions, we design an encoding algorithm for the source node. In Algorithm 1, During the encoding process, the source node first obtains the value of current signal strength \(V\), and then dynamically set the redundancy according to the \(V\). When the signal strength is greater than \(-60\) dBm, it indicates that the wireless network signal is good, so we use this value as a threshold. When the signal strength is lower than \(-60\) dBm, we will increase the redundancy according to the measured signal strength. This algorithm ensures that the destination node can get enough encoded packets. After the encoding process is finished, the encoded data will be packaged and sent. We record the number of the frame in the header of each packet to prevent repeated reception and encoding. When we encapsulate a package, we pack the encoded data and the corresponding row vectors into the package. When a node receives a data packet, it will check whether the data packet is linearly independent of the packets that have been received. If it is, it discards the data packet; otherwise, it accepts the packet. In this way, nodes can avoid receiving duplicate or linearly dependent data packets. To improve decoding efficiency, we designed a re-encoding algorithm and a decoding algorithm. In the algorithms, \(N\) stands for the frame number, which is placed in the header of the data packet to distinguish different frames. When nodes receive data packets, they need to determine whether the frame number \(N\) in the data packet is the same as the frame number being received. Packets with the same frame number will be accepted; otherwise, the package will be dropped. _Flag_ is the flag of the current frame, _RTlag_ is the flag of re-encoding, and _DFlag_ is the flag of decoding. These flags are recorded in each destination node and are used to mark whether frame data is available. Besides, \(\textbf{P}_{i}\) is a row vector of the random matrix, and \(Y_{i}\) is an encoded data slice corresponding to the row vector. \(G\) is a random matrix composed of the row vectors in the received data packet, and \(H\) is the sum of the encoded data slices that have been received. In Algorithm 2, after receiving a packet, the intermediate node first obtains the video frame number \(N\) of the packet and then checks whether the frame has been re-encoded. In other words, the intermediate node checks whether the frame number \(N\) of the frame already exists in the re-encoding flag _RTlag_. If number \(N\) exists, it means that the node has re-encoded the frame; otherwise, it has not been re-encoded. If the frame has been re-encoded, it will be dropped.