SPO600 - Project Stage 2
Published: 2021-12-11 21:00:35

## Introduction
Hello everyone, my name is Dustin. Today I'd like to talk about my process of working with project stage 2 in SPO600 course, and how I got it done, and the result.

For this stage 2 of the project, you have to choose one of these packages open source packages 
`ardour
eigen
ffmpeg
gnuradio
gromacs
lame
mjpegtools
nettle
numpy
pipewire
pulseaudio
vlc
xz`

to do a little research about. After a while looking it up online, I decided to go with `ffmpeg` because it may be the closest one to me :) The project can be found [here](https://github.com/FFmpeg/FFmpeg). 

As they state on their github: `FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata.` This basically means that we have already used it before but we don't really know their existence because it is just a small program in daily use of computer but has a huge importance. This project has lasted for more than a decade now since it's first created but we can see it's still actively being updated and contributed by looking at the last commit which is just a few hours ago. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogd8usiyzxnpp9vclpod.png)

## About the package
SIMD (Single Instruction Multiple Data) is a processing which using single instruction to process data including audio, video, subtitles and related metadata. 

They have like more than thousands files which contain humongous lines of code in there so finding which one is which also proposes a great challenge. But Github makes it easier as it offers people with search in the directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0x0krcyb40ihygqb3ggg.png)

This is an example of them using SIMD in Aarch64 architecture.  

Regarding x86_64 folder, it can be found [here](https://github.com/FFmpeg/FFmpeg/tree/master/libswscale/x86)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bubocnb4d78i92fudd45.png)

and SIMD use can be found [here](https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/x86/hscale_fast_bilinear_simd.c)

Because I'm not familiar with these architectures and I just spent a few hours looking at it. So I cannot fully understand what's going on in these files. It's just my personal perspective. And these files don't include lots of comments which brings the difficulty to a whole new level.

Speaking of h264pred_neon.s, in my opinion, it will be called during runtime because the line will only be called when the function outside is called. As we can see, this function is deep inside a file, another function from outside of this file can directly calls the function. Apart from that, it has a lot of function declarations and its implementations which I think will be called somewhere else. 

For hscale_fast_bilinear_simd.c, as far as I understand, it's written in c because it's in .c file but nested within a `__asm__`. This file will create optimized horizontal scaling routine. This scaler is made of runtime-generated MMXEXT code using specially tuned pshufw instructions. For every four output pixels, if four input pixels are enough for the fast bilinear scaling, then a chunk of fragmentB is used. If five input pixels are needed, then a chunk of fragmentA is used.
 

## Wrap up
It seems like this project is using a lot of SIMD in its code as in aarch64 folder, most of the files are `.c`, and `.S`. Because this is a transcoding, conversing library so it needs to utilize SIMD to maximize its performance.

This is one of the most difficult assignment I've ever had in this course. Mostly because I have not got a chance to deeply learn about these architectures. Besides, this is a big project that has been there for more than 1 decade, more than 100k commits have been made. So a few hours of looking at the source code means nothing.