Linux/Kernel Driver

Multimedia 처리 드라이버 개발 및 Video Codec 드라이버 포팅 및 테스트

임베디드 친구 2025. 3. 31. 08:50
728x90
반응형

Multimedia 처리 드라이버 개발 및 Video Codec 드라이버 포팅 및 테스트

소프트웨어 공장에서는 오늘 Rockchip RK3399 시스템을 기반으로 Multimedia 처리 드라이버를 개발하고 Video Codec 드라이버를 포팅 및 테스트하는 방법을 소개합니다. 이 글은 임베디드 리눅스 개발자들이 실제 시스템에서 동작하는 드라이버를 작성하고 문제를 해결할 수 있도록 돕는 실용적인 가이드입니다.

1. Rockchip RK3399 개요

RK3399는 Rockchip에서 개발한 고성능 SoC(System on Chip)로, 다양한 멀티미디어 기능을 지원합니다. 주요 특징은 다음과 같습니다:

  • Dual Cortex-A72 + Quad Cortex-A53 Big.LITTLE 구조
  • Mali-T860MP4 GPU
  • 4K H.265/H.264 디코딩 및 1080p 인코딩 지원
  • VPU(Video Processing Unit) 포함

이 가이드는 VPU를 활용하여 Video Codec 드라이버를 포팅하고 테스트하는 과정을 다룹니다.

2. Multimedia 처리 드라이버 개발 과정

2.1 드라이버 개발 환경 준비

먼저 드라이버 개발을 위해 Linux Kernel 소스 코드와 Cross-Compiler가 필요합니다.

필수 도구 설치

sudo apt update
sudo apt install gcc-aarch64-linux-gnu make git build-essential

RK3399용 Kernel 소스 다운로드

git clone https://github.com/rockchip-linux/kernel.git -b stable-4.4
cd kernel
make ARCH=arm64 rockchip_defconfig

2.2 VPU 드라이버 코드 작성

VPU(Video Processing Unit) 드라이버는 /dev 인터페이스를 통해 사용자 애플리케이션과 상호 작용합니다. 아래는 간단한 VPU 드라이버 예제입니다.
Rockchip 커널 드라이버 소스와 차이가 있을 수 있으니, 실제 환경에 맞는 커널 소스를 확인하세요.

VPU 드라이버 코드 예제

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/cdev.h>

#define DEVICE_NAME "rk3399_vpu"

static int vpu_open(struct inode *inode, struct file *file) {
    printk(KERN_INFO "VPU: Device opened\n");
    return 0;
}

static int vpu_release(struct inode *inode, struct file *file) {
    printk(KERN_INFO "VPU: Device closed\n");
    return 0;
}

static ssize_t vpu_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) {
    char *message = "VPU: Hello from RK3399!\n";
    size_t len = strlen(message);

    if (*ppos >= len) return 0;
    if (count > len - *ppos) count = len - *ppos;

    if (copy_to_user(buf, message + *ppos, count)) return -EFAULT;

    *ppos += count;
    return count;
}

static struct file_operations fops = {
    .open = vpu_open,
    .release = vpu_release,
    .read = vpu_read,
};

static struct cdev vpu_cdev;
static int __init vpu_init(void) {
    int ret;
    dev_t dev;

    ret = alloc_chrdev_region(&dev, 0, 1, DEVICE_NAME);
    if (ret) {
        printk(KERN_ERR "Failed to allocate char device region\n");
        return ret;
    }

    cdev_init(&vpu_cdev, &fops);
    vpu_cdev.owner = THIS_MODULE;
    ret = cdev_add(&vpu_cdev, dev, 1);
    if (ret) {
        printk(KERN_ERR "Failed to add cdev\n");
        unregister_chrdev_region(dev, 1);
        return ret;
    }

    printk(KERN_INFO "VPU: Driver initialized\n");
    return 0;
}

static void __exit vpu_exit(void) {
    cdev_del(&vpu_cdev);
    unregister_chrdev_region(vpu_cdev.dev, 1);
    printk(KERN_INFO "VPU: Driver removed\n");
}

module_init(vpu_init);
module_exit(vpu_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("소프트웨어 공장");
MODULE_DESCRIPTION("RK3399 VPU Driver Example");

2.3 드라이버 컴파일 및 로드

컴파일

위 코드를 vpu_driver.c로 저장한 후 컴파일합니다.

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C /path/to/kernel M=$(pwd) modules

드라이버 로드

insmod vpu_driver.ko

확인

dmesg | grep VPU

3. Video Codec 드라이버 포팅 및 테스트

3.1 기존 드라이버 확인

RK3399 SDK에는 기본 Video Codec 드라이버가 포함되어 있습니다. 이를 수정하거나 포팅해야 합니다.

Video Codec 드라이버 경로

drivers/media/platform/rockchip/

3.2 테스트를 위한 유저 애플리케이션 작성

아래는 /dev/rk3399_vpu 디바이스와 통신하는 간단한 사용자 애플리케이션입니다.

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
    int fd = open("/dev/rk3399_vpu", O_RDONLY);
    if (fd < 0) {
        perror("Failed to open device");
        return 1;
    }

    char buffer[128];
    ssize_t bytes = read(fd, buffer, sizeof(buffer) - 1);
    if (bytes < 0) {
        perror("Failed to read from device");
        close(fd);
        return 1;
    }

    buffer[bytes] = '\0';
    printf("Device says: %s\n", buffer);

    close(fd);
    return 0;
}

3.3 테스트

  1. 드라이버를 로드합니다.

    insmod vpu_driver.ko
  2. 사용자 애플리케이션을 실행하여 디바이스 동작을 확인합니다.

    gcc user_app.c -o user_app
    ./user_app

4. 마무리

이 글에서는 RK3399 기반 Multimedia 처리 드라이버를 개발하고 Video Codec 드라이버를 포팅 및 테스트하는 과정을 설명했습니다.

반응형