/*****************************************************************************
* avi.c : AVI file Stream input module for vlc
*****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2001-2004 the VideoLAN team
* $Id$
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+
+#include <vlc_dialog.h>
-#include "vlc_meta.h"
-#include "codecs.h"
+#include <vlc_meta.h>
+#include <vlc_codecs.h>
+#include <vlc_charset.h>
#include "libavi.h"
*****************************************************************************/
#define INTERLEAVE_TEXT N_("Force interleaved method" )
-#define INTERLEAVE_LONGTEXT N_( "Force interleaved method" )
+#define INTERLEAVE_LONGTEXT N_( "Force interleaved method." )
#define INDEX_TEXT N_("Force index creation")
#define INDEX_LONGTEXT N_( \
- "Recreate a index for the AVI file so we can seek trough it more reliably." )
+ "Recreate a index for the AVI file. Use this if your AVI file is damaged "\
+ "or incomplete (not seekable)." )
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
-vlc_module_begin();
- set_shortname( "AVI" );
- set_description( _("AVI demuxer") );
- set_capability( "demux2", 212 );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_DEMUX );
+static const int pi_index[] = {0,1,2};
+
+static const char *const ppsz_indexes[] = { N_("Ask"), N_("Always fix"),
+ N_("Never fix") };
+
+vlc_module_begin ()
+ set_shortname( "AVI" )
+ set_description( N_("AVI demuxer") )
+ set_capability( "demux", 212 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
add_bool( "avi-interleaved", 0, NULL,
- INTERLEAVE_TEXT, INTERLEAVE_LONGTEXT, VLC_TRUE );
- add_bool( "avi-index", 0, NULL,
- INDEX_TEXT, INDEX_LONGTEXT, VLC_TRUE );
+ INTERLEAVE_TEXT, INTERLEAVE_LONGTEXT, true )
+ add_integer( "avi-index", 0, NULL,
+ INDEX_TEXT, INDEX_LONGTEXT, false )
+ change_integer_list( pi_index, ppsz_indexes, NULL )
- set_callbacks( Open, Close );
-vlc_module_end();
+ set_callbacks( Open, Close )
+vlc_module_end ()
/*****************************************************************************
* Local prototypes
static int Demux_Seekable ( demux_t * );
static int Demux_UnSeekable( demux_t * );
-#define FREE( p ) if( p ) { free( p ); (p) = NULL; }
#define __ABS( x ) ( (x) < 0 ? (-(x)) : (x) )
typedef struct
uint32_t i_flags;
off_t i_pos;
uint32_t i_length;
- uint32_t i_lengthtotal;
+ int64_t i_lengthtotal;
} avi_entry_t;
typedef struct
{
- vlc_bool_t b_activated;
+ bool b_activated;
unsigned int i_cat; /* AUDIO_ES, VIDEO_ES */
vlc_fourcc_t i_codec;
es_out_id_t *p_es;
+ /* Avi Index */
avi_entry_t *p_index;
- unsigned int i_idxnb;
- unsigned int i_idxmax;
+ unsigned int i_idxnb;
+ unsigned int i_idxmax;
- unsigned int i_idxposc; /* numero of chunk */
- unsigned int i_idxposb; /* byte in the current chunk */
+ unsigned int i_idxposc; /* numero of chunk */
+ unsigned int i_idxposb; /* byte in the current chunk */
+
+ /* extra information given to the decoder */
+ void *p_extra;
/* For VBR audio only */
- unsigned int i_blockno;
- unsigned int i_blocksize;
+ unsigned int i_blockno;
+ unsigned int i_blocksize;
+
+ /* For muxed streams */
+ stream_t *p_out_muxed;
} avi_track_t;
struct demux_sys_t
mtime_t i_time;
mtime_t i_length;
- vlc_bool_t b_seekable;
+ bool b_seekable;
+ bool b_muxed;
avi_chunk_t ck_root;
- vlc_bool_t b_odml;
+ bool b_odml;
off_t i_movi_begin;
off_t i_movi_lastchunk_pos; /* XXX position of last valid chunk */
demux_t *p_demux = (demux_t *)p_this;
demux_sys_t *p_sys;
+ bool b_index = false;
+ int i_do_index;
+
avi_chunk_t ck_riff;
avi_chunk_list_t *p_riff = (avi_chunk_list_t*)&ck_riff;
avi_chunk_list_t *p_hdrl, *p_movi;
unsigned int i_track;
unsigned int i, i_peeker;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
/* Is it an avi file ? */
if( stream_Peek( p_demux->s, &p_peek, 200 ) < 200 ) return VLC_EGENERIC;
for( i_peeker = 0; i_peeker < 188; i_peeker++ )
{
- if( !strncmp( &p_peek[0], "RIFF", 4 ) &&
- !strncmp( &p_peek[8], "AVI ", 4 ) ) break;
+ if( !strncmp( (char *)&p_peek[0], "RIFF", 4 ) && !strncmp( (char *)&p_peek[8], "AVI ", 4 ) )
+ break;
+ if( !strncmp( (char *)&p_peek[0], "ON2 ", 4 ) && !strncmp( (char *)&p_peek[8], "ON2f", 4 ) )
+ break;
p_peek++;
}
if( i_peeker == 188 )
p_sys->i_time = 0;
p_sys->i_length = 0;
p_sys->i_movi_lastchunk_pos = 0;
- p_sys->b_odml = VLC_FALSE;
+ p_sys->b_odml = false;
+ p_sys->b_muxed = false;
p_sys->i_track = 0;
p_sys->track = NULL;
p_sys->meta = NULL;
p_demux->pf_control = Control;
p_demux->pf_demux = Demux_Seekable;
+
/* For unseekable stream, automaticaly use Demux_UnSeekable */
if( !p_sys->b_seekable || config_GetInt( p_demux, "avi-interleaved" ) )
{
if( i_peeker > 0 )
{
- stream_Read( p_demux->s, NULL, i_peeker );
+ stream_Read( p_demux->s, NULL, i_peeker );
}
if( AVI_ChunkReadRoot( p_demux->s, &p_sys->ck_root ) )
if( p_sysx->i_type == AVIFOURCC_AVIX )
{
msg_Warn( p_demux, "detected OpenDML file" );
- p_sys->b_odml = VLC_TRUE;
+ p_sys->b_odml = true;
break;
}
}
if( ( p_sys->meta = vlc_meta_New() ) )
{
char buffer[200];
- sprintf( buffer, "%s%s%s%s",
- p_avih->i_flags&AVIF_HASINDEX?" HAS_INDEX":"",
- p_avih->i_flags&AVIF_MUSTUSEINDEX?" MUST_USE_INDEX":"",
- p_avih->i_flags&AVIF_ISINTERLEAVED?" IS_INTERLEAVED":"",
- p_avih->i_flags&AVIF_TRUSTCKTYPE?" TRUST_CKTYPE":"" );
- vlc_meta_Add( p_sys->meta, VLC_META_SETTING, buffer );
+ snprintf( buffer, sizeof(buffer), "%s%s%s%s",
+ p_avih->i_flags&AVIF_HASINDEX?" HAS_INDEX":"",
+ p_avih->i_flags&AVIF_MUSTUSEINDEX?" MUST_USE_INDEX":"",
+ p_avih->i_flags&AVIF_ISINTERLEAVED?" IS_INTERLEAVED":"",
+ p_avih->i_flags&AVIF_TRUSTCKTYPE?" TRUST_CKTYPE":"" );
+ vlc_meta_SetSetting( p_sys->meta, buffer );
}
/* now read info on each stream and create ES */
for( i = 0 ; i < i_track; i++ )
{
- avi_track_t *tk = malloc( sizeof( avi_track_t ) );
- avi_chunk_list_t *p_strl = AVI_ChunkFind( p_hdrl, AVIFOURCC_strl, i );
- avi_chunk_strh_t *p_strh = AVI_ChunkFind( p_strl, AVIFOURCC_strh, 0 );
- avi_chunk_STRING_t *p_strn = AVI_ChunkFind( p_strl, AVIFOURCC_strn, 0 );
- avi_chunk_strf_auds_t *p_auds;
- avi_chunk_strf_vids_t *p_vids;
- es_format_t fmt;
+ avi_track_t *tk = malloc( sizeof( avi_track_t ) );
+ if( !tk )
+ goto error;
- tk->b_activated = VLC_FALSE;
- tk->p_index = 0;
- tk->i_idxnb = 0;
- tk->i_idxmax = 0;
- tk->i_idxposc = 0;
- tk->i_idxposb = 0;
+ avi_chunk_list_t *p_strl = AVI_ChunkFind( p_hdrl, AVIFOURCC_strl, i );
+ avi_chunk_strh_t *p_strh = AVI_ChunkFind( p_strl, AVIFOURCC_strh, 0 );
+ avi_chunk_STRING_t *p_strn = AVI_ChunkFind( p_strl, AVIFOURCC_strn, 0 );
+ avi_chunk_strf_auds_t *p_auds = NULL;
+ avi_chunk_strf_vids_t *p_vids = NULL;
+ es_format_t fmt;
- tk->i_blockno = 0;
- tk->i_blocksize = 0;
+ memset( tk, 0, sizeof( avi_track_t ) );
p_vids = (avi_chunk_strf_vids_t*)AVI_ChunkFind( p_strl, AVIFOURCC_strf, 0 );
p_auds = (avi_chunk_strf_auds_t*)AVI_ChunkFind( p_strl, AVIFOURCC_strf, 0 );
if( p_strl == NULL || p_strh == NULL || p_auds == NULL || p_vids == NULL )
{
msg_Warn( p_demux, "stream[%d] incomplete", i );
+ free( tk );
continue;
}
tk->i_cat = AUDIO_ES;
tk->i_codec = AVI_FourccGetCodec( AUDIO_ES,
p_auds->p_wf->wFormatTag );
- if( ( tk->i_blocksize = p_auds->p_wf->nBlockAlign ) == 0 )
+
+ tk->i_blocksize = p_auds->p_wf->nBlockAlign;
+ if( tk->i_blocksize == 0 )
{
if( p_auds->p_wf->wFormatTag == 1 )
- {
tk->i_blocksize = p_auds->p_wf->nChannels * (p_auds->p_wf->wBitsPerSample/8);
- }
else
- {
tk->i_blocksize = 1;
- }
}
+ else if( tk->i_samplesize != 0 && tk->i_samplesize != tk->i_blocksize )
+ {
+ msg_Warn( p_demux, "track[%d] samplesize=%d and blocksize=%d are not equal."
+ "Using blocksize as a workaround.",
+ i, tk->i_samplesize, tk->i_blocksize );
+ tk->i_samplesize = tk->i_blocksize;
+ }
+
+ if( tk->i_codec == VLC_CODEC_VORBIS )
+ {
+ tk->i_blocksize = 0; /* fix vorbis VBR decoding */
+ }
+
es_format_Init( &fmt, AUDIO_ES, tk->i_codec );
fmt.audio.i_channels = p_auds->p_wf->nChannels;
fmt.i_bitrate = p_auds->p_wf->nAvgBytesPerSec*8;
fmt.audio.i_blockalign = p_auds->p_wf->nBlockAlign;
fmt.audio.i_bitspersample = p_auds->p_wf->wBitsPerSample;
+ fmt.b_packetized = !tk->i_blocksize;
+
+ msg_Dbg( p_demux,
+ "stream[%d] audio(0x%x) %d channels %dHz %dbits",
+ i, p_auds->p_wf->wFormatTag, p_auds->p_wf->nChannels,
+ p_auds->p_wf->nSamplesPerSec,
+ p_auds->p_wf->wBitsPerSample );
+
fmt.i_extra = __MIN( p_auds->p_wf->cbSize,
p_auds->i_chunk_size - sizeof(WAVEFORMATEX) );
- fmt.p_extra = &p_auds->p_wf[1];
- msg_Dbg( p_demux, "stream[%d] audio(0x%x) %d channels %dHz %dbits",
- i, p_auds->p_wf->wFormatTag, p_auds->p_wf->nChannels,
- p_auds->p_wf->nSamplesPerSec, p_auds->p_wf->wBitsPerSample);
+ fmt.p_extra = tk->p_extra = malloc( fmt.i_extra );
+ if( !fmt.p_extra ) goto error;
+ memcpy( fmt.p_extra, &p_auds->p_wf[1], fmt.i_extra );
+
+ /* Rewrite the vorbis headers from Xiph-like format
+ * to VLC internal format
+ *
+ * Xiph format:
+ * - 1st byte == N, is the number of packets - 1
+ * - Following bytes are the size of the N first packets:
+ * while( *p == 0xFF ) { size += 0xFF; p++ } size += *p;
+ * (the size of the last packet is the size of remaining
+ * data in the buffer)
+ * - Finally, all the packets concatenated
+ *
+ * VLC format:
+ * - Size of the packet on 16 bits (big endian) FIXME: should be 32 bits to be safe
+ * - The packet itself
+ * - Size of the next packet, and so on ...
+ */
+
+ if( tk->i_codec == VLC_CODEC_VORBIS )
+ {
+ uint8_t *p_extra = fmt.p_extra;
+ size_t i_extra = fmt.i_extra;
+
+ if( i_extra <= 1 ) break;
+ if( *p_extra++ != 2 ) break; /* 3 packets - 1 = 2 */
+ i_extra--;
+
+ size_t i_identifier_len = 0;
+ while( *p_extra == 0xFF )
+ {
+ i_identifier_len += 0xFF;
+ p_extra++;
+ if( --i_extra <= 1 ) break;
+ }
+ i_identifier_len += *p_extra++;
+ if( i_identifier_len > --i_extra ) break;
+
+ size_t i_comment_len = 0;
+ while( *p_extra == 0xFF )
+ {
+ i_comment_len += 0xFF;
+ p_extra++;
+ if( --i_extra <= 1 ) break;
+ }
+ i_comment_len += *p_extra++;
+ if( i_comment_len > --i_extra ) break;
+ size_t i_cookbook_len = i_extra;
+
+ size_t i_headers_size = 3 * 2 + i_identifier_len +
+ i_comment_len + i_cookbook_len;
+ uint8_t *p_out = malloc( i_headers_size );
+ if( !p_out ) goto error;
+ free( fmt.p_extra );
+ fmt.p_extra = tk->p_extra = p_out;
+ fmt.i_extra = i_headers_size;
+ #define copy_packet( len ) \
+ *p_out++ = len >> 8; \
+ *p_out++ = len & 0xFF; \
+ memcpy( p_out, p_extra, len ); \
+ p_out += len; \
+ p_extra += len;
+ copy_packet( i_identifier_len );
+ copy_packet( i_comment_len );
+ copy_packet( i_cookbook_len );
+ #undef copy_packet
+ break;
+ }
break;
case( AVIFOURCC_vids ):
tk->i_cat = VIDEO_ES;
tk->i_codec = AVI_FourccGetCodec( VIDEO_ES,
p_vids->p_bih->biCompression );
- if( p_vids->p_bih->biCompression == 0x00 )
+ if( p_vids->p_bih->biCompression == VLC_FOURCC( 'D', 'X', 'S', 'B' ) )
+ {
+ msg_Dbg( p_demux, "stream[%d] subtitles", i );
+ es_format_Init( &fmt, SPU_ES, p_vids->p_bih->biCompression );
+ break;
+ }
+ else if( p_vids->p_bih->biCompression == 0x00 )
{
switch( p_vids->p_bih->biBitCount )
{
case 32:
- tk->i_codec = VLC_FOURCC('R','V','3','2');
+ tk->i_codec = VLC_CODEC_RGB32;
break;
case 24:
- tk->i_codec = VLC_FOURCC('R','V','2','4');
+ tk->i_codec = VLC_CODEC_RGB24;
break;
- case 16:
- /* tk->i_codec = VLC_FOURCC('R','V','1','6');*/
- /* break;*/
+ case 16: /* Yes it is RV15 */
case 15:
- tk->i_codec = VLC_FOURCC('R','V','1','5');
+ tk->i_codec = VLC_CODEC_RGB15;
break;
- case 9:
- tk->i_codec = VLC_FOURCC( 'Y', 'V', 'U', '9' ); /* <- TODO check that */
+ case 9: /* <- TODO check that */
+ tk->i_codec = VLC_CODEC_I410;
+ break;
+ case 8: /* <- TODO check that */
+ tk->i_codec = VLC_CODEC_GREY;
break;
}
es_format_Init( &fmt, VIDEO_ES, tk->i_codec );
- if( p_vids->p_bih->biBitCount == 24 )
+ switch( tk->i_codec )
{
- /* This is in BGR format */
- fmt.video.i_bmask = 0x00ff0000;
+ case VLC_CODEC_RGB24:
+ case VLC_CODEC_RGB32:
+ fmt.video.i_rmask = 0x00ff0000;
fmt.video.i_gmask = 0x0000ff00;
- fmt.video.i_rmask = 0x000000ff;
+ fmt.video.i_bmask = 0x000000ff;
+ break;
+ case VLC_CODEC_RGB15:
+ fmt.video.i_rmask = 0x7c00;
+ fmt.video.i_gmask = 0x03e0;
+ fmt.video.i_bmask = 0x001f;
+ break;
+ default:
+ break;
}
}
else
{
es_format_Init( &fmt, VIDEO_ES, p_vids->p_bih->biCompression );
- if( tk->i_codec == FOURCC_mp4v &&
+ if( tk->i_codec == VLC_CODEC_MP4V &&
!strncasecmp( (char*)&p_strh->i_handler, "XVID", 4 ) )
{
- fmt.i_codec = VLC_FOURCC( 'X', 'V', 'I', 'D' );
+ fmt.i_codec =
+ fmt.i_original_fourcc = VLC_FOURCC( 'X', 'V', 'I', 'D' );
}
}
tk->i_samplesize = 0;
__MIN( p_vids->p_bih->biSize - sizeof( BITMAPINFOHEADER ),
p_vids->i_chunk_size - sizeof(BITMAPINFOHEADER) );
fmt.p_extra = &p_vids->p_bih[1];
- msg_Dbg( p_demux, "stream[%d] video(%4.4s) %dx%d %dbpp %ffps",
+ msg_Dbg( p_demux, "stream[%d] video(%4.4s) %"PRIu32"x%"PRIu32" %dbpp %ffps",
i, (char*)&p_vids->p_bih->biCompression,
- p_vids->p_bih->biWidth,
- p_vids->p_bih->biHeight,
+ (uint32_t)p_vids->p_bih->biWidth,
+ (uint32_t)p_vids->p_bih->biHeight,
p_vids->p_bih->biBitCount,
(float)tk->i_rate/(float)tk->i_scale );
/* Extract palette from extradata if bpp <= 8
* (assumes that extradata contains only palette but appears
* to be true for all palettized codecs we support) */
- if( fmt.i_extra && fmt.video.i_bits_per_pixel <= 8 &&
- fmt.video.i_bits_per_pixel > 0 )
+ if( fmt.video.i_bits_per_pixel > 0 && fmt.video.i_bits_per_pixel <= 8 )
{
- int i;
-
- fmt.video.p_palette = calloc( sizeof(video_palette_t), 1 );
- fmt.video.p_palette->i_entries = 1;
+ /* The palette is not always included in biSize */
+ fmt.i_extra = p_vids->i_chunk_size - sizeof(BITMAPINFOHEADER);
+ if( fmt.i_extra > 0 )
+ {
+ const uint8_t *p_pal = fmt.p_extra;
- /* Apparently this is necessary. But why ? */
- fmt.i_extra =
- p_vids->i_chunk_size - sizeof(BITMAPINFOHEADER);
+ fmt.video.p_palette = calloc( 1, sizeof(video_palette_t) );
+ fmt.video.p_palette->i_entries = __MIN(fmt.i_extra/4, 256);
- for( i = 0; i < __MIN(fmt.i_extra/4, 256); i++ )
- {
- ((uint32_t *)&fmt.video.p_palette->palette[0][0])[i] =
- GetDWLE((uint32_t*)fmt.p_extra + i);
- }
+ for( int i = 0; i < fmt.video.p_palette->i_entries; i++ )
+ {
+ for( int j = 0; j < 4; j++ )
+ fmt.video.p_palette->palette[i][j] = p_pal[4*i+j];
+ }
+ }
}
-
break;
case( AVIFOURCC_txts):
tk->i_cat = SPU_ES;
- tk->i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
+ tk->i_codec = VLC_CODEC_SUBT;
msg_Dbg( p_demux, "stream[%d] subtitles", i );
es_format_Init( &fmt, SPU_ES, tk->i_codec );
break;
-
+
+ case( AVIFOURCC_iavs):
+ case( AVIFOURCC_ivas):
+ p_sys->b_muxed = true;
+ msg_Dbg( p_demux, "stream[%d] iavs with handler %4.4s", i, (char *)&p_strh->i_handler );
+ if( p_strh->i_handler == FOURCC_dvsd ||
+ p_strh->i_handler == FOURCC_dvhd ||
+ p_strh->i_handler == FOURCC_dvsl ||
+ p_strh->i_handler == FOURCC_dv25 ||
+ p_strh->i_handler == FOURCC_dv50 )
+ {
+ tk->p_out_muxed = stream_DemuxNew( p_demux, (char *)"rawdv", p_demux->out );
+ if( !tk->p_out_muxed )
+ msg_Err( p_demux, "could not load the DV parser" );
+ else break;
+ }
+ free( tk );
+ continue;
+
case( AVIFOURCC_mids):
msg_Dbg( p_demux, "stream[%d] midi is UNSUPPORTED", i );
+
default:
- msg_Warn( p_demux, "stream[%d] unknown type", i );
+ msg_Warn( p_demux, "stream[%d] unknown type %4.4s", i, (char *)&p_strh->i_type );
free( tk );
continue;
}
if( p_strn )
- {
- fmt.psz_description = strdup( p_strn->p_str );
- }
- tk->p_es = es_out_Add( p_demux->out, &fmt );
+ fmt.psz_description = FromLatin1( p_strn->p_str );
+ if( tk->p_out_muxed == NULL )
+ tk->p_es = es_out_Add( p_demux->out, &fmt );
TAB_APPEND( p_sys->i_track, p_sys->track, tk );
}
goto error;
}
- if( config_GetInt( p_demux, "avi-index" ) )
+ i_do_index = config_GetInt( p_demux, "avi-index" );
+ if( i_do_index == 1 ) /* Always fix */
{
+aviindex:
if( p_sys->b_seekable )
{
AVI_IndexCreate( p_demux );
(mtime_t)p_avih->i_microsecperframe /
(mtime_t)1000000 )
{
- msg_Warn( p_demux, "broken or missing index, 'seek' will be axproximative or will have strange behavour" );
+ msg_Warn( p_demux, "broken or missing index, 'seek' will be "
+ "approximative or will exhibit strange behavior" );
+ if( i_do_index == 0 && !b_index )
+ {
+ if( !p_sys->b_seekable ) {
+ b_index = true;
+ goto aviindex;
+ }
+ switch( dialog_Question( p_demux, _("AVI Index") ,
+ _( "This AVI file is broken. Seeking will not work correctly.\n"
+ "Do you want to try to fix it?\n\n"
+ "This might take a long time." ),
+ _( "Repair" ), _( "Don't repair" ), _( "Cancel") ) )
+ {
+ case 1:
+ b_index = true;
+ msg_Dbg( p_demux, "Fixing AVI index" );
+ goto aviindex;
+ case 3:
+ /* Kill input */
+ vlc_object_kill( p_demux->p_parent );
+ goto error;
+ }
+ }
}
+
/* fix some BeOS MediaKit generated file */
for( i = 0 ; i < p_sys->i_track; i++ )
{
{
if( p_sys->track[i] )
{
- FREE( p_sys->track[i]->p_index );
+ if( p_sys->track[i]->p_out_muxed )
+ stream_Delete( p_sys->track[i]->p_out_muxed );
+ free( p_sys->track[i]->p_index );
+ free( p_sys->track[i]->p_extra );
free( p_sys->track[i] );
}
}
- FREE( p_sys->track );
+ free( p_sys->track );
AVI_ChunkFreeRoot( p_demux->s, &p_sys->ck_root );
vlc_meta_Delete( p_sys->meta );
*****************************************************************************/
typedef struct
{
- vlc_bool_t b_ok;
+ bool b_ok;
int i_toread;
unsigned int i_track_count = 0;
unsigned int i_track;
- vlc_bool_t b_stream;
+ bool b_stream;
/* cannot be more than 100 stream (dcXX or wbXX) */
avi_track_toread_t toread[100];
for( i_track = 0; i_track < p_sys->i_track; i_track++ )
{
avi_track_t *tk = p_sys->track[i_track];
- vlc_bool_t b;
+ bool b;
+
+ if( p_sys->b_muxed && tk->p_out_muxed )
+ {
+ i_track_count++;
+ tk->b_activated = true;
+ continue;
+ }
es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b );
if( b && !tk->b_activated )
{
AVI_TrackSeek( p_demux, i_track, p_sys->i_time );
}
- tk->b_activated = VLC_TRUE;
+ tk->b_activated = true;
}
else if( !b && tk->b_activated )
{
- tk->b_activated = VLC_FALSE;
+ tk->b_activated = false;
}
if( b )
{
}
}
- b_stream = VLC_FALSE;
+ b_stream = false;
for( ;; )
{
avi_track_t *tk;
- vlc_bool_t b_done;
+ bool b_done;
block_t *p_frame;
off_t i_pos;
unsigned int i;
size_t i_size;
/* search for first chunk to be read */
- for( i = 0, b_done = VLC_TRUE, i_pos = -1; i < p_sys->i_track; i++ )
+ for( i = 0, b_done = true, i_pos = -1; i < p_sys->i_track; i++ )
{
if( !toread[i].b_ok ||
AVI_GetDPTS( p_sys->track[i],
if( toread[i].i_toread > 0 )
{
- b_done = VLC_FALSE; /* not yet finished */
+ b_done = false; /* not yet finished */
}
if( toread[i].i_posf > 0 )
{
- if( i_pos == -1 || i_pos > toread[i_track].i_posf )
+ if( i_pos == -1 || i_pos > toread[i].i_posf )
{
i_track = i;
i_pos = toread[i].i_posf;
if( b_done )
{
- return( 1 );
+ for( i = 0; i < p_sys->i_track; i++ )
+ {
+ if( toread[i].b_ok )
+ return 1;
+ }
+ msg_Warn( p_demux, "all tracks have failed, exiting..." );
+ return 0;
}
if( i_pos == -1 )
* affect the reading speed too much. */
if( !(++i_loop_count % 1024) )
{
- if( p_demux->b_die ) return -1;
+ if( !vlc_object_alive (p_demux) ) return -1;
msleep( 10000 );
if( !(i_loop_count % (1024 * 10)) )
if( ( p_frame = stream_Block( p_demux->s, __EVEN( i_size ) ) )==NULL )
{
- msg_Warn( p_demux, "failled reading data" );
- tk->b_activated = VLC_FALSE;
- toread[i_track].b_ok = VLC_FALSE;
+ msg_Warn( p_demux, "failed reading data" );
+ tk->b_activated = false;
+ toread[i_track].b_ok = false;
continue;
}
if( i_size % 2 ) /* read was padded on word boundary */
toread[i_track].i_posf = -1;
}
- b_stream = VLC_TRUE; /* at least one read succeed */
+ b_stream = true; /* at least one read succeed */
if( tk->i_cat != VIDEO_ES )
p_frame->i_dts = p_frame->i_pts;
}
//p_pes->i_rate = p_demux->stream.control.i_rate;
- es_out_Send( p_demux->out, tk->p_es, p_frame );
+ if( tk->p_out_muxed )
+ stream_DemuxSend( tk->p_out_muxed, p_frame );
+ else
+ es_out_Send( p_demux->out, tk->p_es, p_frame );
}
}
unsigned int i_stream;
unsigned int i_packet;
+ if( p_sys->b_muxed )
+ {
+ msg_Err( p_demux, "Can not yet process muxed avi substreams without seeking" );
+ return VLC_EGENERIC;
+ }
+
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time + 1 );
/* *** find master stream for data packet skipping algo *** */
for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
{
avi_track_t *tk = p_sys->track[i_stream];
- vlc_bool_t b;
+ bool b;
es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b );
demux_sys_t *p_sys = p_demux->p_sys;
unsigned int i_stream;
- msg_Dbg( p_demux, "seek requested: "I64Fd" secondes %d%%",
+ msg_Dbg( p_demux, "seek requested: %"PRId64" seconds %d%%",
i_date / 1000000, i_percent );
if( p_sys->b_seekable )
int64_t i_pos;
/* use i_percent to create a true i_date */
- msg_Warn( p_demux, "mmh, seeking without index at %d%%"
- " work only for interleaved file", i_percent );
+ msg_Warn( p_demux, "seeking without index at %d%%"
+ " only works for interleaved files", i_percent );
if( i_percent >= 100 )
{
msg_Warn( p_demux, "cannot seek so far !" );
i_date = AVI_GetPTS( p_stream );
/* TODO better support for i_samplesize != 0 */
- msg_Dbg( p_demux, "estimate date "I64Fd, i_date );
+ msg_Dbg( p_demux, "estimate date %"PRId64, i_date );
}
-#define p_stream p_sys->track[i_stream]
- p_sys->i_time = 0;
- /* seek for chunk based streams */
+ /* */
for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
{
- if( p_stream->b_activated && !p_stream->i_samplesize )
-/* if( p_stream->b_activated ) */
- {
- AVI_TrackSeek( p_demux, i_stream, i_date );
- p_sys->i_time = __MAX( AVI_GetPTS( p_stream ),
- p_sys->i_time );
- }
- }
-#if 1
- if( p_sys->i_time )
- {
- i_date = p_sys->i_time;
- }
- /* seek for bytes based streams */
- for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
- {
- if( p_stream->b_activated && p_stream->i_samplesize )
- {
- AVI_TrackSeek( p_demux, i_stream, i_date );
-/* p_sys->i_time = __MAX( AVI_GetPTS( p_stream ), p_sys->i_time );*/
- }
- }
- msg_Dbg( p_demux, "seek: "I64Fd" seconds", p_sys->i_time /1000000 );
- /* set true movie time */
-#endif
- if( !p_sys->i_time )
- {
- p_sys->i_time = i_date;
+ avi_track_t *p_stream = p_sys->track[i_stream];
+
+ if( !p_stream->b_activated )
+ continue;
+
+ AVI_TrackSeek( p_demux, i_stream, i_date );
}
-#undef p_stream
+ es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
+ p_sys->i_time = i_date;
+ msg_Dbg( p_demux, "seek: %"PRId64" seconds", p_sys->i_time /1000000 );
return VLC_SUCCESS;
}
else
/*****************************************************************************
* Control:
- *****************************************************************************
- *
*****************************************************************************/
static double ControlGetPosition( demux_t *p_demux )
{
}
}
}
- return (double)i64 / (double)stream_Size( p_demux->s );
+ return (double)i64 / stream_Size( p_demux->s );
}
return 0.0;
}
-static int Control( demux_t *p_demux, int i_query, va_list args )
+static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
int i;
double f, *pf;
int64_t i64, *pi64;
- vlc_meta_t **pp_meta;
+ vlc_meta_t *p_meta;
switch( i_query )
{
}
return VLC_SUCCESS;
case DEMUX_GET_META:
- pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
- *pp_meta = vlc_meta_Duplicate( p_sys->meta );
+ p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
+ vlc_meta_Merge( p_meta, p_sys->meta );
return VLC_SUCCESS;
default:
static mtime_t AVI_PTSToChunk( avi_track_t *tk, mtime_t i_pts )
{
+ if( !tk->i_scale )
+ return (mtime_t)0;
+
return (mtime_t)((int64_t)i_pts *
(int64_t)tk->i_rate /
(int64_t)tk->i_scale /
}
static mtime_t AVI_PTSToByte( avi_track_t *tk, mtime_t i_pts )
{
+ if( !tk->i_scale || !tk->i_samplesize )
+ return (mtime_t)0;
+
return (mtime_t)((int64_t)i_pts *
(int64_t)tk->i_rate /
(int64_t)tk->i_scale /
static mtime_t AVI_GetDPTS( avi_track_t *tk, int64_t i_count )
{
- mtime_t i_dpts;
+ mtime_t i_dpts = 0;
+
+ if( !tk->i_rate )
+ return i_dpts;
i_dpts = (mtime_t)( (int64_t)1000000 *
(int64_t)i_count *
for( ;; )
{
- if( p_demux->b_die ) return VLC_EGENERIC;
+ if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
if( AVI_PacketGetHeader( p_demux, &avi_pk ) )
{
* affect the reading speed too much. */
if( !(++i_loop_count % 1024) )
{
- if( p_demux->b_die ) return VLC_EGENERIC;
+ if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
msleep( 10000 );
if( !(i_loop_count % (1024 * 10)) )
}
}
-
/* be sure that i_ck will be a valid index entry */
static int AVI_StreamChunkSet( demux_t *p_demux, unsigned int i_stream,
unsigned int i_ck )
return VLC_SUCCESS;
}
-
/* XXX FIXME up to now, we assume that all chunk are one after one */
static int AVI_StreamBytesSet( demux_t *p_demux,
unsigned int i_stream,
}
msg_Dbg( p_demux,
- "old:"I64Fd" %s new "I64Fd,
+ "old:%"PRId64" %s new %"PRId64,
i_oldpts,
i_oldpts > i_date ? ">" : "<",
i_date );
if( p_stream->i_cat == VIDEO_ES )
{
/* search key frame */
- if( i_date < i_oldpts )
+ //if( i_date < i_oldpts || 1 )
{
while( p_stream->i_idxposc > 0 &&
!( p_stream->p_index[p_stream->i_idxposc].i_flags &
}
}
}
+#if 0
else
{
while( p_stream->i_idxposc < p_stream->i_idxnb &&
}
}
}
+#endif
}
}
else
}
/****************************************************************************
- * Return VLC_TRUE if it's a key frame
+ * Return 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:
+ case VLC_CODEC_DIV1:
/* we have:
* startcode: 0x00000100 32bits
* framenumber ? 5bits
}
return p_byte[4] & 0x06 ? 0 : AVIIF_KEYFRAME;
- case FOURCC_DIV2:
- case FOURCC_DIV3: /* wmv1 also */
+ case VLC_CODEC_DIV2:
+ case VLC_CODEC_DIV3:
+ case VLC_CODEC_WMV1:
/* we have
* picture type 0(I),1(P) 2bits
*/
return p_byte[0] & 0xC0 ? 0 : AVIIF_KEYFRAME;
- case FOURCC_mp4v:
+ case VLC_CODEC_MP4V:
/* we should find first occurrence of 0x000001b6 (32bits)
* startcode: 0x000001b6 32bits
* piture type 0(I),1(P) 2bits
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;
- }
+ return vlc_fourcc_GetCodec( i_cat, i_codec );
default:
return VLC_FOURCC( 'u', 'n', 'd', 'f' );
}
*
****************************************************************************/
static void AVI_ParseStreamHeader( vlc_fourcc_t i_id,
- int *pi_number, int *pi_type )
+ unsigned int *pi_number, unsigned int *pi_type )
{
#define SET_PTR( p, v ) if( p ) *(p) = (v);
int c1, c2;
break;
case AVITWOCC_dc:
case AVITWOCC_db:
+ case AVITWOCC_AC:
SET_PTR( pi_type, VIDEO_ES );
break;
default:
****************************************************************************/
static int AVI_PacketGetHeader( demux_t *p_demux, avi_packet_t *p_pk )
{
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( stream_Peek( p_demux->s, &p_peek, 16 ) < 16 )
{
}
return VLC_SUCCESS;
}
+
static int AVI_PacketRead( demux_t *p_demux,
avi_packet_t *p_pk,
block_t **pp_frame )
* this code is called only on broken files). */
if( !(++i_count % 1024) )
{
- if( p_demux->b_die ) return VLC_EGENERIC;
+ if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
msleep( 10000 );
if( !(i_count % (1024 * 10)) )
off_t i_offset;
unsigned int i;
- vlc_bool_t b_keyset[100];
+ bool b_keyset[100];
p_riff = AVI_ChunkFind( &p_sys->ck_root, AVIFOURCC_RIFF, 0);
p_idx1 = AVI_ChunkFind( p_riff, AVIFOURCC_idx1, 0);
/* Reset b_keyset */
for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
- b_keyset[i_stream] = VLC_FALSE;
+ b_keyset[i_stream] = false;
for( i_index = 0; i_index < p_idx1->i_entry_count; i_index++ )
{
AVI_IndexAddEntry( p_sys, i_stream, &index );
if( index.i_flags&AVIIF_KEYFRAME )
- b_keyset[i_stream] = VLC_TRUE;
+ b_keyset[i_stream] = true;
}
}
if( !p_indx )
{
- msg_Warn( p_demux, "cannot find indx (misdetect/broken OpenDML file?)" );
+ msg_Warn( p_demux, "cannot find indx (misdetect/broken OpenDML "
+ "file?)" );
continue;
}
{
demux_sys_t *p_sys = p_demux->p_sys;
- avi_chunk_list_t *p_riff;
- avi_chunk_list_t *p_movi;
+ avi_chunk_list_t *p_riff;
+ avi_chunk_list_t *p_movi;
unsigned int i_stream;
off_t i_movi_end;
+ mtime_t i_dialog_update;
+ dialog_progress_bar_t *p_dialog = NULL;
+
p_riff = AVI_ChunkFind( &p_sys->ck_root, AVIFOURCC_RIFF, 0);
p_movi = AVI_ChunkFind( p_riff, AVIFOURCC_movi, 0);
stream_Seek( p_demux->s, p_movi->i_chunk_pos + 12 );
msg_Warn( p_demux, "creating index from LIST-movi, will take time !" );
+
+
+ /* Only show dialog if AVI is > 10MB */
+ i_dialog_update = mdate();
+ if( stream_Size( p_demux->s ) > 10000000 )
+ p_dialog = dialog_ProgressCreate( p_demux, _("Fixing AVI Index..."),
+ NULL, _("Cancel") );
+
for( ;; )
{
avi_packet_t pk;
- if( p_demux->b_die )
+ if( !vlc_object_alive (p_demux) )
+ break;
+
+ /* Don't update/check dialog too often */
+ if( p_dialog && mdate() - i_dialog_update > 100000 )
{
- return;
+ if( dialog_ProgressCancelled( p_dialog ) )
+ break;
+
+ float f_pos = (float)stream_Tell( p_demux->s ) /
+ (float)stream_Size( p_demux->s );
+ dialog_ProgressSet( p_dialog, NULL, f_pos );
+
+ i_dialog_update = mdate();
}
if( AVI_PacketGetHeader( p_demux, &pk ) )
- {
break;
- }
+
if( pk.i_stream < p_sys->i_track &&
pk.i_cat == p_sys->track[pk.i_stream]->i_cat )
{
{
switch( pk.i_fourcc )
{
- case AVIFOURCC_idx1:
- if( p_sys->b_odml )
- {
- avi_chunk_list_t *p_sysx;
- p_sysx = AVI_ChunkFind( &p_sys->ck_root,
- AVIFOURCC_RIFF, 1 );
+ case AVIFOURCC_idx1:
+ if( p_sys->b_odml )
+ {
+ avi_chunk_list_t *p_sysx;
+ p_sysx = AVI_ChunkFind( &p_sys->ck_root,
+ AVIFOURCC_RIFF, 1 );
- msg_Dbg( p_demux, "looking for new RIFF chunk" );
- if( stream_Seek( p_demux->s, p_sysx->i_chunk_pos + 24))
- {
- goto print_stat;
- }
- break;
- }
- goto print_stat;
- case AVIFOURCC_RIFF:
- msg_Dbg( p_demux, "new RIFF chunk found" );
- case AVIFOURCC_rec:
- case AVIFOURCC_JUNK:
- break;
- default:
- msg_Warn( p_demux, "need resync, probably broken avi" );
- if( AVI_PacketSearch( p_demux ) )
- {
- msg_Warn( p_demux, "lost sync, abord index creation" );
+ msg_Dbg( p_demux, "looking for new RIFF chunk" );
+ if( stream_Seek( p_demux->s, p_sysx->i_chunk_pos + 24 ) )
goto print_stat;
- }
+ break;
+ }
+ goto print_stat;
+
+ case AVIFOURCC_RIFF:
+ msg_Dbg( p_demux, "new RIFF chunk found" );
+ break;
+
+ case AVIFOURCC_rec:
+ case AVIFOURCC_JUNK:
+ break;
+
+ default:
+ msg_Warn( p_demux, "need resync, probably broken avi" );
+ if( AVI_PacketSearch( p_demux ) )
+ {
+ msg_Warn( p_demux, "lost sync, abord index creation" );
+ goto print_stat;
+ }
}
}
}
print_stat:
+ if( p_dialog != NULL )
+ dialog_ProgressDestroy( p_dialog );
+
for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
{
- msg_Dbg( p_demux,
- "stream[%d] creating %d index entries",
- i_stream,
- p_sys->track[i_stream]->i_idxnb );
+ msg_Dbg( p_demux, "stream[%d] creating %d index entries",
+ i_stream, p_sys->track[i_stream]->i_idxnb );
}
}
{
demux_sys_t *p_sys = p_demux->p_sys;
unsigned int i;
- int b_end = VLC_TRUE;
+ int b_end = true;
for( i = 0; i < p_sys->i_track; i++ )
{
avi_track_t *tk = p_sys->track[i];
if( tk->i_idxposc >= tk->i_idxnb )
{
- tk->b_activated = VLC_FALSE;
- es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->p_es, VLC_FALSE );
+ tk->b_activated = false;
+ if( tk->p_es ) es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->p_es, false );
}
else
{
- b_end = VLC_FALSE;
+ b_end = false;
}
}
return( b_end );
i_length /= (mtime_t)1000000; /* in seconds */
msg_Dbg( p_demux,
- "stream[%d] length:"I64Fd" (based on index)",
+ "stream[%d] length:%"PRId64" (based on index)",
i,
i_length );
i_maxlength = __MAX( i_maxlength, i_length );
return i_maxlength;
}
-
-