4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #ifndef __MM_STREAMRECORDER_H__
23 #define __MM_STREAMRECORDER_H__
25 /*=======================================================================================
27 ========================================================================================*/
32 #include <mm_message.h>
38 /*=======================================================================================
39 | GLOBAL DEFINITIONS AND DECLARATIONS FOR STREAMRECORDER |
40 ========================================================================================*/
42 /*=======================================================================================
44 ========================================================================================*/
46 /* Attributes Macros */
48 #define MMSTR_VIDEO_ENABLE "video-enable"
50 #define MMSTR_VIDEO_BUFFER_TYPE "videobuffer-type"
52 #define MMSTR_VIDEO_SOURCE_FORMAT "videosource-format"
54 #define MMSTR_VIDEO_FRAMERATE "video-framerate"
56 #define MMSTR_VIDEO_BITRATE "video-bitrate"
58 #define MMSTR_VIDEO_RESOLUTION_WIDTH "video-resolution-width"
60 #define MMSTR_VIDEO_RESOLUTION_HEIGHT "video-resolution-height"
63 * Disable Audio stream when record.
65 #define MMSTR_AUDIO_ENABLE "audio-enable"
67 #define MMSTR_AUDIO_SOURCE_FORMAT "audio-source-format"
69 #define MMSTR_AUDIO_BITRATE "audio-bitrate"
71 #define MMSTR_AUDIO_SAMPLERATE "audio-samplerate"
73 #define MMSTR_VIDEO_ENCODER "video-encoder"
75 #define MMSTR_AUDIO_ENCODER "audio-encoder"
77 #define MMSTR_AUDIO_CHANNEL "audio-channel-count"
79 #define MMSTR_FILE_FORMAT "file-format"
81 #define MMSTR_FILENAME "filename"
83 #define MMSTR_RECORDER_MODE "recorder-mode"
85 #define MMSTR_TARGET_MAX_SIZE "target-max-size"
87 #define MMSTR_TARGET_TIME_LIMIT "target-time-limit"
89 /*=======================================================================================
91 ========================================================================================*/
93 * An enumeration for streamrecorder states.
96 MM_STREAMRECORDER_STATE_NONE, /**< Streamrecorder is not created yet */
97 MM_STREAMRECORDER_STATE_CREATED, /**< Streamrecorder is created, but not initialized yet */
98 MM_STREAMRECORDER_STATE_PREPARED, /**< Streamrecorder is prepared to record */
99 MM_STREAMRECORDER_STATE_RECORDING, /**< Streamrecorder is now recording */
100 MM_STREAMRECORDER_STATE_PAUSED, /**< Streamrecorder is paused while recording */
101 MM_STREAMRECORDER_STATE_NUM, /**< Number of streamrecorder states */
102 } MMStreamRecorderStateType;
105 * An enumeration of Audio Format.
108 MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8 = 0, /**< unsigned 8bit audio */
109 MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE = 2, /**< signed 16bit audio. Little endian. */
110 } MMStreamRecorderAudioFormat;
112 /**********************************
114 **********************************/
118 MM_STREAM_TYPE_VIDEO,
119 MM_STREAM_TYPE_AUDIO,
120 } MMStreamRecorderStreamType;
122 /*=======================================================================================
123 | STRUCTURE DEFINITIONS |
124 ========================================================================================*/
126 /* General Structure */
128 * An enumeration for streamrecorder mode.
132 MM_STREAMRECORDER_MODE_MEDIABUFFER = 0, /**< Recording with mediabuffer */
133 MM_STREAMRECORDER_MODE_SCREENRECORD, /**< Recording with screenrecord */
134 } MMStreamRecorderModeType;
137 MM_STREAMRECORDER_VIDEO_TYPE_TBM_BO, /**< TBM BO type */
138 MM_STREAMRECORDER_VIDEO_TYPE_NORMAL_BUFFER, /**< Normal Raw data buffer */
139 } MMStreamRecorderVideoBufType;
142 MM_STREAMRECORDER_INPUT_FORMAT_INVALID = -1,/**< Invalid pixel format */
143 MM_STREAMRECORDER_INPUT_FORMAT_NV12, /**< NV12 pixel format */
144 MM_STREAMRECORDER_INPUT_FORMAT_NV21, /**< NV21 pixel format */
145 MM_STREAMRECORDER_INPUT_FORMAT_I420, /**< I420 pixel format */
146 MM_STREAMRECORDER_INPUT_FORMAT_UYVY, /**< UYVY pixel format */
147 MM_STREAMRECORDER_INPUT_FORMAT_YUYV, /**< YUYV pixel format */
148 MM_STREAMRECORDER_INPUT_FORMAT_BGRA8888, /**< BGRA8888 pixel format */
149 MM_STREAMRECORDER_INPUT_FORMAT_NUM /**< Number of the pixel format */
150 } MMStreamRecorderVideoSourceFormat;
152 /**********************************
154 **********************************/
157 * Report structure of recording file
160 char *recording_filename; /**< File name of stored recording file. Please free after using. */
161 } MMStreamRecordingReport; /**< report structure definition of recording file */
164 * An enumeration for attribute values types.
167 MM_STR_REC_ATTRS_TYPE_INVALID = -1, /**< Type is invalid */
168 MM_STR_REC_ATTRS_TYPE_INT, /**< Integer type attribute */
169 MM_STR_REC_ATTRS_TYPE_DOUBLE, /**< Double type attribute */
170 MM_STR_REC_ATTRS_TYPE_STRING, /**< UTF-8 String type attribute */
171 MM_STR_REC_ATTRS_TYPE_DATA, /**< Pointer type attribute */
172 } MMStreamRecorderAttrsType;
175 * An enumeration for attribute validation type.
178 MM_STR_REC_ATTRS_VALID_TYPE_INVALID = -1, /**< Invalid validation type */
179 MM_STR_REC_ATTRS_VALID_TYPE_NONE, /**< Do not check validity */
180 MM_STR_REC_ATTRS_VALID_TYPE_INT_ARRAY, /**< validity checking type of integer array */
181 MM_STR_REC_ATTRS_VALID_TYPE_INT_RANGE, /**< validity checking type of integer range */
182 MM_STR_REC_ATTRS_VALID_TYPE_DOUBLE_ARRAY, /**< validity checking type of double array */
183 MM_STR_REC_ATTRS_VALID_TYPE_DOUBLE_RANGE, /**< validity checking type of double range */
184 } MMStreamRecorderAttrsValidType;
187 * An enumeration for attribute access flag.
190 MM_STR_REC_ATTRS_FLAG_DISABLED = 0, /**< None flag is set. This means the attribute is not allowed to use. */
191 MM_STR_REC_ATTRS_FLAG_READABLE = 1 << 0,/**< Readable */
192 MM_STR_REC_ATTRS_FLAG_WRITABLE = 1 << 1,/**< Writable */
193 MM_STR_REC_ATTRS_FLAG_MODIFIED = 1 << 2,/**< Modified */
194 MM_STR_REC_ATTRS_FLAG_RW = MM_STR_REC_ATTRS_FLAG_READABLE | MM_STR_REC_ATTRS_FLAG_WRITABLE,
195 /**< Readable and Writable */
196 } MMStreamRecorderAttrsFlag;
199 * A structure for attribute information
202 MMStreamRecorderAttrsType type;
203 MMStreamRecorderAttrsFlag flag;
204 MMStreamRecorderAttrsValidType validity_type;
207 * A union that describes validity of the attribute.
211 * Validity structure for integer array.
214 int *array; /**< a pointer of array */
215 int count; /**< size of array */
216 int def; /**< default value. Real value not index of array */
220 * Validity structure for integer range.
223 int min; /**< minimum range */
224 int max; /**< maximum range */
225 int def; /**< default value */
229 * Validity structure for double array.
232 double *array; /**< a pointer of array */
233 int count; /**< size of array */
234 double def; /**< default value. Real value not index of array */
238 * Validity structure for double range.
241 double min; /**< minimum range */
242 double max; /**< maximum range */
243 double def; /**< default value */
246 } MMStreamRecorderAttrsInfo;
249 /*=======================================================================================
251 ========================================================================================*/
252 /*=======================================================================================
253 | GLOBAL FUNCTION PROTOTYPES |
254 ========================================================================================*/
256 * mm_streamrecorder_create:\n
257 * Create streamrecorder object. This is the function that an user who wants to use mm_streamrecorder calls first.
258 * This function creates handle structure and initialize mutex, attributes, gstreamer.
259 * When this function success, it will return a handle of newly created object.
260 * A user have to put the handle when he calls every function of mm_streamrecorder. \n
262 * @param[out] streamrecorder A handle of streamrecorder.
263 * @param[in] info Information for devices
264 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
265 * Please refer 'mm_error.h' to know the exact meaning of the error.
266 * @see mm_streamrecorder_destroy
268 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_CREATED
269 * @remarks You can create multiple handles on a context at the same time. However,
270 * streamrecordercorder cannot guarantee proper operation because of limitation of resources.
274 #include <mm_streamrecorder.h>
276 gboolean initialize_streamrecorder()
280 err = mm_streamrecorder_create(&hstream);
282 if (err != MM_ERROR_NONE) {
293 int mm_streamrecorder_create(MMHandleType *streamrecorder);
296 * mm_streamrecorder_destroy:\n
297 * Destroy streamrecorder object. Release handle and all of the resources that were created in mm_streamrecorder_create().\n
298 * This is the finalizing function of mm_streamrecorder. If this function is not called or fails to call, the handle isn't released fully.
299 * This function releases attributes, mutexes, sessions, and handle itself. This function also removes all of remaining messages.
300 * So if your application should wait a certain message of mm_streamrecorder, please wait to call this function till getting the message.
303 * @param[in] streamrecorder A handle of streamrecorder.
304 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
305 * Please refer 'mm_error.h' to know the exact meaning of the error.
306 * @see mm_streamrecorder_create
307 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_CREATED
308 * @post Because the handle is not valid, you can't check the state.
313 #include <mm_streamrecorder.h>
315 gboolean destroy_streamrecorder()
319 //Destroy streamrecorder handle
320 err = mm_streamrecorder_destroy(hstreamrecorder);
332 int mm_streamrecorder_destroy(MMHandleType streamrecorder);
335 * mm_streamrecorder_realize:\n
336 * Allocate resources for streamrecorder and initialize it.
337 * This also creates streamer pipeline. So you have to set attributes that are pivotal to create
338 * the pipeline before calling this function. This function also takes a roll to manage confliction
339 * between different applications which use streamrecorder. For example, if you try to use streamrecorder when
340 * other application that is more important such as call application, this function will return
341 * 'MM_ERROR_POLICY_BLOCKED'. On the contrary, if your application that uses streamrecorder starts to launch
342 * while another application that uses speaker and has lower priority, your application will kick
343 * another application.
345 * @param[in] streamrecorder A handle of streamrecorder.
346 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
347 * Please refer 'mm_error.h' to know the exact meaning of the error.
348 * @see mm_streamrecorder_unrealize
349 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_CREATED
350 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_READY
355 int mm_streamrecorder_realize(MMHandleType streamrecorder);
358 * mm_streamrecorder_unrealize:\n
359 * Uninitialize streamrecoder resources and free allocated memory.
360 * Most important resource that is released here is gstreamer pipeline of mm_streamrecorder.
361 * Because most of resources are operating on the gstreamer pipeline,
362 * this function should be called to release its resources.
363 * Moreover, mm_streamrecorder is controlled by audio session manager. If an user doesn't call this function when he want to release mm_streamrecorder,
364 * other multimedia frameworks may face session problem. For more detail information, please refer mm_session module.
366 * @param[in] streamrecorder A handle of streamrecorder.
367 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
368 * Please refer 'mm_error.h' to know the exact meaning of the error.
369 * @see mm_streamrecorder_realize
370 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_READY
371 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_CREATED
376 int mm_streamrecorder_unrealize(MMHandleType streamrecorder);
379 * mm_streamrecorder_start:\n
380 * Start previewing. (Image/Video mode)
382 * @param[in] streamrecorder A handle of streamrecorder.
383 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
384 * Please refer 'mm_error.h' to know the exact meaning of the error.
385 * @see mm_streamrecorder_stop
386 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_READY
387 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_PREPARED
392 int mm_streamrecorder_record(MMHandleType streamrecorder);
395 * mm_streamrecorder_pause:\n
396 * Pause A/V recording or Audio recording. (Audio/Video mode only)
398 * @param[in] streamrecorder A handle of streamrecorder.
399 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
400 * Please refer 'mm_error.h' to know the exact meaning of the error.
401 * @see mm_streamrecorder_record
402 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_RECORDING
403 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_PAUSED
404 * @remarks Even though this function is for pausing recording, small amount of buffers could be recorded after pause().
405 * Because the buffers which are existed in the queue were created before pause(), the buffers should be recorded.
407 int mm_streamrecorder_pause(MMHandleType streamrecorder);
410 * mm_streamrecorder_stop:\n
411 * Stop previewing. (Image/Video mode)
412 * This function will change the status of pipeline.
414 * @param[in] streamrecorder A handle of streamrecorder.
415 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
416 * Please refer 'mm_error.h' to know the exact meaning of the error.
417 * @see mm_streamrecorder_start
418 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_PREPARED
419 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_READY
424 #include <mm_streamrecorder.h>
426 gboolean stop_streamrecorder()
431 err = mm_streamrecorder_stop(hstreamrecorder);
441 int mm_streamrecorder_commit(MMHandleType streamrecorder);
443 int mm_streamrecorder_cancel(MMHandleType streamrecorder);
445 int mm_streamrecorder_push_stream_buffer(MMHandleType streamrecorder, MMStreamRecorderStreamType streamtype, unsigned long timestamp, void *buffer, int size);
448 * mm_streamrecorder_commit:\n
449 * Stop recording and save results. (Audio/Video mode only)\n
450 * After starting recording, encoded data frame will be stored in the location specified in MMSTR_FILENAME.
451 * Some encoder or muxer require a certain type of finalizing such as adding some information to header.
452 * This function takes that roll. So if you don't call this function after recording, the result file may not be playable.\n
453 * Because this is the function for saving the recording result, the operation is available
455 * @param[in] streamrecorder A handle of streamrecorder.
456 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
457 * Please refer 'mm_error.h' to know the exact meaning of the error.
458 * @see mm_streamrecorder_cancel
459 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_RECORDING
460 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_PREPARED
461 * @remarks This function can take a few second when recording time is long.
462 * and if there are only quite few input buffer from video src or audio src,
463 * committing could be failed.
467 #include <mm_streamrecorder.h>
469 gboolean record_and_save_video_file()
474 err = mm_streamrecorder_record(hstreamrecorder);
479 // Wait while recording for test...
480 // In normal case, mm_streamrecorder_record() and mm_streamrecorder_commit() aren't called in the same function.
483 err = mm_streamrecorder_commit(hstreamrecorder);
493 int mm_streamrecorder_commit(MMHandleType streamrecorder);
496 * mm_streamrecorder_cancel:\n
497 * Stop recording and discard the result. (Audio/Video mode only)
498 * When a user want to finish recording without saving the result file, this function can be used.
499 * Like mm_streamrecorder_commit(), this function also stops recording, release related resources(like codec) ,and goes back to preview status.
500 * However, instead of saving file, this function unlinks(delete) the result.\n
501 * Because this is the function for canceling recording, the operation is available
503 * @param[in] streamrecorder A handle of streamrecorder.
504 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
505 * Please refer 'mm_error.h' to know the exact meaning of the error.
506 * @see mm_streamrecorder_commit
507 * @pre Previous state of mm-streamrecorder should be MM_STREAMRECORDER_STATE_RECORDING
508 * @post Next state of mm-streamrecorder will be MM_STREAMRECORDER_STATE_PREPARED
513 #include <mm_streamrecorder.h>
515 gboolean record_and_cancel_video_file()
520 err = mm_streamrecorder_record(hstreamrecorder);
525 // Wait while recording...
528 err = mm_streamrecorder_cancel(hstreamrecorder);
538 int mm_streamrecorder_cancel(MMHandleType streamrecorder);
541 * mm_streamrecorder_set_message_callback:\n
542 * Set callback for receiving messages from streamrecorder. Through this callback function, streamrecorder
543 * sends various message including status changes, asynchronous error, capturing, and limitations.
544 * One thing you have to know is that message callback is working on the main loop of application.
545 * So until releasing the main loop, message callback will not be called.
547 * @param[in] streamrecorder A handle of streamrecorder.
548 * @param[in] callback Function pointer of callback function. Please refer 'MMMessageCallback'.
549 * @param[in] user_data User parameter for passing to callback function.
550 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
551 * Please refer 'mm_error.h' to know the exact meaning of the error.
552 * @see MMMessageCallback
555 * @remarks registered 'callback' is called on main loop of the application. So until the main loop is released, 'callback' will not be called.
559 #include <mm_streamrecorder.h>
561 gboolean setting_msg_callback()
564 mm_streamrecorder_set_message_callback(hstreamrecorder,(MMMessageCallback)msg_callback, (void*)hstreamrecorder);
571 int mm_streamrecorder_set_message_callback(MMHandleType streamrecorder, MMMessageCallback callback, void *user_data);
574 * mm_streamrecorder_get_attributes:\n
575 * Get attributes of streamrecorder with given attribute names. This function can get multiple attributes
576 * simultaneously. If one of attribute fails, this function will stop at the point.
577 * 'err_attr_name' let you know the name of the attribute.
579 * @param[in] streamrecorder Specifies the streamrecorder handle.
580 * @param[out] err_attr_name Specifies the name of attributes that made an error. If the function doesn't make an error, this will be null. @n
581 * Free this variable after using.
582 * @param[in] attribute_name attribute name that user want to get.
583 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
584 * Please refer 'mm_error.h' to know the exact meaning of the error.
587 * @remarks You can retrieve multiple attributes at the same time. @n
588 * This function must finish with 'NULL' argument. @n
589 * ex) mm_streamrecorder_get_attributes(....... , NULL);
590 * @see mm_streamrecorder_set_attributes
592 int mm_streamrecorder_get_attributes(MMHandleType streamrecorder, char **err_attr_name, const char *attribute_name, ...) G_GNUC_NULL_TERMINATED;
595 * mm_streamrecorder_set_attributes:\n
596 * Set attributes of streamrecorder with given attribute names. This function can set multiple attributes
597 * simultaneously. If one of attribute fails, this function will stop at the point.
598 * 'err_attr_name' let you know the name of the attribute.
600 * @param[in] streamrecorder Specifies the streamrecorder handle.
601 * @param[out] err_attr_name Specifies the name of attributes that made an error. If the function doesn't make an error, this will be null. @n
602 * Free this variable after using.
603 * @param[in] attribute_name attribute name that user want to set.
604 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
605 * Please refer 'mm_error.h' to know the exact meaning of the error.
608 * @remarks You can put multiple attributes to streamrecorder at the same time. @n
609 * This function must finish with 'NULL' argument. @n
610 * ex) mm_streamrecorder_set_attributes(....... , NULL);
611 * @see mm_streamrecorder_get_attributes
613 int mm_streamrecorder_set_attributes(MMHandleType streamrecorder, char **err_attr_name, const char *attribute_name, ...) G_GNUC_NULL_TERMINATED;
616 * mm_streamrecorder_get_attribute_info:\n
617 * Get detail information of the attribute. To manager attributes, an user may want to know the exact character of the attribute,
618 * such as type, flag, and validity. This is the function to provide such information.
619 * Depending on the 'validity_type', validity union would be different. To know about the type of union, please refer 'MMStreamRecorderAttrsInfo'.
621 * @param[in] streamrecorder Specifies the streamrecorder handle.
622 * @param[in] attribute_name attribute name that user want to get information.
623 * @param[out] info a structure that holds information related with the attribute.
624 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
625 * Please refer 'mm_error.h' to know the exact meaning of the error.
628 * @remarks If the function succeeds, 'info' holds detail information about the attribute, such as type,
629 * flag, validity_type, validity_values, and default values.
630 * @see mm_streamrecorder_get_attributes, mm_streamrecorder_set_attributes
633 int mm_streamrecorder_get_attribute_info(MMHandleType streamrecorder, const char *attribute_name, MMStreamRecorderAttrsInfo *info);
636 * mm_streamrecorder_get_state:\n
637 * Get the current state of streamreccorder.
638 * mm_streamrecorderr is working on the base of its state. An user should check the state of mm_streamrecorder before calling its functions.
639 * If the handle is avaiable, user can retrieve the value.
641 * @param[in] streamrecorder A handle of streamrecorder.
642 * @param[out] state On return, it contains current state of streamrecorder.
643 * @return This function returns zero(MM_ERROR_NONE) on success, or negative value with error code.\n
644 * Please refer 'mm_error.h' to know the exact meaning of the error.
645 * @see MMStreamRecorderStateType
650 int mm_streamrecorder_get_state(MMHandleType streamrecorder, MMStreamRecorderStateType *status);
660 #endif /* __MM_STREAMRECORDER_H__ */