Skip to content

Commit c3865b7

Browse files
committed
change: rtsp play control with speed/scale both
1 parent 574ec1f commit c3865b7

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

librtsp/source/client/rtsp-client-internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ struct rtsp_client_t
6161

6262
// media
6363
char range[64]; // rtsp header Range
64-
char speed[16]; // rtsp header speed
65-
char scale[16]; // rtsp header scale
64+
//char speed[16]; // rtsp header speed
65+
char scale[32]; // rtsp header scale
6666
char req[2048];
6767

6868
char uri[256];

librtsp/source/client/rtsp-client-play.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,25 @@ static int rtsp_client_media_play(struct rtsp_client_t *rtsp, int i)
6161

6262
assert(rtsp->media[i].uri[0] && rtsp->session[i].session[0]);
6363
r = rtsp_client_authenrization(rtsp, "PLAY", rtsp->media[i].uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization));
64-
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);
64+
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);
6565
return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->media[i].uri, rtsp->req, r)) ? 0 : -1;
6666
}
6767

68-
int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const float *speed)
68+
int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const float * scale)
6969
{
7070
int r;
7171
assert(RTSP_SETUP == rtsp->state || RTSP_PLAY == rtsp->state || RTSP_PAUSE == rtsp->state);
7272
rtsp->state = RTSP_PLAY;
7373
rtsp->progress = 0;
74-
rtsp->speed[0] = rtsp->range[0] = '\0';
75-
76-
if ( (speed && snprintf(rtsp->speed, sizeof(rtsp->speed), "Scale: %.2f\r\n", *speed) >= sizeof(rtsp->speed))
74+
rtsp->scale[0] = rtsp->range[0] = '\0';
75+
76+
#if RTSP_PLAY_SCALE == 2
77+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\n", *scale) >= sizeof(rtsp->scale))
78+
#elif defined(RTSP_PLAY_SCALE)
79+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale))
80+
#else
81+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\nScale: %.2f\r\n", *scale, *scale) >= sizeof(rtsp->scale))
82+
#endif
7783
|| (npt && snprintf(rtsp->range, sizeof(rtsp->range), "Range: npt=%" PRIu64 ".%" PRIu64 "-\r\n", *npt / 1000, *npt % 1000) >= sizeof(rtsp->range)) )
7884
return -1;
7985

@@ -82,7 +88,7 @@ int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const floa
8288
assert(rtsp->media_count > 0);
8389
assert(rtsp->aggregate_uri[0]);
8490
r = rtsp_client_authenrization(rtsp, "PLAY", rtsp->aggregate_uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization));
85-
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);
91+
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);
8692
return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->aggregate_uri, rtsp->req, r)) ? 0 : -1;
8793
}
8894
else
@@ -108,6 +114,8 @@ static int rtsp_client_media_play_onreply(struct rtsp_client_t* rtsp, void* pars
108114

109115
prange = http_get_header_by_name(parser, "Range");
110116
pscale = http_get_header_by_name(parser, "Scale");
117+
if(!pscale)
118+
pscale = http_get_header_by_name(parser, "Speed");
111119
prtpinfo = http_get_header_by_name(parser, "RTP-Info");
112120

113121
if (pscale)

librtsp/source/client/rtsp-client-record.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ int rtsp_client_record(struct rtsp_client_t *rtsp, const uint64_t *npt, const fl
6161
rtsp->progress = 0;
6262
rtsp->scale[0] = rtsp->range[0] = '\0';
6363

64-
if ( (scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale))
64+
#if RTSP_PLAY_SCALE == 2
65+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\n", *scale) >= sizeof(rtsp->scale))
66+
#elif defined(RTSP_PLAY_SCALE)
67+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Scale: %.2f\r\n", *scale) >= sizeof(rtsp->scale))
68+
#else
69+
if ((scale && snprintf(rtsp->scale, sizeof(rtsp->scale), "Speed: %.2f\r\nScale: %.2f\r\n", *scale, *scale) >= sizeof(rtsp->scale))
70+
#endif
6571
|| (npt && snprintf(rtsp->range, sizeof(rtsp->range), "Range: npt=%" PRIu64 ".%" PRIu64 "-\r\n", *npt / 1000, *npt % 1000) >= sizeof(rtsp->range)))
6672
return -1;
6773

@@ -95,6 +101,8 @@ static int rtsp_client_media_record_onreply(struct rtsp_client_t* rtsp, void* pa
95101

96102
prange = http_get_header_by_name(parser, "Range");
97103
pscale = http_get_header_by_name(parser, "Scale");
104+
if(!pscale)
105+
pscale = http_get_header_by_name(parser, "Speed");
98106
prtpinfo = http_get_header_by_name(parser, "RTP-Info");
99107

100108
if (pscale)

librtsp/source/server/rtsp-server-play.c

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ int rtsp_server_play(struct rtsp_server_t *rtsp, const char* uri)
1010
struct rtsp_header_range_t range;
1111

1212
pscale = http_get_header_by_name(rtsp->parser, "scale");
13+
if(!pscale)
14+
pscale = http_get_header_by_name(rtsp->parser, "speed");
1315
prange = http_get_header_by_name(rtsp->parser, "range");
1416

1517
if (0 == rtsp->session.session[0])

librtsp/source/server/rtsp-server-record.c

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ int rtsp_server_record(struct rtsp_server_t *rtsp, const char* uri)
1010
struct rtsp_header_range_t range;
1111

1212
pscale = http_get_header_by_name(rtsp->parser, "scale");
13+
if (!pscale)
14+
pscale = http_get_header_by_name(rtsp->parser, "speed");
1315
prange = http_get_header_by_name(rtsp->parser, "range");
1416

1517
if (0 == rtsp->session.session[0])

0 commit comments

Comments
 (0)