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

📄 live555.cpp

📁 VLC Player Source Code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    //msg_Dbg( p_demux, "pts: %d", pts.tv_sec );    int64_t i_pts = (int64_t)pts.tv_sec * INT64_C(1000000) +        (int64_t)pts.tv_usec;    /* XXX Beurk beurk beurk Avoid having negative value XXX */    i_pts &= INT64_C(0x00ffffffffffffff);    /* Retrieve NPT for this pts */    tk->i_npt = (int64_t) INT64_C(1000000) * tk->sub->getNormalPlayTime(pts);    if( tk->b_quicktime && tk->p_es == NULL )    {        QuickTimeGenericRTPSource *qtRTPSource =            (QuickTimeGenericRTPSource*)tk->sub->rtpSource();        QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;        uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];        if( tk->fmt.i_cat == VIDEO_ES ) {            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 int atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3];                    if( atomLength == 0 || atomLength > (unsigned int)(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 );            }        }        else {            if( qtState.sdAtomSize < 4 )            {                /* invalid */                p_sys->event = 0xff;                tk->waiting = 0;                return;            }            tk->fmt.i_codec = VLC_FOURCC(sdAtom[0],sdAtom[1],sdAtom[2],sdAtom[3]);        }        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->sub->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') )    {        H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->sub->rtpSource();        uint32_t header = h261Source->lastSpecialHeader();        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->sub->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( p_sys->i_pcr < i_pts )    {        p_sys->i_pcr = i_pts;    }    if( (i_pts != tk->i_pts) && (!tk->b_muxed) )    {        p_block->i_pts = i_pts;    }    /* Update our global npt value */    if( tk->i_npt > 0 && tk->i_npt > p_sys->i_npt && tk->i_npt < p_sys->i_npt_length)        p_sys->i_npt = tk->i_npt;     if( !tk->b_muxed )    {        /*FIXME: for h264 you should check that packetization-mode=1 in sdp-file */        p_block->i_dts = ( tk->fmt.i_codec == VLC_FOURCC( 'm', 'p', 'g', 'v' ) ) ? 0 : 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 = 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 = 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( vlc_object_t * p_this ){    timeout_thread_t *p_timeout = (timeout_thread_t *)p_this;    p_timeout->b_die = 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( vlc_object_alive (p_timeout) )    {        if( p_timeout->i_remain <= 0 )        {            char *psz_bye = NULL;            p_timeout->i_remain = (int64_t)p_timeout->p_sys->i_timeout -2;            p_timeout->i_remain *= 1000000;            msg_Dbg( p_timeout, "reset the timeout timer" );            if( p_timeout->b_handle_keep_alive == true )            {                p_timeout->p_sys->rtsp->getMediaSessionParameter( *p_timeout->p_sys->ms, NULL, psz_bye );                p_timeout->p_sys->b_timeout_call = false;            }            else            {                p_timeout->p_sys->b_timeout_call = true;            }        }        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 */    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;}static 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;    }    free( dup );    return cfg;}/*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 */        -

⌨️ 快捷键说明

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