1 /*** 2 This file is part of PulseAudio. 3 4 Copyright 2006 Lennart Poettering 5 6 PulseAudio is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published 8 by the Free Software Foundation; either version 2.1 of the License, 9 or (at your option) any later version. 10 11 PulseAudio is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 18 ***/ 19 20 #ifdef HAVE_CONFIG_H 21 #include <config.h> 22 #endif 23 24 #include "rtp.h" 25 26 #include <pulsecore/core-util.h> 27 pa_rtp_payload_from_sample_spec(const pa_sample_spec * ss)28uint8_t pa_rtp_payload_from_sample_spec(const pa_sample_spec *ss) { 29 pa_assert(ss); 30 31 if (ss->format == PA_SAMPLE_S16BE && ss->rate == 44100 && ss->channels == 2) 32 return 10; 33 if (ss->format == PA_SAMPLE_S16BE && ss->rate == 44100 && ss->channels == 1) 34 return 11; 35 36 return 127; 37 } 38 pa_rtp_sample_spec_from_payload(uint8_t payload,pa_sample_spec * ss)39pa_sample_spec *pa_rtp_sample_spec_from_payload(uint8_t payload, pa_sample_spec *ss) { 40 pa_assert(ss); 41 42 switch (payload) { 43 case 10: 44 ss->channels = 2; 45 ss->format = PA_SAMPLE_S16BE; 46 ss->rate = 44100; 47 break; 48 49 case 11: 50 ss->channels = 1; 51 ss->format = PA_SAMPLE_S16BE; 52 ss->rate = 44100; 53 break; 54 55 default: 56 return NULL; 57 } 58 59 return ss; 60 } 61 pa_rtp_sample_spec_fixup(pa_sample_spec * ss)62pa_sample_spec *pa_rtp_sample_spec_fixup(pa_sample_spec * ss) { 63 pa_assert(ss); 64 65 if (!pa_rtp_sample_spec_valid(ss)) 66 ss->format = PA_SAMPLE_S16BE; 67 68 pa_assert(pa_rtp_sample_spec_valid(ss)); 69 return ss; 70 } 71 pa_rtp_sample_spec_valid(const pa_sample_spec * ss)72int pa_rtp_sample_spec_valid(const pa_sample_spec *ss) { 73 pa_assert(ss); 74 75 if (!pa_sample_spec_valid(ss)) 76 return 0; 77 78 return ss->format == PA_SAMPLE_S16BE; 79 } 80 pa_rtp_format_to_string(pa_sample_format_t f)81const char* pa_rtp_format_to_string(pa_sample_format_t f) { 82 switch (f) { 83 case PA_SAMPLE_S16BE: 84 return "L16"; 85 default: 86 return NULL; 87 } 88 } 89 pa_rtp_string_to_format(const char * s)90pa_sample_format_t pa_rtp_string_to_format(const char *s) { 91 pa_assert(s); 92 93 if (pa_streq(s, "L16")) 94 return PA_SAMPLE_S16BE; 95 else 96 return PA_SAMPLE_INVALID; 97 } 98