Multimedia
The AM62Px has video encoder/decoder: the Chips & Media Wave5.
The wave5 hardware is implemented via:
the
wave5
driver, located in${YOUR_PATH}/ti-kernel-aosp/common/drivers/media/platform/chips-media/wave5/
a firmware located in
${YOUR_PATH}/ti-aosp-15/vendor/ti/vendor/ti/am62x/firmware/vendor/firmware/cnm/
The userspace associated component is based on the AOSP-provided v4l2_codec2
HAL.
The source can be found in ${YOUR_PATH}/ti-aosp-15/external/v4l2_codec2
.
Testing
Using atest
Android provides all kind of tests to test the media framework.
We can run a sample playback via atest
from a development tree.
# Standard Android build commands
$ cd ${YOUR_PATH}/ti-aosp-15
$ source build/envsetup.sh
$ lunch am62p-ap4a-userdebug
# install the required media files, downloads from network
$ cts/tests/tests/media/player/
$ ./copy_media.sh
$ cd -
# run the playback test
$ atest android.media.player.cts.MediaPlayerTest#testLocalVideo_MP4_H264_480x360_500kbps_25fps_AAC_Stereo_128kbps_44110Hz
Using Gallery
To play test videos, we can also use the Gallery app.
First, download the Big Buck Bunny test videos:
# 1080p, 60FPS, h264
$ wget http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4
# 4k, 30FPS, h264
$ wget http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_2160p_30fps_normal.mp4
Then, push them in the Movies
folder:
$ adb push bbb_sunflower_1080p_60fps_normal.mp4 /sdcard/Movies
$ adb push bbb_sunflower_2160p_30fps_normal.mp4 /sdcard/Movies
Finally, reboot the board
$ adb reboot
Then run the Gallery app from the UI and play the videos.
Using screenrecord
To test video encoding, we can use the screenrecord
command.
$ adb root
$ adb shell 'screenrecord /data/screenrecord.mp4' # Do some screen activity, then hit Ctrl-C
$ adb pull /data/screenrecord.mp4
Tip
screenrecord
only records frames when there is some user activity detected.
Make sure to generate some activity to avoid empty video files.
Using C2E2ETest.apk
v4l2_codec2
also comes with its own test suite.
Build and install it on the board with:
$ source build/envsetup.sh $ lunch am62p-ap4a-userdebug $ mmm external/v4l2_codec2/tests/c2_e2e_test $ adb install out/target/product/am62p/testcases/C2E2ETest/arm64/C2E2ETest.apk # Make sure to give the app storage permissions to read from /sdcard/Downloads $ adb shell pm grant org.chromium.c2.test android.permission.WRITE_EXTERNAL_STORAGE $ adb shell pm grant org.chromium.c2.test android.permission.READ_EXTERNAL_STORAGE
Install the test files on the board:
Download
the example file
and push it:$ adb push videotestsrc_720p.h264 /sdcard/Download/
Run it with:
$ INPUT=/sdcard/Download/videotestsrc_720p.h264:1280:720:200:258:::1:25 $ OUTPUT=/sdcard/Download/out.raw # Make sure previous instances are stopped $ adb shell am force-stop org.chromium.c2.test # Clear the logs $ adb shell rm /sdcard/Download/gtest_logs.txt # Run the test $ adb shell touch /sdcard/Download/gtest_logs.txt $ adb shell am start -n org.chromium.c2.test/.E2eTestActivity \ --ez do-encode false \ --es log-file "/sdcard/Download/gtest_logs.txt" \ --esa test-args "--test_video_data=$INPUT","--gtest_filter=C2VideoDecoderByteBufferE2ETest.TestSimpleDecode","--output_frames_path=$OUTPUT" # View the results $ adb shell cat /sdcard/Download/gtest_logs.txt
Tip
It’s possible to run the software decoder as well to compare. Pass
"--use_sw_decoder"
totest-args
:$ adb shell am start -n org.chromium.c2.test/.E2eTestActivity \ --ez do-encode false \ --es log-file "/sdcard/Download/gtest_logs.txt" \ --esa test-args "--test_video_data=$INPUT","--gtest_filter=C2VideoDecoderByteBufferE2ETest.TestSimpleDecode","--output_frames_path=$OUTPUT","--use_sw_decoder"
Then, it’s possible to analyze the result file with tools such as YUVView.
$ adb pull /sdcard/Download/out.raw
Warning
The per-frame md5 checksum feature is broken. To disable it in code, use the following diff:
diff --git a/tests/c2_e2e_test/jni/video_decoder_e2e_test.cpp b/tests/c2_e2e_test/jni/video_decoder_e2e_test.cpp
index 62589c2818a4..4df27e18e8ed 100644
--- a/tests/c2_e2e_test/jni/video_decoder_e2e_test.cpp
+++ b/tests/c2_e2e_test/jni/video_decoder_e2e_test.cpp
@@ -325,12 +328,14 @@ private:
TEST_F(C2VideoDecoderByteBufferE2ETest, TestSimpleDecode) {
VideoFrameValidator video_frame_validator;
+#if 0 // disable MD5 per-frame check, just dump output
ASSERT_TRUE(video_frame_validator.SetGoldenMD5File(g_env->GoldenMD5FilePath()))
<< "Failed to open MD5 file: " << g_env->GoldenMD5FilePath();
decoder_->AddOutputBufferReadyCb(std::bind(&VideoFrameValidator::VerifyMD5,
&video_frame_validator, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
+#endif
if (video_frame_validator.SetOutputFile(g_env->output_frames_path())) {
decoder_->AddOutputBufferReadyCb(std::bind(&VideoFrameValidator::OutputToFile,
Debugging tips
List available codecs
dumpsys
can be used to list the available codecs on an Android system.
To check that the v4l2 codecs are available, run:
$ adb shell dumpsys media.player | grep -A 10 v4l2
Decoder "c2.v4l2.avc.decoder" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "codec2::default"
rank: 128
profile/levels: [
1/65536 (Baseline/5.2),
--
Decoder "c2.v4l2.hevc.decoder" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "codec2::default"
rank: 128
profile/levels: [
1/524288 (Main/High 5.2),
--
Encoder "c2.v4l2.avc.encoder" supports
aliases: []
attributes: 0xb: [
encoder: 1,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "codec2::default"
rank: 128
profile/levels: [
1/32768 (Baseline/5.1),
Verbose logcat logging
The logs in logcat from v4l2_codec2
are not very verbose by default.
To enable more logs, v4l2_codec2
should be rebuild. It’s possible to enable all logs with:
$ cd ${YOUR_PATH}/ti-aosp-15/external/v4l2_codec2
$ sed -i 's#//\#define LOG_NDEBUG 0#\#define LOG_NDEBUG 0#' *.cpp