From 452ca7e88f7b3f680f9e69331df4bbf3dedf707e Mon Sep 17 00:00:00 2001 From: matthew1838 <77285055+matthew1838@users.noreply.github.com> Date: Wed, 11 Aug 2021 09:38:22 +0700 Subject: [PATCH 1/2] add server_id into http_hooks (#2521) Co-authored-by: SK --- trunk/conf/full.conf | 19 ++++++++++--------- trunk/src/app/srs_app_http_hooks.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index f6bcd2783..5a93333f7 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -1078,7 +1078,7 @@ vhost hooks.callback.srs.com { # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # "tcUrl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a", - # "pageUrl": "http://www.test.com/live.html" + # "pageUrl": "http://www.test.com/live.html", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1094,7 +1094,7 @@ vhost hooks.callback.srs.com { # "action": "on_close", # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", - # "send_bytes": 10240, "recv_bytes": 10240 + # "send_bytes": 10240, "recv_bytes": 10240, "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1110,7 +1110,7 @@ vhost hooks.callback.srs.com { # "action": "on_publish", # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", - # "stream": "livestream", "param":"?token=xxx&salt=yyy" + # "stream": "livestream", "param":"?token=xxx&salt=yyy", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1126,7 +1126,7 @@ vhost hooks.callback.srs.com { # "action": "on_unpublish", # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", - # "stream": "livestream", "param":"?token=xxx&salt=yyy" + # "stream": "livestream", "param":"?token=xxx&salt=yyy", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1143,7 +1143,7 @@ vhost hooks.callback.srs.com { # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # "stream": "livestream", "param":"?token=xxx&salt=yyy", - # "pageUrl": "http://www.test.com/live.html" + # "pageUrl": "http://www.test.com/live.html", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1159,7 +1159,7 @@ vhost hooks.callback.srs.com { # "action": "on_stop", # "client_id": 1985, # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", - # "stream": "livestream", "param":"?token=xxx&salt=yyy" + # "stream": "livestream", "param":"?token=xxx&salt=yyy", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1177,7 +1177,7 @@ vhost hooks.callback.srs.com { # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # "stream": "livestream", "param":"?token=xxx&salt=yyy", # "cwd": "/usr/local/srs", - # "file": "./objs/nginx/html/live/livestream.1420254068776.flv" + # "file": "./objs/nginx/html/live/livestream.1420254068776.flv", "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1196,7 +1196,7 @@ vhost hooks.callback.srs.com { # "url": "live/livestream/2015-04-23/01/476584165.ts", # "m3u8": "./objs/nginx/html/live/livestream/live.m3u8", # "m3u8_url": "live/livestream/live.m3u8", - # "seq_no": 100 + # "seq_no": 100, "server_id": "vid-werty" # } # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): @@ -1205,13 +1205,14 @@ vhost hooks.callback.srs.com { # when srs reap a ts file of hls, call this hook, # used to push file to cdn network, by get the ts file from cdn network. # so we use HTTP GET and use the variable following: + # [server_id], replace with the server_id # [app], replace with the app. # [stream], replace with the stream. # [param], replace with the param. # [ts_url], replace with the ts url. # ignore any return data of server. # @remark random select a url to report, not report all. - on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param]; + on_hls_notify http://127.0.0.1:8085/api/v1/hls/[server_id]/[app]/[stream]/[ts_url][param]; } } diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index caedf3a62..4d642a862 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -21,6 +21,7 @@ using namespace std; #include #include #include +#include #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) @@ -78,9 +79,12 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int SrsContextId cid = _srs_context->get_id(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_close")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -114,9 +118,12 @@ srs_error_t SrsHttpHooks::on_publish(string url, SrsRequest* req) SrsContextId cid = _srs_context->get_id(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_publish")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -148,9 +155,12 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) SrsContextId cid = _srs_context->get_id(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_unpublish")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -184,9 +194,12 @@ srs_error_t SrsHttpHooks::on_play(string url, SrsRequest* req) SrsContextId cid = _srs_context->get_id(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_play")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -218,9 +231,12 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) SrsContextId cid = _srs_context->get_id(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_stop")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -255,9 +271,12 @@ srs_error_t SrsHttpHooks::on_dvr(SrsContextId c, string url, SrsRequest* req, st SrsContextId cid = c; std::string cwd = _srs_config->cwd(); + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_dvr")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -297,9 +316,12 @@ srs_error_t SrsHttpHooks::on_hls(SrsContextId c, string url, SrsRequest* req, st ts_url = prefix + "/" + ts_url; } + SrsStatistic* stat = SrsStatistic::instance(); + SrsJsonObject* obj = SrsJsonAny::object(); SrsAutoFree(SrsJsonObject, obj); + obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("action", SrsJsonAny::str("on_hls")); obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("ip", SrsJsonAny::str(req->ip.c_str())); @@ -341,6 +363,9 @@ srs_error_t SrsHttpHooks::on_hls_notify(SrsContextId c, std::string url, SrsRequ url = ts_url; } + SrsStatistic* stat = SrsStatistic::instance(); + + url = srs_string_replace(url, "[server_id]", stat->server_id().c_str()); url = srs_string_replace(url, "[app]", req->app); url = srs_string_replace(url, "[stream]", req->stream); url = srs_string_replace(url, "[ts_url]", ts_url); From ab988abc59b8d4db2a3bc649283b5f5fb4b48cd8 Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Fri, 13 Aug 2021 12:05:28 +0800 Subject: [PATCH 2/2] For #2516, fix codec issue for G.711 or H.263. 4.0.152 --- CHANGELOG.md | 1 + trunk/src/app/srs_app_dash.cpp | 12 ++++++++++-- trunk/src/app/srs_app_source.cpp | 6 ++++++ trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/kernel/srs_kernel_ts.cpp | 12 ++++++++++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0bd5268..bfd05672c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-08-13, RTC: Merge [#2526](https://github.com/ossrs/srs/pull/2526), fix codec issue for G.711 or H.263. 4.0.152 * v4.0, 2021-08-10, RTC: Merge [#2509](https://github.com/ossrs/srs/pull/2514), support http hooks n_play/stop/publish/unpublish. 4.0.151 * v4.0, 2021-08-07, Merge [#2514](https://github.com/ossrs/srs/pull/2514), Get original client ip instead of proxy ip, for rtc api #2514. 4.0.150 * v4.0, 2021-08-07, Fix [#2508](https://github.com/ossrs/srs/pull/2508), Support features query by API. 4.0.149 diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index ef9082cfa..e3ec90a14 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -540,7 +540,11 @@ srs_error_t SrsDash::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* form if (!enabled) { return err; } - + + if (!format->acodec) { + return err; + } + if ((err = controller->on_audio(shared_audio, format)) != srs_success) { return srs_error_wrap(err, "Consume audio failed"); } @@ -555,7 +559,11 @@ srs_error_t SrsDash::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* form if (!enabled) { return err; } - + + if (!format->vcodec) { + return err; + } + if ((err = controller->on_video(shared_video, format)) != srs_success) { return srs_error_wrap(err, "Consume video failed"); } diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index e09892c51..aae228b48 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -931,6 +931,12 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) if ((err = format->on_audio(msg)) != srs_success) { return srs_error_wrap(err, "format consume audio"); } + + // Ignore if no format->acodec, it means the codec is not parsed, or unsupport/unknown codec + // such as G.711 codec + if (!format->acodec) { + return err; + } // cache the sequence header if aac // donot cache the sequence header to gop_cache, return here. diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 29d64471e..c0afc04a2 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 151 +#define VERSION_REVISION 152 #endif diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index a6f0d3809..96a95c0ff 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -3064,7 +3064,11 @@ srs_error_t SrsTsTransmuxer::write_audio(int64_t timestamp, char* data, int size if ((err = format->on_audio(timestamp, data, size)) != srs_success) { return srs_error_wrap(err, "ts: format on audio"); } - + + if (!format->acodec) { + return err; + } + // ts support audio codec: aac/mp3 srs_assert(format->acodec && format->audio); if (format->acodec->id != SrsAudioCodecIdAAC && format->acodec->id != SrsAudioCodecIdMP3) { @@ -3100,7 +3104,11 @@ srs_error_t SrsTsTransmuxer::write_video(int64_t timestamp, char* data, int size if ((err = format->on_video(timestamp, data, size)) != srs_success) { return srs_error_wrap(err, "ts: on video"); } - + + if (!format->vcodec) { + return err; + } + // ignore info frame, // @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909 srs_assert(format->video && format->vcodec);