mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	format: Allow format->sample spec conversion for compressed formats
This allows clients to get a "fake" sample space for compressed formats that we can support. This should make size/time conversion for things like calculating buffer attributes simpler.
This commit is contained in:
		
							parent
							
								
									8baf8e90c2
								
							
						
					
					
						commit
						a0706e7c84
					
				
					 6 changed files with 38 additions and 43 deletions
				
			
		| 
						 | 
					@ -189,7 +189,6 @@ pa_format_info_set_rate;
 | 
				
			||||||
pa_format_info_set_sample_format;
 | 
					pa_format_info_set_sample_format;
 | 
				
			||||||
pa_format_info_snprint;
 | 
					pa_format_info_snprint;
 | 
				
			||||||
pa_format_info_to_sample_spec;
 | 
					pa_format_info_to_sample_spec;
 | 
				
			||||||
pa_format_info_to_sample_spec_fake;
 | 
					 | 
				
			||||||
pa_format_info_valid;
 | 
					pa_format_info_valid;
 | 
				
			||||||
pa_frame_size;
 | 
					pa_frame_size;
 | 
				
			||||||
pa_get_binary_name;
 | 
					pa_get_binary_name;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -218,6 +218,28 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
 | 
				
			||||||
    return f;
 | 
					    return f;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* For compressed streams */
 | 
				
			||||||
 | 
					static int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
 | 
				
			||||||
 | 
					    int rate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_assert(f);
 | 
				
			||||||
 | 
					    pa_assert(ss);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Note: When we add support for non-IEC61937 encapsulated compressed
 | 
				
			||||||
 | 
					     * formats, this function should return a non-zero values for these. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ss->format = PA_SAMPLE_S16LE;
 | 
				
			||||||
 | 
					    ss->channels = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, -PA_ERR_INVALID);
 | 
				
			||||||
 | 
					    ss->rate = (uint32_t) rate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (f->encoding == PA_ENCODING_EAC3_IEC61937)
 | 
				
			||||||
 | 
					        ss->rate *= 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* For PCM streams */
 | 
					/* For PCM streams */
 | 
				
			||||||
int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
 | 
					int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
 | 
				
			||||||
    char *sf = NULL, *m = NULL;
 | 
					    char *sf = NULL, *m = NULL;
 | 
				
			||||||
| 
						 | 
					@ -226,7 +248,9 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(f);
 | 
					    pa_assert(f);
 | 
				
			||||||
    pa_assert(ss);
 | 
					    pa_assert(ss);
 | 
				
			||||||
    pa_return_val_if_fail(f->encoding == PA_ENCODING_PCM, FALSE);
 | 
					
 | 
				
			||||||
 | 
					    if (!pa_format_info_is_pcm(f))
 | 
				
			||||||
 | 
					        return pa_format_info_to_sample_spec_fake(f, ss);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf))
 | 
					    if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf))
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
| 
						 | 
					@ -260,26 +284,6 @@ out:
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* For compressed streams */
 | 
					 | 
				
			||||||
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
 | 
					 | 
				
			||||||
    int rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(f);
 | 
					 | 
				
			||||||
    pa_assert(ss);
 | 
					 | 
				
			||||||
    pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, -PA_ERR_INVALID);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ss->format = PA_SAMPLE_S16LE;
 | 
					 | 
				
			||||||
    ss->channels = 2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, -PA_ERR_INVALID);
 | 
					 | 
				
			||||||
    ss->rate = (uint32_t) rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (f->encoding == PA_ENCODING_EAC3_IEC61937)
 | 
					 | 
				
			||||||
        ss->rate *= 4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key) {
 | 
					pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key) {
 | 
				
			||||||
    const char *str;
 | 
					    const char *str;
 | 
				
			||||||
    json_object *o, *o1;
 | 
					    json_object *o, *o1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,8 +118,11 @@ pa_format_info* pa_format_info_from_string(const char *str);
 | 
				
			||||||
/** Utility function to take a \a pa_sample_spec and generate the corresponding \a pa_format_info. \since 2.0 */
 | 
					/** Utility function to take a \a pa_sample_spec and generate the corresponding \a pa_format_info. \since 2.0 */
 | 
				
			||||||
pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
 | 
					pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. Returns
 | 
					/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. The
 | 
				
			||||||
 * a negative integer if conversion failed and 0 on success. \since 2.0 */
 | 
					 * conversion for PCM formats is straight-forward. For non-PCM formats, if there is a fixed size-time conversion (i.e. all
 | 
				
			||||||
 | 
					 * IEC61937-encapsulated formats), a "fake" sample spec whose size-time conversion corresponds to this format is provided and
 | 
				
			||||||
 | 
					 * the channel map argument is ignored. For formats with variable size-time conversion, this function will fail. Returns a
 | 
				
			||||||
 | 
					 * negative integer if conversion failed and 0 on success. \since 2.0 */
 | 
				
			||||||
int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
 | 
					int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Represents the type of value type of a property on a \ref pa_format_info. \since 2.0 */
 | 
					/** Represents the type of value type of a property on a \ref pa_format_info. \since 2.0 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -304,7 +304,6 @@ void pa_ext_device_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t)
 | 
				
			||||||
void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
 | 
					void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_format_info_free2(pa_format_info *f, void *userdata);
 | 
					void pa_format_info_free2(pa_format_info *f, void *userdata);
 | 
				
			||||||
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
 | 
					pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -292,15 +292,10 @@ int pa_sink_input_new(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Now populate the sample spec and format according to the final
 | 
					    /* Now populate the sample spec and format according to the final
 | 
				
			||||||
     * format that we've negotiated */
 | 
					     * format that we've negotiated */
 | 
				
			||||||
    if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
 | 
					 | 
				
			||||||
    pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
 | 
					    pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
 | 
				
			||||||
    pa_sink_input_new_data_set_sample_spec(data, &ss);
 | 
					    pa_sink_input_new_data_set_sample_spec(data, &ss);
 | 
				
			||||||
        if (pa_channel_map_valid(&map))
 | 
					    if (pa_format_info_is_pcm(data->format) && pa_channel_map_valid(&map))
 | 
				
			||||||
        pa_sink_input_new_data_set_channel_map(data, &map);
 | 
					        pa_sink_input_new_data_set_channel_map(data, &map);
 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
 | 
					 | 
				
			||||||
        pa_sink_input_new_data_set_sample_spec(data, &ss);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE);
 | 
					    pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE);
 | 
				
			||||||
    pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED), -PA_ERR_INVALID);
 | 
					    pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED), -PA_ERR_INVALID);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -272,15 +272,10 @@ int pa_source_output_new(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Now populate the sample spec and format according to the final
 | 
					    /* Now populate the sample spec and format according to the final
 | 
				
			||||||
     * format that we've negotiated */
 | 
					     * format that we've negotiated */
 | 
				
			||||||
    if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
 | 
					 | 
				
			||||||
    pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
 | 
					    pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
 | 
				
			||||||
    pa_source_output_new_data_set_sample_spec(data, &ss);
 | 
					    pa_source_output_new_data_set_sample_spec(data, &ss);
 | 
				
			||||||
        if (pa_channel_map_valid(&map))
 | 
					    if (pa_format_info_is_pcm(data->format) && pa_channel_map_valid(&map))
 | 
				
			||||||
        pa_source_output_new_data_set_channel_map(data, &map);
 | 
					        pa_source_output_new_data_set_channel_map(data, &map);
 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
 | 
					 | 
				
			||||||
        pa_source_output_new_data_set_sample_spec(data, &ss);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_return_val_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source)), -PA_ERR_BADSTATE);
 | 
					    pa_return_val_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source)), -PA_ERR_BADSTATE);
 | 
				
			||||||
    pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID);
 | 
					    pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue