Ticket #8989: ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran.patch

File ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran.patch, 4.2 KB (added by VigneshRavichandran, 6 years ago)

WIP fix for defect 8989

  • libavformat/hlsenc.c

    diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
    index cbfd8f7c0d..cfc3093c1a 100644
    a b  
    2525#include <stdint.h>
    2626#if HAVE_UNISTD_H
    2727#include <unistd.h>
     28#include <stdbool.h>
     29
    2830#endif
    2931
    3032#if CONFIG_GCRYPT
    … … typedef struct HLSSegment {  
    8890    char iv_string[KEYSIZE*2 + 1];
    8991
    9092    struct HLSSegment *next;
     93    double discont_program_date_time;
    9194} HLSSegment;
    9295
    9396typedef enum HLSFlags {
    … … static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,  
    11241127    en->keyframe_size     = vs->video_keyframe_size;
    11251128    en->next     = NULL;
    11261129    en->discont  = 0;
     1130    en->discont_program_date_time = 0;
    11271131
    11281132    if (vs->discontinuity) {
    11291133        en->discont = 1;
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    11821186    char line[MAX_URL_SIZE];
    11831187    const char *ptr;
    11841188    const char *end;
     1189    bool is_discont_detected = false;
     1190    double discont_program_date_time = 0;
    11851191
    11861192    if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ,
    11871193                                   &s->interrupt_callback, NULL,
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12111217        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
    12121218            is_segment = 1;
    12131219            vs->discontinuity = 1;
     1220            is_discont_detected = true;
    12141221        } else if (av_strstart(line, "#EXTINF:", &ptr)) {
    12151222            is_segment = 1;
    12161223            vs->duration = atof(ptr);
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12361243                    av_strlcpy(vs->iv_string, ptr, sizeof(vs->iv_string));
    12371244                }
    12381245            }
    1239 
     1246        } else if (av_strstart(line, "#EXT-X-PROGRAM-DATE-TIME:", &ptr) && is_discont_detected) {
     1247            av_log(hls, AV_LOG_VERBOSE, "program_date_time: %s\n", ptr);
     1248            struct tm program_date_time;
     1249            int y,M,d,h,m,s;
     1250            double ms;
     1251            sscanf(ptr, "%d-%d-%dT%d:%d:%d.%lf", &y, &M, &d, &h, &m, &s, &ms);
     1252
     1253            program_date_time.tm_year = y - 1900;
     1254            program_date_time.tm_mon = M - 1;
     1255            program_date_time.tm_mday = d;
     1256            program_date_time.tm_hour = h;
     1257            program_date_time.tm_min = m;
     1258            program_date_time.tm_sec = s;
     1259            program_date_time.tm_isdst = -1;
     1260
     1261            discont_program_date_time = mktime(&program_date_time);
     1262            discont_program_date_time += (double)(ms / 1000);
     1263            is_discont_detected = false;
    12401264        } else if (av_strstart(line, "#", NULL)) {
    12411265            continue;
    12421266        } else if (line[0]) {
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12541278                ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
    12551279                if (ret < 0)
    12561280                    goto fail;
     1281                vs->last_segment->discont_program_date_time = discont_program_date_time;
     1282                discont_program_date_time += vs->duration;
    12571283                vs->start_pos = new_start_pos;
    12581284            }
    12591285        }
    … … static int hls_window(AVFormatContext *s, int last, VariantStream *vs)  
    15721598        ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode,
    15731599                                      en->duration, hls->flags & HLS_ROUND_DURATIONS,
    15741600                                      en->size, en->pos, hls->baseurl,
    1575                                       en->filename, prog_date_time_p, en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
     1601                                      en->filename,
     1602                                      en->discont_program_date_time ? &en->discont_program_date_time : prog_date_time_p,
     1603                                      en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
    15761604        if (ret < 0) {
    15771605            av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
    15781606        }
     1607        if (en->discont_program_date_time)
     1608            en->discont_program_date_time -= en->duration;
    15791609    }
    15801610
    15811611    if (last && (hls->flags & HLS_OMIT_ENDLIST)==0)