[mediastreamrecorder] change memory check and pass the media packet 62/58462/3 accepted/tizen/common/20160302.193538 accepted/tizen/ivi/20160302.072341 accepted/tizen/mobile/20160302.072254 accepted/tizen/tv/20160302.072312 accepted/tizen/wearable/20160302.072327 submit/tizen/20160302.023712
authorHyuntae, Kim <ht1211.kim@samsung.com>
Mon, 1 Feb 2016 08:35:35 +0000 (17:35 +0900)
committerHyuntae, Kim <ht1211.kim@samsung.com>
Tue, 2 Feb 2016 11:34:35 +0000 (20:34 +0900)
Change-Id: I4eee31fad72c7fc95d87fa45c1cc97eb7d8ed1fd

include/streamrecorder.h
include/streamrecorder_private.h
packaging/capi-media-streamrecorder.spec
src/streamrecorder.c
src/streamrecorder_private.c

index b9c8653..209cd21 100644 (file)
@@ -36,7 +36,7 @@ extern "C" {
  */
 
 #ifndef TIZEN_ERROR_STREAMRECORDER
-#define TIZEN_ERROR_STREAMRECORDER       -0x01B0000
+#define TIZEN_ERROR_STREAMRECORDER       -0x01A10000
 #endif /* TIZEN_ERROR_STREAMRECORDER */
 
 /**
index 223ece6..40e269c 100644 (file)
@@ -27,6 +27,8 @@
 extern "C" {
 #endif
 
+#define MAX_MPACKET_DATA 100
+
 typedef enum {
        _STREAMRECORDER_EVENT_TYPE_NOTIFY,
        _STREAMRECORDER_EVENT_TYPE_RECORDING_LIMITED,
@@ -37,9 +39,16 @@ typedef enum {
 }_streamrecorder_event_e;
 
 typedef struct {
+       media_packet_h packet[MAX_MPACKET_DATA];
+       void *consumed_buf[MAX_MPACKET_DATA];
+       bool is_video[MAX_MPACKET_DATA];
+}streamrecorder_mediapacket;
+
+typedef struct {
        MMHandleType mm_handle;
        void* user_cb[_STREAMRECORDER_EVENT_TYPE_NUM];
        void* user_data[_STREAMRECORDER_EVENT_TYPE_NUM];
+       streamrecorder_mediapacket *pkt;
        unsigned int state;
        _streamrecorder_event_e type;
        double last_max_input_level;
index 52fcd53..20a8389 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-streamrecorder
 Summary:    A Streamrecorder library in Tizen Native API
-Version:    0.0.2
+Version:    0.0.3
 Release:    0
 Group:      Multimedia/Other
 License:    Apache-2.0
index 6814ba3..1090c2c 100644 (file)
@@ -53,6 +53,9 @@ int streamrecorder_create(streamrecorder_h *recorder)
 
        memset(handle, 0 , sizeof(streamrecorder_s));
 
+       handle->pkt = (streamrecorder_mediapacket *)malloc(sizeof(streamrecorder_mediapacket));
+       memset(handle->pkt, 0, sizeof(streamrecorder_mediapacket));
+
        ret = mm_streamrecorder_create(&handle->mm_handle);
        if (ret != MM_ERROR_NONE) {
                free(handle);
@@ -107,12 +110,16 @@ int streamrecorder_push_stream_buffer(streamrecorder_h recorder, media_packet_h
        tbm_surface_h surface = NULL;
        int width;
        int height;
+       int i = 0;
+       bool is_full = FALSE;
+       streamrecorder_mediapacket *pkt = NULL;
 
        if ((recorder == NULL) || (packet == NULL)) {
                LOGE("[%s] INVALID_PARAMETER(0x%08x)", __func__, STREAMRECORDER_ERROR_INVALID_PARAMETER);
                return STREAMRECORDER_ERROR_INVALID_PARAMETER;
        }
        streamrecorder_s *handle = (streamrecorder_s *)recorder;
+       pkt = handle->pkt;
 
        /* pts */
        media_packet_get_pts(packet, &pts);
@@ -150,8 +157,21 @@ int streamrecorder_push_stream_buffer(streamrecorder_h recorder, media_packet_h
                        media_packet_get_video_stride_width(packet, 0, &video_buf->stride_height[0]);
                        video_buf->size[0] = width*height*3/2;
 
+                       for (i = 0; i < MAX_MPACKET_DATA; i++) {
+                               if (pkt->packet[i] == NULL) {
+                                       pkt->packet[i] = packet;
+                                       pkt->consumed_buf[i] = video_buf;
+                                       pkt->is_video[i] = TRUE;
+                                       break;
+                               } else {
+                                       if (i == MAX_MPACKET_DATA -1) {
+                                               free(video_buf);
+                                               return STREAMRECORDER_ERROR_OUT_OF_MEMORY;
+                                       }
+                               }
+                       }
+
                        ret = mm_streamrecorder_push_stream_buffer(handle->mm_handle, MM_STREAM_TYPE_VIDEO, pts, video_buf, video_buf->size[0]);
-                       free(video_buf);
                } else if (mimetype == MEDIA_FORMAT_I420) {
                        void *buf_data = NULL;
                        uint64_t buf_size = 0;
@@ -172,6 +192,7 @@ int streamrecorder_push_stream_buffer(streamrecorder_h recorder, media_packet_h
                if (flag) {
                        void *buf_data = NULL;
                        uint64_t buf_size = 0;
+
                        ret = media_packet_get_buffer_size(packet, &buf_size);
                        if (ret != MEDIA_PACKET_ERROR_NONE) {
                                LOGW("buffer size get fail");
@@ -182,6 +203,19 @@ int streamrecorder_push_stream_buffer(streamrecorder_h recorder, media_packet_h
                                LOGW("buffer size get fail");
                                return STREAMRECORDER_ERROR_INVALID_PARAMETER;
                        }
+
+                       for (i = 0; i < MAX_MPACKET_DATA; i++) {
+                               if (pkt->packet[i] == NULL) {
+                                       pkt->packet[i] = packet;
+                                       pkt->consumed_buf[i] = buf_data;
+                                       pkt->is_video[i] = FALSE;
+                                       break;
+                               } else {
+                                       if (i == MAX_MPACKET_DATA -1) {
+                                               return STREAMRECORDER_ERROR_OUT_OF_MEMORY;
+                                       }
+                               }
+                       }
                        ret = mm_streamrecorder_push_stream_buffer(handle->mm_handle, MM_STREAM_TYPE_AUDIO, pts, buf_data, buf_size);
                }
 
@@ -916,7 +950,27 @@ static int __mm_streamrecorder_msg_cb(int message, void *param, void *user_data)
        }       break;
        case MM_MESSAGE_STREAMRECORDER_CONSUME_COMPLETE:
        {
-               void *consume = (m->consumed_mediabuffer).consumed_buffer;
+               void *consume_data = (m->consumed_mediabuffer).consumed_buffer;
+               void *consume = NULL;
+               streamrecorder_mediapacket *pkt;
+               bool flag = FALSE;
+               int i = 0;
+
+               if (consume_data == NULL)
+                       break;
+
+               pkt = handle->pkt;
+
+               for (i = 0; i< MAX_MPACKET_DATA; i++) {
+                       if (pkt->consumed_buf[i] == consume_data) {
+                               consume = pkt->packet[i];
+                               if (pkt->is_video[i] == TRUE) {
+                                       free(pkt->consumed_buf[i]);             // MMVideoBuffer free
+                                       pkt->consumed_buf[i] = NULL;
+                               }
+                       }
+               }
+
                if (handle->user_cb[_STREAMRECORDER_EVENT_TYPE_CONSUME_COMPLETE]) {
                        ((streamrecorder_consume_completed_cb)handle->user_cb[_STREAMRECORDER_EVENT_TYPE_CONSUME_COMPLETE])(consume, handle->user_data[_STREAMRECORDER_EVENT_TYPE_CONSUME_COMPLETE]);
                }
index 9b1c116..abcf893 100644 (file)
@@ -252,6 +252,7 @@ int _streamrecorder_destroy(streamrecorder_h recorder)
        ret = mm_streamrecorder_destroy(handle->mm_handle);
 
        if (ret == MM_ERROR_NONE) {
+               free(handle->pkt);
                free(handle);
        }