ae70cb99134ef9f2c6c711f17e7de8e59cd5f036
[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_REALIZE,            /**< command for realizing 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_STOP,       /**< command for stopping wifi-display sink  */
108         MM_WFD_SINK_COMMAND_UNREALIZE,          /**< command for unrealizing 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         gboolean is_constructed;
174         gint added_av_pad_num;
175         gboolean audio_bin_is_linked;
176         gboolean video_bin_is_linked;
177         gboolean audio_bin_is_prepared;
178         gboolean video_bin_is_prepared;
179         GstPad * prev_audio_dec_src_pad;
180         GstPad * next_audio_dec_sink_pad;
181         guint demux_video_pad_probe_id;
182         guint demux_audio_pad_probe_id;
183         gboolean need_to_reset_basetime;
184         /* attributes */
185         MMHandleType attrs;
186
187         /* state */
188         MMWFDSinkState state;
189
190         /* initialize values */
191         mm_wfd_sink_ini_t ini;
192
193         /* command */
194         MMWfdSinkCommandType cmd;
195         GMutex* cmd_lock;
196
197
198         /* stream information */
199         MMWFDSinkStreamInfo stream_info;
200
201         /* Message handling */
202         MMWFDMessageCallback msg_cb;
203         void *msg_user_data;
204
205         /* audio session manager related variables */
206         GList *resource_list;
207
208         GThread         *manager_thread;
209         GMutex *manager_thread_mutex;
210         GCond* manager_thread_cond;
211         WFDSinkManagerCMDType manager_thread_cmd;
212 } mm_wfd_sink_t;
213
214
215 int _mm_wfd_sink_create(mm_wfd_sink_t **wfd_sink);
216 int _mm_wfd_sink_realize(mm_wfd_sink_t *wfd_sink);
217 int _mm_wfd_sink_connect(mm_wfd_sink_t *wfd_sink, const char *uri);
218 int _mm_wfd_sink_start(mm_wfd_sink_t *wfd_sink);
219 int _mm_wfd_sink_stop(mm_wfd_sink_t *wfd_sink);
220 int _mm_wfd_sink_unrealize(mm_wfd_sink_t *wfd_sink);
221 int _mm_wfd_sink_destroy(mm_wfd_sink_t *wfd_sink);
222 int _mm_wfd_set_message_callback(mm_wfd_sink_t *wfd_sink, MMWFDMessageCallback callback, void *user_data);
223 int _mm_wfd_sink_get_resource(mm_wfd_sink_t* wfd_sink);
224
225 int __mm_wfd_sink_link_audiobin(mm_wfd_sink_t *wfd_sink);
226 int __mm_wfd_sink_prepare_videobin (mm_wfd_sink_t *wfd_sink);
227 int __mm_wfd_sink_prepare_audiobin(mm_wfd_sink_t * wfd_sink);
228
229 #endif
230