1
0

FLVHeader.cpp 816 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "FLVHeader.h"
  2. #include "FLVUtil.h"
  3. /*
  4. (c) 2006 Nullsoft, Inc.
  5. Author: Ben Allison [email protected]
  6. */
  7. #define FLV_BITMASK_AUDIO 0x4
  8. #define FLV_BITMASK_VIDEO 0x1
  9. /*
  10. FLV Header spec
  11. Signature - uint8[3] - must equal "FLV"
  12. Version - uint8 - only known version is 1
  13. Flags - uint8 - bitmask, 4 is audio, 1 is video
  14. Offset - uint32 - total size of header (9), big endian
  15. */
  16. bool FLVHeader::Read(uint8_t *data, size_t size)
  17. {
  18. if (size < 9)
  19. return false; // too small to be an FLV header
  20. if (data[0] != 'F' || data[1] != 'L' || data[2] != 'V')
  21. return false; // invalid signature
  22. version = data[3];
  23. hasAudio = !!(data[4] & FLV_BITMASK_AUDIO);
  24. hasVideo = data[4] & FLV_BITMASK_VIDEO;
  25. headerSize = FLV::Read32(&data[5]);
  26. if (headerSize != 9)
  27. return false;
  28. return true;
  29. }