1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __AUDIO_PLAYER_H__
6 #define __AUDIO_PLAYER_H__
7 
8 #ifdef __cplusplus
9 extern "C"
10 {
11 #endif
12 
13     typedef enum
14     {
15         AUDIO_PLAYER_FORMAT_INVALID = -1,
16         AUDIO_PLAYER_FORMAT_MP3 = 0,
17         AUDIO_PLAYER_FORMAT_AAC_ADTS,
18         AUDIO_PLAYER_FORMAT_AAC_M4A,
19         AUDIO_PLAYER_FORMAT_OPUS,
20         AUDIO_PLAYER_FORMAT_PCM,
21         AUDIO_PLAYER_FORMAT_WAV,
22     } audio_player_format_t;
23 
24     int audio_player_init(void);
25     typedef void (*audio_player_playback_cb)(void);
26 
27     /* if player pcm audio, should config pcm arg. */
28     int audio_player_fomat_pcm_config(uint32_t sample_rate, uint8_t channels_num);
29 
30     /* audio_player play audio from file, auto start player. */
31     int audio_player_play_file(const char *path_name, audio_player_playback_cb cb);
32 
33     /* audio_player play audio from memory data, audo start player. */
34     int audio_player_play_mem_init(audio_player_format_t format, uint32_t total_size, audio_player_playback_cb cb);
35     int audio_player_play_mem(const uint8_t *data, uint32_t data_len);
36     int audio_player_play_mem_denint(void);
37 
38     /* audio_player control function */
39     int audio_player_stop(void);
40 #if 0
41     /* Not Support */
42     int audio_player_pause(void);
43     int audio_player_resume(void);
44 #endif
45 
46     /* for filesystem */
47     typedef int (*audio_player_file_open)(const char *pathname, int flags);
48     typedef int (*audio_player_file_close)(int fd);
49     typedef int (*audio_player_file_read)(int fd, void *buf, uint32_t count);
50 
51     typedef struct {
52         audio_player_file_open open;
53         audio_player_file_close close;
54         audio_player_file_read read;
55     } audio_player_file_opt_t;
56 
57     int audio_player_file_ops_register(audio_player_file_opt_t * file_opt);
58     int audio_fs_open(const char *pathname, int flags);
59     int audio_fs_close(int fd);
60     uint32_t audio_fs_read(int fd, void *buf, uint32_t count);
61 
62     /* some test case */
63     int audio_player_test_from_sd_card_file(const char *path);
64     int audio_player_test_from_sd_card_file_and_stop(const char *path, uint32_t play_time_ms);
65     int audio_player_test_from_mem(audio_player_format_t foramt, uint8_t *raw_data, uint32_t raw_data_size);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif /* __AUDIO_PLAYER_H__ */
72