Skip to content

Commit

Permalink
Specify bitrate and samplerate for GetAudioEncoderConfigurationOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Jan 3, 2025
1 parent 385b136 commit 457d84c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
34 changes: 28 additions & 6 deletions media2_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ int media2_get_audio_encoder_configuration_options()
const char *profile_token = get_element("ProfileToken", "Body");
char token[10];

char bitrate[4], samplerate[4];

memset(token, '\0', sizeof(token));
if (configuration_token != NULL) {
// Extract "Profile_x" from token Profile_x_VideoEncoderConfig
Expand All @@ -950,21 +952,37 @@ int media2_get_audio_encoder_configuration_options()
if ((service_ctx.profiles_num > 0) &&
(strcasecmp(service_ctx.profiles[0].name, token) == 0)) {

if (service_ctx.profiles[0].audio_encoder != AUDIO_NONE) {
// G726 is not suppoerted
if ((service_ctx.profiles[0].audio_encoder != AUDIO_NONE) && (service_ctx.profiles[0].audio_encoder != G726)) {

set_audio_codec(audio_enc, 16, service_ctx.profiles[0].audio_encoder, 2);

if (service_ctx.profiles[0].audio_encoder == G711) {
sprintf(bitrate, "%d", 64);
sprintf(samplerate, "%d", 8);
} else if (service_ctx.profiles[0].audio_encoder == AAC) {
sprintf(bitrate, "%d", 50);
sprintf(samplerate, "%d", 16);
}
} else {
send_fault("media2_service", "Receiver", "ter:ActionNotSupported", "ter:AudioNotSupported", "AudioNotSupported", "The device does not support audio");
return -2;
}
} else if ((service_ctx.profiles_num == 2) &&
(strcasecmp(service_ctx.profiles[1].name, token) == 0)) {

if (service_ctx.profiles[1].audio_encoder != AUDIO_NONE) {
// G726 is not suppoerted
if ((service_ctx.profiles[1].audio_encoder != AUDIO_NONE) && (service_ctx.profiles[1].audio_encoder != G726)) {

set_audio_codec(audio_enc, 16, service_ctx.profiles[1].audio_encoder, 2);

if (service_ctx.profiles[1].audio_encoder == G711) {
sprintf(bitrate, "%d", 64);
sprintf(samplerate, "%d", 8);
} else if (service_ctx.profiles[1].audio_encoder == AAC) {
sprintf(bitrate, "%d", 50);
sprintf(samplerate, "%d", 16);
}
} else {
send_fault("media2_service", "Receiver", "ter:ActionNotSupported", "ter:AudioNotSupported", "AudioNotSupported", "The device does not support audio");
return -3;
Expand All @@ -974,14 +992,18 @@ int media2_get_audio_encoder_configuration_options()
return -4;
}

long size = cat(NULL, "media2_service_files/GetAudioEncoderConfigurationOptions.xml", 2,
"%AUDIO_ENCODING%", audio_enc);
long size = cat(NULL, "media2_service_files/GetAudioEncoderConfigurationOptions.xml", 6,
"%AUDIO_ENCODING%", audio_enc,
"%BITRATE%", bitrate,
"%SAMPLERATE%", samplerate);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "media2_service_files/GetAudioEncoderConfigurationOptions.xml", 2,
"%AUDIO_ENCODING%", audio_enc);
return cat("stdout", "media2_service_files/GetAudioEncoderConfigurationOptions.xml", 6,
"%AUDIO_ENCODING%", audio_enc,
"%BITRATE%", bitrate,
"%SAMPLERATE%", samplerate);
}

int media2_get_audio_output_configurations()
Expand Down
4 changes: 2 additions & 2 deletions media2_service_files/GetAudioEncoderConfigurationOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<tr2:Options>
<tt:Encoding>%AUDIO_ENCODING%</tt:Encoding>
<tt:BitrateList>
<tt:Items>50</tt:Items>
<tt:Items>%BITRATE%</tt:Items>
</tt:BitrateList>
<tt:SampleRateList>
<tt:Items>16</tt:Items>
<tt:Items>%SAMPLERATE%</tt:Items>
</tt:SampleRateList>
</tr2:Options>
</tr2:GetAudioEncoderConfigurationOptionsResponse>
Expand Down
34 changes: 28 additions & 6 deletions media_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ int media_get_audio_encoder_configuration_options()
const char *profile_token = get_element("ProfileToken", "Body");
char token[10];

char bitrate[4], samplerate[4];

memset(token, '\0', sizeof(token));
if (configuration_token != NULL) {
// Extract "Profile_x" from token Profile_x_AudioEncoderToken
Expand All @@ -1208,21 +1210,37 @@ int media_get_audio_encoder_configuration_options()
if ((service_ctx.profiles_num > 0) &&
(strcasecmp(service_ctx.profiles[0].name, token) == 0)) {

if (service_ctx.profiles[0].audio_encoder != AUDIO_NONE) {
// G726 is not suppoerted
if ((service_ctx.profiles[0].audio_encoder != AUDIO_NONE) && (service_ctx.profiles[0].audio_encoder != G726)) {

set_audio_codec(audio_encoder, 16, service_ctx.profiles[0].audio_encoder, 1);

if (service_ctx.profiles[0].audio_encoder == G711) {
sprintf(bitrate, "%d", 64);
sprintf(samplerate, "%d", 8);
} else if (service_ctx.profiles[0].audio_encoder == AAC) {
sprintf(bitrate, "%d", 50);
sprintf(samplerate, "%d", 16);
}
} else {
send_fault("media_service", "Receiver", "ter:ActionNotSupported", "ter:AudioNotSupported", "AudioNotSupported", "The device does not support audio");
return -2;
}
} else if ((service_ctx.profiles_num == 2) &&
(strcasecmp(service_ctx.profiles[1].name, token) == 0)) {

if (service_ctx.profiles[1].audio_encoder != AUDIO_NONE) {
// G726 is not suppoerted
if ((service_ctx.profiles[1].audio_encoder != AUDIO_NONE) && (service_ctx.profiles[1].audio_encoder != G726)) {

set_audio_codec(audio_encoder, 16, service_ctx.profiles[1].audio_encoder, 1);

if (service_ctx.profiles[1].audio_encoder == G711) {
sprintf(bitrate, "%d", 64);
sprintf(samplerate, "%d", 8);
} else if (service_ctx.profiles[1].audio_encoder == AAC) {
sprintf(bitrate, "%d", 50);
sprintf(samplerate, "%d", 16);
}
} else {
send_fault("media_service", "Receiver", "ter:ActionNotSupported", "ter:AudioNotSupported", "AudioNotSupported", "The device does not support audio");
return -3;
Expand All @@ -1232,14 +1250,18 @@ int media_get_audio_encoder_configuration_options()
return -4;
}

long size = cat(NULL, "media_service_files/GetAudioEncoderConfigurationOptions.xml", 2,
"%AUDIO_ENCODING%", audio_encoder);
long size = cat(NULL, "media_service_files/GetAudioEncoderConfigurationOptions.xml", 6,
"%AUDIO_ENCODING%", audio_encoder,
"%BITRATE%", bitrate,
"%SAMPLERATE%", samplerate);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "media_service_files/GetAudioEncoderConfigurationOptions.xml", 2,
"%AUDIO_ENCODING%", audio_encoder);
return cat("stdout", "media_service_files/GetAudioEncoderConfigurationOptions.xml", 6,
"%AUDIO_ENCODING%", audio_encoder,
"%BITRATE%", bitrate,
"%SAMPLERATE%", samplerate);
}

int media_get_audio_decoder_configuration()
Expand Down
4 changes: 2 additions & 2 deletions media_service_files/GetAudioEncoderConfigurationOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<tt:Options>
<tt:Encoding>%AUDIO_ENCODING%</tt:Encoding>
<tt:BitrateList>
<tt:Items>50</tt:Items>
<tt:Items>%BITRATE%</tt:Items>
</tt:BitrateList>
<tt:SampleRateList>
<tt:Items>16</tt:Items>
<tt:Items>%SAMPLERATE%</tt:Items>
</tt:SampleRateList>
</tt:Options>
</trt:Options>
Expand Down

0 comments on commit 457d84c

Please sign in to comment.