Ticket #12602: mythtranscode.patch

File mythtranscode.patch, 4.7 KB (added by Timothy D Witham <twitham@…>, 4 years ago)

abort failed .mpg transcode upon full disk

  • mythtv/programs/mythtranscode/mpeg2fix.cpp

    diff --git a/mythtv/programs/mythtranscode/mpeg2fix.cpp b/mythtv/programs/mythtranscode/mpeg2fix.cpp
    index c7214d3..d5f161f 100644
    a b int MPEG2replex::WaitBuffers() 
    495495    if (done)
    496496    {
    497497        finish_mpg(mplex);
    498         pthread_exit(NULL);
     498        static int errorcount = 0; // thread exit must return static, not stack
     499        errorcount = mplex->error;
     500        if (mplex->error) {
     501          LOG(VB_GENERAL, LOG_ERR,
     502              QString("twitham: thread finished with %1 write errors")
     503              .arg(mplex->error));
     504        }
     505        pthread_exit(&errorcount);
    499506    }
    500507
    501508    return 0;
    void MPEG2replex::Start() 
    554561    while (1)
    555562    {
    556563        check_times( &mx, &video_ok, ext_ok, &start);
    557         write_out_packs( &mx, video_ok, ext_ok);
     564        if (write_out_packs( &mx, video_ok, ext_ok)) {
     565          // exiting here blocks the reading thread indefinitely;
     566          // maybe there is a way to fail it also?
     567          // LOG(VB_GENERAL, LOG_ERR, // or comment all this to fail until close
     568          //     QString("twitham: exiting thread after %1 write errors")
     569          //     .arg(mplex->error));
     570          // pthread_exit(&mplex->error);
     571        }
    558572    }
    559573}
    560574
    int MPEG2fixup::Start() 
    25552569    pthread_mutex_lock( &rx.mutex );
    25562570    pthread_cond_signal(&rx.cond);
    25572571    pthread_mutex_unlock( &rx.mutex );
    2558     pthread_join(thread, NULL);
     2572    int ex = REENCODE_OK;
     2573    void *errors;       // return error if any write or close failures
     2574    pthread_join(thread, &errors);
     2575    if (*(int *)errors > 0) {
     2576      LOG(VB_GENERAL, LOG_ERR,
     2577          QString("twitham: joined thread failed with %1 write errors")
     2578          .arg(*(int *)errors));
     2579      ex = REENCODE_ERROR;
     2580    }
    25592581
    25602582    avformat_close_input(&inputFC);
    25612583    inputFC = NULL;
    2562     return REENCODE_OK;
     2584    return ex;
    25632585}
    25642586
    25652587#ifdef NO_MYTH
  • mythtv/programs/mythtranscode/replex/multiplex.c

    diff --git a/mythtv/programs/mythtranscode/replex/multiplex.c b/mythtv/programs/mythtranscode/replex/multiplex.c
    index d6cf1a3..09516f6 100644
    a b static void writeout_video(multiplex_t *mx) 
    295295        //estimate next pts based on bitrate of this stream and data written
    296296        viu->dts = uptsdiff(viu->dts + ((nlength*viu->ptsrate)>>8), 0);
    297297
    298         write(mx->fd_out, outbuf, written);
     298        if (write(mx->fd_out, outbuf, written) != written) {
     299          if (mx->error++ < 10) /* log only first few failures */
     300            LOG(VB_GENERAL, LOG_ERR, "twitham: %d write failed: %s",
     301                mx->error, strerror(errno));
     302        }
    299303
    300304#ifdef OUT_DEBUG
    301305        LOG(VB_GENERAL, LOG_DEBUG, "VPTS");
    void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start) 
    571575        }
    572576#endif
    573577}
    574 void write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok)
     578int write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok)
    575579{
    576580        int i;
    577581
    void write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok) 
    589593                        writeout_padding(mx);
    590594                }
    591595        }
    592        
     596        return mx->error || 0;
    593597}
    594598
    595 void finish_mpg(multiplex_t *mx)
     599int finish_mpg(multiplex_t *mx)
    596600{
    597601        int start=0;
    598602        int video_ok = 0;
    void finish_mpg(multiplex_t *mx) 
    637641        if (mx->otype == REPLEX_MPEG2)
    638642                write(mx->fd_out, mpeg_end,4);
    639643
     644        if (close(mx->fd_out) < 0) {
     645          mx->error++;
     646          LOG(VB_GENERAL, LOG_ERR, "twitham: %d close failed: %s",
     647              mx->error, strerror(errno));
     648        }
     649
    640650        dummy_destroy(&mx->vdbuf);
    641651        for (i=0; i<mx->extcnt;i++)
    642652                dummy_destroy(&mx->ext[i].dbuf);
     653        return mx->error || 0;
    643654}
    644655
    645656static int get_ts_video_overhead(int pktsize, sequence_t *seq)
    void init_multiplex( multiplex_t *mx, sequence_t *seq_head, 
    684695        int i;
    685696        uint32_t data_rate;
    686697
     698        mx->error = 0;
    687699        mx->fill_buffers = fill_buffers;
    688700        mx->video_delay = video_delay;
    689701        mx->audio_delay = audio_delay;
  • mythtv/programs/mythtranscode/replex/multiplex.h

    diff --git a/mythtv/programs/mythtranscode/replex/multiplex.h b/mythtv/programs/mythtranscode/replex/multiplex.h
    index 56e2a69..cf4dac3 100644
    a b typedef struct multiplex_s{ 
    8181
    8282        int (*fill_buffers)(void *p, int f);
    8383        void *priv;
     84        int error;
    8485} multiplex_t;
    8586
    8687void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start);
    87 void write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok);
    88 void finish_mpg(multiplex_t *mx);
     88int write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok);
     89int finish_mpg(multiplex_t *mx);
    8990void init_multiplex( multiplex_t *mx, sequence_t *seq_head,
    9091                     audio_frame_t *extframe, int *exttype, int *exttypcnt,
    9192                     uint64_t video_delay, uint64_t audio_delay, int fd,