1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
void* threadReaderFrameBuffer ( void* arg ) {
printf ( "[threadReaderFrameBuffer] se lance \n" ) ;
threadReaderFrameBufferIsWorking = true ;
// ouverture du frame buffer
int frameBuffer = open ( "/dev/fb0", O_RDONLY ) ;
if ( frameBuffer == -1 ) {
perror ( "Erreur a l'ouverture du frameBuffer de VLC \n" ) ;
exit ( 1 ) ;
}
printf ( "Ouverture du frameBuffer de VLC avec succes \n" ) ;
// frame recuperee sur le frame buffer
unsigned char* frameVLC = ( unsigned char* ) mmap ( 0, 1024 * 768 * 2, PROT_READ, MAP_SHARED, frameBuffer, 0) ;
while ( frameVLC != ( void* ) -1 ) {
// allocation d'une frame video qu'on envoit dans le buffer YUV
unsigned char* currentFrame = ( unsigned char* ) malloc ( 1024 * 768 * 2 ) ;
// posix_memalign ( ( void** ) ¤tFrame, 4096, 1024 * 768 * 2 ) ;
// recopie du contenu du frameBuffer VLC dans cette frame
memcpy ( ( void* ) currentFrame, ( void* ) frameVLC, 1024 * 768 * 2 ) ;
// currentFrame pointe sur l'image de la capture d'ecran en 1024 * 768 YUY2
// on l'a convertit en 1024 * 768 RGB
currentFrame = YUY2toRGB ( 1024, 768, currentFrame ) ;
// on la filtre pour obtenir une image 720 * 576 RGB
currentFrame = gaussianFilter ( currentFrame ) ;
// on convertit cette image filtree au format YUY2
// currentFrame = RGBtoYUY2 ( 720, 576, currentFrame ) ;
// currentFrame pointe sur une image allouee par posix_memalign en 720 * 576 YUY2 lisible par la carte AJA
// si le buffer YUV est plein, on bloque le thread
if ( bufferYUV.size() == NBFRAMEBUFFERYUV ) {
threadReaderFrameBufferIsWorking = false ;
printf ( "[threadReaderFrameBuffer] se bloque \n" ) ; fflush ( stdout ) ;
pthread_cond_wait( &conditionYUV_cond, &conditionYUV_mutex ) ;
}
// on envoit la frame lue dans le buffer YUV
pthread_mutex_lock ( &conditionYUV_mutex ) ;
printf ( "[threadReaderFrameBuffer] envoi d'une frame dans le buffer YUV ... " ) ; fflush ( stdout ) ;
bufferYUV.push ( currentFrame ) ;
printf ( "ok \n" ) ; fflush ( stdout ) ;
pthread_mutex_unlock ( &conditionYUV_mutex ) ;
// si le buffer YUV etait vide, on reveille le thread AJA
if ( bufferYUV.size () == 1 ) {
AJAThreadIsWorking = true ;
printf ( "[AJA] se reveille \n" ) ; fflush ( stdout ) ;
pthread_cond_broadcast( &conditionYUV_cond ) ;
}
} // fin boucle de lecture
// on a fini de lire toutes les donnees depuis le buffer
threadReaderFrameBufferIsWorking = false ;
threadReaderFrameBufferEnd = true ;
free ( frameVLC ) ;
printf ( "[threadReaderFrameBuffer] a termine \n" ) ;
exit ( 1 ) ;
} |
Partager