5be6d3136108633b333d4789af79fc6ccce8818c
[platform/core/multimedia/libmm-wfd.git] / sink / 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 #include <mm_wfd_sink_ini.h>
36 #include <mm_wfd_attrs.h>
37
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 pipeline's element id */
50 enum WFDSinkAudioElementID {
51         WFD_SINK_A_BIN = 0, /* NOTE : WFD_SINK_A_BIN should be zero */
52         WFD_SINK_A_QUEUE,
53         WFD_SINK_A_HDCP,
54         WFD_SINK_A_AAC_PARSE,
55         WFD_SINK_A_AAC_DEC,
56         WFD_SINK_A_AC3_PARSE,
57         WFD_SINK_A_AC3_DEC,
58         WFD_SINK_A_LPCM_CONVERTER,
59         WFD_SINK_A_LPCM_FILTER,
60         WFD_SINK_A_CAPSFILTER,
61         WFD_SINK_A_RESAMPLER,
62         WFD_SINK_A_VOLUME,
63         WFD_SINK_A_SINK,
64         WFD_SINK_A_NUM
65 };
66
67 /* video pipeline's element id */
68 enum WFDSinkVideoElementID {
69         WFD_SINK_V_BIN = 0, /* NOTE : WFD_SINK_V_BIN should be zero */
70         WFD_SINK_V_QUEUE,
71         WFD_SINK_V_HDCP,
72         WFD_SINK_V_PARSE,
73         WFD_SINK_V_CAPSSETTER,
74         WFD_SINK_V_DEC,
75         WFD_SINK_V_CONVERT,
76         WFD_SINK_V_CAPSFILTER,
77         WFD_SINK_V_SINK,
78         WFD_SINK_V_NUM
79 };
80
81 /**
82  *  * Enumerations of wifi-display command.
83  *   */
84 typedef enum {
85         MM_WFD_SINK_COMMAND_NONE,               /**< command for nothing */
86         MM_WFD_SINK_COMMAND_CREATE,             /**< command for creating wifi-display sink */
87         MM_WFD_SINK_COMMAND_PREPARE,            /**< command for preparing wifi-display sink */
88         MM_WFD_SINK_COMMAND_CONNECT,    /**< command for connecting wifi-display sink  */
89         MM_WFD_SINK_COMMAND_START,       /**< command for starting wifi-display sink  */
90         MM_WFD_SINK_COMMAND_PAUSE,       /**< command for pausing wifi-display sink  */
91         MM_WFD_SINK_COMMAND_RESUME,      /**< command for resuming wifi-display sink  */
92         MM_WFD_SINK_COMMAND_DISCONNECT, /**< command for disconnecting wifi-display sink  */
93         MM_WFD_SINK_COMMAND_UNPREPARE,          /**< command for unpreparing wifi-display sink  */
94         MM_WFD_SINK_COMMAND_DESTROY,            /**< command for destroting wifi-display sink  */
95         MM_WFD_SINK_COMMAND_NUM,                /**< Number of wifi-display commands */
96 } MMWFDSinkCommandType;
97
98 /**
99  *  * Enumerations of thread command.
100  *   */
101 typedef enum {
102         WFD_SINK_MANAGER_CMD_NONE = 0,
103         WFD_SINK_MANAGER_CMD_LINK_A_BIN = (1 << 0),
104         WFD_SINK_MANAGER_CMD_LINK_V_BIN = (1 << 1),
105         WFD_SINK_MANAGER_CMD_PREPARE_A_BIN = (1 << 2),
106         WFD_SINK_MANAGER_CMD_PREPARE_V_BIN = (1 << 3),
107         WFD_SINK_MANAGER_CMD_EXIT = (1 << 8)
108 } WFDSinkManagerCMDType;
109
110 /**
111  *  * Enumerations of resolution.
112  *   */
113 typedef enum {
114         MM_WFD_SINK_RESOLUTION_UNKNOWN = 0,
115         MM_WFD_SINK_RESOLUTION_1920x1080_P30 = (1 << 0),  /**< W-1920, H-1080, 30 fps*/
116         MM_WFD_SINK_RESOLUTION_1280x720_P30 = (1 << 1),   /**< W-1280, H-720, 30 fps*/
117         MM_WFD_SINK_RESOLUTION_960x540_P30 = (1 << 2),    /**< W-960, H-540, 30 fps*/
118         MM_WFD_SINK_RESOLUTION_864x480_P30 = (1 << 3),    /**< W-864, H-480, 30 fps*/
119         MM_WFD_SINK_RESOLUTION_720x480_P60 = (1 << 4),    /**< W-720, H-480, 30 fps*/
120         MM_WFD_SINK_RESOLUTION_640x480_P60 = (1 << 5),    /**< W-640, H-480, 60 fps*/
121         MM_WFD_SINK_RESOLUTION_640x360_P30 = (1 << 6),    /**< W-640, H-360, 30 fps*/
122         MM_WFD_SINK_RESOLUTION_MAX = 128,
123 } MMWFDSinkResolution;
124
125 typedef struct {
126         gint codec;
127         gint width;
128         gint height;
129         gint frame_rate;
130 } MMWFDSinkVideoStreamInfo;
131
132 typedef struct {
133         gint codec;
134         gint channels;
135         gint sample_rate;
136         gint bitwidth;
137 } MMWFDSinkAudioStreamInfo;
138
139 typedef struct {
140         MMWFDSinkAudioStreamInfo audio_stream_info;
141         MMWFDSinkVideoStreamInfo video_stream_info;
142 } MMWFDSinkStreamInfo;
143
144
145 typedef struct {
146         gint id;
147         GstElement *gst;
148 } MMWFDSinkGstElement;
149
150 typedef struct {
151         MMWFDSinkGstElement     *mainbin;
152         MMWFDSinkGstElement     *audiobin;
153         MMWFDSinkGstElement     *videobin;
154 } MMWFDSinkGstPipelineInfo;
155
156 typedef struct {
157         MMWFDSinkStateType state;         /* wfd current state */
158         MMWFDSinkStateType prev_state;    /* wfd  previous state */
159         MMWFDSinkStateType pending_state; /* wfd  state which is going to now */
160 } MMWFDSinkState;
161
162 #define MMWFDSINK_GET_ATTRS(x_wfd) ((x_wfd)? ((mm_wfd_sink_t*)x_wfd)->attrs : (MMHandleType)NULL)
163
164 typedef struct {
165         /* gstreamer pipeline */
166         MMWFDSinkGstPipelineInfo *pipeline;
167         gint added_av_pad_num;
168         gboolean audio_bin_is_linked;
169         gboolean video_bin_is_linked;
170         GstPad *prev_audio_dec_src_pad;
171         GstPad *next_audio_dec_sink_pad;
172
173         /* timestamp compensation */
174         gboolean need_to_reset_basetime;
175
176         GstClock *clock;
177         gint64 video_average_gap;
178         gint64 video_accumulated_gap;
179         gint64 video_buffer_count;
180         gint64 audio_average_gap;
181         gint64 audio_accumulated_gap;
182         gint64 audio_buffer_count;
183         GstClockTime last_buffer_timestamp;
184
185         /* attributes */
186         MMHandleType attrs;
187
188         /* state */
189         MMWFDSinkState state;
190
191         /* initialize values */
192         mm_wfd_sink_ini_t ini;
193
194         /* command */
195         MMWFDSinkCommandType cmd;
196         GMutex cmd_lock;
197         gboolean waiting_cmd;
198
199         /* stream information */
200         MMWFDSinkStreamInfo stream_info;
201
202         /* Message handling */
203         MMWFDMessageCallback msg_cb;
204         void *msg_user_data;
205
206         /* audio session manager related variables */
207         GList *resource_list;
208
209         /* video resolution for negotiation */
210         MMWFDSinkResolution supportive_resolution;
211
212         GThread         *manager_thread;
213         GMutex manager_thread_mutex;
214         GCond manager_thread_cond;
215         WFDSinkManagerCMDType manager_thread_cmd;
216 } mm_wfd_sink_t;
217
218
219 int _mm_wfd_sink_create(mm_wfd_sink_t **wfd_sink);
220 int _mm_wfd_sink_destroy(mm_wfd_sink_t *wfd_sink);
221 int _mm_wfd_sink_prepare(mm_wfd_sink_t *wfd_sink);
222 int _mm_wfd_sink_unprepare(mm_wfd_sink_t *wfd_sink);
223 int _mm_wfd_sink_connect(mm_wfd_sink_t *wfd_sink, const char *uri);
224 int _mm_wfd_sink_disconnect(mm_wfd_sink_t *wfd_sink);
225 int _mm_wfd_sink_start(mm_wfd_sink_t *wfd_sink);
226 int _mm_wfd_sink_pause(mm_wfd_sink_t *wfd_sink);
227 int _mm_wfd_sink_resume(mm_wfd_sink_t *wfd_sink);
228 int _mm_wfd_set_message_callback(mm_wfd_sink_t *wfd_sink, MMWFDMessageCallback callback, void *user_data);
229 int _mm_wfd_sink_get_resource(mm_wfd_sink_t *wfd_sink);
230 int _mm_wfd_sink_set_resolution(mm_wfd_sink_t *wfd_sink, MMWFDSinkResolution resolution);
231
232 int __mm_wfd_sink_link_audiobin(mm_wfd_sink_t *wfd_sink);
233 int __mm_wfd_sink_link_videobin(mm_wfd_sink_t *wfd_sink);
234 int __mm_wfd_sink_prepare_videobin(mm_wfd_sink_t *wfd_sink);
235 int __mm_wfd_sink_prepare_audiobin(mm_wfd_sink_t *wfd_sink);
236
237 const gchar *_mm_wfds_sink_get_state_name(MMWFDSinkStateType state);
238
239 #endif
240