From 05705c5ce20b74da3b6029f014aed9fea132f2a9 Mon Sep 17 00:00:00 2001 From: Snehanshu Date: Tue, 10 Dec 2024 16:05:31 +0900 Subject: [PATCH] framework/Media: Add reset API for recorder and player. This commit add reset API for recorder and player which will help application to do reset for recorder and player to IDLE state. --- framework/include/media/MediaPlayer.h | 9 +++++++ framework/include/media/MediaRecorder.h | 9 +++++++ framework/src/media/MediaPlayer.cpp | 5 ++++ framework/src/media/MediaPlayerImpl.cpp | 23 +++++++++++++++++ framework/src/media/MediaPlayerImpl.h | 1 + framework/src/media/MediaRecorder.cpp | 5 ++++ framework/src/media/MediaRecorderImpl.cpp | 30 +++++++++++++++++++++++ framework/src/media/MediaRecorderImpl.h | 1 + 8 files changed, 83 insertions(+) diff --git a/framework/include/media/MediaPlayer.h b/framework/include/media/MediaPlayer.h index b007167c87..5beeb1b57d 100644 --- a/framework/include/media/MediaPlayer.h +++ b/framework/include/media/MediaPlayer.h @@ -134,6 +134,15 @@ class MediaPlayer */ player_result_t unprepare(); + /** + * @brief Reset allocated resources related to the player, after the API, player is in state PLAYER_STATE_IDLE. + * @details @b #include + * This function is a synchronous API + * @return The result of the reset operation + * @since TizenLite v5.0 + */ + player_result_t reset(); + /** * @brief Start playback. * @details @b #include diff --git a/framework/include/media/MediaRecorder.h b/framework/include/media/MediaRecorder.h index f10c37a87b..6bab4856ad 100644 --- a/framework/include/media/MediaRecorder.h +++ b/framework/include/media/MediaRecorder.h @@ -121,6 +121,15 @@ class MediaRecorder * @since TizenRT v2.0 */ recorder_result_t unprepare(); + + /** + * @brief Reset allocated resources related to the recorder, after the API, recorder is in state RECORDER_STATE_IDLE. + * @details @b #include + * This function is a synchronous API + * @return The result of the reset operation + * @since TizenLite v5.0 + */ + recorder_result_t reset(); /** * @brief Start recording. diff --git a/framework/src/media/MediaPlayer.cpp b/framework/src/media/MediaPlayer.cpp index 3fc1d3cc75..481f1a9b63 100644 --- a/framework/src/media/MediaPlayer.cpp +++ b/framework/src/media/MediaPlayer.cpp @@ -52,6 +52,11 @@ player_result_t MediaPlayer::unprepare() return mPMpImpl->unprepare(); } +player_result_t MediaPlayer::reset() +{ + return mPMpImpl->reset(); +} + player_result_t MediaPlayer::start() { return mPMpImpl->start(); diff --git a/framework/src/media/MediaPlayerImpl.cpp b/framework/src/media/MediaPlayerImpl.cpp index cf68c7915e..181e65a288 100644 --- a/framework/src/media/MediaPlayerImpl.cpp +++ b/framework/src/media/MediaPlayerImpl.cpp @@ -299,6 +299,29 @@ void MediaPlayerImpl::unpreparePlayer(player_result_t &ret) return notifySync(); } +player_result_t MediaPlayerImpl::reset() +{ + LOG_STATE_INFO(mCurState); + meddbg("MediaPlayer reset mPlayer : %x\n", &mPlayer); + + if (mCurState == PLAYER_STATE_READY || mCurState == PLAYER_STATE_PLAYING || mCurState == PLAYER_STATE_PAUSED) { + mInputHandler.close(); + if (reset_audio_stream_out(mStreamInfo->id) != AUDIO_MANAGER_SUCCESS) { + meddbg("MediaPlayer reset fail : reset_audio_stream_out fail\n"); + return PLAYER_ERROR_INTERNAL_OPERATION_FAILED; + } + + if (mBuffer) { + delete[] mBuffer; + mBuffer = nullptr; + } + mBufSize = 0; + } + + mCurState = PLAYER_STATE_IDLE; + return PLAYER_OK; +} + player_result_t MediaPlayerImpl::start() { player_result_t ret = PLAYER_OK; diff --git a/framework/src/media/MediaPlayerImpl.h b/framework/src/media/MediaPlayerImpl.h index 4423fd15be..6facb6a59c 100644 --- a/framework/src/media/MediaPlayerImpl.h +++ b/framework/src/media/MediaPlayerImpl.h @@ -96,6 +96,7 @@ class MediaPlayerImpl : public std::enable_shared_from_this player_result_t prepare(); player_result_t prepareAsync(); player_result_t unprepare(); + player_result_t reset(); player_result_t start(); player_result_t pause(); player_result_t stop(); diff --git a/framework/src/media/MediaRecorder.cpp b/framework/src/media/MediaRecorder.cpp index df562ec0b7..a2981f2b77 100644 --- a/framework/src/media/MediaRecorder.cpp +++ b/framework/src/media/MediaRecorder.cpp @@ -47,6 +47,11 @@ recorder_result_t MediaRecorder::unprepare() return mPMrImpl->unprepare(); } +recorder_result_t MediaRecorder::reset() +{ + return mPMrImpl->reset(); +} + recorder_result_t MediaRecorder::start() { return mPMrImpl->start(); diff --git a/framework/src/media/MediaRecorderImpl.cpp b/framework/src/media/MediaRecorderImpl.cpp index 61e796c301..889ac38f6a 100644 --- a/framework/src/media/MediaRecorderImpl.cpp +++ b/framework/src/media/MediaRecorderImpl.cpp @@ -244,6 +244,36 @@ void MediaRecorderImpl::unprepareRecorder(recorder_result_t& ret) notifySync(); } +recorder_result_t MediaRecorderImpl::reset() +{ + LOG_STATE_INFO(mCurState); + meddbg("MediaRecorderImpl::reset()\n"); + + if (mCurState == RECORDER_STATE_READY || mCurState == RECORDER_STATE_RECORDING || mCurState == RECORDER_STATE_PAUSED) { + audio_manager_result_t result = reset_audio_stream_in(); + if (result != AUDIO_MANAGER_SUCCESS) { + meddbg("reset_audio_stream_in failed ret : %d\n", result); + return RECORDER_ERROR_INTERNAL_OPERATION_FAILED; + } + auto source = mOutputHandler.getDataSource(); + if (source->isPrepared()) { + mOutputHandler.close(); + } + if (mBuffer) { + delete[] mBuffer; + mBuffer = nullptr; + } + mBuffSize = 0; + mDuration = 0; + mFileSize = 0; + mTotalFrames = 0; + mCapturedFrames = 0; + } + + mCurState = RECORDER_STATE_IDLE; + return RECORDER_OK; +} + recorder_result_t MediaRecorderImpl::start() { std::lock_guard lock(mCmdMtx); diff --git a/framework/src/media/MediaRecorderImpl.h b/framework/src/media/MediaRecorderImpl.h index 8159b93a87..27b96f6b65 100644 --- a/framework/src/media/MediaRecorderImpl.h +++ b/framework/src/media/MediaRecorderImpl.h @@ -90,6 +90,7 @@ class MediaRecorderImpl : public enable_shared_from_this recorder_result_t destroy(); recorder_result_t prepare(); recorder_result_t unprepare(); + recorder_result_t reset(); recorder_result_t start(); recorder_result_t pause();