Browse code

Merge commit 'c44191039944526dd7eb6e536990b555837961f5'

* commit 'c44191039944526dd7eb6e536990b555837961f5':
hls: Store all durations in AV_TIME_BASE

Conflicts:
libavformat/hls.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/07/30 17:12:48
Showing 1 changed files
... ...
@@ -56,7 +56,7 @@ enum KeyType {
56 56
 };
57 57
 
58 58
 struct segment {
59
-    double duration;
59
+    int64_t duration;
60 60
     char url[MAX_URL_SIZE];
61 61
     char key[MAX_URL_SIZE];
62 62
     enum KeyType key_type;
... ...
@@ -81,7 +81,7 @@ struct variant {
81 81
     int stream_offset;
82 82
 
83 83
     int finished;
84
-    int target_duration;
84
+    int64_t target_duration;
85 85
     int start_seq_no;
86 86
     int n_segments;
87 87
     struct segment **segments;
... ...
@@ -207,7 +207,7 @@ static int parse_playlist(HLSContext *c, const char *url,
207 207
                           struct variant *var, AVIOContext *in)
208 208
 {
209 209
     int ret = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
210
-    double duration = 0.0;
210
+    int64_t duration = 0;
211 211
     enum KeyType key_type = KEY_NONE;
212 212
     uint8_t iv[16] = "";
213 213
     int has_iv = 0;
... ...
@@ -272,7 +272,7 @@ static int parse_playlist(HLSContext *c, const char *url,
272 272
                     goto fail;
273 273
                 }
274 274
             }
275
-            var->target_duration = atoi(ptr);
275
+            var->target_duration = atoi(ptr) * AV_TIME_BASE;
276 276
         } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
277 277
             if (!var) {
278 278
                 var = new_variant(c, 0, url, NULL);
... ...
@@ -287,7 +287,7 @@ static int parse_playlist(HLSContext *c, const char *url,
287 287
                 var->finished = 1;
288 288
         } else if (av_strstart(line, "#EXTINF:", &ptr)) {
289 289
             is_segment = 1;
290
-            duration   = atof(ptr);
290
+            duration   = atof(ptr) * AV_TIME_BASE;
291 291
         } else if (av_strstart(line, "#", NULL)) {
292 292
             continue;
293 293
         } else if (line[0]) {
... ...
@@ -414,7 +414,6 @@ restart:
414 414
         int64_t reload_interval = v->n_segments > 0 ?
415 415
                                   v->segments[v->n_segments - 1]->duration :
416 416
                                   v->target_duration;
417
-        reload_interval *= 1000000;
418 417
 
419 418
 reload:
420 419
         if (!v->finished &&
... ...
@@ -424,7 +423,7 @@ reload:
424 424
             /* If we need to reload the playlist again below (if
425 425
              * there's still no more segments), switch to a reload
426 426
              * interval of half the target duration. */
427
-            reload_interval = v->target_duration * 500000LL;
427
+            reload_interval = v->target_duration / 2;
428 428
         }
429 429
         if (v->cur_seq_no < v->start_seq_no) {
430 430
             av_log(NULL, AV_LOG_WARNING,
... ...
@@ -527,7 +526,7 @@ static int hls_read_header(AVFormatContext *s)
527 527
     if (c->variants[0]->finished) {
528 528
         int64_t duration = 0;
529 529
         for (i = 0; i < c->variants[0]->n_segments; i++)
530
-            duration += round(c->variants[0]->segments[i]->duration * AV_TIME_BASE);
530
+            duration += c->variants[0]->segments[i]->duration;
531 531
         s->duration = duration;
532 532
     }
533 533
 
... ...
@@ -769,7 +768,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
769 769
                                        s->streams[stream_index]->time_base.den,
770 770
                                        flags & AVSEEK_FLAG_BACKWARD ?
771 771
                                        AV_ROUND_DOWN : AV_ROUND_UP);
772
-    timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
772
+    timestamp = av_rescale_rnd(timestamp, AV_TIME_BASE, stream_index >= 0 ?
773 773
                                s->streams[stream_index]->time_base.den :
774 774
                                AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
775 775
                                AV_ROUND_DOWN : AV_ROUND_UP);
... ...
@@ -782,9 +781,8 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
782 782
     for (i = 0; i < c->n_variants; i++) {
783 783
         /* Reset reading */
784 784
         struct variant *var = c->variants[i];
785
-        int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? 0 :
786
-                      av_rescale_rnd(c->first_timestamp, 1, AV_TIME_BASE,
787
-                          flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
785
+        int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ?
786
+                      0 : c->first_timestamp;
788 787
         if (var->input) {
789 788
             ffurl_close(var->input);
790 789
             var->input = NULL;