videoLIVE555Source: fix the crash in the destructor #22

Merged
ClaudeAI merged 1 commits from fix/live555-source-destructor into master 42 minutes ago
Collaborator

Summary

Fixes the crash in the videoLIVE555Source destructor (lib/data/media/video/videoLive555AVLibSource.cpp/.h).

What caused the crash

  • Wrong thread: ~videoLIVE555Source -> _stop() -> shutdownStream() ran on the caller's thread while the live555 thread was still inside doEventLoop(). It deleted the RTSP client, the environment and the task scheduler under the running loop.
  • Double shutdown: a second shutdown used the scheduler and client that had already been deleted. This happened after _close() followed by the destructor, or after a live555 callback (DESCRIBE/PLAY failure, RTCP BYE, stream timer) followed by the destructor.
  • Uninitialised client pointer: m_pRtspClient was not initialised, so a source that was never opened, or failed to open, shut down a random pointer.
  • DummySink pointers: they were not initialised. The destructor freed an uninitialised m_pFrame when the codec was not found, and always in stream-proxy mode.
  • Proxy plus decode: with STREAM_PROXY | DECODE_FRAMES (as deviceNodeCamera sets them), the decode frames and scaler were never created, but every received frame was decoded with them.

Changes

  • _stop() sets the event-loop flag, joins the live555 thread, then closes what is left on the calling thread. Called from a live555 callback, it only ends the loop.
  • shutdownStream() closes the subsession sinks and sends TEARDOWN, as live555 testRTSPClient does, then closes the client. It no longer frees the scheduler or environment, and a second call does nothing. Only the destructor frees the scheduler and environment, once.
  • All pointers are initialised in both constructors (initMembers()).
  • The event-loop flag is reset in _open() instead of at thread start, so a stop issued before the thread runs is not lost.
  • DummySink:
    • every pointer is NULL until allocated;
    • the decode resources are created whenever DECODE_FRAMES is set, and decoding is skipped if any is missing (canDecode());
    • m_sAvPkt is zeroed;
    • the destructor frees the frames, RGB buffer, scaler, codec context, output format context and dictionary, and m_pH264;
    • the trailer is written only after a written header.
  • continueAfterPLAY frees resultString.

Testing

  • The file compiles with -Wall -W and no warnings against the current live555 headers. For the check, the event-loop flag type was swapped to EventLoopWatchVariable in a temporary copy, because the newest live555 uses std::atomic<char>. The repo keeps volatile char for the version in use.
  • Not linked or run: live555 is not installed in the check environment.

Please check on the target

  • TEARDOWN is now sent: before, it was commented out with "Must be checked if Client is connected before sending TearDown". It is sent only when at least one subsession was set up (sink active). It is a single line to remove if it causes trouble.
  • Test cases: open a stream and delete the source while it plays; delete a source that failed to open; check with a camera that drops the stream (BYE).

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary Fixes the crash in the `videoLIVE555Source` destructor (`lib/data/media/video/videoLive555AVLibSource.cpp/.h`). ### What caused the crash - **Wrong thread:** `~videoLIVE555Source` -> `_stop()` -> `shutdownStream()` ran on the caller's thread while the live555 thread was still inside `doEventLoop()`. It deleted the RTSP client, the environment and the task scheduler under the running loop. - **Double shutdown:** a second shutdown used the scheduler and client that had already been deleted. This happened after `_close()` followed by the destructor, or after a live555 callback (DESCRIBE/PLAY failure, RTCP BYE, stream timer) followed by the destructor. - **Uninitialised client pointer:** `m_pRtspClient` was not initialised, so a source that was never opened, or failed to open, shut down a random pointer. - **`DummySink` pointers:** they were not initialised. The destructor freed an uninitialised `m_pFrame` when the codec was not found, and always in stream-proxy mode. - **Proxy plus decode:** with `STREAM_PROXY | DECODE_FRAMES` (as `deviceNodeCamera` sets them), the decode frames and scaler were never created, but every received frame was decoded with them. ### Changes - `_stop()` sets the event-loop flag, joins the live555 thread, then closes what is left on the calling thread. Called from a live555 callback, it only ends the loop. - `shutdownStream()` closes the subsession sinks and sends TEARDOWN, as live555 `testRTSPClient` does, then closes the client. It no longer frees the scheduler or environment, and a second call does nothing. Only the destructor frees the scheduler and environment, once. - All pointers are initialised in both constructors (`initMembers()`). - The event-loop flag is reset in `_open()` instead of at thread start, so a stop issued before the thread runs is not lost. - `DummySink`: - every pointer is NULL until allocated; - the decode resources are created whenever `DECODE_FRAMES` is set, and decoding is skipped if any is missing (`canDecode()`); - `m_sAvPkt` is zeroed; - the destructor frees the frames, RGB buffer, scaler, codec context, output format context and dictionary, and `m_pH264`; - the trailer is written only after a written header. - `continueAfterPLAY` frees `resultString`. ## Testing - The file compiles with `-Wall -W` and no warnings against the current live555 headers. For the check, the event-loop flag type was swapped to `EventLoopWatchVariable` in a temporary copy, because the newest live555 uses `std::atomic<char>`. The repo keeps `volatile char` for the version in use. - **Not linked or run:** live555 is not installed in the check environment. ## Please check on the target - **TEARDOWN is now sent:** before, it was commented out with "Must be checked if Client is connected before sending TearDown". It is sent only when at least one subsession was set up (sink active). It is a single line to remove if it causes trouble. - **Test cases:** open a stream and delete the source while it plays; delete a source that failed to open; check with a camera that drops the stream (BYE). Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 1 commit 43 minutes ago
b12fb1e907
videoLIVE555Source: fix the crash in the destructor
ClaudeAI merged commit 24df4668f1 into master 42 minutes ago
The pull request has been merged as 24df4668f1.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.