]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
audioes: add stream type / index filtering
authorJaroslav Kysela <perex@perex.cz>
Thu, 6 Oct 2016 14:11:06 +0000 (16:11 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 6 Oct 2016 14:11:06 +0000 (16:11 +0200)
src/muxer.h
src/muxer/muxer_audioes.c
src/profile.c

index 8b79f77ecb877cb9f2066f8d1040008be06840d0..b2e442c6828af67efd07c660ec2e3e4f1379bdee 100644 (file)
@@ -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
index f6f2b357c1c52ea563510dfa418b6494af518816..857e4254a145016fedb1456332a162b47e90faf5 100644 (file)
@@ -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_tm, 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;
   }
 
@@ -81,11 +96,12 @@ audioes_muxer_mime(muxer_t* m, const struct streaming_start *ss)
  * Reconfigure the muxer
  */
 static int
-audioes_muxer_reconfigure(muxer_tm, 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;
 
@@ -93,8 +109,16 @@ audioes_muxer_reconfigure(muxer_t* m, const struct streaming_start *ss)
     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++;
     }
   }
 
index 75af0af828da2881420436204791d2a263e882c9..0cb2872c53c5264a01ca2aecfe62ebaa64277ddb 100644 (file)
@@ -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
+    },
     { }
   }
 };
@@ -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);
@@ -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 *
@@ -1367,10 +1406,6 @@ profile_audio_builder(void)
 }
 
 
-
-
-
-
 #if ENABLE_LIBAV
 
 /*