fix: prevent segfault on --use_fake_clock_for_muxer (#1289)

The option for --use_fake_clock_for_muxer was resulting in a segfault,
exposed by the integration tests. Switch to using a shared_ptr for
Clock.
This commit is contained in:
Cosmin Stejerean 2023-11-30 13:42:18 -08:00 committed by GitHub
parent 01e7f3bd19
commit 8bb1961c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -78,7 +78,7 @@ std::shared_ptr<Muxer> MuxerFactory::CreateMuxer(
return muxer; return muxer;
} }
void MuxerFactory::OverrideClock(Clock* clock) { void MuxerFactory::OverrideClock(std::shared_ptr<Clock> clock) {
clock_ = clock; clock_ = clock;
} }
} // namespace media } // namespace media

View File

@ -37,7 +37,7 @@ class MuxerFactory {
/// For testing, if you need to replace the clock that muxers work with /// For testing, if you need to replace the clock that muxers work with
/// this will replace the clock for all muxers created after this call. /// this will replace the clock for all muxers created after this call.
void OverrideClock(Clock* clock); void OverrideClock(std::shared_ptr<Clock> clock);
void SetTsStreamOffset(int32_t offset_ms) { void SetTsStreamOffset(int32_t offset_ms) {
transport_stream_timestamp_offset_ms_ = offset_ms; transport_stream_timestamp_offset_ms_ = offset_ms;
@ -50,7 +50,7 @@ class MuxerFactory {
const Mp4OutputParams mp4_params_; const Mp4OutputParams mp4_params_;
const std::string temp_dir_; const std::string temp_dir_;
int32_t transport_stream_timestamp_offset_ms_ = 0; int32_t transport_stream_timestamp_offset_ms_ = 0;
Clock* clock_ = nullptr; std::shared_ptr<Clock> clock_ = nullptr;
}; };
} // namespace media } // namespace media

View File

@ -54,7 +54,7 @@ class Muxer : public MediaHandler {
/// If no clock is injected, the code uses std::chrone::system_clock::now() /// If no clock is injected, the code uses std::chrone::system_clock::now()
/// to generate the time-stamps. /// to generate the time-stamps.
/// @param clock is the Clock to be injected. /// @param clock is the Clock to be injected.
void set_clock(Clock* clock) { clock_.reset(clock); } void set_clock(std::shared_ptr<Clock> clock) { clock_ = clock; }
protected: protected:
/// @name MediaHandler implementation overrides. /// @name MediaHandler implementation overrides.
@ -112,7 +112,7 @@ class Muxer : public MediaHandler {
std::unique_ptr<MuxerListener> muxer_listener_; std::unique_ptr<MuxerListener> muxer_listener_;
std::unique_ptr<ProgressListener> progress_listener_; std::unique_ptr<ProgressListener> progress_listener_;
std::unique_ptr<Clock> clock_; std::shared_ptr<Clock> clock_;
// In VOD single segment case with Ad Cues, |output_file_name| is allowed to // In VOD single segment case with Ad Cues, |output_file_name| is allowed to
// be a template. In this case, there will be NumAdCues + 1 files generated. // be a template. In this case, there will be NumAdCues + 1 files generated.

View File

@ -809,7 +809,7 @@ Status CreateAllJobs(const std::vector<StreamDescriptor>& stream_descriptors,
} // namespace media } // namespace media
struct Packager::PackagerInternal { struct Packager::PackagerInternal {
media::FakeClock fake_clock; std::shared_ptr<media::FakeClock> fake_clock;
std::unique_ptr<KeySource> encryption_key_source; std::unique_ptr<KeySource> encryption_key_source;
std::unique_ptr<MpdNotifier> mpd_notifier; std::unique_ptr<MpdNotifier> mpd_notifier;
std::unique_ptr<hls::HlsNotifier> hls_notifier; std::unique_ptr<hls::HlsNotifier> hls_notifier;
@ -942,7 +942,7 @@ Status Packager::Initialize(
media::MuxerFactory muxer_factory(packaging_params); media::MuxerFactory muxer_factory(packaging_params);
if (packaging_params.test_params.inject_fake_clock) { if (packaging_params.test_params.inject_fake_clock) {
muxer_factory.OverrideClock(&internal->fake_clock); muxer_factory.OverrideClock(internal->fake_clock);
} }
media::MuxerListenerFactory muxer_listener_factory( media::MuxerListenerFactory muxer_listener_factory(