amf.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef __AMF_H__
  2. #define __AMF_H__
  3. /*
  4. * Copyright (C) 2005-2008 Team XBMC
  5. * http://www.xbmc.org
  6. * Copyright (C) 2008-2009 Andrej Stepanchuk
  7. * Copyright (C) 2009-2010 Howard Chu
  8. *
  9. * This file is part of librtmp.
  10. *
  11. * librtmp is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as
  13. * published by the Free Software Foundation; either version 2.1,
  14. * or (at your option) any later version.
  15. *
  16. * librtmp is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with librtmp see the file COPYING. If not, write to
  23. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. * Boston, MA 02110-1301, USA.
  25. * http://www.gnu.org/copyleft/lgpl.html
  26. */
  27. #ifndef TRUE
  28. #define TRUE 1
  29. #define FALSE 0
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. typedef enum
  36. {
  37. AMF_NUMBER = 0, AMF_BOOLEAN, AMF_STRING, AMF_OBJECT,
  38. AMF_MOVIECLIP, /* reserved, not used */
  39. AMF_NULL, AMF_UNDEFINED, AMF_REFERENCE, AMF_ECMA_ARRAY, AMF_OBJECT_END,
  40. AMF_STRICT_ARRAY, AMF_DATE, AMF_LONG_STRING, AMF_UNSUPPORTED,
  41. AMF_RECORDSET, /* reserved, not used */
  42. AMF_XML_DOC, AMF_TYPED_OBJECT,
  43. AMF_AVMPLUS, /* switch to AMF3 */
  44. AMF_INVALID = 0xff
  45. }
  46. AMFDataType;
  47. typedef enum
  48. {
  49. AMF3_UNDEFINED = 0, AMF3_NULL, AMF3_FALSE, AMF3_TRUE,
  50. AMF3_INTEGER, AMF3_DOUBLE, AMF3_STRING, AMF3_XML_DOC, AMF3_DATE,
  51. AMF3_ARRAY, AMF3_OBJECT, AMF3_XML, AMF3_BYTE_ARRAY
  52. } AMF3DataType;
  53. typedef struct AVal
  54. {
  55. char *av_val;
  56. int av_len;
  57. } AVal;
  58. #define AVC(str) {str,sizeof(str)-1}
  59. #define AVMATCH(a1,a2) ((a1)->av_len == (a2)->av_len && !memcmp((a1)->av_val,(a2)->av_val,(a1)->av_len))
  60. struct AMFObjectProperty;
  61. typedef struct AMFObject
  62. {
  63. int o_num;
  64. struct AMFObjectProperty *o_props;
  65. } AMFObject;
  66. typedef struct AMFObjectProperty
  67. {
  68. AVal p_name;
  69. AMFDataType p_type;
  70. union
  71. {
  72. double p_number;
  73. AVal p_aval;
  74. AMFObject p_object;
  75. } p_vu;
  76. int16_t p_UTCoffset;
  77. } AMFObjectProperty;
  78. char *AMF_EncodeString(char *output, char *outend, const AVal * str);
  79. char *AMF_EncodeNumber(char *output, char *outend, double dVal);
  80. char *AMF_EncodeInt16(char *output, char *outend, short nVal);
  81. char *AMF_EncodeInt24(char *output, char *outend, int nVal);
  82. char *AMF_EncodeInt32(char *output, char *outend, int nVal);
  83. char *AMF_EncodeBoolean(char *output, char *outend, int bVal);
  84. /* Shortcuts for AMFProp_Encode */
  85. char *AMF_EncodeNamedString(char *output, char *outend, const AVal * name, const AVal * value);
  86. char *AMF_EncodeNamedNumber(char *output, char *outend, const AVal * name, double dVal);
  87. char *AMF_EncodeNamedBoolean(char *output, char *outend, const AVal * name, int bVal);
  88. unsigned short AMF_DecodeInt16(const char *data);
  89. unsigned int AMF_DecodeInt24(const char *data);
  90. unsigned int AMF_DecodeInt32(const char *data);
  91. void AMF_DecodeString(const char *data, AVal * str);
  92. void AMF_DecodeLongString(const char *data, AVal * str);
  93. int AMF_DecodeBoolean(const char *data);
  94. double AMF_DecodeNumber(const char *data);
  95. char *AMF_Encode(AMFObject * obj, char *pBuffer, char *pBufEnd);
  96. char *AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
  97. char *AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
  98. int AMF_Decode(AMFObject * obj, const char *pBuffer, int nSize,
  99. int bDecodeName);
  100. int AMF_DecodeArray(AMFObject * obj, const char *pBuffer, int nSize,
  101. int nArrayLen, int bDecodeName);
  102. int AMF3_Decode(AMFObject * obj, const char *pBuffer, int nSize,
  103. int bDecodeName);
  104. void AMF_Dump(AMFObject * obj);
  105. void AMF_Reset(AMFObject * obj);
  106. void AMF_AddProp(AMFObject * obj, const AMFObjectProperty * prop);
  107. int AMF_CountProp(AMFObject * obj);
  108. AMFObjectProperty *AMF_GetProp(AMFObject * obj, const AVal * name,
  109. int nIndex);
  110. AMFDataType AMFProp_GetType(AMFObjectProperty * prop);
  111. void AMFProp_SetNumber(AMFObjectProperty * prop, double dval);
  112. void AMFProp_SetBoolean(AMFObjectProperty * prop, int bflag);
  113. void AMFProp_SetString(AMFObjectProperty * prop, AVal * str);
  114. void AMFProp_SetObject(AMFObjectProperty * prop, AMFObject * obj);
  115. void AMFProp_GetName(AMFObjectProperty * prop, AVal * name);
  116. void AMFProp_SetName(AMFObjectProperty * prop, AVal * name);
  117. double AMFProp_GetNumber(AMFObjectProperty * prop);
  118. int AMFProp_GetBoolean(AMFObjectProperty * prop);
  119. void AMFProp_GetString(AMFObjectProperty * prop, AVal * str);
  120. void AMFProp_GetObject(AMFObjectProperty * prop, AMFObject * obj);
  121. int AMFProp_IsValid(AMFObjectProperty * prop);
  122. char *AMFProp_Encode(AMFObjectProperty * prop, char *pBuffer, char *pBufEnd);
  123. int AMF3Prop_Decode(AMFObjectProperty * prop, const char *pBuffer,
  124. int nSize, int bDecodeName);
  125. int AMFProp_Decode(AMFObjectProperty * prop, const char *pBuffer,
  126. int nSize, int bDecodeName);
  127. void AMFProp_Dump(AMFObjectProperty * prop);
  128. void AMFProp_Reset(AMFObjectProperty * prop);
  129. typedef struct AMF3ClassDef
  130. {
  131. AVal cd_name;
  132. char cd_externalizable;
  133. char cd_dynamic;
  134. int cd_num;
  135. AVal *cd_props;
  136. } AMF3ClassDef;
  137. void AMF3CD_AddProp(AMF3ClassDef * cd, AVal * prop);
  138. AVal *AMF3CD_GetProp(AMF3ClassDef * cd, int idx);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif /* __AMF_H__ */