zero-copy pipelines in gstreamer · “two elements are doing zero-copy when the data produced by...

19
Open First Open First Zero-Copy Pipelines in GStreamer by Nicolas Dufresne IRC: ndufresne Email: [email protected]

Upload: others

Post on 27-Jan-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

Open FirstOpen First

Zero-Copy Pipelines in GStreamer by Nicolas DufresneIRC: ndufresneEmail: [email protected]

Page 2: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

● What does zero-copy mean ?● Why do we copy ?● What are the side effects ?

GStreamer Conference 2017 2

Overview

Page 3: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

What does zero-copy mean?

GStreamer Conference 2017 3

Page 4: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

“Two Elements are doing zero-copy when the data produced by one Element is used by the 

other Element without requiring an idempotent transform.”

GStreamer Conference 2017 4

Definition

Page 5: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 5

GStreamer Mechanisms Allocation

Query

BufferPools and / or

Allocators

Refcounted Buffers and Memories

Memory Logical

Grouping

Caps Features

(Since 1.2)

Page 6: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 6

Upstream vs Downstream

Allocation

DownstreamUpstream

Queries the AllocationFills the Query

Decides Allocation

Queries the Caps

Decides Caps

Sends the Caps Event

Sends Buffers

Page 7: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

Why do we copy ?

GStreamer Conference 2017 7

Page 8: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 8

Allocation Type

Virtual Memory

Contiguous

Scatter Gather

GPUMemory

Page 9: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 9

Abstractions leads to trial and error

...GEM

Surface DMA-Buf

Page 10: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 10

Video AlignmentY Plane

Y Plane

U Plane

Stride

Width

Offse

t

Height

Page 11: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 11

Audio CopiesUnified Channel

Order

Format and Sampling

Conversion

Ring Buffers with Threads

Page 12: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

Ring Buffer Based Buffer Pools ?

GstFlowReturngst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer, GstBufferPoolAcquireParams *params);

struct GstBufferPoolAcquireParams { GstFormat format; gint64 start; gint64 stop; GstBufferPoolAcquireFlags flags;};

Page 13: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 13

Why should I copy ?

To help with transitions

To Support Software Elements

To help testing

Page 14: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

What are the side effects ?

GStreamer Conference 2017 14

Page 15: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 15

Pooling

Source

Encoder

Tee Display

Transmitter

Page 16: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017 16

BufferReclaiming

Required with V4L2 and OMX

DownstreamUpstream

Allocation or Drain QueryDrains and returns ref frames

orCopy and return ref frame

Mostly Needed for legacy APIs

Should not be needed

for DMABuf (it’s a bug!)

Page 17: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

What do we gain ?

Higher Performance

More CPU Time

Lower Processing

Latency

Page 18: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

Questions

Page 19: Zero-Copy Pipelines in GStreamer · “Two Elements are doing zero-copy when the data produced by one Element is used by the other Element without requiring an idempotent transform.”

GStreamer Conference 2017

Thank you!