⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtmp_amf_flv.c

📁 vlc源码
💻 C
📖 第 1 页 / 共 5 页
字号:
static voidrtmp_handler_audio_data( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet ){    block_t *p_buffer;    if( !p_thread->has_audio )    {        p_thread->has_audio = 1;        flv_get_metadata_audio( p_thread, rtmp_packet,            &p_thread->metadata_stereo, &p_thread->metadata_samplesize,            &p_thread->metadata_samplerate, &p_thread->metadata_audiocodecid );    }    flv_rebuild( p_thread, rtmp_packet );    p_buffer = rtmp_new_block( p_thread, rtmp_packet->body->body, rtmp_packet->body->length_body );    block_FifoPut( p_thread->p_fifo_input, p_buffer );    free( rtmp_packet->body->body );    free( rtmp_packet->body );    free( rtmp_packet );}static voidrtmp_handler_video_data( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet ){    block_t *p_buffer;    if( !p_thread->has_video )    {        p_thread->has_video = 1;        flv_get_metadata_video( p_thread, rtmp_packet,            &p_thread->metadata_videocodecid, &p_thread->metadata_frametype );    }    flv_rebuild( p_thread, rtmp_packet );    p_buffer = rtmp_new_block( p_thread, rtmp_packet->body->body, rtmp_packet->body->length_body );    block_FifoPut( p_thread->p_fifo_input, p_buffer );    free( rtmp_packet->body->body );    free( rtmp_packet->body );    free( rtmp_packet );}static voidrtmp_handler_notify( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet ){    block_t *p_buffer;    p_thread->metadata_received = 1;    flv_rebuild( p_thread, rtmp_packet );    p_buffer = rtmp_new_block( p_thread, rtmp_packet->body->body, rtmp_packet->body->length_body );    block_FifoPut( p_thread->p_fifo_input, p_buffer );    free( rtmp_packet->body->body );    free( rtmp_packet->body );    free( rtmp_packet );}static voidrtmp_handler_invoke( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet ){    rtmp_packet_t *tmp_rtmp_packet;    uint8_t *i, *end, *tmp_buffer;    double number;    char *string, *string2;    ssize_t i_ret;    i = rtmp_packet->body->body;    end = rtmp_packet->body->body + rtmp_packet->body->length_body;    i++; /* Pass over AMF_DATATYPE_STRING */    string = amf_decode_string( &i );    i++; /* Pass over AMF_DATATYPE_NUMBER */    number = amf_decode_number( &i );    msg_Dbg( p_thread, "%s %.1f", string, number );    if( strcmp( "connect", string ) == 0 )    {        /* Connection bandwith */        tmp_rtmp_packet = rtmp_encode_onBWDone( p_thread, AMF_CALL_ONBWDONE );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send connection bandwith" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Server bandwith */        tmp_rtmp_packet = rtmp_encode_server_bw( p_thread, RTMP_SERVER_BW );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send server bandwith" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Clear stream */        tmp_rtmp_packet = rtmp_encode_ping_clear_stream( p_thread, RTMP_SRC_DST_CONNECT_OBJECT );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send clear stream" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Reply NetConnection.connect */        tmp_rtmp_packet = rtmp_encode_NetConnection_connect_result( p_thread, number );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send reply NetConnection.connect" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );    }    else if( strcmp( "createStream", string ) == 0 )    {        p_thread->stream_client_id = number;        p_thread->stream_server_id = RTMP_DEFAULT_STREAM_SERVER_ID;        /* Reply createStream */        tmp_rtmp_packet = rtmp_encode_createStream_result( p_thread, p_thread->stream_client_id, p_thread->stream_server_id );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send reply createStream" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Reset stream */        tmp_rtmp_packet = rtmp_encode_ping_reset_stream( p_thread );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send reset stream" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Clear stream */        tmp_rtmp_packet = rtmp_encode_ping_clear_stream( p_thread, RTMP_SRC_DST_CONNECT_OBJECT2 );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );            i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send clear stream" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );    }    else if( strcmp( "publish", string ) == 0 )    {        i++;        msg_Dbg( p_thread, "null" );        i++;        string2 = amf_decode_string( &i );        msg_Dbg( p_thread, "string: %s", string2 );        p_thread->psz_publish = strdup( string2 );        free( string2 );    }    else if( strcmp( "play", string ) == 0 )    {        i++;        msg_Dbg( p_thread, "null" );        i++;        string2 = amf_decode_string( &i );        msg_Dbg( p_thread, "string: %s", string2 );        /* Reply NetStream.play.reset */        tmp_rtmp_packet = rtmp_encode_NetStream_play_reset_onStatus( p_thread, string2 );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send reply NetStream.play.reset" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        /* Reply NetStream.play.start */        tmp_rtmp_packet = rtmp_encode_NetStream_play_start_onStatus( p_thread, string2 );        tmp_buffer = rtmp_encode_packet( p_thread, tmp_rtmp_packet );        i_ret = net_Write( p_thread, p_thread->fd, NULL, tmp_buffer, tmp_rtmp_packet->length_encoded );        if( i_ret != tmp_rtmp_packet->length_encoded )        {            msg_Err( p_thread, "failed send reply NetStream.play.start" );            goto error;        }        free( tmp_rtmp_packet->body->body );        free( tmp_rtmp_packet->body );        free( tmp_rtmp_packet );        free( tmp_buffer );        free( string2 );        p_thread->result_play = 0;        vlc_mutex_lock( &p_thread->lock );        vlc_cond_signal( &p_thread->wait );        vlc_mutex_unlock( &p_thread->lock );    }    free( string );    while( i < end )    {        if( *i == AMF_DATATYPE_NUMBER )        {            i++;            msg_Dbg( p_thread, "number: %le", amf_decode_number( &i ) );        }        else if( *i == AMF_DATATYPE_BOOLEAN )        {            i++;            msg_Dbg( p_thread, "boolean: %s", amf_decode_boolean( &i ) ? "true" : "false" );        }        else if( *i == AMF_DATATYPE_STRING )        {            i++;            string = amf_decode_string( &i );            msg_Dbg( p_thread, "string: %s", string );            free( string );        }        else if( *i == AMF_DATATYPE_OBJECT )        {            i++;            msg_Dbg( p_thread, "object" );            while( ( string = amf_decode_object( &i ) ) != NULL )            {                if( *i == AMF_DATATYPE_NUMBER )                {                    i++;                    msg_Dbg( p_thread, "key: %s value: %le", string, amf_decode_number( &i ) );                }                else if( *i == AMF_DATATYPE_BOOLEAN )                {                    i++;                    msg_Dbg( p_thread, "key: %s value: %s", string, amf_decode_boolean( &i ) ? "true" : "false" );                }                else if( *i == AMF_DATATYPE_STRING )                {                    i++;                    string2 = amf_decode_string( &i );                    msg_Dbg( p_thread, "key: %s value: %s", string, string2 );                    if( strcmp( "code", string ) == 0 )                    {                        if( strcmp( "NetConnection.Connect.Success", string2 ) == 0 )                        {                            p_thread->result_connect = 0;                            vlc_mutex_lock( &p_thread->lock );                            vlc_cond_signal( &p_thread->wait );                            vlc_mutex_unlock( &p_thread->lock );                        }                        else if( strcmp( "NetConnection.Connect.InvalidApp", string2 ) == 0 )                        {                            p_thread->b_die = 1;                             vlc_mutex_lock( &p_thread->lock );                            vlc_cond_signal( &p_thread->wait );                            vlc_mutex_unlock( &p_thread->lock );                        }                        else if( strcmp( "NetStream.Play.Start", string2 ) == 0 )                        {                            p_thread->result_play = 0;                            vlc_mutex_lock( &p_thread->lock );                            vlc_cond_signal( &p_thread->wait );                            vlc_mutex_unlock( &p_thread->lock );                        }                        else if( strcmp( "NetStream.Play.Stop", string2 ) == 0 )                        {                            p_thread->result_stop = 1;                            block_FifoWake( p_thread->p_fifo_input );                        }                    }                    free( string2 );                }                else if( *i == AMF_DATATYPE_NULL )                {                    i++;                    msg_Dbg( p_thread, "key: %s value: Null", string );                }                else if( *i == AMF_DATATYPE_UNDEFINED )                {                    i++;                    msg_Dbg( p_thread, "key: %s value: undefined (Null)", string );                }                else                {                    i++;                    msg_Warn( p_thread, "key: %s value: undefined AMF type", string );                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -