mp3_player.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * SPDX-License-Identifier: Apache-2.0
  3. *
  4. * Date Author Notes
  5. * 2021-06-02 MrzhangF1ghter first implementation
  6. */
  7. #ifndef __MP3_PLAYER_H__
  8. #define __MP3_PLAYER_H__
  9. #include <stdio.h>
  10. #include <rtdevice.h>
  11. #include "mp3dec.h" /* helix include files */
  12. enum MSG_TYPE
  13. {
  14. MSG_NONE = 0,
  15. MSG_START = 1,
  16. MSG_STOP = 2,
  17. MSG_PAUSE = 3,
  18. MSG_RESUME = 4,
  19. };
  20. enum PLAYER_EVENT
  21. {
  22. PLAYER_EVENT_NONE = 0,
  23. PLAYER_EVENT_PLAY = 1,
  24. PLAYER_EVENT_STOP = 2,
  25. PLAYER_EVENT_PAUSE = 3,
  26. PLAYER_EVENT_RESUME = 4,
  27. };
  28. struct play_msg
  29. {
  30. int type;
  31. void *data;
  32. };
  33. #pragma pack(1)
  34. typedef struct
  35. {
  36. uint8_t *read_ptr;
  37. int read_offset;
  38. int bytes_left;
  39. } decode_oper_t;
  40. /*
  41. * music basic info structure definition
  42. */
  43. typedef struct
  44. {
  45. uint8_t title[30];
  46. uint8_t artist[30];
  47. uint8_t year[4];
  48. uint8_t comment[30];
  49. uint8_t genre;
  50. } mp3_basic_info_t;
  51. /*
  52. * mp3_info structure definition
  53. */
  54. typedef struct
  55. {
  56. mp3_basic_info_t mp3_basic_info;
  57. uint32_t total_seconds;
  58. uint32_t curent_seconds;
  59. uint32_t bitrate;
  60. uint32_t samplerate;
  61. uint16_t outsamples;
  62. uint8_t vbr;
  63. uint32_t data_start;
  64. long file_size;
  65. } mp3_info_t;
  66. /*
  67. * mp3 player main structure definition
  68. */
  69. struct mp3_player
  70. {
  71. int state;
  72. char *uri;
  73. uint8_t *in_buffer;
  74. uint16_t *out_buffer;
  75. rt_device_t audio_device;
  76. rt_mq_t mq;
  77. rt_mutex_t lock;
  78. struct rt_completion ack;
  79. FILE *fp;
  80. int volume;
  81. /* helix decoder */
  82. HMP3Decoder mp3_decoder;
  83. MP3FrameInfo mp3_frameinfo;
  84. mp3_info_t mp3_info;
  85. decode_oper_t decode_oper;
  86. };
  87. #pragma pack()
  88. /**
  89. * mp3 player status
  90. */
  91. enum PLAYER_STATE
  92. {
  93. PLAYER_STATE_STOPED = 0,
  94. PLAYER_STATE_PLAYING = 1,
  95. PLAYER_STATE_PAUSED = 2,
  96. };
  97. /**
  98. * @brief Play wav music
  99. *
  100. * @param uri the pointer for file path
  101. *
  102. * @return
  103. * - 0 Success
  104. * - others Failed
  105. */
  106. int mp3_player_play(char *uri);
  107. /**
  108. * @brief Stop music
  109. *
  110. * @return
  111. * - 0 Success
  112. * - others Failed
  113. */
  114. int mp3_player_stop(void);
  115. /**
  116. * @brief Pause music
  117. *
  118. * @return
  119. * - 0 Success
  120. * - others Failed
  121. */
  122. int mp3_player_pause(void);
  123. /**
  124. * @brief Resume music
  125. *
  126. * @return
  127. * - 0 Success
  128. * - others Failed
  129. */
  130. int mp3_player_resume(void);
  131. /**
  132. * @brief Sev volume
  133. *
  134. * @param volume volume value(0 ~ 99)
  135. *
  136. * @return
  137. * - 0 Success
  138. * - others Failed
  139. */
  140. int mp3_player_volume_set(int volume);
  141. /**
  142. * @brief Get volume
  143. *
  144. * @return volume value(0~00)
  145. */
  146. int mp3_player_volume_get(void);
  147. /**
  148. * @brief Get wav player state
  149. *
  150. * @return
  151. * - PLAYER_STATE_STOPED stoped status
  152. * - PLAYER_STATE_PLAYING playing status
  153. * - PLAYER_STATE_PAUSED paused
  154. */
  155. int mp3_player_state_get(void);
  156. /**
  157. * @brief Get the uri that is currently playing
  158. *
  159. * @return uri that is currently playing
  160. */
  161. char *mp3_player_uri_get(void);
  162. /**
  163. * @brief show mp3 info
  164. */
  165. void mp3_info_show(void);
  166. /**
  167. * @brief show mp3 info
  168. */
  169. void mp3_disp_time(void);
  170. /**
  171. * @brief seek to destination seconds
  172. *
  173. * @return the error code,0 on success
  174. */
  175. rt_err_t mp3_seek(uint32_t seconds);
  176. #endif