예제 #1
0
파일: jdmerge.c 프로젝트: Try/Tempest
h2v1_merged_upsample_565D (j_decompress_ptr cinfo,
                           JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
                           JSAMPARRAY output_buf)
{
  if (is_big_endian())
    h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
                                 output_buf);
  else
    h2v1_merged_upsample_565D_le(cinfo, input_buf, in_row_group_ctr,
                                 output_buf);
}
예제 #2
0
// same as byteval, just for double here
byte* bytevaldouble(double value) {
  static byte bits[8] = {0};
  byte* p = (byte*)&value;
  int i;
  if (is_big_endian()) {
    *(double*)bits = value;
  } else {
    for (i = 0; i < 8; ++i)
      bits[i] = p[7-i];
  }
  return bits;
}
예제 #3
0
// convert a raw integer which is read from FLV file to which endian current system fits
int intval(byte* bits, int size) {
  int i, ret = 0;
  if (bits == NULL || size < 1 || size > 4) {
    quit("invalid bits(is NULL?) or size(out of [1,4]?) when calling intval\n", 1);
  }
  if (is_big_endian()) {
      return *(int*)bits;
  }
  for (i = 0; i < size; i++)
    ret = (int)bits[i] + (ret << 8);
  return ret;
}
예제 #4
0
 ostream& operator<<(float x) {
     floatbytes bytes;
     bytes.f = x;
     if(!is_big_endian())
         std::reverse(bytes.c, bytes.c + 4);
     for(int i = 0; i < 4; i++) {
         if(!put(bytes.c[i])) {
             setstate(std::ios::failbit);
             break;
         }
     }
     return *this;
 }
예제 #5
0
// same as intval, just for double here
double doubleval(byte* bits) {
  static byte reverse_bits[8] = {0};
  int i;
  if (bits == NULL)
    quit("invalid bits(is NULL?)\n", 1);
  if (is_big_endian()) {
    *(double*)reverse_bits = *(double*)bits;
  } else {
    for(i = 0; i < 8; ++i)
      reverse_bits[i] = bits[7 - i];
  }
  return *(double*)reverse_bits;
}
예제 #6
0
파일: main.cpp 프로젝트: CCJY/coliru
int main() {
    std::cout << " host is " << (is_big_endian() ? "big endian\n" : "little endian\n");
    
    unsigned int uliteral = 0x456e7120;
    int sliteral = 0x456e7120;
    std::cout << " unsigned 0x456e7120 = " << uliteral << "\n";
    std::cout << "   signed 0x456e7120 = " << sliteral << "\n";
    
    std::stringstream sstr(std::ios::binary);
    // Write 0x456e7120 in little endian to stream
    sstr << 0x20 << 0x71 << 0x6e << 0x45 << std::flush;
    std::cout << " " << parse_uint32(std::istreambuf_iterator<char>(sstr)) << "\n";
    return 0;
}
예제 #7
0
ms::GLPixelBuffer::GLPixelBuffer(std::unique_ptr<graphics::GLContext> gl_context)
    : gl_context{std::move(gl_context)},
      tex{0}, fbo{0}, gl_pixel_format{0}, pixels_need_y_flip{false}
{
    /*
     * TODO: Handle systems that are big-endian, and therefore GL_BGRA doesn't
     * give the 0xAARRGGBB pixel format we need.
     */
    if (is_big_endian())
    {
        BOOST_THROW_EXCEPTION(std::runtime_error(
            "GLPixelBuffer doesn't support big endian architectures"));
    }
}
예제 #8
0
int main(int nargs, char** args) {
	if(nargs != 1) {
		printf("was expecting no arguments\n");
		return -1;
	}
	
	if(is_big_endian()) {
		printf("This machine is big endian\n");
	} else if(is_little_endian()) {
		printf("This machine is little endian\n");
	} else {
		printf("This machine is neither big nor little endian. There is a bug!\n");
	}
}
예제 #9
0
파일: writeinput_xdr.c 프로젝트: kouui/rh
void writeInput(void)
{
  const char routineName[] = "writeInput";

  bool_t  result=TRUE, PRD_angle_dep, XRD, big_endian;
  FILE   *fp_out;
  XDR     xdrs;

  if (!strcmp(INPUT_DOT_OUT, "none")) return;

  if ((fp_out = fopen(INPUT_DOT_OUT, "w")) == NULL) {
    sprintf(messageStr, "Unable to open output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
    return;
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  PRD_angle_dep = (input.PRD_angle_dep != PRD_ANGLE_INDEP  &&  atmos.NPRDactive > 0);
  XRD           = (input.XRD  &&  atmos.NPRDactive > 0);

  /* --- Write various input parameters to file --     -------------- */      

  result &= xdr_bool(&xdrs, &input.magneto_optical);
  result &= xdr_bool(&xdrs, &PRD_angle_dep);
  result &= xdr_bool(&xdrs, &XRD);

  result &= xdr_enum(&xdrs, (enum_t *) &input.startJ);
  result &= xdr_enum(&xdrs, (enum_t *) &input.StokesMode);

  result &= xdr_double(&xdrs, &input.metallicity);

  result &= xdr_bool(&xdrs, &input.backgr_pol);

  /* --- Write Endianness of compute architecture so that J can be
         read properly in the analysis --              -------------- */

  big_endian = is_big_endian();
  result &= xdr_bool(&xdrs, &big_endian);


  if (!result) {
    sprintf(messageStr, "Unable to write proper amount to output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
  }
  xdr_destroy(&xdrs);
  fclose(fp_out);
}
예제 #10
0
// convert an integer stored as which endian current system fits to raw in FLV file
byte* byteval(int value, int size) {
  static byte bits[4] = {0};
  byte* p = (byte*)&value;
  int i;
  if (size < 1 || size > 4) {
    quit("invalid size(out of [1,4]?) when calling byteval\n", 1);
  }
  if (is_big_endian()) {
      *(int*)bits= value;
  } else {
      for (i=0; i < 4; ++i)
        bits[i] = p[3-i];
  }
  return bits + 4 - size;
}
예제 #11
0
/*Shift one row right*/
static int state_shift_row_right(byte_t * state,int n)
{
	if(n>3 || n<0 || !state) 
		return -1;
	if(n==0) return 0;
	word_t * swt = (word_t*)state;
	word_t sw=*swt;
	if(is_big_endian()){
		*swt=ROTATE_RIGHT(sw,32,n*8); 
	}else{
		*swt=ROTATE_LEFT(sw,32,n*8);
	}		

	return 0;
}
예제 #12
0
int main()
{
  if(is_big_endian())
    printf("\nbig endian");

  else
    printf("\nlittle endian");

  show_char('C');
  show_int(-535703600);
  show_double(1.7E+308);

  printf("\n");

  return EXIT_SUCCESS;
}
예제 #13
0
static inline void encode_base256_value(unsigned char *field, size_t len, uint64_t value) {
    size_t i;
    size_t value_size = sizeof(value);
    size_t offset     = len - value_size;

    for (i=0; i<value_size; i++) {
        int from_i = is_big_endian()? i: value_size - i - 1;

        field[offset + i] = ((uint8_t *)&value)[from_i];
    }

    /*
     * Set the uppermost bit to indicate a base256-encoded size value.
     */
    field[0] |= 0x80;
}
예제 #14
0
int main(int argc, char **argv)
{
	short val;
	char *p_val;
	p_val = (char *) &val;

    p_val[0] = 0x12;
    p_val[1] = 0x34;
 
    if (!is_big_endian()) {
	    val = SWAP_BYTES(val);
    }

	printf("%x\n", val);    
	return 0;
}
예제 #15
0
void vowel_length(int socket_descriptor, lab_1_request *request) {
    vlength_response *response = (vlength_response *)malloc(sizeof(vlength_response));
    response->request_id = request->request_id;
    response->vlength = 0;

    int i;
    char *response_payload = (char *)malloc(sizeof(char) * MAX_MESSAGE_SIZE);
    memset(response_payload, 0, sizeof(char) * MAX_MESSAGE_SIZE);

    printf("Received for vowel length: %s\n", request->message);
    for(i = 0; i < request->total_message_length - 5; i++) {
        switch(request->message[i]) {        
            case 'a':
            case 'A':
            case 'e':
            case 'E':
            case 'i':
            case 'I':            
            case 'o':
            case 'O':
            case 'u':
            case 'U':
                response->vlength += 1;
                break;
            default:
                break;
        }
    }

    response->total_message_length = 6;
    int bytes_to_send = response->total_message_length;

    printf("\nSending:\n\nTotal Message Length: %d\nRequest ID: %d\nVlength: %d\n", 
            response->total_message_length, 
            response->request_id,
            response->vlength);    
    displayBuffer((char *)response, sizeof(vlength_response));

    to_network_byte_order((lab_1_request *) response);
    if(!is_big_endian()) {
        response->vlength = htons(response->vlength);
    }
   
    send(socket_descriptor, response, bytes_to_send, 0);
}
예제 #16
0
파일: csi_fun.c 프로젝트: HSID/Localization
void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status){
    if (is_big_endian()){
        csi_status->tstamp  =
            ((buf_addr[0] << 56) & 0x00000000000000ff) | ((buf_addr[1] << 48) & 0x000000000000ff00) |
            ((buf_addr[2] << 40) & 0x0000000000ff0000) | ((buf_addr[3] << 32) & 0x00000000ff000000) |
            ((buf_addr[4] << 24) & 0x000000ff00000000) | ((buf_addr[5] << 16) & 0x0000ff0000000000) |
            ((buf_addr[6] << 8)  & 0x00ff000000000000) | ((buf_addr[7])       & 0xff00000000000000) ;
        csi_status->csi_len = ((buf_addr[8] << 8) & 0xff00) | (buf_addr[9] & 0x00ff);
        csi_status->channel = ((buf_addr[10] << 8) & 0xff00) | (buf_addr[11] & 0x00ff);
        csi_status->buf_len = ((buf_addr[cnt-2] << 8) & 0xff00) | (buf_addr[cnt-1] & 0x00ff);
        csi_status->payload_len = ((buf_addr[csi_st_len] << 8) & 0xff00) |
            ((buf_addr[csi_st_len + 1]) & 0x00ff);
    }else{
        csi_status->tstamp  =
            ((buf_addr[7] << 56) & 0x00000000000000ff) | ((buf_addr[6] << 48) & 0x000000000000ff00) |
            ((buf_addr[5] << 40) & 0x0000000000ff0000) | ((buf_addr[4] << 32) & 0x00000000ff000000) |
            ((buf_addr[3] << 24) & 0x000000ff00000000) | ((buf_addr[2] << 16) & 0x0000ff0000000000) |
            ((buf_addr[1] << 8)  & 0x00ff000000000000) | ((buf_addr[0])       & 0xff00000000000000) ;
        csi_status->csi_len = ((buf_addr[9] << 8) & 0xff00) | (buf_addr[8] & 0x00ff);

        csi_status->channel = ((buf_addr[11] << 8) & 0xff00) | (buf_addr[10] & 0x00ff);

        csi_status->buf_len = ((buf_addr[cnt-1] << 8) & 0xff00) | (buf_addr[cnt-2] & 0x00ff);

        csi_status->payload_len = ((buf_addr[csi_st_len+1] << 8) & 0xff00) |
            (buf_addr[csi_st_len] & 0x00ff);
    }
    csi_status->phyerr    = buf_addr[12];
    csi_status->noise     = buf_addr[13];
    csi_status->rate      = buf_addr[14];
    csi_status->chanBW    = buf_addr[15];
    csi_status->num_tones = buf_addr[16];
    csi_status->nr        = buf_addr[17];
    csi_status->nc        = buf_addr[18];

    csi_status->rssi      = buf_addr[19];
    csi_status->rssi_0    = buf_addr[20];
    csi_status->rssi_1    = buf_addr[21];
    csi_status->rssi_2    = buf_addr[22];
}
예제 #17
0
int trace_get_item(struct trace_item *item)
{
    int n_items;

    if (trace_buf_ptr == trace_buf_end) {	/* if no more unprocessed items in the trace buffer, get new data  */
        n_items = fread(trace_buf, sizeof(struct trace_item), TRACE_BUFSIZE, trace_fd);
        if (!n_items) return 0;				/* if no more items in the file, we are done */

        trace_buf_ptr = 0;
        trace_buf_end = n_items;			/* n_items were read and placed in trace buffer */
    }
    struct trace_item* temp = &trace_buf[trace_buf_ptr];	/* read a new trace item for processing */
    *item = *temp;
    trace_buf_ptr++;

    if (is_big_endian()) {
        item->PC = my_ntohl(temp->PC);
        item->Addr = my_ntohl(temp->Addr);
    }

    return 1;
}
예제 #18
0
		reference dereference() const {
			SPRIG_ASSERT(index_ >= 0 && index_ < sizeof(data_type));
			return *(reinterpret_cast<byte_ptr_type>(ptr_) + (is_big_endian() ? index_ : sizeof(data_type) - 1 - index_));
		}
예제 #19
0
int main()
{
  printf ("%d\n", Endianness() );
  printf ("%d\n", is_big_endian() );
}
예제 #20
0
파일: puretext.c 프로젝트: nanu-c/LiVES
weed_plant_t *weed_setup(weed_bootstrap_f weed_boot) {
  weed_plant_t *plugin_info=weed_plugin_info_init(weed_boot,num_versions,api_versions);

  if (plugin_info!=NULL) {
    weed_plant_t *in_params[P_END+1],*gui;
    weed_plant_t *filter_class;
    PangoContext *ctx;

    const char *modes[]= {"Spiral text","Spinning letters","Letter starfield","Word coalesce",NULL};
    char *rfx_strings[]= {"special|fileread|0|"};

    char *deftextfile;

    int palette_list[2];
    weed_plant_t *in_chantmpls[2];
    weed_plant_t *out_chantmpls[2];

    int flags,error;

    if (is_big_endian())
      palette_list[0]=WEED_PALETTE_ARGB32;
    else
      palette_list[0]=WEED_PALETTE_BGRA32;

    palette_list[1]=WEED_PALETTE_END;

    in_chantmpls[0]=weed_channel_template_init("in channel 0",0,palette_list);
    in_chantmpls[1]=NULL;

    out_chantmpls[0]=weed_channel_template_init("out channel 0",WEED_CHANNEL_CAN_DO_INPLACE,palette_list);
    out_chantmpls[1]=NULL;

    init_unal();


    // this section contains code
    // for configure fonts available
    num_fonts_available = 0;
    fonts_available = NULL;

    ctx = gdk_pango_context_get();
    if (ctx) {
      PangoFontMap *pfm = pango_context_get_font_map(ctx);
      if (pfm) {
        int num = 0;
        PangoFontFamily **pff = NULL;
        pango_font_map_list_families(pfm, &pff, &num);
        if (num > 0) {
          // we should reserve num+1 for a final NULL pointer
          fonts_available = (char **)weed_malloc((num+1)*sizeof(char *));
          if (fonts_available) {
            register int i;
            num_fonts_available = num;
            for (i = 0; i < num; ++i) {
              fonts_available[i] = strdup(pango_font_family_get_name(pff[i]));
            }
            // don't forget this thing
            fonts_available[num] = NULL;
          }
        }
        g_free(pff);
      }
      g_object_unref(ctx);
    }

    deftextfile=g_build_filename(g_get_home_dir(), "livestext.txt", NULL);

    in_params[P_TEXT]=weed_text_init("textfile","_Text file",deftextfile);
    gui=weed_parameter_template_get_gui(in_params[P_TEXT]);
    weed_set_int_value(gui,"maxchars",80); // for display only - fileread will override this
    flags=0;
    if (weed_plant_has_leaf(in_params[P_TEXT],"flags"))
      flags=weed_get_int_value(in_params[P_TEXT],"flags",&error);
    flags|=WEED_PARAMETER_REINIT_ON_VALUE_CHANGE;
    weed_set_int_value(in_params[P_TEXT],"flags",flags);

    in_params[P_MODE]=weed_string_list_init("mode","Effect _mode",0,modes);
    flags=0;
    if (weed_plant_has_leaf(in_params[P_MODE],"flags"))
      flags=weed_get_int_value(in_params[P_MODE],"flags",&error);
    flags|=WEED_PARAMETER_REINIT_ON_VALUE_CHANGE;
    weed_set_int_value(in_params[P_MODE],"flags",flags);
    in_params[P_END]=NULL;

    g_free(deftextfile);

    filter_class=weed_filter_class_init("puretext","Salsaman & Aleksej Penkov",1,0,&puretext_init,&puretext_process,NULL,
                                        in_chantmpls,out_chantmpls,in_params,NULL);

    gui=weed_filter_class_get_gui(filter_class);
    weed_set_string_value(gui,"layout_scheme","RFX");
    weed_set_string_value(gui,"rfx_delim","|");
    weed_set_string_array(gui,"rfx_strings",1,rfx_strings);

    weed_plugin_info_add_filter_class(plugin_info,filter_class);

    weed_set_int_value(plugin_info,"version",package_version);

  }

  return plugin_info;
}
예제 #21
0
static void decode_ex_CosNaming_NamingContext_NotFound(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_) {

    gboolean stream_is_big_endian;          /* big endianess */

    
    /* Operation specific Variable declarations Begin */

    guint32   u_octet4;
    guint32   u_octet4_loop_NotFound_rest_of_name;
    guint32   i_NotFound_rest_of_name;
    
    /* Operation specific Variable declarations End */

    
    stream_is_big_endian = is_big_endian(header);  /* get stream endianess */


    
    u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
    if (tree) {
       proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u (%s)",u_octet4,val_to_str(u_octet4,CosNaming_NamingContext_NotFoundReason,"Unknown Enum Value"));
    }

    u_octet4_loop_NotFound_rest_of_name = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
    if (tree) {
       proto_tree_add_text(tree,tvb,*offset-4, 4 ,"Seq length of NotFound_rest_of_name = %u",u_octet4_loop_NotFound_rest_of_name);
    }

    for (i_NotFound_rest_of_name=0; i_NotFound_rest_of_name < u_octet4_loop_NotFound_rest_of_name; i_NotFound_rest_of_name++) {
예제 #22
0
TEST(ConvertEndian, CheckEndian)
{
    EXPECT_TRUE(is_big_endian() == sak::host_endian::big_endian);
}
예제 #23
0
파일: wavsum.c 프로젝트: MaxGabriel/yblog
int main(int argc, char *argv[]) {
    char *filename=argv[1];
    FILE *wav = fopen(filename,"rb");
    struct wavfile header;

    if ( wav == NULL ) {
        fprintf(stderr,"Can't open input file %s\n", filename);
        exit(1);
    }


    // read header
    if ( fread(&header,sizeof(header),1,wav) < 1 ) {
        fprintf(stderr,"Can't read input file header %s\n", filename);
        exit(1);
    }

    // if wav file isn't the same endianness than the current environment
    // we quit
    if ( is_big_endian() ) {
        if (   memcmp( header.id,"RIFX", 4) != 0 ) {
            fprintf(stderr,"ERROR: %s is not a big endian wav file\n", filename); 
            exit(1);
        }
    } else {
        if (   memcmp( header.id,"RIFF", 4) != 0 ) {
            fprintf(stderr,"ERROR: %s is not a little endian wav file\n", filename); 
            exit(1);
        }
    }

    if (   memcmp( header.wavefmt, "WAVEfmt ", 8) != 0 
        || memcmp( header.data, "data", 4) != 0 
            ) {
        fprintf(stderr,"ERROR: Not wav format\n"); 
        exit(1); 
    }
    if (header.format != 16) {
        fprintf(stderr,"\nERROR: not 16 bit wav format.");
        exit(1);
    }
    fprintf(stderr,"format: %d bits", header.format);
    if (header.format == 16) {
        fprintf(stderr,", PCM");
    } else {
        fprintf(stderr,", not PCM (%d)", header.format);
    }
    if (header.pcm == 1) {
        fprintf(stderr, " uncompressed" );
    } else {
        fprintf(stderr, " compressed" );
    }
    fprintf(stderr,", channel %d", header.pcm);
    fprintf(stderr,", freq %d", header.frequency );
    fprintf(stderr,", %d bytes per sec", header.bytes_per_second );
    fprintf(stderr,", %d bytes by capture", header.bytes_by_capture );
    fprintf(stderr,", %d bits per sample", header.bytes_by_capture );
    fprintf(stderr,"\n" );

    if ( memcmp( header.data, "data", 4) != 0 ) { 
        fprintf(stderr,"ERROR: Prrroblem?\n"); 
        exit(1); 
    }
    fprintf(stderr,"wav format\n");

    // read data
    long long sum=0;
    int16_t value;
    int i=0;
    fprintf(stderr,"---\n", value);
    while( fread(&value,sizeof(value),1,wav) ) {
        if (value<0) { value=-value; }
        sum += value;
    }
    printf("%lld\n",sum);
    exit(0);
}
예제 #24
0
//------------------------------------------------------------------------------
//
// Get the endianness of the machine
//
//------------------------------------------------------------------------------
std::string endianness()
{
  return (is_big_endian() ? "BigEndian" : "LittleEndian");
}
예제 #25
0
/**
TIFF_ifd*  get_tiff_ifd(unsigned char* buf, int num)

TIFF形式のデータから num番目の IFDデータを取り出す.

@param  buf  TIFFデータの格納された Buffer型変数
@param  num  何番目の IFDデータを取り出すか?

@return IFDデータ (ifd)
@retval ifd->tga==0 is header
@retval ifd->type  is seq number of this image (num)
@retval ifd->count is number of IFDs in this image
@retval ifd->value is next image IFD offset. if this is 0, next image does not exist
*/
TIFF_ifd*  get_tiff_ifd(unsigned char* buf, int num)
{
	TIFF_ifd* ifd = NULL;
	int  i, k;


	// Endian
	if (buf[0]=='I' && buf[1]=='I') {
		if (is_big_endian()) TIFF_Swap_Flag = TRUE;
	}
	else if (buf[0]=='M' && buf[1]=='M') {
		if (is_little_endian()) TIFF_Swap_Flag = TRUE;
	}
	else {
		return NULL;
	}

	unsigned char* ptr = buf + 2;
	short version = *((short*)ptr);
	if (TIFF_Swap_Flag) version = swaps(version);
	if (version!=42) {
		return NULL;
	}

	ptr += 2;
	unsigned int offset = *((unsigned int*)ptr);
	if (TIFF_Swap_Flag) offset = swapl(offset);


	if (num<0) num = 1;
	k = 0;
	while (k!=num && offset!=0) {
		k++;
		ptr = buf + offset;
		short nn = *((short*)ptr);
		if (TIFF_Swap_Flag) nn = swaps(nn);
		ptr += 2;

		if (k==num) {
			ifd = (TIFF_ifd*)malloc(sizeof(TIFF_ifd)*(nn+1));
			if (ifd==NULL) {
				return NULL;
			}

			memset(&ifd[0], 0, 12);
			ifd[0].type  = num;
			ifd[0].count = nn;

			for (i=1; i<=nn; i++) {
				if (k==num) {
					memcpy(&ifd[i], ptr, 12);
					if (TIFF_Swap_Flag) {
						ifd[i].tag   = swaps(ifd[i].tag);
						ifd[i].type  = swaps(ifd[i].type);
						ifd[i].count = swapl(ifd[i].count);
						ifd[i].value = swapl(ifd[i].value);
					}
					ifd[i].ex_value = NULL;
				}
				ptr += 12;
			}
		}
		else {
			for (i=0; i<nn; i++) ptr += 12;
		}

		offset = *((unsigned int*)ptr);
		if (TIFF_Swap_Flag) offset = swapl(offset);
	}

	if (ifd!=NULL) ifd[0].value = offset;
	return ifd;
}
예제 #26
0
  void decode_frame(unsigned int frame_number,
                    uint_32* framebuffer,
                    int width, int height)
  {
    assert(av_fc != 0);

    double wanted_timestamp = m_start_time + ((double) frame_number) / m_fps;

    double frame_duration = 1.0 / m_fps;
    
    // do we have to seek?
    if (fabs(wanted_timestamp - m_current_timestamp) >= 0.98*frame_duration)
      {
#if defined FFMPEGDRIVER_PRINT_DEBUG
        std::cout << "Need to seek: wanted_timestamp =" << wanted_timestamp
                  << "s - m_current_timestamp = " << m_current_timestamp
                  << "s (frame_duration = " << frame_duration << "s)\n";

        std::cout << "seeking to frame " << frame_number 
                  << ", time " << wanted_timestamp << "s\n";
#endif

        // first seek to the nearest keyframe before wanted_timestamp
        int ret = seek_to_second(av_fc, video_stream_index, wanted_timestamp);

        if (ret < 0)
          {
            std::cerr << "Could not seek\n";
          }
      }
#if defined FFMPEGDRIVER_PRINT_DEBUG
    else
      {
        std::cout << "No need to seek: wanted_timestamp =" << wanted_timestamp
                  << "s - m_current_timestamp = " << m_current_timestamp
                  << "s (frame_duration = " << frame_duration
                  << "s, diff = "
                  << fabs(wanted_timestamp - m_current_timestamp) << "s)\n";
      }
#endif

    AVPacket pkt;
    pkt.stream_index = -1;
    pkt.data = 0;

    int ret = decode_to_timestamp(av_fc, video_stream_index, wanted_timestamp,
                                  m_fps, &pkt, m_frame, &m_current_timestamp);

    if (ret < 0)
      {
        throw std::runtime_error("Could not decode");
      }

    m_current_timestamp += frame_duration;

    av_free_packet(&pkt);

#if defined FFMPEGDRIVER_PRINT_DEBUG
    std::cout << "-> got frame\n";
#endif
    int dst_pix_fmt = PIX_FMT_RGBA32;
    AVPicture pict;

    AVStream* video_stream = av_fc->streams[video_stream_index];

    int cwidth  = video_stream->codec->width;
    int cheight = video_stream->codec->height;

    if (video_stream->codec->width == width &&
        video_stream->codec->height == height)
      {
        pict.data[0] = (uint_8*) framebuffer;
      }
    else
      {
        int size = cwidth*cheight*4;
        if (m_scale_buf == 0 || m_scale_buf_size < size)
          {
            if (m_scale_buf)
              delete[] m_scale_buf;
            
            m_scale_buf = new uint_8[size];
            m_scale_buf_size = size;
          }
        pict.data[0] = m_scale_buf;
      }

    pict.data[1] = pict.data[2] = pict.data[0];
    pict.linesize[0] = cwidth*4;
    pict.linesize[1] = pict.linesize[2] = 0;
    
    img_convert(&pict, dst_pix_fmt,
                (AVPicture *) m_frame,
                video_stream->codec->pix_fmt,
                video_stream->codec->width,
                video_stream->codec->height);
    
    if (cwidth != width || cheight != height)
      {
        ls_scale32(framebuffer, width, height,
                   reinterpret_cast<const uint_32*>(pict.data[0]),
                   cwidth, cheight);
      }
    else
      {
        if (m_scale_buf)
          {
            delete[] m_scale_buf;
            m_scale_buf = 0;
            m_scale_buf_size = 0;
          }
      }

    // Correct byte order on big endian machines (using the
    // correct pixel format crashes in img_convert).
    if (is_big_endian())
      {
	std::for_each(framebuffer, framebuffer + width*height,
		      switch_byteorder);
      }
  }
예제 #27
0
int main(int argc, char *argv[])
{

    int sockfd, numbytes;  
    struct addrinfo hints, *servinfo, *p;
    int rv;
    char s[INET6_ADDRSTRLEN];

    //client servername PortNumber Operation String
    if (argc != 5) {
        fprintf(stderr,"usage: client servername PortNumber Operation String\n");
        exit(1);
    }

    
    const int SERVER_NAME = 1;
    const int PORT_NUMBER = 2;
    const int OPERATION = 3;
    const int MESSAGE_INDEX = 4;

    //char* server_name = argv[SERVER_NAME];
    char* server_name = (char *)malloc(strlen(argv[SERVER_NAME]));
    memcpy(server_name, argv[SERVER_NAME], strlen(argv[SERVER_NAME]));
    printf("\nServer name: %s\n", server_name);

    char* port_number = (char *)malloc(strlen(argv[PORT_NUMBER]));
    memcpy(port_number, argv[PORT_NUMBER], strlen(argv[PORT_NUMBER]));
    printf("Port number: %s\n", port_number);

    char* operation = (char *)malloc(strlen(argv[OPERATION]));
    memcpy(operation, argv[OPERATION], strlen(argv[OPERATION]));
    printf("Operation: %s\n", operation);

    char* message = (char *)malloc(strlen(argv[MESSAGE_INDEX]));
    memcpy(message, argv[MESSAGE_INDEX], strlen(argv[MESSAGE_INDEX]));
    printf("String: %s\n", message);
    //displayBuffer(message, strlen(message));

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if ((rv = getaddrinfo(server_name, port_number, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    // loop through all the results and connect to the first we can
    for(p = servinfo; p != NULL; p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }

        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }

        break;
    }

    if (p == NULL) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }

    inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
            s, sizeof s);
    printf("client: connecting to %s\n", s);

    freeaddrinfo(servinfo); // all done with this structure

    lab_1_request *request = (lab_1_request *)malloc(sizeof(lab_1_request));
    memcpy(request->message, message, strlen(message));
    request->request_id = 1;
    request->operation = atoi(operation);
    request->total_message_length = 5 + strlen(request->message);

    int bytes_to_send = request->total_message_length;
    to_network_byte_order(request);

    clock_t begin, end;
    double time_spent = 0;

    begin = clock();
    /* here, do your time-consuming job */
    
    if(send(sockfd, request, bytes_to_send, 0) == -1) {
        perror("send");
    }

    if(request->operation == VLENGTH_REQUEST) {
        vlength_response *response = (vlength_response *)malloc(sizeof(vlength_response));

        if ((numbytes = recv(sockfd, response, sizeof(vlength_response), 0)) == -1) {
            perror("recv");
            exit(1);
        }

        end = clock();
        time_spent = (double)(end - begin) / CLOCKS_PER_SEC;


	    displayBuffer((char *)response, numbytes);

        to_host_byte_order((lab_1_request *) response);
        if(!is_big_endian()) {
            response->vlength = ntohs(response->vlength);
        }

        printf("client: Total round trip '%f' seconds\n", time_spent);
	    printf("client: message length '%d'\n", response->total_message_length);
	    printf("client: request ID '%d'\n", response->request_id);
        printf("client: received vlength '%d'\n\n", response->vlength);

    } else if (request->operation == VOWEL_REMOVAL_REQUEST) {
        disemvowel_response *response = (disemvowel_response *)malloc(sizeof(disemvowel_response));
        memset(response, 0, MAX_MESSAGE_SIZE);

        if ((numbytes = recv(sockfd, response, sizeof(disemvowel_response), 0)) == -1) {
            perror("recv");
            exit(1);
        }

        end = clock();
        time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

        to_host_byte_order((lab_1_request *) response);

	    displayBuffer((char *)response, numbytes);
        printf("client: Total round trip '%f' seconds\n", time_spent);
	    printf("client: message length '%d'\n", response->total_message_length);
	    printf("client: request ID '%d'\n", response->request_id);
        printf("client: received message '%s'\n\n", response->message);

    }

    close(sockfd);

    return 0;
}
예제 #28
0
int main(int argc, char const *argv[])
{
	printf("%d\n", is_big_endian());
	return 0;
}
예제 #29
0
파일: tospdif.c 프로젝트: IAPark/vlc
static void write_buffer( filter_t *p_filter, block_t *p_in_buf )
{
    write_data( p_filter, p_in_buf->p_buffer, p_in_buf->i_buffer,
                is_big_endian( p_filter, p_in_buf ) );
    p_filter->p_sys->p_out_buf->i_length += p_in_buf->i_length;
}
예제 #30
0
/**
 * \brief Load ELF32 binary image into memory
 *
 * This function loads an ELF32 binary image, based at 'base' and of size
 * 'size' into the memory provided by 'allocate'
 *
 * \param em_machine    ELF machine type.
 * \param allocate      Memory allocation function.
 * \param state         Pointer to state for allocation function.
 * \param base          Base address of ELF32 binary image in memory.
 * \param size          Size of ELF32 binary image in bytes.
 * \param retentry      Used to return entry point address
 * \param ret_tlsbase   Used to return TLS block base address
 * \param ret_tlsinitlen Used to return length of initialised TLS data block
 * \param ret_tlstotallen Used to return total length of TLS data
 */
errval_t elf32_load(uint16_t em_machine, elf_allocator_fn allocate_func,
                    void *state, lvaddr_t base, size_t size,
                    genvaddr_t *retentry,
                    genvaddr_t *ret_tlsbase, size_t *ret_tlsinitlen,
                    size_t *ret_tlstotallen)
{
    struct Elf32_Ehdr *head = (struct Elf32_Ehdr *)base;
    errval_t err;
    int i;

    // Check for valid file size
    if (size < sizeof(struct Elf32_Ehdr)) {
        return ELF_ERR_FILESZ;
    }

    // Stage 1: Check for compatible ELF32 header: check endianess
    if(is_big_endian() && head->e_ident[EI_DATA] != ELFDATA2MSB){
        return ELF_ERR_HEADER;
    } else if(!is_big_endian() && head->e_ident[EI_DATA] != ELFDATA2LSB){
        return ELF_ERR_HEADER;
    }

    // Stage 2: Check for compatible ELF32 header
    if (!IS_ELF(*head)
        || head->e_ident[EI_CLASS] != ELFCLASS32
//        || head->e_ident[EI_DATA] != ELFDATA2MSB   //Enhanced with a function to check machine endianess
        || head->e_ident[EI_VERSION] != EV_CURRENT
        || head->e_ident[EI_OSABI] != ELFOSABI_SYSV
        || head->e_ident[EI_ABIVERSION] != 0
        || (head->e_type != ET_EXEC && head->e_type != ET_DYN)
        || head->e_machine != em_machine
        || head->e_version != EV_CURRENT) {
        return ELF_ERR_HEADER;
    }

    // More sanity checks
    if (head->e_phoff + head->e_phentsize * head->e_phnum > size
        || head->e_phentsize != sizeof(struct Elf32_Phdr)) {
        return ELF_ERR_PROGHDR;
    }

    struct Elf32_Shdr *shead =
        (struct Elf32_Shdr *)(base + (uintptr_t)head->e_shoff);
    struct Elf32_Shdr *rela =
        elf32_find_section_header_type(shead, head->e_shnum, SHT_REL);
    struct Elf32_Shdr *symtab =
        elf32_find_section_header_type(shead, head->e_shnum, SHT_SYMTAB);

    size_t rela_size = rela ? rela->sh_size : 0, new_rela_size = 0;
    struct Elf32_Shdr *new_rela = NULL;

    // Find dynamic program header, if any
    struct Elf32_Phdr *phead =
        (struct Elf32_Phdr *)(base + (uintptr_t)head->e_phoff);
    for (i = 0; i < head->e_phnum; i++) {
        struct Elf32_Phdr *p = &phead[i];

        if (p->p_type == PT_DYNAMIC) {
            struct Elf32_Dyn *dynamic = (void *)(base + (uintptr_t)p->p_offset);
            int n_dynamic = p->p_filesz / sizeof(struct Elf32_Dyn);
            for (int j = 0; j < n_dynamic; j++) {
                switch (dynamic[j].d_tag) {
                case DT_RELA:
                    // virtual address of relocations, look for matching section
                    new_rela =
                        elf32_find_section_header_vaddr(shead, head->e_shnum,
                                                        dynamic[j].d_un.d_val);
                    break;

                case DT_RELASZ:
                    // store size of relocations, as they may cover more than
                    // one section
                    new_rela_size = dynamic[j].d_un.d_val;
                    break;

                case DT_SYMTAB:
                    // virtual address of symtab, look for matching section
                    symtab =
                        elf32_find_section_header_vaddr(shead, head->e_shnum,
                                                        dynamic[j].d_un.d_val);
                    break;

                case DT_SYMENT:
                    assert(dynamic[j].d_un.d_val == sizeof(struct Elf32_Sym));
                    break;
                }
            }

            if (new_rela != NULL) {
                assert(new_rela_size != 0);
                rela = new_rela;
                rela_size = new_rela_size;
            }
            break;
        }
    }

    genvaddr_t tls_base = 0;
    size_t tls_init_len = 0, tls_total_len = 0;

    // Process program headers to load file
    for (i = 0; i < head->e_phnum; i++) {
        struct Elf32_Phdr *p = &phead[i];

        if (p->p_type == PT_LOAD) {
            // Map segment in user-space memory
            void *dest = NULL;
            err = allocate_func(state, p->p_vaddr, p->p_memsz, p->p_flags, &dest);
            if (err_is_fail(err)) {
                return err_push(err, ELF_ERR_ALLOCATE);
            }
            assert(dest != NULL);

            // Copy file segment into memory
            memcpy(dest, (void *)(base + (uintptr_t)p->p_offset), p->p_filesz);

            // Initialize rest of memory segment (ie. BSS) with all zeroes
            memset((char *)dest + p->p_filesz, 0, p->p_memsz - p->p_filesz);

            // Apply relocations
            if (rela != NULL && symtab != NULL) {
                elf32_relocate(p->p_vaddr, p->p_vaddr,
                               (struct Elf32_Rel *)
                               (base + (uintptr_t)rela->sh_offset),
                               rela_size,
                               (struct Elf32_Sym *)
                               (base + (uintptr_t)symtab->sh_offset),
                               symtab->sh_size, p->p_vaddr, dest);
            }
        } else if (p->p_type == PT_TLS) {
            assert(p->p_vaddr != 0);
            assert(tls_base == 0); // if not we have multiple TLS sections!
            tls_base = p->p_vaddr;
            tls_init_len = p->p_filesz;
            tls_total_len = p->p_memsz;
        }
    }

    if (retentry != NULL) {
        *retentry = head->e_entry;
    }

    if (ret_tlsbase != NULL) {
        *ret_tlsbase = tls_base;
    }

    if (ret_tlsinitlen != NULL) {
        *ret_tlsinitlen = tls_init_len;
    }

    if (ret_tlstotallen != NULL) {
        *ret_tlstotallen = tls_total_len;
    }

    return SYS_ERR_OK;
}