pure sdk for main
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#include "sys_config.h"
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "osal/string.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal_file.h"
|
||||
#include "lib/ota/fw.h"
|
||||
#include "tx_platform.h"
|
||||
#include "dev/csi/hgdvp.h"
|
||||
|
||||
#define SD_CACHE_SIZE (4*1024)
|
||||
int32 demo_atcmd_sd_ota(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if(argc < 1)
|
||||
{
|
||||
os_printf("argv is too less\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if DVP_EN
|
||||
//dvp_close();
|
||||
void *dvp = (void *)dev_get(HG_DVP_DEVID);
|
||||
if(dvp)
|
||||
{
|
||||
dvp_close(dvp);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t *cache_buf = NULL;
|
||||
const char *sd_ota_filename = argv[0];
|
||||
void *fp = osal_fopen(sd_ota_filename,"r");
|
||||
if(!fp)
|
||||
{
|
||||
os_printf("%s file not exist\n",sd_ota_filename);
|
||||
goto demo_atcmd_sd_ota_end;
|
||||
}
|
||||
uint32_t filesize = osal_fsize(fp);
|
||||
uint32_t filesize_tmp = filesize;
|
||||
uint32_t readsize = SD_CACHE_SIZE;
|
||||
uint32_t ota_offset = 0;
|
||||
cache_buf = (uint8_t*)os_malloc(SD_CACHE_SIZE);
|
||||
if(!cache_buf)
|
||||
{
|
||||
goto demo_atcmd_sd_ota_end;
|
||||
}
|
||||
os_printf("filesize:%d\t%X\n",filesize,cache_buf);
|
||||
|
||||
|
||||
while(filesize)
|
||||
{
|
||||
if(filesize < SD_CACHE_SIZE)
|
||||
{
|
||||
readsize = filesize;
|
||||
}
|
||||
|
||||
osal_fread(cache_buf,readsize,1,fp);
|
||||
libota_write_fw(filesize_tmp,ota_offset,cache_buf,readsize);
|
||||
filesize -= readsize;
|
||||
ota_offset += readsize;
|
||||
}
|
||||
|
||||
|
||||
demo_atcmd_sd_ota_end:
|
||||
if(fp)
|
||||
{
|
||||
osal_fclose(fp);
|
||||
}
|
||||
|
||||
if(cache_buf)
|
||||
{
|
||||
os_free(cache_buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/***************************************************
|
||||
该demo主要是使用AT命令控制播放音频,录制格式为WAV
|
||||
AT命令格式:AT+PLAY_AUDIO=xxx.wav,mode
|
||||
***************************************************/
|
||||
#include "sys_config.h"
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "osal/task.h"
|
||||
#include "osal/string.h"
|
||||
#include "hal/audac.h"
|
||||
#include "stream_frame.h"
|
||||
#include "osal_file.h"
|
||||
#include "custom_mem/custom_mem.h"
|
||||
|
||||
|
||||
#ifdef PSRAM_HEAP
|
||||
#define PLAY_AUDIO_MALLOC custom_malloc_psram
|
||||
#define PLAY_AUDIO_FREE custom_free_psram
|
||||
#else
|
||||
#define PLAY_AUDIO_MALLOC custom_malloc
|
||||
#define PLAY_AUDIO_FREE custom_free
|
||||
#endif
|
||||
|
||||
|
||||
extern int get_audio_dac_set_filter_type(void);
|
||||
extern void audio_dac_set_filter_type(int filter_type);
|
||||
extern int audio_dac_get_samplingrate(void);
|
||||
extern void audio_da_recfg(uint32_t hz);
|
||||
#define AUDIO_LEN (1024)
|
||||
char audio_filePath[10];
|
||||
void *audio_fp = NULL;
|
||||
|
||||
typedef struct _riff_chunk {
|
||||
uint8 ChunkID[4];
|
||||
uint32 ChunkSize;
|
||||
uint8 Format[4];
|
||||
} TYPE_RIFF_CHUNK;
|
||||
typedef struct _fmt_chunk {
|
||||
uint8 FmtID[4];
|
||||
uint32 FmtSize;
|
||||
uint16 FmtTag;
|
||||
uint16 FmtChannels;
|
||||
uint32 SampleRate;
|
||||
uint32 ByteRate;
|
||||
uint16 BlockAlign;
|
||||
uint16 BitsPerSample;
|
||||
} TYPE_FMT_CHUNK;
|
||||
typedef struct _data_chunk {
|
||||
uint8 DataID[4];
|
||||
uint32 DataSize;
|
||||
} TYPE_DATA_CHUNK;
|
||||
typedef struct _wave_head {
|
||||
TYPE_RIFF_CHUNK riff_chunk;
|
||||
TYPE_FMT_CHUNK fmt_chunk;
|
||||
TYPE_DATA_CHUNK data_chunk;
|
||||
} TYPE_WAVE_HEAD;
|
||||
|
||||
TYPE_WAVE_HEAD *wave_head = NULL;
|
||||
uint32 audio_data_len;
|
||||
static uint8_t play_mode = 0;
|
||||
static uint8_t play_status = 0;
|
||||
stream *wave_src = NULL;
|
||||
struct os_task at_play_audio_task;
|
||||
|
||||
|
||||
|
||||
static uint32_t get_sound_data_len(void *data)
|
||||
{
|
||||
struct data_structure *d = (struct data_structure *)data;
|
||||
return (uint32_t)d->priv;
|
||||
}
|
||||
static uint32_t set_sound_data_len(void *data,uint32_t len)
|
||||
{
|
||||
struct data_structure *d = (struct data_structure *)data;
|
||||
d->priv = (void*)len;
|
||||
return (uint32_t)len;
|
||||
}
|
||||
static const stream_ops_func stream_sound_ops =
|
||||
{
|
||||
.get_data_len = get_sound_data_len,
|
||||
.set_data_len = set_sound_data_len,
|
||||
};
|
||||
static uint8_t get_play_status(void)
|
||||
{
|
||||
return play_status;
|
||||
}
|
||||
static void set_play_status(uint8_t sta)
|
||||
{
|
||||
play_status = sta;
|
||||
}
|
||||
int at_play_audio_thread(void *d);
|
||||
int32 demon_atcmd_play_audio(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
os_printf("%s argc too small:%d,enter the path and mode\n",__FUNCTION__,argc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argv[0])
|
||||
{
|
||||
memset(audio_filePath,0,sizeof(audio_filePath));
|
||||
memcpy(audio_filePath,argv[0],strlen(argv[0]));
|
||||
os_printf("audio path:%s\n",audio_filePath);
|
||||
play_mode = os_atoi(argv[1]);
|
||||
|
||||
if(get_play_status() == 1)
|
||||
{
|
||||
set_play_status(0);
|
||||
while(wave_src != NULL)
|
||||
os_sleep_ms(100);
|
||||
}
|
||||
if((play_mode == 1) || (play_mode == 2)) {
|
||||
audio_fp = osal_fopen(audio_filePath,"rb");
|
||||
if(!audio_fp)
|
||||
{
|
||||
os_printf("\nopen audio file err");
|
||||
return 0;
|
||||
}
|
||||
if(wave_head == NULL)
|
||||
wave_head = (TYPE_WAVE_HEAD*)PLAY_AUDIO_MALLOC(sizeof(TYPE_WAVE_HEAD));
|
||||
else
|
||||
os_memset(wave_head, 0, sizeof(TYPE_WAVE_HEAD));
|
||||
if(!wave_head)
|
||||
return 0;
|
||||
osal_fread(wave_head,1,sizeof(TYPE_WAVE_HEAD),audio_fp);
|
||||
audio_data_len = wave_head->data_chunk.DataSize;
|
||||
|
||||
os_printf("SampleRate:%d FmtChannels:%d BitsPerSample:%d data_len:%d\r\n",
|
||||
wave_head->fmt_chunk.SampleRate,wave_head->fmt_chunk.FmtChannels,wave_head->fmt_chunk.BitsPerSample,audio_data_len);
|
||||
set_play_status(1);
|
||||
OS_TASK_INIT("at_play_audio", &at_play_audio_task, at_play_audio_thread, (void*)audio_fp, OS_TASK_PRIORITY_NORMAL, 1024);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int opcode_func(stream *s,void *priv,int opcode)
|
||||
{
|
||||
static uint8_t *audio_buf = NULL;
|
||||
int res = 0;
|
||||
switch(opcode)
|
||||
{
|
||||
case STREAM_OPEN_ENTER:
|
||||
break;
|
||||
case STREAM_OPEN_EXIT:
|
||||
{
|
||||
audio_buf = PLAY_AUDIO_MALLOC(4 * AUDIO_LEN);
|
||||
if(audio_buf)
|
||||
{
|
||||
os_printf("at audio malloc:%x\n",audio_buf);
|
||||
stream_data_dis_mem(s,4);
|
||||
}
|
||||
streamSrc_bind_streamDest(s,R_SPEAKER);
|
||||
}
|
||||
break;
|
||||
case STREAM_OPEN_FAIL:
|
||||
break;
|
||||
|
||||
case STREAM_FILTER_DATA:
|
||||
break;
|
||||
|
||||
case STREAM_DATA_DIS:
|
||||
{
|
||||
struct data_structure *data = (struct data_structure *)priv;
|
||||
int data_num = (int)data->priv;
|
||||
data->ops = (stream_ops_func*)&stream_sound_ops;
|
||||
data->data = audio_buf + (data_num)*AUDIO_LEN;
|
||||
}
|
||||
break;
|
||||
|
||||
case STREAM_DATA_DESTORY:
|
||||
{
|
||||
if(audio_buf) {
|
||||
os_printf("at audio free:%x\n",audio_buf);
|
||||
PLAY_AUDIO_FREE(audio_buf);
|
||||
audio_buf = NULL;
|
||||
}
|
||||
}
|
||||
case STREAM_DATA_FREE:
|
||||
//_os_printf("%s:%d\n",__FUNCTION__,__LINE__);
|
||||
break;
|
||||
|
||||
|
||||
//数据发送完成,可以选择唤醒对应的任务
|
||||
case STREAM_RECV_DATA_FINISH:
|
||||
break;
|
||||
|
||||
default:
|
||||
//默认都返回成功
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int16_t *wav_buf = NULL;
|
||||
int at_play_audio_thread(void *d)
|
||||
{
|
||||
int readLen = 0;
|
||||
int audio_len = 0;
|
||||
uint32 read_total_len = 0;
|
||||
struct data_structure *data = NULL;
|
||||
int32_t audio_temp = 0;
|
||||
int former_dac_priv = 0;
|
||||
int former_dac_samplingrate = 0;
|
||||
|
||||
//struct audac_device *volume_dev = (struct audac_device *)dev_get(HG_AUDAC_DEVID);
|
||||
|
||||
FIL *fp = (FIL*)d;
|
||||
stream *wave_src = open_stream_available("file_audio", 4, 0, opcode_func,NULL);
|
||||
|
||||
if(!wave_src)
|
||||
{
|
||||
osal_fclose(fp);
|
||||
PLAY_AUDIO_FREE(wave_head);
|
||||
os_printf("\nopen stream err");
|
||||
return 0;
|
||||
}
|
||||
former_dac_priv = get_audio_dac_set_filter_type();
|
||||
audio_dac_set_filter_type(SOUND_FILE);
|
||||
former_dac_samplingrate = audio_dac_get_samplingrate();
|
||||
if(former_dac_samplingrate != wave_head->fmt_chunk.SampleRate)
|
||||
broadcast_cmd_to_destStream(wave_src,SET_CMD_TYPE(CMD_AUDIO_DAC_MODIFY_HZ,wave_head->fmt_chunk.SampleRate));
|
||||
if(wave_head->fmt_chunk.BitsPerSample == 24) {
|
||||
audio_len = AUDIO_LEN*8/24; //sample取整
|
||||
audio_len = audio_len*3/4; //sample取偶
|
||||
audio_len *= 4;
|
||||
}
|
||||
else if(wave_head->fmt_chunk.BitsPerSample == 16) {
|
||||
audio_len = AUDIO_LEN;
|
||||
}
|
||||
else if(wave_head->fmt_chunk.BitsPerSample == 8) {
|
||||
audio_len = AUDIO_LEN/2;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
if(get_play_status() == 0)
|
||||
break;
|
||||
data = get_src_data_f(wave_src);
|
||||
if(data)
|
||||
{
|
||||
wav_buf = get_stream_real_data(data);
|
||||
// os_printf("wb:%x\n",wav_buf);
|
||||
if((read_total_len+audio_len) > audio_data_len) {
|
||||
readLen = osal_fread((uint8_t*)wav_buf, 1, (audio_data_len-read_total_len), fp);
|
||||
}
|
||||
else
|
||||
readLen = osal_fread((uint8_t*)wav_buf, 1, audio_len, fp);
|
||||
if(readLen > 0) {
|
||||
read_total_len += readLen;
|
||||
data->type = SET_DATA_TYPE(SOUND, SOUND_FILE);
|
||||
if(wave_head->fmt_chunk.BitsPerSample == 24) {
|
||||
for(uint32_t i=0; i<(readLen/3); i++) {
|
||||
audio_temp = (int32_t)((*((uint8_t*)wav_buf+3*i))|(*((uint8_t*)wav_buf+3*i+1)<<8)|(*((uint8_t*)wav_buf+3*i+2))<<16)&0x00FFFFFF;
|
||||
// os_printf("former:%x %x %x %x ",(*((uint8_t*)wav_buf+3*i)),(*((uint8_t*)wav_buf+3*i+1)),(*((uint8_t*)wav_buf+3*i+2)),audio_temp);
|
||||
wav_buf[i] = audio_temp>>8;
|
||||
// printf("new:%x %d\n",(int16_t)wav_buf[i], read_total_len);
|
||||
}
|
||||
readLen = readLen*2/3;
|
||||
}
|
||||
else if(wave_head->fmt_chunk.BitsPerSample == 8) {
|
||||
os_memcpy(wav_buf+readLen/2, wav_buf, readLen);
|
||||
for(uint32_t i=0; i<readLen; i++) {
|
||||
wav_buf[i] = (int16_t)(*(((uint8_t*)wav_buf)+readLen+i)-128)<<8;
|
||||
}
|
||||
readLen = readLen*2;
|
||||
}
|
||||
|
||||
if(wave_head->fmt_chunk.FmtChannels == 1) {
|
||||
set_sound_data_len(data, readLen);
|
||||
send_data_to_stream(data);
|
||||
}
|
||||
else if(wave_head->fmt_chunk.FmtChannels == 2) {
|
||||
for(uint32_t i=0; i<(readLen/4); i++) {
|
||||
wav_buf[i] = ((wav_buf[2*i]+wav_buf[2*i+1])>>1);
|
||||
}
|
||||
readLen = readLen/2;
|
||||
set_sound_data_len(data, readLen);
|
||||
send_data_to_stream(data);
|
||||
}
|
||||
}
|
||||
else if(readLen <= 0 )
|
||||
{
|
||||
os_printf("\nread audio data err");
|
||||
break;
|
||||
}
|
||||
if(read_total_len >= audio_data_len) {
|
||||
if(play_mode == 1)
|
||||
break;
|
||||
else if(play_mode == 2) {
|
||||
read_total_len = 0;
|
||||
osal_fseek(fp, sizeof(TYPE_WAVE_HEAD));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
os_sleep_ms(1);
|
||||
}
|
||||
|
||||
audio_dac_set_filter_type(former_dac_priv);
|
||||
osal_fclose(fp);
|
||||
if(former_dac_samplingrate != audio_dac_get_samplingrate())
|
||||
audio_da_recfg(former_dac_samplingrate);
|
||||
os_printf("\nplay wav end");
|
||||
close_stream(wave_src);
|
||||
wave_src = NULL;
|
||||
if(wave_head) {
|
||||
PLAY_AUDIO_FREE(wave_head);
|
||||
wave_head = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "sys_config.h"
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "string.h"
|
||||
#include "osal_file.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal/string.h"
|
||||
#include "mp3_decode.h"
|
||||
|
||||
static uint8_t play_mode = 0;
|
||||
char audio_filePath[10];
|
||||
|
||||
int32 demon_atcmd_play_mp3(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
os_printf("%s argc too small:%d,enter the path and mode\n",__FUNCTION__,argc);
|
||||
return 0;
|
||||
}
|
||||
if(argv[0])
|
||||
{
|
||||
memset(audio_filePath,0,sizeof(audio_filePath));
|
||||
memcpy(audio_filePath,argv[0],strlen(argv[0]));
|
||||
play_mode = os_atoi(argv[1]);
|
||||
|
||||
if(play_mode == 0) {
|
||||
set_mp3_decode_status(MP3_STOP);
|
||||
}
|
||||
else if(play_mode == 1) {
|
||||
mp3_decode_init(audio_filePath, NULL);
|
||||
|
||||
}
|
||||
}
|
||||
os_printf("%s %s\n",__FUNCTION__,audio_filePath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
/***************************************************
|
||||
该demo主要是使用AT命令控制录制音频,录制格式为WAV
|
||||
***************************************************/
|
||||
#include "osal/string.h"
|
||||
#include "custom_mem/custom_mem.h"
|
||||
#include "stream_frame.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal_file.h"
|
||||
void at_save_audio_thread(void *d);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char chRIFF[4]; // "RIFF" 标志
|
||||
int total_Len; // 文件长度
|
||||
char chWAVE[4]; // "WAVE" 标志
|
||||
char chFMT[4]; // "fmt" 标志
|
||||
int dwFMTLen; // 过渡字节(不定) 一般为16
|
||||
short fmt_pcm; // 格式类别
|
||||
short channels; // 声道数
|
||||
int fmt_samplehz; // 采样率
|
||||
int fmt_bytepsec; // 位速
|
||||
short fmt_bytesample; // 一个采样多声道数据块大小
|
||||
short fmt_bitpsample; // 一个采样占的 bit 数
|
||||
char chDATA[4]; // 数据标记符"data "
|
||||
int dwDATALen; // 语音数据的长度,比文件长度小42一般。这个是计算音频播放时长的关键参数~
|
||||
}WaveHeader;
|
||||
|
||||
|
||||
const unsigned char wav_header[] = {
|
||||
'R', 'I', 'F', 'F', // "RIFF" 标志
|
||||
0, 0, 0, 0, // 文件长度
|
||||
'W', 'A', 'V', 'E', // "WAVE" 标志
|
||||
'f', 'm', 't', ' ', // "fmt" 标志
|
||||
16, 0, 0, 0, // 过渡字节(不定)
|
||||
0x01, 0x00, // 格式类别
|
||||
0x01, 0x00, // 声道数
|
||||
0, 0, 0, 0, // 采样率
|
||||
0, 0, 0, 0, // 位速
|
||||
0x01, 0x00, // 一个采样多声道数据块大小
|
||||
0x10, 0x00, // 一个采样占的 bit 数
|
||||
'd', 'a', 't', 'a', // 数据标记符"data "
|
||||
0, 0, 0, 0 // 语音数据的长度,比文件长度小42一般。这个是计算音频播放时长的关键参数~
|
||||
};
|
||||
|
||||
struct AT_AUDIO
|
||||
{
|
||||
uint32_t frq;
|
||||
struct os_task task;
|
||||
uint8_t filename_prefix[4];
|
||||
uint8_t running;
|
||||
uint32_t minute;
|
||||
|
||||
};
|
||||
|
||||
static struct AT_AUDIO *audio_s = NULL;
|
||||
|
||||
int32 demo_atcmd_save_audio(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
os_printf("%s argc too small:%d,should more 2 arg\n",__FUNCTION__,argc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(os_atoi(argv[0]) == 1)
|
||||
{
|
||||
if(audio_s)
|
||||
{
|
||||
os_printf("%s already running\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_s = custom_malloc(sizeof(struct AT_AUDIO));
|
||||
|
||||
if(audio_s)
|
||||
{
|
||||
os_memset(audio_s,0,sizeof(struct AT_AUDIO));
|
||||
audio_s->frq = os_atoi(argv[1]);
|
||||
os_printf("frq:%d\n",audio_s->frq);
|
||||
if(argc > 2)
|
||||
{
|
||||
audio_s->minute = os_atoi(argv[2]) ;
|
||||
if(audio_s->minute == 0)
|
||||
{
|
||||
audio_s->minute = ~0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_s->minute = ~0;
|
||||
}
|
||||
if(argc > 3)
|
||||
{
|
||||
int prefix_len = strlen(argv[3]);
|
||||
if(prefix_len > 3)
|
||||
{
|
||||
os_memcpy(audio_s->filename_prefix,argv[3],3);
|
||||
}
|
||||
else
|
||||
{
|
||||
os_memcpy(audio_s->filename_prefix,argv[3],prefix_len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
os_memcpy(audio_s->filename_prefix,"def",3);
|
||||
}
|
||||
//创建录音频的任务
|
||||
OS_TASK_INIT("at_audio", &audio_s->task, at_save_audio_thread, (uint32)audio_s, OS_TASK_PRIORITY_NORMAL, 1024);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(os_atoi(argv[0]) == 0)
|
||||
{
|
||||
if(!audio_s)
|
||||
{
|
||||
os_printf("%s not running\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//设置停止标志位
|
||||
audio_s->running = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int opcode_func(stream *s,void *priv,int opcode)
|
||||
{
|
||||
int res = 0;
|
||||
//_os_printf("%s:%d\topcode:%d\n",__FUNCTION__,__LINE__,opcode);
|
||||
switch(opcode)
|
||||
{
|
||||
case STREAM_OPEN_ENTER:
|
||||
break;
|
||||
case STREAM_OPEN_EXIT:
|
||||
{
|
||||
enable_stream(s,1);
|
||||
}
|
||||
break;
|
||||
case STREAM_OPEN_FAIL:
|
||||
break;
|
||||
default:
|
||||
//默认都返回成功
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void at_save_audio_thread(void *d)
|
||||
{
|
||||
struct AT_AUDIO *a_s = (struct AT_AUDIO *)d;
|
||||
WaveHeader header;
|
||||
os_memcpy(&header,wav_header,sizeof(WaveHeader));
|
||||
header.fmt_samplehz = a_s->frq;
|
||||
header.fmt_bytepsec = a_s->frq*2;
|
||||
|
||||
char filename[64] = {0};
|
||||
a_s->running = 1;
|
||||
uint32_t count = 0;
|
||||
int w_len = 0;
|
||||
uint32_t flen;
|
||||
uint32_t w_count = 0;
|
||||
uint8_t *buf;
|
||||
void *fp = NULL;
|
||||
struct data_structure *get_f = NULL;
|
||||
stream* s = NULL;
|
||||
uint32_t start_time = 0;
|
||||
s = open_stream_available(R_AT_SAVE_AUDIO,0,8,opcode_func,NULL);
|
||||
if(!s)
|
||||
{
|
||||
goto at_save_audio_thread_end;
|
||||
}
|
||||
|
||||
os_printf("prefix:%s\n",a_s->filename_prefix);
|
||||
os_sprintf(filename,"0:audio/%s_%04d.wav",a_s->filename_prefix,(uint32_t)os_jiffies()%9999);
|
||||
os_printf("record name:%s\n",filename);
|
||||
fp = osal_fopen(filename,"wb+");
|
||||
if(!fp)
|
||||
{
|
||||
goto at_save_audio_thread_end;
|
||||
}
|
||||
//偏移头部信息
|
||||
osal_fseek(fp,sizeof(WaveHeader));
|
||||
start_time = os_jiffies();
|
||||
while(a_s->running && (os_jiffies()-start_time)/1000 < a_s->minute*60)
|
||||
{
|
||||
count++;
|
||||
if(count % 1000 == 0)
|
||||
{
|
||||
os_printf("%s:%d\t%d\trecord time:%d\n",__FUNCTION__,__LINE__,w_count,os_jiffies()-start_time);
|
||||
}
|
||||
get_f = recv_real_data(s);
|
||||
if(get_f)
|
||||
{
|
||||
buf = get_stream_real_data(get_f);
|
||||
flen = get_stream_real_data_len(get_f);
|
||||
w_len = osal_fwrite(buf, flen, 1, fp);
|
||||
free_data(get_f);
|
||||
get_f = NULL;
|
||||
if(w_len <= 0)
|
||||
{
|
||||
goto at_save_audio_thread_end;
|
||||
}
|
||||
w_count += w_len;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
os_sleep_ms(1);
|
||||
}
|
||||
|
||||
}
|
||||
at_save_audio_thread_end:
|
||||
header.dwDATALen = w_count;
|
||||
header.total_Len = w_count + sizeof(WaveHeader) - 8;
|
||||
|
||||
|
||||
os_printf("%s end!!!!!!!!!!!!!\n",__FUNCTION__);
|
||||
os_printf("start_time:%d\tend_time:%d\n",start_time,os_jiffies());
|
||||
if(fp)
|
||||
{
|
||||
osal_fseek(fp,0);
|
||||
osal_fwrite(&header, sizeof(header), 1, fp);
|
||||
osal_fclose(fp);
|
||||
}
|
||||
if(s)
|
||||
{
|
||||
close_stream(s);
|
||||
}
|
||||
a_s->running = 0;
|
||||
custom_free((void*)a_s);
|
||||
audio_s = NULL;
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/***************************************************
|
||||
该demo主要是录制AVI使用
|
||||
***************************************************/
|
||||
#include "osal/string.h"
|
||||
#include "custom_mem/custom_mem.h"
|
||||
#include "stream_frame.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal_file.h"
|
||||
#include "video_app/video_app.h"
|
||||
struct AT_AVI
|
||||
{
|
||||
struct os_task task;
|
||||
uint32_t fps;
|
||||
uint32_t frq;
|
||||
int running;
|
||||
uint8_t record_num;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern void at_save_avi_thread(void *d);
|
||||
static struct AT_AVI *avi_s = NULL;
|
||||
int32 demo_atcmd_save_avi(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
#if OPENDML_EN && SDH_EN && FS_EN
|
||||
if(argc < 3)
|
||||
{
|
||||
os_printf("%s argc too small:%d,should more 2 arg\n",__FUNCTION__,argc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(os_atoi(argv[0]) == 0)
|
||||
{
|
||||
os_printf("avi_s:%X\n",avi_s);
|
||||
if(avi_s)
|
||||
{
|
||||
avi_s->running = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_printf("%s not running\n",__FUNCTION__);
|
||||
}
|
||||
}
|
||||
else if(os_atoi(argv[0]) == 1)
|
||||
{
|
||||
avi_s = custom_malloc(sizeof(struct AT_AVI));
|
||||
if(avi_s)
|
||||
{
|
||||
os_memset(avi_s,0,sizeof(struct AT_AVI));
|
||||
avi_s->fps = os_atoi(argv[1]);
|
||||
avi_s->frq = os_atoi(argv[2]);
|
||||
if(argc > 3)
|
||||
{
|
||||
avi_s->record_num = os_atoi(argv[3]);
|
||||
}
|
||||
|
||||
if(avi_s->record_num == 0)
|
||||
{
|
||||
avi_s->record_num = 1;
|
||||
}
|
||||
os_printf("fps:%d\tfrq:%d\n",avi_s->fps,avi_s->frq);
|
||||
OS_TASK_INIT("at_avi", &avi_s->task, at_save_avi_thread, (uint32)avi_s, OS_TASK_PRIORITY_NORMAL, 1024);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int opcode_func(stream *s,void *priv,int opcode)
|
||||
{
|
||||
int res = 0;
|
||||
//_os_printf("%s:%d\topcode:%d\n",__FUNCTION__,__LINE__,opcode);
|
||||
switch(opcode)
|
||||
{
|
||||
case STREAM_OPEN_ENTER:
|
||||
break;
|
||||
case STREAM_OPEN_EXIT:
|
||||
{
|
||||
enable_stream(s,1);
|
||||
}
|
||||
break;
|
||||
case STREAM_OPEN_FAIL:
|
||||
break;
|
||||
default:
|
||||
//默认都返回成功
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
extern int new_sd_save_avi2(int *exit_flag,stream *s,stream *audio_s,int fps,int audiofrq,int settime,int pic_w,int pic_h);
|
||||
void at_save_avi_thread(void *d)
|
||||
{
|
||||
struct AT_AVI *func_avi_s = (struct AT_AVI *)d;
|
||||
stream *video_s = NULL;
|
||||
stream *audio_s = NULL;
|
||||
video_s = open_stream_available(R_AT_AVI_JPEG,0,8,opcode_func,NULL);
|
||||
if(!video_s)
|
||||
{
|
||||
goto at_save_avi_thread_end;
|
||||
}
|
||||
|
||||
if(func_avi_s->frq)
|
||||
{
|
||||
audio_s = open_stream(R_AT_AVI_AUDIO,0,8,opcode_func,NULL);
|
||||
}
|
||||
|
||||
jpeg_stream_init();
|
||||
|
||||
func_avi_s->running = 1;
|
||||
os_printf("video_s:%X\taudio_s:%X\n",video_s,audio_s);
|
||||
while(func_avi_s->running && func_avi_s->record_num)
|
||||
{
|
||||
if(video_s)
|
||||
{
|
||||
enable_stream(video_s,1);
|
||||
}
|
||||
|
||||
if(audio_s)
|
||||
{
|
||||
enable_stream(audio_s,1);
|
||||
}
|
||||
new_sd_save_avi2(&func_avi_s->running,video_s,audio_s,func_avi_s->fps,func_avi_s->frq,60*1,640,480);
|
||||
func_avi_s->record_num--;
|
||||
}
|
||||
|
||||
|
||||
at_save_avi_thread_end:
|
||||
|
||||
if(video_s)
|
||||
{
|
||||
jpeg_stream_deinit();
|
||||
close_stream(video_s);
|
||||
}
|
||||
|
||||
if(audio_s)
|
||||
{
|
||||
close_stream(audio_s);
|
||||
}
|
||||
func_avi_s->running = 0;
|
||||
custom_free((void*)func_avi_s);
|
||||
avi_s = NULL;
|
||||
os_printf("%s end\n",__FUNCTION__,__LINE__);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/***************************************************
|
||||
该demo主要是使用AT命令拍一张照片,前提要将jpeg打开
|
||||
***************************************************/
|
||||
#include "osal/string.h"
|
||||
#include "custom_mem/custom_mem.h"
|
||||
#include "stream_frame.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal_file.h"
|
||||
#include "video_app/video_app.h"
|
||||
|
||||
void at_save_photo_thread(void *d);
|
||||
struct AT_PHOTO
|
||||
{
|
||||
struct os_task task;
|
||||
uint32_t photo_num;
|
||||
uint8_t filename_prefix[4];
|
||||
uint8_t running;
|
||||
|
||||
};
|
||||
|
||||
static struct AT_PHOTO *photo_s = NULL;
|
||||
int32 demo_atcmd_save_photo(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
#if OPENDML_EN && SDH_EN && FS_EN
|
||||
if(argc < 2)
|
||||
{
|
||||
os_printf("%s argc too small:%d,should more 2 arg\n",__FUNCTION__,argc);
|
||||
return 0;
|
||||
}
|
||||
if(os_atoi(argv[0]) == 0)
|
||||
{
|
||||
if(photo_s)
|
||||
{
|
||||
photo_s->running = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_printf("%s takephoto num err:%d\n",__FUNCTION__,os_atoi(argv[0]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
photo_s = custom_malloc(sizeof(struct AT_PHOTO));
|
||||
if(photo_s)
|
||||
{
|
||||
memset(photo_s,0,sizeof(struct AT_PHOTO));
|
||||
//连续拍照多少张
|
||||
photo_s->photo_num = os_atoi(argv[0]);
|
||||
int prefix_len = strlen(argv[1]);
|
||||
if(prefix_len > 3)
|
||||
{
|
||||
os_memcpy(photo_s->filename_prefix,argv[1],3);
|
||||
}
|
||||
else
|
||||
{
|
||||
os_memcpy(photo_s->filename_prefix,argv[1],prefix_len);
|
||||
}
|
||||
|
||||
//创建拍照的任务
|
||||
OS_TASK_INIT("at_photo", &photo_s->task, at_save_photo_thread, (uint32)photo_s, OS_TASK_PRIORITY_NORMAL, 1024);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int opcode_func(stream *s,void *priv,int opcode)
|
||||
{
|
||||
int res = 0;
|
||||
//_os_printf("%s:%d\topcode:%d\n",__FUNCTION__,__LINE__,opcode);
|
||||
switch(opcode)
|
||||
{
|
||||
case STREAM_OPEN_ENTER:
|
||||
break;
|
||||
case STREAM_OPEN_EXIT:
|
||||
{
|
||||
enable_stream(s,1);
|
||||
}
|
||||
break;
|
||||
case STREAM_OPEN_FAIL:
|
||||
break;
|
||||
default:
|
||||
//默认都返回成功
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
extern int no_frame_record_video2(void *fp,void *d,int flen);
|
||||
void at_save_photo_thread(void *d)
|
||||
{
|
||||
struct data_structure *get_f = NULL;
|
||||
struct AT_PHOTO *p_s = (struct AT_PHOTO *)d;
|
||||
stream *s = NULL;
|
||||
uint32_t flen;
|
||||
char filename[64] = {0};
|
||||
s = open_stream_available(R_AT_SAVE_PHOTO,0,8,opcode_func,NULL);
|
||||
if(!s)
|
||||
{
|
||||
goto at_save_photo_thread_end;
|
||||
}
|
||||
p_s->running = 1;
|
||||
void *fp = NULL;
|
||||
uint32_t err_count = 0;
|
||||
start_jpeg();
|
||||
while(p_s->photo_num && p_s->running)
|
||||
{
|
||||
get_f = recv_real_data(s);
|
||||
if(get_f)
|
||||
{
|
||||
err_count = 0;
|
||||
os_sprintf(filename,"0:photo/%s_%04d.jpg",p_s->filename_prefix,(uint32_t)os_jiffies()%9999);
|
||||
os_printf("filename:%s\n",filename);
|
||||
fp = osal_fopen(filename,"wb+");
|
||||
if(!fp)
|
||||
{
|
||||
goto at_save_photo_thread_end;
|
||||
}
|
||||
flen = get_stream_real_data_len(get_f);
|
||||
no_frame_record_video2(fp,get_f,flen);
|
||||
free_data(get_f);
|
||||
get_f = NULL;
|
||||
osal_fclose(fp);
|
||||
p_s->photo_num--;
|
||||
}
|
||||
else
|
||||
{
|
||||
err_count++;
|
||||
os_sleep_ms(1);
|
||||
if(err_count++ > 1000)
|
||||
{
|
||||
goto at_save_photo_thread_end;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
at_save_photo_thread_end:
|
||||
if(get_f)
|
||||
{
|
||||
free_data(get_f);
|
||||
get_f = NULL;
|
||||
}
|
||||
|
||||
if(s)
|
||||
{
|
||||
stop_jpeg();
|
||||
close_stream(s);
|
||||
}
|
||||
p_s->running = 0;
|
||||
custom_free((void*)p_s);
|
||||
photo_s = NULL;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef __TEST_DEMO_H
|
||||
#define __TEST_DEMO_H
|
||||
int32 demo_atcmd_save_audio(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demo_atcmd_save_photo(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demo_atcmd_save_avi(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demon_atcmd_play_audio(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demo_atcmd_sd_ota(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demo_atcmd_save_h264(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demo_atcmd_save_osd(const char *cmd, char *argv[], uint32 argc);
|
||||
int32 demon_atcmd_play_mp3(const char *cmd, char *argv[], uint32 argc);
|
||||
#endif
|
||||
Reference in New Issue
Block a user