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
+
1
10
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
3
12
--- a/components/audio_stream/http_stream.c
4
13
+++ b/components/audio_stream/http_stream.c
5
14
@@ -32,7 +32,6 @@
@@ -27,7 +36,7 @@ index b0e9957e..28c1ddd6 100644
27
36
} http_stream_t;
28
37
29
38
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)
31
40
ESP_LOGE(TAG, "already opened");
32
41
return ESP_FAIL;
33
42
}
@@ -36,16 +45,36 @@ index b0e9957e..28c1ddd6 100644
36
45
_stream_open_begin:
37
46
38
47
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)
40
49
http->is_variant_playlist = false;
41
50
http->is_playlist_resolved = false;
42
51
}
43
52
- 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)) {
45
54
audio_element_report_pos(self);
46
55
audio_element_set_byte_pos(self, 0);
47
56
}
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
49
78
}
50
79
}
51
80
if (rlen <= 0) {
@@ -68,7 +97,7 @@ index b0e9957e..28c1ddd6 100644
68
97
}
69
98
if (http->auto_connect_next_track) {
70
99
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
72
101
}
73
102
74
103
if ((wrlen = esp_http_client_write(http->client, buffer, len)) <= 0) {
@@ -78,7 +107,7 @@ index b0e9957e..28c1ddd6 100644
78
107
}
79
108
return wrlen;
80
109
}
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
82
111
}
83
112
int w_size = 0;
84
113
if (r_size > 0) {
@@ -93,15 +122,18 @@ index b0e9957e..28c1ddd6 100644
93
122
+ return ESP_FAIL;
94
123
+ };
95
124
+ http->connect_times++;
96
- + ret |= _http_close(self);
97
- + ret |= _http_open(self);
125
+ + ret = _http_reconnect(self);
98
126
+ if (ret != ESP_OK) {
99
127
+ ESP_LOGE(TAG, "Failed to reset connection");
100
128
+ return ret;
101
129
+ }
102
130
+ ESP_LOGW(TAG, "reconnect to peer successful");
131
+ + return ESP_ERR_INVALID_STATE;
103
132
} else {
104
133
+ http->connect_times = 0;
105
134
w_size = audio_element_output(self, in_buffer, r_size);
106
135
audio_element_multi_output(self, in_buffer, r_size, 0);
107
136
}
137
+ - -
138
+ 2.17.1
139
+
0 commit comments