Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
transcode: use av codec string names instead IDs
- to allow the selection from the multiple encoders for same type
  • Loading branch information
perexg committed Oct 12, 2014
1 parent 47f56f7 commit 9ca0248
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 122 deletions.
43 changes: 42 additions & 1 deletion src/config.c
Expand Up @@ -1041,6 +1041,46 @@ config_migrate_v13 ( void )
}
}

static const char *
config_migrate_v14_codec(int i)
{
switch (i) {
case 1: return "mpeg2video";
case 2: return "mp2";
case 3: return "libx264";
case 4: return "ac3";
case 8: return "aac";
case 13: return "libvpx";
case 14: return "libvorbis";
default: return "";
}
}

static void
config_migrate_v14 ( void )
{
htsmsg_t *c, *e;
htsmsg_field_t *f;
int i;

if ((c = hts_settings_load("profile")) != NULL) {
HTSMSG_FOREACH(f, c) {
if (!(e = htsmsg_field_get_map(f))) continue;
if (!htsmsg_get_s32(e, "vcodec", &i)) {
htsmsg_delete_field(e, "vcodec");
htsmsg_set_str(e, "vcodec", config_migrate_v14_codec(i));
}
if (!htsmsg_get_s32(e, "acodec", &i)) {
htsmsg_delete_field(e, "acodec");
htsmsg_set_str(e, "acodec", config_migrate_v14_codec(i));
}
if (!htsmsg_get_s32(e, "scodec", &i))
htsmsg_delete_field(e, "scodec");
hts_settings_save(e, "profile/%s", f->hmf_name);
}
}
}

/*
* Perform backup
*/
Expand Down Expand Up @@ -1142,7 +1182,8 @@ static const config_migrate_t config_migrate_table[] = {
config_migrate_v10,
config_migrate_v11,
config_migrate_v12,
config_migrate_v13
config_migrate_v13,
config_migrate_v14
};

/*
Expand Down
80 changes: 40 additions & 40 deletions src/plumbing/transcoding.c
Expand Up @@ -184,28 +184,13 @@ transcoder_get_decoder(streaming_component_type_t ty)
*
*/
static AVCodec *
transcoder_get_encoder(streaming_component_type_t ty)
transcoder_get_encoder(const char *codec_name)
{
enum AVCodecID codec_id;
AVCodec *codec;

codec_id = streaming_component_type2codec_id(ty);
if (codec_id == AV_CODEC_ID_NONE) {
tvhlog(LOG_ERR, "transcode", "Unable to find %s codec",
streaming_component_type2txt(ty));
return NULL;
}

if (!WORKING_ENCODER(codec_id)) {
tvhlog(LOG_WARNING, "transcode", "Unsupported output codec %s",
streaming_component_type2txt(ty));
return NULL;
}

codec = avcodec_find_encoder(codec_id);
codec = avcodec_find_encoder_by_name(codec_name);
if (!codec) {
tvhlog(LOG_ERR, "transcode", "Unable to find %s encoder",
streaming_component_type2txt(ty));
tvhlog(LOG_ERR, "transcode", "Unable to find %s encoder", codec_name);
return NULL;
}
tvhlog(LOG_DEBUG, "transcode", "Using encoder %s", codec->name);
Expand Down Expand Up @@ -1416,11 +1401,12 @@ transcoder_init_subtitle(transcoder_t *t, streaming_start_component_t *ssc)
subtitle_stream_t *ss;
AVCodec *icodec, *ocodec;
transcoder_props_t *tp = &t->t_props;
int sct;

if (tp->tp_scodec == SCT_NONE)
if (tp->tp_scodec[0] == '\0')
return 0;

else if (tp->tp_scodec == SCT_UNKNOWN)
else if (!strcmp(tp->tp_scodec, "copy"))
return transcoder_init_stream(t, ssc);

else if (!(icodec = transcoder_get_decoder(ssc->ssc_type)))
Expand All @@ -1429,13 +1415,15 @@ transcoder_init_subtitle(transcoder_t *t, streaming_start_component_t *ssc)
else if (!(ocodec = transcoder_get_encoder(tp->tp_scodec)))
return transcoder_init_stream(t, ssc);

if (tp->tp_scodec == ssc->ssc_type)
sct = codec_id2streaming_component_type(ocodec->id);

if (sct == ssc->ssc_type)
return transcoder_init_stream(t, ssc);

ss = calloc(1, sizeof(subtitle_stream_t));

ss->ts_index = ssc->ssc_index;
ss->ts_type = tp->tp_scodec;
ss->ts_type = sct;
ss->ts_target = t->t_output;
ss->ts_handle_pkt = transcoder_stream_subtitle;
ss->ts_destroy = transcoder_destroy_subtitle;
Expand All @@ -1453,7 +1441,7 @@ transcoder_init_subtitle(transcoder_t *t, streaming_start_component_t *ssc)
streaming_component_type2txt(ssc->ssc_type),
streaming_component_type2txt(ss->ts_type));

ssc->ssc_type = tp->tp_scodec;
ssc->ssc_type = sct;
ssc->ssc_gh = NULL;

return 1;
Expand Down Expand Up @@ -1506,11 +1494,12 @@ transcoder_init_audio(transcoder_t *t, streaming_start_component_t *ssc)
transcoder_stream_t *ts;
AVCodec *icodec, *ocodec;
transcoder_props_t *tp = &t->t_props;
int sct;

if (tp->tp_acodec == SCT_NONE)
if (tp->tp_acodec[0] == '\0')
return 0;

else if (tp->tp_acodec == SCT_UNKNOWN)
else if (!strcmp(tp->tp_acodec, "copy"))
return transcoder_init_stream(t, ssc);

else if (!(icodec = transcoder_get_decoder(ssc->ssc_type)))
Expand All @@ -1523,13 +1512,15 @@ transcoder_init_audio(transcoder_t *t, streaming_start_component_t *ssc)
if (SCT_ISAUDIO(ts->ts_type))
return 0;

if (tp->tp_acodec == ssc->ssc_type)
sct = codec_id2streaming_component_type(ocodec->id);

if (sct == ssc->ssc_type)
return transcoder_init_stream(t, ssc);

as = calloc(1, sizeof(audio_stream_t));

as->ts_index = ssc->ssc_index;
as->ts_type = tp->tp_acodec;
as->ts_type = sct;
as->ts_target = t->t_output;
as->ts_handle_pkt = transcoder_stream_audio;
as->ts_destroy = transcoder_destroy_audio;
Expand Down Expand Up @@ -1559,7 +1550,7 @@ transcoder_init_audio(transcoder_t *t, streaming_start_component_t *ssc)
streaming_component_type2txt(ssc->ssc_type),
streaming_component_type2txt(as->ts_type));

ssc->ssc_type = tp->tp_acodec;
ssc->ssc_type = sct;
ssc->ssc_gh = NULL;

// resampling not implemented yet
Expand Down Expand Up @@ -1621,11 +1612,12 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc)
AVCodec *icodec, *ocodec;
double aspect;
transcoder_props_t *tp = &t->t_props;
int sct;

if (tp->tp_vcodec == SCT_NONE)
if (tp->tp_vcodec[0] == '\0')
return 0;

else if (tp->tp_vcodec == SCT_UNKNOWN)
else if (!strcmp(tp->tp_vcodec, "copy"))
return transcoder_init_stream(t, ssc);

else if (!(icodec = transcoder_get_decoder(ssc->ssc_type)))
Expand All @@ -1634,10 +1626,12 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc)
else if (!(ocodec = transcoder_get_encoder(tp->tp_vcodec)))
return transcoder_init_stream(t, ssc);

sct = codec_id2streaming_component_type(ocodec->id);

vs = calloc(1, sizeof(video_stream_t));

vs->ts_index = ssc->ssc_index;
vs->ts_type = tp->tp_vcodec;
vs->ts_type = sct;
vs->ts_target = t->t_output;
vs->ts_handle_pkt = transcoder_stream_video;
vs->ts_destroy = transcoder_destroy_video;
Expand Down Expand Up @@ -1683,7 +1677,7 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc)
vs->vid_width,
vs->vid_height);

ssc->ssc_type = tp->tp_vcodec;
ssc->ssc_type = sct;
ssc->ssc_width = vs->vid_width;
ssc->ssc_height = vs->vid_height;
ssc->ssc_gh = NULL;
Expand Down Expand Up @@ -1712,23 +1706,23 @@ transcoder_calc_stream_count(transcoder_t *t, streaming_start_t *ss) {
continue;

if (SCT_ISVIDEO(ssc->ssc_type)) {
if (t->t_props.tp_vcodec == SCT_NONE)
if (t->t_props.tp_vcodec[0] == '\0')
video = 0;
else if (t->t_props.tp_vcodec == SCT_UNKNOWN)
video++;
else
video = 1;

} else if (SCT_ISAUDIO(ssc->ssc_type)) {
if (t->t_props.tp_acodec == SCT_NONE)
if (t->t_props.tp_acodec[0] == '\0')
audio = 0;
else if (t->t_props.tp_acodec == SCT_UNKNOWN)
audio++;
else
audio = 1;

} else if (SCT_ISSUBTITLE(ssc->ssc_type)) {
if (t->t_props.tp_scodec == SCT_NONE)
if (t->t_props.tp_scodec[0] == '\0')
subtitle = 0;
else if (t->t_props.tp_scodec == SCT_UNKNOWN)
subtitle++;
Expand Down Expand Up @@ -1898,9 +1892,9 @@ transcoder_set_properties(streaming_target_t *st,
transcoder_t *t = (transcoder_t *)st;
transcoder_props_t *tp = &t->t_props;

tp->tp_vcodec = props->tp_vcodec;
tp->tp_acodec = props->tp_acodec;
tp->tp_scodec = props->tp_scodec;
strncpy(tp->tp_vcodec, props->tp_vcodec, sizeof(tp->tp_vcodec)-1);
strncpy(tp->tp_acodec, props->tp_acodec, sizeof(tp->tp_acodec)-1);
strncpy(tp->tp_scodec, props->tp_scodec, sizeof(tp->tp_scodec)-1);
tp->tp_channels = props->tp_channels;
tp->tp_bandwidth = props->tp_bandwidth;
tp->tp_resolution = props->tp_resolution;
Expand Down Expand Up @@ -1930,7 +1924,7 @@ transcoder_get_capabilities(int experimental)
{
AVCodec *p = NULL;
streaming_component_type_t sct;
htsmsg_t *array = htsmsg_create_list();
htsmsg_t *array = htsmsg_create_list(), *m;

while ((p = av_codec_next(p))) {

Expand All @@ -1947,7 +1941,13 @@ transcoder_get_capabilities(int experimental)
if (sct == SCT_NONE)
continue;

htsmsg_add_s32(array, NULL, sct);
m = htsmsg_create_map();
htsmsg_add_s32(m, "type", sct);
htsmsg_add_u32(m, "id", p->id);
htsmsg_add_str(m, "name", p->name);
if (p->long_name)
htsmsg_add_str(m, "long_name", p->long_name);
htsmsg_add_msg(array, NULL, m);
}
return array;
}
Expand Down
6 changes: 3 additions & 3 deletions src/plumbing/transcoding.h
Expand Up @@ -21,9 +21,9 @@
#include "htsmsg.h"

typedef struct transcoder_prop {
streaming_component_type_t tp_vcodec;
streaming_component_type_t tp_acodec;
streaming_component_type_t tp_scodec;
char tp_vcodec[32];
char tp_acodec[32];
char tp_scodec[32];

int8_t tp_channels;
int32_t tp_bandwidth;
Expand Down

0 comments on commit 9ca0248

Please sign in to comment.