mm_qcamera_video.c revision 6f83d735d8e3b918da42e6b559fcd0efb78133e5
1/*
2Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are
6met:
7    * Redistributions of source code must retain the above copyright
8      notice, this list of conditions and the following disclaimer.
9    * Redistributions in binary form must reproduce the above
10      copyright notice, this list of conditions and the following
11      disclaimer in the documentation and/or other materials provided
12      with the distribution.
13    * Neither the name of The Linux Foundation nor the names of its
14      contributors may be used to endorse or promote products derived
15      from this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#include "mm_qcamera_dbg.h"
31#include "mm_qcamera_app.h"
32
33static void mm_app_video_notify_cb(mm_camera_super_buf_t *bufs,
34                                   void *user_data)
35{
36    char file_name[64];
37    mm_camera_buf_def_t *frame = bufs->bufs[0];
38    mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
39
40    CDBG("%s: BEGIN - length=%d, frame idx = %d\n",
41         __func__, frame->frame_len, frame->frame_idx);
42    snprintf(file_name, sizeof(file_name), "V_C%d", pme->cam->camera_handle);
43    mm_app_dump_frame(frame, file_name, "yuv", frame->frame_idx);
44
45    if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
46                                            bufs->ch_id,
47                                            frame)) {
48        CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
49    }
50    mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
51                     ION_IOC_INV_CACHES);
52
53    CDBG("%s: END\n", __func__);
54}
55
56mm_camera_stream_t * mm_app_add_video_stream(mm_camera_test_obj_t *test_obj,
57                                             mm_camera_channel_t *channel,
58                                             mm_camera_buf_notify_t stream_cb,
59                                             void *userdata,
60                                             uint8_t num_bufs)
61{
62    int rc = MM_CAMERA_OK;
63    mm_camera_stream_t *stream = NULL;
64    cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
65
66    stream = mm_app_add_stream(test_obj, channel);
67    if (NULL == stream) {
68        CDBG_ERROR("%s: add stream failed\n", __func__);
69        return NULL;
70    }
71
72    stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
73    stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
74    stream->s_config.mem_vtbl.user_data = (void *)stream;
75    stream->s_config.stream_cb = stream_cb;
76    stream->s_config.userdata = userdata;
77    stream->num_of_bufs = num_bufs;
78
79    stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
80    memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
81    stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_VIDEO;
82    stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
83    stream->s_config.stream_info->fmt = DEFAULT_VIDEO_FORMAT;
84    stream->s_config.stream_info->dim.width = DEFAULT_VIDEO_WIDTH;
85    stream->s_config.stream_info->dim.height = DEFAULT_VIDEO_HEIGHT;
86    stream->s_config.padding_info = cam_cap->padding_info;
87
88    rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
89    if (MM_CAMERA_OK != rc) {
90        CDBG_ERROR("%s:config preview stream err=%d\n", __func__, rc);
91        return NULL;
92    }
93
94    return stream;
95}
96
97mm_camera_channel_t * mm_app_add_video_channel(mm_camera_test_obj_t *test_obj)
98{
99    mm_camera_channel_t *channel = NULL;
100    mm_camera_stream_t *stream = NULL;
101
102    channel = mm_app_add_channel(test_obj,
103                                 MM_CHANNEL_TYPE_VIDEO,
104                                 NULL,
105                                 NULL,
106                                 NULL);
107    if (NULL == channel) {
108        CDBG_ERROR("%s: add channel failed", __func__);
109        return NULL;
110    }
111
112    stream = mm_app_add_video_stream(test_obj,
113                                     channel,
114                                     mm_app_video_notify_cb,
115                                     (void *)test_obj,
116                                     1);
117    if (NULL == stream) {
118        CDBG_ERROR("%s: add video stream failed\n", __func__);
119        mm_app_del_channel(test_obj, channel);
120        return NULL;
121    }
122
123    return channel;
124}
125
126int mm_app_start_record_preview(mm_camera_test_obj_t *test_obj)
127{
128    int rc = MM_CAMERA_OK;
129    mm_camera_channel_t *p_ch = NULL;
130    mm_camera_channel_t *v_ch = NULL;
131    mm_camera_channel_t *s_ch = NULL;
132
133    p_ch = mm_app_add_preview_channel(test_obj);
134    if (NULL == p_ch) {
135        CDBG_ERROR("%s: add preview channel failed", __func__);
136        return -MM_CAMERA_E_GENERAL;
137    }
138
139    v_ch = mm_app_add_video_channel(test_obj);
140    if (NULL == v_ch) {
141        CDBG_ERROR("%s: add video channel failed", __func__);
142        mm_app_del_channel(test_obj, p_ch);
143        return -MM_CAMERA_E_GENERAL;
144    }
145
146    s_ch = mm_app_add_snapshot_channel(test_obj);
147    if (NULL == s_ch) {
148        CDBG_ERROR("%s: add snapshot channel failed", __func__);
149        mm_app_del_channel(test_obj, p_ch);
150        mm_app_del_channel(test_obj, v_ch);
151        return -MM_CAMERA_E_GENERAL;
152    }
153
154    rc = mm_app_start_channel(test_obj, p_ch);
155    if (MM_CAMERA_OK != rc) {
156        CDBG_ERROR("%s:start preview failed rc=%d\n", __func__, rc);
157        mm_app_del_channel(test_obj, p_ch);
158        mm_app_del_channel(test_obj, v_ch);
159        mm_app_del_channel(test_obj, s_ch);
160        return rc;
161    }
162
163    return rc;
164}
165
166int mm_app_stop_record_preview(mm_camera_test_obj_t *test_obj)
167{
168    int rc = MM_CAMERA_OK;
169    mm_camera_channel_t *p_ch = NULL;
170    mm_camera_channel_t *v_ch = NULL;
171    mm_camera_channel_t *s_ch = NULL;
172
173    p_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_PREVIEW);
174    v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
175    s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
176
177    rc = mm_app_stop_and_del_channel(test_obj, p_ch);
178    if (MM_CAMERA_OK != rc) {
179        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
180    }
181
182    rc = mm_app_stop_and_del_channel(test_obj, v_ch);
183    if (MM_CAMERA_OK != rc) {
184        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
185    }
186
187    rc = mm_app_stop_and_del_channel(test_obj, s_ch);
188    if (MM_CAMERA_OK != rc) {
189        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
190    }
191
192    return rc;
193}
194
195int mm_app_start_record(mm_camera_test_obj_t *test_obj)
196{
197    int rc = MM_CAMERA_OK;
198    mm_camera_channel_t *v_ch = NULL;
199
200    v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
201
202    rc = mm_app_start_channel(test_obj, v_ch);
203    if (MM_CAMERA_OK != rc) {
204        CDBG_ERROR("%s:start recording failed rc=%d\n", __func__, rc);
205    }
206
207    return rc;
208}
209
210int mm_app_stop_record(mm_camera_test_obj_t *test_obj)
211{
212    int rc = MM_CAMERA_OK;
213    mm_camera_channel_t *v_ch = NULL;
214
215    v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
216
217    rc = mm_app_stop_channel(test_obj, v_ch);
218    if (MM_CAMERA_OK != rc) {
219        CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc);
220    }
221
222    return rc;
223}
224
225int mm_app_start_live_snapshot(mm_camera_test_obj_t *test_obj)
226{
227    int rc = MM_CAMERA_OK;
228    mm_camera_channel_t *s_ch = NULL;
229
230    s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
231
232    rc = mm_app_start_channel(test_obj, s_ch);
233    if (MM_CAMERA_OK != rc) {
234        CDBG_ERROR("%s:start recording failed rc=%d\n", __func__, rc);
235    }
236
237    return rc;
238}
239
240int mm_app_stop_live_snapshot(mm_camera_test_obj_t *test_obj)
241{
242    int rc = MM_CAMERA_OK;
243    mm_camera_channel_t *s_ch = NULL;
244
245    s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
246
247    rc = mm_app_stop_channel(test_obj, s_ch);
248    if (MM_CAMERA_OK != rc) {
249        CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc);
250    }
251
252    return rc;
253}
254