7962af7c82f7b6ea78302134f8510024bba0cf2a
[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 {
43         WFD_SINK_M_PIPE = 0, /* NOTE : WFD_SINK_M_PIPE should be zero */
44         WFD_SINK_M_SRC,
45         WFD_SINK_M_DEPAY,
46         WFD_SINK_M_DEMUX,
47         WFD_SINK_M_NUM
48 };
49
50 /* audio pipeline's element id */
51 enum WFDSinkAudioElementID
52 {
53         WFD_SINK_A_BIN = 0, /* NOTE : WFD_SINK_A_BIN should be zero */
54         WFD_SINK_A_QUEUE,
55         WFD_SINK_A_HDCP,
56         WFD_SINK_A_AAC_PARSE,
57         WFD_SINK_A_AAC_DEC,
58         WFD_SINK_A_AC3_PARSE,
59         WFD_SINK_A_AC3_DEC,
60         WFD_SINK_A_LPCM_CONVERTER,
61         WFD_SINK_A_LPCM_FILTER,
62         WFD_SINK_A_CAPSFILTER,
63         WFD_SINK_A_RESAMPLER,
64         WFD_SINK_A_VOLUME,
65         WFD_SINK_A_SINK,
66         WFD_SINK_A_NUM
67 };
68
69 /* video pipeline's element id */
70 enum WFDSinkVideoElementID
71 {
72         WFD_SINK_V_BIN = 0, /* NOTE : WFD_SINK_V_BIN should be zero */
73         WFD_SINK_V_QUEUE,
74         WFD_SINK_V_HDCP,
75         WFD_SINK_V_PARSE,
76         WFD_SINK_V_DEC,
77         WFD_SINK_V_CONVERT,
78         WFD_SINK_V_SINK,
79         WFD_SINK_V_NUM
80 };
81
82 /* audio codec : AAC, AC3, LPCM  */
83 enum WFDSinkAudioCodec
84 {
85         WFD_SINK_AUDIO_CODEC_NONE,
86         WFD_SINK_AUDIO_CODEC_AAC = 0x0F,
87         WFD_SINK_AUDIO_CODEC_AC3 = 0x81,
88         WFD_SINK_AUDIO_CODEC_LPCM = 0x83
89 };
90
91 /* video codec : H264  */
92 enum WFDSinkVideoCodec
93 {
94         WFD_SINK_VIDEO_CODEC_NONE,
95         WFD_SINK_VIDEO_CODEC_H264 = 0x1b
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_DISCONNECT, /**< command for disconnecting wifi-display sink  */
108         MM_WFD_SINK_COMMAND_UNPREPARE,          /**< command for unpreparing wifi-display sink  */
109         MM_WFD_SINK_COMMAND_DESTROY,            /**< command for destroting wifi-display sink  */
110         MM_WFD_SINK_COMMAND_NUM,                /**< Number of wifi-display commands */
111 } MMWFDSinkCommandType;
112
113 /**
114  *  * Enumerations of thread command.
115  *   */
116 typedef enum {
117         WFD_SINK_MANAGER_CMD_NONE = 0,
118         WFD_SINK_MANAGER_CMD_LINK_A_BIN = (1 << 0),
119         WFD_SINK_MANAGER_CMD_LINK_V_BIN = (1 << 1),
120         WFD_SINK_MANAGER_CMD_PREPARE_A_BIN = (1 << 2),
121         WFD_SINK_MANAGER_CMD_PREPARE_V_BIN = (1 << 3),
122         WFD_SINK_MANAGER_CMD_EXIT = (1 << 8)
123 } WFDSinkManagerCMDType;
124
125 typedef struct
126 {
127         gint codec;
128         gint width;
129         gint height;
130         gint frame_rate;
131 }MMWFDSinkVideoStreamInfo;
132
133 typedef struct
134 {
135         gint codec;
136         gint channels;
137         gint sample_rate;
138         gint bitwidth;
139 }MMWFDSinkAudioStreamInfo;
140
141 typedef struct
142 {
143         MMWFDSinkAudioStreamInfo audio_stream_info;
144         MMWFDSinkVideoStreamInfo video_stream_info;
145 }MMWFDSinkStreamInfo;
146
147
148 typedef struct
149 {
150         gint id;
151         GstElement *gst;
152 } MMWFDSinkGstElement;
153
154 typedef struct
155 {
156         MMWFDSinkGstElement     *mainbin;
157         MMWFDSinkGstElement     *audiobin;
158         MMWFDSinkGstElement     *videobin;
159 } MMWFDSinkGstPipelineInfo;
160
161 typedef struct
162 {
163         MMWFDSinkStateType state;         // wfd current state
164         MMWFDSinkStateType prev_state;    // wfd  previous state
165         MMWFDSinkStateType pending_state; // wfd  state which is going to now
166 } MMWFDSinkState;
167
168 #define MMWFDSINK_GET_ATTRS(x_wfd) ((x_wfd)? ((mm_wfd_sink_t*)x_wfd)->attrs : (MMHandleType)NULL)
169
170 typedef struct {
171         /* gstreamer pipeline */
172         MMWFDSinkGstPipelineInfo *pipeline;
173         gint added_av_pad_num;
174         gboolean audio_bin_is_linked;
175         gboolean video_bin_is_linked;
176         GstPad * prev_audio_dec_src_pad;
177         GstPad * next_audio_dec_sink_pad;
178
179         /* timestamp compensation */
180         gboolean need_to_reset_basetime;
181
182         GstClock *clock;
183         gint64 video_average_gap;
184         gint64 video_accumulated_gap;
185         gint64 video_buffer_count;
186         gint64 audio_average_gap;
187         gint64 audio_accumulated_gap;
188         gint64 audio_buffer_count;
189         GstClockTime last_buffer_timestamp;
190
191         /* attributes */
192         MMHandleType attrs;
193
194         /* state */
195         MMWFDSinkState state;
196
197         /* initialize values */
198         mm_wfd_sink_ini_t ini;
199
200         /* command */
201         MMWFDSinkCommandType cmd;
202         GMutex cmd_lock;
203         gboolean waiting_cmd;
204
205         /* stream information */
206         MMWFDSinkStreamInfo stream_info;
207
208         /* Message handling */
209         MMWFDMessageCallback msg_cb;
210         void *msg_user_data;
211
212         /* audio session manager related variables */
213         GList *resource_list;
214
215         GThread         *manager_thread;
216         GMutex manager_thread_mutex;
217         GCond manager_thread_cond;
218         WFDSinkManagerCMDType manager_thread_cmd;
219 } mm_wfd_sink_t;
220
221
222 int _mm_wfd_sink_create(mm_wfd_sink_t **wfd_sink);
223 int _mm_wfd_sink_destroy(mm_wfd_sink_t *wfd_sink);
224 int _mm_wfd_sink_prepare(mm_wfd_sink_t *wfd_sink);
225 int _mm_wfd_sink_unprepare(mm_wfd_sink_t *wfd_sink);
226 int _mm_wfd_sink_connect(mm_wfd_sink_t *wfd_sink, const char *uri);
227 int _mm_wfd_sink_disconnect(mm_wfd_sink_t *wfd_sink);
228 int _mm_wfd_sink_start(mm_wfd_sink_t *wfd_sink);
229 int _mm_wfd_set_message_callback(mm_wfd_sink_t *wfd_sink, MMWFDMessageCallback callback, void *user_data);
230 int _mm_wfd_sink_get_resource(mm_wfd_sink_t* wfd_sink);
231
232 int __mm_wfd_sink_link_audiobin(mm_wfd_sink_t *wfd_sink);
233 int __mm_wfd_sink_prepare_videobin (mm_wfd_sink_t *wfd_sink);
234 int __mm_wfd_sink_prepare_audiobin(mm_wfd_sink_t * wfd_sink);
235
236 #endif
237