1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 5 #ifndef __UVOICE_PLAY_H__ 6 #define __UVOICE_PLAY_H__ 7 8 9 typedef enum { 10 PLAYER_MSG_PCM_INFO = 0, 11 PLAYER_MSG_MEDIA_INFO, 12 PLAYER_MSG_SEEK_DONE, 13 PLAYER_MSG_LOAD_BLOCK, 14 } player_message_t; 15 16 typedef enum { 17 STREAM_MGR_STAT_IDLE = 0, 18 STREAM_MGR_STAT_READY, 19 STREAM_MGR_STAT_RUNNING, 20 STREAM_MGR_STAT_STOP, 21 } stream_mgr_state_t; 22 23 typedef enum { 24 FADE_NOP = 0, 25 FADE_IN_END, 26 FADE_OUT_END, 27 FADE_IN, 28 FADE_OUT, 29 } fade_state_t; 30 31 typedef enum { 32 SEEK_NOP = 0, 33 SEEK_PREPARE, 34 SEEK_START, 35 SEEK_COMPLETE, 36 } seek_state_t; 37 38 typedef enum { 39 PLAYER_CLOSE = 0, 40 PLAYER_PAUSE, 41 PLAYER_RESUME, 42 PLAYER_START, 43 PLAYER_NEXT, 44 PLAYER_STOP, 45 PLAYER_COMPLETE, 46 PLAYER_SEEK_BEGIN, 47 PLAYER_SEEK, 48 PLAYER_SEEK_END, 49 PLAYER_RELOAD, 50 PLAYER_DLOAD, 51 PLAYER_DLOAD_ABORT, 52 PLAYER_UNBLOCK, 53 PLAYER_CONFIGURE, 54 STREAM_MGR_START, 55 STREAM_MGR_STOP, 56 } player_action_t; 57 58 typedef struct { 59 int dirty_cache_size; 60 int avail_cache_size; 61 int seek_forward_limit; 62 int seek_backward_limit; 63 } cache_info_t; 64 65 typedef struct { 66 media_format_t format; 67 uint8_t *buffer_out; 68 int buffer_out_size; 69 int unproc_size; 70 int input_size; 71 uint8_t initialized:1; 72 uint8_t running:1; 73 uint8_t stere_enable:1; 74 uint8_t pos_rebase:1; 75 uint32_t rebase_offset; 76 int (*decode)(void *priv, uint8_t *buffer, int nbytes); 77 int (*action)(void *priv, player_action_t action, void *arg); 78 int (*message)(void *priv, player_message_t msg, void *arg); 79 int (*output)(void *priv, uint8_t *buffer, int nbytes); 80 int (*reset)(void *priv); 81 void *decoder; 82 void *priv; 83 } media_decoder_t; 84 85 typedef struct { 86 media_type_t type; 87 uint8_t *buffer; 88 int buffer_size; 89 int buffer_dirty_size; 90 int rebase_request; 91 int rebase_offset; 92 int (*read)(void *priv, uint8_t *buffer, int nbytes); 93 int (*action)(void *priv, player_action_t action, void *arg); 94 int (*reset)(void *priv); 95 int (*message)(void *priv, player_message_t msg, void *arg); 96 int (*get_format)(void *priv, media_format_t *format); 97 int (*get_mediainfo)(void *priv, media_info_t *info, media_format_t format); 98 int (*get_cacheinfo)(void *priv, cache_info_t *info); 99 void *loader; 100 void *priv; 101 } media_loader_t; 102 103 typedef struct { 104 uvoice_ringbuff_t rb; 105 uint8_t *buffer; 106 uint8_t *stream_pool; 107 int buffer_size; 108 int buffer_dirty_size; 109 int stream_pool_size; 110 int wr_len; 111 int rd_len; 112 uint8_t cache_enable:1; 113 uint8_t wr_waiting:1; 114 uint8_t rd_waiting:1; 115 uint8_t cplt_waiting:1; 116 uint8_t stop:1; 117 uint8_t abort:1; 118 media_format_t format; 119 os_sem_t cplt_sem; 120 os_sem_t wr_sem; 121 os_sem_t rd_sem; 122 media_decoder_t *mdecoder; 123 struct out_stream *out; 124 stream_mgr_state_t state; 125 os_mutex_t lock; 126 os_task_t task; 127 media_pcminfo_t pcm_info; 128 } stream_mgr_t; 129 130 typedef struct { 131 int out_scope; 132 int out_period_ms; 133 int in_scope; 134 int in_period_ms; 135 int pos; 136 int reset; 137 fade_state_t state; 138 os_mutex_t lock; 139 } fade_process_t; 140 141 typedef struct { 142 int offset; 143 int fade_request; 144 seek_state_t state; 145 } seek_process_t; 146 147 typedef struct { 148 int src_channels; 149 int dst_channels; 150 int src_bits; 151 int dst_bits; 152 int coeff; 153 uint8_t *buffer; 154 int buffer_size; 155 } format_convert_t; 156 157 typedef struct { 158 uint32_t pause:1; 159 uint32_t stop:1; 160 uint32_t complete:1; 161 uint32_t error:1; 162 uint32_t pcm_reset:1; 163 uint32_t stream_flowing:1; 164 uint32_t cplt_waiting:1; 165 uint32_t start_waiting:1; 166 uint32_t pause_waiting:1; 167 uint32_t resume_waiting:1; 168 uint32_t stop_waiting:1; 169 uint32_t sw_volume:1; 170 uint32_t fade_enable:1; 171 uint32_t fade_ignore:1; 172 uint32_t blocking:1; 173 uint32_t deep_cplt:1; 174 uint32_t frame_skip:1; 175 uint32_t out_bypass:1; 176 uint32_t vol_level; 177 fade_process_t fade; 178 seek_process_t seek; 179 media_format_t format; 180 media_format_t format_preferable; 181 media_type_t type; 182 player_state_t state; 183 long long silent_time; 184 int consumed_len; 185 int idle_period; 186 int standby_msec; 187 int reference_count; 188 os_mutex_t lock; 189 os_mutex_t vol_lock; 190 os_sem_t start_sem; 191 os_sem_t pause_sem; 192 os_sem_t resume_sem; 193 os_sem_t cplt_sem; 194 os_sem_t reset_sem; 195 os_sem_t stop_sem; 196 format_convert_t *convertor; 197 media_decoder_t *mdecoder; 198 media_loader_t *mloader; 199 stream_mgr_t *stream_mgr; 200 struct out_stream *out; 201 void *resampler; 202 media_info_t *media_info; 203 media_pcminfo_t pcm_info; 204 os_task_t task; 205 } player_t; 206 207 int media_loader_reset(media_loader_t *mloader); 208 media_loader_t *media_loader_create(media_type_t type, char *source); 209 int media_loader_release(media_loader_t *mloader); 210 int media_decoder_reset(media_decoder_t *mdecoder); 211 media_decoder_t *media_decoder_create(media_format_t format); 212 int media_decoder_release(media_decoder_t *mdecoder); 213 214 215 #endif /* __UVOICE_PLAY_H__ */ 216 217