Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_avplay] Remove duplicate code for checking player #674

Closed

Conversation

xiaowei-guan
Copy link
Contributor

  1. Extract a new Macro Definition to check if the player exists.
#define CHECK_PLAYER(statement)                                    \
  {                                                                \
    VideoPlayer *player = (statement);                             \
    if (!player) {                                                 \
      return FlutterError("Invalid argument", "Player not found"); \
    }                                                              \
  }
  1. Extract a new macro definition to check the result of player
#define CHECK_PLAYER_RESULT(statement, return_value)                           \
  {                                                                            \
    const auto result = (statement);                                           \
    if (result != PLAYER_ERROR_NONE) {                                         \
      LOG_ERROR("[MediaPlayer] Player error : %s", get_error_message(result)); \
      return return_value;                                                     \
    }                                                                          \
  }

#define CHECK_PLAYER_RESULT_NO_RETURN(statement)                               \
  {                                                                            \
    const auto result = (statement);                                           \
    if (result != PLAYER_ERROR_NONE) {                                         \
      LOG_ERROR("[MediaPlayer] Player error : %s", get_error_message(result)); \
    }                                                                          \
  }

@xiaowei-guan xiaowei-guan requested review from JSUYA, hyue7 and xuelian-bai and removed request for JSUYA March 4, 2024 09:46
Copy link
Member

@JSUYA JSUYA left a comment

Choose a reason for hiding this comment

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

Hi I agree with your intention to reduce duplicate code.
However, we don't generally use the macro method.(we follow Google c++ style guide.)
https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros
If there is no suitable way, you can rename the macro (add project name + avoid conflict) and add #undef.
But I recommend changing it to an appropriate function.

@xiaowei-guan
Copy link
Contributor Author

Hi I agree with your intention to reduce duplicate code. However, we don't generally use the macro method.(we follow Google c++ style guide.) https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros If there is no suitable way, you can rename the macro (add project name + avoid conflict) and add #undef. But I recommend changing it to an appropriate function.

Ok, I'll find a batter solution.

@xiaowei-guan xiaowei-guan marked this pull request as draft March 7, 2024 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants