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