📄 video_output.c
字号:
break;#endif } if( p_free_picture->p_data != NULL ) { /* Copy picture informations, set some default values */ p_free_picture->i_type = i_type; p_free_picture->i_status = RESERVED_PICTURE; p_free_picture->i_matrix_coefficients = 1; p_free_picture->i_width = i_width; p_free_picture->i_height = i_height; p_free_picture->i_chroma_width = i_chroma_width; p_free_picture->i_display_horizontal_offset = 0; p_free_picture->i_display_vertical_offset = 0; p_free_picture->i_display_width = i_width; p_free_picture->i_display_height = i_height; p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE; p_free_picture->i_refcount = 0; p_vout->i_pictures++; } else { /* Memory allocation failed : set picture as empty */ p_free_picture->i_type = EMPTY_PICTURE; p_free_picture->i_status = FREE_PICTURE; p_free_picture = NULL; intf_ErrMsg("warning: %s\n", strerror( ENOMEM ) ); }#ifdef DEBUG_VIDEO intf_DbgMsg("picture %p (in free picture slot)\n", p_free_picture );#endif vlc_mutex_unlock( &p_vout->picture_lock ); return( p_free_picture ); } /* No free or destroyed picture could be found */ intf_DbgMsg( "warning: heap is full\n" ); vlc_mutex_unlock( &p_vout->picture_lock ); return( NULL );}/***************************************************************************** * vout_DestroyPicture: remove a permanent or reserved picture from the heap ***************************************************************************** * This function frees a previously reserved picture or a permanent * picture. It is meant to be used when the construction of a picture aborted. * Note that the picture will be destroyed even if it is linked ! *****************************************************************************/void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic ){ vlc_mutex_lock( &p_vout->picture_lock );#ifdef DEBUG /* Check if picture status is valid */ if( (p_pic->i_status != RESERVED_PICTURE) && (p_pic->i_status != RESERVED_DATED_PICTURE) && (p_pic->i_status != RESERVED_DISP_PICTURE) ) { intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status ); }#endif p_pic->i_status = DESTROYED_PICTURE; p_vout->i_pictures--;#ifdef DEBUG_VIDEO intf_DbgMsg("picture %p\n", p_pic);#endif vlc_mutex_unlock( &p_vout->picture_lock );}/***************************************************************************** * vout_LinkPicture: increment reference counter of a picture ***************************************************************************** * This function increment the reference counter of a picture in the video * heap. It needs a lock since several producer threads can access the picture. *****************************************************************************/void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic ){ vlc_mutex_lock( &p_vout->picture_lock ); p_pic->i_refcount++;#ifdef DEBUG_VIDEO intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );#endif vlc_mutex_unlock( &p_vout->picture_lock );}/***************************************************************************** * vout_UnlinkPicture: decrement reference counter of a picture ***************************************************************************** * This function decrement the reference counter of a picture in the video heap. *****************************************************************************/void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic ){ vlc_mutex_lock( &p_vout->picture_lock ); p_pic->i_refcount--;#ifdef DEBUG_VIDEO if( p_pic->i_refcount < 0 ) { intf_DbgMsg("error: refcount < 0\n"); p_pic->i_refcount = 0; }#endif if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) ) { p_pic->i_status = DESTROYED_PICTURE; p_vout->i_pictures--; }#ifdef DEBUG_VIDEO intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );#endif vlc_mutex_unlock( &p_vout->picture_lock );}/***************************************************************************** * vout_SetBuffers: set buffers adresses ***************************************************************************** * This function is called by system drivers to set buffers video memory * adresses. *****************************************************************************/void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 ){ /* No picture previously */ p_vout->p_buffer[0].i_pic_x = 0; p_vout->p_buffer[0].i_pic_y = 0; p_vout->p_buffer[0].i_pic_width = 0; p_vout->p_buffer[0].i_pic_height = 0; p_vout->p_buffer[1].i_pic_x = 0; p_vout->p_buffer[1].i_pic_y = 0; p_vout->p_buffer[1].i_pic_width = 0; p_vout->p_buffer[1].i_pic_height = 0; /* The first area covers all the screen */ p_vout->p_buffer[0].i_areas = 1; p_vout->p_buffer[0].pi_area_begin[0] = 0; p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1; p_vout->p_buffer[1].i_areas = 1; p_vout->p_buffer[1].pi_area_begin[0] = 0; p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1; /* Set adresses */ p_vout->p_buffer[0].p_data = p_buf1; p_vout->p_buffer[1].p_data = p_buf2;}/***************************************************************************** * vout_Pixel2RGB: return red, green and blue from pixel value ***************************************************************************** * Return color values, in 0-255 range, of the decomposition of a pixel. This * is a slow routine and should only be used for initialization phase. *****************************************************************************/void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue ){ *pi_red = i_pixel & p_vout->i_red_mask; *pi_green = i_pixel & p_vout->i_green_mask; *pi_blue = i_pixel & p_vout->i_blue_mask;}/* following functions are local *//***************************************************************************** * BinaryLog: computes the base 2 log of a binary value ***************************************************************************** * This functions is used by MaskToShift, to get a bit index from a binary * value. *****************************************************************************/static int BinaryLog(u32 i){ int i_log; i_log = 0; if (i & 0xffff0000) { i_log = 16; } if (i & 0xff00ff00) { i_log += 8; } if (i & 0xf0f0f0f0) { i_log += 4; } if (i & 0xcccccccc) { i_log += 2; } if (i & 0xaaaaaaaa) { i_log++; } if (i != ((u32)1 << i_log)) { intf_ErrMsg("internal error: binary log overflow\n"); } return( i_log );}/***************************************************************************** * MaskToShift: transform a color mask into right and left shifts ***************************************************************************** * This function is used for obtaining color shifts from masks. *****************************************************************************/static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask ){ u32 i_low, i_high; /* lower hand higher bits of the mask */ /* Get bits */ i_low = i_mask & (- i_mask); /* lower bit of the mask */ i_high = i_mask + i_low; /* higher bit of the mask */ /* Transform bits into an index */ i_low = BinaryLog (i_low); i_high = BinaryLog (i_high); /* Update pointers and return */ *pi_left = i_low; *pi_right = (8 - i_high + i_low);}/***************************************************************************** * InitThread: initialize video output thread ***************************************************************************** * This function is called from RunThread and performs the second step of the * initialization. It returns 0 on success. Note that the thread's flag are not * modified inside this function. *****************************************************************************/static int InitThread( vout_thread_t *p_vout ){ /* Update status */ intf_DbgMsg("\n"); *p_vout->pi_status = THREAD_START; /* Initialize output method - this function issues its own error messages */ if( p_vout->p_sys_init( p_vout ) ) { return( 1 ); } /* Initialize convertion tables and functions */ if( vout_InitYUV( p_vout ) ) { intf_ErrMsg("error: can't allocate YUV translation tables\n"); return( 1 ); } /* Mark thread as running and return */ p_vout->b_active = 1; *p_vout->pi_status = THREAD_READY; intf_DbgMsg("thread ready\n"); return( 0 );}/***************************************************************************** * RunThread: video output thread ***************************************************************************** * Video output thread. This function does only returns when the thread is * terminated. It handles the pictures arriving in the video heap and the * display device events. *****************************************************************************/static void RunThread( vout_thread_t *p_vout){ /* XXX?? welcome to gore land */ static int i_trash_count = 0; static mtime_t last_display_date = 0; int i_index; /* index in heap */ mtime_t current_date; /* current date */ mtime_t display_date; /* display date */ boolean_t b_display; /* display flag */ picture_t * p_pic; /* picture pointer */ subpicture_t * p_subpic; /* subpicture pointer */ /* * Initialize thread */ p_vout->b_error = InitThread( p_vout ); if( p_vout->b_error ) { DestroyThread( p_vout, THREAD_ERROR ); return; } intf_DbgMsg("\n"); /* * Main loop - it is not executed if an error occured during * initialization */ while( (!p_vout->b_die) && (!p_vout->b_error) ) { /* Initialize loop variables */ p_pic = NULL; p_subpic = NULL; display_date = 0; current_date = mdate(); /* * Find the picture to display - this operation does not need lock, * since only READY_PICTUREs are handled */ for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ ) { if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) && ( (p_pic == NULL) || (p_vout->p_picture[i_index].date < display_date) ) ) { p_pic = &p_vout->p_picture[i_index]; display_date = p_pic->date; } } if( p_pic ) {#ifdef STATS /* Computes FPS rate */ p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;#endif/* XXX?? */i_trash_count++;//fprintf( stderr, "gap : %Ld\n", display_date-last_display_date );last_display_date = display_date;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -