]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtspdec.c
rtmp: Read and handle incoming packets while writing data
[ffmpeg] / libavformat / rtspdec.c
index c453b821956eac7086acfe280c74cdba39636dc8..063e82501c867be1734c60b6e1fd8daa46872b82 100644 (file)
@@ -52,6 +52,8 @@ static int rtsp_read_play(AVFormatContext *s)
                 rtpctx->last_rtcp_ntp_time  = AV_NOPTS_VALUE;
                 rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;
                 rtpctx->base_timestamp      = 0;
+                rtpctx->timestamp           = 0;
+                rtpctx->unwrapped_timestamp = 0;
                 rtpctx->rtcp_ts_offset      = 0;
             }
         }
@@ -148,8 +150,7 @@ static int rtsp_probe(AVProbeData *p)
     return 0;
 }
 
-static int rtsp_read_header(AVFormatContext *s,
-                            AVFormatParameters *ap)
+static int rtsp_read_header(AVFormatContext *s)
 {
     RTSPState *rt = s->priv_data;
     int ret;
@@ -158,8 +159,9 @@ static int rtsp_read_header(AVFormatContext *s,
     if (ret)
         return ret;
 
-    rt->real_setup_cache = av_mallocz(2 * s->nb_streams * sizeof(*rt->real_setup_cache));
-    if (!rt->real_setup_cache)
+    rt->real_setup_cache = !s->nb_streams ? NULL :
+                           av_mallocz(2 * s->nb_streams * sizeof(*rt->real_setup_cache));
+    if (!rt->real_setup_cache && s->nb_streams)
         return AVERROR(ENOMEM);
     rt->real_setup = rt->real_setup_cache + s->nb_streams;
 
@@ -334,7 +336,8 @@ retry:
     rt->packets++;
 
     /* send dummy request to keep TCP connection alive */
-    if ((av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {
+    if ((av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2 ||
+         rt->auth_state.stale) {
         if (rt->server_type == RTSP_SERVER_WMS ||
            (rt->server_type != RTSP_SERVER_REAL &&
             rt->get_parameter_supported)) {
@@ -342,6 +345,10 @@ retry:
         } else {
             ff_rtsp_send_cmd_async(s, "OPTIONS", "*", NULL);
         }
+        /* The stale flag should be reset when creating the auth response in
+         * ff_rtsp_send_cmd_async, but reset it here just in case we never
+         * called the auth code (if we didn't have any credentials set). */
+        rt->auth_state.stale = 0;
     }
 
     return 0;
@@ -387,7 +394,7 @@ static int rtsp_read_close(AVFormatContext *s)
     return 0;
 }
 
-const AVClass rtsp_demuxer_class = {
+static const AVClass rtsp_demuxer_class = {
     .class_name     = "RTSP demuxer",
     .item_name      = av_default_item_name,
     .option         = ff_rtsp_options,
@@ -403,8 +410,8 @@ AVInputFormat ff_rtsp_demuxer = {
     .read_packet    = rtsp_read_packet,
     .read_close     = rtsp_read_close,
     .read_seek      = rtsp_read_seek,
-    .flags = AVFMT_NOFILE,
-    .read_play = rtsp_read_play,
-    .read_pause = rtsp_read_pause,
-    .priv_class = &rtsp_demuxer_class,
+    .flags          = AVFMT_NOFILE,
+    .read_play      = rtsp_read_play,
+    .read_pause     = rtsp_read_pause,
+    .priv_class     = &rtsp_demuxer_class,
 };