mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	tagstruct: Add pa_tagstruct_put/get_direction()
This will be used for dealing with node directions. Someone might ask what's the point of adding functions for serializing just one byte; the point is the validation in pa_tagstruct_get_direction(). It's nice to be able to assume that the function will return a valid direction, instead of an arbitrary 8-bit value.
This commit is contained in:
		
							parent
							
								
									dd2b54282a
								
							
						
					
					
						commit
						9e598bfec5
					
				
					 2 changed files with 37 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -304,6 +304,15 @@ void pa_tagstruct_put_format_info(pa_tagstruct *t, pa_format_info *f) {
 | 
			
		|||
    pa_tagstruct_put_proplist(t, f->plist);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pa_tagstruct_put_direction(pa_tagstruct *t, pa_direction_t direction) {
 | 
			
		||||
    pa_assert(t);
 | 
			
		||||
 | 
			
		||||
    extend(t, 2);
 | 
			
		||||
 | 
			
		||||
    t->data[t->length++] = PA_TAG_DIRECTION;
 | 
			
		||||
    t->data[t->length++] = (uint8_t) direction;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int pa_tagstruct_gets(pa_tagstruct*t, const char **s) {
 | 
			
		||||
    int error = 0;
 | 
			
		||||
    size_t n;
 | 
			
		||||
| 
						 | 
				
			
			@ -677,6 +686,30 @@ fail:
 | 
			
		|||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int pa_tagstruct_get_direction(pa_tagstruct *t, pa_direction_t *direction) {
 | 
			
		||||
    uint8_t u;
 | 
			
		||||
    uint8_t mask = PA_DIRECTION_OUTPUT | PA_DIRECTION_INPUT;
 | 
			
		||||
 | 
			
		||||
    pa_assert(t);
 | 
			
		||||
    pa_assert(direction);
 | 
			
		||||
 | 
			
		||||
    if (t->rindex + 2 > t->length)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    if (t->data[t->rindex] != PA_TAG_DIRECTION)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    u = t->data[t->rindex + 1];
 | 
			
		||||
 | 
			
		||||
    if (!(u & mask) || (u & ~mask))
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    *direction = (pa_direction_t) u;
 | 
			
		||||
    t->rindex += 2;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pa_tagstruct_put(pa_tagstruct *t, ...) {
 | 
			
		||||
    va_list va;
 | 
			
		||||
    pa_assert(t);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@
 | 
			
		|||
#include <sys/types.h>
 | 
			
		||||
#include <sys/time.h>
 | 
			
		||||
 | 
			
		||||
#include <pulse/def.h>
 | 
			
		||||
#include <pulse/sample.h>
 | 
			
		||||
#include <pulse/format.h>
 | 
			
		||||
#include <pulse/channelmap.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -60,6 +61,7 @@ enum {
 | 
			
		|||
    PA_TAG_PROPLIST = 'P',
 | 
			
		||||
    PA_TAG_VOLUME = 'V',
 | 
			
		||||
    PA_TAG_FORMAT_INFO = 'f',
 | 
			
		||||
    PA_TAG_DIRECTION = 'd',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length);
 | 
			
		||||
| 
						 | 
				
			
			@ -86,6 +88,7 @@ void pa_tagstruct_put_cvolume(pa_tagstruct *t, const pa_cvolume *cvolume);
 | 
			
		|||
void pa_tagstruct_put_proplist(pa_tagstruct *t, pa_proplist *p);
 | 
			
		||||
void pa_tagstruct_put_volume(pa_tagstruct *t, pa_volume_t volume);
 | 
			
		||||
void pa_tagstruct_put_format_info(pa_tagstruct *t, pa_format_info *f);
 | 
			
		||||
void pa_tagstruct_put_direction(pa_tagstruct *t, pa_direction_t direction);
 | 
			
		||||
 | 
			
		||||
int pa_tagstruct_get(pa_tagstruct *t, ...);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -104,5 +107,6 @@ int pa_tagstruct_get_cvolume(pa_tagstruct *t, pa_cvolume *v);
 | 
			
		|||
int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p);
 | 
			
		||||
int pa_tagstruct_get_volume(pa_tagstruct *t, pa_volume_t *v);
 | 
			
		||||
int pa_tagstruct_get_format_info(pa_tagstruct *t, pa_format_info *f);
 | 
			
		||||
int pa_tagstruct_get_direction(pa_tagstruct *t, pa_direction_t *direction);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue