Skip to content

Commit

Permalink
fixed publish timestamp gap
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Nov 4, 2018
1 parent f5bfc17 commit 432cd69
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
8 changes: 5 additions & 3 deletions libdash/test/dash-dynamic-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ static int dash_live_worker(const char* file, dash_playlist_t* dash)
clock = system_clock(); // timestamp start from 0
while ((r = flv_reader_read(f, &type, &timestamp, dash->packet, sizeof(dash->packet))) > 0)
{
uint64_t t = system_clock();
if (clock + timestamp > t + 10)
system_sleep(clock + timestamp - t);
uint64_t t = system_clock();
if (clock + timestamp > t && clock + timestamp < t + 3 * 1000)
system_sleep(clock + timestamp - t);
else if (clock + timestamp > t + 3 * 1000)
clock = t - timestamp;

timestamp += diff;
s_timestamp = timestamp > s_timestamp ? timestamp : s_timestamp;
Expand Down
10 changes: 5 additions & 5 deletions librtmp/aio/aio-rtmp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static int rtmp_handler_onpause(void* param, int pause, uint32_t ms)
session = (struct aio_rtmp_session_t*)param;
if(session->server->handle.onpause && session->usr)
return session->server->handle.onpause(session->usr, pause, ms);
return -1;
return 0;
}

static int rtmp_handler_onseek(void* param, uint32_t ms)
Expand All @@ -245,7 +245,7 @@ static int rtmp_handler_onseek(void* param, uint32_t ms)
session = (struct aio_rtmp_session_t*)param;
if(session->server->handle.onseek && session->usr)
return session->server->handle.onseek(session->usr, ms);
return -1;
return 0;
}

static int rtmp_handler_onpublish(void* param, const char* app, const char* stream, const char* type)
Expand All @@ -262,7 +262,7 @@ static int rtmp_handler_onscript(void* param, const void* data, size_t bytes, ui
session = (struct aio_rtmp_session_t*)param;
if (session->server->handle.onscript && session->usr)
return session->server->handle.onscript(session->usr, data, bytes, timestamp);
return -1;
return 0;
}

static int rtmp_handler_onvideo(void* param, const void* data, size_t bytes, uint32_t timestamp)
Expand All @@ -271,7 +271,7 @@ static int rtmp_handler_onvideo(void* param, const void* data, size_t bytes, uin
session = (struct aio_rtmp_session_t*)param;
if(session->server->handle.onvideo && session->usr)
return session->server->handle.onvideo(session->usr, data, bytes, timestamp);
return -1;
return 0;
}

static int rtmp_handler_onaudio(void* param, const void* data, size_t bytes, uint32_t timestamp)
Expand All @@ -280,5 +280,5 @@ static int rtmp_handler_onaudio(void* param, const void* data, size_t bytes, uin
session = (struct aio_rtmp_session_t*)param;
if(session->server->handle.onaudio && session->usr)
return session->server->handle.onaudio(session->usr, data, bytes, timestamp);
return -1;
return 0;
}
8 changes: 4 additions & 4 deletions librtmp/source/rtmp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct rtmp_server_t
size_t handshake_bytes;
int handshake_state; // RTMP_HANDSHAKE_XXX

char app[64]; // Server application name, e.g.: testapp
struct rtmp_connect_t info; // Server application name, e.g.: testapp
char stream_name[256]; // Play/Publishing stream name, flv:sample, mp3:sample, H.264/AAC: mp4:sample.m4v
char stream_type[18]; // Publishing type: live/record/append
uint32_t stream_id; // createStream/deleteStream
Expand Down Expand Up @@ -168,7 +168,7 @@ static int rtmp_server_onconnect(void* param, int r, double transaction, const s
if (0 == r)
{
assert(1 == (int)transaction);
snprintf(ctx->app, sizeof(ctx->app), "%s", connect->app);
memcpy(&ctx->info, connect, sizeof(ctx->info));
r = rtmp_server_send_server_bandwidth(ctx);
r = 0 == r ? rtmp_server_send_client_bandwidth(ctx) : r;
r = 0 == r ? rtmp_server_send_set_chunk_size(ctx) : r;
Expand Down Expand Up @@ -248,7 +248,7 @@ static int rtmp_server_onpublish(void* param, int r, double transaction, const c

if (0 == r)
{
r = ctx->handler.onpublish(ctx->param, ctx->app, stream_name, stream_type);
r = ctx->handler.onpublish(ctx->param, ctx->info.app, stream_name, stream_type);
if (0 == r)
{
snprintf(ctx->stream_name, sizeof(ctx->stream_name), "%s", stream_name);
Expand All @@ -275,7 +275,7 @@ static int rtmp_server_onplay(void* param, int r, double transaction, const char

if (0 == r)
{
r = ctx->handler.onplay(ctx->param, ctx->app, stream_name, start, duration, reset);
r = ctx->handler.onplay(ctx->param, ctx->info.app, stream_name, start, duration, reset);
if (0 == r)
{
snprintf(ctx->stream_name, sizeof(ctx->stream_name), "%s", stream_name);
Expand Down
8 changes: 5 additions & 3 deletions librtmp/test/rtmp-publish-aio-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ static int STDCALL rtmp_client_push(void* flv)
static char packet[2 * 1024 * 1024];
while (0 == s_param.code && (r = flv_reader_read(f, &type, &timestamp, packet, sizeof(packet))) > 0)
{
uint64_t clock = system_clock();
if(clock0 + timestamp > clock && clock0 + timestamp < clock0 + 3 * 1000)
system_sleep(clock0 + timestamp - clock);
uint64_t t = system_clock();
if(clock0 + timestamp > t && clock0 + timestamp < t + 3 * 1000)
system_sleep(clock0 + timestamp - t);
else if (t + timestamp > t + 3 * 1000)
t = t - timestamp;

while (s_param.rtmp && aio_rtmp_client_get_unsend(s_param.rtmp) > 8 * 1024 * 1024)
system_sleep(1000); // can't send?
Expand Down
2 changes: 2 additions & 0 deletions librtmp/test/rtmp-publish-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static void rtmp_client_push(const char* flv, rtmp_client_t* rtmp)
uint64_t t = system_clock();
if (clock + timestamp > t && clock + timestamp < t + 3 * 1000) // dts skip
system_sleep(clock + timestamp - t);
else if (clock + timestamp > t + 3 * 1000)
clock = t - timestamp;

timestamp += diff;
s_timestamp = timestamp > s_timestamp ? timestamp : s_timestamp;
Expand Down
2 changes: 2 additions & 0 deletions librtmp/test/rtmp-server-vod-aio-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ static int STDCALL aio_rtmp_server_worker(void* param)
uint64_t t = system_clock();
if (clock + timestamp > t && clock + timestamp < t + 3 * 1000)
system_sleep(clock + timestamp - t);
else if (clock + timestamp > t + 3 * 1000)
clock = t - timestamp;

timestamp += diff;
s_timestamp = timestamp > s_timestamp ? timestamp : s_timestamp;
Expand Down
8 changes: 5 additions & 3 deletions librtmp/test/rtmp-server-vod-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ static int STDCALL rtmp_server_worker(void* param)
while ((r = flv_reader_read(f, &type, &timestamp, packet, sizeof(packet))) > 0)
{
assert(r < sizeof(packet));
uint64_t clock = system_clock();
if (clock0 + timestamp > clock && clock0 + timestamp < clock + 3 * 1000)
system_sleep(clock0 + timestamp - clock);
uint64_t t = system_clock();
if (clock0 + timestamp > t && clock0 + timestamp < t + 3 * 1000)
system_sleep(clock0 + timestamp - t);
else if (clock0 + timestamp > t + 3 * 1000)
clock0 = t - timestamp;

if (FLV_TYPE_AUDIO == type)
{
Expand Down

0 comments on commit 432cd69

Please sign in to comment.