[vlc-commits] mux: ogg: Store the entire es_format_t in ogg_stream_t
Hugo Beauzée-Luyssen
git at videolan.org
Wed Apr 25 09:55:07 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Apr 24 13:25:44 2018 +0200| [ceaf051a6e2d38146835df0d8ba3685e86a02f74] | committer: Hugo Beauzée-Luyssen
mux: ogg: Store the entire es_format_t in ogg_stream_t
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ceaf051a6e2d38146835df0d8ba3685e86a02f74
---
modules/mux/ogg.c | 130 ++++++++++++++++++++++++++++--------------------------
1 file changed, 67 insertions(+), 63 deletions(-)
diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c
index 73cc406ced..aa067d5471 100644
--- a/modules/mux/ogg.c
+++ b/modules/mux/ogg.c
@@ -143,8 +143,7 @@ typedef struct
*****************************************************************************/
typedef struct
{
- enum es_format_category_e i_cat;
- vlc_fourcc_t i_fourcc;
+ es_format_t fmt;
int b_new;
@@ -291,6 +290,7 @@ static void Close( vlc_object_t * p_this )
{
ogg_stream_t *p_stream = p_sys->pp_del_streams[i];
+ es_format_Clean( &p_stream->fmt );
OggCreateStreamFooter( p_mux, p_stream );
free( p_stream->p_oggds_header );
free( p_stream->skeleton.p_index );
@@ -354,8 +354,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
if( !p_stream )
return VLC_ENOMEM;
- p_stream->i_cat = p_input->p_fmt->i_cat;
- p_stream->i_fourcc = p_input->p_fmt->i_codec;
+ if( es_format_Copy( &p_stream->fmt, &p_input->fmt ) != VLC_SUCCESS )
+ {
+ free( p_stream );
+ return VLC_ENOMEM;
+ }
+
p_stream->i_serial_no = p_sys->i_next_serial_no++;
p_stream->i_packet_no = 0;
p_stream->i_last_keyframe = 0;
@@ -382,7 +386,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
i_frame_rate_base = 1;
}
- switch( p_stream->i_fourcc )
+ switch( p_stream->fmt.i_codec )
{
case VLC_CODEC_MP4V:
case VLC_CODEC_MPGV:
@@ -402,18 +406,18 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER;
memcpy( p_stream->p_oggds_header->stream_type, "video", 5 );
- if( p_stream->i_fourcc == VLC_CODEC_MP4V )
+ if( p_stream->fmt.i_codec == VLC_CODEC_MP4V )
{
memcpy( p_stream->p_oggds_header->sub_type, "XVID", 4 );
}
- else if( p_stream->i_fourcc == VLC_CODEC_DIV3 )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_DIV3 )
{
memcpy( p_stream->p_oggds_header->sub_type, "DIV3", 4 );
}
else
{
memcpy( p_stream->p_oggds_header->sub_type,
- &p_stream->i_fourcc, 4 );
+ &p_stream->fmt.i_codec, 4 );
}
p_stream->p_oggds_header->i_size = 0 ;
p_stream->p_oggds_header->i_time_unit =
@@ -425,7 +429,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
p_stream->p_oggds_header->i_bits_per_sample = 0;
p_stream->p_oggds_header->header.video.i_width = p_input->p_fmt->video.i_width;
p_stream->p_oggds_header->header.video.i_height = p_input->p_fmt->video.i_height;
- msg_Dbg( p_mux, "%4.4s stream", (char *)&p_stream->i_fourcc );
+ msg_Dbg( p_mux, "%4.4s stream", (char *)&p_stream->fmt.i_codec );
break;
case VLC_CODEC_DIRAC:
@@ -452,7 +456,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
break;
case AUDIO_ES:
- switch( p_stream->i_fourcc )
+ switch( p_stream->fmt.i_codec )
{
case VLC_CODEC_OPUS:
msg_Dbg( p_mux, "opus stream" );
@@ -471,7 +475,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
break;
default:
- fourcc_to_wf_tag( p_stream->i_fourcc, &i_tag );
+ fourcc_to_wf_tag( p_stream->fmt.i_codec, &i_tag );
if( i_tag == WAVE_FORMAT_UNKNOWN )
{
FREENULL( p_input->p_sys );
@@ -511,13 +515,13 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
p_stream->p_oggds_header->header.audio.i_channels = p_input->p_fmt->audio.i_channels;
p_stream->p_oggds_header->header.audio.i_block_align = p_input->p_fmt->audio.i_blockalign;
p_stream->p_oggds_header->header.audio.i_avgbytespersec = p_input->p_fmt->i_bitrate / 8;
- msg_Dbg( p_mux, "%4.4s stream", (char *)&p_stream->i_fourcc );
+ msg_Dbg( p_mux, "%4.4s stream", (char *)&p_stream->fmt.i_codec );
break;
}
break;
case SPU_ES:
- switch( p_stream->i_fourcc )
+ switch( p_stream->fmt.i_codec )
{
case VLC_CODEC_SUBT:
p_stream->p_oggds_header = calloc( 1, sizeof(oggds_header_t) );
@@ -738,7 +742,7 @@ static void OggGetSkeletonFisbone( uint8_t **pp_buffer, long *pi_size,
} headers = { NULL, NULL, 0, 0 };
*pi_size = 0;
- switch( p_stream->i_fourcc )
+ switch( p_stream->fmt.i_codec )
{
case VLC_CODEC_VORBIS:
psz_value = "audio/vorbis";
@@ -767,7 +771,7 @@ static void OggGetSkeletonFisbone( uint8_t **pp_buffer, long *pi_size,
default:
psz_value = "application/octet-stream";
msg_Warn( p_mux, "Unknown fourcc for stream %s, setting Content-Type to %s",
- vlc_fourcc_GetDescription( p_stream->i_cat, p_stream->i_fourcc ),
+ vlc_fourcc_GetDescription( p_stream->fmt.i_cat, p_stream->fmt.i_codec ),
psz_value );
}
@@ -998,25 +1002,25 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
sout_input_t *p_input = p_mux->pp_inputs[i];
p_stream = (ogg_stream_t*)p_input->p_sys;
- bool video = ( p_stream->i_fourcc == VLC_CODEC_THEORA ||
- p_stream->i_fourcc == VLC_CODEC_DIRAC ||
- p_stream->i_fourcc == VLC_CODEC_DAALA );
+ bool video = ( p_stream->fmt.i_codec == VLC_CODEC_THEORA ||
+ p_stream->fmt.i_codec == VLC_CODEC_DIRAC ||
+ p_stream->fmt.i_codec == VLC_CODEC_DAALA );
if( ( ( pass == 0 && !video ) || ( pass == 1 && video ) ) )
continue;
msg_Dbg( p_mux, "creating header for %4.4s",
- (char *)&p_stream->i_fourcc );
+ (char *)&p_stream->fmt.i_codec );
ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
p_stream->b_new = false;
p_stream->i_packet_no = 0;
p_stream->b_started = true;
- if( p_stream->i_fourcc == VLC_CODEC_VORBIS ||
- p_stream->i_fourcc == VLC_CODEC_SPEEX ||
- p_stream->i_fourcc == VLC_CODEC_OPUS ||
- p_stream->i_fourcc == VLC_CODEC_THEORA ||
- p_stream->i_fourcc == VLC_CODEC_DAALA )
+ if( p_stream->fmt.i_codec == VLC_CODEC_VORBIS ||
+ p_stream->fmt.i_codec == VLC_CODEC_SPEEX ||
+ p_stream->fmt.i_codec == VLC_CODEC_OPUS ||
+ p_stream->fmt.i_codec == VLC_CODEC_THEORA ||
+ p_stream->fmt.i_codec == VLC_CODEC_DAALA )
{
/* First packet in order: vorbis/speex/opus/theora/daala info */
unsigned pi_size[XIPH_MAX_HEADER_COUNT];
@@ -1043,14 +1047,14 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
/* Get keyframe_granule_shift for theora or daala granulepos calculation */
- if( p_stream->i_fourcc == VLC_CODEC_THEORA ||
- p_stream->i_fourcc == VLC_CODEC_DAALA )
+ if( p_stream->fmt.i_codec == VLC_CODEC_THEORA ||
+ p_stream->fmt.i_codec == VLC_CODEC_DAALA )
{
p_stream->i_keyframe_granule_shift =
( (op.packet[40] & 0x03) << 3 ) | ( (op.packet[41] & 0xe0) >> 5 );
}
}
- else if( p_stream->i_fourcc == VLC_CODEC_DIRAC )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_DIRAC )
{
op.packet = p_input->p_fmt->p_extra;
op.bytes = p_input->p_fmt->i_extra;
@@ -1061,7 +1065,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
- else if( p_stream->i_fourcc == VLC_CODEC_FLAC )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_FLAC )
{
/* flac stream marker (yeah, only that in the 1st packet) */
op.packet = (unsigned char *)"fLaC";
@@ -1073,7 +1077,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
- else if( p_stream->i_fourcc == VLC_CODEC_VP8 )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_VP8 )
{
/* VP8 Header */
op.packet = malloc( 26 );
@@ -1095,7 +1099,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
op.packet = malloc( sizeof(*p_stream->p_oggds_header) + p_stream->p_oggds_header->i_size );
if( !op.packet )
return false;
- op.bytes = OggFillDsHeader( op.packet, p_stream->p_oggds_header, p_stream->i_cat );
+ op.bytes = OggFillDsHeader( op.packet, p_stream->p_oggds_header, p_stream->fmt.i_cat );
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
@@ -1179,11 +1183,11 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
sout_input_t *p_input = p_mux->pp_inputs[i];
ogg_stream_t *p_stream = (ogg_stream_t*)p_input->p_sys;
- if( p_stream->i_fourcc == VLC_CODEC_VORBIS ||
- p_stream->i_fourcc == VLC_CODEC_SPEEX ||
- p_stream->i_fourcc == VLC_CODEC_OPUS ||
- p_stream->i_fourcc == VLC_CODEC_THEORA ||
- p_stream->i_fourcc == VLC_CODEC_DAALA )
+ if( p_stream->fmt.i_codec == VLC_CODEC_VORBIS ||
+ p_stream->fmt.i_codec == VLC_CODEC_SPEEX ||
+ p_stream->fmt.i_codec == VLC_CODEC_OPUS ||
+ p_stream->fmt.i_codec == VLC_CODEC_THEORA ||
+ p_stream->fmt.i_codec == VLC_CODEC_DAALA )
{
unsigned pi_size[XIPH_MAX_HEADER_COUNT];
void *pp_data[XIPH_MAX_HEADER_COUNT];
@@ -1215,8 +1219,8 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
block_ChainAppend( &p_hdr, p_og );
}
}
- else if( p_stream->i_fourcc != VLC_CODEC_FLAC &&
- p_stream->i_fourcc != VLC_CODEC_DIRAC )
+ else if( p_stream->fmt.i_codec != VLC_CODEC_FLAC &&
+ p_stream->fmt.i_codec != VLC_CODEC_DIRAC )
{
uint8_t com[128];
int i_com;
@@ -1238,8 +1242,8 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
}
/* Special case for mp4v and flac */
- if( ( p_stream->i_fourcc == VLC_CODEC_MP4V ||
- p_stream->i_fourcc == VLC_CODEC_FLAC ) &&
+ if( ( p_stream->fmt.i_codec == VLC_CODEC_MP4V ||
+ p_stream->fmt.i_codec == VLC_CODEC_FLAC ) &&
p_input->p_fmt->i_extra )
{
/* Send a packet with the VOL data for mp4v
@@ -1248,7 +1252,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
op.bytes = p_input->p_fmt->i_extra;
op.packet = p_input->p_fmt->p_extra;
uint8_t flac_streaminfo[34 + 4];
- if( p_stream->i_fourcc == VLC_CODEC_FLAC )
+ if( p_stream->fmt.i_codec == VLC_CODEC_FLAC )
{
if (op.bytes == 42 && !memcmp(op.packet, "fLaC", 4)) {
op.bytes -= 4;
@@ -1581,20 +1585,20 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
ogg_packet op;
uint64_t i_time;
- if( p_stream->i_fourcc != VLC_CODEC_VORBIS &&
- p_stream->i_fourcc != VLC_CODEC_FLAC &&
- p_stream->i_fourcc != VLC_CODEC_SPEEX &&
- p_stream->i_fourcc != VLC_CODEC_OPUS &&
- p_stream->i_fourcc != VLC_CODEC_THEORA &&
- p_stream->i_fourcc != VLC_CODEC_DAALA &&
- p_stream->i_fourcc != VLC_CODEC_VP8 &&
- p_stream->i_fourcc != VLC_CODEC_DIRAC )
+ if( p_stream->fmt.i_codec != VLC_CODEC_VORBIS &&
+ p_stream->fmt.i_codec != VLC_CODEC_FLAC &&
+ p_stream->fmt.i_codec != VLC_CODEC_SPEEX &&
+ p_stream->fmt.i_codec != VLC_CODEC_OPUS &&
+ p_stream->fmt.i_codec != VLC_CODEC_THEORA &&
+ p_stream->fmt.i_codec != VLC_CODEC_DAALA &&
+ p_stream->fmt.i_codec != VLC_CODEC_VP8 &&
+ p_stream->fmt.i_codec != VLC_CODEC_DIRAC )
{
p_data = block_Realloc( p_data, 1, p_data->i_buffer );
p_data->p_buffer[0] = PACKET_IS_SYNCPOINT; // FIXME
}
- if ( p_stream->i_fourcc == VLC_CODEC_DIRAC && p_stream->i_baseptsdelay < 0 )
+ if ( p_stream->fmt.i_codec == VLC_CODEC_DIRAC && p_stream->i_baseptsdelay < 0 )
p_stream->i_baseptsdelay = p_data->i_pts - p_data->i_dts;
op.packet = p_data->p_buffer;
@@ -1604,12 +1608,12 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
op.packetno = p_stream->i_packet_no++;
op.granulepos = -1;
- if( p_stream->i_cat == AUDIO_ES )
+ if( p_stream->fmt.i_cat == AUDIO_ES )
{
- if( p_stream->i_fourcc == VLC_CODEC_VORBIS ||
- p_stream->i_fourcc == VLC_CODEC_FLAC ||
- p_stream->i_fourcc == VLC_CODEC_OPUS ||
- p_stream->i_fourcc == VLC_CODEC_SPEEX )
+ if( p_stream->fmt.i_codec == VLC_CODEC_VORBIS ||
+ p_stream->fmt.i_codec == VLC_CODEC_FLAC ||
+ p_stream->fmt.i_codec == VLC_CODEC_OPUS ||
+ p_stream->fmt.i_codec == VLC_CODEC_SPEEX )
{
/* number of sample from begining + current packet */
op.granulepos =
@@ -1626,10 +1630,10 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
p_stream->p_oggds_header->i_samples_per_unit / CLOCK_FREQ;
}
}
- else if( p_stream->i_cat == VIDEO_ES )
+ else if( p_stream->fmt.i_cat == VIDEO_ES )
{
- if( p_stream->i_fourcc == VLC_CODEC_THEORA ||
- p_stream->i_fourcc == VLC_CODEC_DAALA )
+ if( p_stream->fmt.i_codec == VLC_CODEC_THEORA ||
+ p_stream->fmt.i_codec == VLC_CODEC_DAALA )
{
p_stream->i_num_frames++;
if( p_data->i_flags & BLOCK_FLAG_TYPE_I )
@@ -1646,7 +1650,7 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
op.granulepos = (p_stream->i_last_keyframe << p_stream->i_keyframe_granule_shift )
| (p_stream->i_num_frames-p_stream->i_last_keyframe);
}
- else if( p_stream->i_fourcc == VLC_CODEC_DIRAC )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_DIRAC )
{
#define FRAME_ROUND(a) \
@@ -1697,7 +1701,7 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
AddIndexEntry( p_mux, dt, p_input );
}
- else if( p_stream->i_fourcc == VLC_CODEC_VP8 )
+ else if( p_stream->fmt.i_codec == VLC_CODEC_VP8 )
{
p_stream->i_num_frames++;
if( p_data->i_flags & BLOCK_FLAG_TYPE_I )
@@ -1717,7 +1721,7 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
op.granulepos = ( p_data->i_dts - p_sys->i_start_dts ) * INT64_C(10) /
p_stream->p_oggds_header->i_time_unit;
}
- else if( p_stream->i_cat == SPU_ES )
+ else if( p_stream->fmt.i_cat == SPU_ES )
{
/* granulepos is in millisec */
op.granulepos = ( p_data->i_dts - p_sys->i_start_dts ) / 1000;
@@ -1728,9 +1732,9 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
p_stream->u_last_granulepos = op.granulepos;
ogg_stream_packetin( &p_stream->os, &op );
- if( p_stream->i_cat == SPU_ES ||
- p_stream->i_fourcc == VLC_CODEC_SPEEX ||
- p_stream->i_fourcc == VLC_CODEC_DIRAC )
+ if( p_stream->fmt.i_cat == SPU_ES ||
+ p_stream->fmt.i_codec == VLC_CODEC_SPEEX ||
+ p_stream->fmt.i_codec == VLC_CODEC_DIRAC )
{
/* Subtitles or Speex packets are quite small so they
* need to be flushed to be sent on time */
More information about the vlc-commits
mailing list