Skip to content

Commit

Permalink
防止对象析构时抛异常导致的崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-chu committed Jul 5, 2024
1 parent 8815776 commit b4fecdc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/FMP4/FMP4MediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class FMP4MediaSource final : public MediaSource, public toolkit::RingDelegate<F
FMP4MediaSource(const MediaTuple& tuple,
int ring_size = FMP4_GOP_SIZE) : MediaSource(FMP4_SCHEMA, tuple), _ring_size(ring_size) {}

~FMP4MediaSource() override { flush(); }
~FMP4MediaSource() override {
try {
flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

/**
* 获取媒体源的环形缓冲
Expand Down
8 changes: 7 additions & 1 deletion src/FMP4/FMP4MediaSourceMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class FMP4MediaSourceMuxer final : public MP4MuxerMemory, public MediaSourceEven
_media_src = std::make_shared<FMP4MediaSource>(tuple);
}

~FMP4MediaSourceMuxer() override { MP4MuxerMemory::flush(); };
~FMP4MediaSourceMuxer() override {
try {
MP4MuxerMemory::flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
setDelegate(listener);
Expand Down
16 changes: 14 additions & 2 deletions src/Record/HlsRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ class HlsRecorder final : public HlsRecorderBase<MpegMuxer> {
using Ptr = std::shared_ptr<HlsRecorder>;
template <typename ...ARGS>
HlsRecorder(ARGS && ...args) : HlsRecorderBase<MpegMuxer>(false, std::forward<ARGS>(args)...) {}
~HlsRecorder() override { this->flush(); }
~HlsRecorder() override {
try {
this->flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

private:
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint64_t timestamp, bool key_pos) override {
Expand All @@ -102,7 +108,13 @@ class HlsFMP4Recorder final : public HlsRecorderBase<MP4MuxerMemory> {
using Ptr = std::shared_ptr<HlsFMP4Recorder>;
template <typename ...ARGS>
HlsFMP4Recorder(ARGS && ...args) : HlsRecorderBase<MP4MuxerMemory>(true, std::forward<ARGS>(args)...) {}
~HlsFMP4Recorder() override { this->flush(); }
~HlsFMP4Recorder() override {
try {
this->flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

void addTrackCompleted() override {
HlsRecorderBase<MP4MuxerMemory>::addTrackCompleted();
Expand Down
8 changes: 7 additions & 1 deletion src/Rtmp/RtmpMediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ class RtmpMediaSource : public MediaSource, public toolkit::RingDelegate<RtmpPac
*/
RtmpMediaSource(const MediaTuple& tuple, int ring_size = RTMP_GOP_SIZE): MediaSource(RTMP_SCHEMA, tuple), _ring_size(ring_size) {}

~RtmpMediaSource() override { flush(); }
~RtmpMediaSource() override {
try {
flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

/**
* 获取媒体源的环形缓冲
Expand Down
8 changes: 7 additions & 1 deletion src/Rtsp/RtspMediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class RtspMediaSource : public MediaSource, public toolkit::RingDelegate<RtpPack
*/
RtspMediaSource(const MediaTuple& tuple, int ring_size = RTP_GOP_SIZE): MediaSource(RTSP_SCHEMA, tuple), _ring_size(ring_size) {}

~RtspMediaSource() override { flush(); }
~RtspMediaSource() override {
try {
flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

/**
* 获取媒体源的环形缓冲
Expand Down
8 changes: 7 additions & 1 deletion src/Rtsp/RtspMediaSourceMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class RtspMediaSourceMuxer final : public RtspMuxer, public MediaSourceEventInte
getRtpRing()->setDelegate(_media_src);
}

~RtspMediaSourceMuxer() override { RtspMuxer::flush(); }
~RtspMediaSourceMuxer() override {
try {
RtspMuxer::flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
setDelegate(listener);
Expand Down
8 changes: 7 additions & 1 deletion src/TS/TSMediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ class TSMediaSource final : public MediaSource, public toolkit::RingDelegate<TSP

TSMediaSource(const MediaTuple& tuple, int ring_size = TS_GOP_SIZE): MediaSource(TS_SCHEMA, tuple), _ring_size(ring_size) {}

~TSMediaSource() override { flush(); }
~TSMediaSource() override {
try {
flush();
} catch (std::exception &ex) {
WarnL << ex.what();
}
}

/**
* 获取媒体源的环形缓冲
Expand Down

0 comments on commit b4fecdc

Please sign in to comment.