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