?? real.c
字號(hào):
/***************************************************************************** * real.c: Real demuxer. ***************************************************************************** * Copyright (C) 2004, 2006-2007 the VideoLAN team * $Id$ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//** * Status of this demuxer: * Real Media format * ----------------- * * version v3 w/ 14_4/lpcJ is ok. * version v4/5: - atrac3 is ok. * - cook is ok. * - raac, racp are ok. * - dnet is twisted "The byte order of the data is reversed * from standard AC3" * - 28_8 seem problematic. * - sipr should be fine, but our decoder suxx :) * - ralf is unsupported, but hardly any sample exist. * - mp3 is unsupported, one sample exists... * * Real Audio Only * --------------- * v3 and v4/5 headers are parsed. * Doesn't work yet... *//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_demux.h>#include <vlc_charset.h>#include <vlc_meta.h>/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close ( vlc_object_t * );vlc_module_begin(); set_description( N_("Real demuxer" ) ); set_capability( "demux", 15 ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_DEMUX ); set_callbacks( Open, Close ); add_shortcut( "real" ); add_shortcut( "rm" );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/typedef struct{ int i_id; es_format_t fmt; es_out_id_t *p_es; int i_frame; block_t *p_frame; int i_subpacket_h; int i_subpacket_size; int i_coded_frame_size; int i_frame_size; int i_subpacket; int i_subpackets; block_t **p_subpackets; int64_t *p_subpackets_timecode; int i_out_subpacket;} real_track_t;typedef struct{ uint32_t file_offset; uint32_t time_offset; uint32_t frame_index;} rm_index_t;struct demux_sys_t{ int64_t i_data_offset; int64_t i_data_size; uint32_t i_data_packets_count; uint32_t i_data_packets; int64_t i_data_offset_next; bool b_is_real_audio; int i_our_duration; int i_mux_rate; char* psz_title; char* psz_artist; char* psz_copyright; char* psz_description; int i_track; real_track_t **track; uint8_t buffer[65536]; int64_t i_pcr; vlc_meta_t *p_meta; int64_t i_index_offset; int b_seek; rm_index_t *p_index;};static int Demux( demux_t *p_demux );static int Control( demux_t *p_demux, int i_query, va_list args );static int HeaderRead( demux_t *p_demux );static const uint8_t * MetaRead( demux_t *p_demux, const uint8_t *p_peek );static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num );/***************************************************************************** * Open *****************************************************************************/static int Open( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; bool b_is_real_audio = false; if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) return VLC_EGENERIC; /* Real Audio */ if( !memcmp( p_peek, ".ra", 3 ) ) { msg_Err( p_demux, ".ra files unsuported" ); b_is_real_audio = true; } /* Real Media Format */ else if( memcmp( p_peek, ".RMF", 4 ) ) return VLC_EGENERIC; /* Fill p_demux field */ p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; memset( p_sys, 0, sizeof( demux_sys_t ) ); p_sys->i_data_offset = 0; p_sys->i_track = 0; p_sys->track = NULL; p_sys->i_pcr = 1; p_sys->b_seek = 0; p_sys->b_is_real_audio = b_is_real_audio; /* Parse the headers */ /* Real Audio files */ if( b_is_real_audio ) { ReadCodecSpecificData( p_demux, 32, 0 ); /* At least 32 */ return VLC_EGENERIC; /* We don't know how to read correctly the data yet */ } /* RMF files */ else if( HeaderRead( p_demux ) ) { int i; msg_Err( p_demux, "invalid header" ); for( i = 0; i < p_sys->i_track; i++ ) { real_track_t *tk = p_sys->track[i]; if( tk->p_es ) { es_out_Del( p_demux->out, tk->p_es ); } free( tk ); } if( p_sys->i_track > 0 ) { free( p_sys->track ); } free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS;}/***************************************************************************** * Close *****************************************************************************/static void Close( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; int i; for( i = 0; i < p_sys->i_track; i++ ) { real_track_t *tk = p_sys->track[i]; int j = tk->i_subpackets; if( tk->p_frame ) block_Release( tk->p_frame ); es_format_Clean( &tk->fmt ); while( j-- ) { if( tk->p_subpackets[ j ] ) block_Release( tk->p_subpackets[ j ] ); } if( tk->i_subpackets ) { free( tk->p_subpackets ); free( tk->p_subpackets_timecode ); } free( tk ); } free( p_sys->psz_title ); free( p_sys->psz_artist ); free( p_sys->psz_copyright ); free( p_sys->psz_description ); free( p_sys->p_index ); if( p_sys->i_track > 0 ) free( p_sys->track ); free( p_sys );}/***************************************************************************** * Demux: *****************************************************************************/static int Demux( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; uint8_t header[18]; int i_id, i_flags, i; unsigned int i_size; int64_t i_pts; real_track_t *tk = NULL; bool b_selected; if( p_sys->i_data_packets >= p_sys->i_data_packets_count && p_sys->i_data_packets_count ) { if( stream_Read( p_demux->s, header, 18 ) < 18 ) { return 0; } if( strncmp( (char *)header, "DATA", 4 ) ) { return 0; } p_sys->i_data_offset = stream_Tell( p_demux->s ) - 18; p_sys->i_data_size = GetDWBE( &header[4] ); p_sys->i_data_packets_count = GetDWBE( &header[10] ); p_sys->i_data_packets = 0; p_sys->i_data_offset_next = GetDWBE( &header[14] ); msg_Dbg( p_demux, "entering new DATA packets=%d next=%u", p_sys->i_data_packets_count, (uint32_t)p_sys->i_data_offset_next ); } if( stream_Read( p_demux->s, header, 12 ) < 12 ) return 0; // int i_version = GetWBE( &header[0] ); i_size = GetWBE( &header[2] ) - 12; i_id = GetWBE( &header[4] ); i_pts = 1000 * GetDWBE( &header[6] ); i_pts += 1000; /* Avoid 0 pts */ i_flags= header[11]; /* flags 0x02 -> keyframe */ msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u", p_sys->i_data_packets, i_size, i_id, (uint32_t)(i_pts/1000) ); p_sys->i_data_packets++; if( i_size == 0 ) { msg_Err( p_demux, "Got a NUKK size to read. (Invalid format?)" ); return 1; } if( i_size > sizeof(p_sys->buffer) ) { msg_Err( p_demux, "Got a size to read bigger than our buffer. (Invalid format?)" ); return 1; } stream_Read( p_demux->s, p_sys->buffer, i_size ); for( i = 0; i < p_sys->i_track; i++ ) { if( p_sys->track[i]->i_id == i_id ) tk = p_sys->track[i]; } if( tk == NULL ) { msg_Warn( p_demux, "unknown track id(0x%x)", i_id ); return 1; } es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b_selected ); if( tk->fmt.i_cat == VIDEO_ES && b_selected ) { uint8_t *p = p_sys->buffer; while( p < &p_sys->buffer[i_size - 2] ) { uint8_t h = *p++; int i_len = 0; int i_copy; int i_subseq = 0; int i_seqnum = 0; int i_offset = 0; if( (h&0xc0) == 0x40 ) { /* Short header */ p++; i_len = &p_sys->buffer[i_size] - p; } else { if( (h&0x40) == 0 ) { i_subseq = (*p++)&0x7f; } i_len = (p[0] << 8)|p[1]; p += 2; if( (i_len&0xc000) == 0 ) { i_len <<= 16; i_len |= (p[0] << 8)|p[1]; p += 2; i_len &= 0x3fffffff; } else { i_len &= 0x3fff; } i_offset = (p[0] << 8)|p[1]; p += 2; if( (i_offset&0xc000) == 0 ) { i_offset <<= 16; i_offset |= (p[0] << 8)|p[1]; p += 2; i_offset &= 0x3fffffff; } else { i_offset &= 0x3fff; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -