CoreSDK  v1.0.0.b1304
red5pro.h
1 /*
2  * Copyright (c) 2022 Infrared5, Inc.
3  * License information: https://account.red5.net/assets/LICENSE.txt
4  *
5  */
6 
7 #pragma once
8 
9 #include <climits>
10 #include <cstring>
11 #include <vector>
12 #include <string>
13 #include <memory>
14 
15 #include "r5common.h"
16 #include "r5codec.h"
17 #include "r5source.h"
18 #include <functional>
19 
20 namespace r5::core {
21 
22 using namespace r5::common;
23 
24 std::string R5_SDK_CORE_EXPORT GetVersion();
25 
30 enum class StatusType {
31  Connected,
32  Disconnected,
33  ConnectionError,
34  ConnectionTimeout,
35  ConnectionClose,
36  StartStreaming,
37  StopStreaming,
38  NetStatus,
39  AudioMute,
40  AudioUnmute,
41  VideoMute,
42  VideoUnmute,
43  LicenseError,
44  LicenseValid,
45  BufferFlushStart,
46  BufferFlushEmpty,
47  VideoRenderStart,
48  AbrLevelChange,
49  SrtpKeyGenError,
50  SrtpKeyHandleError,
51  HardwareDecodeError,
52  ConnectionRejectedError,
53 };
54 
58 enum class RecordType {
59  Live,
60  Record,
61  Append
62 };
66 enum class ProtocolType {
67  Rtsp,
68  Srtp,
69  NullSrtp,
70  WebRTC
71 };
75 enum class NetworkTransport {
76  Tcp,
77  Udp
78 };
82 enum class AudioFormat {
83  Aac,
84  Opus,
85  L16
86 };
91 typedef std::pair<std::string, std::string> MetadataRecord;
96 typedef struct Metadata
97 {
98  std::string name;
99  uint32_t timestamp;
100  std::vector<MetadataRecord> records;
101 } Metadata;
109 {
110 public:
117  virtual int GetNumberMediaDescs() = 0;
125  virtual int GetMediaDesc(int idx, MediaTransform &desc) = 0;
132  virtual int GetCurrentMediaDesc(MediaTransform &desc) = 0;
140  virtual int SetCurrentMediaDesc(const MediaTransform &desc) = 0;
141 };
142 typedef std::shared_ptr<IMediaDescEnumerator> IMediaDescEnumeratorPtr;
150 {
151 public:
160  virtual int SinkSample(const MediaSample &outSample) = 0;
161 };
162 typedef std::shared_ptr<IMediaSink> IMediaSinkPtr;
170 {
171 public:
178  virtual int Init(MediaDesc &desc) = 0;
185  virtual int GetData(MediaSample &outSample) = 0;
191  virtual int Release() = 0;
192 };
193 typedef std::shared_ptr<ISingleSource> ISingleSourcePtr;
200 {
201 public:
208  virtual int Init(std::vector<MediaDesc> &descs) = 0;
216  virtual int GetData(int idx, MediaSample &outSample) = 0;
222  virtual int Release() = 0;
223 };
224 typedef std::shared_ptr<IDemuxingSource> IDemuxingSourcePtr;
231 {
232 public:
239  virtual int Init(MediaTransform &desc) = 0;
246  virtual int PutData(MediaSample &inSample) = 0;
253  virtual int GetData(MediaSample &outSample) = 0;
259  virtual int Release() = 0;
260 };
261 typedef std::shared_ptr<ITransform> ITransformPtr;
269 {
270 public:
278  virtual int Init(MediaDesc &desc) = 0;
285  virtual int PutData(const MediaSample &inSample) = 0;
291  virtual int Release() = 0;
292 };
293 typedef std::shared_ptr<ISingleRenderer> ISingleRendererPtr;
300 {
301 public:
308  virtual int Init(std::vector<MediaDesc> &descs) = 0;
316  virtual int PutData(int idx, const MediaSample &inSample) = 0;
322  virtual int Release() = 0;
323 };
324 
325 typedef std::shared_ptr<IMuxingRenderer> IMuxingRendererPtr;
326 
332 {
333 public:
339  virtual DataType GetType() = 0;
347  virtual int SetEncoderSettings(EncoderSettings set) = 0;
355  virtual int AddTransform(ITransformPtr tfm) = 0;
362  virtual int AddSink(IMediaSinkPtr sink) = 0;
363 };
364 
365 typedef std::shared_ptr<IMediaStream> IMediaStreamPtr;
366 
372 {
373 public:
379  virtual int InitHandler() = 0;
387  virtual int OnStatus(StatusType statusType, const std::string &statusMessage) = 0;
394  virtual int OnReceiveMetadata(Metadata &metadata) = 0;
400  virtual int ReleaseHandler() = 0;
401 };
402 typedef std::shared_ptr<ICallbackHandler> ICallbackHandlerPtr;
408 class IClient
409 {
410 public:
417  virtual std::vector<IMediaStreamPtr> AddStreams(IDemuxingSourcePtr src) = 0;
424  virtual IMediaStreamPtr AddStream(ISingleSourcePtr src) = 0;
432  virtual IMediaStreamPtr AddStream(ISingleRendererPtr rdr) = 0;
438  virtual int SetCallbackHandler(ICallbackHandlerPtr handler) = 0;
444  virtual int SetLogger(std::shared_ptr<ILogger>) = 0;
450  virtual int Connect() = 0;
456  virtual int Disconnect() = 0;
463  virtual bool IsRunning() = 0;
470  virtual int SendMetadata(const Metadata &metadata) = 0;
477  virtual uint64_t GetBytesSent(DataType type) = 0;
484  virtual uint64_t GetBytesReceived(DataType type) = 0;
485 };
486 typedef std::shared_ptr<IClient> IClientPtr;
491 typedef struct ServerDescription
492 {
493  std::string host;
494  int port;
495  std::string contextName;
496  std::string streamName;
497  NetworkTransport transport = NetworkTransport::Tcp;
498  ProtocolType protocolType = ProtocolType::Rtsp;
499  RecordType recordType = RecordType::Live;
500 
501  std::string username;
502  std::string password;
504 
509 class R5_SDK_CORE_EXPORT Red5Pro
510 {
511 public:
517  static void SetLicenseKey(const std::string &licenseKey);
523  static ILoggerPtr GetDefaultLogger();
530  static int SetDefaultLogger(ILoggerPtr logger);
536  static void SetDefaultLogLevel(LogLevel level);
542  static void SetPreferredAudioFormat(AudioFormat fmt);
543 
551  static ITransformPtr CreateEncoderForCodec(CodecPtr codec, EncoderSettings set);
558  static ITransformPtr CreateDecoderForCodec(CodecPtr codec);
567  static IDemuxingSourcePtr OpenMediaFile(std::string fname, int numberOfRepeat, ILoggerPtr logger = nullptr);
574  static IClientPtr CreateClient(const ServerDescription &desc);
575 };
576 }
Interface for single media renderer This interface can be used to implement different media renderers...
Definition: red5pro.h:268
Interface to access media type information This interface can be used to enumerate available media ty...
Definition: red5pro.h:108
Interface to setup media stream created by client This interface should be used only before client is...
Definition: red5pro.h:331
std::string contextName
name of context of the stream (e.g. "live")
Definition: red5pro.h:495
Interface for single media source objects This interface can be used to implement different media sou...
Definition: red5pro.h:169
std::vector< MetadataRecord > records
set of key-value data pairs
Definition: red5pro.h:100
Interface that can be used to receive media samples from different points of dataflow graph Implement...
Definition: red5pro.h:149
Service structure that describes Red5Pro server connection parameters.
Definition: red5pro.h:491
Main interface for object that handle Red5Pro server connection This interface can be used to configu...
Definition: red5pro.h:408
Set of encoder settings.
Definition: r5codec.h:62
uint32_t timestamp
timestamp for metadata event
Definition: red5pro.h:99
Description of media sample used.
Definition: r5data.h:351
std::string host
IP or DNS address of Red5Pro server to connect.
Definition: red5pro.h:493
Structure with set of MetadataRecord Structure to send and receive set of MetadataRecord with IClient...
Definition: red5pro.h:96
Interface for different transformation filters In most cases this interface implemented by encoders a...
Definition: red5pro.h:230
Interface for source object that can provide multiple media types at same time This interface can be ...
Definition: red5pro.h:199
Description of media data transformation This structure can specify input, output or both media descr...
Definition: r5data.h:253
Interface to get status notifications and receive metadata This interface can be implemented by user ...
Definition: red5pro.h:371
std::string streamName
name of the stream
Definition: red5pro.h:496
Interface for renderer object that can handle multiple media types at same time This interface can be...
Definition: red5pro.h:299
Definition: r5stream_manager.h:12
std::string username
optional user name, used if server has enabled authentication
Definition: red5pro.h:501
std::string name
RPC method name. "onMetaData" in most cases.
Definition: red5pro.h:98
Unified media data description.
Definition: r5data.h:132
int port
port on server side to connect (Note: make sure that server can handle selected protocol on this port...
Definition: red5pro.h:494
Definition: r5codec.h:12
std::string password
optional password, used if server has enabled authentication
Definition: red5pro.h:502
Main Red5Pro CoreSDK object This object is used to specify default and common settings for applicatio...
Definition: red5pro.h:509