Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
transcode: use metadata from streaming_start message, fixes #3331
  • Loading branch information
perexg committed Nov 25, 2015
1 parent 2ddbb07 commit 97cbcb3
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/plumbing/transcoding.c
Expand Up @@ -53,6 +53,8 @@ typedef struct transcoder_stream {
LIST_ENTRY(transcoder_stream) ts_link;
int ts_first;

pktbuf_t *ts_input_gh;

void (*ts_handle_pkt) (struct transcoder *, struct transcoder_stream *, th_pkt_t *);
void (*ts_destroy) (struct transcoder *, struct transcoder_stream *);
} transcoder_stream_t;
Expand Down Expand Up @@ -494,14 +496,14 @@ transcoder_stream_audio(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)

if (!avcodec_is_open(ictx)) {
if (icodec->id == AV_CODEC_ID_AAC || icodec->id == AV_CODEC_ID_VORBIS) {
if (pkt->pkt_meta) {
ictx->extradata_size = pktbuf_len(pkt->pkt_meta);
if (ts->ts_input_gh) {
ictx->extradata_size = pktbuf_len(ts->ts_input_gh);
ictx->extradata = av_malloc(ictx->extradata_size);
memcpy(ictx->extradata,
pktbuf_ptr(pkt->pkt_meta), pktbuf_len(pkt->pkt_meta));
pktbuf_ptr(ts->ts_input_gh), pktbuf_len(ts->ts_input_gh));
} else {
/* wait for metadata */
return;
tvherror("transcode", "%04X: missing meta data for %s",
shortid(t), icodec->id == AV_CODEC_ID_AAC ? "AAC" : "VORBIS");
}
}

Expand Down Expand Up @@ -1179,14 +1181,13 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)

if (!avcodec_is_open(ictx)) {
if (icodec->id == AV_CODEC_ID_H264) {
if (pkt->pkt_meta) {
ictx->extradata_size = pktbuf_len(pkt->pkt_meta);
if (ts->ts_input_gh) {
ictx->extradata_size = pktbuf_len(ts->ts_input_gh);
ictx->extradata = av_malloc(ictx->extradata_size);
memcpy(ictx->extradata,
pktbuf_ptr(pkt->pkt_meta), pktbuf_len(pkt->pkt_meta));
pktbuf_ptr(ts->ts_input_gh), pktbuf_len(ts->ts_input_gh));
} else {
/* wait for metadata */
return;
tvherror("transcode", "%04X: missing meta data for H264", shortid(t));
}
}

Expand Down Expand Up @@ -1511,6 +1512,8 @@ transcoder_packet(transcoder_t *t, th_pkt_t *pkt)
static void
transcoder_destroy_stream(transcoder_t *t, transcoder_stream_t *ts)
{
if (ts->ts_input_gh)
pktbuf_ref_dec(ts->ts_input_gh);
free(ts);
}

Expand All @@ -1531,8 +1534,11 @@ transcoder_init_stream(transcoder_t *t, streaming_start_component_t *ssc)

LIST_INSERT_HEAD(&t->t_stream_list, ts, ts_link);

if(ssc->ssc_gh)
if(ssc->ssc_gh) {
pktbuf_ref_inc(ssc->ssc_gh);
ts->ts_input_gh = ssc->ssc_gh;
pktbuf_ref_inc(ssc->ssc_gh);
}

tvhinfo("transcode", "%04X: %d:%s ==> Passthrough",
shortid(t), ssc->ssc_index,
Expand Down Expand Up @@ -1562,7 +1568,7 @@ transcoder_destroy_subtitle(transcoder_t *t, transcoder_stream_t *ts)
av_free(ss->sub_octx);
}

free(ts);
transcoder_destroy_stream(t, ts);
}


Expand Down Expand Up @@ -1601,6 +1607,10 @@ transcoder_init_subtitle(transcoder_t *t, streaming_start_component_t *ssc)
ss->ts_target = t->t_output;
ss->ts_handle_pkt = transcoder_stream_subtitle;
ss->ts_destroy = transcoder_destroy_subtitle;
if (ssc->ssc_gh) {
ss->ts_input_gh = ssc->ssc_gh;
pktbuf_ref_inc(ssc->ssc_gh);
}

ss->sub_icodec = icodec;
ss->sub_ocodec = ocodec;
Expand Down Expand Up @@ -1649,7 +1659,7 @@ transcoder_destroy_audio(transcoder_t *t, transcoder_stream_t *ts)

av_audio_fifo_free(as->fifo);

free(ts);
transcoder_destroy_stream(t, ts);
}


Expand Down Expand Up @@ -1695,6 +1705,10 @@ transcoder_init_audio(transcoder_t *t, streaming_start_component_t *ssc)
as->ts_target = t->t_output;
as->ts_handle_pkt = transcoder_stream_audio;
as->ts_destroy = transcoder_destroy_audio;
if (ssc->ssc_gh) {
as->ts_input_gh = ssc->ssc_gh;
pktbuf_ref_inc(ssc->ssc_gh);
}

as->aud_icodec = icodec;
as->aud_ocodec = ocodec;
Expand Down Expand Up @@ -1760,7 +1774,7 @@ transcoder_destroy_video(transcoder_t *t, transcoder_stream_t *ts)
vs->flt_graph = NULL;
}

free(ts);
transcoder_destroy_stream(t, ts);
}


Expand Down Expand Up @@ -1796,6 +1810,10 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc)
vs->ts_target = t->t_output;
vs->ts_handle_pkt = transcoder_stream_video;
vs->ts_destroy = transcoder_destroy_video;
if (ssc->ssc_gh) {
vs->ts_input_gh = ssc->ssc_gh;
pktbuf_ref_inc(ssc->ssc_gh);
}

vs->vid_icodec = icodec;
vs->vid_ocodec = ocodec;
Expand Down

0 comments on commit 97cbcb3

Please sign in to comment.