80d04bd2d6f6688314bc8293e2e4161956ad9fd2
[platform/core/multimedia/libmm-wfd.git] / src / include / mm_wfd_sink_priv.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_PRIV_H_
24 #define _MM_WFD_SINK_PRIV_H_
25
26 #include <string.h>
27 #include <stdlib.h>
28 #include <glib.h>
29 #include <gst/gst.h>
30 #include <mm_types.h>
31 #include <mm_attrs.h>
32 #include <mm_message.h>
33 #include <mm_error.h>
34 #include <mm_types.h>
35
36 #include "mm_wfd_sink_ini.h"
37 #include "mm_wfd_sink_attrs.h"
38 #include "mm_wfd_sink.h"
39
40 /* main pipeline's element id */
41 enum WFDSinkMainElementID {
42         WFD_SINK_M_PIPE = 0, /* NOTE : WFD_SINK_M_PIPE should be zero */
43         WFD_SINK_M_SRC,
44         WFD_SINK_M_DEPAY,
45         WFD_SINK_M_QUEUE,
46         WFD_SINK_M_D_VALVE,
47         WFD_SINK_M_DEMUX,
48         WFD_SINK_M_A_VALVE,
49         WFD_SINK_M_V_VALVE,
50         WFD_SINK_M_NUM
51 };
52
53 /* audio decodebin's element id */
54 enum WFDSinkAudioDecodeBinElementID {
55         WFD_SINK_A_D_BIN = 0, /* NOTE : WFD_SINK_A_D_BIN should be zero */
56         WFD_SINK_A_D_QUEUE,
57         WFD_SINK_A_D_HDCP,
58         WFD_SINK_A_D_AAC_PARSE,
59         WFD_SINK_A_D_AAC_DEC,
60         WFD_SINK_A_D_AC3_PARSE,
61         WFD_SINK_A_D_AC3_DEC,
62         WFD_SINK_A_D_LPCM_CONVERTER,
63         WFD_SINK_A_D_LPCM_FILTER,
64         WFD_SINK_A_D_NUM
65 };
66
67 /* audio sinkbin's element id */
68 enum WFDSinkAudioSinkBinElementID {
69         WFD_SINK_A_S_BIN = 0, /* NOTE : WFD_SINK_A_S_BIN should be zero */
70         WFD_SINK_A_S_RESAMPLER,
71         WFD_SINK_A_S_VOLUME,
72         WFD_SINK_A_S_QUEUE,
73         WFD_SINK_A_S_SINK,
74         WFD_SINK_A_S_NUM
75 };
76
77 /* video decodebin's element id */
78 enum WFDSinkVideoDecodeBinElementID {
79         WFD_SINK_V_D_BIN = 0, /* NOTE : WFD_SINK_V_D_BIN should be zero */
80         WFD_SINK_V_D_QUEUE,
81         WFD_SINK_V_D_HDCP,
82         WFD_SINK_V_D_H264_PARSE,
83         WFD_SINK_V_D_H264_DEC,
84         WFD_SINK_V_D_H265_PARSE,
85         WFD_SINK_V_D_H265_DEC,
86         WFD_SINK_V_D_NUM
87 };
88
89 /* video sinkbin's element id */
90 enum WFDSinkVideoSinkBinElementID {
91         WFD_SINK_V_S_BIN = 0, /* NOTE : WFD_SINK_V_S_BIN should be zero */
92         WFD_SINK_V_S_CONVERT,
93         WFD_SINK_V_S_FILTER,
94         WFD_SINK_V_S_SINK,
95         WFD_SINK_V_S_NUM
96 };
97
98 /**
99  *  * Enumerations of wifi-display command.
100  *   */
101 typedef enum {
102         MM_WFD_SINK_COMMAND_NONE,               /**< command for nothing */
103         MM_WFD_SINK_COMMAND_CREATE,             /**< command for creating wifi-display sink */
104         MM_WFD_SINK_COMMAND_PREPARE,            /**< command for preparing wifi-display sink */
105         MM_WFD_SINK_COMMAND_CONNECT,    /**< command for connecting wifi-display sink  */
106         MM_WFD_SINK_COMMAND_START,       /**< command for starting wifi-display sink  */
107         MM_WFD_SINK_COMMAND_PAUSE,       /**< command for pausing wifi-display sink  */
108         MM_WFD_SINK_COMMAND_RESUME,      /**< command for resuming wifi-display sink  */
109         MM_WFD_SINK_COMMAND_DISCONNECT, /**< command for disconnecting wifi-display sink  */
110         MM_WFD_SINK_COMMAND_UNPREPARE,          /**< command for unpreparing wifi-display sink  */
111         MM_WFD_SINK_COMMAND_DESTROY,            /**< command for destroting wifi-display sink  */
112         MM_WFD_SINK_COMMAND_NUM,                /**< Number of wifi-display commands */
113 } MMWFDSinkCommandType;
114
115 /**
116  *  * Enumerations of thread command.
117  *   */
118 typedef enum {
119         WFD_SINK_MANAGER_CMD_NONE = 0,
120         WFD_SINK_MANAGER_CMD_LINK_A_DECODEBIN,
121         WFD_SINK_MANAGER_CMD_LINK_V_DECODEBIN,
122         WFD_SINK_MANAGER_CMD_PREPARE_A_PIPELINE,
123         WFD_SINK_MANAGER_CMD_PREPARE_V_PIPELINE,
124         WFD_SINK_MANAGER_CMD_UNPREPARE_A_PIPELINE,
125         WFD_SINK_MANAGER_CMD_UNPREPARE_V_PIPELINE,
126         WFD_SINK_MANAGER_CMD_EXIT,
127 } WFDSinkManagerCMDType;
128
129 /**
130  *  * Enumerations of resolution.
131  *   */
132 typedef enum {
133         MM_WFD_SINK_RESOLUTION_UNKNOWN = 0,
134         MM_WFD_SINK_RESOLUTION_1920x1080_P30 = (1 << 0),  /**< W-1920, H-1080, 30 fps*/
135         MM_WFD_SINK_RESOLUTION_1280x720_P30 = (1 << 1),   /**< W-1280, H-720, 30 fps*/
136         MM_WFD_SINK_RESOLUTION_960x540_P30 = (1 << 2),    /**< W-960, H-540, 30 fps*/
137         MM_WFD_SINK_RESOLUTION_864x480_P30 = (1 << 3),    /**< W-864, H-480, 30 fps*/
138         MM_WFD_SINK_RESOLUTION_720x480_P60 = (1 << 4),    /**< W-720, H-480, 30 fps*/
139         MM_WFD_SINK_RESOLUTION_640x480_P60 = (1 << 5),    /**< W-640, H-480, 60 fps*/
140         MM_WFD_SINK_RESOLUTION_640x360_P30 = (1 << 6),    /**< W-640, H-360, 30 fps*/
141         MM_WFD_SINK_RESOLUTION_MAX = 128,
142 } MMWFDSinkResolution;
143
144 typedef struct {
145         gint codec;
146         gint width;
147         gint height;
148         gint frame_rate;
149 } MMWFDSinkVideoStreamInfo;
150
151 typedef struct {
152         gint codec;
153         gint channels;
154         gint sample_rate;
155         gint bitwidth;
156 } MMWFDSinkAudioStreamInfo;
157
158 typedef struct {
159         MMWFDSinkAudioStreamInfo audio_stream_info;
160         MMWFDSinkVideoStreamInfo video_stream_info;
161 } MMWFDSinkStreamInfo;
162
163
164 typedef struct {
165         gint id;
166         GstElement *gst;
167 } MMWFDSinkGstElement;
168
169 typedef struct {
170         MMWFDSinkGstElement     *mainbin;
171         MMWFDSinkGstElement     *a_decodebin;
172         MMWFDSinkGstElement     *v_decodebin;
173         MMWFDSinkGstElement     *a_sinkbin;
174         MMWFDSinkGstElement     *v_sinkbin;
175 } MMWFDSinkGstPipelineInfo;
176
177 typedef struct {
178         MMWFDSinkStateType state;         /* wfd current state */
179         MMWFDSinkStateType prev_state;    /* wfd  previous state */
180         MMWFDSinkStateType pending_state; /* wfd  state which is going to now */
181 } MMWFDSinkState;
182
183 /* priv func */
184 typedef struct {
185         int(*prepare)(MMHandleType wfd_sink);
186         int(*connect)(MMHandleType wfd_sink, const char *uri);
187         int(*start)(MMHandleType wfd_sink);
188         int(*pause)(MMHandleType wfd_sink);
189         int(*resume)(MMHandleType wfd_sink);
190         int(*disconnect)(MMHandleType wfd_sink);
191         int(*unprepare)(MMHandleType wfd_sink);
192 } MMWFDSinkPrivateFunc;
193
194 #define MMWFDSINK_GET_ATTRS(x_wfd) ((x_wfd) ? ((mm_wfd_sink_t*)x_wfd)->attrs : (MMHandleType)NULL)
195
196 typedef struct {
197         /* gstreamer pipeline */
198         MMWFDSinkGstPipelineInfo *pipeline;
199         gboolean audio_decodebin_is_linked;
200         gboolean video_decodebin_is_linked;
201         gulong update_stream_info_sig_id;
202         gulong change_av_format_sig_id;
203
204         /* timestamp compensation */
205         gboolean need_to_reset_basetime;
206
207         GstClock *clock;
208         gint64 video_average_gap;
209         gint64 video_accumulated_gap;
210         gint64 video_buffer_count;
211         gint64 audio_average_gap;
212         gint64 audio_accumulated_gap;
213         gint64 audio_buffer_count;
214         GstClockTime last_buffer_timestamp;
215
216         /* attributes */
217         MMHandleType attrs;
218
219         /* state */
220         MMWFDSinkState state;
221
222         /* initialize values */
223         mm_wfd_sink_ini_t ini;
224
225         /* command */
226         MMWFDSinkCommandType cmd;
227         GMutex cmd_lock;
228         gboolean waiting_cmd;
229
230         /* stream information */
231         MMWFDSinkStreamInfo stream_info;
232
233         /* Message handling */
234         MMWFDMessageCallback msg_cb;
235         void *msg_user_data;
236
237         /* video resolution for negotiation */
238         MMWFDSinkResolution supportive_resolution;
239
240         GThread         *manager_thread;
241         GMutex manager_thread_mutex;
242         GCond manager_thread_cond;
243         GList *manager_thread_cmd;
244         gboolean manager_thread_exit;
245
246         MMWFDSinkPrivateFunc *func_table;
247         MMHandleType extend_handle;
248         guint msg_callback_id;
249
250 } mm_wfd_sink_t;
251
252
253 int _mm_wfd_sink_create(mm_wfd_sink_t **wfd_sink, const char *ini_path);
254 int _mm_wfd_sink_destroy(mm_wfd_sink_t *wfd_sink);
255 int _mm_wfd_sink_prepare(mm_wfd_sink_t *wfd_sink);
256 int _mm_wfd_sink_unprepare(mm_wfd_sink_t *wfd_sink);
257 int _mm_wfd_sink_connect(mm_wfd_sink_t *wfd_sink, const char *uri);
258 int _mm_wfd_sink_disconnect(mm_wfd_sink_t *wfd_sink);
259 int _mm_wfd_sink_start(mm_wfd_sink_t *wfd_sink);
260 int _mm_wfd_sink_pause(mm_wfd_sink_t *wfd_sink);
261 int _mm_wfd_sink_resume(mm_wfd_sink_t *wfd_sink);
262 int _mm_wfd_set_message_callback(mm_wfd_sink_t *wfd_sink, MMWFDMessageCallback callback, void *user_data);
263 int _mm_wfd_sink_set_resolution(mm_wfd_sink_t *wfd_sink, MMWFDSinkResolution resolution);
264
265 int __mm_wfd_sink_link_audio_decodebin(mm_wfd_sink_t *wfd_sink);
266 int __mm_wfd_sink_link_video_decodebin(mm_wfd_sink_t *wfd_sink);
267 int __mm_wfd_sink_prepare_video_pipeline(mm_wfd_sink_t *wfd_sink, GstPad **sinkpad);
268 int __mm_wfd_sink_prepare_audio_pipeline(mm_wfd_sink_t *wfd_sink, GstPad **sinkpad);
269 int __mm_wfd_sink_unprepare_audio_pipeline(mm_wfd_sink_t *wfd_sink);
270 int __mm_wfd_sink_unprepare_video_pipeline(mm_wfd_sink_t *wfd_sink);
271 int __mm_wfd_sink_activate_audio_stream(mm_wfd_sink_t *wfd_sink);
272 int __mm_wfd_sink_activate_video_stream(mm_wfd_sink_t *wfd_sink);
273 int __mm_wfd_sink_deactivate_audio_stream(mm_wfd_sink_t *wfd_sink, gboolean unprepare);
274 int __mm_wfd_sink_deactivate_video_stream(mm_wfd_sink_t *wfd_sink, gboolean unprepare);
275
276 const gchar *_mm_wfds_sink_get_state_name(MMWFDSinkStateType state);
277 int __mm_wfd_sink_check_state(mm_wfd_sink_t *wfd_sink, MMWFDSinkCommandType cmd);
278 int __mm_wfd_sink_create_audio_decodebin(mm_wfd_sink_t *wfd_sink);
279 int __mm_wfd_sink_create_video_decodebin(mm_wfd_sink_t *wfd_sink);
280 int __mm_wfd_sink_create_video_sinkbin(mm_wfd_sink_t *wfd_sink);
281 int __mm_wfd_sink_create_audio_sinkbin(mm_wfd_sink_t *wfd_sink);
282 void __mm_wfd_sink_print_ref_count(mm_wfd_sink_t *wfd_sink);
283 int __mm_wfd_sink_gst_element_add_bucket_to_bin(GstBin *bin, GList *element_bucket, gboolean need_prepare);
284 int __mm_wfd_sink_gst_element_link_bucket(GList *element_bucket);
285 #endif