Skip to content

Commit

Permalink
Fixed an issue Stream IDs could be duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Jan 30, 2023
1 parent b44fd38 commit 30a6bff
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/projects/base/provider/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace pvd
const std::shared_ptr<Stream> GetStreamById(uint32_t stream_id);
const std::shared_ptr<Stream> GetStreamByName(ov::String stream_name);

uint32_t IssueUniqueStreamId();
static uint32_t IssueUniqueStreamId();

virtual bool AddStream(const std::shared_ptr<Stream> &stream);
virtual bool DeleteStream(const std::shared_ptr<Stream> &stream);
Expand Down
2 changes: 1 addition & 1 deletion src/projects/base/provider/pull_provider/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace pvd

std::shared_ptr<pvd::Stream> PullApplication::CreateStream(const ov::String &stream_name, const std::vector<ov::String> &url_list, const std::shared_ptr<pvd::PullStreamProperties> &properties)
{
auto stream = CreateStream(IssueUniqueStreamId(), stream_name, url_list, properties);
auto stream = CreateStream(pvd::Application::IssueUniqueStreamId(), stream_name, url_list, properties);
if(stream == nullptr)
{
return nullptr;
Expand Down
18 changes: 17 additions & 1 deletion src/projects/base/provider/push_provider/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,27 @@ namespace pvd
PushStream::PushStream(StreamSourceType source_type, uint32_t channel_id, const std::shared_ptr<PushProvider> &provider)
: Stream(source_type)
{
SetId(channel_id);
SetId(pvd::Application::IssueUniqueStreamId());
_channel_id = channel_id;
_provider = provider;
}

PushStream::PushStream(StreamSourceType source_type, ov::String channel_name, const std::shared_ptr<PushProvider> &provider)
: PushStream(source_type, provider)
{
SetName(channel_name);
}

PushStream::PushStream(StreamSourceType source_type, const std::shared_ptr<PushProvider> &provider)
: Stream(source_type)
{
auto id = pvd::Application::IssueUniqueStreamId();
SetId(id);
// If the channel id is not given, use the stream id as the channel id
_channel_id = id;
_provider = provider;
}

uint32_t PushStream::GetChannelId()
{
return _channel_id;
Expand Down
2 changes: 2 additions & 0 deletions src/projects/base/provider/push_provider/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ namespace pvd

protected:
PushStream(StreamSourceType source_type, ov::String channel_name, uint32_t channel_id, const std::shared_ptr<PushProvider> &provider);
PushStream(StreamSourceType source_type, ov::String channel_name, const std::shared_ptr<PushProvider> &provider);
PushStream(StreamSourceType source_type, uint32_t channel_id, const std::shared_ptr<PushProvider> &provider);
PushStream(StreamSourceType source_type, const std::shared_ptr<PushProvider> &provider);

// app name, stream name, tracks
// provider->AssignStream (app)
Expand Down
2 changes: 1 addition & 1 deletion src/projects/providers/rtmp/rtmp_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace pvd

logti("A RTMP client has connected from %s", remote->ToString().CStr());

PushProvider::OnChannelCreated(remote->GetNativeHandle(), stream);
PushProvider::OnChannelCreated(channel_id, stream);
}

void RtmpProvider::OnDataReceived(const std::shared_ptr<ov::Socket> &remote,
Expand Down
7 changes: 3 additions & 4 deletions src/projects/providers/webrtc/webrtc_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ namespace pvd
}

// Create Stream
auto channel_id = offer_sdp->GetSessionId();
auto stream = WebRTCStream::Create(StreamSourceType::WebRTC, final_stream_name, channel_id, PushProvider::GetSharedPtrAs<PushProvider>(), offer_sdp, peer_sdp, _certificate, _ice_port);
auto stream = WebRTCStream::Create(StreamSourceType::WebRTC, final_stream_name, PushProvider::GetSharedPtrAs<PushProvider>(), offer_sdp, peer_sdp, _certificate, _ice_port);
if(stream == nullptr)
{
logte("Could not create %s stream in %s application", final_stream_name.CStr(), final_vhost_app_name.CStr());
Expand All @@ -441,12 +440,12 @@ namespace pvd
stream->SetMediaSource(request->GetRemote()->GetRemoteAddressAsUrl());

// The stream of the webrtc provider has already completed signaling at this point.
if(PublishChannel(channel_id, final_vhost_app_name, stream) == false)
if(PublishChannel(stream->GetId(), final_vhost_app_name, stream) == false)
{
return false;
}

if(OnChannelCreated(channel_id, stream) == false)
if(OnChannelCreated(stream->GetId(), stream) == false)
{
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/projects/providers/webrtc/webrtc_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

namespace pvd
{
std::shared_ptr<WebRTCStream> WebRTCStream::Create(StreamSourceType source_type, ov::String stream_name, uint32_t stream_id,
std::shared_ptr<WebRTCStream> WebRTCStream::Create(StreamSourceType source_type, ov::String stream_name,
const std::shared_ptr<PushProvider> &provider,
const std::shared_ptr<const SessionDescription> &offer_sdp,
const std::shared_ptr<const SessionDescription> &peer_sdp,
const std::shared_ptr<Certificate> &certificate,
const std::shared_ptr<IcePort> &ice_port)
{
auto stream = std::make_shared<WebRTCStream>(source_type, stream_name, stream_id, provider, offer_sdp, peer_sdp, certificate, ice_port);
auto stream = std::make_shared<WebRTCStream>(source_type, stream_name, provider, offer_sdp, peer_sdp, certificate, ice_port);
if (stream != nullptr)
{
if (stream->Start() == false)
Expand All @@ -34,13 +34,13 @@ namespace pvd
return stream;
}

WebRTCStream::WebRTCStream(StreamSourceType source_type, ov::String stream_name, uint32_t stream_id,
WebRTCStream::WebRTCStream(StreamSourceType source_type, ov::String stream_name,
const std::shared_ptr<PushProvider> &provider,
const std::shared_ptr<const SessionDescription> &offer_sdp,
const std::shared_ptr<const SessionDescription> &peer_sdp,
const std::shared_ptr<Certificate> &certificate,
const std::shared_ptr<IcePort> &ice_port)
: PushStream(source_type, stream_name, stream_id, provider), Node(NodeType::Edge)
: PushStream(source_type, stream_name, provider), Node(NodeType::Edge)
{
_offer_sdp = offer_sdp;
_peer_sdp = peer_sdp;
Expand Down
4 changes: 2 additions & 2 deletions src/projects/providers/webrtc/webrtc_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace pvd
class WebRTCStream : public pvd::PushStream, public RtpRtcpInterface, public ov::Node
{
public:
static std::shared_ptr<WebRTCStream> Create(StreamSourceType source_type, ov::String stream_name, uint32_t stream_id,
static std::shared_ptr<WebRTCStream> Create(StreamSourceType source_type, ov::String stream_name,
const std::shared_ptr<PushProvider> &provider,
const std::shared_ptr<const SessionDescription> &offer_sdp,
const std::shared_ptr<const SessionDescription> &peer_sdp,
const std::shared_ptr<Certificate> &certificate,
const std::shared_ptr<IcePort> &ice_port);

explicit WebRTCStream(StreamSourceType source_type, ov::String stream_name, uint32_t stream_id,
explicit WebRTCStream(StreamSourceType source_type, ov::String stream_name,
const std::shared_ptr<PushProvider> &provider,
const std::shared_ptr<const SessionDescription> &offer_sdp,
const std::shared_ptr<const SessionDescription> &peer_sdp,
Expand Down

0 comments on commit 30a6bff

Please sign in to comment.