Skip to content

Commit

Permalink
change: rtsp client play range npt/clock
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed May 5, 2024
1 parent c3865b7 commit c0ade3f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
14 changes: 13 additions & 1 deletion librtsp/source/client/rtsp-client-play.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Date: 23 Jan 1997 15:35:06 GMT
#include "rtsp-header-range.h"
#include "rtsp-header-rtp-info.h"
#include <assert.h>
#include <time.h>

static const char* sc_format =
"PLAY %s RTSP/1.0\r\n"
Expand All @@ -51,6 +52,17 @@ static const char* sc_format =
"User-Agent: %s\r\n"
"\r\n";

int rtsp_header_range_write(char* s, int n, uint64_t npt)
{
time_t now;
if (npt / 1000 < 946656000 /* 2000-01-01 00:00:00 */ ) {
return snprintf(s, n, "Range: npt=%" PRIu64 ".%" PRIu64 "-\r\n", npt / 1000, npt % 1000);
} else {
now = npt / 1000; // ms -> s
return strftime(s, n, "Range: clock=%Y%m%dT%H%M%SZ-\r\n", gmtime(&now));
}
}

static int rtsp_client_media_play(struct rtsp_client_t *rtsp, int i)
{
int r;
Expand Down Expand Up @@ -80,7 +92,7 @@ int rtsp_client_play(struct rtsp_client_t *rtsp, const uint64_t *npt, const floa
#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)) )
|| (npt && rtsp_header_range_write(rtsp->range, sizeof(rtsp->range), *npt) >= sizeof(rtsp->range)))
return -1;

if(rtsp->aggregate)
Expand Down
4 changes: 3 additions & 1 deletion librtsp/source/client/rtsp-client-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static const char* sc_format =
"User-Agent: %s\r\n"
"\r\n";

int rtsp_header_range_write(char* s, int n, uint64_t npt);

static int rtsp_client_media_record(struct rtsp_client_t *rtsp, int i)
{
int r;
Expand Down Expand Up @@ -68,7 +70,7 @@ int rtsp_client_record(struct rtsp_client_t *rtsp, const uint64_t *npt, const fl
#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)))
|| (npt && rtsp_header_range_write(rtsp->range, sizeof(rtsp->range), *npt) >= sizeof(rtsp->range)))
return -1;

if (rtsp->aggregate)
Expand Down
18 changes: 2 additions & 16 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ SOURCE_PATHS = . $(ROOT)/source/digest $(ROOT)/libhttp/test \

SOURCE_FILES = $(foreach dir,$(SOURCE_PATHS),$(wildcard $(dir)/*.cpp))
SOURCE_FILES += $(foreach dir,$(SOURCE_PATHS),$(wildcard $(dir)/*.c))
SOURCE_FILES += $(ROOT)/source/uri-parse.c
SOURCE_FILES += $(ROOT)/source/urlcodec.c
SOURCE_FILES += $(ROOT)/source/ntp-time.c
SOURCE_FILES += $(ROOT)/source/time64.c
SOURCE_FILES += $(ROOT)/source/base64.c
SOURCE_FILES += $(ROOT)/source/unicode.c
SOURCE_FILES += $(ROOT)/source/thread-pool.c
SOURCE_FILES += $(ROOT)/source/app-log.c
SOURCE_FILES += $(ROOT)/source/port/ip-route.c
SOURCE_FILES += $(ROOT)/source/sockpair.c
SOURCE_FILES += $(ROOT)/source/darray.c
SOURCE_FILES += $(ROOT)/source/channel.c
SOURCE_FILES += $(ROOT)/source/uuid.c
SOURCE_FILES += $(ROOT)/source/random.c
SOURCE_FILES += $(ROOT)/source/port/sysnetconfig.c
SOURCE_FILES += $(ROOT)/libice/test/ice-transport.c
SOURCE_FILES += $(ROOT)/deprecated/tools.c

Expand Down Expand Up @@ -89,7 +74,8 @@ STATIC_LIBS = ../libdash/$(BUILD).$(PLATFORM)/libdash.a \
$(AVCODEC)/avbsf/$(BUILD).$(PLATFORM)/libavbsf.a \
$(AVCODEC)/avcodec/$(BUILD).$(PLATFORM)/libavcodec.a \
$(AVCODEC)/h264/$(BUILD).$(PLATFORM)/libh264.a \
$(AVCODEC)/h265/$(BUILD).$(PLATFORM)/libh265.a
$(AVCODEC)/h265/$(BUILD).$(PLATFORM)/libh265.a \
$(ROOT)/libsdk/$(BUILD).$(PLATFORM)/libsdk.a


#-----------------------------DEFINES--------------------------------
Expand Down
3 changes: 3 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ DEF_FUN_PCHAR(mpeg_ts_dec_test, const char* file);
DEF_FUN_PCHAR(mpeg_ts_test, const char* input);
DEF_FUN_PCHAR(mpeg_ps_test, const char* input);
DEF_FUN_PCHAR(mpeg_ps_2_flv_test, const char* ps);
DEF_FUN_PCHAR(mov_2_mpeg_ps_test, const char* mp4);
DEF_FUN_PCHAR(flv_2_mpeg_ps_test, const char* flv);
DEF_FUN_PCHAR(mpeg_ps_dec_test, const char* file);

Expand Down Expand Up @@ -220,6 +221,7 @@ extern "C" DEF_FUN_VOID(sip_header_test);
extern "C" DEF_FUN_VOID(sip_agent_test);
DEF_FUN_VOID(sip_uac_message_test);
DEF_FUN_VOID(sip_uas_message_test);
DEF_FUN_VOID(sip_message_test);
DEF_FUN_VOID(sip_uac_test);
DEF_FUN_VOID(sip_uas_test);
DEF_FUN_VOID(sip_uac_test2);
Expand Down Expand Up @@ -262,6 +264,7 @@ int main(int argc, const char* argv[])
RE_RUN_REG("http_header_www_authenticate_test", argc, argv);
RE_RUN_REG("rtsp_client_auth_test", argc, argv);
RE_RUN_REG("sip_header_test", argc, argv);
RE_RUN_REG("sip_message_test", argc, argv);
RE_RUN_REG("sip_uac_message_test", argc, argv);
RE_RUN_REG("sip_uas_message_test", argc, argv);
goto EXIT;
Expand Down
1 change: 1 addition & 0 deletions test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
<ClCompile Include="..\libmov\test\mov-writer-subtitle.cpp" />
<ClCompile Include="..\libmov\test\mov-writer-test.cpp" />
<ClCompile Include="..\libmpeg\test\flv-2-mpeg-ps-test.cpp" />
<ClCompile Include="..\libmpeg\test\mov-2-mpeg-ps-test.cpp" />
<ClCompile Include="..\libmpeg\test\mpeg-ps-2-flv-test.cpp" />
<ClCompile Include="..\libmpeg\test\mpeg-ps-dec-test.cpp" />
<ClCompile Include="..\libmpeg\test\mpeg-ps-test.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions test/test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@
<ClCompile Include="..\librtsp\test\rtsp-client-test2.c">
<Filter>librtsp</Filter>
</ClCompile>
<ClCompile Include="..\libmpeg\test\mov-2-mpeg-ps-test.cpp">
<Filter>libmpeg</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\libflv\test\rtmp.onStatus.amf0">
Expand Down

0 comments on commit c0ade3f

Please sign in to comment.