Skip to content

Commit

Permalink
Organized source codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiden committed Jan 6, 2025
1 parent a5eee11 commit 0dba720
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
82 changes: 50 additions & 32 deletions src/projects/publishers/srt/srt_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ namespace pub
logad("SrtStream has been terminated finally");
}

bool SrtStream::IsSupportedCodec(cmn::MediaCodecId codec_id)
{
switch (codec_id)
{
case cmn::MediaCodecId::H264:
[[fallthrough]];
case cmn::MediaCodecId::Aac:
return true;

default:
return false;
}
}

#define SRT_SET_TRACK(from, to, supported, message, ...) \
if (to == nullptr) \
{ \
if (supported) \
{ \
to = from; \
} \
else \
{ \
logai("SrtStream - " message, ##__VA_ARGS__); \
} \
}

bool SrtStream::Start()
{
if (GetState() != Stream::State::CREATED)
Expand Down Expand Up @@ -82,39 +109,30 @@ namespace pub

for (const auto &[id, track] : GetTracks())
{
if (mpegts::Packetizer::IsSupportedCodec(track->GetCodecId()))
switch (track->GetMediaType())
{
if ((first_video_track == nullptr) && (track->GetMediaType() == cmn::MediaType::Video))
{
first_video_track = track;
}
else if ((first_audio_track == nullptr) && (track->GetMediaType() == cmn::MediaType::Audio))
{
first_audio_track = track;
}
}
else if (track->GetMediaType() == cmn::MediaType::Data)
{
// mpegts::Packetizer only supports ID3v2 format for data track
if (track->GetOriginBitstream() == cmn::BitstreamFormat::ID3v2)
{
if (first_data_track == nullptr)
{
first_data_track = track;
}
}
else
{
logai("SrtStream - Ignore unsupported bitstream format(%s)",
GetBitstreamFormatString(track->GetOriginBitstream()).CStr());
}
}
else
{
logai("SrtStream - Ignore unsupported codec(%s)",
StringFromMediaCodecId(track->GetCodecId()).CStr());

continue;
case cmn::MediaType::Video:
SRT_SET_TRACK(track, first_video_track,
IsSupportedCodec(track->GetCodecId()),
"Ignore unsupported video codec (%s)", StringFromMediaCodecId(track->GetCodecId()).CStr());
break;

case cmn::MediaType::Audio:
SRT_SET_TRACK(track, first_audio_track,
IsSupportedCodec(track->GetCodecId()),
"Ignore unsupported audio codec (%s)", StringFromMediaCodecId(track->GetCodecId()).CStr());
break;

case cmn::MediaType::Data:
// mpegts::Packetizer only supports ID3v2 format for data track
SRT_SET_TRACK(track, first_data_track,
(track->GetOriginBitstream() == cmn::BitstreamFormat::ID3v2),
"Ignore unsupported data bitstream format (%s)", GetBitstreamFormatString(track->GetOriginBitstream()).CStr());
break;

default:
logad("SrtStream - Ignore unsupported media type(%s)", GetMediaTypeString(track->GetMediaType()).CStr());
continue;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/projects/publishers/srt/srt_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace pub
uint32_t worker_count);
~SrtStream() override final;

static bool IsSupportedCodec(cmn::MediaCodecId codec_id);

//--------------------------------------------------------------------
// Overriding of Stream
//--------------------------------------------------------------------
Expand All @@ -53,6 +55,8 @@ namespace pub
bool Start() override;
bool Stop() override;

void SetTrack(const std::shared_ptr<MediaTrack> &from, std::shared_ptr<MediaTrack> *to);

void EnqueuePacket(const std::shared_ptr<MediaPacket> &media_packet);
void BroadcastIfReady(const std::vector<std::shared_ptr<mpegts::Packet>> &packets);

Expand Down

0 comments on commit 0dba720

Please sign in to comment.