1 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : libu.c |
---|
3 | // Date : octobre 2015 |
---|
4 | // author : Alain Greiner |
---|
5 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
6 | // This file define the code of the LIBU (line building) thread for MJPEG application. |
---|
7 | // This function execute an infinite loop on a stream of decompressed images. |
---|
8 | // The image size is fbf_width * fbf_height pixels. Each pixel is one byte. |
---|
9 | // The LIBU[index] thread read all blocks of a given image to fill its private |
---|
10 | // bufout[index] buffer, that is part of a FBF_CMA chbuf. |
---|
11 | // For each image: |
---|
12 | // - it checks that buf_out[index] is empty (released by the CMA peripheral). |
---|
13 | // - it move all blocks fom the input MWMR channel to the bufout[index] buffer. |
---|
14 | // - it request the CMA peripheral to display the image stored in bufout[index] |
---|
15 | // - It register the date of display in the date[] array for intrumentation. |
---|
16 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <mwmr_channel.h> |
---|
20 | #include <stdint.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include "mjpeg.h" |
---|
23 | |
---|
24 | // macro to use a shared TTY |
---|
25 | #define PRINTF(...) lock_acquire( &tty_lock ); \ |
---|
26 | giet_tty_printf(__VA_ARGS__); \ |
---|
27 | lock_release( &tty_lock ); |
---|
28 | |
---|
29 | ////////////////////////////////////////////////////////////// |
---|
30 | __attribute__ ((constructor)) void libu( unsigned int index ) |
---|
31 | ////////////////////////////////////////////////////////////// |
---|
32 | { |
---|
33 | mwmr_channel_t* input = idct_2_libu[index]; |
---|
34 | |
---|
35 | uint32_t time; |
---|
36 | |
---|
37 | uint8_t bufin[64]; |
---|
38 | uint32_t line; |
---|
39 | uint32_t column; |
---|
40 | |
---|
41 | // get platform parameters |
---|
42 | uint32_t x_size; |
---|
43 | uint32_t y_size; |
---|
44 | uint32_t nprocs; |
---|
45 | giet_procs_number( &x_size , &y_size , &nprocs ); |
---|
46 | |
---|
47 | // get processor coordinates |
---|
48 | unsigned int x , y , p; |
---|
49 | giet_proc_xyp( &x ,&y , &p ); |
---|
50 | |
---|
51 | // private TTY allocation |
---|
52 | // giet_tty_alloc( 0 ); |
---|
53 | |
---|
54 | PRINTF("\n[MJPEG] thread LIBU[%d] starts on P[%d,%d,%d]\n", index , x , y , p ) |
---|
55 | |
---|
56 | uint32_t image = index; |
---|
57 | |
---|
58 | while( image < MAX_IMAGES ) // one image per iteration |
---|
59 | { |
---|
60 | // check CMA buffer empty |
---|
61 | giet_fbf_cma_check( index ); |
---|
62 | |
---|
63 | // two loops on blocks to build image |
---|
64 | for ( line = 0 ; line < nblocks_h ; ++line ) |
---|
65 | { |
---|
66 | for ( column = 0 ; column < nblocks_w ; ++column ) |
---|
67 | { |
---|
68 | // move one block from input MWMR channel (one byte per pixel |
---|
69 | mwmr_read( input , (uint32_t*)bufin , 16 ); |
---|
70 | |
---|
71 | // copy block to cma_buf |
---|
72 | unsigned int i; |
---|
73 | unsigned int src; |
---|
74 | unsigned int dst; |
---|
75 | for ( i = 0; i < 8 ; ++i ) |
---|
76 | { |
---|
77 | src = (i * 8); |
---|
78 | dst = ((line * 8 + i) * fbf_width) + (column * 8); |
---|
79 | |
---|
80 | // copy 8 bytes to cma_buf[index] |
---|
81 | memcpy( &cma_buf[index][dst] , &bufin[src] , 8 ); |
---|
82 | } |
---|
83 | |
---|
84 | #if (DEBUG_LIBU > 1) |
---|
85 | PRINTF("\nLIBU[%d] copy block[%d] for image %d\n", |
---|
86 | index, line * nblocks_w + column , image ) |
---|
87 | #endif |
---|
88 | } |
---|
89 | |
---|
90 | } // end loops on blocks |
---|
91 | |
---|
92 | // request CMA to display image |
---|
93 | giet_fbf_cma_display( index ); |
---|
94 | |
---|
95 | // get date of display |
---|
96 | time = giet_proctime(); |
---|
97 | |
---|
98 | #if DEBUG_LIBU |
---|
99 | PRINTF("\nLIBU[%d] completes image %d at cycle %d\n", index , image , time ) |
---|
100 | #endif |
---|
101 | // register date of display for instrumentation |
---|
102 | date[image] = time; |
---|
103 | |
---|
104 | image = image + x_size*y_size; |
---|
105 | |
---|
106 | } // end while on images |
---|
107 | |
---|
108 | giet_pthread_exit( "libu completed" ); |
---|
109 | |
---|
110 | } // end libu() |
---|
111 | |
---|