c021363f6d2ebaa494a8579ae6b625d3c6dc3994
[platform/core/multimedia/libmm-wfd.git] / sink / include / mm_wfd_sink_util.h
1 /*
2  * libmm-wfd
3  *
4  * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, ByungWook Jang <bw.jang@samsung.com>,
7  * Maksym Ukhanov <m.ukhanov@samsung.com>, Hyunjun Ko <zzoon.ko@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifndef _MM_WFD_SINK_UTIL_H_
24 #define _MM_WFD_SINK_UTIL_H_
25
26 #include <glib.h>
27 #include <gst/gst.h>
28 #include <mm_message.h>
29 #include <mm_error.h>
30 #include <mm_types.h>
31 #include "mm_wfd_sink_dlog.h"
32
33 #define MMWFDSINK_FREEIF(x) \
34 do\
35 {\
36         if ( (x) ) \
37                 g_free( (gpointer)(x) ); \
38         (x) = NULL;\
39 } while(0);
40
41 /* lock for commnad */
42 #define MMWFDSINK_CMD_LOCK(x_wfd) \
43 if(x_wfd) \
44   g_mutex_lock(&(((mm_wfd_sink_t*)x_wfd)->cmd_lock));
45
46 #define MMWFDSINK_CMD_UNLOCK(x_wfd) \
47 if(x_wfd) \
48   g_mutex_unlock(&(((mm_wfd_sink_t*)x_wfd)->cmd_lock));
49
50 /* create element  */
51 #define MMWFDSINK_CREATE_ELEMENT(x_bin, x_id, x_factory, x_name, x_add_bucket) \
52 do \
53 { \
54         if ( x_name &&\
55                 ( strlen( x_factory ) > 1 )) \
56         {\
57                 x_bin[x_id].id = x_id;\
58                 x_bin[x_id].gst = gst_element_factory_make(x_factory, x_name);\
59                 if ( ! x_bin[x_id].gst )\
60                 {\
61                         wfd_sink_error("failed to create %s \n", x_factory);\
62                         goto CREATE_ERROR;\
63                 }\
64                 wfd_sink_debug("%s is created \n", x_factory);\
65                 if ( x_add_bucket )\
66                         element_bucket = g_list_append(element_bucket, &x_bin[x_id]);\
67         }\
68 } while(0);
69
70 /* generating dot */
71 #define MMWFDSINK_GENERATE_DOT_IF_ENABLED( x_wfd_sink, x_name ) \
72 if ( x_wfd_sink->ini.generate_dot ) \
73 { \
74         wfd_sink_debug ("create dot file : %s.dot", x_name);\
75         GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (x_wfd_sink->pipeline->mainbin[WFD_SINK_M_PIPE].gst), \
76                 GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
77 }
78
79 /* postint message */
80 #define MMWFDSINK_POST_MESSAGE( x_wfd_sink, x_error_type, x_state_type ) \
81 if (x_wfd_sink->msg_cb) \
82 { \
83         wfd_sink_debug("Message (error : %d, state : %d) will be posted using user callback\n", x_error_type, x_state_type); \
84         x_wfd_sink->msg_cb(x_error_type, x_state_type, x_wfd_sink->msg_user_data); \
85 }
86
87
88 /* state */
89 #define MMWFDSINK_CURRENT_STATE( x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.state
90 #define MMWFDSINK_PREVIOUS_STATE( x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.prev_state
91 #define MMWFDSINK_PENDING_STATE( x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.pending_state
92 #define MMWFDSINK_STATE_GET_NAME(x_state) __mm_wfds_sink_get_state_name(x_state)
93
94 #define MMWFDSINK_PRINT_STATE(x_wfd_sink) \
95 wfd_sink_debug("-- prev %s, current %s, pending %s --\n", \
96         MMWFDSINK_STATE_GET_NAME(MMWFDSINK_PREVIOUS_STATE(x_wfd_sink)), \
97         MMWFDSINK_STATE_GET_NAME(MMWFDSINK_CURRENT_STATE(x_wfd_sink)), \
98         MMWFDSINK_STATE_GET_NAME(MMWFDSINK_PENDING_STATE(x_wfd_sink)));
99
100 #define MMWFDSINK_CHECK_STATE( x_wfd_sink, x_cmd) \
101 switch ( __mm_wfd_sink_check_state((mm_wfd_sink_t *)x_wfd_sink, x_cmd) ) \
102 { \
103         case MM_ERROR_NONE: \
104                 break;\
105         case MM_ERROR_WFD_NO_OP: \
106                 return MM_ERROR_NONE; \
107                 break; \
108         default: \
109                 return MM_ERROR_WFD_INVALID_STATE; \
110                 break; \
111 }
112
113
114 /* pad probe */
115 void
116 mm_wfd_sink_util_add_pad_probe(GstPad *pad, GstElement *element, const gchar *pad_name);
117 void
118 mm_wfd_sink_util_add_pad_probe_for_checking_first_buffer(GstPad *pad, GstElement *element, const gchar *pad_name);
119
120 #define MMWFDSINK_PAD_PROBE( x_wfd_sink, x_pad, x_element, x_pad_name ) \
121 if ( x_wfd_sink ) \
122 {  \
123         if (x_wfd_sink->ini.enable_pad_probe ) \
124         { \
125                 mm_wfd_sink_util_add_pad_probe (x_pad, x_element, (const gchar*)x_pad_name); \
126         } \
127         else \
128         {\
129                 mm_wfd_sink_util_add_pad_probe_for_checking_first_buffer (x_pad, x_element, (const gchar*)x_pad_name); \
130         }\
131 }
132
133 void
134 mm_wfd_sink_util_add_pad_probe_for_data_dump(GstElement *element, const gchar *pad_name);
135
136 #define MMWFDSINK_TS_DATA_DUMP( x_wfd_sink, x_element, x_pad_name ) \
137 if ( x_wfd_sink && x_wfd_sink->ini.enable_ts_data_dump ) \
138 { \
139         mm_wfd_sink_util_add_pad_probe_for_data_dump (x_element, (const gchar*)x_pad_name); \
140 }
141
142 #endif