luckfox-pico-sdk/sysdrv/source/mcu/rt-thread/components/aupipe/basics/filesink.c
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

185 lines
4.0 KiB
C

/**
* Copyright (c) 2023 Rockchip Electronics Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************
* @file filesink.c
* @author Jun Zeng
* @version V0.1
* @date 10-03-2023
* @brief filesink for rksoc
*
******************************************************************************
*/
#include "aupipe.h"
#ifdef RT_USING_AUPIPE_FILESINK
#include "drv_heap.h"
#include "rk_audio.h"
#undef DBG_SECTION_NAME
#define DBG_SECTION_NAME "FILESINK"
#define FILESINK(obj) ((ApFileSink *)(obj))
typedef struct filesink_object
{
ApObject base;
ApPad *sink_pad;
int channels;
int bit_width;
int period_byte;
int sinkpad_map;
FILE *fp;
char *buffer;
rt_thread_t loop;
} ApFileSink;
static int filesink_process(ApPad *pad, ApBuffer *buffer);
static int filesink_init(ApObject *obj, void *arg)
{
ApFileSink *object = FILESINK(obj);
int status = 0;
char *filename = NULL;
char *parameters = (char *)arg;
Aupipe *aupipe = object->base.parent;
status |= aupipe_find_property(parameters, "filename",
VALUE_TYPE_STRING, &filename);
status |= aupipe_find_property(parameters, "channels",
VALUE_TYPE_INT, &object->channels);
if (status != RT_EOK)
{
LOG_E("%s plug-in parameter initialization failed", object->base.name);
return -RT_ERROR;
}
object->bit_width = aupipe->bits >> 3;
object->sinkpad_map = (1 << object->channels) - 1;
object->fp = fopen(filename, "wb");
if (!object->fp)
{
rt_kprintf("Unable to open file %s\n", filename);
return RT_EOK;
}
object->period_byte = aupipe->period_size * object->channels * object->bit_width;
object->buffer = rt_malloc(object->period_byte);
if (object->buffer == NULL)
{
LOG_E("%s malloc %d failed", object->base.name, object->period_byte);
return -RT_ERROR;
}
object->sink_pad = aupipe_pad_new(obj, object->channels);
RT_ASSERT(object->sink_pad != NULL);
for (int i = 0; i < object->channels; i++)
{
object->sink_pad[i].process = filesink_process;
}
return RT_EOK;
}
static int filesink_deinit(ApObject *obj)
{
ApFileSink *object = FILESINK(obj);
fclose(object->fp);
rt_free(object->buffer);
rt_free(object->sink_pad);
return RT_EOK;
}
static int filesink_process(ApPad *pad, ApBuffer *buffer)
{
ApFileSink *obj = FILESINK(pad->parent);
int status = RT_EOK;
short *out = (short *)obj->buffer;
Aupipe *aupipe = obj->base.parent;
if (buffer->type != DATA_TYPE_AUDIO)
{
aupipe_buffer_unref(buffer);
return -RT_ERROR;
}
for (int i = 0; i < aupipe->period_size; i++)
{
rt_memcpy(obj->buffer + (obj->channels * i + pad->id) * obj->bit_width,
buffer->data + obj->bit_width * i, obj->bit_width);
}
aupipe_buffer_unref(buffer);
obj->sinkpad_map &= ~(1 << pad->id);
if (obj->sinkpad_map == 0)
{
obj->sinkpad_map = (1 << obj->channels) - 1;
}
else
{
return status;
}
fwrite(obj->buffer, obj->period_byte, 1, obj->fp);
return status;
}
static int filesink_set_state(ApObject *obj, int state)
{
ApFileSink *object = FILESINK(obj);
switch (state)
{
case STATE_NULL_TO_READY:
LOG_I("STATE_NULL_TO_READY");
break;
case STATE_READY_TO_NULL:
LOG_I("STATE_READY_TO_NULL");
break;
default:
break;
}
return RT_EOK;
}
static int filesink_set_property(ApObject *obj, char *name, void *arg)
{
return RT_EOK;
}
static int filesink_get_property(ApObject *obj, char *name, void *arg)
{
return RT_EOK;
}
static ApPad *filesink_get_pad(ApObject *obj, int type, int id)
{
ApFileSink *object = FILESINK(obj);
if (type == PAD_TYPE_SRC)
return NULL;
return &object->sink_pad[id];
}
OBJECT_BASE_DEFINE(filesink, ApFileSink);
#endif