From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id B391C4DA70
	for <ffmpegdev@gitmailbox.com>; Tue,  3 Jun 2025 16:23:51 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id CBDDE68D863;
	Tue,  3 Jun 2025 19:23:49 +0300 (EEST)
Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com
 [209.85.219.178])
 by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id C9CCB68D841
 for <ffmpeg-devel@ffmpeg.org>; Tue,  3 Jun 2025 19:23:43 +0300 (EEST)
Received: by mail-yb1-f178.google.com with SMTP id
 3f1490d57ef6-e694601f624so4065935276.1
 for <ffmpeg-devel@ffmpeg.org>; Tue, 03 Jun 2025 09:23:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1748967822; x=1749572622; darn=ffmpeg.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=JVAWPT1zFaytELlqis4tKZZXXSZptbeObNEh8FLCAdo=;
 b=OkufZ87zHmHp8Tb8YC7z3UgPyFlLvKuJ1wBvGx3brm4sPW8UgP4TdBfsZoJlKXPH+7
 YYkxDh5R+JDXOwM3sXlQwbls8qcCcfJQTn01ewuNLk5Eh+5C395HG4fo6yp2WZcQd3rY
 X5fbqoCdy75/BipfOrA5C4D8NaCSQUpfOlpsctIrelP+HX96Zo89XleGUeEaCJhqiNPR
 MFztvjsV9EHFbNGBRktjxBOYEKXhmb5VI22MQLtejfl0HKJAaMR2VeDTSL6w/frfq5mT
 3WbzHtUy2O08Z0pXboPX/nevy5MCFUb+wYApcQoCipC7UwfUYUEQcVjrYejcrMVqYRoc
 Zy/g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1748967822; x=1749572622;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=JVAWPT1zFaytELlqis4tKZZXXSZptbeObNEh8FLCAdo=;
 b=LMHRuh2AUWyLvHbozuaV9vesMc1veVwtj9kfKW702x1WeH06O7iv9NWc/XHcls7hfo
 +Cij++o4SnY3LXWZ58FEqu7FkqtgncAuT8BIGPrwmoPvbfzGHnSQtJYtQCVtrVbgpQgu
 ijFqtOTEdN5LB0JZMtob38ahp93fKOTCedXxqBDdHLxzszX5DEO2YQBe1j6BXU1fV7N7
 P+G7UnEoPH7nc3iJ9xrRj8j4BC8VZkx2PsokLCKzx/wHOgxW0aNpSohl75o/f80qTYBT
 30DbkxHRqFkWZ6ZMCdLO/LkzRA/QX/hycFTUrF/GPkuYyCLF0Q/Qb4CS7G0w/GWDtX88
 n9aQ==
X-Gm-Message-State: AOJu0Ywb55piPdoyn4TDjtfwx35sNHkurE7g4VSHNQ4sSxwIOz4Mjhkg
 8A7DiypQLFqB7B755dUfB2nbeU+laBPX14C+FClwQ70wjkHar3rSobiEQR6pLg==
X-Gm-Gg: ASbGnctTrAtHeNOSbWV0kS4f1aI8HgYEwYRoj2ENX5+RhvrZMVzpXZ3yRjH/0ygCRLw
 wGhEBuNj/Ngs+Bwr1EyeLkxZPyFQ14gsKUemf0aoTwP0kZfmjHHJGjKdTQS1fHPJme2KICJQT3D
 MC4eYm5WCYUnbz0o2t2P8xIMs1kgVAkf3bHem29kGo619gELyrN+nfnDg9Zhqb+7ohYcVIIuVb4
 /zDnP+J9J/vAWimrz2QePyDgOQCUouhNYoyVQU7be/Ozz4Zu2NzYJTXYM5ahI68VxFQ8NOwBfRq
 UkpMDKYkS27XQEwnLhGYmOJB7blzy4pzqSTtgTgnfBm8w34BD5z3xA6knsZbFbkPPi+M6IA=
X-Google-Smtp-Source: AGHT+IH8K9BFl/xLqAAIin5pbpfIFfjJSax9QjQTA9XO8BX+NWFFhoGl1TPSzKJi2Vz+qzgbtGBhfw==
X-Received: by 2002:a05:6902:26c9:b0:e7d:8eee:ae8f with SMTP id
 3f1490d57ef6-e7f81e3077cmr19542916276.19.1748967821767; 
 Tue, 03 Jun 2025 09:23:41 -0700 (PDT)
Received: from localhost.localdomain ([2600:1700:9f70:5cdf:989f:2b50:4ab:e82d])
 by smtp.gmail.com with ESMTPSA id
 3f1490d57ef6-e7f73500ca4sm2718229276.43.2025.06.03.09.23.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 03 Jun 2025 09:23:40 -0700 (PDT)
From: Rashad Tatum <tatum.rashad@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Tue,  3 Jun 2025 12:23:28 -0400
Message-ID: <20250603162332.3230398-1-tatum.rashad@gmail.com>
X-Mailer: git-send-email 2.49.0
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH v3] Add new method for playing network based
 streams with a play rate.
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Rashad Tatum <tatum.rashad@gmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250603162332.3230398-1-tatum.rashad@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

Add implementation for changing the play rate for rtsp streams.
---
 libavformat/avformat.h    |  6 ++++++
 libavformat/demux.h       |  6 ++++++
 libavformat/demux_utils.c |  6 ++++++
 libavformat/rtsp.c        |  1 +
 libavformat/rtsp.h        | 10 ++++++++++
 libavformat/rtspdec.c     | 21 +++++++++++++++++++--
 6 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 2034d2aecc..7819b61d3e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2358,6 +2358,12 @@ int avformat_flush(AVFormatContext *s);
  */
 int av_read_play(AVFormatContext *s);
 
+/**
+ * Play a network-based stream (e.g. RTSP stream) with a given play rate
+ * (e.g. Scale value for RTSP) and timestamp position.
+ */
+int av_read_play_with_rate(AVFormatContext *s, double play_rate, int stream_index, int64_t timestamp);
+
 /**
  * Pause a network-based stream (e.g. RTSP stream).
  *
diff --git a/libavformat/demux.h b/libavformat/demux.h
index e83d84a201..965743bdf0 100644
--- a/libavformat/demux.h
+++ b/libavformat/demux.h
@@ -113,6 +113,12 @@ typedef struct FFInputFormat {
      * (RTSP).
      */
     int (*read_play)(struct AVFormatContext *);
+    
+    /**
+     * Play a network-based stream (e.g. RTSP stream) with a given play rate
+     * (e.g. Scale value for RTSP) and timestamp position.
+     */
+    int (*read_play_with_rate)(struct AVFormatContext *s, double play_rate, int stream_index, int64_t timestamp);
 
     /**
      * Pause playing - only meaningful if using a network-based format
diff --git a/libavformat/demux_utils.c b/libavformat/demux_utils.c
index b632277460..8fed41e3b6 100644
--- a/libavformat/demux_utils.c
+++ b/libavformat/demux_utils.c
@@ -179,6 +179,12 @@ int av_read_play(AVFormatContext *s)
     return AVERROR(ENOSYS);
 }
 
+int av_read_play_with_rate(AVFormatContext *s, double play_rate, int stream_index, int64_t timestamp) {
+    if (ffifmt(s->iformat)->read_play_with_rate)
+        return ffifmt(s->iformat)->read_play_with_rate(s, play_rate, stream_index, timestamp);
+    return AVERROR(ENOSYS); 
+}
+
 int av_read_pause(AVFormatContext *s)
 {
     if (ffifmt(s->iformat)->read_pause)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5ea471b40c..6cfbcdf989 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1998,6 +1998,7 @@ redirect:
     av_strlcpy(rt->real_challenge, real_challenge, sizeof(rt->real_challenge));
     rt->state = RTSP_STATE_IDLE;
     rt->seek_timestamp = 0; /* default is to start stream at position zero */
+    rt->scale = 1.0; /* default is to play at the normal rate */
     return 0;
  fail:
     ff_rtsp_close_streams(s);
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 83b2e3f4fb..1b8ce05d74 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -245,6 +245,16 @@ typedef struct RTSPState {
      * whenever we resume playback. Either way, the value is only used once,
      * see rtsp_read_play() and rtsp_read_seek(). */
     int64_t seek_timestamp;
+    
+    /** the scale value requested when calling av_read_play(). This value
+     * is subsequently used as part of the "Scale" parameter when emitting
+     * the RTSP PLAY command. The "Scale" parameter determines the stream play 
+     * rate. A value of 1 represents the normal play rate. Any other value is 
+     * in regards to the normal play rate. A negative value represents reverse
+     * playback. If we are currently playing, this command is called instantly. 
+     * If we are currently paused, this command is called whenever we resume 
+     * playback.  */
+    double scale;
 
     int seq;                          /**< RTSP command sequence number */
 
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 10078ce2fa..f1e44ccb63 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -39,6 +39,7 @@
 #include "tls.h"
 #include "url.h"
 #include "version.h"
+#include <stdio.h>
 
 static const struct RTSPStatusMessage {
     enum RTSPStatusCode code;
@@ -527,7 +528,7 @@ static int rtsp_read_play(AVFormatContext *s)
 {
     RTSPState *rt = s->priv_data;
     RTSPMessageHeader reply1, *reply = &reply1;
-    int i;
+    int i, cmd_char_count = 0;
     char cmd[MAX_URL_SIZE];
 
     av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
@@ -564,11 +565,17 @@ static int rtsp_read_play(AVFormatContext *s)
         if (rt->state == RTSP_STATE_PAUSED) {
             cmd[0] = 0;
         } else {
-            snprintf(cmd, sizeof(cmd),
+           
+            cmd_char_count += snprintf(cmd, sizeof(cmd),
                      "Range: npt=%"PRId64".%03"PRId64"-\r\n",
                      rt->seek_timestamp / AV_TIME_BASE,
                      rt->seek_timestamp / (AV_TIME_BASE / 1000) % 1000);
+            
+            snprintf(cmd + cmd_char_count, sizeof(cmd) - cmd_char_count, "Scale: %f\r\n", rt->scale);
+                     
         }
+        
+       
         ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL);
         if (reply->status_code != RTSP_STATUS_OK) {
             return ff_rtsp_averror(reply->status_code, -1);
@@ -593,6 +600,15 @@ static int rtsp_read_play(AVFormatContext *s)
     return 0;
 }
 
+static int rtsp_read_play_with_rate(AVFormatContext *s, double play_rate, int stream_index, int64_t timestamp) {
+    RTSPState *rt = s->priv_data;
+    rt->seek_timestamp = av_rescale_q(timestamp,
+                                      s->streams[stream_index]->time_base,
+                                      AV_TIME_BASE_Q);
+    rt->scale = play_rate;
+    return rtsp_read_play(s);
+}
+
 /* pause the stream */
 static int rtsp_read_pause(AVFormatContext *s)
 {
@@ -1006,5 +1022,6 @@ const FFInputFormat ff_rtsp_demuxer = {
     .read_close     = rtsp_read_close,
     .read_seek      = rtsp_read_seek,
     .read_play      = rtsp_read_play,
+    .read_play_with_rate = rtsp_read_play_with_rate,
     .read_pause     = rtsp_read_pause,
 };
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".