1 /*
2 * Copyright (C) 2020-2023 Alibaba Group Holding Limited
3 */
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <ulog/ulog.h>
8 #include "uvoice_init.h"
9 #include "uvoice_types.h"
10 #include "uvoice_event.h"
11 #include "uvoice_recorder.h"
12 #include "ulog/ulog.h"
13 #include "aos/kernel.h"
14 #include "uvoice_os.h"
15
16 #define TAG "recorder"
17 static uvoice_recorder_t *mrecorder = NULL;
18
recorder_init(void)19 int32_t recorder_init(void)
20 {
21 mrecorder = uvoice_recorder_create();
22 if (!mrecorder) {
23 LOGE(TAG, "create uvoice recorder failed !\n");
24 return -1;
25 }
26
27 return 0;
28 }
29
recorder_uninit(void)30 int32_t recorder_uninit(void)
31 {
32 return mrecorder->stop();
33 }
34
recorder_start(media_format_t fmt,int32_t rate,int32_t channels,int32_t bits,int32_t samples,char * sink)35 int32_t recorder_start(media_format_t fmt, int32_t rate, int32_t channels, int32_t bits, int32_t samples, char *sink)
36 {
37 int32_t len = 0, ret = 0;
38
39 ret = mrecorder->set_sink(fmt, rate, channels, bits, samples, 0, sink);
40 if (ret < 0) {
41 LOGE(TAG, "uvoice recorder set_sink failed !\n");
42 return -1;
43 }
44 ret = mrecorder->start();
45 if (ret < 0) {
46 LOGE(TAG, "uvoice recorder start failed !\n");
47 return -1;
48 }
49 return 0;
50 }
51
recorder_stop(void)52 int32_t recorder_stop(void)
53 {
54 return mrecorder->clr_sink();
55 }
56
recorder_get_stream(uint8_t * buf,int32_t read_size)57 int32_t recorder_get_stream(uint8_t *buf, int32_t read_size)
58 {
59 return mrecorder->get_stream(buf, read_size);
60 }
61