|
|
@ -66,9 +66,9 @@ void AudioTaskMain(void* args) { |
|
|
|
!element->IsOverBuffered(); |
|
|
|
!element->IsOverBuffered(); |
|
|
|
|
|
|
|
|
|
|
|
if (has_work_to_do) { |
|
|
|
if (has_work_to_do) { |
|
|
|
ESP_LOGI(kTag, "checking for events"); |
|
|
|
ESP_LOGD(kTag, "checking for events"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ESP_LOGI(kTag, "waiting for events"); |
|
|
|
ESP_LOGD(kTag, "waiting for events"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If we have no new events to process and the element has nothing left to
|
|
|
|
// If we have no new events to process and the element has nothing left to
|
|
|
@ -83,13 +83,13 @@ void AudioTaskMain(void* args) { |
|
|
|
if (new_event->tag == StreamEvent::UNINITIALISED) { |
|
|
|
if (new_event->tag == StreamEvent::UNINITIALISED) { |
|
|
|
ESP_LOGE(kTag, "discarding invalid event!!"); |
|
|
|
ESP_LOGE(kTag, "discarding invalid event!!"); |
|
|
|
} else if (new_event->tag == StreamEvent::CHUNK_NOTIFICATION) { |
|
|
|
} else if (new_event->tag == StreamEvent::CHUNK_NOTIFICATION) { |
|
|
|
ESP_LOGI(kTag, "marking chunk as used"); |
|
|
|
ESP_LOGD(kTag, "marking chunk as used"); |
|
|
|
element->OnChunkProcessed(); |
|
|
|
element->OnChunkProcessed(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// This isn't an event that needs to be actioned immediately. Add it
|
|
|
|
// This isn't an event that needs to be actioned immediately. Add it
|
|
|
|
// to our work queue.
|
|
|
|
// to our work queue.
|
|
|
|
pending_events.emplace_back(new_event); |
|
|
|
pending_events.emplace_back(new_event); |
|
|
|
ESP_LOGI(kTag, "deferring event"); |
|
|
|
ESP_LOGD(kTag, "deferring event"); |
|
|
|
} |
|
|
|
} |
|
|
|
// Loop again, so that we service all incoming events before doing our
|
|
|
|
// Loop again, so that we service all incoming events before doing our
|
|
|
|
// possibly expensive processing.
|
|
|
|
// possibly expensive processing.
|
|
|
@ -97,7 +97,7 @@ void AudioTaskMain(void* args) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (element->HasUnflushedOutput()) { |
|
|
|
if (element->HasUnflushedOutput()) { |
|
|
|
ESP_LOGI(kTag, "flushing output"); |
|
|
|
ESP_LOGD(kTag, "flushing output"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// We have no new events. Next, see if there's anything that needs to be
|
|
|
|
// We have no new events. Next, see if there's anything that needs to be
|
|
|
@ -112,7 +112,7 @@ void AudioTaskMain(void* args) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (element->HasUnprocessedInput()) { |
|
|
|
if (element->HasUnprocessedInput()) { |
|
|
|
ESP_LOGI(kTag, "processing input events"); |
|
|
|
ESP_LOGD(kTag, "processing input events"); |
|
|
|
auto process_res = element->Process(); |
|
|
|
auto process_res = element->Process(); |
|
|
|
if (!process_res.has_error() || process_res.error() != OUT_OF_DATA) { |
|
|
|
if (!process_res.has_error() || process_res.error() != OUT_OF_DATA) { |
|
|
|
// TODO: log!
|
|
|
|
// TODO: log!
|
|
|
@ -123,19 +123,20 @@ void AudioTaskMain(void* args) { |
|
|
|
// The element ran out of data, so now it's time to let it process more
|
|
|
|
// The element ran out of data, so now it's time to let it process more
|
|
|
|
// input.
|
|
|
|
// input.
|
|
|
|
while (!pending_events.empty()) { |
|
|
|
while (!pending_events.empty()) { |
|
|
|
auto& event = pending_events.front(); |
|
|
|
std::unique_ptr<StreamEvent> event; |
|
|
|
ESP_LOGI(kTag, "processing event, tag %i", event->tag); |
|
|
|
pending_events.front().swap(event); |
|
|
|
|
|
|
|
pending_events.pop_front(); |
|
|
|
|
|
|
|
ESP_LOGD(kTag, "processing event, tag %i", event->tag); |
|
|
|
|
|
|
|
|
|
|
|
if (event->tag == StreamEvent::STREAM_INFO) { |
|
|
|
if (event->tag == StreamEvent::STREAM_INFO) { |
|
|
|
ESP_LOGI(kTag, "processing stream info"); |
|
|
|
ESP_LOGD(kTag, "processing stream info"); |
|
|
|
auto process_res = element->ProcessStreamInfo(*event->stream_info); |
|
|
|
auto process_res = element->ProcessStreamInfo(*event->stream_info); |
|
|
|
pending_events.pop_front(); |
|
|
|
|
|
|
|
if (process_res.has_error()) { |
|
|
|
if (process_res.has_error()) { |
|
|
|
// TODO(jacqueline)
|
|
|
|
// TODO(jacqueline)
|
|
|
|
ESP_LOGE(kTag, "failed to process stream info"); |
|
|
|
ESP_LOGE(kTag, "failed to process stream info"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (event->tag == StreamEvent::CHUNK_DATA) { |
|
|
|
} else if (event->tag == StreamEvent::CHUNK_DATA) { |
|
|
|
ESP_LOGI(kTag, "processing chunk data"); |
|
|
|
ESP_LOGD(kTag, "processing chunk data"); |
|
|
|
auto callback = |
|
|
|
auto callback = |
|
|
|
StreamEvent::CreateChunkNotification(element->InputEventQueue()); |
|
|
|
StreamEvent::CreateChunkNotification(element->InputEventQueue()); |
|
|
|
if (!xQueueSend(event->source, &callback, 0)) { |
|
|
|
if (!xQueueSend(event->source, &callback, 0)) { |
|
|
@ -145,7 +146,6 @@ void AudioTaskMain(void* args) { |
|
|
|
|
|
|
|
|
|
|
|
auto process_chunk_res = |
|
|
|
auto process_chunk_res = |
|
|
|
element->ProcessChunk(event->chunk_data.bytes); |
|
|
|
element->ProcessChunk(event->chunk_data.bytes); |
|
|
|
pending_events.pop_front(); |
|
|
|
|
|
|
|
if (process_chunk_res.has_error()) { |
|
|
|
if (process_chunk_res.has_error()) { |
|
|
|
// TODO(jacqueline)
|
|
|
|
// TODO(jacqueline)
|
|
|
|
ESP_LOGE(kTag, "failed to process chunk"); |
|
|
|
ESP_LOGE(kTag, "failed to process chunk"); |
|
|
|