amf.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #include <stdint.h>
  28. #ifndef TRUE
  29. #define TRUE 1
  30. #define FALSE 0
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. typedef enum
  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. } AMFDataType;
  46. typedef enum
  47. { AMF3_UNDEFINED = 0, AMF3_NULL, AMF3_FALSE, AMF3_TRUE,
  48. AMF3_INTEGER, AMF3_DOUBLE, AMF3_STRING, AMF3_XML_DOC, AMF3_DATE,
  49. AMF3_ARRAY, AMF3_OBJECT, AMF3_XML, AMF3_BYTE_ARRAY
  50. } AMF3DataType;
  51. typedef struct AVal
  52. {
  53. char *av_val;
  54. int av_len;
  55. } AVal;
  56. #define AVC(str) {str,sizeof(str)-1}
  57. #define AVMATCH(a1,a2) ((a1)->av_len == (a2)->av_len && !memcmp((a1)->av_val,(a2)->av_val,(a1)->av_len))
  58. struct AMFObjectProperty;
  59. typedef struct AMFObject
  60. {
  61. int o_num;
  62. struct AMFObjectProperty *o_props;
  63. } AMFObject;
  64. typedef struct AMFObjectProperty
  65. {
  66. AVal p_name;
  67. AMFDataType p_type;
  68. union
  69. {
  70. double p_number;
  71. AVal p_aval;
  72. AMFObject p_object;
  73. } p_vu;
  74. int16_t p_UTCoffset;
  75. } AMFObjectProperty;
  76. char *AMF_EncodeString(char *output, char *outend, const AVal * str);
  77. char *AMF_EncodeNumber(char *output, char *outend, double dVal);
  78. char *AMF_EncodeInt16(char *output, char *outend, short nVal);
  79. char *AMF_EncodeInt24(char *output, char *outend, int nVal);
  80. char *AMF_EncodeInt32(char *output, char *outend, int nVal);
  81. char *AMF_EncodeBoolean(char *output, char *outend, int bVal);
  82. /* Shortcuts for AMFProp_Encode */
  83. char *AMF_EncodeNamedString(char *output, char *outend, const AVal * name, const AVal * value);
  84. char *AMF_EncodeNamedNumber(char *output, char *outend, const AVal * name, double dVal);
  85. char *AMF_EncodeNamedBoolean(char *output, char *outend, const AVal * name, int bVal);
  86. unsigned short AMF_DecodeInt16(const char *data);
  87. unsigned int AMF_DecodeInt24(const char *data);
  88. unsigned int AMF_DecodeInt32(const char *data);
  89. void AMF_DecodeString(const char *data, AVal * str);
  90. void AMF_DecodeLongString(const char *data, AVal * str);
  91. int AMF_DecodeBoolean(const char *data);
  92. double AMF_DecodeNumber(const char *data);
  93. char *AMF_Encode(AMFObject * obj, char *pBuffer, char *pBufEnd);
  94. char *AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
  95. char *AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
  96. int AMF_Decode(AMFObject * obj, const char *pBuffer, int nSize,
  97. int bDecodeName);
  98. int AMF_DecodeArray(AMFObject * obj, const char *pBuffer, int nSize,
  99. int nArrayLen, int bDecodeName);
  100. int AMF3_Decode(AMFObject * obj, const char *pBuffer, int nSize,
  101. int bDecodeName);
  102. void AMF_Dump(AMFObject * obj);
  103. void AMF_Reset(AMFObject * obj);
  104. void AMF_AddProp(AMFObject * obj, const AMFObjectProperty * prop);
  105. int AMF_CountProp(AMFObject * obj);
  106. AMFObjectProperty *AMF_GetProp(AMFObject * obj, const AVal * name,
  107. int nIndex);
  108. AMFDataType AMFProp_GetType(AMFObjectProperty * prop);
  109. void AMFProp_SetNumber(AMFObjectProperty * prop, double dval);
  110. void AMFProp_SetBoolean(AMFObjectProperty * prop, int bflag);
  111. void AMFProp_SetString(AMFObjectProperty * prop, AVal * str);
  112. void AMFProp_SetObject(AMFObjectProperty * prop, AMFObject * obj);
  113. void AMFProp_GetName(AMFObjectProperty * prop, AVal * name);
  114. void AMFProp_SetName(AMFObjectProperty * prop, AVal * name);
  115. double AMFProp_GetNumber(AMFObjectProperty * prop);
  116. int AMFProp_GetBoolean(AMFObjectProperty * prop);
  117. void AMFProp_GetString(AMFObjectProperty * prop, AVal * str);
  118. void AMFProp_GetObject(AMFObjectProperty * prop, AMFObject * obj);
  119. int AMFProp_IsValid(AMFObjectProperty * prop);
  120. char *AMFProp_Encode(AMFObjectProperty * prop, char *pBuffer, char *pBufEnd);
  121. int AMF3Prop_Decode(AMFObjectProperty * prop, const char *pBuffer,
  122. int nSize, int bDecodeName);
  123. int AMFProp_Decode(AMFObjectProperty * prop, const char *pBuffer,
  124. int nSize, int bDecodeName);
  125. void AMFProp_Dump(AMFObjectProperty * prop);
  126. void AMFProp_Reset(AMFObjectProperty * prop);
  127. typedef struct AMF3ClassDef
  128. {
  129. AVal cd_name;
  130. char cd_externalizable;
  131. char cd_dynamic;
  132. int cd_num;
  133. AVal *cd_props;
  134. } AMF3ClassDef;
  135. void AMF3CD_AddProp(AMF3ClassDef * cd, AVal * prop);
  136. AVal *AMF3CD_GetProp(AMF3ClassDef * cd, int idx);
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif /* __AMF_H__ */