diff mbox

[FFmpeg-devel] avformat/concatdec: don't call open_file when seek position within a file

Message ID 1474602520-12918-1-git-send-email-raymondzheng1412@gmail.com
State Accepted
Commit 2366efce3cd5be7c6aeafa24ae9a3f550b4518c6
Headers show

Commit Message

raymond Sept. 23, 2016, 3:48 a.m. UTC
Thanks for your suggest, I have modified patch. see below.
---
 libavformat/concatdec.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

raymond Sept. 26, 2016, 8:07 a.m. UTC | #1
ping...

2016-09-23 11:48 GMT+08:00 raymondzheng1412@gmail.com <
raymondzheng1412@gmail.com>:

> Thanks for your suggest, I have modified patch. see below.
> ---
>  libavformat/concatdec.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> index b3a430e..5cc239a 100644
> --- a/libavformat/concatdec.c
> +++ b/libavformat/concatdec.c
> @@ -689,7 +689,7 @@ static int try_seek(AVFormatContext *avf, int stream,
>  }
>
>  static int real_seek(AVFormatContext *avf, int stream,
> -                     int64_t min_ts, int64_t ts, int64_t max_ts, int
> flags)
> +                     int64_t min_ts, int64_t ts, int64_t max_ts, int
> flags, AVFormatContext *cur_avf)
>  {
>      ConcatContext *cat = avf->priv_data;
>      int ret, left, right;
> @@ -711,13 +711,19 @@ static int real_seek(AVFormatContext *avf, int
> stream,
>              left  = mid;
>      }
>
> -    if ((ret = open_file(avf, left)) < 0)
> -        return ret;
> +    if (cat->cur_file != &cat->files[left]) {
> +        if ((ret = open_file(avf, left)) < 0)
> +            return ret;
> +    } else {
> +        cat->avf = cur_avf;
> +    }
>
>      ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
>      if (ret < 0 &&
>          left < cat->nb_files - 1 &&
>          cat->files[left + 1].start_time < max_ts) {
> +        if (cat->cur_file == &cat->files[left])
> +            cat->avf = NULL;
>          if ((ret = open_file(avf, left + 1)) < 0)
>              return ret;
>          ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
> @@ -738,13 +744,17 @@ static int concat_seek(AVFormatContext *avf, int
> stream,
>      if (flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME))
>          return AVERROR(ENOSYS);
>      cat->avf = NULL;
> -    if ((ret = real_seek(avf, stream, min_ts, ts, max_ts, flags)) < 0) {
> -        if (cat->avf)
> -            avformat_close_input(&cat->avf);
> +    if ((ret = real_seek(avf, stream, min_ts, ts, max_ts, flags,
> cur_avf_saved)) < 0) {
> +        if (cat->cur_file != cur_file_saved) {
> +            if (cat->avf)
> +                avformat_close_input(&cat->avf);
> +        }
>          cat->avf      = cur_avf_saved;
>          cat->cur_file = cur_file_saved;
>      } else {
> -        avformat_close_input(&cur_avf_saved);
> +        if (cat->cur_file != cur_file_saved) {
> +            avformat_close_input(&cur_avf_saved);
> +        }
>          cat->eof = 0;
>      }
>      return ret;
> --
> 2.7.4
>
>
Nicolas George Sept. 26, 2016, 2:50 p.m. UTC | #2
Le quintidi 5 vendémiaire, an CCXXV, raymond zheng a écrit :
> ping...

Sorry for the delay, I forgot yesterday. It looks nice at first glance, but
I will need a little more time for testing.

Regards,
Nicolas George Sept. 28, 2016, 6:39 p.m. UTC | #3
Le duodi 2 vendémiaire, an CCXXV, raymondzheng1412@gmail.com a écrit :
> Thanks for your suggest, I have modified patch. see below.
> ---
>  libavformat/concatdec.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c

The comment should have been below the line with the three dashes, otherwise
it ends up in the commit message.

I have fixed this, tested and pushed, thanks for the patch.

Regards,
diff mbox

Patch

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index b3a430e..5cc239a 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -689,7 +689,7 @@  static int try_seek(AVFormatContext *avf, int stream,
 }
 
 static int real_seek(AVFormatContext *avf, int stream,
-                     int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
+                     int64_t min_ts, int64_t ts, int64_t max_ts, int flags, AVFormatContext *cur_avf)
 {
     ConcatContext *cat = avf->priv_data;
     int ret, left, right;
@@ -711,13 +711,19 @@  static int real_seek(AVFormatContext *avf, int stream,
             left  = mid;
     }
 
-    if ((ret = open_file(avf, left)) < 0)
-        return ret;
+    if (cat->cur_file != &cat->files[left]) {
+        if ((ret = open_file(avf, left)) < 0)
+            return ret;
+    } else {
+        cat->avf = cur_avf;
+    }
 
     ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
     if (ret < 0 &&
         left < cat->nb_files - 1 &&
         cat->files[left + 1].start_time < max_ts) {
+        if (cat->cur_file == &cat->files[left])
+            cat->avf = NULL;
         if ((ret = open_file(avf, left + 1)) < 0)
             return ret;
         ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
@@ -738,13 +744,17 @@  static int concat_seek(AVFormatContext *avf, int stream,
     if (flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME))
         return AVERROR(ENOSYS);
     cat->avf = NULL;
-    if ((ret = real_seek(avf, stream, min_ts, ts, max_ts, flags)) < 0) {
-        if (cat->avf)
-            avformat_close_input(&cat->avf);
+    if ((ret = real_seek(avf, stream, min_ts, ts, max_ts, flags, cur_avf_saved)) < 0) {
+        if (cat->cur_file != cur_file_saved) {
+            if (cat->avf)
+                avformat_close_input(&cat->avf);
+        }
         cat->avf      = cur_avf_saved;
         cat->cur_file = cur_file_saved;
     } else {
-        avformat_close_input(&cur_avf_saved);
+        if (cat->cur_file != cur_file_saved) {
+            avformat_close_input(&cur_avf_saved);
+        }
         cat->eof = 0;
     }
     return ret;