ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.75k stars 5.28k forks source link

Issue with the invocation sequence of the HTTP hook API. #3909

Open terry8204 opened 6 months ago

terry8204 commented 6 months ago

Describe the bug Monitor whether the user has closed the browser using the HTTP hook API, and then automatically disconnect the device's stream. Each time the playback is clicked to restart, the 'on_play' event is received first, followed by the 'on_stop' event.

Configuration file:

    http_hooks {
        enabled on;
        on_play http://127.0.0.1/userwebservlet?action=srshookcallback;
        on_stop http://127.0.0.1/userwebservlet?action=srshookcallback;
        }

Version V6.0_d3

To Reproduce Steps to reproduce the behavior:

  1. Open the player to play the video.
  2. Replay the video.
  3. The HTTP API callback receives an 'on_play' event, followed by an 'on_stop' event.
  4. As a result of stopping the stream through the 'on_stop' event, the front-end browser is unable to play the video normally.

Expected behavior First, an 'on_stop' event is received, followed by an 'on_play' event.

Screenshots

  [2023-12-12 16:32:38,575] 920639 [catalina-exec-302] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack
  [2023-12-12 16:32:38,575] 920639 [catalina-exec-302] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack:{"server_id":"vid-2081113","service_id":"s8751307","action":"on_play","client_id":"8899843x","ip":"113.87.130.178","vhost":"__defaultVhost__","app":"live","stream":"19019000003_1_0_1078_video","tcUrl":"rtmp://__defaultVhost__/live","param":"","pageUrl":"https://gps51.com/","stream_url":"/live/19019000003_1_0_1078_video","stream_id":"vid-m057071"}
  [2023-12-12 16:32:38,575] 920639 [catalina-exec-302] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack removeCallBack:19019000003_1_1078
  [2023-12-12 16:32:39,149] 921213 [catalina-exec-303] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack
  [2023-12-12 16:32:39,149] 921213 [catalina-exec-303] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack:{"server_id":"vid-2081113","service_id":"s8751307","action":"on_stop","client_id":"lc5nz82m","ip":"113.87.130.178","vhost":"__defaultVhost__","app":"live","tcUrl":"rtmp://__defaultVhost__/live","stream":"19019000003_1_0_1078_video","param":"","stream_url":"/live/19019000003_1_0_1078_video","stream_id":"vid-m057071"}
  [2023-12-12 16:32:39,149] 921213 [catalina-exec-303] ERROR com.minigps.loc.userweb.UserWebServlet  - processSrsHookCallBack addCallBack:19019000003_1_1078
  [2023-12-12 16:32:41,822] 923886 [Timer-6] ERROR com.minigps.loc.userweb.SrsHookMgr  - processSrsHookCallBack forceDisconnectConnection:19019000003_1_1078

Additional context

TRANS_BY_GPT4

winlinvip commented 6 months ago

Could you please post the logs from SRS? When SRS triggers the on_play and on_stop callbacks, it generates logs with timestamp information.

TRANS_BY_GPT4

terry8204 commented 6 months ago
  1. Play device 53810829311.
  2. Click to replay, destroy the previous player instance (mpegts.js player), and then play again.
  3. From the log, it can be seen that the last callback is on_stop, while the actual video player is playing. Additional log:
    [2023-12-30 15:06:01.718][INFO][30378][6081177o] http: on_play ok, client_id=6081177o, url=http://127.0.0.1/userwebservlet?action=srshookcallback, request={"server_id":"vid-2081113","service_id":"9iv27566","action":"on_play","client_id":"6081177o","ip":"211.72.34.7","vhost":"__defaultVhost__","app":"live","stream":"53810829311_1_0_1078_video","tcUrl":"rtmp://__defaultVhost__/live","param":"","pageUrl":"https://gps51.com/","stream_url":"/live/53810829311_1_0_1078_video","stream_id":"vid-8kyv194"}, response={"code":0}
    [2023-12-30 15:06:01.718][INFO][30378][6081177o] FLV /live/53810829311_1_0_1078_video.flv, encoder=FLV, mw_sleep=100ms, cache=0, msgs=128, dinm=1, guess_av=0/1/1
    [2023-12-30 15:06:01.827][INFO][30378][2w010367] http: on_stop ok, client_id=2w010367, url=http://127.0.0.1/userwebservlet?action=srshookcallback, request={"server_id":"vid-2081113","service_id":"9iv27566","action":"on_stop","client_id":"2w010367","ip":"211.72.34.7","vhost":"__defaultVhost__","app":"live","tcUrl":"rtmp://__defaultVhost__/live","stream":"53810829311_1_0_1078_video","param":"","stream_url":"/live/53810829311_1_0_1078_video","stream_id":"vid-8kyv194"}, response={"code":0}
    [2023-12-30 15:06:01.909][INFO][30378][759vl211] HTTP #0 127.0.0.1:41838 GET http://rtmpbackend/live/53810829311_1_0_1078_video.flv, content-length=-1
    [2023-12-30 15:06:01.911][INFO][30378][759vl211] http: on_play ok, client_id=759vl211, url=http://127.0.0.1/userwebservlet?action=srshookcallback, request={"server_id":"vid-2081113","service_id":"9iv27566","action":"on_play","client_id":"759vl211","ip":"211.72.34.7","vhost":"__defaultVhost__","app":"live","stream":"53810829311_1_0_1078_video","tcUrl":"rtmp://__defaultVhost__/live","param":"","pageUrl":"https://gps51.com/","stream_url":"/live/53810829311_1_0_1078_video","stream_id":"vid-8kyv194"}, response={"code":0}
    [2023-12-30 15:06:01.912][INFO][30378][759vl211] FLV /live/53810829311_1_0_1078_video.flv, encoder=FLV, mw_sleep=100ms, cache=0, msgs=128, dinm=1, guess_av=0/1/1
    [2023-12-30 15:06:01.920][INFO][30378][6081177o] http: on_stop ok, client_id=6081177o, url=http://127.0.0.1/userwebservlet?action=srshookcallback, request={"server_id":"vid-2081113","service_id":"9iv27566","action":"on_stop","client_id":"6081177o","ip":"211.72.34.7","vhost":"__defaultVhost__","app":"live","tcUrl":"rtmp://__defaultVhost__/live","stream":"53810829311_1_0_1078_video","param":"","stream_url":"/live/53810829311_1_0_1078_video","stream_id":"vid-8kyv194"}, response={"code":0}

TRANS_BY_GPT4

winlinvip commented 6 months ago

This issue is indeed quite peculiar. I will take some time to look into it next week. Thank you for the feedback.

TRANS_BY_GPT4

winlinvip commented 5 months ago

Run SRS 5.0:

./objs/srs -c conf/http.hooks.callback.conf

Run callback server:

go run research/api-server/server.go

Publish stream to SRS:

ffmpeg -re -i ~/srs/doc/source.flv -c copy -f flv rtmp://localhost/live/livestream

Use ffmpeg as player to pull stream, which should trigger on_play and on_stop:

ffmpeg -i rtmp://localhost/live/livestream

The events is on_play then on_stop:

2024/01/09 15:03:09.112678 server.go:689: Got action=on_play, client_id=08g9611r, ip=127.0.0.1, vhost=__defaultVhost__, stream=livestream, param=, pageUrl=
2024/01/09 15:03:09.461312 server.go:689: Got action=on_stop, client_id=08g9611r, ip=127.0.0.1, vhost=__defaultVhost__, stream=livestream, param=

I can not reproduce this issue.

winlinvip commented 5 months ago

What's your SRS version?

terry8204 commented 5 months ago

version: V6.0_d3 The first playback occurs without issues. During the second operation, the first playback is terminated while initiating a new playback session.

TRANS_BY_GPT4