]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
libav: make sure we don't write a trailer if the header has not been written
authorJohn Törnblom <john@workstation.(none)>
Sun, 17 Mar 2013 07:47:46 +0000 (08:47 +0100)
committerJohn Törnblom <john@workstation.(none)>
Sun, 17 Mar 2013 07:51:35 +0000 (08:51 +0100)
src/muxer/muxer_libav.c

index 451bb63f51c6bd7a70509a61541573d61e419ab2..2f549823b4f98693ad0366751dcdd5984cc602df 100644 (file)
@@ -33,6 +33,7 @@ typedef struct lav_muxer {
   AVFormatContext *lm_oc;
   AVBitStreamFilterContext *lm_h264_filter;
   int lm_fd;
+  int lm_init;
 } lav_muxer_t;
 
 #define MUX_BUF_SIZE 4096
@@ -276,6 +277,8 @@ lav_muxer_init(muxer_t* m, const struct streaming_start *ss, const char *name)
     return -1;
   }
 
+  lm->lm_init = 1;
+
   return 0;
 }
 
@@ -357,6 +360,12 @@ lav_muxer_write_pkt(muxer_t *m, streaming_message_type_t smt, void *data)
     return -1;
   }
 
+  if(!lm->lm_init) {
+    tvhlog(LOG_ERR, "libav", "Muxer not initialized correctly");
+    lm->m_errors++;
+    return -1;
+  }
+
   for(i=0; i<oc->nb_streams; i++) {
     st = oc->streams[i];
 
@@ -440,7 +449,7 @@ lav_muxer_close(muxer_t *m)
   int ret = 0;
   lav_muxer_t *lm = (lav_muxer_t*)m;
 
-  if(lm->lm_oc->nb_streams && av_write_trailer(lm->lm_oc) < 0) {
+  if(lm->lm_init && av_write_trailer(lm->lm_oc) < 0) {
     tvhlog(LOG_WARNING, "libav",  "Failed to write %s trailer", 
           muxer_container_type2txt(lm->m_container));
     lm->m_errors++;
@@ -517,6 +526,7 @@ lav_muxer_create(muxer_container_type_t mc)
   lm->lm_oc          = avformat_alloc_context();
   lm->lm_oc->oformat = fmt;
   lm->lm_fd          = -1;
+  lm->lm_init        = 0;
 
   return (muxer_t*)lm;
 }