[3/3] applehttp: Merge two for loops

Message ID 1301516483-83108-4-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö March 30, 2011, 8:21 p.m.
The previous diff didn't do this straight away, to keep the

Patch

diff slightly simpler.
---
 libavformat/applehttp.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index b9ffded..97f5123 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -509,9 +509,15 @@  static int applehttp_read_seek(AVFormatContext *s, int stream_index,
     if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished)
         return AVERROR(ENOSYS);
 
-    /* Reset the variants */
+    timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
+                               s->streams[stream_index]->time_base.den :
+                               AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
+                               AV_ROUND_DOWN : AV_ROUND_UP);
+    ret = AVERROR(EIO);
     for (i = 0; i < c->n_variants; i++) {
+        /* Reset reading */
         struct variant *var = c->variants[i];
+        int64_t pos = 0;
         if (var->input) {
             url_close(var->input);
             var->input = NULL;
@@ -519,16 +525,7 @@  static int applehttp_read_seek(AVFormatContext *s, int stream_index,
         av_free_packet(&var->pkt);
         reset_packet(&var->pkt);
         var->pb.eof_reached = 0;
-    }
 
-    timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
-                               s->streams[stream_index]->time_base.den :
-                               AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
-                               AV_ROUND_DOWN : AV_ROUND_UP);
-    ret = AVERROR(EIO);
-    for (i = 0; i < c->n_variants; i++) {
-        struct variant *var = c->variants[i];
-        int64_t pos = 0;
         /* Locate the segment that contains the target timestamp */
         for (i = 0; i < var->n_segments; i++) {
             if (timestamp >= pos &&