From 792b816314ddd9c50069b5bb6766744ec522217a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Fri, 10 Aug 2007 11:39:30 +0000 Subject: [PATCH] Make it possible to select recording format on a per-recording basis --- pvr.c | 1 + pvr_rec.c | 35 ++++++++++++++++++++++------------- tvhead.h | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pvr.c b/pvr.c index ef187bfb..58e3cc2a 100644 --- a/pvr.c +++ b/pvr.c @@ -191,6 +191,7 @@ pvr_free(pvr_rec_t *pvrr) free(pvrr->pvrr_desc); free(pvrr->pvrr_printname); free(pvrr->pvrr_filename); + free(pvrr->pvrr_format); free(pvrr); } diff --git a/pvr_rec.c b/pvr_rec.c index caca26c9..b49829d0 100644 --- a/pvr_rec.c +++ b/pvr_rec.c @@ -347,6 +347,9 @@ pvr_generate_filename(pvr_rec_t *pvrr) pvrr->pvrr_filename = NULL; } + free(pvrr->pvrr_format); + pvrr->pvrr_format = strdup("asf"); + if(name != NULL && name[0] != 0) { /* Convert from utf8 */ @@ -374,8 +377,8 @@ pvr_generate_filename(pvr_rec_t *pvrr) strcpy(chname, pvrr->pvrr_channel->ch_name); deslashify(chname); - snprintf(fullname, sizeof(fullname), "%s/%s-%s", - config_get_str("pvrdir", "."), chname, out); + snprintf(fullname, sizeof(fullname), "%s/%s-%s.%s", + config_get_str("pvrdir", "."), chname, out, pvrr->pvrr_format); while(1) { if(stat(fullname, &st) == -1) { @@ -385,8 +388,9 @@ pvr_generate_filename(pvr_rec_t *pvrr) } tally++; - snprintf(fullname, sizeof(fullname), "%s/%s-%s-%d", - config_get_str("pvrdir", "."), chname, out, tally); + snprintf(fullname, sizeof(fullname), "%s/%s-%s-%d.%s", + config_get_str("pvrdir", "."), chname, out, tally, + pvrr->pvrr_format); syslog(LOG_DEBUG, "pvr: Testing filename \"%s\"", fullname); @@ -557,7 +561,6 @@ pwo_init(th_subscription_t *s, pvr_rec_t *pvrr) { char urlname[400]; int i, err; - const char *format = NULL; th_transport_t *t = s->ths_transport; pwo_ffmpeg_t *pf; pidinfo_t *p; @@ -565,15 +568,13 @@ pwo_init(th_subscription_t *s, pvr_rec_t *pvrr) AVCodec *codec; const char *cname; - format = "asf"; - pf = calloc(1, sizeof(pwo_ffmpeg_t)); - pf->fmt = guess_format(format, NULL, NULL); + pf->fmt = guess_format(pvrr->pvrr_format, NULL, NULL); if(pf->fmt == NULL) { syslog(LOG_ERR, "pvr: \"%s\" - Unable to open file format \".%s\" for output", - pvrr->pvrr_printname, format); + pvrr->pvrr_printname, pvrr->pvrr_format); free(pf); return NULL; } @@ -592,7 +593,7 @@ pwo_init(th_subscription_t *s, pvr_rec_t *pvrr) pf->fctx->oformat = pf->fmt; snprintf(urlname, sizeof(urlname), "file:%s.%s", - pvrr->pvrr_filename,format); + pvrr->pvrr_filename, pvrr->pvrr_format); if((err = url_fopen(&pf->fctx->pb, urlname, URL_WRONLY)) < 0) { syslog(LOG_ERR, @@ -789,7 +790,7 @@ pwo_writepkt(pvr_rec_t *pvrr, th_subscription_t *s, uint32_t startcode, if(pf->hdr_written == 0) { if(av_write_header(pf->fctx)) return 0; - dump_format(pf->fctx, 0, "pvr", 1); + // dump_format(pf->fctx, 0, "pvr", 1); pf->hdr_written = 1; syslog(LOG_DEBUG, "pvr: \"%s\" - Header written to file, stream dump:", pvrr->pvrr_printname); @@ -837,9 +838,17 @@ pwo_writepkt(pvr_rec_t *pvrr, th_subscription_t *s, uint32_t startcode, switch(pvrr->pvrr_status) { case HTSTV_PVR_STATUS_PAUSED_WAIT_FOR_START: - case HTSTV_PVR_STATUS_PAUSED_COMMERCIAL: return 0; - + + case HTSTV_PVR_STATUS_PAUSED_COMMERCIAL: + if(th == NULL || th->tht_tt_commercial_advice != COMMERCIAL_YES) { + pvrr->pvrr_status = HTSTV_PVR_STATUS_WAIT_KEY_FRAME; + } else { + return 0; + } + + /* FALLTHRU */ + case HTSTV_PVR_STATUS_WAIT_KEY_FRAME: if(st->codec->codec_type == CODEC_TYPE_VIDEO && st->parser->pict_type == FF_I_TYPE) { diff --git a/tvhead.h b/tvhead.h index b1740c2c..a843b495 100644 --- a/tvhead.h +++ b/tvhead.h @@ -410,6 +410,7 @@ typedef struct pvr_rec { char *pvrr_desc; /* Description in UTF-8 */ char *pvrr_printname; /* Only ASCII chars, used for logging and such */ + char *pvrr_format; /* File format trailer */ char pvrr_status; /* defined in libhts/htstv.h */