SlideShare a Scribd company logo
1 of 15
Gstreamer – Multimedia Stack
Dr. Selvaraj Kesavan
Contents
2
Gstreamer overview
Gstreamer building blocks
Memory management
Debug/Tracing
Clock and synchronization
Latency
Gstreamer
3
 Gstreamer is multimedia stack ,provides elements and pipeline between different elements for
creating multimedia applications such as player ,recorder ,streaming player ,video telephony, STB
rendering etc.
 End to end Multimedia stack for audio, video ,Image ,streaming ,player ,recorder ,video
telephony , Settopbox applications
 Higher level than just input / filters / output
 Networking, audio/video mixed streams, auto data handling
 Various options utilizing hardware accelerators
 Elements
 Sources, filters, sinks
 Bins and Pipelines
 Containers, pipeline is the overall bin
 Elements that contain other elements
 Allow multiple elements to be treated as one entity
 Pads
 Element source / sink connection points
 Caps
Simple pipeline
4
Create dynamically using gst-launch
Source element reads from a file
Filter element converts MP3 to PWM
Sink element passes to ALSA output
gst-launch filesrc location=a.mp3 ! mad ! alsasink
gst-launch videotestsrc ! ffmpegcolorspace ! Fbdevsink
Buffers and Events
5
Buffer:
• A pointer to the actual data being passed
• A reference to a caps structure
•Timestamp, offset, some other metadata
• Reference-counted
• Sub buffers
Events:
• Messages passed in both directions up and down the pipeline
• Used to find out about the pipeline details
• Can be in-band or out-of-band
• Examples:
– Seeking
– Flush
– Segments
– Position
– Duration
State
6
gst_element_set_state (element, state)
GST_STATE_NULL
• default state. No resources are allocated in this state, so, transitioning to it will free all resources
GST_STATE_READY
• Element has allocated all of its global resources. Resources kept within streams. In this state element
open the devices, allocating buffers but the stream is not opened in this state
GST_STATE_PAUSED
• Element has opened the stream, but is not actively processing .Element is allowed to modify a stream's
position, read and process data and such to prepare for playback. Video or audio outputs pushed into
buffer and queue to play it right after the state change. video sinks can already play the first frame
GST_STATE_PLAYING
• element does exactly the same as in the PAUSED state, except that the clock now run
Threads and Bus
7
THREADS:
•Tell an element to go to PLAYING, and something starts happening behind the scenes...
• Data flow happens in separate threads
• States change asynchronously
• GStreamer is thread-safe when using API functions.
BUS:
• Receives messages from elements such as End-Of-Stream, error, warning, tags (title, track,
etc.), state changes...
• Marshals the messages to the main thread
• Apps can, for the most part, ignore the existence of threads
Memory
8
• Most objects might deal with are refcounted.
• GstMemory is an object that manages a region of memory
• GstMemory objects are created by a GstAllocator object
• Different allocators exist for, for example, system memory, shared memory and memory
backed by a DMAbuf file descriptor
• The buffer contains one or more GstMemory objects thet represent the data in the buffer
/* allocate 100 bytes */
mem = gst_allocator_alloc (NULL, 100, NULL);
/* get access to the memory in write mode */
gst_memory_map (mem, &info, GST_MAP_WRITE);
/* fill with pattern */
for (i = 0; i < info.size; i++) info.data[i] = i;
/* release memory */
gst_memory_unmap (mem, &info);
Gstremaer – Debug options
9
• Elements are instrumented with debug output using macros.
• Debug statements are directed to a specific category, and debug level.
• The output is only produced if the category and level are enabled.
• Preferably elements also supply the GstObject outputting the message – makes the output more
useful.
• Plugins can register their own debug categories.
• See the list of available categories:– gst-inspect –gst-debug-help
• 5 levels available: ERROR, WARN, INFO, DEBUG and LOG
• To turn all categories on set the GST_DEBUG env var to the level: GST_DEBUG=5 gst-launch ....
• Turn on specific debug categories: GST_DEBUG=filesrc:5,GST_PADS:3 gst-launch ...
• Can use wildcards: GST_DEBUG=*src:5 gstlaunch...
• Works with all apps of course,(not just gst-launch)
• The overhead is fairly low for disabled categories, but the whole thing can be compiled out.
Clocks and synchronization
10
System Clock
• GStreamer uses a GstClock object, buffer timestamps and a SEGMENT event to synchronize streams in a pipeline
• running-time = absolute-time - base-time
• A GStreamer GstPipeline object maintains a GstClock object and a base-time when it goes to the PLAYING state. The pipeline gives a
handle to the selected GstClock to each element in the pipeline along with selected base-time
• all objects in the pipeline have the same clock and base-time, they can thus all calculate the running-time according to the pipeline clock.
Buffer running-time
• Buffer running-time, needs buffer timestamp and the SEGMENT event that preceded the buffer.
• First we can convert the SEGMENT event into a GstSegment object and then we can use the gst_segment_to_running_time () function to
perform the calculation of the buffer running-time
• Synchronization is now a matter of making sure that a buffer with a certain running-time is played when the clock reaches the same
running-time
• Usually this task is done by sink elements. Sink also have to take into account the latency configured in the pipeline and add this to the
buffer running-time before synchronizing to the pipeline clock
• Non-live sources timestamp buffers with a running-time starting from 0. After a flushing seek, they will produce buffers again from a
running-time of 0.
• Live sources need to timestamp buffers with a running-time matching the pipeline running-time when the first byte of the buffer was
captured
Clocks and synchronization
11
Buffer stream-time:
• The buffer stream-time, also known as the position in the stream, is calculated from the buffer timestamps
and the preceding SEGMENT event. It represents the time inside the media as a value between 0 and the
total duration of the media.
• The stream-time is never used to synchronize streams, this is only done with the running-time
• running-time of a buffer always increments monotonically along with the clock-time. Buffers are played
when their running-time is equal to the clock-time - base-time. The stream-time represents the position in
the stream and jumps backwards when repeating
Clocks and synchronization
12
Clock providers:
• A clock provider is an element in the pipeline that can provide a GstClock object.
• The clock object needs to report an absoulute-time that is monotonocally increasing when the element is in the PLAYING state..
• Clock providers exist because they play back media at some rate, and this rate is not necessarily the same as the system clock
rate.
• For example, a soundcard may playback at 44,1 kHz, but that doesn't mean that after exactly 1 second according to the system
clock, the soundcard has played back 44.100 samples. This is only true by approximation. In fact, the audio device has an
internal clock based on the number of samples played that we can expose
• If an element with an internal clock needs to synchronize, it needs to estimate when a time according to the pipeline clock will
take place according to the internal clock. To estimate this, it needs to slave its clock to the pipeline clock.
• If the pipeline clock is exactly the internal clock of an element, the element can skip the slaving step and directly use the pipeline
clock to schedule playback. This can be both faster and more accurate. Therefore, generally, elements with an internal clock like
audio input or output devices will be a clock provider for the pipeline.
Clocks and synchronization
13
• When the pipeline goes to the PLAYING state, it will go over all elements in the pipeline from sink to source and ask each
element if they can provide a clock. The last element that can provide a clock will be used as the clock provider in the pipeline.
This algorithm prefers a clock from an audio sink in a typical playback pipeline and a clock from source elements in a typical
capture pipeline.
• There exist some bus messages to let you know about the clock and clock providers in the pipeline. You can see what clock is
selected in the pipeline by looking at the NEW_CLOCK message on the bus. When a clock provider is removed from the
pipeline, a CLOCK_LOST message is posted and the application should go to PAUSED and back to PLAYING to select a new
clock.
Latency
14
• The latency is the time it takes for a sample captured at timestamp X to reach the sink. This time is measured against the clock in
the pipeline. For pipelines where the only elements that synchronize against the clock are the sinks, the latency is always 0 since
no other element is delaying the buffer
• For pipelines with live sources, a latency is introduced, mostly because of the way a live source works. Consider an audio source,
it will start capturing the first sample at time 0. If the source pushes buffers with 44100 samples at a time at 44100Hz it will have
collected the buffer at second 1. Since the timestamp of the buffer is 0 and the time of the clock is now >= 1 second, the sink will
drop this buffer because it is too late. Without any latency compensation in the sink, all buffers will be dropped.
• Before the pipeline goes to the PLAYING state, it will, in addition to selecting a clock and calculating a base-time, calculate the
latency in the pipeline. It does this by doing a LATENCY query on all the sinks in the pipeline. The pipeline then selects the
maximum latency in the pipeline and configures this with a LATENCY event.
• All sink elements will delay playback by the value in the LATENCY event. Since all sinks delay with the same amount of time, they
will be relative in sync
• Adding/removing elements to/from a pipeline or changing element properties can change the latency in a pipeline. An element
can request a latency change in the pipeline by posting a LATENCY message on the bus. The application can then decide to
query and redistribute a new latency or not. Changing the latency in a pipeline might cause visual or audible glitches and
should therefore only be done by the application when it is allowed.
Thank You
15

More Related Content

What's hot

Gstreamer: an Overview
Gstreamer: an OverviewGstreamer: an Overview
Gstreamer: an OverviewRodrigo Costa
 
Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...Luis Lopez
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewRajKumar Rampelli
 
HKG18-402 - Build secure key management services in OP-TEE
HKG18-402 - Build secure key management services in OP-TEEHKG18-402 - Build secure key management services in OP-TEE
HKG18-402 - Build secure key management services in OP-TEELinaro
 
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEEBKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEELinaro
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux MultimediaCaglar Dursun
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAMChris Simmonds
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewLinaro
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringAnne Nicolas
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overviewJerrin George
 

What's hot (20)

Gstreamer plugin development
Gstreamer plugin development Gstreamer plugin development
Gstreamer plugin development
 
Gstreamer: an Overview
Gstreamer: an OverviewGstreamer: an Overview
Gstreamer: an Overview
 
Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
HKG18-402 - Build secure key management services in OP-TEE
HKG18-402 - Build secure key management services in OP-TEEHKG18-402 - Build secure key management services in OP-TEE
HKG18-402 - Build secure key management services in OP-TEE
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEEBKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Important adb commands
Important adb commandsImportant adb commands
Important adb commands
 
Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux Multimedia
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uring
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
 

Similar to Gstreamer internals

Fluentd v0.14 Plugin API Details
Fluentd v0.14 Plugin API DetailsFluentd v0.14 Plugin API Details
Fluentd v0.14 Plugin API DetailsSATOSHI TAGOMORI
 
Monitoring and tuning your chef server - chef conf talk
Monitoring and tuning your chef server - chef conf talk Monitoring and tuning your chef server - chef conf talk
Monitoring and tuning your chef server - chef conf talk Andrew DuFour
 
Process scheduling &amp; time
Process scheduling &amp; timeProcess scheduling &amp; time
Process scheduling &amp; timeYojana Nanaware
 
Backing Up and Recovery
Backing Up and RecoveryBacking Up and Recovery
Backing Up and RecoveryMaham Huda
 
Comprehensive Monitoring for Docker
Comprehensive Monitoring for DockerComprehensive Monitoring for Docker
Comprehensive Monitoring for DockerChristian Beedgen
 
Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Stamo Petkov
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of ProcessorsGaditek
 
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorOrenEzer1
 
On the benchmark of Chainer
On the benchmark of ChainerOn the benchmark of Chainer
On the benchmark of ChainerKenta Oono
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptxDivyaKS18
 
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBegan
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBeganKoprowskiT_SQLSatMoscow_2AMaDisaterJustBegan
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBeganTobias Koprowski
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualFreyrSCADA Embedded Solution
 

Similar to Gstreamer internals (20)

I/O Organization
I/O OrganizationI/O Organization
I/O Organization
 
Fluentd v0.14 Plugin API Details
Fluentd v0.14 Plugin API DetailsFluentd v0.14 Plugin API Details
Fluentd v0.14 Plugin API Details
 
Monitoring and tuning your chef server - chef conf talk
Monitoring and tuning your chef server - chef conf talk Monitoring and tuning your chef server - chef conf talk
Monitoring and tuning your chef server - chef conf talk
 
Process scheduling &amp; time
Process scheduling &amp; timeProcess scheduling &amp; time
Process scheduling &amp; time
 
Backing Up and Recovery
Backing Up and RecoveryBacking Up and Recovery
Backing Up and Recovery
 
AMC Minor Technical Issues
AMC Minor Technical IssuesAMC Minor Technical Issues
AMC Minor Technical Issues
 
Comprehensive Monitoring for Docker
Comprehensive Monitoring for DockerComprehensive Monitoring for Docker
Comprehensive Monitoring for Docker
 
ch2.pptx
ch2.pptxch2.pptx
ch2.pptx
 
Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
C++ scalable network_io
C++ scalable network_ioC++ scalable network_io
C++ scalable network_io
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
 
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactor
 
On the benchmark of Chainer
On the benchmark of ChainerOn the benchmark of Chainer
On the benchmark of Chainer
 
IoT Aquarium
IoT AquariumIoT Aquarium
IoT Aquarium
 
IoT Aquarium 2
IoT Aquarium 2IoT Aquarium 2
IoT Aquarium 2
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBegan
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBeganKoprowskiT_SQLSatMoscow_2AMaDisaterJustBegan
KoprowskiT_SQLSatMoscow_2AMaDisaterJustBegan
 
C100 k and go
C100 k and goC100 k and go
C100 k and go
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manual
 

More from Selvaraj Kesavan

Role of cloud and analytics in IoT
Role of cloud and analytics in IoTRole of cloud and analytics in IoT
Role of cloud and analytics in IoTSelvaraj Kesavan
 
Cloud computing aws -key services
Cloud computing  aws -key servicesCloud computing  aws -key services
Cloud computing aws -key servicesSelvaraj Kesavan
 
Cloud Computing Virtualization and containers
Cloud Computing Virtualization and containersCloud Computing Virtualization and containers
Cloud Computing Virtualization and containersSelvaraj Kesavan
 
Emergence of cloud computing and internet of things an overview
Emergence of cloud computing and internet of things   an overviewEmergence of cloud computing and internet of things   an overview
Emergence of cloud computing and internet of things an overviewSelvaraj Kesavan
 

More from Selvaraj Kesavan (8)

Analytics&IoT
Analytics&IoTAnalytics&IoT
Analytics&IoT
 
Role of cloud and analytics in IoT
Role of cloud and analytics in IoTRole of cloud and analytics in IoT
Role of cloud and analytics in IoT
 
Cloud computing aws -key services
Cloud computing  aws -key servicesCloud computing  aws -key services
Cloud computing aws -key services
 
Cloud Computing Virtualization and containers
Cloud Computing Virtualization and containersCloud Computing Virtualization and containers
Cloud Computing Virtualization and containers
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Internet of things
Internet of thingsInternet of things
Internet of things
 
Emergence of cloud computing and internet of things an overview
Emergence of cloud computing and internet of things   an overviewEmergence of cloud computing and internet of things   an overview
Emergence of cloud computing and internet of things an overview
 
Multimedia streaming
Multimedia streamingMultimedia streaming
Multimedia streaming
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 

Gstreamer internals

  • 1. Gstreamer – Multimedia Stack Dr. Selvaraj Kesavan
  • 2. Contents 2 Gstreamer overview Gstreamer building blocks Memory management Debug/Tracing Clock and synchronization Latency
  • 3. Gstreamer 3  Gstreamer is multimedia stack ,provides elements and pipeline between different elements for creating multimedia applications such as player ,recorder ,streaming player ,video telephony, STB rendering etc.  End to end Multimedia stack for audio, video ,Image ,streaming ,player ,recorder ,video telephony , Settopbox applications  Higher level than just input / filters / output  Networking, audio/video mixed streams, auto data handling  Various options utilizing hardware accelerators  Elements  Sources, filters, sinks  Bins and Pipelines  Containers, pipeline is the overall bin  Elements that contain other elements  Allow multiple elements to be treated as one entity  Pads  Element source / sink connection points  Caps
  • 4. Simple pipeline 4 Create dynamically using gst-launch Source element reads from a file Filter element converts MP3 to PWM Sink element passes to ALSA output gst-launch filesrc location=a.mp3 ! mad ! alsasink gst-launch videotestsrc ! ffmpegcolorspace ! Fbdevsink
  • 5. Buffers and Events 5 Buffer: • A pointer to the actual data being passed • A reference to a caps structure •Timestamp, offset, some other metadata • Reference-counted • Sub buffers Events: • Messages passed in both directions up and down the pipeline • Used to find out about the pipeline details • Can be in-band or out-of-band • Examples: – Seeking – Flush – Segments – Position – Duration
  • 6. State 6 gst_element_set_state (element, state) GST_STATE_NULL • default state. No resources are allocated in this state, so, transitioning to it will free all resources GST_STATE_READY • Element has allocated all of its global resources. Resources kept within streams. In this state element open the devices, allocating buffers but the stream is not opened in this state GST_STATE_PAUSED • Element has opened the stream, but is not actively processing .Element is allowed to modify a stream's position, read and process data and such to prepare for playback. Video or audio outputs pushed into buffer and queue to play it right after the state change. video sinks can already play the first frame GST_STATE_PLAYING • element does exactly the same as in the PAUSED state, except that the clock now run
  • 7. Threads and Bus 7 THREADS: •Tell an element to go to PLAYING, and something starts happening behind the scenes... • Data flow happens in separate threads • States change asynchronously • GStreamer is thread-safe when using API functions. BUS: • Receives messages from elements such as End-Of-Stream, error, warning, tags (title, track, etc.), state changes... • Marshals the messages to the main thread • Apps can, for the most part, ignore the existence of threads
  • 8. Memory 8 • Most objects might deal with are refcounted. • GstMemory is an object that manages a region of memory • GstMemory objects are created by a GstAllocator object • Different allocators exist for, for example, system memory, shared memory and memory backed by a DMAbuf file descriptor • The buffer contains one or more GstMemory objects thet represent the data in the buffer /* allocate 100 bytes */ mem = gst_allocator_alloc (NULL, 100, NULL); /* get access to the memory in write mode */ gst_memory_map (mem, &info, GST_MAP_WRITE); /* fill with pattern */ for (i = 0; i < info.size; i++) info.data[i] = i; /* release memory */ gst_memory_unmap (mem, &info);
  • 9. Gstremaer – Debug options 9 • Elements are instrumented with debug output using macros. • Debug statements are directed to a specific category, and debug level. • The output is only produced if the category and level are enabled. • Preferably elements also supply the GstObject outputting the message – makes the output more useful. • Plugins can register their own debug categories. • See the list of available categories:– gst-inspect –gst-debug-help • 5 levels available: ERROR, WARN, INFO, DEBUG and LOG • To turn all categories on set the GST_DEBUG env var to the level: GST_DEBUG=5 gst-launch .... • Turn on specific debug categories: GST_DEBUG=filesrc:5,GST_PADS:3 gst-launch ... • Can use wildcards: GST_DEBUG=*src:5 gstlaunch... • Works with all apps of course,(not just gst-launch) • The overhead is fairly low for disabled categories, but the whole thing can be compiled out.
  • 10. Clocks and synchronization 10 System Clock • GStreamer uses a GstClock object, buffer timestamps and a SEGMENT event to synchronize streams in a pipeline • running-time = absolute-time - base-time • A GStreamer GstPipeline object maintains a GstClock object and a base-time when it goes to the PLAYING state. The pipeline gives a handle to the selected GstClock to each element in the pipeline along with selected base-time • all objects in the pipeline have the same clock and base-time, they can thus all calculate the running-time according to the pipeline clock. Buffer running-time • Buffer running-time, needs buffer timestamp and the SEGMENT event that preceded the buffer. • First we can convert the SEGMENT event into a GstSegment object and then we can use the gst_segment_to_running_time () function to perform the calculation of the buffer running-time • Synchronization is now a matter of making sure that a buffer with a certain running-time is played when the clock reaches the same running-time • Usually this task is done by sink elements. Sink also have to take into account the latency configured in the pipeline and add this to the buffer running-time before synchronizing to the pipeline clock • Non-live sources timestamp buffers with a running-time starting from 0. After a flushing seek, they will produce buffers again from a running-time of 0. • Live sources need to timestamp buffers with a running-time matching the pipeline running-time when the first byte of the buffer was captured
  • 11. Clocks and synchronization 11 Buffer stream-time: • The buffer stream-time, also known as the position in the stream, is calculated from the buffer timestamps and the preceding SEGMENT event. It represents the time inside the media as a value between 0 and the total duration of the media. • The stream-time is never used to synchronize streams, this is only done with the running-time • running-time of a buffer always increments monotonically along with the clock-time. Buffers are played when their running-time is equal to the clock-time - base-time. The stream-time represents the position in the stream and jumps backwards when repeating
  • 12. Clocks and synchronization 12 Clock providers: • A clock provider is an element in the pipeline that can provide a GstClock object. • The clock object needs to report an absoulute-time that is monotonocally increasing when the element is in the PLAYING state.. • Clock providers exist because they play back media at some rate, and this rate is not necessarily the same as the system clock rate. • For example, a soundcard may playback at 44,1 kHz, but that doesn't mean that after exactly 1 second according to the system clock, the soundcard has played back 44.100 samples. This is only true by approximation. In fact, the audio device has an internal clock based on the number of samples played that we can expose • If an element with an internal clock needs to synchronize, it needs to estimate when a time according to the pipeline clock will take place according to the internal clock. To estimate this, it needs to slave its clock to the pipeline clock. • If the pipeline clock is exactly the internal clock of an element, the element can skip the slaving step and directly use the pipeline clock to schedule playback. This can be both faster and more accurate. Therefore, generally, elements with an internal clock like audio input or output devices will be a clock provider for the pipeline.
  • 13. Clocks and synchronization 13 • When the pipeline goes to the PLAYING state, it will go over all elements in the pipeline from sink to source and ask each element if they can provide a clock. The last element that can provide a clock will be used as the clock provider in the pipeline. This algorithm prefers a clock from an audio sink in a typical playback pipeline and a clock from source elements in a typical capture pipeline. • There exist some bus messages to let you know about the clock and clock providers in the pipeline. You can see what clock is selected in the pipeline by looking at the NEW_CLOCK message on the bus. When a clock provider is removed from the pipeline, a CLOCK_LOST message is posted and the application should go to PAUSED and back to PLAYING to select a new clock.
  • 14. Latency 14 • The latency is the time it takes for a sample captured at timestamp X to reach the sink. This time is measured against the clock in the pipeline. For pipelines where the only elements that synchronize against the clock are the sinks, the latency is always 0 since no other element is delaying the buffer • For pipelines with live sources, a latency is introduced, mostly because of the way a live source works. Consider an audio source, it will start capturing the first sample at time 0. If the source pushes buffers with 44100 samples at a time at 44100Hz it will have collected the buffer at second 1. Since the timestamp of the buffer is 0 and the time of the clock is now >= 1 second, the sink will drop this buffer because it is too late. Without any latency compensation in the sink, all buffers will be dropped. • Before the pipeline goes to the PLAYING state, it will, in addition to selecting a clock and calculating a base-time, calculate the latency in the pipeline. It does this by doing a LATENCY query on all the sinks in the pipeline. The pipeline then selects the maximum latency in the pipeline and configures this with a LATENCY event. • All sink elements will delay playback by the value in the LATENCY event. Since all sinks delay with the same amount of time, they will be relative in sync • Adding/removing elements to/from a pipeline or changing element properties can change the latency in a pipeline. An element can request a latency change in the pipeline by posting a LATENCY message on the bus. The application can then decide to query and redistribute a new latency or not. Changing the latency in a pipeline might cause visual or audible glitches and should therefore only be done by the application when it is allowed.

Editor's Notes

  1. .