[Q] How to cross-compile libav and x264 (C/C++ & ARMv7 assembler)? - Android Q&A, Help & Troubleshooting

Hello!
I would like to ask about compiling existing C/C++/asm sourcecode on Android, specifically the code of the libav codec system. After that, I would like to statically link against it, and build the x264 commandline video encoder. I don't need any fancy GUI video encoding stuff, just the statically linked x264 cli tool. The libav is needed to be able to read H.264/AVC input, the x264 to encode somewhat similar H.264/AVC output.
I do have some experience in compiling that code on x86/x86_64 and MIPSEL (chinese Loongson-2f specifically) architectures in Linux with gcc/yasm, but I am a total noob, when it comes to cross-compiling unfortunately, I have only built the code sitting directly on the target system so far.
What I do have here, is a CentOS 6.0 x86_64 multilib Linux, GNU make and autoconf tools, latest Android SDK (probably not needed) and latest Android NDK toolchain (definitely needed) as well as the yasm assembler to build the ARMv7 assembler codepaths of libav and x264. I'm also able to fall back to pure C/C++ in case the asm stuff is impossible. I have found some guys having done the x264 alone using Google search, but info on how exactly they did it is quite scarce.
My primary target platform is Android 2.2 on a TI OMAP3 chipset with an ARM Cortex A8 processor that I believe has a hardware FPU, but no NEON SIMD extensions. I may also want to target slightly different hardware, but all using the ARMv7 instruction set basically.
So, if anyone has experience in cross-compiling libav/x264 or similar stuff like ffmpeg, I would greatly appreciate help in getting that done. At the moment I'm quite at a loss with cross-compiling using the NDK..
I hope I am posting in the correct subforum, it's my first post here. Thanks for any help you might be able to provide!!

Related

[Linux Kernel] Linux Kernel and its Structure Defined[part II][nOOb friendly]

This is just a compilation about the topic and i have made it as much as noob friendly as i can. i will write it part wise when i get time. Hope it helps the community. if i missed something or wrote something wrong please point me out.
Do not forget to hit thanks if this helped
Linux Kernel and its Structure
PART I
Introduction:-
The Linux Kernel is as we all know is on of the most prominent example of free and open source software. Linux kernel is one of the most popular operating system kernel widely used by Linux distributions and variety of mobile devices. If was the result of a hobby of Finnish student Linus Torvalds and in 1991 he gave the birth to the Linux Kernel which redefined the concept of free and open source software.
The Linux Kernel is released under GNU General Public License version 2(GPLv2) and due to which more then a thousand people contribute to each kernel release. The large and dynamic developer and user community around Linux helps it to rapidly accumulate developers and users to adopt code from other free software projects to use with the Linux Kernel.
The main features of Linux Kernel are :-
1.Multitasking: several programs running at the same time.
2.Multiuser: several users on the same machine at the same time (and license for two users)
3.Scalibility: can run on super computers as well as tiny devices.
4. Multithreading: has native kernel support for multiple independent threads of control within a single process memory space and even has memory protection between processes, so that one program can't bring the whole system down.
demand loads executable: Linux only reads from disk those parts of a program that are actually used.
5.Free and open source:- All source code is available, including the whole kernel and all drivers, the development tools and all user programs; also, all of it can be freely distributed.
6.Multiple virtual consoles: several independent login sessions through the console, you switch by pressing a hot-key combination.
7.Supports several common filesystems, including minix, Xenix, and all the common system V filesystems, and has an advanced filesystem of its own.
8.An extensive networking support.
9.Modulatiry: Loads only those modules that are needed by the system, even at runtime.
10 Easy to code: Almost all the resources are available free, so users and developers can learn form existing codes already contributed by the community.
Defining System Calls:-
The main interface between the Linux Kernel and the user space is a set of system calls. Normally the system provides a library or API such as glibc, that provides the wrapper functions for the system calls. Kernel services like file operations, networking operations inter-process communications, threads, memory mapping etc are provided by over 300 system calls.
At present the system call interface is stable and only new system calls can be added by the Kernel developers. The user space applications usually never make a system call directly but rather it uses the corresponding C library function.
Getting Linux Kernel Sources:-
The Linux kernel Sources are free and open source as it is distributed by the GNU General Public License v2, you can get the source as released by Linus Torvalds at
HTML:
https://www.kernel.org
There are various versions available namely Prepatch, Minline, Stable, Longterm depending on the maintainers and stability status.
Thought many of the chip vendors supply their own kernel sources as you already have seen in case of Google device kernels maintained and distributed by Google. There are many sub-communities that maintain their own kernel, with usually new features or specific features, and my be stable or unstable.
The Linux Kernel sources can be downloaded at
HTML:
https://kernel.org/pub/linux/kernel/{version}/{branch}
as a full tarballs and patches.
But you can also get the kernel using the git version control system. Detailed description of the git version control system can be found here -
HTML:
http://git-scm.com/
The Linux kernel size vary from 500Mb to around 1Gb but you can get the kernel as archive in gzip, bzip2, xz depending upon the compression rate. The Linux core is pretty small but it contains thousands of device drivers, network protocol, many architectures, filesystems, documentations, firmware, scripts etc, so the large size of the Linux kernel.
The Linux Kernel is implemented in C as like all the UNIX system. A little assembly language is also used, but no C++ is used in the Linux Kernel. All the codes are compiled by gcc and a few alternative compilers, but ANSI C compile cannot compile the Linux Kernel as gcc specific extensions are used in the kernel code.
The main feature of the Linux kernel is that it has to be standalone, which means no user space code or part can be used in the Linux Kernel. The user space is then implemented on the top of the Linux Kernel. The Linux Kernel has to supply its own library implementations, and no standard C library functions are used in the kernel. But it provides its own similar C library.
The Linux Kernel is designed to be portable, and the kernel provides macros and functions to abstract the architecture specific details. The Linux Kernel never uses floating point unit as some of the architecture may not be compatible with it. The internal kernel API is not stable and can undergo changes between releases and so if you have to use the API then keep track of all the API available for the specific kernel release. An out-of-the tree compiled driver for a older version of the kernel may not work on the recent ones. Though the kernel to user space API does not change as it may break the existing scripts and program running in the user space.
GPL licensing and open source drivers:-
As mentioned earlier the Linux Kernel is licensed under the GNU General Public License version 2, which gives you the right to study, use, modify and share it without any cost. However it states that if the code is redistributed or shared modified or unmodified then it will be under the same license. More information about the GPLv2 can be found at -
HTML:
http://www.gnu.org/licenses/gpl-2.0.html
Thought there are a lot of propriety drivers that are available for different hardware. You cannot distribute a binary kernel that includes statistically compiled propriety drivers. Most of the common form of the propriety drivers can be found in the case of graphics cards, though open source drivers are also available for the same.
The main advantage of GPL licensed drivers is that you do not have to write the whole driver from scratch and you can reuse the code for similar free software. The GPL licensed drivers can be easily distributed inside a compiled kernel for example a Linux distribution. Free community contribution, support, testing can be attained. And the code becomes much more stable as many people review the code and contribute to it. Many device driver codes are also implemented in the user space. This is possible as the Linux Kernel provides a mechanism that allows the user space application to access the hardware directly. Certain drivers are handled partly in kernel space and partly in user space.
The user space drivers have a lot of advantages as you need no kernel coding skills to write a user space driver. User space drivers can be written in any language and they can even be kept propriety. The driver code can be killed and debugged without crashing the kernel, and moreover it can be swapped out for a much stable version without changing the kernel.
Part II
Part II
Overview Linux Kernel Source:-
The Linux Source structure is defined in this section. The directories give here are at the top level of the Linux source tree.
Makefile
This is the top level Makefile for the whole source tree. It defines a lot of useful variable and rules, such as the default gcc compilation flag. Here also we set the architecture and the version.
Documentation/
This directory contains a lot of useful information about configuring the kernel and all the help items. The help entries corresponding to the different configuration cannot be found here. They are located in the Kconfig files in each source directory. If you are starting out this folder you should now miss.
arch/
All the architecture corresponding codes are in this directory. Each architecture has its own directory underneath this directory. Some of the important sub-directories are -
Code:
arch/<ARCH>/mach-<machine>
machine/board specific code
Code:
arch/<ARCH>/include/asm
architecture specific headers
Code:
arch/<ARCH>boot/dts
Device tree architecture
block/
Block layer code
COPYING
This contains the license(GNU GPLv2)
CREDITS
This contains the main contributors are mentioned here.
crypto/
This is the cryptographic API for the use by the kernel itself
drivers/
In this directory we find all the device drivers of the peripheral devices. Only sound device driver is not located here.
firmware/
Firmware images extracted from old drivers are located here.
fs/
This directory contains the generic filesystem code, known as Virtual File System and also the code for each different filesystem are found in this directory. If you are on a Linux distribution, the root filesystem is probably ext4 filesystem. The code to read the ext4 filesystem can be found in
Code:
fs/ext4
.
include/
This directory contains all the kernel headers. During compilation a symbolic link from the asm-<ARCH> is created so the
Code:
#include <asm/file.h>
will get proper file for that architecture. There are other non-architectural specific header file.
init/
This directory contains the files main.c and version.c and code for creating an “early userspace”. The version.c defines the Linux version string.
ipc/
IPC stands for inter process communication. It contains the code for shared memory and other forms of process communications.
Kbuild
Part of the kernel build system.
kernel/
It contains the general kernel level code.
lib/
Routines of generic usefulness to all kernel code are here.
mm/
High level memory management codes are found here. Virtual memory(VM) implementation and early boot memory management are done here, as well as memory mapping of files, management of paging cache, memory allocation are done here.
net/
The high-level networking code is here. The low-level networking driver pass received packets up to and get get packets to send from this level, then it passes the data to the main application.
scripts/
This directory contains scripts that are useful in building the kernel, but does not include any code that is incorporated into the kernel itself.
sound/
Drivers for sound cards and other sound related code is placed here.
usr/
This directory contains code that builds a cpio-format archive containing a root filesystem image, which will be used for early user space.
tools/
Code for various user space tools
security/
Code for different Linux security models can be found here.
samples/
Sample codes

porting QEMU on android with KVM..

I have been compiling QEMU 1.7.2 version for android ARM based device.
Currently I have been able to successfully emulate Windows XP using TCG (tiny code generator) present in QEMU for binary translation and hardware emulation as it is not using KVM (hw based acceleration).
I am facing difficulty in booting Windows 8 image in QEMU, and facing the below error.
Your PC needs to restart.
Please hold down the power button.
Error Code : 0x0000005D
Parameters:
0x03060303
0x756E6547
0X49656E69
0X6C65746E
........................................
the above experiment with windows is emulated on x86 based device emulation whereas actual device is an ARM based device.
So inorder to use KVM I need ARM based image of Windows OR combine the TCG binary translation part along with KVM Direct Execution which will utilise hardware acceleration.
Anyone has been able to use TCG and KVM together??
Thoughts on this will be very helpful..Please let me know if anyone has experimented.
Regards
Kushal Parmar
Any progress on this? I would like to run qemu on android.

An executable from ARM Linux in Android.

Hi,
I have a program compiled for ARM Linux. It can use /dev/fb0 rather than X. Is there an Android app, possibly more than one choice, which will provide an environment where this program can run?
The version of this program for the Intel PC runs in Android under bochs. If the ARM executable can work, I'd expect it to be faster than the Intel executable.
Thanks! ... Peter E.

Building lz4 compression util for Android's ADB?

Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
kdar1987 said:
Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
Click to expand...
Click to collapse
If you want to build it for unnoficial devices such as the ones youve listed, follow any tutorial to download the CyanogenMod source (or other rom that supports those) and after lunching the device you want to build for, run 'make liblz4'
For device-independent tools like lz4, you can also lunch for some generic device with a matching CPU architecture.
And you need "make lz4" if you want the CLI tool.
kdar1987 said:
Does anyone have a build of lz4 compression or could explain to me how I can build it with NDK for Android? I want to run this compression utility from ADB on my phones (OnePlusOne and Galaxy S7).
I found lz4 source code here:
https://android.googlesource.com/platform/external/lz4/
Apparently NDK now uses .bp files instead of .mk.
Click to expand...
Click to collapse
It's ndk build/aosp build env methods aren't straight forward to make it a binary, only a lib, so i went ahead and compiled it into a binary. I didn't test it or anything, just compiled it statically for arm.
I tried using this and got
: Error 65 : Allocation error : not enough memory
Would this be because the program was built for 32-bit and my tablet is 64-bit? Can anyone tell if that message is from the system, that the program never loaded; or if that message is being printed by the program?

[CM13] ALSA instead of tinyALSA

Hey guys
I already asked this in some way over at Zenfone 2 sub forum but it might be better to post it here since it could be more CM-related than phone related.
At work we're developing an app which requires an x86 based processor to function properly. But we also need to use ALSA instead of tinyALSA related to various startup scripts required for that mentioned application and the application itself. Rewrite the whole parser is out of question due to the amount of work involved to port it over ARM platform.
Anyway we digged through the mixer settings of tinyALSA and came to the conclusion that it's not suitable for our app.
Currently I'm using the CyanogenMod 13 source code with ALSA lib and ALSA utils packages from Android x86 project (the Marshmallow-one of course). The build process is all fine and the binaries are usable inside an ADB shell but I'm not really able to use aplay for recording or playback of audio files.
Right now I'm stuck with the following error:
Code:
aplay: pcm_write:1684: write error: I/O error
I used "alsa_aplay /sdcard/Front_Center.wav -D hw:0,5 " to test the audio playback.
Some other problems occur when I want to use "alsa_ctl init", alsa_amixer can't load default mixer settings, "alsa_aplay -L" results in "NULL" output and so on.
Any suggestions on how to get audio capabilities working with true ALSA?
By the way: Our Zenfone 2 uses an Intel Atom Z3560 processor with rt5647-audio codec.

Categories

Resources