ADTF Qt5
Loading...
Searching...
No Matches
adtf::javascript::scripting::cScriptReader Class Reference

#include <reader.h>

Inherits QObject.

Public Member Functions

Q_INVOKABLE QVariant getNextSample ()
 
Q_INVOKABLE QVariant getLastSample ()
 
Q_INVOKABLE void requestSamples (const QVariant &oSubStreamFilter)
 
Q_INVOKABLE void cancelRequest (const QVariant &oSubStreamFilter)
 

Properties

QVariantList requests
 

Detailed Description

A Reader that is returned by cScriptFilter::createInputPin.

Samples returned by getNextSample(), getLastSample() and passed via the sample() signal contain the following elements:

  • sample.timestamp: contains the timestamp of the sample in nanoseconds.
  • sample.substream: contains the name of the substream that the sample belongs to (can be empty)
  • sample.data: contains the payload of the sample in one of the following forms:
    • For streams that have a media description:
      • A javascript object that represents the data structure of the media description, i.e sample.data.parent.child.value etc.
    • For streams with stream type "adtf/image"
      • A QImage with the image data.
    • For all others
      • A javascript ArrayBuffer object containing the raw data bytes of the sample

Please keep in mind that when you do not connect a callback to at least one of trigger() or sample(), all incoming samples will be discarded.

Member Function Documentation

◆ cancelRequest()

Q_INVOKABLE void adtf::javascript::scripting::cScriptReader::cancelRequest ( const QVariant & oSubStreamFilter)

Cancels a request for samples from a given Substream. If a Substream has been requested multiple times, all requests must be canceled individually.

Parameters
[in]oSubStreamFilterThe substream. Request can be of type QString or QRegularExpression. Must be a request that has been made before.

◆ getLastSample()

Q_INVOKABLE QVariant adtf::javascript::scripting::cScriptReader::getLastSample ( )

Returns the last available sample.

Example Usage

var input = filter.createInputPin("input")
input.trigger.connect(function(timestamp)
{
console.info("last sample: " + JSON.stringify(input.getLastSample()))
})
Warning
Mind that this does not work for Substreams.
Returns
The last sample available or false.

◆ getNextSample()

Q_INVOKABLE QVariant adtf::javascript::scripting::cScriptReader::getNextSample ( )

Returns the next available sample.

Example Usage

var input = filter.createInputPin("input")
input.trigger.connect(function(timestamp)
{
var sampleCount = 0
while ((sample = input.getNextSample()))
{
++sampleCount
}
console.info("recieved " + sampleCount + " samples")
})
Returns
The next sample available or false.

◆ requestSamples()

Q_INVOKABLE void adtf::javascript::scripting::cScriptReader::requestSamples ( const QVariant & oSubStreamFilter)

Request samples from Substreams matching the filter by name.

Example Usage

var input = filter.createInputPin("input")
// Whenever possible, set up requests for future substreams immediately after the pin was created.
// Trying to wait until a type change would result in potentially never reaching the type change.
// Request all streams starting with ^foo using an RegExp object.
input.requestSamples(/^foo/)
// Cancel previous request - type and content of the request must match exactly.
input.cancelRequest(/^foo/)
// Clearing all currently active requests.
for (const request of input.requests) {
input.cancelRequest(request)
}
// Request streamy by exact name.
input.requestSamples("stream1")
input.requestSamples("stream2")
input.streamTypeChanged.connect(function (type) {
console.info("stream type : " + JSON.stringify(type))
// Possible output:
/*
{
"stream_meta_type": "adtf/substreams"
"properties": {
// The property "substreams" denotes the use of nested substreams instead of a flat stream type.
"substreams": "true",
// Properties of form "substreams/[^/]+" denote presence of a named substream.
"substreams/stream1": "1",
// Properties of the nested type are prefixed with "substreams/[^/]+/".
"substreams/stream1/type": "adtf/plaintype",
"substreams/stream1/type/md_definitions": "...",
"substreams/stream1/type/md_struct": "UINT32"
}
}
*/
})
input.sample.connect(function (sample) {
// The property substream can only contain stream names that have matched a request.
if (sample.substream === "stream1") {
console.info("recieved sample from substream stream1")
}
else if (sample.substream === "stream2") {
console.info("recieved sample from substream stream2")
}
})
Parameters
[in]oSubStreamFilterThe Substream. Request can be of type QString or QRegularExpression.

Property Documentation

◆ requests

QVariantList adtf::javascript::scripting::cScriptReader::requests
read

List of currently active requests for Substreams. All list entries are of type QString or QRegularExpression.# Use requestSamples and cancelRequest to manipulate this list.


The documentation for this class was generated from the following file: