Ticket #8989: ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran_2.patch

File ffmpeg_defect_ticket_8989_wip_fix_vignesh_ravichandran_2.patch, 4.1 KB (added by VigneshRavichandran, 6 years ago)

Fix for defect 8989

  • libavformat/hlsenc.c

    diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
    index cbfd8f7c0d..7de17f7031 100644
    a b typedef struct HLSSegment {  
    8888    char iv_string[KEYSIZE*2 + 1];
    8989
    9090    struct HLSSegment *next;
     91    double discont_program_date_time;
    9192} HLSSegment;
    9293
    9394typedef enum HLSFlags {
    … … static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,  
    11241125    en->keyframe_size     = vs->video_keyframe_size;
    11251126    en->next     = NULL;
    11261127    en->discont  = 0;
     1128    en->discont_program_date_time = 0;
    11271129
    11281130    if (vs->discontinuity) {
    11291131        en->discont = 1;
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    11821184    char line[MAX_URL_SIZE];
    11831185    const char *ptr;
    11841186    const char *end;
     1187    int is_discont_detected = 0;
     1188    double discont_program_date_time = 0;
    11851189
    11861190    if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ,
    11871191                                   &s->interrupt_callback, NULL,
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12111215        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
    12121216            is_segment = 1;
    12131217            vs->discontinuity = 1;
     1218            is_discont_detected = 1;
    12141219        } else if (av_strstart(line, "#EXTINF:", &ptr)) {
    12151220            is_segment = 1;
    12161221            vs->duration = atof(ptr);
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12361241                    av_strlcpy(vs->iv_string, ptr, sizeof(vs->iv_string));
    12371242                }
    12381243            }
    1239 
     1244        } else if (av_strstart(line, "#EXT-X-PROGRAM-DATE-TIME:", &ptr) && is_discont_detected) {
     1245            struct tm program_date_time;
     1246            int y,M,d,h,m,s;
     1247            double ms;
     1248            sscanf(ptr, "%d-%d-%dT%d:%d:%d.%lf", &y, &M, &d, &h, &m, &s, &ms);
     1249
     1250            program_date_time.tm_year = y - 1900;
     1251            program_date_time.tm_mon = M - 1;
     1252            program_date_time.tm_mday = d;
     1253            program_date_time.tm_hour = h;
     1254            program_date_time.tm_min = m;
     1255            program_date_time.tm_sec = s;
     1256            program_date_time.tm_isdst = -1;
     1257
     1258            discont_program_date_time = mktime(&program_date_time);
     1259            discont_program_date_time += (double)(ms / 1000);
     1260            is_discont_detected = 0;
    12401261        } else if (av_strstart(line, "#", NULL)) {
    12411262            continue;
    12421263        } else if (line[0]) {
    … … static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs  
    12501271                is_segment = 0;
    12511272                new_start_pos = avio_tell(vs->avf->pb);
    12521273                vs->size = new_start_pos - vs->start_pos;
    1253                 vs->initial_prog_date_time -= vs->duration; // this is a previously existing segment
    12541274                ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
     1275                vs->last_segment->discont_program_date_time = discont_program_date_time;
     1276                discont_program_date_time += vs->duration;
    12551277                if (ret < 0)
    12561278                    goto fail;
    12571279                vs->start_pos = new_start_pos;
    … … static int hls_window(AVFormatContext *s, int last, VariantStream *vs)  
    15721594        ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode,
    15731595                                      en->duration, hls->flags & HLS_ROUND_DURATIONS,
    15741596                                      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);
     1597                                      en->filename,
     1598                                      en->discont_program_date_time ? &en->discont_program_date_time : prog_date_time_p,
     1599                                      en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
     1600        if (en->discont_program_date_time)
     1601            en->discont_program_date_time -= en->duration;
    15761602        if (ret < 0) {
    15771603            av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
    15781604        }