From c3865b72838b0bedef9785120cc7cdea2f33607f Mon Sep 17 00:00:00 2001 From: ireader Date: Sat, 4 May 2024 12:21:40 +0800 Subject: [PATCH] change: rtsp play control with speed/scale both --- librtsp/source/client/rtsp-client-internal.h | 4 ++-- librtsp/source/client/rtsp-client-play.c | 20 ++++++++++++++------ librtsp/source/client/rtsp-client-record.c | 10 +++++++++- librtsp/source/server/rtsp-server-play.c | 2 ++ librtsp/source/server/rtsp-server-record.c | 2 ++ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/librtsp/source/client/rtsp-client-internal.h b/librtsp/source/client/rtsp-client-internal.h index 22078a4e..6bee3dca 100644 --- a/librtsp/source/client/rtsp-client-internal.h +++ b/librtsp/source/client/rtsp-client-internal.h @@ -61,8 +61,8 @@ struct rtsp_client_t // media char range[64]; // rtsp header Range - char speed[16]; // rtsp header speed - char scale[16]; // rtsp header scale + //char speed[16]; // rtsp header speed + char scale[32]; // rtsp header scale char req[2048]; char uri[256]; diff --git a/librtsp/source/client/rtsp-client-play.c b/librtsp/source/client/rtsp-client-play.c index a4580be9..56a7320b 100644 --- a/librtsp/source/client/rtsp-client-play.c +++ b/librtsp/source/client/rtsp-client-play.c @@ -61,19 +61,25 @@ static int rtsp_client_media_play(struct rtsp_client_t *rtsp, int i) assert(rtsp->media[i].uri[0] && rtsp->session[i].session[0]); r = rtsp_client_authenrization(rtsp, "PLAY", rtsp->media[i].uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization)); - r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->media[i].uri, rtsp->cseq++, rtsp->session[i].session, rtsp->range, rtsp->speed, rtsp->authenrization, USER_AGENT); + r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->media[i].uri, rtsp->cseq++, rtsp->session[i].session, rtsp->range, rtsp->scale, rtsp->authenrization, USER_AGENT); return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->media[i].uri, rtsp->req, r)) ? 0 : -1; } -int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const float *speed) +int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const float * scale) { int r; assert(RTSP_SETUP == rtsp->state || RTSP_PLAY == rtsp->state || RTSP_PAUSE == rtsp->state); rtsp->state = RTSP_PLAY; rtsp->progress = 0; - rtsp->speed[0] = rtsp->range[0] = '\0'; - - if ( (speed && snprintf(rtsp->speed, sizeof(rtsp->speed), "Scale: %.2f\r\n", *speed) >= sizeof(rtsp->speed)) + rtsp->scale[0] = rtsp->range[0] = '\0'; + +#if RTSP_PLAY_SCALE == 2 + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\n", *scale) >= sizeof(rtsp->scale)) +#elif defined(RTSP_PLAY_SCALE) + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale)) +#else + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\nScale: %.2f\r\n", *scale, *scale) >= sizeof(rtsp->scale)) +#endif || (npt && snprintf(rtsp->range, sizeof(rtsp->range), "Range: npt=%" PRIu64 ".%" PRIu64 "-\r\n", *npt / 1000, *npt % 1000) >= sizeof(rtsp->range)) ) return -1; @@ -82,7 +88,7 @@ int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const floa assert(rtsp->media_count > 0); assert(rtsp->aggregate_uri[0]); r = rtsp_client_authenrization(rtsp, "PLAY", rtsp->aggregate_uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization)); - r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->aggregate_uri, rtsp->cseq++, rtsp->session[0].session, rtsp->range, rtsp->speed, rtsp->authenrization, USER_AGENT); + r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->aggregate_uri, rtsp->cseq++, rtsp->session[0].session, rtsp->range, rtsp->scale, rtsp->authenrization, USER_AGENT); return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->aggregate_uri, rtsp->req, r)) ? 0 : -1; } else @@ -108,6 +114,8 @@ static int rtsp_client_media_play_onreply(struct rtsp_client_t* rtsp, void* pars prange = http_get_header_by_name(parser, "Range"); pscale = http_get_header_by_name(parser, "Scale"); + if(!pscale) + pscale = http_get_header_by_name(parser, "Speed"); prtpinfo = http_get_header_by_name(parser, "RTP-Info"); if (pscale) diff --git a/librtsp/source/client/rtsp-client-record.c b/librtsp/source/client/rtsp-client-record.c index 9d90c365..61ebf83b 100644 --- a/librtsp/source/client/rtsp-client-record.c +++ b/librtsp/source/client/rtsp-client-record.c @@ -61,7 +61,13 @@ int rtsp_client_record(struct rtsp_client_t *rtsp, const uint64_t *npt, const fl rtsp->progress = 0; rtsp->scale[0] = rtsp->range[0] = '\0'; - if ( (scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale)) +#if RTSP_PLAY_SCALE == 2 + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\n", *scale) >= sizeof(rtsp->scale)) +#elif defined(RTSP_PLAY_SCALE) + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale)) +#else + if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\nScale: %.2f\r\n", *scale, *scale) >= sizeof(rtsp->scale)) +#endif || (npt && snprintf(rtsp->range, sizeof(rtsp->range), "Range: npt=%" PRIu64 ".%" PRIu64 "-\r\n", *npt / 1000, *npt % 1000) >= sizeof(rtsp->range))) return -1; @@ -95,6 +101,8 @@ static int rtsp_client_media_record_onreply(struct rtsp_client_t* rtsp, void* pa prange = http_get_header_by_name(parser, "Range"); pscale = http_get_header_by_name(parser, "Scale"); + if(!pscale) + pscale = http_get_header_by_name(parser, "Speed"); prtpinfo = http_get_header_by_name(parser, "RTP-Info"); if (pscale) diff --git a/librtsp/source/server/rtsp-server-play.c b/librtsp/source/server/rtsp-server-play.c index ae1faecd..373da819 100644 --- a/librtsp/source/server/rtsp-server-play.c +++ b/librtsp/source/server/rtsp-server-play.c @@ -10,6 +10,8 @@ int rtsp_server_play(struct rtsp_server_t *rtsp, const char* uri) struct rtsp_header_range_t range; pscale = http_get_header_by_name(rtsp->parser, "scale"); + if(!pscale) + pscale = http_get_header_by_name(rtsp->parser, "speed"); prange = http_get_header_by_name(rtsp->parser, "range"); if (0 == rtsp->session.session[0]) diff --git a/librtsp/source/server/rtsp-server-record.c b/librtsp/source/server/rtsp-server-record.c index f8041882..5d1f0abd 100644 --- a/librtsp/source/server/rtsp-server-record.c +++ b/librtsp/source/server/rtsp-server-record.c @@ -10,6 +10,8 @@ int rtsp_server_record(struct rtsp_server_t *rtsp, const char* uri) struct rtsp_header_range_t range; pscale = http_get_header_by_name(rtsp->parser, "scale"); + if (!pscale) + pscale = http_get_header_by_name(rtsp->parser, "speed"); prange = http_get_header_by_name(rtsp->parser, "range"); if (0 == rtsp->session.session[0])