uvox2Common.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #ifndef uvox2Common_H_
  3. #define uvox2Common_H_
  4. #include "unicode/uniString.h"
  5. std::string XTEA_encipher(const __uint8* c_data, const size_t c_data_cnt, const __uint8* c_key, const size_t c_key_cnt) throw();
  6. uniString::utf8 XTEA_decipher(const __uint8* c_data, const size_t c_data_cnt, const __uint8* c_key, const size_t c_key_cnt) throw();
  7. #pragma pack(push,1)
  8. struct uv2xHdr
  9. { // uvox2 message
  10. __uint8 sync;
  11. __uint8 qos;
  12. __uint16 msgType;
  13. __uint16 msgLen;
  14. };
  15. struct uv2xMetadataHdr
  16. { /* uvox 2 metadata header */
  17. __uint16 id; /* ID (cookie) identifying a metadata package */
  18. __uint16 span; /* Span of messages in the metadata package being assembled */
  19. __uint16 index;/* Index of the message in the metadata package being assembled */
  20. };
  21. #pragma pack(pop)
  22. static const int MAX_MESSAGE_SIZE = (16 * 1024);
  23. static const int MAX_CIPHER_KEY_SIZE = 256;
  24. static const char UV2X_EOM = 0;
  25. static const int UV2X_HDR_SIZE = sizeof(uv2xHdr);
  26. static const int UV2X_OVERHEAD = (UV2X_HDR_SIZE + 1); /* header+end_of_msg */
  27. static const int UV2X_META_HDR_SIZE = sizeof(uv2xMetadataHdr);
  28. static const int MAX_PAYLOAD_SIZE = MAX_MESSAGE_SIZE - UV2X_OVERHEAD;
  29. #define UVOX2_SYNC_BYTE 0X5A
  30. static const int MSG_AUTH = 0x1001;
  31. static const int MSG_BROADCAST_SETUP = 0x1002;
  32. static const int MSG_NEGOTIATE_BUFFER_SIZE = 0x1003;
  33. static const int MSG_STANDBY = 0x1004;
  34. static const int MSG_TERMINATE = 0x1005;
  35. static const int MSG_FLUSH_CACHED_METADATA = 0x1006;
  36. static const int MSG_LISTENER_AUTHENTICATION= 0x1007;
  37. static const int MSG_MAX_PAYLOAD_SIZE = 0x1008;
  38. static const int MSG_CIPHER = 0x1009; // cipher request for uvox 2.1
  39. static const int MSG_MIME_TYPE = 0x1040;
  40. static const int MSG_FILE_TRANSFER_BEGIN = 0x1050;
  41. static const int MSG_FILE_TRANSFER_DATA = 0x1051;
  42. static const int MSG_BROADCAST_INTERRUPTION = 0x2001;
  43. static const int MSG_BROADCAST_TERMINATE = 0x2002;
  44. static const int MSG_ICYNAME = 0x1100;
  45. static const int MSG_ICYGENRE = 0x1101;
  46. static const int MSG_ICYURL = 0x1102;
  47. static const int MSG_ICYPUB = 0x1103;
  48. static const int MSG_METADATA_CONTENTINFO = 0x3000;
  49. static const int MSG_METADATA_URL = 0x3001;
  50. //static const int MSG_METADATA_XML = 0x3901;
  51. static const int MSG_METADATA_XML_NEW = 0x3902;
  52. // only id the start of the album art type as it's variable
  53. static const int MSG_METADATA_ALBUMART = 0x4000;
  54. static const int MSG_METADATA_STATION_ART = 0x0000;
  55. static const int MSG_METADATA_PLAYING_ART = 0x0100;
  56. /*
  57. 0x4 0x0xx Station logo
  58. 0x4 0x1xx Album art
  59. 00 = image/jpeg
  60. 01 = image/png
  61. 02 = image/bmp
  62. 03 = image/gif
  63. */
  64. static const int MSG_METADATA_TIMEREMAINING = 0x5001;
  65. static const int MP3_DATA = 0x7000;
  66. static const int VLB_DATA = 0x8000;
  67. static const int AAC_LC_DATA = 0x8001;
  68. static const int AACP_DATA = 0x8003;
  69. static const int OGG_DATA = 0x8004;
  70. /// these are the same
  71. static const int MAX_METADATA_SEGMENTS = 32;
  72. #define MAX_METADATA_FRAGMENTS 32
  73. ///////
  74. static const int MAX_METADATA_TIME(300); // five minutes
  75. // take data and create a uvox message appended to "v". Limit by MAX_PAYLOAD_SIZE.
  76. // return amount of data UNconsumed
  77. int formMessage(const __uint8 *data, const int len, const int type, std::vector<__uint8> &v) throw(std::runtime_error);
  78. // similar to above, except it writes data into a buffer pointed to by v
  79. int formMessage(const __uint8 *data, const int len, const int type, __uint8 *v) throw(std::runtime_error);
  80. // this one also returns actual full message size in msgSize
  81. inline int formMessage(const std::string &dataIn, const int type, __uint8 *v, int &msgSize) throw(std::runtime_error)
  82. {
  83. msgSize = (int)(dataIn.size() + 1); // include null
  84. int amt_left = formMessage((const __uint8 *)dataIn.c_str(), msgSize /* include null */, type, v);
  85. msgSize += UV2X_OVERHEAD;
  86. return amt_left;
  87. }
  88. // load vector v up with metadata packets.
  89. void createMetadataPackets(const __uint8 *data, const int len, const int type,
  90. std::vector<__uint8> &v, const __uint16 metadataID = 1) throw(std::runtime_error);
  91. #endif