libgpac
Documentation of the core library of GPAC
CustomFilter class

User-defined filters. More...

+ Collaboration diagram for CustomFilter class:

Data Structures

interface  CustomFilter
 
interface  _FilterPid
 
interface  _BufferOccupancy
 
interface  _FilterPacket
 
interface  _FilterEvent
 

Detailed Description

A custom filter allows your application to interact closely with the media pipeline, but cannot be used in graph resolution. Custom filters can be sources, sinks, or intermediate filters. The following limitations however exist:

A custom filter must implement the CustomFilter class, and optionally provide the following methods

A custom filter must also declare its capabilities, input and output, using push_cap method

let fs = new gpac.FilterSession();
let cust = fs.new_filter("NodeJS_Test");
//we accept any number of input pids
cust.set_max_pids(-1);
cust.pids = [];
cust.push_cap('StreamType', 'Visual', gpac.GF_CAPS_INPUT);
cust.push_cap('StreamType', 'Audio', gpac.GF_CAPS_INPUT);
cust.configure_pid = function(pid, is_remove)
{
if (this.pids.indexOf(pid) < 0) {
this.pids.push(pid);
console.log('New PID !');
} else if (is_remove) {
console.log('PID remove !');
} else {
console.log('PID reconfigure !');
}
return gpac.GF_OK;
}
cust.process = function() {
let nb_eos=0;
this.pids.forEach(pid =>{
if (pid.eos) {
nb_eos++;
return;
}
let pck = pid.get_packet();
if (!pck) return;
//do something
//done
pid.drop_packet();
return;
}
if (nb_eos == this.pids.length)
return gpac.GF_EOS;
return gpac.GF_OK;
}
cust.process_event = function(evt)
{
//do something, return true to cancel event
return false;
}

See GF_Filter


Data Structure Documentation

◆ _BufferOccupancy

interface _BufferOccupancy

buffer occupancy descriptor

Data Fields
unsigned long max_units

maximum number of packets (partial or full AU) allowed in buffer

unsigned long nb_pck

number of block allowed in buffer

unsigned long max_dur

maximum buffer duration in microseconds

unsigned long dur

buffer duration in microseconds

boolean is_final_flush

if true, the session has been aborted and this is the final flush for this buffer

◆ _FilterEvent

interface _FilterEvent

event object for filters and GPAC event proc.

The variables defined have the same names as the fields in the various unions of __gf_filter_event.

The variables are defined depending on the event type.

Additional variables are defined:

  • name: string decribing the event type
  • ui_type: integer giving the UI event type (see GF_Event)
  • ui_name: string decribing the UI event type

Events properties are read-only for input events and read/write for events created by the JS code.