Ignore:
Timestamp:
Dec 10, 2015, 12:16:18 PM (9 years ago)
Author:
alain
Message:

Remove the TG thread: The mjpeg strem dispatch is
directly done by the main thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/mjpeg/mjpeg.c

    r740 r741  
    1010// communications between threads uses MWMR channels,.
    1111// 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.
    1314// and 7 types of MWMR communication channels:
    14 // - the TG thread is only mapped in cluster[0,0], but all other threads
     15// - the main thread is only mapped in cluster[0,0], but all other threads
    1516//   (DEMUX, VLD, IQZZ, IDCT, LIBU) are replicated in all clusters.
    1617// - all MWMR channels are replicated in all clusters.
     
    4142
    4243// arrays of pointers on MWMR channels
    43 mwmr_channel_t*  tg_2_demux[256];         // one per cluster
     44mwmr_channel_t*  main_2_demux[256];       // one per cluster
    4445mwmr_channel_t*  demux_2_vld_data[256];   // one per cluster
    4546mwmr_channel_t*  demux_2_vld_huff[256];   // one per cluster
     
    5051
    5152// thread trdid ( for pthread_create() and pthread_join() )
    52 pthread_t   trdid_tg;
    5353pthread_t   trdid_demux[256];             // one per cluster
    5454pthread_t   trdid_vld[256];               // one per cluster
     
    7474////////////////////////////////////////////////
    7575
    76 extern void tg( );
    7776extern void demux( uint32_t index );
    7877extern void vld( uint32_t index );
     
    122121    uint32_t      image_width;
    123122    uint32_t      image_height;
     123    uint32_t      fd;                   // file descriptor
    124124
    125125    if ( INTERACTIVE_MODE )
     
    165165
    166166    // open file containing the MJPEG bit stream
    167     int fd = giet_fat_open( file_pathname , 0 );
     167    fd = giet_fat_open( file_pathname , 0 );
    168168
    169169    giet_pthread_assert( (fd >= 0),
     
    190190
    191191            // 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 );
    195195
    196196            demux_2_vld_data[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y );
     
    228228    giet_fbf_cma_start();
    229229
    230     mwmr_channel_t* ptr;
     230    mwmr_channel_t* pc;
    231231
    232232    for ( n = 0 ; n < x_size*y_size ; n++ )
    233233    {
    234         ptr = tg_2_demux[n];
    235         PRINTF(" - tg_2_demux[%d]  = %x / &lock = %x / &buf = %x / size = %d\n",
    236                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    237 
    238         ptr = 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];
    239239        PRINTF(" - demux_2_vld[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    240                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    241 
    242         ptr = 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];
    243243        PRINTF(" - vld_2_iqzz[%d]  = %x / &lock = %x / &buf = %x / size = %d\n",
    244                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    245 
    246         ptr = 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];
    247247        PRINTF(" - iqzz_2_idct[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    248                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    249 
    250         ptr = 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];
    251251        PRINTF(" - idct_2_libu[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    252                n, ptr, (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 )
    253253    }
    254254
    255255    // launch all threads : precise mapping is defined in the mjpeg.py file
    256256    uint32_t index;
    257 
    258     if ( giet_pthread_create( &trdid_tg, NULL, &tg , NULL ) )
    259     giet_pthread_exit( "error launching thread tg\n");
    260257
    261258    for ( x = 0 ; x < x_size ; x++ )
     
    321318    }
    322319
     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
     408PRINTF("\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    /////////////////////////////////////////////////////////////////////////////////////
    323421    // 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    /////////////////////////////////////////////////////////////////////////////////////
    327423
    328424    for ( x = 0 ; x < x_size ; x++ )
     
    359455    }
    360456
    361     // instrumentation
    362 
    363     uint32_t image;
     457    /////////////////////////////////////////////////////////////////////////////////////
     458    // makes instrumentation
     459    /////////////////////////////////////////////////////////////////////////////////////
     460
    364461    PRINTF("\n[MJPEG] Instumentation Results\n" )
    365462    for ( image = 0 ; image < MAX_IMAGES ; image++ )
Note: See TracChangeset for help on using the changeset viewer.