add wav_player_start_loop_stop_others internal api 68/282168/7 accepted/tizen/unified/20221102.020516
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 28 Sep 2022 01:45:38 +0000 (10:45 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 14 Oct 2022 00:50:15 +0000 (09:50 +0900)
[Version] 0.3.9
[Issue Type] Internal

Change-Id: I0d6f3235eb54ff7fb6c9b22c3129e74a8d703408

include/wav_player_internal.h
include/wav_player_private.h
packaging/capi-media-wav-player.spec
src/wav_player.c [changed mode: 0755->0644]
src/wav_player_internal.c
src/wav_player_private.c [changed mode: 0755->0644]
test/wav_player_test.c

index 15be664..3a48671 100644 (file)
@@ -59,6 +59,34 @@ extern "C"
  */
 int wav_player_play_simple(const char *path, const char *stream_role);
 
+/**
+ * @internal
+ * @brief Plays a WAV file after stopping previous WAV playbacks
+ * @since_tizen 7.0
+ *
+ * @param[in] path     The file path to play
+ * @param[in] stream_info      The sound stream information handle
+ * @param[in] loop_count       The number of times the file should be played (@c 0 indicates infinite loops)
+ * @param[in] callback The callback function to be invoked when the WAV file is no longer being played
+ * @param[in] user_data        The user data to be passed to the callback function
+ * @param[out] id      The WAV player ID (can be set to @c NULL)
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WAV_PLAYER_ERROR_NONE Successful
+ * @retval #WAV_PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WAV_PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #WAV_PLAYER_ERROR_FORMAT_NOT_SUPPORTED Not supported format
+ * @retval #WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE Not supported stream type
+ *
+ */
+int wav_player_start_loop_stop_others(const char *path,
+                                                                       sound_stream_info_h stream_info,
+                                                                       unsigned int loop_count,
+                                                                       wav_player_playback_completed_cb callback,
+                                                                       void *user_data,
+                                                                       int *id);
+
 
 /**
  * @}
@@ -68,4 +96,4 @@ int wav_player_play_simple(const char *path, const char *stream_role);
 }
 #endif
 
-#endif /* __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ */
\ No newline at end of file
+#endif /* __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ */
index 591bd60..cde21c3 100644 (file)
@@ -36,7 +36,7 @@ extern "C"
 
 int _convert_wav_player_error_code(const char *func, int code);
 int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned int loop_count,
-                       wav_player_playback_completed_cb cb, void *user_data, int *id);
+                       wav_player_playback_completed_cb cb, void *user_data, bool stop_others, int *id);
 int _wav_play_sound_simple(const char *path, const char *stream_role);
 int _wav_stop_sound(int id);
 
index d36f6d1..ef6f885 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-wav-player
 Summary:    A wav player library in Tizen C API
-Version:    0.3.8
+Version:    0.3.9
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
old mode 100755 (executable)
new mode 100644 (file)
index 1f28594..68c4bc6
 int wav_player_start_new(const char *path, sound_stream_info_h stream_info,
                                wav_player_playback_completed_cb callback, void *user_data, int *id)
 {
-       return _wav_play_sound(path, stream_info, 1, callback, user_data, id);
+       return _wav_play_sound(path, stream_info, 1, callback, user_data, false, id);
 }
 
 int wav_player_start_loop(const char *path, sound_stream_info_h stream_info, unsigned int loop_count,
                                wav_player_playback_completed_cb callback, void *user_data, int *id)
 {
-       return _wav_play_sound(path, stream_info, loop_count, callback, user_data, id);
+       return _wav_play_sound(path, stream_info, loop_count, callback, user_data, false, id);
 }
 
 int wav_player_stop(int id)
index 067e9a3..444ba84 100644 (file)
@@ -22,3 +22,13 @@ int wav_player_play_simple(const char *path, const char *stream_role)
 {
        return _wav_play_sound_simple(path, stream_role);
 }
+
+int wav_player_start_loop_stop_others(const char *path,
+                                                                       sound_stream_info_h stream_info,
+                                                                       unsigned int loop_count,
+                                                                       wav_player_playback_completed_cb callback,
+                                                                       void *user_data,
+                                                                       int *id)
+{
+       return _wav_play_sound(path, stream_info, loop_count, callback, user_data, true, id);
+}
old mode 100755 (executable)
new mode 100644 (file)
index 978ed5d..7b8e048
@@ -105,7 +105,7 @@ static void __internal_complete_cb(GDBusConnection *connection,
 }
 
 int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned loop_count,
-                       wav_player_playback_completed_cb callback, void *user_data, int *id)
+                       wav_player_playback_completed_cb callback, void *user_data, bool stop_others, int *id)
 {
        int ret = WAV_PLAYER_ERROR_NONE;
        char m_path[PATH_MAX];
@@ -163,8 +163,8 @@ int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned
                        PA_SOUND_PLAYER_OBJECT_PATH,
                        PA_SOUND_PLAYER_INTERFACE,
                        PA_SOUND_PLAYER_METHOD_NAME_SOUND_PLAY,
-                       g_variant_new("(siisi)", m_path, loop_count == 0 ? -1 : loop_count,
-                                       getpid(), stream_type, stream_id),
+                       g_variant_new("(siisib)", m_path, loop_count == 0 ? -1 : loop_count,
+                                       getpid(), stream_type, stream_id, (gboolean)stop_others),
                        NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
        if (!reply) {
                LOGE("g_dbus_connection_call_sync error (%s)", err->message);
@@ -242,8 +242,8 @@ int _wav_play_sound_simple(const char *path, const char *stream_role)
                                                                                PA_SOUND_PLAYER_OBJECT_PATH,
                                                                                PA_SOUND_PLAYER_INTERFACE,
                                                                                PA_SOUND_PLAYER_METHOD_NAME_SOUND_PLAY,
-                                                                               g_variant_new("(siisi)", m_path, 1,
-                                                                                                         getpid(), stream_role, -1),
+                                                                               g_variant_new("(siisib)", m_path, 1,
+                                                                                                         getpid(), stream_role, -1, FALSE),
                                                                                NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
        if (!reply) {
                if (err) {
index 36d1357..d8eac67 100644 (file)
@@ -43,6 +43,7 @@ void help()
                   "  -s, --streamtype          stream type (0:media(default), 1:system, 2:notification, 3:voice-information, 4:solo)\n"
                   "  -i, --iterate             how many times to play\n"
                   "  -q, --quickplay           play quick\n"
+                  "  -o, --stopothers          play after stopping others\n"
                   "  -h, --help                help\n");
 }
 
@@ -59,7 +60,7 @@ void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e
        return;
 }
 
-void wav_play_test(const char *file_path, int iterate, int stream_type)
+void wav_play_test(const char *file_path, int iterate, int stream_type, bool stop_others)
 {
        int ret = 0;
        sound_stream_info_h stream_info;
@@ -101,8 +102,13 @@ void wav_play_test(const char *file_path, int iterate, int stream_type)
        }
 
        printf("Play Wav, File Path : %s, Iterate : %d\n", file_path, iterate);
-       ret = wav_player_start_loop(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid);
-       printf("wav_player_start_loop(id=%d) ret = %d\n", gid, ret);
+       if (stop_others) {
+               ret = wav_player_start_loop_stop_others(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid);
+               printf("wav_player_start_loop_stop_others(id=%d) ret = %d\n", gid, ret);
+       } else {
+               ret = wav_player_start_loop(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid);
+               printf("wav_player_start_loop(id=%d) ret = %d\n", gid, ret);
+       }
        if (ret) {
                sound_manager_destroy_stream_information(stream_info);
                return;
@@ -155,6 +161,7 @@ int main(int argc, char**argv)
        int iterate = 1;
        int stream_type = 0;
        bool quickplay = false;
+       bool stop_others = false;
        char file_path[FILE_PATH_MAX] = DEFAULT_FILE;
        struct sigaction sig_action;
        sig_action.sa_handler = __sig_handler;
@@ -171,26 +178,32 @@ int main(int argc, char**argv)
                        {"file"       , required_argument, 0, 'f'},
                        {"streamtype" , required_argument, 0, 's'},
                        {"quickplay"  , no_argument,       0, 'q'},
+                       {"stopothers" , no_argument,       0, 'o'},
+                       {"help"       , no_argument,       0, 'h'},
                        { 0, 0, 0, 0 }
                };
 
-               if ((opt = getopt_long(argc, argv, "i:f:s:q", long_options, &opt_idx)) == -1)
+               if ((opt = getopt_long(argc, argv, "i:f:s:qoh", long_options, &opt_idx)) == -1)
                        break;
 
+               printf("opt = %d(%c), opt_idx = %d\n", opt, opt, opt_idx);
+
                switch (opt) {
-               case 'f':
-                       strncpy(file_path, optarg, FILE_PATH_MAX - 1);
-                       file_path[FILE_PATH_MAX - 1] = '\0';
-                       break;
                case 'i':
                        iterate = atoi(optarg);
                        break;
+               case 'f':
+                       snprintf(file_path, FILE_PATH_MAX, "%s", optarg);
+                       break;
                case 's':
                        stream_type = atoi(optarg);
                        break;
                case 'q':
                        quickplay = true;
                        break;
+               case 'o':
+                       stop_others = true;
+                       break;
                case 'h':
                default:
                        help();
@@ -201,7 +214,7 @@ int main(int argc, char**argv)
        if (quickplay)
                wav_play_test_quick(file_path);
        else
-               wav_play_test(file_path, iterate, stream_type);
+               wav_play_test(file_path, iterate, stream_type, stop_others);
 
        return 0;
 }