1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __UVOICE_RECORD_H__
6 #define __UVOICE_RECORD_H__
7 
8 
9 typedef enum {
10 	RECORDER_CLOSE = 0,
11 	RECORDER_PAUSE,
12 	RECORDER_RESUME,
13 	RECORDER_START,
14 	RECORDER_STOP,
15 	RECORDER_UPDATE_HEAD,
16 } recorder_action_t;
17 
18 typedef struct {
19 	media_type_t type;
20 	uint32_t size;
21 	int (*pack)(void *priv, uint8_t *buffer, int nbytes);
22 	int (*update)(void *priv, uint8_t *buffer, int nbytes, int pos);
23 	int (*action)(void *priv, recorder_action_t action, void *arg);
24 	void *packer;
25 } media_packer_t;
26 
27 typedef struct {
28 	media_format_t format;
29 	void *encoder;
30 	void *header;
31 	void *tail;
32 	int header_size;
33 	int tail_size;
34 	uint8_t initialized:1;
35 	uint8_t header_pack:1;
36 	uint8_t header_cplt:1;
37 	uint8_t running:1;
38 	uint8_t vbr:1;
39 	int rate;
40 	int channels;
41 	int bits;
42 	int frames;
43 	int bitrate;
44 	int (*encode)(void *priv, uint8_t *buffer, int nbytes);
45 	int (*header_gen)(void *priv, void *arg);
46 	int (*header_update)(void *priv, int size);
47 	int (*action)(void *priv, recorder_action_t action, void *arg);
48 } media_encoder_t;
49 
50 typedef struct {
51 	uint8_t *buffer;
52 	uint8_t *rec_buffer;
53 	int buffer_size;
54 	int buffer_dirty_size;
55 	int record_len;
56 	int reference_count;
57 	media_format_t format;
58 	media_type_t type;
59 	recorder_state_t state;
60 	uint8_t stop:1;
61 	uint8_t error:1;
62 	uint8_t ns_enable:1;
63 	uint8_t ec_enable:1;
64 	uint8_t agc_enable:1;
65 	uint8_t vad_enable:1;
66 	os_mutex_t lock;
67 	os_sem_t cplt_sem;
68 	int src_rate;
69 	int dst_rate;
70 	void *resampler;
71 	media_encoder_t *mencoder;
72 	media_packer_t *mpacker;
73 	struct in_stream *in;
74 	os_task_t task;
75 	media_pcminfo_t pcm_info;
76 } recorder_t;
77 
78 media_packer_t *media_packer_create(char *sink, media_type_t type);
79 int media_packer_release(media_packer_t *mpacker);
80 int media_encoder_header_gen(media_encoder_t *mencoder, media_pcminfo_t *pcminfo);
81 media_encoder_t *media_encoder_create(media_format_t format);
82 int media_encoder_release(media_encoder_t *mencoder);
83 
84 
85 #endif /* __UVOICE_RECORD_H__ */
86 
87