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

📄 live555.cpp

📁 uclinux 下的vlc播放器源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        {            msg_Err( p_demux, "WTF !" );            goto error;        }        tk = p_sys->track[i_tk];        /* Reset state */        tk->waiting = 0;        tk->i_pts   = 0;        tk->b_rtcp_sync = VLC_FALSE;        if( sub->rtcpInstance() != NULL )            sub->rtcpInstance()->setByeHandler( StreamClose, tk );        tk->readSource = sub->readSource();        tk->rtpSource  = sub->rtpSource();        i_tk++;    }    delete iter;    return VLC_SUCCESS;error:    if( iter ) delete iter;    return VLC_EGENERIC;}/***************************************************************************** * *****************************************************************************/static void StreamRead( void *p_private, unsigned int i_size,                        unsigned int i_truncated_bytes, struct timeval pts,                        unsigned int duration ){    live_track_t   *tk = (live_track_t*)p_private;    demux_t        *p_demux = tk->p_demux;    demux_sys_t    *p_sys = p_demux->p_sys;    block_t        *p_block;    int64_t i_pts = (uint64_t)pts.tv_sec * UI64C(1000000) +        (uint64_t)pts.tv_usec;    /* XXX Beurk beurk beurk Avoid having negative value XXX */    i_pts &= UI64C(0x00ffffffffffffff);    if( tk->b_quicktime && tk->p_es == NULL )    {        QuickTimeGenericRTPSource *qtRTPSource =            (QuickTimeGenericRTPSource*)tk->rtpSource;        QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;        uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];        if( qtState.sdAtomSize < 16 + 32 )        {            /* invalid */            p_sys->event = 0xff;            tk->waiting = 0;            return;        }        tk->fmt.i_codec = VLC_FOURCC(sdAtom[0],sdAtom[1],sdAtom[2],sdAtom[3]);        tk->fmt.video.i_width  = (sdAtom[28] << 8) | sdAtom[29];        tk->fmt.video.i_height = (sdAtom[30] << 8) | sdAtom[31];        if( tk->fmt.i_codec == VLC_FOURCC('a', 'v', 'c', '1') )        {            uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86;            uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom                              + qtRTPSource->qtState.sdAtomSize;            while (pos+8 < endpos) {                unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3];                if( atomLength == 0 || atomLength > endpos-pos) break;                if( memcmp(pos+4, "avcC", 4) == 0 &&                    atomLength > 8 &&                    atomLength <= INT_MAX)                {                    tk->fmt.i_extra = atomLength-8;                    tk->fmt.p_extra = malloc( tk->fmt.i_extra );                    memcpy(tk->fmt.p_extra, pos+8, atomLength-8);                    break;                }                pos += atomLength;            }        }        else        {            tk->fmt.i_extra        = qtState.sdAtomSize - 16;            tk->fmt.p_extra        = malloc( tk->fmt.i_extra );            memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra );        }        tk->p_es = es_out_Add( p_demux->out, &tk->fmt );    }#if 0    fprintf( stderr, "StreamRead size=%d pts=%lld\n",             i_size,             pts.tv_sec * 1000000LL + pts.tv_usec );#endif    /* grow buffer if it looks like buffer is too small, but don't eat     * up all the memory on strange streams */    if( i_truncated_bytes > 0 && tk->i_buffer < 2000000 )    {        void *p_tmp;        msg_Dbg( p_demux, "lost %d bytes", i_truncated_bytes );        msg_Dbg( p_demux, "increasing buffer size to %d", tk->i_buffer * 2 );        tk->i_buffer *= 2;        p_tmp = realloc( tk->p_buffer, tk->i_buffer );        if (p_tmp == NULL)        {            msg_Warn( p_demux, "realloc failed" );        }        else        {            tk->p_buffer = (uint8_t*)p_tmp;        }    }    if( i_size > tk->i_buffer )    {        msg_Warn( p_demux, "buffer overflow" );    }    /* FIXME could i_size be > buffer size ? */    if( tk->fmt.i_codec == VLC_FOURCC('s','a','m','r') ||        tk->fmt.i_codec == VLC_FOURCC('s','a','w','b') )    {        AMRAudioSource *amrSource = (AMRAudioSource*)tk->readSource;        p_block = block_New( p_demux, i_size + 1 );        p_block->p_buffer[0] = amrSource->lastFrameHeader();        memcpy( p_block->p_buffer + 1, tk->p_buffer, i_size );    }    else if( tk->fmt.i_codec == VLC_FOURCC('H','2','6','1') )    {#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1081468800        H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->rtpSource;        uint32_t header = h261Source->lastSpecialHeader();#else        uint32_t header = 0;        msg_Warn( p_demux, "need livemedia library >= \"2004.04.09\"" );#endif        p_block = block_New( p_demux, i_size + 4 );        memcpy( p_block->p_buffer, &header, 4 );        memcpy( p_block->p_buffer + 4, tk->p_buffer, i_size );        if( tk->rtpSource->curPacketMarkerBit() )            p_block->i_flags |= BLOCK_FLAG_END_OF_FRAME;    }    else if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','4') )    {        if( (tk->p_buffer[0] & 0x1f) >= 24 )            msg_Warn( p_demux, "unsupported NAL type for H264" );        /* Normal NAL type */        p_block = block_New( p_demux, i_size + 4 );        p_block->p_buffer[0] = 0x00;        p_block->p_buffer[1] = 0x00;        p_block->p_buffer[2] = 0x00;        p_block->p_buffer[3] = 0x01;        memcpy( &p_block->p_buffer[4], tk->p_buffer, i_size );    }    else if( tk->b_asf )    {        int i_copy = __MIN( p_sys->asfh.i_min_data_packet_size, (int)i_size );        p_block = block_New( p_demux, p_sys->asfh.i_min_data_packet_size );        memcpy( p_block->p_buffer, tk->p_buffer, i_copy );    }    else    {        p_block = block_New( p_demux, i_size );        memcpy( p_block->p_buffer, tk->p_buffer, i_size );    }    if( i_pts != tk->i_pts && !tk->b_muxed )    {        p_block->i_dts = ( tk->fmt.i_cat == VIDEO_ES ) ? 0 : i_pts;        p_block->i_pts = i_pts;    }    if( tk->b_muxed )    {        stream_DemuxSend( tk->p_out_muxed, p_block );    }    else if( tk->b_asf )    {        stream_DemuxSend( p_sys->p_out_asf, p_block );    }    else    {        es_out_Send( p_demux->out, tk->p_es, p_block );    }    /* warn that's ok */    p_sys->event = 0xff;    /* we have read data */    tk->waiting = 0;    p_demux->p_sys->b_no_data = VLC_FALSE;    p_demux->p_sys->i_no_data_ti = 0;    if( i_pts > 0 && !tk->b_muxed )    {        tk->i_pts = i_pts;    }}/***************************************************************************** * *****************************************************************************/static void StreamClose( void *p_private ){    live_track_t   *tk = (live_track_t*)p_private;    demux_t        *p_demux = tk->p_demux;    demux_sys_t    *p_sys = p_demux->p_sys;    msg_Dbg( p_demux, "StreamClose" );    p_sys->event = 0xff;    p_demux->b_error = VLC_TRUE;}/***************************************************************************** * *****************************************************************************/static void TaskInterrupt( void *p_private ){    demux_t *p_demux = (demux_t*)p_private;    p_demux->p_sys->i_no_data_ti++;    /* Avoid lock */    p_demux->p_sys->event = 0xff;}/***************************************************************************** *   *****************************************************************************/static void TimeoutPrevention( timeout_thread_t *p_timeout ){    p_timeout->b_die = VLC_FALSE;    p_timeout->i_remain = (int64_t)p_timeout->p_sys->i_timeout -2;    p_timeout->i_remain *= 1000000;    vlc_thread_ready( p_timeout );    /* Avoid lock */    while( !p_timeout->b_die )    {        if( p_timeout->i_remain <= 0 )        {            p_timeout->i_remain = (int64_t)p_timeout->p_sys->i_timeout -2;            p_timeout->i_remain *= 1000000;            p_timeout->p_sys->b_timeout_call = VLC_TRUE;            msg_Dbg( p_timeout, "reset the timeout timer" );        }        p_timeout->i_remain -= 200000;        msleep( 200000 ); /* 200 ms */    }}/***************************************************************************** * *****************************************************************************/static int b64_decode( char *dest, char *src );static int ParseASF( demux_t *p_demux ){    demux_sys_t    *p_sys = p_demux->p_sys;    const char *psz_marker = "a=pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,";    char *psz_asf = strcasestr( p_sys->p_sdp, psz_marker );    char *psz_end;    block_t *p_header;    /* Parse the asf header */    if( psz_asf == NULL )        return VLC_EGENERIC;    psz_asf += strlen( psz_marker );    psz_asf = strdup( psz_asf );    /* Duplicate it */    psz_end = strchr( psz_asf, '\n' );    while( psz_end > psz_asf && ( *psz_end == '\n' || *psz_end == '\r' ) )        *psz_end-- = '\0';    if( psz_asf >= psz_end )    {        free( psz_asf );        return VLC_EGENERIC;    }    /* Always smaller */    p_header = block_New( p_demux, psz_end - psz_asf );    p_header->i_buffer = b64_decode( (char*)p_header->p_buffer, psz_asf );    //msg_Dbg( p_demux, "Size=%d Hdrb64=%s", p_header->i_buffer, psz_asf );    if( p_header->i_buffer <= 0 )    {        free( psz_asf );        return VLC_EGENERIC;    }    /* Parse it to get packet size */    E_(asf_HeaderParse)( &p_sys->asfh, p_header->p_buffer, p_header->i_buffer );    /* Send it to demuxer */    stream_DemuxSend( p_sys->p_out_asf, p_header );    free( psz_asf );    return VLC_SUCCESS;}#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800static unsigned char* parseH264ConfigStr( char const* configStr,                                          unsigned int& configSize ){    char *dup, *psz;    int i, i_records = 1;    if( configSize )    configSize = 0;    if( configStr == NULL || *configStr == '\0' )        return NULL;    psz = dup = strdup( configStr );    /* Count the number of comma's */    for( psz = dup; *psz != '\0'; ++psz )    {        if( *psz == ',')        {            ++i_records;            *psz = '\0';        }    }    unsigned char *cfg = new unsigned char[5 * strlen(dup)];    psz = dup;    for( i = 0; i < i_records; i++ )    {        cfg[configSize++] = 0x00;        cfg[configSize++] = 0x00;        cfg[configSize++] = 0x00;        cfg[configSize++] = 0x01;        configSize += b64_decode( (char*)&cfg[configSize], psz );        psz += strlen(psz)+1;    }    if( dup ) free( dup );    return cfg;}#endif/*char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";*/static int b64_decode( char *dest, char *src ){    const char *dest_start = dest;    int  i_level;    int  last = 0;    int  b64[256] = {        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* 00-0F */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* 10-1F */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,  /* 20-2F */        52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,  /* 30-3F */        -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,  /* 40-4F */        15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,  /* 50-5F */        -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,  /* 60-6F */        41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,  /* 70-7F */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* 80-8F */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* 90-9F */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* A0-AF */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* B0-BF */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* C0-CF */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* D0-DF */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  /* E0-EF */        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1   /* F0-FF */        };    for( i_level = 0; *src != '\0'; src++ )    {        int  c;        c = b64[(unsigned int)*src];        if( c == -1 )        {            continue;        }        switch( i_level )        {            case 0:                i_level++;                break;            case 1:                *dest++ = ( last << 2 ) | ( ( c >> 4)&0x03 );                i_level++;                break;            case 2:                *dest++ = ( ( last << 4 )&0xf0 ) | ( ( c >> 2 )&0x0f );                i_level++;                break;            case 3:                *dest++ = ( ( last &0x03 ) << 6 ) | c;                i_level = 0;        }        last = c;    }    *dest = '\0';    return dest - dest_start;}

⌨️ 快捷键说明

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