1. Use wfdtsdemux instead of tsdemux.
[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                 if ((x)) \
36                         g_free((gpointer)(x)); \
37                 (x) = NULL;\
38         } while (0);
39
40 /* lock for commnad */
41 #define MMWFDSINK_CMD_LOCK(x_wfd) \
42         if (x_wfd) \
43                 g_mutex_lock(&(((mm_wfd_sink_t *)x_wfd)->cmd_lock));
44
45 #define MMWFDSINK_CMD_UNLOCK(x_wfd) \
46         if (x_wfd) \
47                 g_mutex_unlock(&(((mm_wfd_sink_t *)x_wfd)->cmd_lock));
48
49 /* create element  */
50 #define MMWFDSINK_CREATE_ELEMENT(x_bin, x_id, x_factory, x_name, x_add_bucket) \
51         do      { \
52                 if (x_name && (strlen(x_factory) > 1)) {\
53                         x_bin[x_id].id = x_id;\
54                         x_bin[x_id].gst = gst_element_factory_make(x_factory, x_name);\
55                         if (! x_bin[x_id].gst)  {\
56                                 wfd_sink_error("failed to create %s \n", x_factory);\
57                                 goto CREATE_ERROR;\
58                         }\
59                         wfd_sink_debug("%s is created \n", x_factory);\
60                         if (x_add_bucket)\
61                                 element_bucket = g_list_append(element_bucket, &x_bin[x_id]);\
62                 }\
63         } while (0);
64
65 /* generating dot */
66 #define MMWFDSINK_GENERATE_DOT_IF_ENABLED(x_wfd_sink, x_name) \
67         if (x_wfd_sink->ini.generate_dot) { \
68                 wfd_sink_debug("create dot file : %s.dot", x_name);\
69                 GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(x_wfd_sink->pipeline->mainbin[WFD_SINK_M_PIPE].gst), \
70                                            GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
71         }
72
73 /* postint message */
74 #define MMWFDSINK_POST_MESSAGE(x_wfd_sink, x_error_type, x_state_type) \
75         if (x_wfd_sink->msg_cb) { \
76                 wfd_sink_debug("Message(error : %d, state : %d) will be posted using user callback\n", x_error_type, x_state_type); \
77                 x_wfd_sink->msg_cb(x_error_type, x_state_type, x_wfd_sink->msg_user_data); \
78         }
79
80
81 /* state */
82 #define MMWFDSINK_CURRENT_STATE(x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.state
83 #define MMWFDSINK_PREVIOUS_STATE(x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.prev_state
84 #define MMWFDSINK_PENDING_STATE(x_wfd_sink) ((mm_wfd_sink_t *)x_wfd_sink)->state.pending_state
85 #define MMWFDSINK_STATE_GET_NAME(x_state) __mm_wfds_sink_get_state_name(x_state)
86
87 #define MMWFDSINK_PRINT_STATE(x_wfd_sink) \
88         wfd_sink_debug("--prev %s, current %s, pending %s--\n", \
89                        MMWFDSINK_STATE_GET_NAME(MMWFDSINK_PREVIOUS_STATE(x_wfd_sink)), \
90                        MMWFDSINK_STATE_GET_NAME(MMWFDSINK_CURRENT_STATE(x_wfd_sink)), \
91                        MMWFDSINK_STATE_GET_NAME(MMWFDSINK_PENDING_STATE(x_wfd_sink)));
92
93 #define MMWFDSINK_CHECK_STATE(x_wfd_sink, x_cmd) \
94         switch (__mm_wfd_sink_check_state((mm_wfd_sink_t *)x_wfd_sink, x_cmd)) \
95         { \
96         case MM_ERROR_NONE: \
97                 break;\
98         case MM_ERROR_WFD_NO_OP: \
99                 return MM_ERROR_NONE; \
100                 break; \
101         default: \
102                 return MM_ERROR_WFD_INVALID_STATE; \
103                 break; \
104         }
105
106
107 /* pad probe */
108 void
109 mm_wfd_sink_util_add_pad_probe(GstPad *pad, GstElement *element, const gchar *pad_name);
110 void
111 mm_wfd_sink_util_add_pad_probe_for_checking_first_buffer(GstPad *pad, GstElement *element, const gchar *pad_name);
112
113 #define MMWFDSINK_PAD_PROBE(x_wfd_sink, x_pad, x_element, x_pad_name) \
114         if (x_wfd_sink) {  \
115                 if (x_wfd_sink->ini.enable_pad_probe) { \
116                         mm_wfd_sink_util_add_pad_probe(x_pad, x_element, (const gchar*)x_pad_name); \
117                 } else {\
118                         mm_wfd_sink_util_add_pad_probe_for_checking_first_buffer (x_pad, x_element, (const gchar*)x_pad_name); \
119                 }\
120         }
121
122 void
123 mm_wfd_sink_util_add_pad_probe_for_data_dump(GstElement *element, const gchar *pad_name);
124
125 #define MMWFDSINK_TS_DATA_DUMP(x_wfd_sink, x_element, x_pad_name) \
126         if (x_wfd_sink && x_wfd_sink->ini.enable_ts_data_dump) { \
127                 mm_wfd_sink_util_add_pad_probe_for_data_dump (x_element, (const gchar*)x_pad_name); \
128         }
129
130 #endif