* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
+ * Gildas Bazin <gbazin@videolan.org>
*
* 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
#include <vlc/sout.h>
#include "codecs.h"
+typedef GUID guid_t;
+
+#define MAX_ASF_TRACKS 128
+#define ASF_DATA_PACKET_SIZE 4096
/*****************************************************************************
* Module descriptor
vlc_module_begin();
set_description( _("ASF muxer") );
+ set_category( CAT_SOUT );
+ set_subcategory( SUBCAT_SOUT_MUX );
+ set_shortname( "ASF" );
+
set_capability( "sout mux", 5 );
add_shortcut( "asf" );
add_shortcut( "asfh" );
static int DelStream( sout_mux_t *, sout_input_t * );
static int Mux ( sout_mux_t * );
-typedef struct
-{
- uint32_t v1; /* le */
- uint16_t v2; /* le */
- uint16_t v3; /* le */
- uint8_t v4[8];
-
-} guid_t;
-
typedef struct
{
int i_id;
uint16_t i_tag; /* for audio */
vlc_fourcc_t i_fourcc; /* for video */
char *psz_name; /* codec name */
+ int i_blockalign; /* for audio only */
+ vlc_bool_t b_audio_correction;
int i_sequence;
int i_extra;
- uint8_t *p_extra;
+ uint8_t *p_extra;
+
+ es_format_t fmt;
} asf_track_t;
int64_t i_bitrate;
int i_track;
- asf_track_t track[128];
+ asf_track_t track[MAX_ASF_TRACKS];
vlc_bool_t b_write_header;
static int MuxGetStream( sout_mux_t *, int *pi_stream, mtime_t *pi_dts );
-static block_t *asf_header_create( sout_mux_t *, vlc_bool_t b_broadcast );
+static block_t *asf_header_create( sout_mux_t *, vlc_bool_t );
static block_t *asf_packet_create( sout_mux_t *, asf_track_t *, block_t * );
static block_t *asf_stream_end_create( sout_mux_t *);
+static block_t *asf_packet_flush( sout_mux_t * );
typedef struct
{
int i_buffer_size;
int i_buffer;
uint8_t *p_buffer;
+
} bo_t;
static void bo_init ( bo_t *, uint8_t *, int );
p_sys->i_seq = 0;
p_sys->b_write_header = VLC_TRUE;
- p_sys->i_track = 1;
- p_sys->i_packet_size = 4096;
+ p_sys->i_track = 0;
+ p_sys->i_packet_size = ASF_DATA_PACKET_SIZE;
p_sys->i_packet_count= 0;
/* Generate a random fid */
srand( mdate() & 0xffffffff );
- p_sys->fid.v1 = 0xbabac001;
- p_sys->fid.v2 = ( (uint64_t)rand() << 16 ) / RAND_MAX;
- p_sys->fid.v3 = ( (uint64_t)rand() << 16 ) / RAND_MAX;
+ p_sys->fid.Data1 = 0xbabac001;
+ p_sys->fid.Data2 = ( (uint64_t)rand() << 16 ) / RAND_MAX;
+ p_sys->fid.Data3 = ( (uint64_t)rand() << 16 ) / RAND_MAX;
for( i = 0; i < 8; i++ )
{
- p_sys->fid.v4[i] = ( (uint64_t)rand() << 8 ) / RAND_MAX;
+ p_sys->fid.Data4[i] = ( (uint64_t)rand() << 8 ) / RAND_MAX;
}
/* Meta data */
msg_Dbg( p_mux, "Asf muxer closed" );
+ /* Flush last packet if any */
+ if( (out = asf_packet_flush( p_mux ) ) )
+ {
+ sout_AccessOutWrite( p_mux->p_access, out );
+ }
+
if( ( out = asf_stream_end_create( p_mux ) ) )
{
sout_AccessOutWrite( p_mux->p_access, out );
sout_AccessOutWrite( p_mux->p_access, out );
}
- for( i = 1; i < p_sys->i_track; i++ )
+ for( i = 0; i < p_sys->i_track; i++ )
{
free( p_sys->track[i].p_extra );
+ es_format_Clean( &p_sys->track[i].fmt );
}
free( p_sys );
}
case MUX_GET_ADD_STREAM_WAIT:
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
- *pb_bool = VLC_FALSE;
+ *pb_bool = VLC_TRUE;
return VLC_SUCCESS;
case MUX_GET_MIME:
bo_t bo;
msg_Dbg( p_mux, "adding input" );
- if( p_sys->i_track > 127 )
+ if( p_sys->i_track >= MAX_ASF_TRACKS )
{
msg_Dbg( p_mux, "cannot add this track (too much track)" );
return VLC_EGENERIC;
}
tk = p_input->p_sys = &p_sys->track[p_sys->i_track];
- tk->i_id = p_sys->i_track;
+ tk->i_id = p_sys->i_track + 1;
tk->i_cat = p_input->p_fmt->i_cat;
tk->i_sequence = 0;
+ tk->b_audio_correction = 0;
switch( tk->i_cat )
{
case AUDIO_ES:
{
int i_blockalign = p_input->p_fmt->audio.i_blockalign;
- int i_bitspersample = 0;
+ int i_bitspersample = p_input->p_fmt->audio.i_bitspersample;
int i_extra = 0;
switch( p_input->p_fmt->i_codec )
case VLC_FOURCC( 'a', '5', '2', ' ' ):
tk->i_tag = WAVE_FORMAT_A52;
tk->psz_name = "A/52";
+ i_bitspersample = 0;
break;
case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
#if 1
tk->psz_name = "MPEG Audio Layer 3";
tk->i_tag = WAVE_FORMAT_MPEGLAYER3;
+ i_bitspersample = 0;
i_blockalign = 1;
i_extra = 12;
break;
#else
tk->psz_name = "MPEG Audio Layer 1/2";
tk->i_tag = WAVE_FORMAT_MPEG;
+ i_bitspersample = 0;
i_blockalign = 1;
i_extra = 22;
break;
#endif
case VLC_FOURCC( 'w', 'm', 'a', '1' ):
- tk->psz_name = "Windows Media Audio 1";
+ tk->psz_name = "Windows Media Audio v1";
tk->i_tag = WAVE_FORMAT_WMA1;
+ tk->b_audio_correction = VLC_TRUE;
break;
+ case VLC_FOURCC( 'w', 'm', 'a', ' ' ):
case VLC_FOURCC( 'w', 'm', 'a', '2' ):
- tk->psz_name = "Windows Media Audio 2";
+ tk->psz_name= "Windows Media Audio (v2) 7, 8 and 9 Series";
tk->i_tag = WAVE_FORMAT_WMA2;
+ tk->b_audio_correction = VLC_TRUE;
+ break;
+ case VLC_FOURCC( 'w', 'm', 'a', 'p' ):
+ tk->psz_name = "Windows Media Audio 9 Professional";
+ tk->i_tag = WAVE_FORMAT_WMAP;
+ tk->b_audio_correction = VLC_TRUE;
break;
- case VLC_FOURCC( 'w', 'm', 'a', '3' ):
- tk->psz_name = "Windows Media Audio 3";
- tk->i_tag = WAVE_FORMAT_WMA3;
+ case VLC_FOURCC( 'w', 'm', 'a', 'l' ):
+ tk->psz_name = "Windows Media Audio 9 Lossless";
+ tk->i_tag = WAVE_FORMAT_WMAL;
+ tk->b_audio_correction = VLC_TRUE;
break;
/* raw codec */
case VLC_FOURCC( 'u', '8', ' ', ' ' ):
return VLC_EGENERIC;
}
-
tk->i_extra = sizeof( WAVEFORMATEX ) +
p_input->p_fmt->i_extra + i_extra;
tk->p_extra = malloc( tk->i_extra );
bo_addle_u32( &bo, p_input->p_fmt->audio.i_rate );
bo_addle_u32( &bo, p_input->p_fmt->i_bitrate / 8 );
bo_addle_u16( &bo, i_blockalign );
+ tk->i_blockalign = i_blockalign;
bo_addle_u16( &bo, i_bitspersample );
if( p_input->p_fmt->i_extra > 0 )
{
return VLC_EGENERIC;
}
+ es_format_Copy( &tk->fmt, p_input->p_fmt );
+
p_sys->i_track++;
return VLC_SUCCESS;
}
}
/****************************************************************************
- * guid
+ * GUID definitions
****************************************************************************/
static void bo_add_guid( bo_t *p_bo, const guid_t *id )
{
int i;
- bo_addle_u32( p_bo, id->v1 );
- bo_addle_u16( p_bo, id->v2 );
- bo_addle_u16( p_bo, id->v3 );
+ bo_addle_u32( p_bo, id->Data1 );
+ bo_addle_u16( p_bo, id->Data2 );
+ bo_addle_u16( p_bo, id->Data3 );
for( i = 0; i < 8; i++ )
{
- bo_add_u8( p_bo, id->v4[i] );
+ bo_add_u8( p_bo, id->Data4[i] );
}
}
static const guid_t asf_object_header_guid =
-{
- 0x75B22630,
- 0x668E,
- 0x11CF,
- { 0xA6,0xD9, 0x00,0xAA,0x00,0x62,0xCE,0x6C }
-};
+{0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
static const guid_t asf_object_data_guid =
-{
- 0x75B22636,
- 0x668E,
- 0x11CF,
- { 0xA6,0xD9, 0x00,0xAA,0x00,0x62,0xCE,0x6C }
-};
+{0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
static const guid_t asf_object_file_properties_guid =
-{
- 0x8cabdca1,
- 0xa947,
- 0x11cf,
- { 0x8e,0xe4, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
-
-};
+{0x8cabdca1, 0xa947, 0x11cf, {0x8e, 0xe4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
static const guid_t asf_object_stream_properties_guid =
-{
- 0xB7DC0791,
- 0xA9B7,
- 0x11CF,
- { 0x8E,0xE6, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
-
-};
+{0xB7DC0791, 0xA9B7, 0x11CF, {0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
static const guid_t asf_object_header_extention_guid =
-{
- 0x5FBF03B5,
- 0xA92E,
- 0x11CF,
- { 0x8E,0xE3, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
-};
+{0x5FBF03B5, 0xA92E, 0x11CF, {0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
static const guid_t asf_object_stream_type_audio =
-{
- 0xF8699E40,
- 0x5B4D,
- 0x11CF,
- { 0xA8,0xFD, 0x00,0x80,0x5F,0x5C,0x44,0x2B }
-};
-
+{0xF8699E40, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
static const guid_t asf_object_stream_type_video =
-{
- 0xbc19efc0,
- 0x5B4D,
- 0x11CF,
- { 0xA8,0xFD, 0x00,0x80,0x5F,0x5C,0x44,0x2B }
-};
-
+{0xbc19efc0, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
static const guid_t asf_guid_audio_conceal_none =
-{
- 0x20FB5700,
- 0x5B55,
- 0x11CF,
- { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }
-};
+{0x20FB5700, 0x5B55, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
+static const guid_t asf_guid_audio_conceal_spread =
+{0xBFC3CD50, 0x618F, 0x11CF, {0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20}};
static const guid_t asf_guid_video_conceal_none =
-{
- 0x20FB5700,
- 0x5B55,
- 0x11CF,
- { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }
-};
+{0x20FB5700, 0x5B55, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
static const guid_t asf_guid_reserved_1 =
-{
- 0xABD3D211,
- 0xA9BA,
- 0x11cf,
- { 0x8E, 0xE6,0x00, 0xC0, 0x0C ,0x20, 0x53, 0x65 }
-};
-static const guid_t asf_object_codec_comment_guid =
-{
- 0x86D15240,
- 0x311D,
- 0x11D0,
- { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }
-};
-static const guid_t asf_object_codec_comment_reserved_guid =
-{
- 0x86D15241,
- 0x311D,
- 0x11D0,
- { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }
-};
+{0xABD3D211, 0xA9BA, 0x11cf, {0x8E, 0xE6, 0x00, 0xC0, 0x0C ,0x20, 0x53, 0x65}};
+static const guid_t asf_object_codec_list_guid =
+{0x86D15240, 0x311D, 0x11D0, {0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
+static const guid_t asf_object_codec_list_reserved_guid =
+{0x86D15241, 0x311D, 0x11D0, {0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
static const guid_t asf_object_content_description_guid =
-{
- 0x75B22633,
- 0x668E,
- 0x11CF,
- { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }
-};
+{0x75B22633, 0x668E, 0x11CF, {0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}};
+static const guid_t asf_object_index_guid =
+{0x33000890, 0xE5B1, 0x11CF, {0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}};
+static const guid_t asf_object_metadata_guid =
+{0xC5F8CBEA, 0x5BAF, 0x4877, {0x84, 0x67, 0xAA, 0x8C, 0x44, 0xFA, 0x4C, 0xCA}};
+/****************************************************************************
+ * Misc
+ ****************************************************************************/
static void asf_chunk_add( bo_t *bo,
int i_type, int i_len, int i_flags, int i_seq )
{
{
sout_mux_sys_t *p_sys = p_mux->p_sys;
asf_track_t *tk;
-
mtime_t i_duration = 0;
- int i_size;
- int i_ci_size;
- int i_cd_size = 0;
+ int i_size, i_header_ext_size, i;
+ int i_ci_size, i_cm_size = 0, i_cd_size = 0;
block_t *out;
bo_t bo;
- int i;
msg_Dbg( p_mux, "Asf muxer creating header" );
}
/* calculate header size */
- i_size = 30 + 104 + 46;
+ i_size = 30 + 104;
i_ci_size = 44;
- for( i = 1; i < p_sys->i_track; i++ )
+ for( i = 0; i < p_sys->i_track; i++ )
{
i_size += 78 + p_sys->track[i].i_extra;
i_ci_size += 8 + 2 * strlen( p_sys->track[i].psz_name );
- if( p_sys->track[i].i_cat == AUDIO_ES )
- {
- i_ci_size += 4;
- }
- else if( p_sys->track[i].i_cat == VIDEO_ES )
- {
- i_ci_size += 6;
- }
+ if( p_sys->track[i].i_cat == AUDIO_ES ) i_ci_size += 4;
+ else if( p_sys->track[i].i_cat == VIDEO_ES ) i_ci_size += 6;
+
+ /* Error correction data field */
+ if( p_sys->track[i].b_audio_correction ) i_size += 8;
}
+ /* size of the content description object */
if( *p_sys->psz_title || *p_sys->psz_author || *p_sys->psz_copyright ||
*p_sys->psz_comment || *p_sys->psz_rating )
{
strlen( p_sys->psz_rating ) + 1 );
}
- i_size += i_ci_size + i_cd_size;
+ /* size of the metadata object */
+ for( i = 0; i < p_sys->i_track; i++ )
+ {
+ if( p_sys->track[i].i_cat == VIDEO_ES )
+ {
+ i_cm_size = 26 + 2 * (16 + 2 * sizeof("AspectRatio?"));
+ break;
+ }
+ }
+
+ i_header_ext_size = i_cm_size ? i_cm_size + 46 : 0;
+ i_size += i_ci_size + i_cd_size + i_header_ext_size ;
if( p_sys->b_asf_http )
{
/* header object */
bo_add_guid ( &bo, &asf_object_header_guid );
bo_addle_u64( &bo, i_size );
- bo_addle_u32( &bo, 2 + p_sys->i_track - 1 );
+ bo_addle_u32( &bo, 2 + p_sys->i_track +
+ (i_cd_size ? 1 : 0) + (i_cm_size ? 1 : 0) );
bo_add_u8 ( &bo, 1 );
bo_add_u8 ( &bo, 2 );
bo_addle_u64( &bo, i_duration * 10 ); /* play duration (100ns) */
bo_addle_u64( &bo, i_duration * 10 ); /* send duration (100ns) */
bo_addle_u64( &bo, p_sys->i_preroll_time ); /* preroll duration (ms) */
- bo_addle_u32( &bo, b_broadcast ? 0x01 : 0x00); /* flags */
+ bo_addle_u32( &bo, b_broadcast ? 0x01 : 0x02 /* seekable */ ); /* flags */
bo_addle_u32( &bo, p_sys->i_packet_size ); /* packet size min */
bo_addle_u32( &bo, p_sys->i_packet_size ); /* packet size max */
bo_addle_u32( &bo, p_sys->i_bitrate ); /* maxbitrate */
/* header extention */
- bo_add_guid ( &bo, &asf_object_header_extention_guid );
- bo_addle_u64( &bo, 46 );
- bo_add_guid ( &bo, &asf_guid_reserved_1 );
- bo_addle_u16( &bo, 6 );
- bo_addle_u32( &bo, 0 );
+ if( i_header_ext_size )
+ {
+ bo_add_guid ( &bo, &asf_object_header_extention_guid );
+ bo_addle_u64( &bo, i_header_ext_size );
+ bo_add_guid ( &bo, &asf_guid_reserved_1 );
+ bo_addle_u16( &bo, 6 );
+ bo_addle_u32( &bo, i_header_ext_size - 46 );
+ }
+
+ /* metadata object (part of header extension) */
+ if( i_cm_size )
+ {
+ int64_t i_num, i_den;
+ int i_dst_num, i_dst_den;
+
+ for( i = 0; i < p_sys->i_track; i++ )
+ if( p_sys->track[i].i_cat == VIDEO_ES ) break;
+
+ i_num = p_sys->track[i].fmt.video.i_aspect *
+ (int64_t)p_sys->track[i].fmt.video.i_height;
+ i_den = VOUT_ASPECT_FACTOR * p_sys->track[i].fmt.video.i_width;
+ vlc_reduce( &i_dst_num, &i_dst_den, i_num, i_den, 0 );
+
+ msg_Dbg( p_mux, "pixel aspect-ratio: %i/%i", i_dst_num, i_dst_den );
+
+ bo_add_guid ( &bo, &asf_object_metadata_guid );
+ bo_addle_u64( &bo, i_cm_size );
+ bo_addle_u16( &bo, 2 ); /* description records count */
+ /* 1st description record */
+ bo_addle_u16( &bo, 0 ); /* reserved */
+ bo_addle_u16( &bo, i + 1 ); /* stream number (0 for the whole file) */
+ bo_addle_u16( &bo, 2 * sizeof("AspectRatioX") ); /* name length */
+ bo_addle_u16( &bo, 0x3 /* DWORD */ ); /* data type */
+ bo_addle_u32( &bo, 4 ); /* data length */
+ bo_addle_str16_nosize( &bo, "AspectRatioX" );
+ bo_addle_u32( &bo, i_dst_num ); /* data */
+ /* 2nd description record */
+ bo_addle_u16( &bo, 0 ); /* reserved */
+ bo_addle_u16( &bo, i + 1 ); /* stream number (0 for the whole file) */
+ bo_addle_u16( &bo, 2 * sizeof("AspectRatioY") ); /* name length */
+ bo_addle_u16( &bo, 0x3 /* DWORD */ ); /* data type */
+ bo_addle_u32( &bo, 4 ); /* data length */
+ bo_addle_str16_nosize( &bo, "AspectRatioY" );
+ bo_addle_u32( &bo, i_dst_den ); /* data */
+ }
/* content description header */
if( i_cd_size > 0 )
}
/* stream properties */
- for( i = 1; i < p_sys->i_track; i++ )
+ for( i = 0; i < p_sys->i_track; i++ )
{
tk = &p_sys->track[i];
bo_add_guid ( &bo, &asf_object_stream_properties_guid );
- bo_addle_u64( &bo, 78 + tk->i_extra );
+ bo_addle_u64( &bo, 78 + tk->i_extra + (tk->b_audio_correction ? 8:0) );
+
if( tk->i_cat == AUDIO_ES )
{
bo_add_guid( &bo, &asf_object_stream_type_audio );
- bo_add_guid( &bo, &asf_guid_audio_conceal_none );
+ if( tk->b_audio_correction )
+ bo_add_guid( &bo, &asf_guid_audio_conceal_spread );
+ else
+ bo_add_guid( &bo, &asf_guid_audio_conceal_none );
}
else if( tk->i_cat == VIDEO_ES )
{
}
bo_addle_u64( &bo, 0 ); /* time offset */
bo_addle_u32( &bo, tk->i_extra );
- bo_addle_u32( &bo, 0 ); /* 0 */
+ /* correction data length */
+ bo_addle_u32( &bo, tk->b_audio_correction ? 8 : 0 );
bo_addle_u16( &bo, tk->i_id ); /* stream number */
bo_addle_u32( &bo, 0 );
bo_add_mem ( &bo, tk->p_extra, tk->i_extra );
+
+ /* Error correction data field */
+ if( tk->b_audio_correction )
+ {
+ bo_add_u8( &bo, 0x1 ); /* span */
+ bo_addle_u16( &bo, tk->i_blockalign ); /* virtual packet length */
+ bo_addle_u16( &bo, tk->i_blockalign ); /* virtual chunck length */
+ bo_addle_u16( &bo, 1 ); /* silence length */
+ bo_add_u8( &bo, 0x0 ); /* data */
+ }
}
/* Codec Infos */
- bo_add_guid ( &bo, &asf_object_codec_comment_guid );
+ bo_add_guid ( &bo, &asf_object_codec_list_guid );
bo_addle_u64( &bo, i_ci_size );
- bo_add_guid ( &bo, &asf_object_codec_comment_reserved_guid );
- bo_addle_u32( &bo, p_sys->i_track - 1 );
- for( i = 1; i < p_sys->i_track; i++ )
+ bo_add_guid ( &bo, &asf_object_codec_list_reserved_guid );
+ bo_addle_u32( &bo, p_sys->i_track );
+ for( i = 0; i < p_sys->i_track; i++ )
{
tk = &p_sys->track[i];
- bo_addle_u16( &bo, tk->i_id );
+ if( tk->i_cat == VIDEO_ES ) bo_addle_u16( &bo, 1 /* video */ );
+ else if( tk->i_cat == AUDIO_ES ) bo_addle_u16( &bo, 2 /* audio */ );
+ else bo_addle_u16( &bo, 0xFFFF /* unknown */ );
+
bo_addle_str16( &bo, tk->psz_name );
bo_addle_u16( &bo, 0 );
if( tk->i_cat == AUDIO_ES )
{
bo_addle_u16( &bo, 4 );
bo_add_mem ( &bo, (uint8_t*)&tk->i_fourcc, 4 );
-
}
}
/****************************************************************************
*
****************************************************************************/
+static block_t *asf_packet_flush( sout_mux_t *p_mux )
+{
+ sout_mux_sys_t *p_sys = p_mux->p_sys;
+ int i_pad, i_preheader = p_sys->b_asf_http ? 12 : 0;
+ block_t *pk;
+ bo_t bo;
+
+ if( !p_sys->pk ) return 0;
+
+ i_pad = p_sys->i_packet_size - p_sys->i_pk_used;
+ memset( p_sys->pk->p_buffer + p_sys->i_pk_used, 0, i_pad );
+
+ bo_init( &bo, p_sys->pk->p_buffer, 14 + i_preheader );
+
+ if( p_sys->b_asf_http )
+ asf_chunk_add( &bo, 0x4424, p_sys->i_packet_size, 0x0, p_sys->i_seq++);
+
+ bo_add_u8 ( &bo, 0x82 );
+ bo_addle_u16( &bo, 0 );
+ bo_add_u8( &bo, 0x11 );
+ bo_add_u8( &bo, 0x5d );
+ bo_addle_u16( &bo, i_pad );
+ bo_addle_u32( &bo, (p_sys->i_pk_dts - p_sys->i_dts_first) / 1000 +
+ p_sys->i_preroll_time );
+ bo_addle_u16( &bo, 0 /* data->i_length */ );
+ bo_add_u8( &bo, 0x80 | p_sys->i_pk_frame );
+
+ pk = p_sys->pk;
+ p_sys->pk = NULL;
+
+ p_sys->i_packet_count++;
+
+ return pk;
+}
+
static block_t *asf_packet_create( sout_mux_t *p_mux,
asf_track_t *tk, block_t *data )
{
/* add payload (header size = 17) */
i_payload = __MIN( i_data - i_pos,
p_sys->i_packet_size - p_sys->i_pk_used - 17 );
- bo_add_u8 ( &bo, 0x80 | tk->i_id );
+
+ if( tk->b_audio_correction && p_sys->i_pk_frame && i_payload < i_data )
+ {
+ /* Don't know why yet but WMP doesn't like splitted WMA packets */
+ *last = asf_packet_flush( p_mux );
+ last = &(*last)->p_next;
+ continue;
+ }
+
+ bo_add_u8 ( &bo, !(data->i_flags & BLOCK_FLAG_TYPE_P ||
+ data->i_flags & BLOCK_FLAG_TYPE_B) ?
+ 0x80 | tk->i_id : tk->i_id );
bo_add_u8 ( &bo, tk->i_sequence );
bo_addle_u32( &bo, i_pos );
bo_add_u8 ( &bo, 0x08 ); /* flags */
bo_addle_u32( &bo, i_data );
- bo_addle_u32( &bo, (data->i_dts - p_sys->i_dts_first) / 1000 -
+ bo_addle_u32( &bo, (data->i_dts - p_sys->i_dts_first) / 1000 +
p_sys->i_preroll_time );
bo_addle_u16( &bo, i_payload );
bo_add_mem ( &bo, &p_data[i_pos], i_payload );
if( p_sys->i_pk_used + 17 >= p_sys->i_packet_size )
{
- /* not enough data for another payload, flush the packet */
- int i_pad = p_sys->i_packet_size - p_sys->i_pk_used;
-
- bo_init( &bo, p_sys->pk->p_buffer, 14 + i_preheader );
-
- if( p_sys->b_asf_http )
- {
- asf_chunk_add( &bo, 0x4424, p_sys->i_packet_size,
- 0x00, p_sys->i_seq++);
- }
- bo_add_u8 ( &bo, 0x82 );
- bo_addle_u16( &bo, 0 );
- bo_add_u8( &bo, 0x11 );
- bo_add_u8( &bo, 0x5d );
- bo_addle_u16( &bo, i_pad );
- bo_addle_u32( &bo, (p_sys->i_pk_dts - p_sys->i_dts_first) / 1000 -
- p_sys->i_preroll_time );
- bo_addle_u16( &bo, 0 * data->i_length / 1000 );
- bo_add_u8( &bo, 0x80 | p_sys->i_pk_frame );
-
- /* append the packet */
- *last = p_sys->pk;
- last = &p_sys->pk->p_next;
-
- p_sys->pk = NULL;
-
- p_sys->i_packet_count++;
+ /* Not enough data for another payload, flush the packet */
+ *last = asf_packet_flush( p_mux );
+ last = &(*last)->p_next;
}
}
bo_init( &bo, out->p_buffer, 12 );
asf_chunk_add( &bo, 0x4524, 0, 0x00, p_sys->i_seq++ );
}
+ else
+ {
+ /* Create index */
+ out = block_New( p_mux, 56 );
+ bo_init( &bo, out->p_buffer, 56 );
+ bo_add_guid ( &bo, &asf_object_index_guid );
+ bo_addle_u64( &bo, 56 );
+ bo_add_guid ( &bo, &p_sys->fid );
+ bo_addle_u64( &bo, 10000000 );
+ bo_addle_u32( &bo, 5 );
+ bo_addle_u32( &bo, 0 );
+ }
return out;
}