Skip to content

Commit dd2d7bd

Browse files
author
donglianghao
committed
Modify http stream reconnect patch
1 parent 51aabb0 commit dd2d7bd

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

idf_patches/adf_http_stream.patch

+41-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
From ee6fd0d1c4f49a44af1ee2d5eb069568265df730 Mon Sep 17 00:00:00 2001
2+
From: donglianghao <[email protected]>
3+
Date: Fri, 18 Sep 2020 15:26:04 +0800
4+
Subject: [PATCH] Modify http stream reconnect patch
5+
6+
---
7+
components/audio_stream/http_stream.c | 59 +++++++++++++++++++--------
8+
1 file changed, 41 insertions(+), 18 deletions(-)
9+
110
diff --git a/components/audio_stream/http_stream.c b/components/audio_stream/http_stream.c
2-
index b0e9957e..28c1ddd6 100644
11+
index ea62c4cf..f43c4830 100644
312
--- a/components/audio_stream/http_stream.c
413
+++ b/components/audio_stream/http_stream.c
514
@@ -32,7 +32,6 @@
@@ -27,7 +36,7 @@ index b0e9957e..28c1ddd6 100644
2736
} http_stream_t;
2837

2938
static esp_err_t http_stream_auto_connect_next_track(audio_element_handle_t el);
30-
@@ -329,7 +331,7 @@ static esp_err_t _http_open(audio_element_handle_t self)
39+
@@ -331,7 +333,7 @@ static esp_err_t _http_open(audio_element_handle_t self)
3140
ESP_LOGE(TAG, "already opened");
3241
return ESP_FAIL;
3342
}
@@ -36,16 +45,36 @@ index b0e9957e..28c1ddd6 100644
3645
_stream_open_begin:
3746

3847
uri = _playlist_get_next_track(self);
39-
@@ -488,7 +490,7 @@ static esp_err_t _http_close(audio_element_handle_t self)
48+
@@ -490,7 +492,7 @@ static esp_err_t _http_close(audio_element_handle_t self)
4049
http->is_variant_playlist = false;
4150
http->is_playlist_resolved = false;
4251
}
4352
- if (AEL_STATE_PAUSED != audio_element_get_state(self) && (errno == 0)) {
44-
+ if (AEL_STATE_PAUSED != audio_element_get_state(self) && (http->_errno == 0)) {
53+
+ if (AEL_STATE_PAUSED != audio_element_get_state(self)) {
4554
audio_element_report_pos(self);
4655
audio_element_set_byte_pos(self, 0);
4756
}
48-
@@ -516,17 +518,11 @@ static int _http_read(audio_element_handle_t self, char *buffer, int len, TickTy
57+
@@ -502,6 +504,19 @@ static esp_err_t _http_close(audio_element_handle_t self)
58+
return ESP_OK;
59+
}
60+
61+
+static esp_err_t _http_reconnect(audio_element_handle_t self)
62+
+{
63+
+ esp_err_t err = ESP_OK;
64+
+ audio_element_info_t info = {0};
65+
+ AUDIO_NULL_CHECK(TAG, self, return ESP_FAIL);
66+
+ err |= audio_element_getinfo(self, &info);
67+
+ err |= _http_close(self);
68+
+ err |= audio_element_set_byte_pos(self, info.byte_pos);
69+
+ err |= _http_open(self);
70+
+ return err;
71+
+}
72+
+
73+
+
74+
static int _http_read(audio_element_handle_t self, char *buffer, int len, TickType_t ticks_to_wait, void *context)
75+
{
76+
http_stream_t *http = (http_stream_t *)audio_element_getdata(self);
77+
@@ -518,17 +533,11 @@ static int _http_read(audio_element_handle_t self, char *buffer, int len, TickTy
4978
}
5079
}
5180
if (rlen <= 0) {
@@ -68,7 +97,7 @@ index b0e9957e..28c1ddd6 100644
6897
}
6998
if (http->auto_connect_next_track) {
7099
if (dispatch_hook(self, HTTP_STREAM_FINISH_PLAYLIST, NULL, 0) != ESP_OK) {
71-
@@ -560,7 +556,8 @@ static int _http_write(audio_element_handle_t self, char *buffer, int len, TickT
100+
@@ -562,7 +571,8 @@ static int _http_write(audio_element_handle_t self, char *buffer, int len, TickT
72101
}
73102

74103
if ((wrlen = esp_http_client_write(http->client, buffer, len)) <= 0) {
@@ -78,7 +107,7 @@ index b0e9957e..28c1ddd6 100644
78107
}
79108
return wrlen;
80109
}
81-
@@ -574,10 +571,23 @@ static int _http_process(audio_element_handle_t self, char *in_buffer, int in_le
110+
@@ -576,10 +586,23 @@ static int _http_process(audio_element_handle_t self, char *in_buffer, int in_le
82111
}
83112
int w_size = 0;
84113
if (r_size > 0) {
@@ -93,15 +122,18 @@ index b0e9957e..28c1ddd6 100644
93122
+ return ESP_FAIL;
94123
+ };
95124
+ http->connect_times++;
96-
+ ret |= _http_close(self);
97-
+ ret |= _http_open(self);
125+
+ ret = _http_reconnect(self);
98126
+ if (ret != ESP_OK) {
99127
+ ESP_LOGE(TAG, "Failed to reset connection");
100128
+ return ret;
101129
+ }
102130
+ ESP_LOGW(TAG, "reconnect to peer successful");
131+
+ return ESP_ERR_INVALID_STATE;
103132
} else {
104133
+ http->connect_times = 0;
105134
w_size = audio_element_output(self, in_buffer, r_size);
106135
audio_element_multi_output(self, in_buffer, r_size, 0);
107136
}
137+
--
138+
2.17.1
139+

0 commit comments

Comments
 (0)