Skip to content

Commit

Permalink
reworked netcap to be assignable at filter level rather than globally
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Dec 20, 2023
1 parent 4ae83a0 commit b026f6d
Show file tree
Hide file tree
Showing 34 changed files with 999 additions and 541 deletions.
1 change: 1 addition & 0 deletions applications/gpac/gpac_help.c
Expand Up @@ -486,6 +486,7 @@ const char *gpac_doc =
"- gfopt: following options are not tracked (no value)\n"
"- gpac: argument separator for URLs (no value)\n"
"- ccp: filter replacement control (string list value)\n"
"- NCID: ID of netcap configuration to use (string)\n"
"\n"
"The buffer control options are used to change the default buffering of PIDs of a filter:\n"
"- `FBT` controls the maximum buffer time of output PIDs of a filter\n"
Expand Down
8 changes: 8 additions & 0 deletions include/gpac/download.h
Expand Up @@ -469,6 +469,14 @@ Retrieves the HTTP header name and value for the given header index.
*/
GF_Err gf_dm_sess_enum_headers(GF_DownloadSession *sess, u32 *idx, const char **hdr_name, const char **hdr_val);

/*!
\brief set netcap rule ID
Sets ID of netcap rules for this session
\param sess the current session
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
*/
void gf_dm_sess_set_netcap_id(GF_DownloadSession *sess, const char *netcap_id);
/*!
\brief sets download manager max rate per session
Expand Down
6 changes: 6 additions & 0 deletions include/gpac/filters.h
Expand Up @@ -3291,6 +3291,12 @@ GF_Err gf_filter_tag_subsession(GF_Filter *filter, u32 subsession_id, u32 source
*/
Bool gf_filter_has_connect_errors(GF_Filter *filter);

/*! Get ID of netcap configuration associated with filter, if any
\param filter target filter
\return netcap ID if set, NULL otherwise
*/
const char *gf_filter_get_netcap_id(GF_Filter *filter);


/*! Sets names of sub-instances involved in a meta-filter instance
\param filter target filter
Expand Down
14 changes: 14 additions & 0 deletions include/gpac/ietf.h
Expand Up @@ -666,6 +666,13 @@ const char *gf_rtsp_get_session_cookie(GF_RTSPSession *sess);
*/
GF_Err gf_rtsp_merge_tunnel(GF_RTSPSession *sess, GF_RTSPSession *post_sess);

/*! sets associated netcap rules
\param sess the target RTSP session
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
*/
void gf_rtsp_session_set_netcap_id(GF_RTSPSession *sess, const char *netcap_id);

/*
RTP LIB EXPORTS
*/
Expand Down Expand Up @@ -719,6 +726,13 @@ typedef struct __tag_rtp_channel GF_RTPChannel;
\return a newly allocated RTP channel
*/
GF_RTPChannel *gf_rtp_new();

/*! creates a new RTP channel
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
\return a newly allocated RTP channel
*/
GF_RTPChannel *gf_rtp_new_ex(const char *netcap_id);

/*! destroys an RTP channel
\param ch the target RTP channel
*/
Expand Down
4 changes: 3 additions & 1 deletion include/gpac/internal/ietf_dev.h
Expand Up @@ -185,7 +185,7 @@ struct __tag_rtp_channel
GF_RTCP_Report rtcp_rr[MAX_RTCP_RR];
u32 nb_rctp_rr;


const char *netcap_id;
const char **ssm, **ssmx;
u32 nb_ssm, nb_ssmx;
u8 disc_state;
Expand Down Expand Up @@ -304,6 +304,8 @@ struct _tag_rtsp_session
char *HTTP_Cookie;
u32 tunnel_state;

const char *netcap_id;

/*RTSP CHANNEL*/
GF_Socket *connection;
u32 SockBufferSize;
Expand Down
13 changes: 12 additions & 1 deletion include/gpac/network.h
Expand Up @@ -408,6 +408,17 @@ Constructs a socket object
\return the socket object or NULL if network initialization failure
*/
GF_Socket *gf_sk_new(u32 SocketType);

/*!
\brief socket constructor
Constructs a socket object with a specific netcap configuration ID
\param SocketType the socket type to create, either UDP or TCP
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
\return the socket object or NULL if network initialization failure
*/
GF_Socket *gf_sk_new_ex(u32 SocketType, const char *netcap_id);

/*!
\brief socket destructor
Expand Down Expand Up @@ -715,7 +726,7 @@ Performs a select (wait) on the socket group
\param sg socket group object
\param wait_usec microseconds to wait (must be less than one second)
\param mode the operation mode desired
\return error if any
\return error if any - if using a capture file and the capture is done, returns GF_IP_CONNECTION_CLOSED if TCP sockets are present, otherwise GF_EOS
*/
GF_Err gf_sk_group_select(GF_SockGroup *sg, u32 wait_usec, GF_SockSelectMode mode);

Expand Down
33 changes: 29 additions & 4 deletions include/gpac/route.h
Expand Up @@ -143,23 +143,48 @@ typedef struct
/*! Creates a new ROUTE ATSC3.0 demultiplexer
\param ifce network interface to monitor, NULL for INADDR_ANY
\param sock_buffer_size default buffer size for the udp sockets. If 0, uses 0x2000
\param on_event the user callback function
\param udta the user data passed back by the callback
\param on_event the user callback function
\param udta the user data passed back by the callback
\return the ROUTE demultiplexer created
*/
GF_ROUTEDmx *gf_route_atsc_dmx_new(const char *ifce, u32 sock_buffer_size, void (*on_event)(void *udta, GF_ROUTEEventType evt, u32 evt_param, GF_ROUTEEventFileInfo *finfo), void *udta);


/*! Creates a new ROUTE ATSC3.0 demultiplexer
\param ifce network interface to monitor, NULL for INADDR_ANY
\param sock_buffer_size default buffer size for the udp sockets. If 0, uses 0x2000
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
\param on_event the user callback function
\param udta the user data passed back by the callback
\return the ROUTE demultiplexer created
*/
GF_ROUTEDmx *gf_route_atsc_dmx_new_ex(const char *ifce, u32 sock_buffer_size, const char *netcap_id, void (*on_event)(void *udta, GF_ROUTEEventType evt, u32 evt_param, GF_ROUTEEventFileInfo *finfo), void *udta);


/*! Creates a new ROUTE demultiplexer
\param ip IP address of ROUTE session
\param port port of ROUTE session
\param ifce network interface to monitor, NULL for INADDR_ANY
\param sock_buffer_size default buffer size for the udp sockets. If 0, uses 0x2000
\param on_event the user callback function
\param udta the user data passed back by the callback
\param on_event the user callback function
\param udta the user data passed back by the callback
\return the ROUTE demultiplexer created
*/
GF_ROUTEDmx *gf_route_dmx_new(const char *ip, u32 port, const char *ifce, u32 sock_buffer_size, void (*on_event)(void *udta, GF_ROUTEEventType evt, u32 evt_param, GF_ROUTEEventFileInfo *finfo), void *udta);


/*! Creates a new ROUTE demultiplexer
\param ip IP address of ROUTE session
\param port port of ROUTE session
\param ifce network interface to monitor, NULL for INADDR_ANY
\param sock_buffer_size default buffer size for the udp sockets. If 0, uses 0x2000
\param netcap_id ID of netcap configuration to use, may be null (see gpac -h netcap)
\param on_event the user callback function
\param udta the user data passed back by the callback
\return the ROUTE demultiplexer created
*/
GF_ROUTEDmx *gf_route_dmx_new_ex(const char *ip, u32 port, const char *ifce, u32 sock_buffer_size, const char *netcap_id, void (*on_event)(void *udta, GF_ROUTEEventType evt, u32 evt_param, GF_ROUTEEventFileInfo *finfo), void *udta);

/*! Deletes an ROUTE demultiplexer
\param routedmx the ROUTE demultiplexer to delete
*/
Expand Down
59 changes: 59 additions & 0 deletions include/gpac/rtp_streamer.h
Expand Up @@ -94,6 +94,65 @@ GF_RTPStreamer *gf_rtp_streamer_new(u32 streamType, u32 codecid, u32 timeScale,
Bool is_crypted, u32 IV_length, u32 KI_length,
u32 MinSize, u32 MaxSize, u32 avgTS, u32 maxDTSDelta, u32 const_dur, u32 bandwidth, u32 max_ptime, u32 au_sn_len, Bool for_rtsp);

/*! RTP streamer configuration*/
typedef struct
{
//! type of the stream (GF_STREAM_* as defined in <gpac/constants.h>
u32 streamType;
//! codec ID for the stream (GF_CODEC_* as defined in <gpac/constants.h>)
u32 codecid;
//! unit to express timestamps of access units
u32 timeScale;
//! IP address of the destination
const char *ip_dest;
//! port number of the destination
u16 port;
//! Maximum Transmission Unit size to use
u32 MTU;
//! Time To Leave
u8 TTL;
//! IP of the local interface to use (may be NULL)
const char *ifce_addr;
//! set of RTP flags passed to the streamer
u32 flags;
//! MPEG-4 Decoder Specific Info for the stream
const u8 *dsi;
//! length of the dsi parameter
u32 dsi_len;
//! RTP payload type
u32 PayloadType;
//! audio sample rate
u32 sample_rate;
//! number of channels in audio streams
u32 nb_ch;
//! indicating if the stream is crypted
Bool is_crypted;
//! length of the Initialisation Vector used for ISMA encryption
u32 IV_length;
//! length of the key index
u32 KI_length;
//! minimum AU size, 0 if unknown
u32 MinSize;
//maximum AU size, 0 if unknown
u32 MaxSize;
//! average TS delta in timeScale, 0 if unknown
u32 avgTS;
//! maximum DTS delta in timeScale, 0 if unknown
u32 maxDTSDelta;
//! constant duration in timeScale, 0 if unknown
u32 const_dur;
//! bandwidth, 0 if unknown
u32 bandwidth;
//! maximum packet duration in timeScale, 0 if unknown
u32 max_ptime;
//! length of the MPEG-4 SL descriptor AU sequence number field, 0 if unknown
u32 au_sn_len;
//! ID of netcap configuration to use, may be null (see gpac -h netcap)
const char *netcap_id;
} GF_RTPStreamerConfig;

GF_RTPStreamer *gf_rtp_streamer_new_ex(const GF_RTPStreamerConfig *cfg, Bool for_rtsp);

/*!
\brief RTP file streamer destructor
Expand Down
16 changes: 8 additions & 8 deletions share/doc/man/gpac-filters.1
Expand Up @@ -7994,7 +7994,7 @@ cicp_idx (uint, default: 2): target output layout CICP index (see gpac -h layo
.br
Description: FFMPEG demultiplexer
.br
Version: Lavf60.5.100
Version: Lavf60.18.100
.br

.br
Expand Down Expand Up @@ -8032,7 +8032,7 @@ strbuf_min (uint, default: 1MB): internal buffer size when demuxing from GPAC's
.br
Description: FFMPEG decoder
.br
Version: Lavc60.14.101
Version: Lavc60.35.100
.br

.br
Expand Down Expand Up @@ -8091,7 +8091,7 @@ c (str): codec name (GPAC or ffmpeg), only used to query p
.br
Description: FFMPEG AV Capture
.br
Version: Lavd60.2.100
Version: Lavd60.4.100
.br

.br
Expand Down Expand Up @@ -8184,7 +8184,7 @@ probes (uint, default: 10, minmax: 0-100): probe a given number of video frames
.br
Description: FFMPEG video rescaler
.br
Version: SwS7.2.100
Version: SwS7.6.100
.br

.br
Expand Down Expand Up @@ -8302,7 +8302,7 @@ osar (frac, default: 0/1): force output pixel aspect ratio
.br
Description: FFMPEG encoder
.br
Version: Lavc60.14.101
Version: Lavc60.35.100
.br

.br
Expand Down Expand Up @@ -8380,7 +8380,7 @@ rld (bool, default: false, updatable): force reloading of encoder when arguments
.br
Description: FFMPEG multiplexer
.br
Version: Lavf60.5.100
Version: Lavf60.18.100
.br

.br
Expand Down Expand Up @@ -8444,7 +8444,7 @@ keepts (bool, default: true): do not shift input timeline back to 0
.br
Description: FFMPEG AVFilter
.br
Version: Lavfi9.8.101
Version: Lavfi9.14.100
.br

.br
Expand Down Expand Up @@ -8587,7 +8587,7 @@ dump (bool, default: false, updatable): dump graph as log media@info or stderr i
.br
Description: FFMPEG BitStream filter
.br
Version: Lavu58.9.100
Version: Lavu58.34.100
.br

.br
Expand Down
48 changes: 32 additions & 16 deletions share/doc/man/gpac.1
Expand Up @@ -880,29 +880,23 @@ use buffered IO instead of file descriptor for read/write - this can speed up op
disable all mutexes, threads and semaphores (do not use if unsure about threading used)
.br
.TP
.B \-netcap-dst (string)
.B \-netcap (string)
.br
output packets to indicated file
set packet capture and filtering rules formatted as [CFG][RULES]. Each -netcap argument will define a configuration
.br
.TP
.B \-netcap-src (string)
.br
read packets from indicated file, as produced by -netcap-dst or a pcap or pcapng file
[CFG] is an optional comma-separated list of:
.br
.TP
.B \-netcap-nrt
* id=ID: ID (string) for this configuration. If NULL, configuration will apply to all sockets not specifying a netcap ID
.br
ignore real-time regulation when reading packet from capture file
* src=F: read packets from F, as produced by GPAC or a pcap or pcapng file
.br
.TP
.B \-netcap-loop (int)
* dst=F: output packets to F (no pcap/pcapng support), cannot be set if src is set
.br
set number of loops of capture file, -1 means forever
* loop[=N]: loop capture file N times, or forever if N is not set or negative
.br
.TP
.B \-net-filter (string)
* nrt: disable real-time playback
.br
set packet filtering rules (live or from file). Value is a list of {OPT,OPT2...} with OPT in:
[RULES] is an optional list of {OPT,OPT2...} with OPT in:
.br
* m=N: set rule mode - N can be r for reception only (default), w for send only or rw for both
.br
Expand All @@ -923,14 +917,34 @@ set packet filtering rules (live or from file). Value is a list of {OPT,OPT2...}
* v=N: set patch byte value to N (hexa) or negative value for random (default)
.br

.br
Example
.br
-netcap=dst=dump.gpc
.br

.br
This will record packets to dump.gpc
.br

.br
Example
.br
-netcap=src=dump.gpc,id=NC1 -i session1.sdp:NCID=NC1 -i session2.sdp
.br

.br
This will read packets from dump.gpc only for session1.sdp and let session2.sdp use regular sockets
.br

.br
Example
.br
{p=1234,s=100,n=20}{r=200,s=500,o=10,v=FE}
.br

.br
This will drop packets 100 to 119 on port 1234 and patch one random packet every 200 starting from packet 500, setting byte 10 to FE
This will use regular network interface and drop packets 100 to 119 on port 1234 and patch one random packet every 200 starting from packet 500, setting byte 10 to FE
.br
.TP
.B \-cache (string)
Expand Down Expand Up @@ -2514,6 +2528,8 @@ As seen previously, the following options may be set on any filter, but are not
.br
* ccp: filter replacement control (string list value)
.br
* NCID: ID of netcap configuration to use (string)
.br

.br
The buffer control options are used to change the default buffering of PIDs of a filter:
Expand Down

0 comments on commit b026f6d

Please sign in to comment.