diff --git a/include/asterisk/res_audiosocket.h b/include/asterisk/res_audiosocket.h index d26d7b939e..c67987c1be 100644 --- a/include/asterisk/res_audiosocket.h +++ b/include/asterisk/res_audiosocket.h @@ -39,19 +39,43 @@ extern "C" { enum ast_audiosocket_msg_kind { /*! \brief Message indicates the channel should be hung up, direction: Sent only. */ - AST_AUDIOSOCKET_KIND_HANGUP = 0x00, + AST_AUDIOSOCKET_KIND_HANGUP = 0x00, /*! \brief Message contains the connection's UUID, direction: Received only. */ - AST_AUDIOSOCKET_KIND_UUID = 0x01, + AST_AUDIOSOCKET_KIND_UUID = 0x01, /*! \brief Message contains a DTMF digit, direction: Received only. */ - AST_AUDIOSOCKET_KIND_DTMF = 0x03, + AST_AUDIOSOCKET_KIND_DTMF = 0x03, - /*! \brief Messages contains audio data, direction: Sent and received. */ - AST_AUDIOSOCKET_KIND_AUDIO = 0x10, + /*! \brief Messages contains audio data, format: slin, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO = 0x10, + + /*! \brief Messages contains audio data, format: slin12, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN12 = 0x11, + + /*! \brief Messages contains audio data, format: slin16, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN16 = 0x12, + + /*! \brief Messages contains audio data, format: slin24, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN24 = 0x13, + + /*! \brief Messages contains audio data, format: slin32, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN32 = 0x14, + + /*! \brief Messages contains audio data, format: slin44, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN44 = 0x15, + + /*! \brief Messages contains audio data, format: slin48, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN48 = 0x16, + + /*! \brief Messages contains audio data, format: slin96, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN96 = 0x17, + + /*! \brief Messages contains audio data, format: slin192, direction: Sent and received. */ + AST_AUDIOSOCKET_KIND_AUDIO_SLIN192 = 0x18, /*! \brief An Asterisk-side error occurred, direction: Received only. */ - AST_AUDIOSOCKET_KIND_ERROR = 0xFF, + AST_AUDIOSOCKET_KIND_ERROR = 0xFF, }; diff --git a/res/res_audiosocket.c b/res/res_audiosocket.c index daf3e5903d..0381fd9493 100644 --- a/res/res_audiosocket.c +++ b/res/res_audiosocket.c @@ -230,7 +230,28 @@ const int ast_audiosocket_send_frame(const int svc, const struct ast_frame *f) depends on agreed upon audio codec for channel driver interface. */ switch (f->frametype) { case AST_FRAME_VOICE: - buf[0] = AST_AUDIOSOCKET_KIND_AUDIO; + if (ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin12) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN12; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin16) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN16; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin24) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN24; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin32) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN32; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin44) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN44; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin48) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN48; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin96) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN96; + } else if (ast_format_cmp(f->subclass.format, ast_format_slin192) == AST_FORMAT_CMP_EQUAL) { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO_SLIN192; + } else { + buf[0] = AST_AUDIOSOCKET_KIND_AUDIO; + } + *length = htons(datalen); memcpy(&buf[3], f->data.ptr, datalen); break; @@ -264,7 +285,6 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc, int i = 0, n = 0, ret = 0; struct ast_frame f = { .frametype = AST_FRAME_VOICE, - .subclass.format = ast_format_slin, .src = "AudioSocket", .mallocd = AST_MALLOCD_DATA, }; @@ -291,9 +311,37 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc, return NULL; } - if (*kind != AST_AUDIOSOCKET_KIND_AUDIO) { - ast_log(LOG_ERROR, "Received AudioSocket message other than hangup or audio, refer to protocol specification for valid message types\n"); - return NULL; + switch (*kind) { + case AST_AUDIOSOCKET_KIND_AUDIO: + f.subclass.format = ast_format_slin; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN12: + f.subclass.format = ast_format_slin12; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN16: + f.subclass.format = ast_format_slin16; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN24: + f.subclass.format = ast_format_slin24; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN32: + f.subclass.format = ast_format_slin32; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN44: + f.subclass.format = ast_format_slin44; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN48: + f.subclass.format = ast_format_slin48; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN96: + f.subclass.format = ast_format_slin96; + break; + case AST_AUDIOSOCKET_KIND_AUDIO_SLIN192: + f.subclass.format = ast_format_slin192; + break; + default: + ast_log(LOG_ERROR, "Received AudioSocket message other than hangup or audio, refer to protocol specification for valid message types\n"); + return NULL; } /* Swap endianess of length if needed. */