GStreamer for Tiny Devices Olivier Crte Open First Who am I ? - - PowerPoint PPT Presentation

gstreamer for tiny devices
SMART_READER_LITE
LIVE PREVIEW

GStreamer for Tiny Devices Olivier Crte Open First Who am I ? - - PowerPoint PPT Presentation

GStreamer for Tiny Devices Olivier Crte Open First Who am I ? GStreamer at Collabora since 2007 Started with VVoIP: Telepathy & Farstream Helps our customers use GStreamer Many embedded projects 2 A Tiny Device? Flash


slide-1
SLIDE 1

Open First

GStreamer for Tiny Devices

Olivier Crête

slide-2
SLIDE 2

Who am I ?

  • GStreamer at Collabora since 2007
  • Started with VVoIP: Telepathy & Farstream
  • Helps our customers use GStreamer

– Many embedded projects

2

slide-3
SLIDE 3

A Tiny Device?

  • Flash Storage
  • Slow CPU
  • Little RAM

3

slide-4
SLIDE 4

Overview of GStreamer

4

slide-5
SLIDE 5

Pipelines!

5

slide-6
SLIDE 6

GStreamer in Applications

6

slide-7
SLIDE 7

Pipelines!

7

slide-8
SLIDE 8

GStreamer: Perfect for embedded!

  • Complete Zero-Copy toolkit

– Full negotiation – Buffer lifetime – Synchronization

  • Loads and loads of hardware enabled plugins
  • Very fast prototyping

8

slide-9
SLIDE 9

Example: A Security Camera

  • 16 MB Flash
  • 1 GB RAM
  • RTSP Server
  • ARMv7

9

slide-10
SLIDE 10

Example: A RTSP to MP4 file segments

  • Captures 2s clips from RTSP server

10

rtspsrc splitmuxsink h264parse rtph264depay

slide-11
SLIDE 11

Example: A RTSP to MP4 file segments

  • Prototype on PC:

g s t

  • l

a u n c h

  • 1

. r t s p s r c l

  • c

a t i

  • n

= r t s p : / / . . . ! r t p h 2 6 4 d e p a y ! h 2 6 4 p a r s e ! s p l i t m u x s i n k l

  • c

a t i

  • n

= f i l e _ t e m p l a t e _ % 5 d . m p 4

11

slide-12
SLIDE 12

Version 0: A shell script with gst-launch-1.0

  • Complete GStreamer build

– 287 MB for total build – 82 MB of dynamic libraries

12

287 MB

slide-13
SLIDE 13

Version 0.1: A shell script with gst-launch-1.0

  • Strip it

– 17 MB of dynamic libraries

13

17 MB

slide-14
SLIDE 14

Version 1: A C program

14

# i n c l u d e < g s t / g s t . h > # i n c l u d e < u n i s t d . h > i n t m a i n ( i n t a r g c , c h a r * * a r g v ) { G s t E l e m e n t * p i p e l i n e ; G E r r

  • r

* e r r

  • r

= N U L L ; g s t _ i n i t ( & a r g c , & a r g v ) ; p i p e l i n e = g s t _ p a r s e _ l a u n c h ( " r t s p s r c l

  • c

a t i

  • n

= r t s p : / / 1 2 7 . . . 1 : 8 5 5 4 / t e s t ! r t p h 2 6 4 d e p a y ! h 2 6 4 p a r s e ! s p l i t m u x s i n k m a x

  • s

i z e

  • t

i m e = 2 l

  • c

a t i

  • n

= v i d e

  • %

5 d . m p 4 " , & e r r

  • r

) ; i f ( ! p i p e l i n e ) g _ e r r

  • r

( " E r r

  • r

: % s " , e r r

  • r
  • >

m e s s a g e ) ; g s t _ e l e m e n t _ s e t _ s t a t e ( p i p e l i n e , G S T _ S T A T E _ P L A Y I N G ) ; p a u s e ( ) ; g s t _ e l e m e n t _ s e t _ s t a t e ( p i p e l i n e , G S T _ S T A T E _ N U L L ) ; r e t u r n ; }

slide-15
SLIDE 15

Version 1: A C program (Makefile)

15

S Y S R O O T = / h

  • m

e /

  • c

r e t e / c

  • l

l a b

  • r

a / c e r b e r

  • /

t

  • l

c h a i n / s y s r

  • t
  • g

l i b c

  • l

i n a r

  • 2

. 2 5

  • 2

1 7 . 8

  • a

r m

  • l

i n u x

  • g

n u e a b i h f C C = / h

  • m

e /

  • c

r e t e / c

  • l

l a b

  • r

a / c e r b e r

  • /

t

  • l

c h a i n / g c c

  • l

i n a r

  • 7

. 1 . 1

  • 2

1 7 . 8

  • i

6 8 6 _ a r m

  • l

i n u x

  • g

n u e a b i h f / b i n / a r m

  • l

i n u x

  • g

n u e a b i h f

  • g

c c P K G _ C O N F I G _ P A T H = / h

  • m

e /

  • c

r e t e / c

  • l

l a b

  • r

a / c e r b e r

  • /

b u i l d / d i s t / l i n u x _ a r m v 7 / l i b / p k g c

  • n

f i g p r

  • g

r a m : p r

  • g

r a m . c M a k e f i l e l i b t

  • l

l i n k

  • t

a g = C C $ ( C C ) ` P K G _ C O N F I G _ P A T H = $ ( P K G _ C O N F I G _ P A T H ) p k g

  • c
  • n

f i g

  • l

i b s

  • c

f l a g s g s t r e a m e r

  • 1

. ` p r

  • g

r a m . c

  • p

r

  • g

r a m

slide-16
SLIDE 16

Version 1: A C program

  • Binary: 13K

– Stripped: 5.5K

  • Plus 17 MB in libraries
  • Total: 17 MB

16

17 MB

slide-17
SLIDE 17

Static Build?

  • Using libtool

– l

i b t

  • l
  • s

t a t i c

  • l

i b t

  • l
  • l

i b s

– p

k g

  • c
  • n

f i g –

  • s

t a t i c

  • 7.5 MB binary
  • Stripped: 1.5 MB static binary

17

1.5 MB

slide-18
SLIDE 18

Try on device

  • Put on Flash, run it:

* * ( p r

  • g

r a m : 1 4 8 6 ) : E R R O R * * : E r r

  • r

: n

  • e

l e m e n t " r t s p s r c "

  • Missing all the plugins!

18

slide-19
SLIDE 19

Copy plugins

  • All ? 17MB

. …

  • Only relevant?!

– G

S T _ D E B U G = G S T _ P L U G I N _ L O A D I N G : 4

  • Total 1.7 MB in plugins once stripped

19

1.7 MB

slide-20
SLIDE 20

Try on device again

( p r

  • g

r a m : 2 3 2 1 1 ) : G S t r e a m e r

  • W

A R N I N G * * : F a i l e d t

  • l
  • a

d p l u g i n ' / l i b / g s t r e a m e r

  • 1

. / l i b g s t u d p . s

  • '

: l i b g s t n e t

  • 1

. . s

  • .

: c a n n

  • t
  • p

e n s h a r e d

  • b

j e c t f i l e : N

  • s

u c h f i l e

  • r

d i r e c t

  • r

y

  • Plugins are not static!

– Need to re-add libraries – Back to 17 MB

20

17 MB

slide-21
SLIDE 21

Statically build plugins

  • Declare functions like

G S T _ P L U G I N _ S T A T I C _ D E C L A R E ( c

  • r

e e l e m e n t s ) ;

  • Register plugins

– After g

s t _ i n i t ( )

– G

S T _ P L U G I N _ S T A T I C _ R E G I S T E R ( c

  • r

e e l e m e n t s ) ;

21

slide-22
SLIDE 22

Statically build plugins

  • Link with
  • L

/ h

  • m

e /

  • c

r e t e / c

  • l

l a b

  • r

a / c e r b e r

  • /

b u i l d / d i s t / l i n u x _ a r m v 7 / l i b / g s t r e a m e r

  • 1

.

  • l

g s t c

  • r

e e l e m e n t s

  • l

g s t i s

  • m

p 4

  • l

g s t v i d e

  • p

a r s e r s b a d

  • l

g s t r t p

  • l

g s t r t s p

  • l

g s t r t p m a n a g e r

  • l

g s t u d p

22

slide-23
SLIDE 23

Statically build plugins

  • Real static binary is 28 MB
  • Stripped to 4.7 MB
  • Really working on device

23

4.7 MB

slide-24
SLIDE 24

Ask the compiler for HELLPPP !

  • Compile with -Os
  • Disappointing, it hasn't improved!

– Stripped Binary: 4.7 MB

24

4.7 MB

slide-25
SLIDE 25

Strip functions that are not used

  • Build with:
  • f

f u n c t i

  • n
  • s

e c t i

  • n

s

  • f

d a t a

  • s

e c t i

  • n

s

  • Link with:
  • W

l ,

  • g

c

  • s

e c t i

  • n

s

  • Stripped Binary : 4 MB

25

4 MB

slide-26
SLIDE 26

Dig into!

  • Find which .o files contribute to the sink
  • Used

– objdump – Python script

  • Tool: Bloaty McBloatface

– Did not work for me

26

slide-27
SLIDE 27

Butcher GLib

  • GLib has internal plugins
  • Always registered
  • Not used, but bot garbage collected
  • Butcher them out

27

slide-28
SLIDE 28

Butcher GLib

  • Removed

– GSettings – GDBus – AppInfo – Gapplication – Notifications

https://people.collabora.com/~tester/Butcher-glib-remove-gdbus-gapplication-desktopap.patch

28

slide-29
SLIDE 29

Butcher GLib

  • Stripped binary down to 3.8 MB

29

3.8 MB

slide-30
SLIDE 30

Cheating time: Compressed binary

  • Using upx

u p x

  • b

e s t p r

  • g

r a m

  • Compress down to 2 MB

30

2 MB

slide-31
SLIDE 31

More steps

  • Remove UTF-8 tables in GLib
  • Dig into exact linked code

31

slide-32
SLIDE 32

Thank you!