RDKEMW-11232 getAudioFormatApi issue on Xione-UK#188
Conversation
Implement audio output port selection with priority.
Added debug output for audio port checks and updated fallback logic.
Rebase to latest
There was a problem hiding this comment.
Pull request overview
This pull request fixes an issue with the getAudioFormat API on Xione-UK by ensuring a valid audio port handle is passed instead of NULL. The fix introduces a new method to select the appropriate audio port based on platform configuration and connection status.
Changes:
- Enhanced error logging in
dsGetAudioFormatRPC handler to track failure scenarios - Added new
getAudioPortHandle()method to intelligently select audio ports based on platform type and port availability - Modified
getCurrentAudioFormat()to use the new port selection method instead of passing NULL
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| rpc/srv/dsAudio.c | Improved error handling by storing return value and adding logging for failure cases |
| ds/include/host.hpp | Added declaration for new getAudioPortHandle() method |
| ds/include/audioOutputPort.hpp | Added getter method to expose internal _handle member and minor formatting changes |
| ds/host.cpp | Implemented getAudioPortHandle() with platform-specific port selection logic and updated getCurrentAudioFormat() to use it |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| intptr_t Host::getAudioPortHandle() | ||
| { | ||
| try | ||
| { | ||
| if (isHDMIOutPortPresent()) | ||
| { | ||
| AudioOutputPort aPort = getAudioOutputPort("HDMI0"); | ||
| return aPort.getOutputPortHandle(); | ||
| } | ||
| else | ||
| { | ||
| //TV profiles with multiple audio output ports | ||
| try | ||
| { | ||
| // Define the priority order for audio ports | ||
| const std::string portPriority[] = {"HDMI_ARC0", "HEADPHONE0", "SPDIF0"}; | ||
|
|
||
| // Try each port in priority order | ||
| for (const auto& portName : portPriority) | ||
| { | ||
| try | ||
| { | ||
| AudioOutputPort aPort = getAudioOutputPort(portName); | ||
| cout << "Checking audio port: " << portName << " isEnabled: " << aPort.isEnabled() << " isConnected: " << aPort.isConnected() << "\n"; | ||
| // Check if port is enabled and connected | ||
| if (aPort.isEnabled() && aPort.isConnected()) | ||
| { | ||
| cout << "Using audio port: " << portName << "\n"; | ||
| return aPort.getOutputPortHandle(); | ||
| } | ||
| } | ||
| catch(const std::exception& e) | ||
| { | ||
| // Port not found or error accessing it, continue to next port | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| // Fallback: use SPEAKER0 if no other port is suitable | ||
| AudioOutputPort fallback_aPort = getAudioOutputPort("SPEAKER0"); | ||
| cout << "Using audio port: SPEAKER0" << "\n"; | ||
| return fallback_aPort.getOutputPortHandle(); | ||
| } | ||
| catch(const std::exception& e) | ||
| { | ||
| cout << " Exception Thrown in getAudioPortHandle().. returning NULL...!\n"; | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
| } | ||
| catch(const std::exception& e) | ||
| { | ||
| cout << " Exception Thrown in getAudioPortHandle().. returning NULL...!\n"; | ||
| } | ||
|
|
||
| return NULL; | ||
| } |
There was a problem hiding this comment.
The new method getAudioPortHandle() lacks test coverage. Consider adding test cases in test/testHost.cpp to verify the port selection logic, including scenarios for HDMI out presence, priority-based port selection, enabled/connected state checks, and fallback behavior.
ds/host.cpp
Outdated
| try | ||
| { | ||
| AudioOutputPort aPort = getAudioOutputPort(portName); | ||
| cout << "Checking audio port: " << portName << " isEnabled: " << aPort.isEnabled() << " isConnected: " << aPort.isConnected() << "\n"; |
There was a problem hiding this comment.
The indentation is inconsistent, using tabs instead of spaces like the surrounding code. Lines 411, 428 use tabs for indentation while the rest of the function uses spaces. This should be consistent with the file's indentation style.
ds/host.cpp
Outdated
|
|
||
| // Fallback: use SPEAKER0 if no other port is suitable | ||
| AudioOutputPort fallback_aPort = getAudioOutputPort("SPEAKER0"); | ||
| cout << "Using audio port: SPEAKER0" << "\n"; |
There was a problem hiding this comment.
The indentation is inconsistent, using tabs instead of spaces like the surrounding code. This should be consistent with the file's indentation style.
ds/host.cpp
Outdated
| catch(const std::exception& e) | ||
| { | ||
| cout << " Exception Thrown in getAudioPortHandle().. returning NULL...!\n"; |
There was a problem hiding this comment.
The exception variable 'e' is caught but never used. Consider logging the exception message using e.what() to provide better debugging information, similar to other exception handlers in this file (e.g., line 141 in manager.cpp).
ds/host.cpp
Outdated
| cout << " Exception Thrown in getAudioPortHandle().. returning NULL...!\n"; | ||
| } | ||
|
|
||
| return NULL; |
There was a problem hiding this comment.
The return statement at line 436 is unreachable code. If getAudioOutputPort("SPEAKER0") at line 427 succeeds, the function returns at line 429. If it throws an exception, it's caught at line 431, which then falls through to the outer catch block at line 439 or returns NULL at line 444. This return statement can never be executed and should be removed.
ds/host.cpp
Outdated
| dsAudioFormat_t aFormat; | ||
|
|
||
| ret = dsGetAudioFormat(NULL, &aFormat); | ||
| intptr_t audioPortHandle = getAudioPortHandle(); |
There was a problem hiding this comment.
The indentation is inconsistent, using tabs instead of spaces like the surrounding code. This should be consistent with the file's indentation style.
| intptr_t audioPortHandle = getAudioPortHandle(); | |
| intptr_t audioPortHandle = getAudioPortHandle(); |
| @@ -385,6 +385,65 @@ Host::~Host() | |||
| return std::string(socID); | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
The new method getAudioPortHandle() is missing documentation. It should have a doxygen-style comment block describing its purpose, return value, and any exceptions it may throw, consistent with other methods in this file.
| /** | |
| * @fn Host::getAudioPortHandle() | |
| * @brief Get the handle of the active audio output port. | |
| * | |
| * This API selects an appropriate audio output port and returns its | |
| * underlying handle. On platforms with an HDMI output port, the handle | |
| * for HDMI0 is returned. On TV profiles with multiple audio output ports, | |
| * the ports are checked in the following priority order: | |
| * HDMI_ARC0, HEADPHONE0, SPDIF0. The first port that is enabled and | |
| * connected is used. If none of these ports are suitable, SPEAKER0 is | |
| * used as a fallback. | |
| * | |
| * @return intptr_t Handle of the selected audio output port on success. | |
| * @return NULL If no suitable audio port handle can be obtained or if | |
| * an error occurs while resolving the port. | |
| * | |
| * @exception std::exception Exceptions from underlying audio port queries | |
| * are caught and cause this method to return NULL. | |
| */ |
| catch(const std::exception& e) | ||
| { | ||
| cout << " Exception Thrown in getAudioPortHandle().. returning NULL...!\n"; | ||
| } |
There was a problem hiding this comment.
The exception variable 'e' is caught but never used. Consider logging the exception message using e.what() to provide better debugging information, similar to other exception handlers in this file (e.g., line 141 in manager.cpp).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
RDKEMW-11232 getAudioFormatApi issue on Xione-UK