Skip to content

Conversation

@kiruba115
Copy link
Contributor

RDKEMW-9781: Video format issue on MTK
Enhance the retry mechanism for AudioPort and VideoDeviceInit as well

Enhance the retry mechanism for AudioPort and VideoDeviceInit as well
@kiruba115 kiruba115 requested a review from a team as a code owner January 12, 2026 17:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses RDKEMW-9781, a video format issue on MTK platforms by enhancing the initialization retry mechanism. The changes extract the existing retry logic into a reusable helper function and extend retry capabilities to AudioPort and VideoDevice initialization, which previously had no retry mechanism.

Changes:

  • Introduced a new retryInitialization helper function with configurable retry logic
  • Extended retry mechanism to dsAudioPortInit, dsVideoPortInit, and dsVideoDeviceInit (previously only dsDisplayInit had retries)
  • Refactored Manager::Initialize to use the new helper function for cleaner code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ds/manager.cpp Outdated
Comment on lines 96 to 97
* @param[in] maxRetries Maximum number of retry attempts. Defaults to 25. The function will
* retry up to this many times with a 100ms delay between attempts.
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states that the function "retries up to this many times with a 100ms delay between attempts" for the maxRetries parameter. However, due to the loop logic issue, the actual behavior may differ. The delay happens after a failed attempt but before checking the retry count, and the post-increment in the condition means the number of executions may not match the documented behavior precisely. This documentation should be clarified once the loop logic is corrected.

Copilot uses AI. Check for mistakes.
ds/manager.cpp Outdated
Comment on lines 167 to 170
err = retryInitialization("dsAudioPortInit", dsAudioPortInit);
CHECK_RET_VAL(err);
err = dsVideoPortInit();

err = retryInitialization("dsVideoPortInit", dsVideoPortInit);
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry behavior has changed for dsAudioPortInit and dsVideoPortInit. Previously, these functions were called directly without retries. Now they use the retry mechanism with default parameters (maxRetries=25, checkInvalidState=false), meaning they will retry on ANY error up to 25 times. This is a significant behavioral change that could mask real errors and delay failure detection. Consider whether retrying on all errors is appropriate for these functions, or if they should only retry on specific errors like dsERR_INVALID_STATE similar to dsDisplayInit.

Copilot uses AI. Check for mistakes.
ds/manager.cpp Outdated
Comment on lines 108 to 126
dsError_t retryInitialization(const char* functionName,
std::function<dsError_t()> initFunc,
unsigned int maxRetries = 25,
bool checkInvalidState = false)
{
dsError_t err = dsERR_GENERAL;
unsigned int retryCount = 0;

do {
err = initFunc();
printf("Manager::Initialize:%s result :%d retryCount :%d\n",
functionName, err, retryCount);
if (dsERR_NONE == err) break;
usleep(100000);
} while ((checkInvalidState ? (dsERR_INVALID_STATE == err) : true) &&
(retryCount++ < maxRetries));

return err;
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new retryInitialization function and the modified retry behavior in Manager::Initialize lack test coverage. Given that the test directory contains tests for other device settings components, consider adding tests to verify the retry logic works correctly, including edge cases like maximum retries reached, successful retry after failures, and the checkInvalidState parameter behavior.

Copilot uses AI. Check for mistakes.
ds/manager.cpp Outdated
Comment on lines 108 to 111
dsError_t retryInitialization(const char* functionName,
std::function<dsError_t()> initFunc,
unsigned int maxRetries = 25,
bool checkInvalidState = false)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default parameter value for maxRetries (25) is specified in the function definition, but this is a static function with a forward declaration at line 66. Default parameter values should only be specified in the function declaration, not in the definition. The compiler may accept this, but it's not standard practice and could cause issues. Move the default parameter values to the declaration at line 66.

Copilot uses AI. Check for mistakes.
ds/manager.cpp Outdated
VideoDeviceConfig::getInstance().load();
}

err = retryInitialization("dsVideoDeviceInit", dsVideoDeviceInit);
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry behavior has changed for dsVideoDeviceInit. Previously, this function was called directly without retries. Now it uses the retry mechanism with default parameters (maxRetries=25, checkInvalidState=false), meaning it will retry on ANY error up to 25 times. This is a significant behavioral change that could mask real errors and delay failure detection. Consider whether retrying on all errors is appropriate for this function, or if it should only retry on specific errors like dsERR_INVALID_STATE similar to dsDisplayInit.

Suggested change
err = retryInitialization("dsVideoDeviceInit", dsVideoDeviceInit);
err = retryInitialization("dsVideoDeviceInit", dsVideoDeviceInit, 25, true);

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@apatel859 apatel859 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

apatel859
apatel859 previously approved these changes Jan 13, 2026
Copilot AI review requested due to automatic review settings January 13, 2026 17:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 149 to 152
if (IsInitialized == 0) {
needInit = true;
}
IsInitialized++;
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential race condition: If an exception is thrown after IsInitialized is incremented (line 152) but before the initialization completes, the decrement in the catch block (line 179) may not fully restore the correct state. Consider moving the IsInitialized increment to after successful initialization to ensure accurate state tracking.

Copilot uses AI. Check for mistakes.
Comment on lines 147 to 152
{std::lock_guard<std::mutex> lock(gManagerInitMutex);
printf("Entering %s count %d with thread id %lu\n",__FUNCTION__,IsInitialized,pthread_self());
if (IsInitialized == 0) {
needInit = true;
}
IsInitialized++;
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: The opening brace on line 147 uses spaces instead of tabs, which is inconsistent with the rest of the file. This should use consistent indentation with the rest of the codebase.

Suggested change
{std::lock_guard<std::mutex> lock(gManagerInitMutex);
printf("Entering %s count %d with thread id %lu\n",__FUNCTION__,IsInitialized,pthread_self());
if (IsInitialized == 0) {
needInit = true;
}
IsInitialized++;
{std::lock_guard<std::mutex> lock(gManagerInitMutex);
printf("Entering %s count %d with thread id %lu\n",__FUNCTION__,IsInitialized,pthread_self());
if (IsInitialized == 0) {
needInit = true;
}
IsInitialized++;

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 13, 2026 17:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apatel859 apatel859 merged commit f90a986 into develop Jan 13, 2026
14 of 15 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants