mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
Rework formats
Use a POD for the format body. This allows us to more easily build and copy the formats. Remove obsolete code to make video and audio formats. Use SpaVideo/AudioInfo to keep track of formats. Make functions to parse the format into the structures. Update plugins
This commit is contained in:
parent
7fc73953cd
commit
16b62de53a
34 changed files with 1096 additions and 1579 deletions
|
|
@ -330,6 +330,10 @@ spa_alsa_sink_node_port_enum_formats (SpaNode *node,
|
|||
unsigned int index)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
SpaResult res;
|
||||
SpaFormat *fmt;
|
||||
uint8_t buffer[1024];
|
||||
SpaPODBuilder b = { buffer, sizeof (buffer), };
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -341,19 +345,43 @@ spa_alsa_sink_node_port_enum_formats (SpaNode *node,
|
|||
|
||||
switch (index) {
|
||||
case 0:
|
||||
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
|
||||
SPA_MEDIA_SUBTYPE_RAW,
|
||||
&this->query_format);
|
||||
fmt = SPA_MEMBER (buffer, spa_pod_builder_format (&b,
|
||||
SPA_MEDIA_TYPE_AUDIO, SPA_MEDIA_SUBTYPE_RAW,
|
||||
SPA_PROP_ID_AUDIO_FORMAT, SPA_POD_TYPE_INT,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_ENUM, 2,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_AUDIO_FORMAT_S32,
|
||||
SPA_PROP_ID_AUDIO_RATE, SPA_POD_TYPE_INT,
|
||||
44100,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
1, INT32_MAX,
|
||||
SPA_PROP_ID_AUDIO_CHANNELS, SPA_POD_TYPE_INT,
|
||||
2,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
1, INT32_MAX,
|
||||
0), SpaFormat);
|
||||
break;
|
||||
case 1:
|
||||
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
|
||||
SPA_MEDIA_SUBTYPE_AAC,
|
||||
&this->query_format);
|
||||
fmt = SPA_MEMBER (buffer, spa_pod_builder_format (&b,
|
||||
SPA_MEDIA_TYPE_AUDIO, SPA_MEDIA_SUBTYPE_AAC,
|
||||
0), SpaFormat);
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*format = &this->query_format.format;
|
||||
|
||||
b.data = this->format_buffer;
|
||||
b.size = sizeof (this->format_buffer);
|
||||
b.offset = 0;
|
||||
|
||||
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK)
|
||||
return res;
|
||||
|
||||
*format = SPA_MEMBER (b.data, 0, SpaFormat);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -456,7 +484,7 @@ spa_alsa_sink_node_port_get_format (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = &this->current_format.format;
|
||||
*format = NULL;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,6 +367,9 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
|
|||
{
|
||||
SpaALSASource *this;
|
||||
SpaResult res;
|
||||
SpaFormat *fmt;
|
||||
uint8_t buffer[256];
|
||||
SpaPODBuilder b = { buffer, sizeof (buffer), };
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -378,23 +381,42 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
|
|||
|
||||
switch (index) {
|
||||
case 0:
|
||||
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
|
||||
SPA_MEDIA_SUBTYPE_RAW,
|
||||
&this->query_format);
|
||||
fmt = SPA_MEMBER (buffer, spa_pod_builder_format (&b,
|
||||
SPA_MEDIA_TYPE_AUDIO, SPA_MEDIA_SUBTYPE_RAW,
|
||||
SPA_PROP_ID_AUDIO_FORMAT, SPA_POD_TYPE_INT,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_ENUM, 2,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_AUDIO_FORMAT_S32,
|
||||
SPA_PROP_ID_AUDIO_RATE, SPA_POD_TYPE_INT,
|
||||
44100,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
1, INT32_MAX,
|
||||
SPA_PROP_ID_AUDIO_CHANNELS, SPA_POD_TYPE_INT,
|
||||
2,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_FLAG_READWRITE |
|
||||
SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
1, INT32_MAX,
|
||||
0), SpaFormat);
|
||||
break;
|
||||
case 1:
|
||||
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
|
||||
SPA_MEDIA_SUBTYPE_AAC,
|
||||
&this->query_format);
|
||||
break;
|
||||
fmt = SPA_MEMBER (buffer, spa_pod_builder_format (&b,
|
||||
SPA_MEDIA_TYPE_AUDIO, SPA_MEDIA_SUBTYPE_AAC,
|
||||
0), SpaFormat);
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
|
||||
if ((res = spa_format_audio_filter (&this->query_format, filter)) != SPA_RESULT_OK)
|
||||
b.data = this->format_buffer;
|
||||
b.size = sizeof (this->format_buffer);
|
||||
b.offset = 0;
|
||||
|
||||
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK)
|
||||
return res;
|
||||
|
||||
*format = &this->query_format.format;
|
||||
*format = SPA_MEMBER (this->format_buffer, 0, SpaFormat);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -502,7 +524,7 @@ spa_alsa_source_node_port_get_format (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = &this->current_format.format;
|
||||
*format = NULL;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ spa_alsa_format_to_alsa (SpaAudioFormat format)
|
|||
}
|
||||
|
||||
int
|
||||
spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlags flags)
|
||||
spa_alsa_set_format (SpaALSAState *state, SpaAudioInfo *fmt, SpaPortFormatFlags flags)
|
||||
{
|
||||
unsigned int rrate, rchannels;
|
||||
snd_pcm_uframes_t period_size;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ extern "C" {
|
|||
#include <spa/loop.h>
|
||||
#include <spa/ringbuffer.h>
|
||||
#include <spa/audio/format.h>
|
||||
#include <spa/format-builder.h>
|
||||
|
||||
typedef struct _SpaALSAState SpaALSAState;
|
||||
typedef struct _SpaALSABuffer SpaALSABuffer;
|
||||
|
|
@ -89,8 +90,9 @@ struct _SpaALSAState {
|
|||
snd_pcm_t *hndl;
|
||||
|
||||
bool have_format;
|
||||
SpaFormatAudio query_format;
|
||||
SpaFormatAudio current_format;
|
||||
SpaAudioInfo current_format;
|
||||
uint8_t format_buffer[1024];
|
||||
|
||||
snd_pcm_sframes_t buffer_frames;
|
||||
snd_pcm_sframes_t period_frames;
|
||||
snd_pcm_format_t format;
|
||||
|
|
@ -125,7 +127,7 @@ struct _SpaALSAState {
|
|||
};
|
||||
|
||||
int spa_alsa_set_format (SpaALSAState *state,
|
||||
SpaFormatAudio *fmt,
|
||||
SpaAudioInfo *info,
|
||||
SpaPortFormatFlags flags);
|
||||
|
||||
SpaResult spa_alsa_start (SpaALSAState *state, bool xrun_recover);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue