📄 avi.c
字号:
{ return VLC_EGENERIC; } if( p_stream->i_cat == AUDIO_ES ) { unsigned int i; tk->i_blockno = 0; for( i = 0; i < tk->i_idxposc; i++ ) { if( tk->i_blocksize > 0 ) { tk->i_blockno += ( tk->p_index[i].i_length + tk->i_blocksize - 1 ) / tk->i_blocksize; } else { tk->i_blockno++; } } } msg_Dbg( p_demux, "old:"I64Fd" %s new "I64Fd, i_oldpts, i_oldpts > i_date ? ">" : "<", i_date ); if( p_stream->i_cat == VIDEO_ES ) { /* search key frame */ if( i_date < i_oldpts ) { while( p_stream->i_idxposc > 0 && !( p_stream->p_index[p_stream->i_idxposc].i_flags & AVIIF_KEYFRAME ) ) { if( AVI_StreamChunkSet( p_demux, i_stream, p_stream->i_idxposc - 1 ) ) { return VLC_EGENERIC; } } } else { while( p_stream->i_idxposc < p_stream->i_idxnb && !( p_stream->p_index[p_stream->i_idxposc].i_flags & AVIIF_KEYFRAME ) ) { if( AVI_StreamChunkSet( p_demux, i_stream, p_stream->i_idxposc + 1 ) ) { return VLC_EGENERIC; } } } } } else { if( AVI_StreamBytesSet( p_demux, i_stream, AVI_PTSToByte( p_stream, i_date ) ) ) { return VLC_EGENERIC; } } return VLC_SUCCESS;#undef p_stream}/**************************************************************************** * Return VLC_TRUE if it's a key frame ****************************************************************************/static int AVI_GetKeyFlag( vlc_fourcc_t i_fourcc, uint8_t *p_byte ){ switch( i_fourcc ) { case FOURCC_DIV1: /* we have: * startcode: 0x00000100 32bits * framenumber ? 5bits * piture type 0(I),1(P) 2bits */ if( GetDWBE( p_byte ) != 0x00000100 ) { /* it's not an msmpegv1 stream, strange...*/ return AVIIF_KEYFRAME; } return p_byte[4] & 0x06 ? 0 : AVIIF_KEYFRAME; case FOURCC_DIV2: case FOURCC_DIV3: /* wmv1 also */ /* we have * picture type 0(I),1(P) 2bits */ return p_byte[0] & 0xC0 ? 0 : AVIIF_KEYFRAME; case FOURCC_mp4v: /* we should find first occurrence of 0x000001b6 (32bits) * startcode: 0x000001b6 32bits * piture type 0(I),1(P) 2bits */ if( GetDWBE( p_byte ) != 0x000001b6 ) { /* not true , need to find the first VOP header */ return AVIIF_KEYFRAME; } return p_byte[4] & 0xC0 ? 0 : AVIIF_KEYFRAME; default: /* I can't do it, so say yes */ return AVIIF_KEYFRAME; }}vlc_fourcc_t AVI_FourccGetCodec( unsigned int i_cat, vlc_fourcc_t i_codec ){ switch( i_cat ) { case AUDIO_ES: wf_tag_to_fourcc( i_codec, &i_codec, NULL ); return i_codec; case VIDEO_ES: /* XXX DIV1 <- msmpeg4v1, DIV2 <- msmpeg4v2, DIV3 <- msmpeg4v3, mp4v for mpeg4 */ switch( i_codec ) { case FOURCC_1: return VLC_FOURCC('m','r','l','e'); case FOURCC_DIV1: case FOURCC_div1: case FOURCC_MPG4: case FOURCC_mpg4: return FOURCC_DIV1; case FOURCC_DIV2: case FOURCC_div2: case FOURCC_MP42: case FOURCC_mp42: case FOURCC_MPG3: case FOURCC_mpg3: return FOURCC_DIV2; case FOURCC_div3: case FOURCC_MP43: case FOURCC_mp43: case FOURCC_DIV3: case FOURCC_DIV4: case FOURCC_div4: case FOURCC_DIV5: case FOURCC_div5: case FOURCC_DIV6: case FOURCC_div6: case FOURCC_AP41: case FOURCC_3IV1: case FOURCC_3iv1: case FOURCC_3IVD: case FOURCC_3ivd: case FOURCC_3VID: case FOURCC_3vid: return FOURCC_DIV3; case FOURCC_DIVX: case FOURCC_divx: case FOURCC_MP4S: case FOURCC_mp4s: case FOURCC_M4S2: case FOURCC_m4s2: case FOURCC_xvid: case FOURCC_XVID: case FOURCC_XviD: case FOURCC_DX50: case FOURCC_dx50: case FOURCC_mp4v: case FOURCC_4: case FOURCC_3IV2: case FOURCC_3iv2: return FOURCC_mp4v; } default: return VLC_FOURCC( 'u', 'n', 'd', 'f' ); }}/**************************************************************************** * ****************************************************************************/static void AVI_ParseStreamHeader( vlc_fourcc_t i_id, unsigned int *pi_number, unsigned int *pi_type ){#define SET_PTR( p, v ) if( p ) *(p) = (v); int c1, c2; c1 = ((uint8_t *)&i_id)[0]; c2 = ((uint8_t *)&i_id)[1]; if( c1 < '0' || c1 > '9' || c2 < '0' || c2 > '9' ) { SET_PTR( pi_number, 100 ); /* > max stream number */ SET_PTR( pi_type, UNKNOWN_ES ); } else { SET_PTR( pi_number, (c1 - '0') * 10 + (c2 - '0' ) ); switch( VLC_TWOCC( ((uint8_t *)&i_id)[2], ((uint8_t *)&i_id)[3] ) ) { case AVITWOCC_wb: SET_PTR( pi_type, AUDIO_ES ); break; case AVITWOCC_dc: case AVITWOCC_db: SET_PTR( pi_type, VIDEO_ES ); break; default: SET_PTR( pi_type, UNKNOWN_ES ); break; } }#undef SET_PTR}/**************************************************************************** * ****************************************************************************/static int AVI_PacketGetHeader( demux_t *p_demux, avi_packet_t *p_pk ){ uint8_t *p_peek; if( stream_Peek( p_demux->s, &p_peek, 16 ) < 16 ) { return VLC_EGENERIC; } p_pk->i_fourcc = VLC_FOURCC( p_peek[0], p_peek[1], p_peek[2], p_peek[3] ); p_pk->i_size = GetDWLE( p_peek + 4 ); p_pk->i_pos = stream_Tell( p_demux->s ); if( p_pk->i_fourcc == AVIFOURCC_LIST || p_pk->i_fourcc == AVIFOURCC_RIFF ) { p_pk->i_type = VLC_FOURCC( p_peek[8], p_peek[9], p_peek[10], p_peek[11] ); } else { p_pk->i_type = 0; } memcpy( p_pk->i_peek, p_peek + 8, 8 ); AVI_ParseStreamHeader( p_pk->i_fourcc, &p_pk->i_stream, &p_pk->i_cat ); return VLC_SUCCESS;}static int AVI_PacketNext( demux_t *p_demux ){ avi_packet_t avi_ck; int i_skip = 0; if( AVI_PacketGetHeader( p_demux, &avi_ck ) ) { return VLC_EGENERIC; } if( avi_ck.i_fourcc == AVIFOURCC_LIST && ( avi_ck.i_type == AVIFOURCC_rec || avi_ck.i_type == AVIFOURCC_movi ) ) { i_skip = 12; } else if( avi_ck.i_fourcc == AVIFOURCC_RIFF && avi_ck.i_type == AVIFOURCC_AVIX ) { i_skip = 24; } else { i_skip = __EVEN( avi_ck.i_size ) + 8; } if( stream_Read( p_demux->s, NULL, i_skip ) != i_skip ) { return VLC_EGENERIC; } return VLC_SUCCESS;}static int AVI_PacketRead( demux_t *p_demux, avi_packet_t *p_pk, block_t **pp_frame ){ size_t i_size; i_size = __EVEN( p_pk->i_size + 8 ); if( ( *pp_frame = stream_Block( p_demux->s, i_size ) ) == NULL ) { return VLC_EGENERIC; } (*pp_frame)->p_buffer += 8; (*pp_frame)->i_buffer -= 8; if( i_size != p_pk->i_size + 8 ) { (*pp_frame)->i_buffer--; } return VLC_SUCCESS;}static int AVI_PacketSearch( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; avi_packet_t avi_pk; int i_count = 0; for( ;; ) { if( stream_Read( p_demux->s, NULL, 1 ) != 1 ) { return VLC_EGENERIC; } AVI_PacketGetHeader( p_demux, &avi_pk ); if( avi_pk.i_stream < p_sys->i_track && ( avi_pk.i_cat == AUDIO_ES || avi_pk.i_cat == VIDEO_ES ) ) { return VLC_SUCCESS; } switch( avi_pk.i_fourcc ) { case AVIFOURCC_JUNK: case AVIFOURCC_LIST: case AVIFOURCC_RIFF: case AVIFOURCC_idx1: return VLC_SUCCESS; } /* Prevents from eating all the CPU with broken files. * This value should be low enough so that it doesn't affect the * reading speed too much (not that we care much anyway because * this code is called only on broken files). */ if( !(++i_count % 1024) ) { if( p_demux->b_die ) return VLC_EGENERIC; msleep( 10000 ); if( !(i_count % (1024 * 10)) ) msg_Warn( p_demux, "trying to resync..." ); } }}/**************************************************************************** * Index stuff. ****************************************************************************/static void AVI_IndexAddEntry( demux_sys_t *p_sys, int i_stream, avi_entry_t *p_index){ avi_track_t *tk = p_sys->track[i_stream]; /* Update i_movi_lastchunk_pos */ if( p_sys->i_movi_lastchunk_pos < p_index->i_pos ) { p_sys->i_movi_lastchunk_pos = p_index->i_pos; } /* add the entry */ if( tk->i_idxnb >= tk->i_idxmax ) { tk->i_idxmax += 16384; tk->p_index = realloc( tk->p_index, tk->i_idxmax * sizeof( avi_entry_t ) ); if( tk->p_index == NULL ) { return; } } /* calculate cumulate length */ if( tk->i_idxnb > 0 ) { p_index->i_lengthtotal = tk->p_index[tk->i_idxnb - 1].i_length + tk->p_index[tk->i_idxnb - 1].i_lengthtotal; } else { p_index->i_lengthtotal = 0; } tk->p_index[tk->i_idxnb++] = *p_index;}static int AVI_IndexLoad_idx1( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; avi_chunk_list_t *p_riff; avi_chunk_list_t *p_movi; avi_chunk_idx1_t *p_idx1; unsigned int i_stream; unsigned int i_index; off_t i_offset; unsigned int i; vlc_bool_t b_keyset[100]; p_riff = AVI_ChunkFind( &p_sys->ck_root, AVIFOURCC_RIFF, 0); p_idx1 = AVI_ChunkFind( p_riff, AVIFOURCC_idx1, 0); p_movi = AVI_ChunkFind( p_riff, AVIFOURCC_movi, 0); if( !p_idx1 ) { msg_Warn( p_demux, "cannot find idx1 chunk, no index defined" )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -