fix: use banban HTTPS timeout prompts
This commit is contained in:
@@ -6,8 +6,10 @@
|
||||
#include "ql_application.h"
|
||||
#include "ql_audio.h"
|
||||
#include "ql_iic.h"
|
||||
#include "ql_gpio.h"
|
||||
#include "ql_fs.h"
|
||||
#include "ql_gpio.h"
|
||||
#include "ql_fs.h"
|
||||
#include "ql_http_client.h"
|
||||
#include "talkingq_wss.h"
|
||||
|
||||
#include "webclient.h"
|
||||
#include <netdb.h>
|
||||
@@ -29,7 +31,105 @@ static int mp3_player_end_frame = 0;
|
||||
int current_sample_rate = 0;
|
||||
static audio_track_handle track_hd;
|
||||
|
||||
static unsigned short pcm_buff[1152*2]={0x00};
|
||||
static unsigned short pcm_buff[1152*2]={0x00};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *buffer;
|
||||
size_t capacity;
|
||||
size_t length;
|
||||
int status_code;
|
||||
int overflow;
|
||||
} https_mp3_recv_t;
|
||||
|
||||
/* HTTPS MP3 下载回调:直接把响应体写入播放器的内存缓冲区。 */
|
||||
static int https_mp3_response_cb(QL_HTTP_CLIENT_T *client,
|
||||
QL_HTTP_CLIENT_EVENT_E event, int status_code,
|
||||
char *data, int data_len, void *private_data)
|
||||
{
|
||||
https_mp3_recv_t *recv = (https_mp3_recv_t *)private_data;
|
||||
(void)client;
|
||||
|
||||
if(recv == NULL){
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(event){
|
||||
case QL_HTTP_CLIENT_EVENT_RECV_HEADER_FINISHED:
|
||||
recv->status_code = status_code;
|
||||
return status_code == 200 ? 1 : 0;
|
||||
case QL_HTTP_CLIENT_EVENT_RECV_BODY:
|
||||
if(data == NULL || data_len <= 0){
|
||||
return 1;
|
||||
}
|
||||
if(recv->length + (size_t)data_len > recv->capacity){
|
||||
recv->overflow = 1;
|
||||
return 0;
|
||||
}
|
||||
memcpy(recv->buffer + recv->length, data, (size_t)data_len);
|
||||
recv->length += (size_t)data_len;
|
||||
return 1;
|
||||
case QL_HTTP_CLIENT_EVENT_RECV_BODY_FINISHED:
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 使用模组原生 HTTP 客户端拉取 HTTPS 音频。 */
|
||||
static int https_mp3_data_fetch(char *uri, uint8_t *buffer, size_t length)
|
||||
{
|
||||
QL_HTTP_CLIENT_T *client = NULL;
|
||||
https_mp3_recv_t recv = {buffer, length, 0, 0, 0};
|
||||
QL_HTTP_CLIENT_ERR_E ret;
|
||||
SSLConfig ssl_config = {
|
||||
.en = 1,
|
||||
.profileIdx = 1,
|
||||
.serverName = "banban.api.talkingq.com",
|
||||
.serverPort = 443,
|
||||
.protocol = 0,
|
||||
.dbgLevel = 0,
|
||||
.sessionReuseEn = 0,
|
||||
.vsn = SSL_VSN_ALL,
|
||||
.verify = SSL_VERIFY_MODE_REQUIRED,
|
||||
.cert.from = SSL_CERT_FROM_BUF,
|
||||
.cert.path.rootCA = (char *)talkingq_root_ca,
|
||||
.cert.path.clientKey = NULL,
|
||||
.cert.path.clientCert = NULL,
|
||||
.cert.clientKeyPwd.data = NULL,
|
||||
.cert.clientKeyPwd.len = 0,
|
||||
.cipherList = "ALL",
|
||||
.CTRDRBGSeed.data = NULL,
|
||||
.CTRDRBGSeed.len = 0
|
||||
};
|
||||
|
||||
client = ql_http_client_init();
|
||||
if(client == NULL){
|
||||
printf("https mp3 client init failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ql_http_client_setopt(client, QL_HTTP_CLIENT_OPT_ASYN, 0);
|
||||
ql_http_client_setopt(client, QL_HTTP_CLIENT_OPT_PDP_CID, 1);
|
||||
ql_http_client_setopt(client, QL_HTTP_CLIENT_OPT_PROTOCOL_VER, 1);
|
||||
ql_http_client_setopt(client, QL_HTTP_CLIENT_OPT_SSL_CTX, &ssl_config);
|
||||
|
||||
ret = ql_http_client_request(client, uri, QL_HTTP_CLIENT_REQUEST_GET,
|
||||
QL_HTTP_CLIENT_AUTH_TYPE_NONE, NULL, NULL, NULL, 0,
|
||||
https_mp3_response_cb, &recv);
|
||||
ql_http_client_release(client);
|
||||
|
||||
if(ret != QL_HTTP_CLIENT_ERR_SUCCESS || recv.status_code != 200 ||
|
||||
recv.overflow || recv.length == 0){
|
||||
printf("https mp3 download failed, ret:%d status:%d size:%d overflow:%d\n",
|
||||
(int)ret, recv.status_code, (int)recv.length, recv.overflow);
|
||||
return -1;
|
||||
}
|
||||
|
||||
total_length = (int)recv.length;
|
||||
printf("https mp3 download success, size:%d\n", total_length);
|
||||
return total_length;
|
||||
}
|
||||
|
||||
struct mp3_decoder
|
||||
{
|
||||
@@ -392,8 +492,10 @@ void aofei_mp3_player(char *file_name)
|
||||
|
||||
memset(mp3_buff, 0, 100*1024);
|
||||
//直接下载到一个100k的buffer
|
||||
if(strstr(file_name, "http:")){//播放url
|
||||
ret = url_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
if(strncmp(file_name, "https://", 8) == 0){//播放HTTPS URL
|
||||
ret = https_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
}else if(strncmp(file_name, "http://", 7) == 0){//播放HTTP URL
|
||||
ret = url_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
}else if(strstr(file_name, "test.mp3")){//播放本地音频
|
||||
total_length = test_data_size;
|
||||
memcpy(mp3_buff, test_data, total_length);
|
||||
|
||||
Reference in New Issue
Block a user