static int send_invoke_response(URLContext *s, RTMPPacket *pkt)

{

    RTMPContext *rt = s->priv_data;

    double seqnum;

    char filename[64];

    char command[64];

    int stringlen;

    char *pchar;

    const uint8_t *p = pkt->data;

    uint8_t *pp      = NULL;

    RTMPPacket spkt  = { 0 };

    GetByteContext gbc;

    int ret;



    bytestream2_init(&gbc, p, pkt->size);

    if (ff_amf_read_string(&gbc, command, sizeof(command),

                           &stringlen)) {

        av_log(s, AV_LOG_ERROR, "Error in PT_INVOKE\n");

        return AVERROR_INVALIDDATA;

    }



    ret = ff_amf_read_number(&gbc, &seqnum);

    if (ret)

        return ret;

    ret = ff_amf_read_null(&gbc);

    if (ret)

        return ret;

    if (!strcmp(command, "FCPublish") ||

        !strcmp(command, "publish")) {

        ret = ff_amf_read_string(&gbc, filename,

                                 sizeof(filename), &stringlen);

        if (ret) {

            if (ret == AVERROR(EINVAL))

                av_log(s, AV_LOG_ERROR, "Unable to parse stream name - name too long?\n");

            else

                av_log(s, AV_LOG_ERROR, "Unable to parse stream name\n");

            return ret;

        }

        // check with url

        if (s->filename) {

            pchar = strrchr(s->filename, '/');

            if (!pchar) {

                av_log(s, AV_LOG_WARNING,

                       "Unable to find / in url %s, bad format\n",

                       s->filename);

                pchar = s->filename;

            }

            pchar++;

            if (strcmp(pchar, filename))

                av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"

                       " %s\n", filename, pchar);

        }

        rt->state = STATE_RECEIVING;

    }



    if (!strcmp(command, "FCPublish")) {

        if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(s, AV_LOG_ERROR, "Unable to create response packet\n");

            return ret;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "onFCPublish");

    } else if (!strcmp(command, "publish")) {

        ret = write_begin(s);

        if (ret < 0)

            return ret;



        // Send onStatus(NetStream.Publish.Start)

        return write_status(s, pkt, "NetStream.Publish.Start",

                           filename);

    } else if (!strcmp(command, "play")) {

        ret = write_begin(s);

        if (ret < 0)

            return ret;

        rt->state = STATE_SENDING;

        return write_status(s, pkt, "NetStream.Play.Start",

                            filename);

    } else {

        if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(s, AV_LOG_ERROR, "Unable to create response packet\n");

            return ret;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "_result");

        ff_amf_write_number(&pp, seqnum);

        ff_amf_write_null(&pp);

        if (!strcmp(command, "createStream")) {

            rt->nb_streamid++;

            if (rt->nb_streamid == 0 || rt->nb_streamid == 2)

                rt->nb_streamid++; /* Values 0 and 2 are reserved */

            ff_amf_write_number(&pp, rt->nb_streamid);

            /* By now we don't control which streams are removed in

             * deleteStream. There is no stream creation control

             * if a client creates more than 2^32 - 2 streams. */

        }

    }

    spkt.size = pp - spkt.data;

    ret = ff_rtmp_packet_write(rt->stream, &spkt, rt->out_chunk_size,

                               &rt->prev_pkt[1], &rt->nb_prev_pkt[1]);

    ff_rtmp_packet_destroy(&spkt);

    return ret;

}

static int send_invoke_response(URLContext *s, RTMPPacket *pkt)

{

    RTMPContext *rt = s->priv_data;

    double seqnum;

    char filename[64];

    char command[64];

    int stringlen;

    char *pchar;

    const uint8_t *p = pkt->data;

    uint8_t *pp      = NULL;

    RTMPPacket spkt  = { 0 };

    GetByteContext gbc;

    int ret;



    bytestream2_init(&gbc, p, pkt->size);

    if (ff_amf_read_string(&gbc, command, sizeof(command),

                           &stringlen)) {

        av_log(s, AV_LOG_ERROR, "Error in PT_INVOKE\n");

        return AVERROR_INVALIDDATA;

    }



    ret = ff_amf_read_number(&gbc, &seqnum);

    if (ret)

        return ret;

    ret = ff_amf_read_null(&gbc);

    if (ret)

        return ret;

    if (!strcmp(command, "FCPublish") ||

        !strcmp(command, "publish")) {

        ret = ff_amf_read_string(&gbc, filename,

                                 sizeof(filename), &stringlen);

        if (ret) {

            if (ret == AVERROR(EINVAL))

                av_log(s, AV_LOG_ERROR, "Unable to parse stream name - name too long?\n");

            else

                av_log(s, AV_LOG_ERROR, "Unable to parse stream name\n");

            return ret;

        }

        

        if (s->filename) {

            pchar = strrchr(s->filename, '/');

            if (!pchar) {

                av_log(s, AV_LOG_WARNING,

                       "Unable to find / in url %s, bad format\n",

                       s->filename);

                pchar = s->filename;

            }

            pchar++;

            if (strcmp(pchar, filename))

                av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"

                       " %s\n", filename, pchar);

        }

        rt->state = STATE_RECEIVING;

    }



    if (!strcmp(command, "FCPublish")) {

        if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(s, AV_LOG_ERROR, "Unable to create response packet\n");

            return ret;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "onFCPublish");

    } else if (!strcmp(command, "publish")) {

        ret = write_begin(s);

        if (ret < 0)

            return ret;



        

        return write_status(s, pkt, "NetStream.Publish.Start",

                           filename);

    } else if (!strcmp(command, "play")) {

        ret = write_begin(s);

        if (ret < 0)

            return ret;

        rt->state = STATE_SENDING;

        return write_status(s, pkt, "NetStream.Play.Start",

                            filename);

    } else {

        if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(s, AV_LOG_ERROR, "Unable to create response packet\n");

            return ret;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "_result");

        ff_amf_write_number(&pp, seqnum);

        ff_amf_write_null(&pp);

        if (!strcmp(command, "createStream")) {

            rt->nb_streamid++;

            if (rt->nb_streamid == 0 || rt->nb_streamid == 2)

                rt->nb_streamid++; 

            ff_amf_write_number(&pp, rt->nb_streamid);

            





        }

    }

    spkt.size = pp - spkt.data;

    ret = ff_rtmp_packet_write(rt->stream, &spkt, rt->out_chunk_size,

                               &rt->prev_pkt[1], &rt->nb_prev_pkt[1]);

    ff_rtmp_packet_destroy(&spkt);

    return ret;

}

    char filename[64];
static int FUNC_0(URLContext *VAR_0, RTMPPacket *VAR_1)

{

    RTMPContext *rt = VAR_0->priv_data;

    double VAR_2;

    char VAR_3[64];

    char VAR_4[64];

    int VAR_5;

    char *VAR_6;

    const uint8_t *VAR_7 = VAR_1->data;

    uint8_t *pp      = NULL;

    RTMPPacket spkt  = { 0 };

    GetByteContext gbc;

    int VAR_8;



    bytestream2_init(&gbc, VAR_7, VAR_1->size);

    if (ff_amf_read_string(&gbc, VAR_4, sizeof(VAR_4),

                           &VAR_5)) {

        av_log(VAR_0, AV_LOG_ERROR, "Error in PT_INVOKE\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_8 = ff_amf_read_number(&gbc, &VAR_2);

    if (VAR_8)

        return VAR_8;

    VAR_8 = ff_amf_read_null(&gbc);

    if (VAR_8)

        return VAR_8;

    if (!strcmp(VAR_4, "FCPublish") ||

        !strcmp(VAR_4, "publish")) {

        VAR_8 = ff_amf_read_string(&gbc, VAR_3,

                                 sizeof(VAR_3), &VAR_5);

        if (VAR_8) {

            if (VAR_8 == AVERROR(EINVAL))

                av_log(VAR_0, AV_LOG_ERROR, "Unable to parse stream name - name too long?\n");

            else

                av_log(VAR_0, AV_LOG_ERROR, "Unable to parse stream name\n");

            return VAR_8;

        }

        

        if (VAR_0->VAR_3) {

            VAR_6 = strrchr(VAR_0->VAR_3, '/');

            if (!VAR_6) {

                av_log(VAR_0, AV_LOG_WARNING,

                       "Unable to find / in url %VAR_0, bad format\n",

                       VAR_0->VAR_3);

                VAR_6 = VAR_0->VAR_3;

            }

            VAR_6++;

            if (strcmp(VAR_6, VAR_3))

                av_log(VAR_0, AV_LOG_WARNING, "Unexpected stream %VAR_0, expecting"

                       " %VAR_0\n", VAR_3, VAR_6);

        }

        rt->state = STATE_RECEIVING;

    }



    if (!strcmp(VAR_4, "FCPublish")) {

        if ((VAR_8 = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Unable to create response packet\n");

            return VAR_8;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "onFCPublish");

    } else if (!strcmp(VAR_4, "publish")) {

        VAR_8 = write_begin(VAR_0);

        if (VAR_8 < 0)

            return VAR_8;



        

        return write_status(VAR_0, VAR_1, "NetStream.Publish.Start",

                           VAR_3);

    } else if (!strcmp(VAR_4, "play")) {

        VAR_8 = write_begin(VAR_0);

        if (VAR_8 < 0)

            return VAR_8;

        rt->state = STATE_SENDING;

        return write_status(VAR_0, VAR_1, "NetStream.Play.Start",

                            VAR_3);

    } else {

        if ((VAR_8 = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,

                                         RTMP_PT_INVOKE, 0,

                                         RTMP_PKTDATA_DEFAULT_SIZE)) < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Unable to create response packet\n");

            return VAR_8;

        }

        pp = spkt.data;

        ff_amf_write_string(&pp, "_result");

        ff_amf_write_number(&pp, VAR_2);

        ff_amf_write_null(&pp);

        if (!strcmp(VAR_4, "createStream")) {

            rt->nb_streamid++;

            if (rt->nb_streamid == 0 || rt->nb_streamid == 2)

                rt->nb_streamid++; 

            ff_amf_write_number(&pp, rt->nb_streamid);

            





        }

    }

    spkt.size = pp - spkt.data;

    VAR_8 = ff_rtmp_packet_write(rt->stream, &spkt, rt->out_chunk_size,

                               &rt->prev_pkt[1], &rt->nb_prev_pkt[1]);

    ff_rtmp_packet_destroy(&spkt);

    return VAR_8;

}

static int FUNC_0(URLContext *VAR_0, RTMPPacket *VAR_1)
{ RTMPContext *rt = VAR_0->priv_data; double VAR_2; char VAR_3[64]; char VAR_4[64]; int VAR_5; char *VAR_6; const uint8_t *VAR_7 = VAR_1->data; uint8_t *pp      = NULL; RTMPPacket spkt  = { 0 }; GetByteContext gbc; int VAR_8; bytestream2_init(&gbc, VAR_7, VAR_1->size); if (ff_amf_read_string(&gbc, VAR_4, sizeof(VAR_4),
&VAR_5)) { av_log(VAR_0, AV_LOG_ERROR, "Error in PT_INVOKE\n"); return AVERROR_INVALIDDATA; } VAR_8 = ff_amf_read_number(&gbc, &VAR_2); if (VAR_8)
return VAR_8; VAR_8 = ff_amf_read_null(&gbc); if (VAR_8)
return VAR_8; if (!strcmp(VAR_4, "FCPublish") ||
!strcmp(VAR_4, "publish")) { VAR_8 = ff_amf_read_string(&gbc, VAR_3,
sizeof(VAR_3), &VAR_5); if (VAR_8) { if (VAR_8 == AVERROR(EINVAL))
av_log(VAR_0, AV_LOG_ERROR, "Unable to parse stream name - name too long?\n"); else
av_log(VAR_0, AV_LOG_ERROR, "Unable to parse stream name\n"); return VAR_8; } if (VAR_0->VAR_3) { VAR_6 = strrchr(VAR_0->VAR_3, '/'); if (!VAR_6) { av_log(VAR_0, AV_LOG_WARNING,
"Unable to find / in url %VAR_0, bad format\n",
VAR_0->VAR_3); VAR_6 = VAR_0->VAR_3; } VAR_6++; if (strcmp(VAR_6, VAR_3))
av_log(VAR_0, AV_LOG_WARNING, "Unexpected stream %VAR_0, expecting"
" %VAR_0\n", VAR_3, VAR_6); } rt->state = STATE_RECEIVING; } if (!strcmp(VAR_4, "FCPublish")) { if ((VAR_8 = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,
RTMP_PT_INVOKE, 0,
RTMP_PKTDATA_DEFAULT_SIZE)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Unable to create response packet\n"); return VAR_8; } pp = spkt.data; ff_amf_write_string(&pp, "onFCPublish"); } else if (!strcmp(VAR_4, "publish")) { VAR_8 = write_begin(VAR_0); if (VAR_8 < 0)
return VAR_8; return write_status(VAR_0, VAR_1, "NetStream.Publish.Start",
VAR_3); } else if (!strcmp(VAR_4, "play")) { VAR_8 = write_begin(VAR_0); if (VAR_8 < 0)
return VAR_8; rt->state = STATE_SENDING; return write_status(VAR_0, VAR_1, "NetStream.Play.Start",
VAR_3); } else { if ((VAR_8 = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL,
RTMP_PT_INVOKE, 0,
RTMP_PKTDATA_DEFAULT_SIZE)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Unable to create response packet\n"); return VAR_8; } pp = spkt.data; ff_amf_write_string(&pp, "_result"); ff_amf_write_number(&pp, VAR_2); ff_amf_write_null(&pp); if (!strcmp(VAR_4, "createStream")) { rt->nb_streamid++; if (rt->nb_streamid == 0 || rt->nb_streamid == 2)
rt->nb_streamid++; ff_amf_write_number(&pp, rt->nb_streamid); } } spkt.size = pp - spkt.data; VAR_8 = ff_rtmp_packet_write(rt->stream, &spkt, rt->out_chunk_size,
&rt->prev_pkt[1], &rt->nb_prev_pkt[1]); ff_rtmp_packet_destroy(&spkt); return VAR_8; }