Commit 6a735f6e authored by Filip Roséen's avatar Filip Roséen Committed by Jean-Baptiste Kempf

mkv: Use StringDispatcher in matroska_segment_c::TrackInit

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 4a80d93f
......@@ -27,6 +27,7 @@
#include "demux.hpp"
#include "Ebml_parser.hpp"
#include "Ebml_dispatcher.hpp"
#include "string_dispatcher.hpp"
#include "util.hpp"
extern "C" {
......@@ -37,6 +38,7 @@ extern "C" {
}
#include <vlc_codecs.h>
#include <stdexcept>
/* GetFourCC helper */
#define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
......@@ -710,7 +712,7 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
{
msg_Err( &sys.demuxer, "Couldn't read info" );
return;
}
}
struct InfoHandlerPayload {
demux_t * p_demuxer;
......@@ -1193,8 +1195,6 @@ void matroska_segment_c::ParseCluster( KaxCluster *cluster, bool b_update_start_
int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
{
es_format_t *p_fmt = &p_tk->fmt;
if( p_tk->psz_codec == NULL )
{
msg_Err( &sys.demuxer, "Empty codec id" );
......@@ -1202,555 +1202,554 @@ int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
return 0;
}
if( !strcmp( p_tk->psz_codec, "V_MS/VFW/FOURCC" ) )
{
if( p_tk->i_extra_data < (int)sizeof( VLC_BITMAPINFOHEADER ) )
{
msg_Err( &sys.demuxer, "missing/invalid VLC_BITMAPINFOHEADER" );
p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
}
else
{
VLC_BITMAPINFOHEADER *p_bih = (VLC_BITMAPINFOHEADER*)p_tk->p_extra_data;
struct HandlerPayload {
matroska_segment_c * obj;
mkv_track_t * p_tk;
es_format_t * p_fmt;
demux_t * p_demuxer;
} captures = {
this, p_tk, &p_tk->fmt, &sys.demuxer
};
p_tk->fmt.video.i_width = GetDWLE( &p_bih->biWidth );
p_tk->fmt.video.i_height= GetDWLE( &p_bih->biHeight );
p_tk->fmt.i_codec = GetFOURCC( &p_bih->biCompression );
MKV_SWITCH_CREATE( StringDispatcher, TrackCodecHandlers, HandlerPayload )
{
MKV_SWITCH_INIT();
p_tk->fmt.i_extra = GetDWLE( &p_bih->biSize ) - sizeof( VLC_BITMAPINFOHEADER );
if( p_tk->fmt.i_extra > 0 )
S_CASE("V_MS/VFW/FOURCC") {
if( vars.p_tk->i_extra_data < (int)sizeof( VLC_BITMAPINFOHEADER ) )
{
/* Very unlikely yet possible: bug #5659*/
size_t maxlen = p_tk->i_extra_data - sizeof( VLC_BITMAPINFOHEADER );
p_tk->fmt.i_extra = ( (unsigned)p_tk->fmt.i_extra < maxlen )?
p_tk->fmt.i_extra : maxlen;
p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
memcpy( p_tk->fmt.p_extra, &p_bih[1], p_tk->fmt.i_extra );
msg_Err(vars.p_demuxer, "missing/invalid VLC_BITMAPINFOHEADER" );
vars.p_fmt->i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
}
}
p_tk->b_dts_only = true;
}
else if( !strcmp( p_tk->psz_codec, "V_MPEG1" ) ||
!strcmp( p_tk->psz_codec, "V_MPEG2" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_MPGV;
if( p_tk->i_extra_data )
fill_extra_data( p_tk, 0 );
}
else if( !strncmp( p_tk->psz_codec, "V_THEORA", 8 ) )
{
p_tk->fmt.i_codec = VLC_CODEC_THEORA;
fill_extra_data( p_tk, 0 );
p_tk->b_pts_only = true;
}
else if( !strncmp( p_tk->psz_codec, "V_REAL/RV", 9 ) )
{
uint8_t *p = p_tk->p_extra_data;
if( !strcmp( p_tk->psz_codec, "V_REAL/RV10" ) )
p_fmt->i_codec = VLC_CODEC_RV10;
else if( !strcmp( p_tk->psz_codec, "V_REAL/RV20" ) )
p_fmt->i_codec = VLC_CODEC_RV20;
else if( !strcmp( p_tk->psz_codec, "V_REAL/RV30" ) )
p_fmt->i_codec = VLC_CODEC_RV30;
else if( !strcmp( p_tk->psz_codec, "V_REAL/RV40" ) )
p_fmt->i_codec = VLC_CODEC_RV40;
/* Extract the framerate from the header */
if( p_tk->i_extra_data >= 26 &&
p[4] == 'V' && p[5] == 'I' && p[6] == 'D' && p[7] == 'O' &&
p[8] == 'R' && p[9] == 'V' &&
(p[10] == '3' || p[10] == '4') && p[11] == '0' )
{
p_tk->fmt.video.i_frame_rate =
p[22] << 24 | p[23] << 16 | p[24] << 8 | p[25] << 0;
p_tk->fmt.video.i_frame_rate_base = 65536;
}
fill_extra_data( p_tk, 26 );
p_tk->b_dts_only = true;
}
else if( !strncmp( p_tk->psz_codec, "V_DIRAC", 7 ) )
{
p_tk->fmt.i_codec = VLC_CODEC_DIRAC;
}
else if( !strncmp( p_tk->psz_codec, "V_VP8", 5 ) )
{
p_tk->fmt.i_codec = VLC_CODEC_VP8;
p_tk->b_pts_only = true;
}
else if( !strncmp( p_tk->psz_codec, "V_VP9", 5 ) )
{
p_tk->fmt.i_codec = VLC_CODEC_VP9;
p_tk->fmt.b_packetized = false;
p_tk->b_pts_only = true;
fill_extra_data( p_tk, 0 );
}
else if( !strncmp( p_tk->psz_codec, "V_MPEG4", 7 ) )
{
if( !strcmp( p_tk->psz_codec, "V_MPEG4/MS/V3" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_DIV3;
}
else if( !strncmp( p_tk->psz_codec, "V_MPEG4/ISO", 11 ) )
{
/* A MPEG 4 codec, SP, ASP, AP or AVC */
if( !strcmp( p_tk->psz_codec, "V_MPEG4/ISO/AVC" ) )
p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'v', 'c', '1' );
else
p_tk->fmt.i_codec = VLC_CODEC_MP4V;
fill_extra_data( p_tk, 0 );
}
}
else if( !strncmp( p_tk->psz_codec, "V_MPEGH/ISO/HEVC", 16) )
{
p_tk->fmt.i_codec = VLC_CODEC_HEVC;
fill_extra_data( p_tk, 0 );
}
else if( !strcmp( p_tk->psz_codec, "V_QUICKTIME" ) )
{
MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
p_tk->p_extra_data,
p_tk->i_extra_data,
true );
if( MP4_PeekBoxHeader( p_mp4_stream, p_box ) &&
MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
{
p_tk->fmt.i_codec = p_box->i_type;
uint32_t i_width = p_box->data.p_sample_vide->i_width;
uint32_t i_height = p_box->data.p_sample_vide->i_height;
if( i_width && i_height )
{
p_tk->fmt.video.i_width = i_width;
p_tk->fmt.video.i_height = i_height;
VLC_BITMAPINFOHEADER *p_bih = (VLC_BITMAPINFOHEADER*)vars.p_tk->p_extra_data;
vars.p_fmt->video.i_width = GetDWLE( &p_bih->biWidth );
vars.p_fmt->video.i_height= GetDWLE( &p_bih->biHeight );
vars.p_fmt->i_codec = GetFOURCC( &p_bih->biCompression );
vars.p_fmt->i_extra = GetDWLE( &p_bih->biSize ) - sizeof( VLC_BITMAPINFOHEADER );
if( vars.p_fmt->i_extra > 0 )
{
/* Very unlikely yet possible: bug #5659*/
size_t maxlen = vars.p_tk->i_extra_data - sizeof( VLC_BITMAPINFOHEADER );
vars.p_fmt->i_extra = ( (unsigned)vars.p_fmt->i_extra < maxlen )?
vars.p_fmt->i_extra : maxlen;
vars.p_fmt->p_extra = xmalloc( vars.p_fmt->i_extra );
memcpy( vars.p_fmt->p_extra, &p_bih[1], vars.p_fmt->i_extra );
}
}
p_tk->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description;
p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
memcpy( p_tk->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, p_tk->fmt.i_extra );
MP4_FreeBox_sample_vide( p_box );
vars.p_tk->b_dts_only = true;
}
else
{
free( p_box );
S_CASE("V_MPEG1") {
vars.p_fmt->i_codec = VLC_CODEC_MPGV;
fill_extra_data( vars.p_tk, 0 );
}
stream_Delete( p_mp4_stream );
}
else if( !strcmp( p_tk->psz_codec, "V_MJPEG" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_MJPG;
}
else if( !strcmp( p_tk->psz_codec, "A_MS/ACM" ) )
{
if( p_tk->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
{
msg_Err( &sys.demuxer, "missing/invalid WAVEFORMATEX" );
p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
S_CASE("V_MPEG2") {
vars.p_fmt->i_codec = VLC_CODEC_MPGV;
fill_extra_data( vars.p_tk, 0 );
}
else
S_CASE("V_THEORA") {
vars.p_fmt->i_codec = VLC_CODEC_THEORA;
vars.p_tk->b_pts_only = true;
fill_extra_data( vars.p_tk, 0 );
}
static void v_real_helper (vlc_fourcc_t codec, HandlerPayload& vars)
{
WAVEFORMATEX *p_wf = (WAVEFORMATEX*)p_tk->p_extra_data;
vars.p_tk->b_dts_only = true;
vars.p_fmt->i_codec = codec;
p_tk->fmt.audio.i_channels = GetWLE( &p_wf->nChannels );
p_tk->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
p_tk->fmt.i_bitrate = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
p_tk->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
p_tk->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
/* Extract the framerate from the header */
uint8_t *p = vars.p_tk->p_extra_data;
p_tk->fmt.i_extra = GetWLE( &p_wf->cbSize );
if( p_tk->fmt.i_extra > 0 )
if (
vars.p_tk->i_extra_data >= 26 && !memcmp(p+4, "VIDORV", 6) && strchr("34", p[10]) && p[11] == '0')
{
p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
if( p_tk->fmt.p_extra )
memcpy( p_tk->fmt.p_extra, &p_wf[1], p_tk->fmt.i_extra );
else
p_tk->fmt.i_extra = 0;
vars.p_tk->fmt.video.i_frame_rate = p[22] << 24 | p[23] << 16 | p[24] << 8 | p[25] << 0;
vars.p_tk->fmt.video.i_frame_rate_base = 65536;
}
if( p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
p_tk->i_extra_data >= sizeof(WAVEFORMATEXTENSIBLE) )
fill_extra_data( vars.p_tk, 26 );
}
S_CASE("V_REAL/RV10") { v_real_helper (VLC_CODEC_RV10, vars ); }
S_CASE("V_REAL/RV20") { v_real_helper (VLC_CODEC_RV20, vars ); }
S_CASE("V_REAL/RV30") { v_real_helper (VLC_CODEC_RV30, vars ); }
S_CASE("V_REAL/RV40") { v_real_helper (VLC_CODEC_RV40, vars ); }
S_CASE("V_DIRAC") {
vars.p_fmt->i_codec = VLC_CODEC_DIRAC;
}
S_CASE("V_VP8") {
vars.p_fmt->i_codec = VLC_CODEC_VP8;
vars.p_tk->b_pts_only = true;
}
S_CASE("V_VP9") {
vars.p_fmt->i_codec = VLC_CODEC_VP9;
vars.p_fmt->b_packetized = false;
vars.p_tk->b_pts_only = true;
fill_extra_data( vars.p_tk, 0 );
}
S_CASE("V_MPEG4/MS/V3") {
vars.p_fmt->i_codec = VLC_CODEC_DIV3;
}
S_CASE("V_MPEG4/ISO/AVC") {
vars.p_fmt->i_codec = VLC_FOURCC( 'a','v','c','1' );
fill_extra_data( vars.p_tk, 0 );
}
S_CASE_GLOB("V_MPEG4/ISO*") {
vars.p_fmt->i_codec = VLC_CODEC_MP4V;
fill_extra_data( vars.p_tk, 0 );
}
S_CASE("V_MPEGH/ISO/HEVC") {
vars.p_tk->fmt.i_codec = VLC_CODEC_HEVC;
fill_extra_data( vars.p_tk, 0 );
}
S_CASE("V_QUICKTIME") {
MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(vars.p_demuxer),
vars.p_tk->p_extra_data,
vars.p_tk->i_extra_data,
true );
if( MP4_PeekBoxHeader( p_mp4_stream, p_box ) &&
MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
{
WAVEFORMATEXTENSIBLE * p_wext = (WAVEFORMATEXTENSIBLE*) p_wf;
sf_tag_to_fourcc( &p_wext->SubFormat, &p_tk->fmt.i_codec, NULL);
/* FIXME should we use Samples */
vars.p_fmt->i_codec = p_box->i_type;
uint32_t i_width = p_box->data.p_sample_vide->i_width;
uint32_t i_height = p_box->data.p_sample_vide->i_height;
if( i_width && i_height )
{
vars.p_tk->fmt.video.i_width = i_width;
vars.p_tk->fmt.video.i_height = i_height;
}
vars.p_fmt->i_extra = p_box->data.p_sample_vide->i_qt_image_description;
vars.p_fmt->p_extra = xmalloc( vars.p_fmt->i_extra );
memcpy( vars.p_fmt->p_extra, p_box->data.p_sample_vide->p_qt_image_description, vars.p_fmt->i_extra );
MP4_FreeBox_sample_vide( p_box );
}
else
{
free( p_box );
}
stream_Delete( p_mp4_stream );
}
S_CASE("V_MJPEG") {
vars.p_fmt->i_codec = VLC_CODEC_MJPG;
}
S_CASE("A_MS/ACM") {
mkv_track_t * p_tk = vars.p_tk;
es_format_t * p_fmt = &vars.p_tk->fmt;
if( p_tk->fmt.audio.i_channels > 2 &&
( p_tk->fmt.i_codec != VLC_FOURCC( 'u', 'n', 'd', 'f' ) ) )
if( p_tk->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
{
msg_Err( vars.p_demuxer, "missing/invalid WAVEFORMATEX" );
p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
}
else
{
WAVEFORMATEX *p_wf = (WAVEFORMATEX*)p_tk->p_extra_data;
p_tk->fmt.audio.i_channels = GetWLE( &p_wf->nChannels );
p_tk->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
p_tk->fmt.i_bitrate = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
p_tk->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
p_tk->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
p_tk->fmt.i_extra = GetWLE( &p_wf->cbSize );
if( p_tk->fmt.i_extra > 0 )
{
uint32_t wfextcm = GetDWLE( &p_wext->dwChannelMask );
int match;
unsigned i_channel_mask = getChannelMask( &wfextcm,
p_tk->fmt.audio.i_channels,
&match );
p_tk->fmt.i_codec = vlc_fourcc_GetCodecAudio( p_tk->fmt.i_codec,
p_tk->fmt.audio.i_bitspersample );
if( i_channel_mask )
{
p_tk->i_chans_to_reorder = aout_CheckChannelReorder(
pi_channels_aout, NULL,
i_channel_mask,
p_tk->pi_chan_table );
p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
if( p_tk->fmt.p_extra )
memcpy( p_tk->fmt.p_extra, &p_wf[1], p_tk->fmt.i_extra );
else
p_tk->fmt.i_extra = 0;
}
p_tk->fmt.audio.i_physical_channels =
p_tk->fmt.audio.i_original_channels = i_channel_mask;
if( p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
p_tk->i_extra_data >= sizeof(WAVEFORMATEXTENSIBLE) )
{
WAVEFORMATEXTENSIBLE * p_wext = (WAVEFORMATEXTENSIBLE*) p_wf;
sf_tag_to_fourcc( &p_wext->SubFormat, &p_tk->fmt.i_codec, NULL);
/* FIXME should we use Samples */
if( p_tk->fmt.audio.i_channels > 2 &&
( p_tk->fmt.i_codec != VLC_FOURCC( 'u', 'n', 'd', 'f' ) ) )
{
uint32_t wfextcm = GetDWLE( &p_wext->dwChannelMask );
int match;
unsigned i_channel_mask = getChannelMask( &wfextcm,
p_tk->fmt.audio.i_channels,
&match );
p_tk->fmt.i_codec = vlc_fourcc_GetCodecAudio( p_tk->fmt.i_codec,
p_tk->fmt.audio.i_bitspersample );
if( i_channel_mask )
{
p_tk->i_chans_to_reorder = aout_CheckChannelReorder(
pi_channels_aout, NULL,
i_channel_mask,
p_tk->pi_chan_table );
p_tk->fmt.audio.i_physical_channels =
p_tk->fmt.audio.i_original_channels = i_channel_mask;
}
}
}
else
wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_tk->fmt.i_codec, NULL );
if( p_tk->fmt.i_codec == VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
msg_Err( vars.p_demuxer, "Unrecognized wf tag: 0x%x", GetWLE( &p_wf->wFormatTag ) );
}
p_fmt->b_packetized = !p_fmt->audio.i_blockalign;
}
static void A_MPEG_helper_ (HandlerPayload& vars) {
vars.p_tk->fmt.i_codec = VLC_CODEC_MPGA;
vars.p_fmt->b_packetized = false;
}
S_CASE("A_MPEG/L3") { A_MPEG_helper_(vars); }
S_CASE("A_MPEG/L2") { A_MPEG_helper_(vars); }
S_CASE("A_MPEG/L1") { A_MPEG_helper_(vars); }
S_CASE("A_AC3") {
// the AC-3 default duration cannot be trusted, see #8512
if ( vars.p_tk->fmt.audio.i_rate == 8000 )
{
vars.p_tk->b_no_duration = true;
vars.p_tk->i_default_duration = 0;
}
else
wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_tk->fmt.i_codec, NULL );
if( p_tk->fmt.i_codec == VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
msg_Err( &sys.demuxer, "Unrecognized wf tag: 0x%x", GetWLE( &p_wf->wFormatTag ) );
vars.p_fmt->i_codec = VLC_CODEC_A52;
}
p_fmt->b_packetized = !p_fmt->audio.i_blockalign;
}
else if( !strcmp( p_tk->psz_codec, "A_MPEG/L3" ) ||
!strcmp( p_tk->psz_codec, "A_MPEG/L2" ) ||
!strcmp( p_tk->psz_codec, "A_MPEG/L1" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_MPGA;
p_fmt->b_packetized = false;
}
else if( !strcmp( p_tk->psz_codec, "A_AC3" ) )
{
// the AC-3 default duration cannot be trusted, see #8512
if ( p_tk->fmt.audio.i_rate == 8000 )
{
p_tk->b_no_duration = true;
p_tk->i_default_duration = 0;
S_CASE("A_EAC3") { vars.p_fmt->i_codec = VLC_CODEC_EAC3; }
S_CASE("A_DTS") { vars.p_fmt->i_codec = VLC_CODEC_DTS; }
S_CASE("A_MLP") { vars.p_fmt->i_codec = VLC_CODEC_MLP; }
S_CASE("A_TRUEHD") { /* FIXME when more samples arrive */
vars.p_fmt->i_codec = VLC_CODEC_TRUEHD;
vars.p_fmt->b_packetized = false;
}
p_tk->fmt.i_codec = VLC_CODEC_A52;
}
else if( !strcmp( p_tk->psz_codec, "A_EAC3" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_EAC3;
}
else if( !strcmp( p_tk->psz_codec, "A_DTS" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_DTS;
}
else if( !strcmp( p_tk->psz_codec, "A_MLP" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_MLP;
}
else if( !strcmp( p_tk->psz_codec, "A_TRUEHD" ) )
{
/* FIXME when more samples arrive */
p_tk->fmt.i_codec = VLC_CODEC_TRUEHD;
p_fmt->b_packetized = false;
}
else if( !strcmp( p_tk->psz_codec, "A_FLAC" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_FLAC;
fill_extra_data( p_tk, 8 );
}
else if( !strcmp( p_tk->psz_codec, "A_VORBIS" ) )
{
p_tk->fmt.i_codec = VLC_CODEC_VORBIS;
fill_extra_data( p_tk, 0 );
}
else if( !strncmp( p_tk->psz_codec, "A_OPUS", 6 ) )
{
p_tk->fmt.i_codec = VLC_CODEC_OPUS;
if( !p_tk->fmt.audio.i_rate )
{
msg_Err( &sys.demuxer,"No sampling rate, defaulting to 48kHz");
p_tk->fmt.audio.i_rate = 48000;
S_CASE("A_FLAC") {
vars.p_fmt->i_codec = VLC_CODEC_FLAC;
fill_extra_data( vars.p_tk, 0 );
}
S_CASE("A_VORBIS") {
vars.p_fmt->i_codec = VLC_CODEC_VORBIS;
fill_extra_data( vars.p_tk, 0 );
}
const uint8_t tags[16] = {'O','p','u','s','T','a','g','s',
0, 0, 0, 0, 0, 0, 0, 0};
unsigned ps[2] = { p_tk->i_extra_data, 16 };
const void *pkt[2] = { static_cast<const void *>( p_tk->p_extra_data ),
static_cast<const void *>( tags ) };
S_CASE("A_OPUS") {
vars.p_fmt->i_codec = VLC_CODEC_OPUS;
if( !vars.p_tk->fmt.audio.i_rate )
{
msg_Err( vars.p_demuxer,"No sampling rate, defaulting to 48kHz");
vars.p_fmt->audio.i_rate = 48000;
}
const uint8_t tags[16] = {'O','p','u','s','T','a','g','s',
0, 0, 0, 0, 0, 0, 0, 0};
unsigned ps[2] = { vars.p_tk->i_extra_data, 16 };
const void *pkt[2] = { static_cast<const void *>( vars.p_tk->p_extra_data ),
static_cast<const void *>( tags ) };
if( xiph_PackHeaders( &p_tk->fmt.i_extra,
&p_tk->fmt.p_extra,
ps, pkt, 2 ) )
msg_Err( &sys.demuxer, "Couldn't pack OPUS headers");
if( xiph_PackHeaders( &vars.p_fmt->i_extra,
&vars.p_fmt->p_extra,
ps, pkt, 2 ) )
msg_Err( vars.p_demuxer, "Couldn't pack OPUS headers");
}
static void A_AAC_MPEG__helper(HandlerPayload& vars, int i_profile, bool sbr = false) {
int i_srate;
}
else if( !strncmp( p_tk->psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
!strncmp( p_tk->psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
{
int i_profile, i_srate, sbr = 0;
static const unsigned int i_sample_rates[] =
{
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 7350, 0, 0, 0
};
mkv_track_t * p_tk = vars.p_tk;
p_tk->fmt.i_codec = VLC_CODEC_MP4A;
/* create data for faad (MP4DecSpecificDescrTag)*/
static const unsigned int i_sample_rates[] =
{
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 7350, 0, 0, 0
};
p_tk->fmt.i_codec = VLC_CODEC_MP4A;
for( i_srate = 0; i_srate < 13; i_srate++ )
{
if( i_sample_rates[i_srate] == p_tk->i_original_rate )
break;
}
msg_Dbg (vars.p_demuxer, "profile=%d srate=%d", i_profile, i_srate );
p_tk->fmt.i_extra = sbr ? 5 : 2;
p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
((uint8_t*)p_tk->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
((uint8_t*)p_tk->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (p_tk->fmt.audio.i_channels << 3);
if (sbr) {
int syncExtensionType = 0x2B7;
int iDSRI;
for (iDSRI=0; iDSRI<13; iDSRI++)
if( i_sample_rates[iDSRI] == p_tk->fmt.audio.i_rate )
break;
((uint8_t*)p_tk->fmt.p_extra)[2] = (syncExtensionType >> 3) & 0xFF;
((uint8_t*)p_tk->fmt.p_extra)[3] = ((syncExtensionType & 0x7) << 5) | 5;
((uint8_t*)p_tk->fmt.p_extra)[4] = ((1 & 0x1) << 7) | (iDSRI << 3);
}
if( !strcmp( &p_tk->psz_codec[12], "MAIN" ) )
{
i_profile = 0;
}
else if( !strcmp( &p_tk->psz_codec[12], "LC" ) )
{
i_profile = 1;
S_CASE("A_AAC/MPEG2/MAIN") { A_AAC_MPEG__helper( vars, 0 ); }
S_CASE("A_AAC/MPEG4/MAIN") { A_AAC_MPEG__helper( vars, 0 ); }
S_CASE("A_AAC/MPEG2/LC") { A_AAC_MPEG__helper( vars, 1 ); }
S_CASE("A_AAC/MPEG4/LC") { A_AAC_MPEG__helper( vars, 1 ); }
S_CASE("A_AAC/MPEG2/SSR") { A_AAC_MPEG__helper( vars, 2 ); }
S_CASE("A_AAC/MPEG4/SSR") { A_AAC_MPEG__helper( vars, 2 ); }
S_CASE("A_AAC/MPEG4/LTP") { A_AAC_MPEG__helper( vars, 3 ); }
S_CASE("A_AAC/MPEG2/LC/SBR") { A_AAC_MPEG__helper( vars, 1, true ); }
S_CASE(