]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
transcode: fix H264 decoding
authorJaroslav Kysela <perex@perex.cz>
Mon, 20 Oct 2014 07:17:58 +0000 (09:17 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 20 Oct 2014 07:17:58 +0000 (09:17 +0200)
src/plumbing/transcoding.c

index f3fa3f3a199dffcc976ebbbbafcdbf62a03bae89..0ebc67658d4d312705858d4899797a6d494ba259 100644 (file)
@@ -368,6 +368,19 @@ transcoder_stream_audio(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)
   ocodec = as->aud_ocodec;
 
   if (ictx->codec_id == AV_CODEC_ID_NONE) {
+
+    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);
+        ictx->extradata = av_malloc(ictx->extradata_size);
+        memcpy(ictx->extradata,
+               pktbuf_ptr(pkt->pkt_meta), pktbuf_len(pkt->pkt_meta));
+      } else {
+        /* wait for metadata */
+        return;
+      }
+    }
+
     ictx->codec_id = icodec->id;
 
     if (avcodec_open2(ictx, icodec, NULL) < 0) {
@@ -922,6 +935,19 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)
   opts = NULL;
 
   if (ictx->codec_id == AV_CODEC_ID_NONE) {
+
+    if (icodec->id == AV_CODEC_ID_H264) {
+      if (pkt->pkt_meta) {
+        ictx->extradata_size = pktbuf_len(pkt->pkt_meta);
+        ictx->extradata = av_malloc(ictx->extradata_size);
+        memcpy(ictx->extradata,
+               pktbuf_ptr(pkt->pkt_meta), pktbuf_len(pkt->pkt_meta));
+      } else {
+        /* wait for metadata */
+        return;
+      }
+    }
+
     ictx->codec_id = icodec->id;
 
     if (avcodec_open2(ictx, icodec, NULL) < 0) {
@@ -932,6 +958,13 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt)
   }
 
   av_init_packet(&packet);
+
+  if (ictx->codec_id == AV_CODEC_ID_H264 && pkt->pkt_meta) {
+    uint8_t *buf = av_packet_new_side_data(&packet, AV_PKT_DATA_NEW_EXTRADATA,
+                                           pktbuf_len(pkt->pkt_meta));
+    memcpy(buf, pktbuf_ptr(pkt->pkt_meta), pktbuf_len(pkt->pkt_meta));
+  }
+
   packet.data     = pktbuf_ptr(pkt->pkt_payload);
   packet.size     = pktbuf_len(pkt->pkt_payload);
   packet.pts      = pkt->pkt_pts;