# Network Coding for Efficient Video Multicast in Device-to-Device Communications
## 3 System Model
### Coding Scheme
Otherwise, it will be recorded. Then we need to determine whether the packet belongs to the current frame. If it does not belong to the current frame, we store the data and mark the frame number. If it does, we verify the availability of the data. If the data is not available, the data packet will be dropped. Otherwise, the data will be saved. Then we check if the amount of data is sufficient. If \(K\) linearly independent packets are received, these packets will be re-encoded and sent out. In Algorithm 3, after receiving a packet, the destination node first obtains its video frame number \(N\). The destination node then checks whether \(N\) already exists in the decoding flag _DFlag_. If exists, it indicates that the frame has been decoded; otherwise, it means that the frame has not been decoded. If the frame is not decoded, the algorithm checks the availability of the data. If the data is useful, it will be stored in the memory for further decoding. After loading the encoded data slice, the integrity of the data should be checked first. If the data slice is enough, the random matrix in it will be extracted, and then the inverse matrix of the random matrix should be calculated. After that, the inverse matrix and the encoded data should be multiplied to recover the original data, namely the original video frame in the H.264 format. Finally, the data frame in the H.264 format is sent to the play module. If there is insufficient data or the decoding operation has been completed, the next packet is immediately fetched. ```
1:Intermediate node \(T\) receives a packet \(pkg2\) from \(S\). 2:\(T\) extracts frame number \(N\) from \(pkg2\). 3:IfN==RFlag
4:\(T\) discards \(pkg2\). 5:Else
6:\(T\) extracts row vector \(P_{i}\) and encoded data slice \(Y_{i}\) from \(pkg2\). 7:IfN==Flag
8:\(r1\)=rank(G)
9:\(r2\)=rank(\(P_{i}\cup G\))
10:If\(r2\)>\(r1\)do
11: Add \(P_{i}\) into matrix \(G\). 12: Add \(P_{i}\) into existing encoded data \(H\). 13:Count++;
14:IfCount==\(K\)
15: Re-encode \(G\), \(H\) and compose new data packets \(pkg\). 16:\(T\) sends \(pkg\) back to the network. 17:RFlag=\(N\)
18:endif
19:endif
20:Else
21:Flag=\(N\)
22: Get K from \(pkg2\) and save the data in it
23: Clear matrix \(G\) and encoded data \(H\)
24:Count==0
25:endif
26:endif
```  
**Algorithm 2** Re-encoding strategy  
```
1:Destination node \(D\) receives a packet \(pkg3\). 2:D gets frame number \(N\) from \(pkg3\). 3:IfN==DFlag
4:\(D\) discards \(pkg3\). 5:Else
6:\(D\) gets row vector \(P_{i}\) and coded data slice \(Y_{i}\) from \(pkg3\). 7:IfN==Flag
8:\(r1\)=rank(\(G\))
9:\(r2\)=rank(\(P_{i}\cup G\))
10:If\(r2\)>\(r1\)do
11: Put \(P_{i}\) into \(G\)
12: Put \(Y_{i}\) into existing encoded data \(H\). 13:Count++;
14:IfCount==\(K\)
15:\(D\) calculates the inverse matrix \(G^{-1}\) of \(G\). 16:\(D\) uses \(G^{-1}\) to decode \(H\) into raw data \(P\). 17:\(D\) sends \(P\) to the play module. 18:\(D\)FIag=\(N\)
19:endif
20:endif
21:Else
22:Flag=\(N\)
23:\(D\) gets \(K\) from \(pkg3\). 24: Clear matrix \(G\) and encoded data \(H\)
25:Count=0
26:goto step 6
27:endif
```  
**Algorithm 3** Decoding strategy at the destination node