## 4 Video Compression Sub-Application Layer Protocol for WVSN
### M-Frame
#### 4.1.1 M-Frames Compression  
In M-MPEG, M-Frame compression has been performed in 5 steps sequentially:  
_Step 1: 128_ is subtracted from each pixel of M-Frame to put zero in the middle of the range [34]. Next, each M-Frame is divided up into 8\(\times\)8 blocks without overlapping. An example is shown in Figures 2 (a, b, and c).  
_Step 2_: DCT [35] is applied to each block independently. The output of each DCT is an 8\(\times\)8 matrix of DCT coefficients as shown in Figure 2.d.  
Figure 2: a) M-Frame Structure, b) The operations are done over M-Frame, c) M-Frame Blocked structure, and DCT is performed over Blockij, d) An 8\(\times\)8 matrix of DCT coefficients called: \(T\).  
_Step 3_: In this phase that is called quantization phase; the less important DCT coefficients are wiped out using quantization matrix. To do this, each of the coefficients in the 8\(\times\)8 DCT matrix (_T_) is divided by the corresponding standard quantization matrix elements (_Z_) [34]. The _quality coefficient_ can be used to adjust compression ratio to get the expected video frame quality. Figure 3 exemplifies this step.  
_Step 4_: The elements of each block are partitioned into _13_ levels as it is shown in Figure 4.a. This structure is formed in order of importance of DCT quantized coefficients in each block. Also, this scheme facilitates linearization which happens in the next step. Each level has a priority that is assigned to it using the Algorithm.1 in Figure 4.b.  
In Figure 4.b, \(N\) defines the number of priority levels that are chosen for transmission. This value is selected by the user with regards to the constraints and specified application. It determines the amount of sent pixels, thus, \(N\) has a direct influence on video quality and energy consumption. Since Level-1 (_L1_) contains a DC component and two major low frequency AC components (as shown in Figure 4.a), it has a higher priority and, as is shown in Figure 4.b, _P_M(1) is dedicated to it. Thus, it is necessary to send the data packets with priority _P_M(1) to the Sink in a more reliable way. To achieve full reliability, all communication stack layers cooperate with each other. _P_M(N) is the lowest priority because the most of elements in this level are zero DCT coefficients. Data packets with priority level _P_M(N) are discarded immediately because they have not great effects on video quality. _P_M(2) to _P_M(N-1) are assigned to the  
Figure 4: a) The used scheme for leveling, b) Algorithm to assign priority levels  
Figure 3: a) The standard luminance matrix called: \(Z\), b) The operation is performed over both \(T\) and \(Z\) matrixes, c) An 8\(\times\)8 Quantized matrix called: \(Q\).  
other levels from \(2\) to _N-1_, respectively. Data packets with these priority levels are transmitted using semi-reliable policies. These policies have used different probabilities for transmitting data packets. Policies and the way in which probabilities are assigned to each level are described in Sections 6.2.  
_Step 5_: The _64_ elements of each block are linearized and run-length encoding is applied to the result. ZigZag transform is used to linearize block elements.  
After end of these steps M-Frame data packets are transferred to the next communication layers where hop-by-hop transmission is used to deliver them to the base-station (Sink).