[FFmpeg-cvslog] r22904 - in trunk/libavformat: flvdec.c librtmp.c

stefano subversion
Sun Apr 18 21:09:25 CEST 2010


Author: stefano
Date: Sun Apr 18 21:09:25 2010
New Revision: 22904

Log:
Implement librtmp seek support.

Implement flv_read_seek(), add a missing check on stream_index
and fix timestamp rounding in rtmp_read_seek().

Also add the flv_read_seek2() function, which is not enabled but is
useful as reference.
To actually implement flv_read_seek2() correctly, there would need to
be some corresponding av_url_read_fseek2() function to propagate the
timestamps down to the ByteIOContext and URLContext.

Patch by Howard Chu <hyc <at> highlandsun.com>.

See the thread:
Subject: [FFmpeg-devel] RTMP seek support
Date: 2010-03-28 23:35:02 GMT

Modified:
   trunk/libavformat/flvdec.c
   trunk/libavformat/librtmp.c

Modified: trunk/libavformat/flvdec.c
==============================================================================
--- trunk/libavformat/flvdec.c	Sun Apr 18 21:09:22 2010	(r22903)
+++ trunk/libavformat/flvdec.c	Sun Apr 18 21:09:25 2010	(r22904)
@@ -449,6 +449,39 @@ leave:
     return ret;
 }
 
+static int flv_read_seek(AVFormatContext *s, int stream_index,
+    int64_t ts, int flags)
+{
+    return av_url_read_fseek(s->pb, stream_index, ts, flags);
+}
+
+#if 0 /* don't know enough to implement this */
+static int flv_read_seek2(AVFormatContext *s, int stream_index,
+    int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
+{
+    int ret = AVERROR(ENOSYS);
+
+    if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD;
+
+    if (url_is_streamed(s->pb)) {
+        if (stream_index < 0) {
+            stream_index = av_find_default_stream_index(s);
+            if (stream_index < 0)
+                return -1;
+
+            /* timestamp for default must be expressed in AV_TIME_BASE units */
+            ts = av_rescale_rnd(ts, 1000, AV_TIME_BASE,
+                flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
+        }
+        ret = av_url_read_fseek(s->pb, stream_index, ts, flags);
+    }
+
+    if (ret == AVERROR(ENOSYS))
+        ret = av_seek_frame(s, stream_index, ts, flags);
+    return ret;
+}
+#endif
+
 AVInputFormat flv_demuxer = {
     "flv",
     NULL_IF_CONFIG_SMALL("FLV format"),
@@ -456,6 +489,10 @@ AVInputFormat flv_demuxer = {
     flv_probe,
     flv_read_header,
     flv_read_packet,
+    .read_seek = flv_read_seek,
+#if 0
+    .read_seek2 = flv_read_seek2,
+#endif
     .extensions = "flv",
     .value = CODEC_ID_FLV1,
 };

Modified: trunk/libavformat/librtmp.c
==============================================================================
--- trunk/libavformat/librtmp.c	Sun Apr 18 21:09:22 2010	(r22903)
+++ trunk/libavformat/librtmp.c	Sun Apr 18 21:09:25 2010	(r22904)
@@ -144,7 +144,10 @@ static int64_t rtmp_read_seek(URLContext
         return AVERROR(ENOSYS);
 
     /* seeks are in milliseconds */
-    timestamp = av_rescale(timestamp, AV_TIME_BASE, 1000);
+    if (stream_index < 0)
+        timestamp = av_rescale_rnd(timestamp, 1000, AV_TIME_BASE,
+            flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
+
     if (!RTMP_SendSeek(r, timestamp))
         return -1;
     return timestamp;



More information about the ffmpeg-cvslog mailing list