From: Hyunsoo Park Date: Fri, 17 Jan 2020 08:43:17 +0000 (+0900) Subject: Applying streamrecorder mode APIs to internal. X-Git-Tag: submit/tizen_5.5/20200120.080455^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F222708%2F7;p=platform%2Fcore%2Fapi%2Fmediastreamrecorder.git Applying streamrecorder mode APIs to internal. It is branch merging of tizen 6.0. (https://review.tizen.org/gerrit/#/c/platform/core/api/mediastreamrecorder/+/218535/) [Modification] - Generates internal header, c file. - 'streamrecoder_set_mode' and 'streamrecorder_get_mode' goes to internal. - 'streamrecorder_mode_e' enum goes to internal. - Adds testsuite for loopback test. Change-Id: I2ea38514dad5bbf3f57ab0f588c36f89322b921e Signed-off-by: Hyunsoo Park --- diff --git a/include/streamrecorder_internal.h b/include/streamrecorder_internal.h new file mode 100644 index 0000000..d0c912e --- /dev/null +++ b/include/streamrecorder_internal.h @@ -0,0 +1,42 @@ + +/* +* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + + +#ifndef __TIZEN_MEDIA_STREAMRECORDER_INTERNAL_H__ +#define __TIZEN_MEDIA_STREAMRECORDER_INTERNAL_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + STREAMRECORDER_MODE_STREAM_BUFFER = 0, /**< Recording with media buffer */ + STREAMRECORDER_MODE_DEVICE_LOOPBACK /**< Recording with device's own screen and audio */ +} streamrecorder_mode_e; + +int streamrecorder_set_mode(streamrecorder_h recorder, streamrecorder_mode_e mode); +int streamrecorder_get_mode(streamrecorder_h recorder, streamrecorder_mode_e *mode); + +#ifdef __cplusplus +} +#endif + +#endif //__TIZEN_MEDIA_STREAMRECORDER_INTERNAL_H__ + diff --git a/packaging/capi-media-streamrecorder.spec b/packaging/capi-media-streamrecorder.spec index dae81ac..28d05ec 100644 --- a/packaging/capi-media-streamrecorder.spec +++ b/packaging/capi-media-streamrecorder.spec @@ -1,6 +1,6 @@ Name: capi-media-streamrecorder Summary: A Streamrecorder library in Tizen Native API -Version: 0.0.25 +Version: 0.0.26 Release: 0 Group: Multimedia/Other License: Apache-2.0 @@ -80,6 +80,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %files devel %{_includedir}/media/streamrecorder.h +%{_includedir}/media/streamrecorder_internal.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-media-streamrecorder.so diff --git a/src/streamrecorder.c b/src/streamrecorder.c index d4d0dc3..83fb8bd 100644 --- a/src/streamrecorder.c +++ b/src/streamrecorder.c @@ -170,9 +170,9 @@ int streamrecorder_push_stream_buffer(streamrecorder_h recorder, media_packet_h } ret = mm_streamrecorder_push_stream_buffer(handle->mm_handle, MM_STREAM_TYPE_VIDEO, pts, video_buf, video_buf->size[0]); - } else if (mimetype == MEDIA_FORMAT_I420) { + } else if (mimetype == MEDIA_FORMAT_I420 || mimetype == MEDIA_FORMAT_BGRA) { void *buf_data = NULL; - + LOGI("mimetype: [%d]", mimetype); ret = media_packet_get_video_plane_data_ptr(packet, 0, (void **)&buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("buffer size get fail"); @@ -891,16 +891,12 @@ int streamrecorder_set_audio_channel(streamrecorder_h recorder, int channel_coun int streamrecorder_get_audio_channel(streamrecorder_h recorder, int *channel_count) { - int ret = STREAMRECORDER_ERROR_NONE; - if (recorder == NULL) { LOGE("NULL pointer handle"); return STREAMRECORDER_ERROR_INVALID_PARAMETER; } - ret = _streamrecorder_get_audio_channel(recorder, channel_count); - return ret; - + return _streamrecorder_get_audio_channel(recorder, channel_count); } static int __mm_streamrecorder_msg_cb(int message, void *param, void *user_data) diff --git a/src/streamrecorder_internal.c b/src/streamrecorder_internal.c new file mode 100644 index 0000000..5bec0a0 --- /dev/null +++ b/src/streamrecorder_internal.c @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_STREAMRECORDER" + +int streamrecorder_set_mode(streamrecorder_h recorder , streamrecorder_mode_e mode) +{ + int ret = MM_ERROR_NONE; + streamrecorder_s *handle = (streamrecorder_s *)recorder; + + if (recorder == NULL) { + LOGE("NULL pointer handle"); + return STREAMRECORDER_ERROR_INVALID_PARAMETER; + } + + if (mode > STREAMRECORDER_MODE_DEVICE_LOOPBACK) { + LOGE("invalid mode %d", mode); + return STREAMRECORDER_ERROR_INVALID_PARAMETER; + } + + ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL, + MMSTR_RECORDER_MODE, mode, + NULL); + return __convert_streamrecorder_error_code(__func__, ret); +} + +int streamrecorder_get_mode(streamrecorder_h recorder, streamrecorder_mode_e *mode) +{ + int ret = MM_ERROR_NONE; + int mm_mode = 0; + streamrecorder_s *handle = (streamrecorder_s *)recorder; + + if (recorder == NULL) { + LOGE("NULL pointer handle"); + return STREAMRECORDER_ERROR_INVALID_PARAMETER; + } + + if (mode == NULL) { + LOGE("mode is NULL"); + return STREAMRECORDER_ERROR_INVALID_PARAMETER; + } + + ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL, + MMSTR_RECORDER_MODE, &mm_mode, + NULL); + if (ret == MM_ERROR_NONE) { + switch (mm_mode) { + case MM_STREAMRECORDER_MODE_STREAM_BUFFER: + *mode = STREAMRECORDER_MODE_STREAM_BUFFER; + break; + case MM_STREAMRECORDER_MODE_DEVICE_LOOPBACK: + *mode = STREAMRECORDER_MODE_DEVICE_LOOPBACK; + break; + default: + ret = MM_ERROR_STREAMRECORDER_INTERNAL; + break; + } + } + return __convert_streamrecorder_error_code(__func__, ret); +} \ No newline at end of file diff --git a/src/streamrecorder_private.c b/src/streamrecorder_private.c index dcbb017..bef81dd 100644 --- a/src/streamrecorder_private.c +++ b/src/streamrecorder_private.c @@ -27,6 +27,11 @@ #include +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_STREAMRECORDER" + int __convert_streamrecorder_error_code(const char *func, int code) { @@ -164,11 +169,11 @@ int _streamrecorder_set_videosource_buffer(streamrecorder_h recorder) streamrecorder_s *handle = (streamrecorder_s *)recorder; mm_streamrecorder_set_attributes(handle->mm_handle, NULL, - MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_MEDIABUFFER, + MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_STREAM_BUFFER, NULL); mm_streamrecorder_set_attributes(handle->mm_handle, NULL, - MMSTR_VIDEO_ENABLE, true, + MMSTR_VIDEO_ENABLE, TRUE, NULL); @@ -182,11 +187,11 @@ int _streamrecorder_set_audiosource_buffer(streamrecorder_h recorder) streamrecorder_s *handle; handle = (streamrecorder_s *) recorder; mm_streamrecorder_set_attributes(handle->mm_handle, NULL, - MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_MEDIABUFFER, + MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_STREAM_BUFFER, NULL); mm_streamrecorder_set_attributes(handle->mm_handle, NULL, - MMSTR_AUDIO_ENABLE, true, + MMSTR_AUDIO_ENABLE, TRUE, NULL); return ret; @@ -992,5 +997,4 @@ int _streamrecorder_get_audio_channel(streamrecorder_h recorder, int *channel_co NULL); return __convert_streamrecorder_error_code(__func__, ret); -} - +} \ No newline at end of file diff --git a/test/streamrecorder_internal_loopback_test.c b/test/streamrecorder_internal_loopback_test.c new file mode 100644 index 0000000..6480bea --- /dev/null +++ b/test/streamrecorder_internal_loopback_test.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include +//#define DUMP 1 +#ifdef DUMP +#include +#endif + + +#define DEST_FILE "/tmp/test_with_suite.mp4" +#define WIDTH 1280 +#define HEIGHT 720 +#define FRAME_RATE 30 + +#define LOGD(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) +#define LOGE(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) +#define LOGW(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) + +typedef struct streamrecorder_data streamrecdata; + +struct streamrecorder_data { + streamrecorder_h streamrecorder; +}; + +static streamrecdata sdata; + +static void +streamrecorder_cb_notify(streamrecorder_state_e previous, + streamrecorder_state_e current, + streamrecorder_notify_e notification, + void *data) +{ + LOGD("streamrecorder_notify (prev: %d, curr: %d)", previous, current); +} + +static gboolean +_cb_finish(gpointer user_data) +{ + GMainLoop *loop = user_data; + streamrecorder_commit(sdata.streamrecorder); + g_main_loop_quit(loop); + return false; +} + +void _recording_status_cb(unsigned long long elapsed_time, unsigned long long file_size, void *user_data) +{ + g_print("elapsed time :%lld, file_size :%lld \r", elapsed_time, file_size); +} + +int +main(int argc, char *argv[]) +{ + streamrecorder_state_e state; + int err = 0; + int ret = 0; + streamrecorder_mode_e mode = STREAMRECORDER_MODE_DEVICE_LOOPBACK; + sdata.streamrecorder = NULL; + + err = streamrecorder_create(&sdata.streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_create()': %d", err); + return -1; + } + + err = streamrecorder_get_state(sdata.streamrecorder, &state); + if (err == STREAMRECORDER_ERROR_NONE) { + if (state == STREAMRECORDER_STATE_CREATED) { + LOGD("A state of StreamRecorder is 'Created'"); + } + else + LOGD("A state of StreamRecorder is '%d'", state); + } + + err = streamrecorder_set_notify_cb(sdata.streamrecorder, + streamrecorder_cb_notify, + &sdata); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_notify_cb()': %d", err); + ret = -1; + goto end; + } + + // err = streamrecorder_enable_source_buffer(sdata.streamrecorder, STREAMRECORDER_SOURCE_VIDEO_AUDIO); + // if (err != STREAMRECORDER_ERROR_NONE) { + // LOGE("failed 'streamrecorder_enable_source_buffer'"); + // return 0; + // } + + err = streamrecorder_set_mode(sdata.streamrecorder, STREAMRECORDER_MODE_DEVICE_LOOPBACK); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_mode'"); + return 0; + } + + err = streamrecorder_get_mode(sdata.streamrecorder, &mode); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_get_mode'"); + return 0; + } + + err = streamrecorder_set_video_resolution(sdata.streamrecorder, WIDTH, HEIGHT); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_video_resolution()'"); + return 0; + } + + err = streamrecorder_set_video_framerate(sdata.streamrecorder, FRAME_RATE); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_video_framerate()'"); + return 0; + } + + +//no to me + err = streamrecorder_set_recording_status_cb(sdata.streamrecorder, + _recording_status_cb, + NULL); + if (err != STREAMRECORDER_ERROR_NONE) + { + LOGE("failed to set callback for recording status"); + return 0; + } + err = streamrecorder_set_filename(sdata.streamrecorder, DEST_FILE); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_filename(): %d'", err); + return 0; + } + + err = streamrecorder_prepare(sdata.streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_prepare()': %d", err); + ret = -1; + goto end; + } + + err = streamrecorder_start(sdata.streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_start()': %d", err); + ret = -1; + goto end; + } + + GMainLoop *loop = g_main_loop_new(NULL, FALSE); + g_timeout_add_seconds(5, _cb_finish, loop); + g_main_loop_run(loop); + + g_main_loop_unref(loop); + +end: + streamrecorder_destroy(sdata.streamrecorder); + sdata.streamrecorder = NULL; + + return ret; +}