Skip to content

Commit

Permalink
added support for user-defined logic in httpout server
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Dec 10, 2023
1 parent 9bae045 commit 3ad5e1e
Show file tree
Hide file tree
Showing 15 changed files with 1,440 additions and 105 deletions.
1 change: 1 addition & 0 deletions Changelog
Expand Up @@ -24,6 +24,7 @@

## Filters
- Async HTTP request in all filters
- JS/Python/NodeJS bindings for httpout server
- Fixed cors and mime types in httpout for wasm and sharedArrayuffer support
- Allow compilation without threads
- Allow compilation without network
Expand Down
6 changes: 3 additions & 3 deletions include/gpac/isomedia.h
Expand Up @@ -1243,7 +1243,7 @@ u32 gf_isom_has_track_reference(GF_ISOFile *isom_file, u32 trackNumber, u32 refe
\param trackNumber the target track
\param referenceType the four character code of the reference to query
\return the track number of the first track referencing the target track, 0 otherwise*/
u32 gf_isom_is_track_referenced(GF_ISOFile *movie, u32 trackNumber, u32 referenceType);
u32 gf_isom_is_track_referenced(GF_ISOFile *isom_file, u32 trackNumber, u32 referenceType);

/*! fetches a sample for a given movie time, handling possible track edit lists.
Expand Down Expand Up @@ -5479,7 +5479,7 @@ GF_Err gf_isom_text_set_wrap(GF_TextSample *tx_samp, u8 wrap_flags);

/*! sets force for the sample
\param tx_samp the target text sample
\param is_force for ce sample if TRUE
\param is_forced for ce sample if TRUE
\return error if any
*/
GF_Err gf_isom_text_set_forced(GF_TextSample *tx_samp, Bool is_forced);
Expand Down Expand Up @@ -6165,7 +6165,7 @@ u32 gf_isom_meta_get_item_ref_id(GF_ISOFile *isom_file, Bool root_meta, u32 trac
\param isom_file the target ISO file
\param root_meta if GF_TRUE uses meta at the file, otherwise uses meta at the movie level if track number is 0
\param track_num if GF_TRUE and root_meta is GF_FALSE, uses meta at the track level
\param from_id item ID to check
\param to_id item ID to check
\param type reference type to check
\return number of referenced items*/
u32 gf_isom_meta_item_has_ref(GF_ISOFile *isom_file, Bool root_meta, u32 track_num, u32 to_id, u32 type);
Expand Down
2 changes: 1 addition & 1 deletion include/gpac/version.h
Expand Up @@ -48,7 +48,7 @@
/*! ABI Major number of libgpac */
#define GPAC_VERSION_MAJOR 12
/*! ABI Minor number of libgpac */
#define GPAC_VERSION_MINOR 11
#define GPAC_VERSION_MINOR 12
/*! ABI Micro number of libgpac */
#define GPAC_VERSION_MICRO 0

Expand Down
1 change: 1 addition & 0 deletions share/doc/doxyfile
Expand Up @@ -876,6 +876,7 @@ INPUT = ../../include/gpac/ \
../../share/doc/idl/webgl.idl \
../../share/doc/idl/filtersession.idl \
../../share/doc/idl/dash_algo.idl \
../../share/doc/idl/httpout.idl \
../../share/doc/idl/nodejs.idl \
../../share/python/libgpac/libgpac.py

Expand Down
2 changes: 1 addition & 1 deletion share/doc/idl/filtersession.idl
Expand Up @@ -357,7 +357,7 @@ void remove();
*/
void insert(DOMString filter_to_add, optional DOMString link_args=null);

/*! binds a JSObject with underlying filter javascript extensions, if any. Currently only dashin filter has such an extension (see \ref JSDASHClient).
/*! binds a JSObject with underlying filter javascript extensions, if any. Currently only dashin (see \ref JSDASHClient) and httpout (see \ref JSHTTPServer) filters have such an extension.
This will throw an exception if failure or no JS binding available
\param obj the JS object to use as interface for the underlying filter script
*/
Expand Down
109 changes: 105 additions & 4 deletions share/doc/idl/nodejs.idl
Expand Up @@ -171,7 +171,7 @@ However it is currently not capable of running asynchronous callbacks into Node.
The consequences are:
- any custom JS filter will run on the main thread (EventLoop or worker thread)
- any packet dispatched by a custom filter and requiring a JS callback upon packet destruction (shared data dispatch) will force filters consuming these packets to run on the main thread as well.
- any filter assigned with a JS binding (only `dashin` for now) will be scheduled on the main thread
- any filter assigned with a JS binding will be scheduled on the main thread

For better multithreaded usage, it is therefore not recommended to use packets with shared JS data.

Expand Down Expand Up @@ -434,9 +434,10 @@ FilterStatistics get_statistics();
/*! enforces sourceID to be present for output pids of this filter - see \ref gf_filter_require_source_id*/
void require_source_id();

/*! Binds the given object to the underlying filter for callbacks override - only supported by DASH demuxer for the current time
/*! Binds the given object to the underlying filter for callbacks override - only supported by DASH demuxer and httpout for the current time

For DASH, the object must derive implement the methods of the \ref _DASHCustomAlgorithm interface
For DASH, the object must implement the methods of the \ref _DASHCustomAlgorithm interface
For DASH, the object must implement the methods of the \ref _HTTPRequestHandler interface

\param interf interface object to bind
*/
Expand Down Expand Up @@ -1143,7 +1144,7 @@ interface _FilterEvent
\brief DASH and HLS user-defined rate adaptation algorithms


The DASH demuxer can be provided with a custom JS algorithm, provided as an object implementing the the DASHAlgorithm interface.
The DASH demuxer can be provided with a custom JS algorithm, provided as an object implementing the DASHAlgorithm interface.

When running the session in multithreaded mode, the dash demuxer will always be scheduled on the main thread if a custom algorithm is bound.

Expand Down Expand Up @@ -1517,6 +1518,106 @@ boolean exists(DOMString URL);

};

/*! @} */



/*!

\defgroup nodehttp_grp HTTPRequestHandler interface
\ingroup nodejs_grp
\brief HTTP server user-defined request handler


The httpout server can use a custom request handler, provided as an object implementing the HTTPRequestHandler interface.

When running the session in multithreaded mode, the httpout filter will always be scheduled on the main thread if a custom request handler is bound.

@{

*/

/*! interface for HTTP custom request handler
*/
interface _HTTPRequestHandler
{

/*! Callback called upon a period reset.
\param request the request to process
*/
void on_request(_HTTPRequest request);

};


/*! interface for HTTP request */
interface _HTTPRequest
{

/*! send the response to the request*/
attribute void send();

/*! HTTP reply code to use. If 0, the request is handled by GPAC as usual. Otherwise, the request is handled by your script if the reply does not indicate an error*/
attribute unsigned long reply;

/*! HTTP method of the request */
attribute readonly DOMString method;

/*! HTTP URL of the request */
attribute readonly DOMString url;

/*! Authentication reply code - requests are pre-identified using GPAC credentials: a value of 401 indicates no identification, 200 indicates identification OK, 403 indicates failure */
attribute readonly unsigned long auth_code;

/*! HTTP headers of the request, array of _HTTPHeader objects*/
attribute readonly Array headers_in;

/*! HTTP headers to set on the response, array of _HTTPHeader objects (initialized as empty)*/
attribute Array headers_out;

/*! reply body. It is undefined by default
- if reply is 0, this can be set to a file path to serve. If not set, usual URL resolving of httpout is done
- if reply is not 0, this can be set to a string containing the body. To deliver a binary file or a large file, use the read function
*/
attribute DOMString body


/*! callback function used to throttle the download, can be used even if the request is handled by gpac. It is undefined by default
\param done amount of bytes already sent in request
\param total total amount of bytes in request
\return a delay for next send in milliseconds
*/
attribute unsigned long throttle(unsigned long long done, unsigned long long total);

/*! callback function used to get data (GET requests). It is undefined by default
\param buffer array buffer to fill (shared array, do NOT keep)
\return the number of bytes read, negative value means no data available yet, 0 means end of file
*/
attribute signed long read(ArrayBuffer buffer);

/*! callback function used to receive data (PUT/POST requests). It is undefined by default
\param buffer array buffer received. If null, end of stream is reached
\return the number of bytes written (informative only)
*/
attribute unsigned long write(ArrayBuffer buffer);

/*! callback function used to monitor end of session. It is undefined by default
\param error GPAC error code for the session
*/
attribute void close(unsigned long error);

};

/*! interface for HTTP header */
interface _HTTPHeader
{

/*! header name */
attribute readonly DOMString name;

/*! header value */
attribute readonly DOMString value;
};

/*! @} */

Expand Down
2 changes: 2 additions & 0 deletions share/doc/man/gpac-filters.1
Expand Up @@ -7344,6 +7344,8 @@ ka (bool, default: true): keep input alive if failure in push mode
.br
hdrs (strl): additional HTTP headers to inject, even values are names, odd values are values
.br
js (str): jaavscript logic for server
.br

.br
.SH hevcsplit
Expand Down

0 comments on commit 3ad5e1e

Please sign in to comment.