示例#1
0
文件: amf0.c 项目: hslinxubin/libamf
/* load AMF data from stream */
amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) {
    uint8_t type;
    if (read_proc(&type, sizeof(uint8_t), user_data) == sizeof(uint8_t)) {
        switch (type) {
            case AMF0_TYPE_NUMBER:
                return amf0_number_read(read_proc, user_data);
            case AMF0_TYPE_BOOLEAN:
                return amf0_boolean_read(read_proc, user_data);
            case AMF0_TYPE_STRING:
                return amf0_string_read(read_proc, user_data);
            case AMF0_TYPE_OBJECT:
                return amf0_object_read(read_proc, user_data);
            case AMF0_TYPE_NULL:
                return amf0_null_new();
            case AMF0_TYPE_UNDEFINED:
                return amf0_undefined_new();
            /*case AMF0_TYPE_REFERENCE:*/
            case AMF0_TYPE_ECMA_ARRAY:
                return amf0_associative_array_read(read_proc, user_data);
            case AMF0_TYPE_STRICT_ARRAY:
                return amf0_array_read(read_proc, user_data);
            case AMF0_TYPE_DATE:
                return amf0_date_read(read_proc, user_data);
            /*case AMF0_TYPE_SIMPLEOBJECT:*/
            case AMF0_TYPE_XML_DOCUMENT:
            case AMF0_TYPE_TYPED_OBJECT:
            case AMF0_TYPE_OBJECT_END:
                return NULL; /* end of composite object */
            default:
                break;
        }
    }
    return NULL;
}
示例#2
0
    Message Message::Play(std::string key) {
        uint8_t buf[4096];
        size_t len;
        Message msg;
        amf0_data *data;

        msg.write_string("play");

        data = amf0_number_new(3);
        len = amf0_data_buffer_write(data, buf, 4096);
        msg.body_.insert(msg.body_.end(), buf, buf + len);
        amf0_data_free(data);

        data = amf0_null_new();
        len = amf0_data_buffer_write(data, buf, 4096);
        msg.body_.insert(msg.body_.end(), buf, buf + len);
        amf0_data_free(data);

        msg.write_string(key);

        data = amf0_number_new(-2000);
        len = amf0_data_buffer_write(data, buf, 4096);
        msg.body_.insert(msg.body_.end(), buf, buf + len);
        amf0_data_free(data);

        msg.csid_ = 8;
        msg.timestamp_ = 0;
        msg.type_ = COMMAND_AMF0;  /* AMF 0 */
        msg.stream_id_ = 1;
        msg.length_ = msg.body_.size();
        return msg;
    }
示例#3
0
/* static */
    Message Message::CreateStream() {
        uint8_t buf[4096];
        size_t len;
        Message msg;
        amf0_data *data;

        msg.write_string("createStream");

        data = amf0_number_new(2);
        len = amf0_data_buffer_write(data, buf, 4096);
        msg.body_.insert(msg.body_.end(), buf, buf + len);
        amf0_data_free(data);

        data = amf0_null_new();
        len = amf0_data_buffer_write(data, buf, 4096);
        msg.body_.insert(msg.body_.end(), buf, buf + len);
        amf0_data_free(data);

        msg.csid_ = 3;
        msg.timestamp_ = 0;
        msg.type_ = COMMAND_AMF0;  /* Command AMF0 */
        msg.stream_id_ = 0;
        msg.length_ = msg.body_.size();
        return msg;
    }
示例#4
0
/* return a null AMF object with the specified error code attached to it */
static amf0_data * amf0_data_error(uint8_t error_code) {
    amf0_data * data = amf0_null_new();
    if (data != NULL) {
        data->error_code = error_code;
    }
    return data;
}
示例#5
0
/* load AMF data from stream */
amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) {
    uint8_t type;
    if (read_proc(&type, sizeof(uint8_t), user_data) == sizeof(uint8_t)) {
        switch (type) {
            case AMF0_TYPE_NUMBER:
                return amf0_number_read(read_proc, user_data);
            case AMF0_TYPE_BOOLEAN:
                return amf0_boolean_read(read_proc, user_data);
            case AMF0_TYPE_STRING:
                return amf0_string_read(read_proc, user_data);
            case AMF0_TYPE_OBJECT:
                return amf0_object_read(read_proc, user_data);
            case AMF0_TYPE_MOVIECLIP:
                return NULL; /* not supported */
            case AMF0_TYPE_NULL:
                return amf0_null_new();
            case AMF0_TYPE_UNDEFINED:
                return amf0_undefined_new();
            case AMF0_TYPE_REFERENCE: /* TODO */
                return NULL;
            case AMF0_TYPE_ECMA_ARRAY:
                return amf0_associative_array_read(read_proc, user_data);
            case AMF0_TYPE_OBJECT_END:
                return amf0_data_error(AMF0_ERROR_END_TAG); /* end of composite object */
            case AMF0_TYPE_STRICT_ARRAY:
                return amf0_array_read(read_proc, user_data);
            case AMF0_TYPE_DATE:
                return amf0_date_read(read_proc, user_data);
            case AMF0_TYPE_LONG_STRING: /* TODO */
            case AMF0_TYPE_UNSUPPORTED: /* TODO */
            case AMF0_TYPE_RECORDSET: /* not supported */
            case AMF0_TYPE_XML_DOCUMENT: /* TODO */
            case AMF0_TYPE_TYPED_OBJECT: /* TODO */
                return NULL;
            default:
                break;
        }
    }
    return NULL;
}