asf.cpp 841 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "stdafx.h"
  2. #include "asf.h"
  3. #include <string.h>
  4. uint64_t get_asf_headsize(void* pbuffer, int ilen)
  5. {
  6. uint64_t uret = 0;
  7. if (ASF_HEADER_SIZE_LEN != ilen || NULL == pbuffer){
  8. return uret;
  9. }
  10. uint32_t ulowbit = 0;
  11. uint32_t uhighbit = 0;
  12. memcpy(&ulowbit, pbuffer, sizeof(uint32_t));
  13. memcpy(&uhighbit, (char*)pbuffer + sizeof(uint32_t), sizeof(uint32_t));
  14. return (ulowbit + (uhighbit << 32));
  15. }
  16. int construct_asf_headsize(char* pbuffer, int ilen, uint64_t usize)
  17. {
  18. int iret = -1;
  19. if (ASF_HEADER_SIZE_LEN > ilen || NULL == pbuffer){
  20. return iret;
  21. }
  22. uint32_t uhighbits = (usize >> 32);
  23. uint32_t ulowbits = usize;
  24. if (uhighbits > 0){
  25. ulowbits = usize - (uhighbits<<32);
  26. }
  27. memcpy(pbuffer, &ulowbits, sizeof(uint32_t));
  28. memcpy(pbuffer+sizeof(uint32_t), &uhighbits, sizeof(uint32_t));
  29. iret = 0;
  30. return iret;
  31. }