Skip to content

Commit

Permalink
framework/Media: Add reset API for recorder and player.
Browse files Browse the repository at this point in the history
This commit add reset API for recorder and player which will help
application to do reset for recorder and player to IDLE state.
  • Loading branch information
s1-vivek committed Dec 12, 2024
1 parent fab3fbb commit 0738a3c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
9 changes: 9 additions & 0 deletions framework/include/media/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ class MediaPlayer
*/
player_result_t unprepare();

/**
* @brief Reset allocated resources related to the player.
* @details @b #include <media/MediaPlayer.h>
* This function is a synchronous API
* @return The result of the reset operation
* @since TizenRT v5.0
*/
player_result_t reset();

/**
* @brief Start playback.
* @details @b #include <media/MediaPlayer.h>
Expand Down
9 changes: 9 additions & 0 deletions framework/include/media/MediaRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ class MediaRecorder
* @since TizenRT v2.0
*/
recorder_result_t unprepare();

/**
* @brief Reset allocated resources related to the recorder.
* @details @b #include <media/MediaRecorder.h>
* This function is a synchronous API
* @return The result of the reset operation
* @since TizenRT v5.0
*/
recorder_result_t reset();

/**
* @brief Start recording.
Expand Down
5 changes: 5 additions & 0 deletions framework/src/media/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 23 additions & 0 deletions framework/src/media/MediaPlayerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 unprepare 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;
Expand Down
1 change: 1 addition & 0 deletions framework/src/media/MediaPlayerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MediaPlayerImpl : public std::enable_shared_from_this<MediaPlayerImpl>
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();
Expand Down
5 changes: 5 additions & 0 deletions framework/src/media/MediaRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions framework/src/media/MediaRecorderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mCmdMtx);
Expand Down
1 change: 1 addition & 0 deletions framework/src/media/MediaRecorderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MediaRecorderImpl : public enable_shared_from_this<MediaRecorderImpl>
recorder_result_t destroy();
recorder_result_t prepare();
recorder_result_t unprepare();
recorder_result_t reset();

recorder_result_t start();
recorder_result_t pause();
Expand Down

0 comments on commit 0738a3c

Please sign in to comment.