c5745637b5294bb2a22f952d191c8b36b22ae552
[platform/core/api/mediacodec.git] / include / media_codec_private.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __TIZEN_MEDIA_CODEC_PRIVATE_H__
18 #define __TIZEN_MEDIA_CODEC_PRIVATE_H__
19
20 #include <tizen.h>
21 #include <stdint.h>
22 #include <glib.h>
23
24 #include <media_codec.h>
25
26 #include <mm_types.h>
27 #include <mm_resource_manager.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #ifdef LOG_TAG
34 #undef LOG_TAG
35 #endif
36 #define LOG_TAG "TIZEN_N_MEDIACODEC"
37
38
39 #define MEDIACODEC_CHECK_CONDITION(condition, error, msg)     \
40         if (condition) {} else \
41         {LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error; }; \
42
43 #define MEDIACODEC_INSTANCE_CHECK(mediacodec)   \
44         MEDIACODEC_CHECK_CONDITION(mediacodec != NULL, MEDIACODEC_ERROR_INVALID_PARAMETER, "MEDIACODEC_ERROR_INVALID_PARAMETER")
45
46 #define MEDIACODEC_STATE_CHECK(mediacodec, expected_state)       \
47         MEDIACODEC_CHECK_CONDITION(mediacodec->state == expected_state, MEDIACODEC_ERROR_INVALID_STATE, "MEDIACODEC_ERROR_INVALID_STATE")
48
49 #define MEDIACODEC_NULL_ARG_CHECK(arg)      \
50         MEDIACODEC_CHECK_CONDITION(arg != NULL, MEDIACODEC_ERROR_INVALID_PARAMETER, "MEDIACODEC_ERROR_INVALID_PARAMETER")
51
52 #define MEDIACODEC_SUPPORT_CHECK(arg)       \
53         MEDIACODEC_CHECK_CONDITION(arg != false, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE, "MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE")
54 /**
55  * @brief Enumeration of media codec state
56  * @since_tizen 2.3
57  */
58 typedef enum {
59         MEDIACODEC_STATE_NONE = 0,      /**< Media codec is not created */
60         MEDIACODEC_STATE_IDLE,          /**< Media codec is created, but not prepared */
61         MEDIACODEC_STATE_READY,         /**< Media codec is ready to process */
62         MEDIACODEC_STATE_EXCUTE,        /**< Media codec is executing media */
63 } mediacodec_state_e;
64
65 typedef enum {
66         MEDIACODEC_SUPPORT_TYPE_OMX = 0x10,     /**< This is optional flag for using openmax il */
67         MEDIACODEC_SUPPORT_TYPE_GEN = 0x20      /**< This is optional flag for using general codec */
68 } mediacodec_internal_support_type_e;
69
70 typedef enum {
71         MEDIACODEC_PORT_TYPE_GENERAL,
72         MEDIACODEC_PORT_TYPE_OMX,
73         MEDIACODEC_PORT_TYPE_GST,
74         MEDIACODEC_PORT_TYPE_MAX,
75 } mediacodec_port_type_e;
76
77 /**
78  * @brief Media Codec's format for configuring codec.
79  */
80 typedef struct _mediacodecformat_s {
81         /* Video */
82         int fps;
83         int height;
84         int width;
85         float aspect;
86         bool vfr;
87         int level;
88         int profile;
89
90         /* Audio */
91         int channels;
92         int samplerate;
93         int bitrate;
94
95         /* Codec Extra Data */
96         void * extradata;
97         unsigned int extrasize;
98 } mediacodec_format_s;
99
100 typedef struct _mediacodec_s {
101         MMHandleType mc_handle;
102         int state;
103         bool is_omx;
104         char *m_mime;
105         mm_resource_manager_res_h codec_resource;
106
107         mediacodec_input_buffer_used_cb empty_buffer_cb;
108         void* empty_buffer_cb_userdata;
109         mediacodec_output_buffer_available_cb fill_buffer_cb;
110         void* fill_buffer_cb_userdata;
111         mediacodec_error_cb error_cb;
112         void* error_cb_userdata;
113         mediacodec_eos_cb eos_cb;
114         void* eos_cb_userdata;
115         mediacodec_buffer_status_cb buffer_status_cb;
116         void* buffer_status_cb_userdata;
117         mediacodec_supported_codec_cb supported_codec_cb;
118         void* supported_codec_cb_userdata;
119 } mediacodec_s;
120
121 bool __mediacodec_state_validate(mediacodec_h mediacodec, mediacodec_state_e threshold);
122
123 #ifdef __cplusplus
124 }
125 #endif
126
127 #endif /* __TIZEN_MEDIA_CODEC_PRIVATE_H__ */