Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
audioes: cleanups, correct suffixes, rename to profile-audio
  • Loading branch information
perexg committed Oct 6, 2016
1 parent 214b2e3 commit 55085b2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 67 deletions.
21 changes: 16 additions & 5 deletions src/muxer.c
Expand Up @@ -46,10 +46,14 @@ static struct strtab container_audio_mime[] = {
{ "audio/webm", MC_AVWEBM },
{ "audio/mp2t", MC_MPEGTS },
{ "audio/mpeg", MC_MPEGPS },
{ "audio/mp2", MC_MPEG2AUDIO },
{ "audio/ac3", MC_AC3 },
{ "audio/aac", MC_AAC },
{ "audio/mp4", MC_MP4A },
{ "audio/ogg", MC_VORBIS },
{ "audio/mp4", MC_AVMP4 },
{ "application/octet-stream", MC_PASS },
{ "application/octet-stream", MC_RAW },
{ "audio/mpeg", MC_AUDIOES },
};


Expand Down Expand Up @@ -84,7 +88,11 @@ static struct strtab container_name[] = {
{ "avmatroska", MC_AVMATROSKA },
{ "avwebm", MC_AVWEBM },
{ "avmp4", MC_AVMP4 },
{ "audioes", MC_AUDIOES },
{ "mp2", MC_MPEG2AUDIO },
{ "ac3", MC_AC3 },
{ "aac", MC_AAC },
{ "mp4a", MC_MP4A },
{ "oga", MC_VORBIS },
};


Expand All @@ -102,7 +110,11 @@ static struct strtab container_audio_file_suffix[] = {
{ "mka", MC_AVMATROSKA },
{ "webm", MC_AVWEBM },
{ "mp4", MC_AVMP4 },
{ "mp2", MC_AUDIOES }, /* Or maybe ac3 or adts */
{ "mp2", MC_MPEG2AUDIO },
{ "ac3", MC_AC3 },
{ "aac", MC_AAC },
{ "mp4a", MC_MP4A },
{ "oga", MC_VORBIS },
};


Expand All @@ -120,7 +132,6 @@ static struct strtab container_video_file_suffix[] = {
{ "mkv", MC_AVMATROSKA },
{ "webm", MC_AVWEBM },
{ "mp4", MC_AVMP4 },
{ NULL, MC_AUDIOES },
};


Expand Down Expand Up @@ -261,7 +272,7 @@ muxer_create(const muxer_config_t *m_cfg)
m = mkv_muxer_create(m_cfg);

if(!m)
m = audioes_muxer_create(m_cfg);
m = audioes_muxer_create(m_cfg);

#if CONFIG_LIBAV
if(!m)
Expand Down
6 changes: 5 additions & 1 deletion src/muxer.h
Expand Up @@ -34,7 +34,11 @@ typedef enum {
MC_AVMATROSKA = 7,
MC_AVWEBM = 8,
MC_AVMP4 = 9,
MC_AUDIOES = 10
MC_MPEG2AUDIO = 10,
MC_AC3 = 11,
MC_AAC = 12,
MC_MP4A = 13,
MC_VORBIS = 14
} muxer_container_type_t;

typedef enum {
Expand Down
92 changes: 55 additions & 37 deletions src/muxer/muxer_audioes.c
Expand Up @@ -40,6 +40,7 @@ typedef struct audioes_muxer {
int am_fd;
int am_seekable;
int am_error;
off_t am_off;

/* Filename is also used for logging */
char *am_filename;
Expand All @@ -49,44 +50,46 @@ typedef struct audioes_muxer {
/**
* Figure out the mimetype
*/
static const char*
static const char *
audioes_muxer_mime(muxer_t* m, const struct streaming_start *ss)
{
int i;
int has_audio;
muxer_container_type_t mc = MC_UNKNOWN;
const streaming_start_component_t *ssc;

has_audio = 0;

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

if(ssc->ssc_disabled)
if (ssc->ssc_disabled)
continue;

has_audio |= SCT_ISAUDIO(ssc->ssc_type);
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;
}
break;
}

if(has_audio)
return muxer_container_type2mime(MC_AUDIOES, 0);
else
return muxer_container_type2mime(MC_UNKNOWN, 0);
return muxer_container_type2mime(mc, 0);
}


/**
* Init the builtin mkv muxer with streams
* Reconfigure the muxer
*/
static int
audioes_muxer_init(muxer_t* m, struct streaming_start *ss, const char *name)
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;

am->am_index = -1;

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

if ((!ssc->ssc_disabled) && (SCT_ISAUDIO(ssc->ssc_type))) {
Expand All @@ -99,12 +102,13 @@ audioes_muxer_init(muxer_t* m, struct streaming_start *ss, const char *name)
}


/**
* Init the builtin mkv muxer with streams
*/
static int
audioes_muxer_reconfigure(muxer_t* m, const struct streaming_start *ss)
audioes_muxer_init(muxer_t* m, struct streaming_start *ss, const char *name)
{
/* TODO: Check our stream still exists? */

return 0;
return audioes_muxer_reconfigure(m, ss);
}


Expand All @@ -118,6 +122,7 @@ audioes_muxer_open_stream(muxer_t *m, int fd)

am->am_fd = fd;
am->am_seekable = 0;
am->am_off = 0;
am->am_filename = strdup("Live stream");

return 0;
Expand Down Expand Up @@ -151,6 +156,7 @@ audioes_muxer_open_file(muxer_t *m, const char *filename)
filename, strerror(errno));

am->am_seekable = 1;
am->am_off = 0;
am->am_fd = fd;
am->am_filename = strdup(filename);
return 0;
Expand All @@ -164,26 +170,37 @@ audioes_muxer_write_pkt(muxer_t *m, streaming_message_type_t smt, void *data)
{
th_pkt_t *pkt = (th_pkt_t*)data;
audioes_muxer_t *am = (audioes_muxer_t*)m;
size_t size;

assert(smt == SMT_PACKET);

// TODO: pkt->pkt_componentindex
/* TODO: ^ What does this even mean? */
if (pkt->pkt_componentindex != am->am_index) {
pkt_ref_dec(pkt);
return am->error;
}

if(pkt->pkt_componentindex != am->am_index) {
size = pktbuf_len(pkt->pkt_payload);
if (size == 0) {
pkt_ref_dec(pkt);
return am->error;
}

if(am->am_error) {
if (am->am_error) {
am->m_errors++;
} else if(tvh_write(am->am_fd, pktbuf_ptr(pkt->pkt_payload), pktbuf_len(pkt->pkt_payload))) {
} else if (tvh_write(am->am_fd, pktbuf_ptr(pkt->pkt_payload), size)) {
am->am_error = errno;
tvherror(LS_AUDIOES, "%s: Write failed -- %s", am->am_filename,
strerror(errno));
/* TODO: Do some EOS handling here. Whatever that is. See muxer_pass.c:415 */
if (!MC_IS_EOS_ERROR(errno)) {
tvherror(LS_AUDIOES, "%s: Write failed -- %s", am->am_filename,
strerror(errno));
} else {
am->m_eos = 1;
}
am->m_errors++;
/* TODO: A muxer_cache_update() call is still missing here. */
muxer_cache_update(m, am->am_fd, am->am_off, 0);
am->am_off = lseek(am->am_fd, 0, SEEK_CUR);
} else {
muxer_cache_update(m, am->am_fd, am->am_off, 0);
am->am_off += size;
}

pkt_ref_dec(pkt);
Expand Down Expand Up @@ -228,12 +245,11 @@ audioes_muxer_close(muxer_t *m)
static void
audioes_muxer_destroy(muxer_t *m)
{
audioes_muxer_t *am = (audioes_muxer_t*)m;
audioes_muxer_t *am = (audioes_muxer_t*)m;

if(am->am_filename)
free(am->am_filename);

free(am);
if (am->am_filename)
free(am->am_filename);
free(am);
}


Expand All @@ -245,7 +261,11 @@ audioes_muxer_create(const muxer_config_t *m_cfg)
{
audioes_muxer_t *am;

if(m_cfg->m_type != MC_AUDIOES)
if(m_cfg->m_type != MC_MPEG2AUDIO &&
m_cfg->m_type != MC_AC3 &&
m_cfg->m_type != MC_AAC &&
m_cfg->m_type != MC_MP4A &&
m_cfg->m_type != MC_VORBIS)
return NULL;

am = calloc(1, sizeof(audioes_muxer_t));
Expand All @@ -258,8 +278,6 @@ audioes_muxer_create(const muxer_config_t *m_cfg)
am->m_write_pkt = audioes_muxer_write_pkt;
am->m_close = audioes_muxer_close;
am->m_destroy = audioes_muxer_destroy;
//am->m_container = *m_cfg; //WTF DOES THIS DO?!

return (muxer_t*)am;
}

51 changes: 27 additions & 24 deletions src/profile.c
Expand Up @@ -1298,41 +1298,41 @@ profile_matroska_builder(void)
/*
* Audioes Muxer
*/
typedef struct profile_audioes {
typedef struct profile_audio {
profile_t;
} profile_audioes_t;
} profile_audio_t;

const idclass_t profile_audioes_class =
const idclass_t profile_audio_class =
{
.ic_super = &profile_class,
.ic_class = "profile-audioes",
.ic_caption = N_("Audioes"),
.ic_class = "profile-audio",
.ic_caption = N_("Audio stream"),
.ic_properties = (const property_t[]){
{ }
}
};


static int
profile_audioes_reopen(profile_chain_t *prch,
muxer_config_t *m_cfg, int flags)
profile_audio_reopen(profile_chain_t *prch,
muxer_config_t *m_cfg, int flags)
{
muxer_config_t c;

if (m_cfg)
c = *m_cfg; /* do not alter the original parameter */
else
memset(&c, 0, sizeof(c));
c.m_type = MC_AUDIOES;
c.m_type = MC_MPEG2AUDIO;

assert(!prch->prch_muxer);
prch->prch_muxer = muxer_create(&c);
return 0;
}

static int
profile_audioes_open(profile_chain_t *prch,
muxer_config_t *m_cfg, int flags, size_t qsize)
profile_audio_open(profile_chain_t *prch,
muxer_config_t *m_cfg, int flags, size_t qsize)
{
int r;

Expand All @@ -1345,24 +1345,24 @@ profile_audioes_open(profile_chain_t *prch,
return r;
}

profile_audioes_reopen(prch, m_cfg, flags);
profile_audio_reopen(prch, m_cfg, flags);
return 0;
}

static muxer_container_type_t
profile_audioes_get_mc(profile_t *_pro)
profile_audio_get_mc(profile_t *_pro)
{
return MC_AUDIOES;
return MC_MPEG2AUDIO; /* may be incorrect */
}

static profile_t *
profile_audioes_builder(void)
profile_audio_builder(void)
{
profile_audioes_t *pro = calloc(1, sizeof(*pro));
profile_audio_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_reopen = profile_audioes_reopen;
pro->pro_open = profile_audioes_open;
pro->pro_get_mc = profile_audioes_get_mc;
pro->pro_reopen = profile_audio_reopen;
pro->pro_open = profile_audio_open;
pro->pro_get_mc = profile_audio_get_mc;
return (profile_t *)pro;
}

Expand Down Expand Up @@ -1641,7 +1641,7 @@ profile_class_mc_list ( void *o, const char *lang )
{ N_("WEBM/built-in"), MC_WEBM, },
{ N_("MPEG-TS/av-lib"), MC_MPEGTS },
{ N_("MPEG-PS (DVD)/av-lib"), MC_MPEGPS },
{ N_("Audioes"), MC_AUDIOES },
{ N_("Raw Audio Stream"), MC_MPEG2AUDIO },
{ N_("Matroska (mkv)/av-lib"), MC_AVMATROSKA },
{ N_("WEBM/av-lib"), MC_AVWEBM },
};
Expand Down Expand Up @@ -2037,7 +2037,10 @@ profile_transcode_mc_valid(int mc)
case MC_WEBM:
case MC_MPEGTS:
case MC_MPEGPS:
case MC_AUDIOES:
case MC_MPEG2AUDIO:
case MC_AC3:
case MC_AAC:
case MC_VORBIS:
case MC_AVMATROSKA:
return 1;
default:
Expand Down Expand Up @@ -2136,7 +2139,7 @@ profile_init(void)
profile_register(&profile_mpegts_pass_class, profile_mpegts_pass_builder);
profile_register(&profile_matroska_class, profile_matroska_builder);
profile_register(&profile_htsp_class, profile_htsp_builder);
profile_register(&profile_audioes_class, profile_audioes_builder);
profile_register(&profile_audio_class, profile_audio_builder);
#if ENABLE_LIBAV
profile_register(&profile_libav_mpegts_class, profile_libav_mpegts_builder);
profile_register(&profile_libav_matroska_class, profile_libav_matroska_builder);
Expand Down Expand Up @@ -2208,16 +2211,16 @@ profile_init(void)
htsmsg_destroy(conf);
}

name = "audioes";
name = "audio";
pro = profile_find_by_name2(name, NULL, 1);
if (pro == NULL || strcmp(profile_get_name(pro), name)) {
htsmsg_t *conf;

conf = htsmsg_create_map();
htsmsg_add_str (conf, "class", "profile-audioes");
htsmsg_add_str (conf, "class", "profile-audio");
htsmsg_add_bool(conf, "enabled", 1);
htsmsg_add_str (conf, "name", name);
htsmsg_add_str (conf, "comment", _("Audio-only MPEG elementary stream"));
htsmsg_add_str (conf, "comment", _("Audio-only stream"));
htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
(void)profile_create(NULL, conf, 1);
htsmsg_destroy(conf);
Expand Down

0 comments on commit 55085b2

Please sign in to comment.