Skip to content

Commit

Permalink
Apply <Server><Name> to HLS service name
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Oct 26, 2021
1 parent f270c76 commit fdce909
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/projects/modules/segment_writer/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool Writer::AddTrack(const std::shared_ptr<const MediaTrack> &media_track)
return true;
}

bool Writer::Prepare()
bool Writer::Prepare(ov::String service_name)
{
if (_format_context != nullptr)
{
Expand Down Expand Up @@ -400,7 +400,7 @@ bool Writer::Prepare()

format_context->pb = avio_context.get();

::av_dict_set(&(format_context->metadata), "service_name", "OvenMediaEngine", 0);
::av_dict_set(&(format_context->metadata), "service_name", service_name.CStr(), 0);
::av_dict_set(&(format_context->metadata), "service_provider", "OvenMediaEngine", 0);

AVDictionary *options = nullptr;
Expand Down Expand Up @@ -450,14 +450,14 @@ bool Writer::Prepare()
return true;
}

bool Writer::PrepareIfNeeded()
bool Writer::PrepareIfNeeded(ov::String service_name)
{
if (_format_context != nullptr)
{
return true;
}

return Prepare();
return Prepare(service_name);
}

int Writer::DecideBufferSize() const
Expand Down
4 changes: 2 additions & 2 deletions src/projects/modules/segment_writer/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Writer
}

bool AddTrack(const std::shared_ptr<const MediaTrack> &media_track);
bool Prepare();
bool PrepareIfNeeded();
bool Prepare(ov::String service_name = "");
bool PrepareIfNeeded(ov::String service_name = "");

bool ResetData(int track_id = -1);
std::shared_ptr<const ov::Data> GetData() const;
Expand Down
3 changes: 2 additions & 1 deletion src/projects/publishers/segment/cmaf/cmaf_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ bool CmafApplication::Start()
std::shared_ptr<pub::Stream> CmafApplication::CreateStream(const std::shared_ptr<info::Stream> &info, uint32_t thread_count)
{
logtd("LL-DASH Stream is created: %s/%u", info->GetName().CStr(), info->GetId());
auto server_config = cfg::ConfigManager::GetInstance()->GetServer();

return SegmentStream::Create(
GetSharedPtrAs<pub::Application>(), *info.get(),
[=](ov::String app_name, ov::String stream_name,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track) -> std::shared_ptr<Packetizer> {
return std::make_shared<CmafPacketizer>(
app_name, stream_name,
server_config->GetName(), app_name, stream_name,
_segment_count, _segment_duration,
_utc_timing_scheme, _utc_timing_value,
video_track, audio_track,
Expand Down
4 changes: 2 additions & 2 deletions src/projects/publishers/segment/cmaf/cmaf_packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ static inline void DumpSegmentToFile(const std::shared_ptr<const SegmentItem> &s
#endif // DEBUG
}

CmafPacketizer::CmafPacketizer(const ov::String &app_name, const ov::String &stream_name,
CmafPacketizer::CmafPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const ov::String &utc_timing_scheme, const ov::String &utc_timing_value,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer)
: Packetizer(app_name, stream_name,
: Packetizer(service_name, app_name, stream_name,
1, 1 * 5, segment_duration,
video_track, audio_track,
chunked_transfer),
Expand Down
2 changes: 1 addition & 1 deletion src/projects/publishers/segment/cmaf/cmaf_packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class CmafPacketizer : public Packetizer
{
public:
CmafPacketizer(const ov::String &app_name, const ov::String &stream_name,
CmafPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const ov::String &utc_timing_scheme, const ov::String &utc_timing_value,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track,
Expand Down
3 changes: 2 additions & 1 deletion src/projects/publishers/segment/dash/dash_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ bool DashApplication::Start()
std::shared_ptr<pub::Stream> DashApplication::CreateStream(const std::shared_ptr<info::Stream> &info, uint32_t thread_count)
{
logtd("DASH Stream is created: %s/%u", info->GetName().CStr(), info->GetId());
auto server_config = cfg::ConfigManager::GetInstance()->GetServer();

return SegmentStream::Create(
GetSharedPtrAs<pub::Application>(), *info.get(),
[=](ov::String app_name, ov::String stream_name,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track) -> std::shared_ptr<Packetizer> {
return std::make_shared<DashPacketizer>(
app_name, stream_name,
server_config->GetName(), app_name, stream_name,
_segment_count, _segment_duration,
_utc_timing_scheme, _utc_timing_value,
video_track, audio_track,
Expand Down
8 changes: 4 additions & 4 deletions src/projects/publishers/segment/dash/dash_packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ static inline void DumpSegmentToFile(const std::shared_ptr<const SegmentItem> &s
#endif // DEBUG
}

DashPacketizer::DashPacketizer(const ov::String &app_name, const ov::String &stream_name,
DashPacketizer::DashPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const ov::String &utc_timing_scheme, const ov::String &utc_timing_value,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer)
: Packetizer(app_name, stream_name,
: Packetizer(service_name, app_name, stream_name,
segment_count, segment_count * 2, segment_duration,
video_track, audio_track,
chunked_transfer),
Expand Down Expand Up @@ -205,7 +205,7 @@ bool DashPacketizer::PrepareVideoInitIfNeeded()
return true;
}

if ((_video_m4s_writer.Prepare() && _video_m4s_writer.Flush()) == false)
if ((_video_m4s_writer.Prepare(GetServiceName()) && _video_m4s_writer.Flush()) == false)
{
return false;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ bool DashPacketizer::PrepareAudioInitIfNeeded()
return true;
}

if ((_audio_m4s_writer.Prepare() && _audio_m4s_writer.Flush()) == false)
if ((_audio_m4s_writer.Prepare(GetServiceName()) && _audio_m4s_writer.Flush()) == false)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/projects/publishers/segment/dash/dash_packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class DashFileType : int32_t
class DashPacketizer : public Packetizer
{
public:
DashPacketizer(const ov::String &app_name, const ov::String &stream_name,
DashPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const ov::String &utc_timing_scheme, const ov::String &utc_timing_value,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track,
Expand Down
4 changes: 3 additions & 1 deletion src/projects/publishers/segment/hls/hls_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ std::shared_ptr<pub::Stream> HlsApplication::CreateStream(const std::shared_ptr<
{
logtd("HLS Stream is created: %s/%u", info->GetName().CStr(), info->GetId());

auto server_config = cfg::ConfigManager::GetInstance()->GetServer();

return SegmentStream::Create(
GetSharedPtrAs<pub::Application>(), *info.get(),
[=](ov::String app_name, ov::String stream_name,
std::shared_ptr<MediaTrack> video_track, std::shared_ptr<MediaTrack> audio_track) -> std::shared_ptr<Packetizer> {
return std::make_shared<HlsPacketizer>(
app_name, stream_name,
server_config->GetName(), app_name, stream_name,
_segment_count, _segment_duration,
video_track, audio_track,
nullptr);
Expand Down
10 changes: 5 additions & 5 deletions src/projects/publishers/segment/hls/hls_packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ static inline void DumpSegmentToFile(const std::shared_ptr<const SegmentItem> &s
#endif // DEBUG
}

HlsPacketizer::HlsPacketizer(const ov::String &app_name, const ov::String &stream_name,
HlsPacketizer::HlsPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const std::shared_ptr<MediaTrack> &video_track, const std::shared_ptr<MediaTrack> &audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer)
: Packetizer(app_name, stream_name,
: Packetizer(service_name, app_name, stream_name,
segment_count, segment_count * 2, segment_duration,
video_track, audio_track,
chunked_transfer),
Expand Down Expand Up @@ -246,7 +246,7 @@ bool HlsPacketizer::AppendVideoPacket(const std::shared_ptr<const MediaPacket> &
_video_key_frame_received = true;
}

if (_ts_writer.PrepareIfNeeded() == false)
if (_ts_writer.PrepareIfNeeded(GetServiceName()) == false)
{
logte("Could not prepare ts writer");
return false;
Expand Down Expand Up @@ -320,7 +320,7 @@ bool HlsPacketizer::AppendAudioPacket(const std::shared_ptr<const MediaPacket> &
_audio_key_frame_received = true;
}

if (_ts_writer.PrepareIfNeeded() == false)
if (_ts_writer.PrepareIfNeeded(GetServiceName()) == false)
{
logte("Could not prepare ts writer");
return false;
Expand Down Expand Up @@ -375,7 +375,7 @@ bool HlsPacketizer::WriteSegment(int64_t timestamp, int64_t timestamp_in_ms, int
duration, duration_in_ms,
data);

if (_ts_writer.Prepare() == false)
if (_ts_writer.Prepare(GetServiceName()) == false)
{
logae("Could not prepare ts writer");
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/projects/publishers/segment/hls/hls_packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class HlsPacketizer : public Packetizer
{
public:
HlsPacketizer(const ov::String &app_name, const ov::String &stream_name,
HlsPacketizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_duration,
const std::shared_ptr<MediaTrack> &video_track, const std::shared_ptr<MediaTrack> &audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include "../segment_stream_private.h"

Packetizer::Packetizer(const ov::String &app_name, const ov::String &stream_name,
Packetizer::Packetizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_save_count, uint32_t segment_duration,
const std::shared_ptr<MediaTrack> &video_track, const std::shared_ptr<MediaTrack> &audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer)

: _app_name(app_name), _stream_name(stream_name),
: _service_name(service_name), _app_name(app_name), _stream_name(stream_name),

_segment_count(segment_count),
_segment_save_count(segment_save_count),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class Packetizer
{
public:
Packetizer(const ov::String &app_name, const ov::String &stream_name,
Packetizer(const ov::String &service_name, const ov::String &app_name, const ov::String &stream_name,
uint32_t segment_count, uint32_t segment_save_count, uint32_t segment_duration,
const std::shared_ptr<MediaTrack> &video_track, const std::shared_ptr<MediaTrack> &audio_track,
const std::shared_ptr<ChunkedTransferInterface> &chunked_transfer);
Expand Down Expand Up @@ -57,13 +57,16 @@ class Packetizer
bool GetVideoPlaySegments(std::vector<std::shared_ptr<SegmentItem>> &segment_datas);
bool GetAudioPlaySegments(std::vector<std::shared_ptr<SegmentItem>> &segment_datas);

ov::String GetServiceName() { return _service_name; }

protected:
virtual void SetReadyForStreaming() noexcept;

static ov::String GetCodecString(const std::shared_ptr<const MediaTrack> &track);

bool AppendVideoSegmentItem(std::shared_ptr<SegmentItem> segment_item);

ov::String _service_name;
ov::String _app_name;
ov::String _stream_name;

Expand Down

0 comments on commit fdce909

Please sign in to comment.