Skip to content

Commit

Permalink
Organized source codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiden committed Nov 14, 2024
1 parent 3c6eee0 commit 6d8418e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
19 changes: 9 additions & 10 deletions src/projects/providers/rtmp/rtmp_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
//==============================================================================

#include "rtmp_application.h"
#include "rtmp_stream.h"
#include "rtmp_provider_private.h"

#include "base/provider/push_provider/application.h"
#include "base/info/stream.h"

#include "base/provider/push_provider/application.h"
#include "rtmp_provider_private.h"
#include "rtmp_stream.h"

namespace pvd
{
Expand All @@ -32,24 +31,24 @@ namespace pvd
bool RtmpApplication::JoinStream(const std::shared_ptr<PushStream> &stream)
{
// Check duplicated stream name
// If there is a same stream name
// If there is a same stream name
auto exist_stream = GetStreamByName(stream->GetName());
if(exist_stream != nullptr)
if (exist_stream != nullptr)
{
// Block
if(GetConfig().GetProviders().GetRtmpProvider().IsBlockDuplicateStreamName())
if (GetConfig().GetProviders().GetRtmpProvider().IsBlockDuplicateStreamName())
{
logti("Reject %s/%s stream it is a stream with a duplicate name.", GetVHostAppName().CStr(), stream->GetName().CStr());
logti("Reject %s/%s stream it is a stream with a duplicate name.", GetVHostAppName().CStr(), stream->GetName().CStr());
return false;
}
else
{
// Disconnect exist stream
logti("Remove exist %s/%s stream because the stream with the same name is connected.", GetVHostAppName().CStr(), stream->GetName().CStr());
logti("Remove exist %s/%s stream because the stream with the same name is connected.", GetVHostAppName().CStr(), stream->GetName().CStr());
DeleteStream(exist_stream);
}
}

return PushApplication::JoinStream(stream);
}
}
} // namespace pvd
4 changes: 1 addition & 3 deletions src/projects/providers/rtmp/rtmp_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
#include "base/provider/push_provider/application.h"
#include "base/provider/push_provider/stream.h"


namespace pvd
{
class RtmpApplication : public PushApplication
{

public:
static std::shared_ptr<RtmpApplication> Create(const std::shared_ptr<PushProvider> &provider, const info::Application &application_info);

Expand All @@ -27,4 +25,4 @@ namespace pvd

bool JoinStream(const std::shared_ptr<PushStream> &stream) override;
};
}
} // namespace pvd
38 changes: 18 additions & 20 deletions src/projects/providers/rtmp/rtmp_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@

#pragma once

#include "amf0/amf_document.h"
#include "base/common_types.h"
#include "base/provider/push_provider/stream.h"
#include "modules/access_control/access_controller.h"

#include "amf0/amf_document.h"
#include "chunk/rtmp_chunk_parser.h"
#include "chunk/rtmp_export_chunk.h"
#include "chunk/rtmp_handshake.h"
#include "chunk/rtmp_chunk_parser.h"
#include "modules/access_control/access_controller.h"

#define MAX_STREAM_MESSAGE_COUNT (500)
#define BASELINE_PROFILE (66)
#define MAIN_PROFILE (77)

// Fix track id
#define RTMP_VIDEO_TRACK_ID 0
#define RTMP_AUDIO_TRACK_ID 1
#define RTMP_DATA_TRACK_ID 2
#define RTMP_VIDEO_TRACK_ID 0
#define RTMP_AUDIO_TRACK_ID 1
#define RTMP_DATA_TRACK_ID 2

namespace pvd
{
class RtmpStream : public pvd::PushStream
{
public:
static std::shared_ptr<RtmpStream> Create(StreamSourceType source_type, uint32_t channel_id, const std::shared_ptr<ov::Socket> &client_socket, const std::shared_ptr<PushProvider> &provider);

explicit RtmpStream(StreamSourceType source_type, uint32_t channel_id, std::shared_ptr<ov::Socket> client_socket, const std::shared_ptr<PushProvider> &provider);
~RtmpStream() final;

Expand Down Expand Up @@ -66,7 +65,6 @@ namespace pvd
bool OnAmfDeleteStream(const std::shared_ptr<const RtmpChunkHeader> &header, AmfDocument &document, double transaction_id);
bool OnAmfMetaData(const std::shared_ptr<const RtmpChunkHeader> &header, const AmfProperty *property);


// Send messages
bool SendData(const std::shared_ptr<const ov::Data> &data);
bool SendData(const void *data, size_t data_size);
Expand All @@ -85,11 +83,11 @@ namespace pvd
bool SendAmfOnFCPublish(uint32_t chunk_stream_id, uint32_t stream_id, double client_id);
bool SendAmfCreateStreamResult(uint32_t chunk_stream_id, double transaction_id);
bool SendAmfOnStatus(uint32_t chunk_stream_id,
uint32_t stream_id,
const char *level,
const char *code,
const char *description,
double client_id);
uint32_t stream_id,
const char *level,
const char *code,
const char *description,
double client_id);

// Parsing handshake messages
off_t ReceiveHandshakePacket(const std::shared_ptr<const ov::Data> &data);
Expand Down Expand Up @@ -126,7 +124,7 @@ namespace pvd

// RTMP related
RtmpHandshakeState _handshake_state = RtmpHandshakeState::Uninitialized;

std::shared_ptr<RtmpChunkParser> _import_chunk;
std::shared_ptr<RtmpExportChunk> _export_chunk;
std::shared_ptr<RtmpMediaInfo> _media_info;
Expand All @@ -151,15 +149,15 @@ namespace pvd
std::shared_ptr<const SignedPolicy> _signed_policy = nullptr;
std::shared_ptr<const AdmissionWebhooks> _admission_webhooks = nullptr;

ov::String _full_url; // with stream_name
ov::String _full_url; // with stream_name
ov::String _tc_url;
ov::String _app_name;
ov::String _domain_name;
info::VHostAppName _vhost_app_name;
ov::String _stream_name;
ov::String _device_string;

std::shared_ptr<ov::Url> _publish_url = nullptr; // AccessControl can redirect url set in RTMP to another url.
std::shared_ptr<ov::Url> _publish_url = nullptr; // AccessControl can redirect url set in RTMP to another url.

// Cache (GetApplicationInfo()->GetId())
info::application_id_t _app_id = 0;
Expand All @@ -168,7 +166,7 @@ namespace pvd
std::shared_ptr<ov::Socket> _remote = nullptr;

// Received data buffer
std::shared_ptr<ov::Data> _remained_data = nullptr;
std::shared_ptr<ov::Data> _remained_data = nullptr;

// Singed Policy
uint64_t _stream_expired_msec = 0;
Expand All @@ -184,7 +182,7 @@ namespace pvd
int64_t _last_audio_pts = 0;
ov::StopWatch _last_audio_pts_clock;

// For statistics
// For statistics
time_t _stream_check_time = 0;

uint32_t _key_frame_interval = 0;
Expand All @@ -203,4 +201,4 @@ namespace pvd

bool _is_incoming_timestamp_used = false;
};
}
} // namespace pvd

0 comments on commit 6d8418e

Please sign in to comment.