Ejemplo n.º 1
0
/*static*/
    Message Message::Connect(std::string app, int rpc_number) {
        uint8_t buf[4096];
        size_t len;
        Message msg;
        amf0_data *data;

        msg.write_string("connect");

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

        data = amf0_object_new();
        amf0_object_add(data, "app", amf0_str(app.c_str()));
        amf0_object_add(data, "type", amf0_str("nonprivate"));
        amf0_object_add(data, "flashVer", amf0_str("FMLE/3.0 (compatible; obs-studio/0.14.2; FMSc/1.0)"));
        amf0_object_add(data, "tcUrl", amf0_str("rtmp://live.hkstv.hk.lxdns.com:1935/live"));
        amf0_object_add(data, "capabilities", amf0_number_new(15));
        amf0_object_add(data, "audioCodecs", amf0_number_new(4071));
        amf0_object_add(data, "videoCodecs", amf0_number_new(252));
        amf0_object_add(data, "videoFunction", amf0_number_new(1));
        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.type_ = COMMAND_AMF0;  /* Command AMF0 */
        msg.stream_id_ = 0;
        msg.length_ = msg.body_.size();
        return msg;
    }
Ejemplo n.º 2
0
/* read an object */
static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data) {
    amf0_data * data = amf0_object_new();
    if (data != NULL) {
        amf0_data * name;
        amf0_data * element;
        while (1) {
            name = amf0_string_read(read_proc, user_data);
            if (name != NULL) {
                element = amf0_data_read(read_proc, user_data);
                if (element != NULL) {
                    if (amf0_object_add(data, (char *)amf0_string_get_uint8_ts(name), element) == NULL) {
                        amf0_data_free(name);
                        amf0_data_free(element);
                        amf0_data_free(data);
                        return NULL;
                    }
                }
                else {
                    amf0_data_free(name);
                    break;
                }
            }
            else {
                /* invalid name: error */
                amf0_data_free(data);
                return NULL;
            }
        }
    }
    return data;
}
Ejemplo n.º 3
0
/* read an object */
static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data) {
    amf0_data * name;
    amf0_data * element;
    uint8_t error_code;
    amf0_data * data;

    data = amf0_object_new();
    if (data == NULL) {
        return NULL;
    }

    while (1) {
        name = amf0_string_read(read_proc, user_data);
        error_code = amf0_data_get_error(name);
        if (error_code != AMF0_ERROR_OK) {
            /* invalid name: error */
            amf0_data_free(name);
            amf0_data_free(data);
            return amf0_data_error(error_code);
        }

        element = amf0_data_read(read_proc, user_data);
        error_code = amf0_data_get_error(element);
        if (error_code == AMF0_ERROR_END_TAG || error_code == AMF0_ERROR_UNKNOWN_TYPE) {
            /* end tag or unknown element: end of data, exit loop */
            amf0_data_free(name);
            amf0_data_free(element);
            break;
        }
        else if (error_code != AMF0_ERROR_OK) {
            amf0_data_free(name);
            amf0_data_free(data);
            amf0_data_free(element);
            return amf0_data_error(error_code);
        }

        if (amf0_object_add(data, (char *)amf0_string_get_bytes(name), element) == NULL) {
            amf0_data_free(name);
            amf0_data_free(element);
            amf0_data_free(data);
            return NULL;
        }
        else {
            amf0_data_free(name);
        }
    }

    return data;
}
Ejemplo n.º 4
0
static amf0_data_t* _amf0_data_rv(SV* sv) {
    svtype svt = SvTYPE(sv);
    int i, len, count;
    amf0_data_t* d;
    SV** svp;
    SV* k;
    AV* ary;
    HV* hval;
    HE* he;
    STRLEN strlen;
    char* key;

    if (SVt_PVAV == svt) {
        d = (amf0_data_t*)amf0_strictarray_init();

        ary = (AV*)sv;
        len = av_len(ary) + 1;

        for (i = 0; i < len; ++i) {
            svp = av_fetch(ary, i, 0);
            if (svp) {
                amf0_strictarray_add((amf0_strictarray_t*)d, _amf0_data(*svp));
            }
            else {
                amf0_strictarray_add((amf0_strictarray_t*)d, _amf0_data(NULL));
            }
        }
    }
    else if (SVt_PVHV == svt) {
        d = (amf0_data_t*)amf0_object_init();

        hval  = (HV*)sv;
        count = hv_iterinit(hval);

        while ( (he = hv_iternext(hval)) ) {
            k = hv_iterkeysv(he);
            key = SvPV(k, strlen);

            amf0_object_add((amf0_object_t*)d, key, _amf0_data(HeVAL(he)));
        }
    }
    else {
        Perl_croak(aTHX_ "Data::AMF::XS doesn't support references except ARRAY and HASH");
    }

    return d;
}