Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
audioes: add stream type / index filtering
  • Loading branch information
perexg committed Oct 6, 2016
1 parent 55085b2 commit b848597
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/muxer.h
Expand Up @@ -60,6 +60,9 @@ typedef struct muxer_config {
int m_rewrite_eit;
int m_cache;

int m_force_type;
int m_index;

/*
* directory_permissions should really be in dvr.h as it's not really needed for the muxer
* but it's kept with file_permissions for neatness
Expand Down
54 changes: 39 additions & 15 deletions src/muxer/muxer_audioes.c
Expand Up @@ -47,29 +47,44 @@ typedef struct audioes_muxer {
} audioes_muxer_t;


/**
*
*/
static int
audioes_muxer_type(streaming_component_type_t type)
{
muxer_container_type_t mc = MC_UNKNOWN;
switch (type) {
case SCT_MPEG2AUDIO: mc = MC_MPEG2AUDIO; break;
case SCT_AC3: mc = MC_AC3; break;
case SCT_EAC3: mc = MC_AC3; break;
case SCT_AAC: mc = MC_AAC; break;
case SCT_MP4A: mc = MC_MP4A; break;
case SCT_VORBIS: mc = MC_VORBIS; break;
default: break;
}
return mc;
}


/**
* Figure out the mimetype
*/
static const char *
audioes_muxer_mime(muxer_t* m, const struct streaming_start *ss)
audioes_muxer_mime(muxer_t *m, const struct streaming_start *ss)
{
int i;
muxer_container_type_t mc = MC_UNKNOWN;
const streaming_start_component_t *ssc;


if (m->m_config.m_force_type != MC_UNKNOWN)
return muxer_container_type2mime(m->m_config.m_force_type, 0);

for (i = 0; i < ss->ss_num_components; i++) {
ssc = &ss->ss_components[i];
if (ssc->ssc_disabled)
continue;
switch (ssc->ssc_type) {
case SCT_MPEG2AUDIO: mc = MC_MPEG2AUDIO; break;
case SCT_AC3: mc = MC_AC3; break;
case SCT_EAC3: mc = MC_AC3; break;
case SCT_AAC: mc = MC_AAC; break;
case SCT_MP4A: mc = MC_MP4A; break;
case SCT_VORBIS: mc = MC_VORBIS; break;
default: break;
}
mc = audioes_muxer_type(ssc->ssc_type);
break;
}

Expand All @@ -81,20 +96,29 @@ audioes_muxer_mime(muxer_t* m, const struct streaming_start *ss)
* Reconfigure the muxer
*/
static int
audioes_muxer_reconfigure(muxer_t* m, const struct streaming_start *ss)
audioes_muxer_reconfigure(muxer_t *m, const struct streaming_start *ss)
{
audioes_muxer_t *am = (audioes_muxer_t*)m;
const streaming_start_component_t *ssc;
int i;
muxer_container_type_t mc;
int i, count = 0;

am->am_index = -1;

for (i = 0; i < ss->ss_num_components;i++) {
ssc = &ss->ss_components[i];

if ((!ssc->ssc_disabled) && (SCT_ISAUDIO(ssc->ssc_type))) {
am->am_index = ssc->ssc_index;
break;
if (m->m_config.m_force_type != MC_UNKNOWN) {
mc = audioes_muxer_type(ssc->ssc_type);
if (m->m_config.m_force_type != mc)
continue;
}
if (m->m_config.m_index == count) {
am->am_index = ssc->ssc_index;
break;
}
count++;
}
}

Expand Down
47 changes: 41 additions & 6 deletions src/profile.c
Expand Up @@ -1300,14 +1300,47 @@ profile_matroska_builder(void)
*/
typedef struct profile_audio {
profile_t;
int pro_mc;
int pro_index;
} profile_audio_t;

static htsmsg_t *
profile_class_mc_audio_list ( void *o, const char *lang )
{
static const struct strtab tab[] = {
{ N_("Any"), MC_UNKNOWN },
{ N_("MPEG-2 audio"), MC_MPEG2AUDIO, },
{ N_("AC3 audio"), MC_AC3, },
{ N_("AAC audio"), MC_AAC },
{ N_("MP4 audio"), MC_MP4A },
{ N_("Vorbis audio"), MC_VORBIS },
};
return strtab2htsmsg(tab, 1, lang);
}

const idclass_t profile_audio_class =
{
.ic_super = &profile_class,
.ic_class = "profile-audio",
.ic_caption = N_("Audio stream"),
.ic_properties = (const property_t[]){
{
.type = PT_INT,
.id = "type",
.name = N_("Audio type"),
.desc = N_("Pick the stream with given audio type only."),
.off = offsetof(profile_audio_t, pro_mc),
.list = profile_class_mc_audio_list,
.group = 1
},
{
.type = PT_INT,
.id = "index",
.name = N_("Stream index"),
.desc = N_("Stream index (starts with zero)."),
.off = offsetof(profile_audio_t, pro_index),
.group = 1
},
{ }
}
};
Expand All @@ -1318,12 +1351,15 @@ profile_audio_reopen(profile_chain_t *prch,
muxer_config_t *m_cfg, int flags)
{
muxer_config_t c;
profile_audio_t *pro = (profile_audio_t *)prch->prch_pro;

if (m_cfg)
c = *m_cfg; /* do not alter the original parameter */
else
memset(&c, 0, sizeof(c));
c.m_type = MC_MPEG2AUDIO;
c.m_type = pro->pro_mc != MC_UNKNOWN ? pro->pro_mc : MC_MPEG2AUDIO;
c.m_force_type = pro->pro_mc;
c.m_index = pro->pro_index;

assert(!prch->prch_muxer);
prch->prch_muxer = muxer_create(&c);
Expand Down Expand Up @@ -1352,7 +1388,10 @@ profile_audio_open(profile_chain_t *prch,
static muxer_container_type_t
profile_audio_get_mc(profile_t *_pro)
{
return MC_MPEG2AUDIO; /* may be incorrect */
profile_audio_t *pro = (profile_audio_t *)_pro;
if (pro->pro_mc == MC_UNKNOWN)
return MC_MPEG2AUDIO;
return pro->pro_mc;
}

static profile_t *
Expand All @@ -1367,10 +1406,6 @@ profile_audio_builder(void)
}






#if ENABLE_LIBAV

/*
Expand Down

0 comments on commit b848597

Please sign in to comment.