Changeset 741 for soft/giet_vm/applications/mjpeg/mjpeg.c
- Timestamp:
- Dec 10, 2015, 12:16:18 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/mjpeg/mjpeg.c
r740 r741 10 10 // communications between threads uses MWMR channels,. 11 11 // It uses the chained buffer DMA component to display the images on the graphic display. 12 // It contains 6 types of threads (plus the "main" thread, that makes initialisation) 12 // It contains 5 types of threads, plus the "main" thread, that makes initialisation, 13 // dispatch the byte stream to the various pipelines, and makes instrumentation. 13 14 // and 7 types of MWMR communication channels: 14 // - the TGthread is only mapped in cluster[0,0], but all other threads15 // - the main thread is only mapped in cluster[0,0], but all other threads 15 16 // (DEMUX, VLD, IQZZ, IDCT, LIBU) are replicated in all clusters. 16 17 // - all MWMR channels are replicated in all clusters. … … 41 42 42 43 // arrays of pointers on MWMR channels 43 mwmr_channel_t* tg_2_demux[256];// one per cluster44 mwmr_channel_t* main_2_demux[256]; // one per cluster 44 45 mwmr_channel_t* demux_2_vld_data[256]; // one per cluster 45 46 mwmr_channel_t* demux_2_vld_huff[256]; // one per cluster … … 50 51 51 52 // thread trdid ( for pthread_create() and pthread_join() ) 52 pthread_t trdid_tg;53 53 pthread_t trdid_demux[256]; // one per cluster 54 54 pthread_t trdid_vld[256]; // one per cluster … … 74 74 //////////////////////////////////////////////// 75 75 76 extern void tg( );77 76 extern void demux( uint32_t index ); 78 77 extern void vld( uint32_t index ); … … 122 121 uint32_t image_width; 123 122 uint32_t image_height; 123 uint32_t fd; // file descriptor 124 124 125 125 if ( INTERACTIVE_MODE ) … … 165 165 166 166 // open file containing the MJPEG bit stream 167 intfd = giet_fat_open( file_pathname , 0 );167 fd = giet_fat_open( file_pathname , 0 ); 168 168 169 169 giet_pthread_assert( (fd >= 0), … … 190 190 191 191 // allocate MWMR channels in cluster[x][y] 192 tg_2_demux[index]= remote_malloc( sizeof( mwmr_channel_t ) , x , y );193 buffer = remote_malloc( 4 * TG_2_DEMUX_DEPTH , x , y );194 mwmr_init( tg_2_demux[index] , buffer , 1 , TG_2_DEMUX_DEPTH );192 main_2_demux[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y ); 193 buffer = remote_malloc( 4 * MAIN_2_DEMUX_DEPTH , x , y ); 194 mwmr_init( main_2_demux[index] , buffer , 1 , MAIN_2_DEMUX_DEPTH ); 195 195 196 196 demux_2_vld_data[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y ); … … 228 228 giet_fbf_cma_start(); 229 229 230 mwmr_channel_t* p tr;230 mwmr_channel_t* pc; 231 231 232 232 for ( n = 0 ; n < x_size*y_size ; n++ ) 233 233 { 234 p tr = tg_2_demux[n];235 PRINTF(" - tg_2_demux[%d] = %x / &lock = %x / &buf = %x / size = %d\n",236 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )237 238 p tr= demux_2_vld_data[n];234 pc = main_2_demux[n]; 235 PRINTF(" - main_2_demux[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 236 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 237 238 pc = demux_2_vld_data[n]; 239 239 PRINTF(" - demux_2_vld[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 240 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )241 242 p tr= vld_2_iqzz[n];240 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 241 242 pc = vld_2_iqzz[n]; 243 243 PRINTF(" - vld_2_iqzz[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 244 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )245 246 p tr= iqzz_2_idct[n];244 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 245 246 pc = iqzz_2_idct[n]; 247 247 PRINTF(" - iqzz_2_idct[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 248 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )249 250 p tr= idct_2_libu[n];248 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 249 250 pc = idct_2_libu[n]; 251 251 PRINTF(" - idct_2_libu[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 252 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )252 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 253 253 } 254 254 255 255 // launch all threads : precise mapping is defined in the mjpeg.py file 256 256 uint32_t index; 257 258 if ( giet_pthread_create( &trdid_tg, NULL, &tg , NULL ) )259 giet_pthread_exit( "error launching thread tg\n");260 257 261 258 for ( x = 0 ; x < x_size ; x++ ) … … 321 318 } 322 319 320 ///////////////////////////////////////////////////////////////////////////////////// 321 // dispatch the byte stream to the demux threads, one compressed image per cluster. 322 // It transfer the stream from the file identified by the fd argument to a 1024 323 // bytes local buffer. It analyses the stream to detect the End_of_Image markers. 324 // All the bytes corresponding to a single image from the first byte, to the EOI 325 // marker included, are written in the main_2_demux[index] channel, in increasing 326 // order of the cluster index. 327 ///////////////////////////////////////////////////////////////////////////////////// 328 329 // allocate input buffer : 1024 bytes 330 uint8_t bufin[1024]; 331 332 // allocate output bufio to access output MWMR channels : 64 bytes == 16 words 333 mwmr_bufio_t bufio; 334 uint8_t bufout[64]; 335 mwmr_bufio_init( &bufio , bufout , 64 , 0 , main_2_demux[0] ); 336 337 uint32_t image; // image index 338 uint32_t cluster; // cluster index / modulo x_size*y_size 339 uint32_t ptr; // byte pointer in input buffer 340 uint32_t eoi_found; // boolean : End-of-Image found 341 uint32_t ff_found; // boolean : 0xFF value found 342 uint32_t bytes_count; // mumber of bytes in compressed image 343 344 // initialise image and cluster index, and bufin pointer 345 image = 0; 346 cluster = 0; 347 ptr = 0; 348 349 while( image < MAX_IMAGES ) // one compressed image per iteration 350 { 351 // initialise image specific variables 352 eoi_found = 0; 353 ff_found = 0; 354 bytes_count = 0; 355 356 // re-initialise the destination buffer for each image 357 bufio.mwmr = main_2_demux[cluster]; 358 359 // scan bit stream until EOI found 360 // transfer one byte per iteration from input buffer to output bufio 361 while ( eoi_found == 0 ) 362 { 363 // - tranfer 1024 bytes from file to input buffer when input buffer empty. 364 // - return to first byte in input file when EOF found, 365 // to emulate an infinite stream of images. 366 if ( ptr == 0 ) 367 { 368 uint32_t r = giet_fat_read( fd , bufin , 1024 ); 369 if ( r < 1024 ) 370 { 371 giet_fat_lseek( fd , 0 , SEEK_SET ); 372 giet_fat_read( fd , bufin + r , 1024 - r ); 373 } 374 } 375 376 // transfer one byte from input buffer to output bufio 377 mwmr_bufio_write_byte( &bufio , bufin[ptr] ); 378 379 // analyse this byte to find EOI marker OxFFD8 380 // flush the output buffer when EOI found 381 if ( ff_found ) // possible End of Image 382 { 383 ff_found = 0; 384 if ( bufin[ptr] == 0xD9 ) // End of Image found 385 { 386 // exit current image 387 eoi_found = 1; 388 389 // flush output bufio 390 mwmr_bufio_flush( &bufio ); 391 } 392 } 393 else // test if first byte of a marker 394 { 395 if ( bufin[ptr] == 0xFF ) ff_found = 1; 396 } 397 398 // increment input buffer pointer modulo 1024 399 ptr++; 400 if ( ptr == 1024 ) ptr = 0; 401 402 // increment bytes_count for current image 403 bytes_count++; 404 405 } // end while (eoi) 406 407 #if DEBUG_MAIN 408 PRINTF("\nMAIN send image %d to cluster %d at cycle %d : %d bytes\n", 409 image , cluster , giet_proctime() , bytes_count ) 410 #endif 411 // increment image index 412 image++; 413 414 // increment cluster index modulo (x_size*y_size) 415 cluster++; 416 if (cluster == x_size * y_size) cluster = 0; 417 418 } // end while on images 419 420 ///////////////////////////////////////////////////////////////////////////////////// 323 421 // wait all threads completion 324 325 if ( giet_pthread_join( trdid_tg , NULL ) ) 326 { PRINTF("\n[MJPEG ERROR] calling giet_pthread_join() for tg\n" ) } 422 ///////////////////////////////////////////////////////////////////////////////////// 327 423 328 424 for ( x = 0 ; x < x_size ; x++ ) … … 359 455 } 360 456 361 // instrumentation 362 363 uint32_t image; 457 ///////////////////////////////////////////////////////////////////////////////////// 458 // makes instrumentation 459 ///////////////////////////////////////////////////////////////////////////////////// 460 364 461 PRINTF("\n[MJPEG] Instumentation Results\n" ) 365 462 for ( image = 0 ; image < MAX_IMAGES ; image++ )
Note: See TracChangeset
for help on using the changeset viewer.