asf.cpp 821 B

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