view xv_ext_test.c @ 3:8d7d1680db7d

style(9) mostly with indent -nbad -nfbs -br -ci4 -nfc1 -l80 -nlp
author darius
date Tue, 04 Jan 2005 05:20:58 +0000
parents 769b155a34f9
children
line wrap: on
line source

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/extensions/Xvlib.h>

char *XvAdaptorTypeMaskToString( int mask )
{
  static char buf[160];

  buf[0] = '\0';
  if ( mask & XvInputMask  )  sprintf( buf+strlen(buf), "XvInputMask, " );
  if ( mask & XvOutputMask )  sprintf( buf+strlen(buf), "XvOutputMask, " );
  if ( mask & XvVideoMask  )  sprintf( buf+strlen(buf), "XvVideoMask, " );
  if ( mask & XvStillMask  )  sprintf( buf+strlen(buf), "XvStillMask, " );
  if ( mask & XvImageMask  )  sprintf( buf+strlen(buf), "XvImageMask, " );

  if ( buf[0] )
    buf[ strlen(buf)-2 ] = '\0';
  return buf;
}

int main()
{
  Display *display;
  XvImageFormatValues *formats;
  XvAdaptorInfo *adaptors;
  int            num_adaptors, num_formats;
  int            i,j;
  unsigned int   xv_version, xv_release, xv_request_base,
                 xv_event_base, xv_error_base;

  display = XOpenDisplay(NULL);

  /*  XvQueryVersion  */
  if ( XvQueryExtension( display, 
                         &xv_version, &xv_release, &xv_request_base,
                         &xv_event_base, &xv_error_base ) != Success ) {
    fprintf( stderr, "XvQueryExtension failed\n" );
    exit(1);
  }
  printf( "\nXvQueryExtension():\n" );
  printf( "  version = %d, release = %d, request_base = %d,\n",
          xv_version, xv_release, xv_request_base );
  printf( "  event_base = %d, error_base = %d\n",
          xv_event_base, xv_error_base );

  /*  XvQueryAdaptors  */
  XvQueryAdaptors( display, DefaultRootWindow(display), &num_adaptors, 
                   &adaptors);

  printf( "\nXvQueryAdaptors():\n" );
  for ( i = 0; i < num_adaptors; i++ ) {
    printf( "  Adaptor %2d:\n", i );
    printf( "    base_id      = %ld\n", adaptors[i].base_id );
    printf( "    num_ports    = %ld\n", adaptors[i].num_ports );
    printf( "    type         = %d (%s)\n", 
            adaptors[i].type, 
            XvAdaptorTypeMaskToString( adaptors[i].type ) );
    printf( "    name         = %s\n", adaptors[i].name );
    printf( "    num_adaptors = %ld\n", adaptors[i].num_adaptors);
    printf( "    num_formats  = %ld\n", adaptors[i].num_formats);
    printf( "    formats      =\n" );

    for ( j = 0; j < adaptors[i].num_formats; j++ )
      printf( "      Format %2d:  depth = %.2d, visual_id = 0x%.2lx\n", 
              j, 
              adaptors[i].formats[j].depth, 
              adaptors[i].formats[j].visual_id );
  }

  /*  XvListImageFormats  */
  printf( "\nXvListImageFormats():\n" );
  for ( i = 0; i < num_adaptors; i++ ) {
    printf( "  Adaptor %2d:\n", i );
    formats = XvListImageFormats( display, adaptors[i].base_id, 
                                  &num_formats );
    printf( "    num_formats = %d\n", num_formats );
    for ( j = 0; j < num_formats; j++ ) {
      printf( "    Format %2d:\n", j );
      printf( "      id                = %d\n", formats[j].id               );
      printf( "      type              = %d (%s)\n", formats[j].type,
              formats[j].type == XvRGB ? "XvRGB" : "XvYUV" );
      printf( "      byte_order        = %d (%s)\n", 
              formats[j].byte_order,
              formats[j].byte_order == LSBFirst ? "LSBFirst" : "MSBFirst" );
      printf( "      guid              = %.4s\n", formats[j].guid           );
      printf( "      bits_per_pixel    = %d\n", formats[j].bits_per_pixel   );
      printf( "      format            = %d (%s)\n", formats[j].format,
              formats[j].format == XvPacked ? "XvPacked" : "XvPlanar" );
      printf( "      num_planes        = %d\n", formats[j].num_planes       );

      if ( formats[j].type == XvRGB ) {
        printf( "      depth             = %d\n", formats[j].depth          );
        printf( "      red_mask          = %x\n", formats[j].red_mask       );
        printf( "      green_mask        = %x\n", formats[j].green_mask     );
        printf( "      blue_mask         = %x\n", formats[j].blue_mask      );
      }
      if ( formats[j].type == XvYUV ) {
        printf( "      sample_bits (yuv) = ( %d, %d, %d )\n",
                formats[j].y_sample_bits, 
                formats[j].u_sample_bits, 
                formats[j].v_sample_bits );
        printf( "      horz_period (yuv) = ( %d, %d, %d )\n", 
                formats[j].horz_y_period,
                formats[j].horz_u_period,
                formats[j].horz_v_period );
        printf( "      vert_period       = ( %d, %d, %d )\n", 
                formats[j].vert_y_period,
                formats[j].vert_u_period,
                formats[j].vert_v_period );
        printf( "      component_order = %.32s\n", 
                formats[j].component_order );
        printf( "      scanline_order  = %d\n", formats[j].scanline_order   );
      }
    }
  }

  XvFreeAdaptorInfo( adaptors );
  return(0);
}