chipaudette
Well-known member
Over the last bunch of years, there's been great work done to enable dynamic audio connections. Fantastic! But, as freely acknowledged, this work was limited to creating/destroying AudioConnection instances. Destroying Audio objects themselves (ie, instances of AudioStream) is still forbidden.
The primary issue is that AudioStream keeps a linked list of every AudioStream instance that's ever been created. If you need to destroy an AudioStream instance, you need to remove it from the list. There is no mechanism right now that does this.
This action should be triggered by the class's destructor. But, AudioStream has no destructor (other than the default one that implicit with C++).
Can we add a destructor to AudioStream? Or has that already been considered and then rejected?
If we were to implement a destructor, one might start with this:
Yes, this is a minimal destructor. For example, it doesn't do anything about stale pointers in AudioConnections. But, now that we dynamic connections implemented in AudioConnection, it is possible for the user to do the right thing and correctly destroy the relevant AudioConnections. That's not the case with AudioStream. Without this minimal destructor, there is no way to remove the instance from the linked list.
Has this kind of change been considered in the past and rejected? Please, let me know!
Chip
(As an aside, I do have an application that desires to dyanmically create / destroy AudioStream instances. So, this is not just idle chatter. I'd love to help make it a reality!)
The primary issue is that AudioStream keeps a linked list of every AudioStream instance that's ever been created. If you need to destroy an AudioStream instance, you need to remove it from the list. There is no mechanism right now that does this.
This action should be triggered by the class's destructor. But, AudioStream has no destructor (other than the default one that implicit with C++).
Can we add a destructor to AudioStream? Or has that already been considered and then rejected?
If we were to implement a destructor, one might start with this:
Code:
virtual ~AudioStream() {
//remove this instance from the AudioStream update list
//__disable_irq(); //should we start with this?
AudioStream *p = first_update;
while (p != NULL) {
if (p->next_update == this) {
p->next_update = this->next_update; //remove the pointer to this instance and replace it with the next instance
}
p = p->next_update; //go to next step in linked list
}
//__enable_irq();
//release any audio blocks held in the input queue for this instance of AudioStream
for (int i=0; i<num_inputs; i++) {
audio_block_t *block = inputQueue[i];
if (block != NULL) release(block);
}
}
Yes, this is a minimal destructor. For example, it doesn't do anything about stale pointers in AudioConnections. But, now that we dynamic connections implemented in AudioConnection, it is possible for the user to do the right thing and correctly destroy the relevant AudioConnections. That's not the case with AudioStream. Without this minimal destructor, there is no way to remove the instance from the linked list.
Has this kind of change been considered in the past and rejected? Please, let me know!
Chip
(As an aside, I do have an application that desires to dyanmically create / destroy AudioStream instances. So, this is not just idle chatter. I'd love to help make it a reality!)
Last edited: