1. Use wfdtsdemux instead of tsdemux.
[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_DEC,
74         WFD_SINK_V_CONVERT,
75         WFD_SINK_V_SINK,
76         WFD_SINK_V_NUM
77 };
78
79 /* audio codec : AAC, AC3, LPCM  */
80 enum WFDSinkAudioCodec {
81         WFD_SINK_AUDIO_CODEC_NONE,
82         WFD_SINK_AUDIO_CODEC_AAC = 0x0F,
83         WFD_SINK_AUDIO_CODEC_AC3 = 0x81,
84         WFD_SINK_AUDIO_CODEC_LPCM = 0x83
85 };
86
87 /* video codec : H264  */
88 enum WFDSinkVideoCodec {
89         WFD_SINK_VIDEO_CODEC_NONE,
90         WFD_SINK_VIDEO_CODEC_H264 = 0x1b
91 };
92
93 /**
94  *  * Enumerations of wifi-display command.
95  *   */
96 typedef enum {
97         MM_WFD_SINK_COMMAND_NONE,               /**< command for nothing */
98         MM_WFD_SINK_COMMAND_CREATE,             /**< command for creating wifi-display sink */
99         MM_WFD_SINK_COMMAND_PREPARE,            /**< command for preparing wifi-display sink */
100         MM_WFD_SINK_COMMAND_CONNECT,    /**< command for connecting wifi-display sink  */
101         MM_WFD_SINK_COMMAND_START,       /**< command for starting wifi-display sink  */
102         MM_WFD_SINK_COMMAND_PAUSE,       /**< command for pausing wifi-display sink  */
103         MM_WFD_SINK_COMMAND_RESUME,      /**< command for resuming wifi-display sink  */
104         MM_WFD_SINK_COMMAND_DISCONNECT, /**< command for disconnecting wifi-display sink  */
105         MM_WFD_SINK_COMMAND_UNPREPARE,          /**< command for unpreparing wifi-display sink  */
106         MM_WFD_SINK_COMMAND_DESTROY,            /**< command for destroting wifi-display sink  */
107         MM_WFD_SINK_COMMAND_NUM,                /**< Number of wifi-display commands */
108 } MMWFDSinkCommandType;
109
110 /**
111  *  * Enumerations of thread command.
112  *   */
113 typedef enum {
114         WFD_SINK_MANAGER_CMD_NONE = 0,
115         WFD_SINK_MANAGER_CMD_LINK_A_BIN = (1 << 0),
116         WFD_SINK_MANAGER_CMD_LINK_V_BIN = (1 << 1),
117         WFD_SINK_MANAGER_CMD_PREPARE_A_BIN = (1 << 2),
118         WFD_SINK_MANAGER_CMD_PREPARE_V_BIN = (1 << 3),
119         WFD_SINK_MANAGER_CMD_EXIT = (1 << 8)
120 } WFDSinkManagerCMDType;
121
122 /**
123  *  * Enumerations of resolution.
124  *   */
125 typedef enum {
126         MM_WFD_SINK_RESOLUTION_UNKNOWN = 0,
127         MM_WFD_SINK_RESOLUTION_1920x1080_P30 = (1 << 0),  /**< W-1920, H-1080, 30 fps*/
128         MM_WFD_SINK_RESOLUTION_1280x720_P30 = (1 << 1),   /**< W-1280, H-720, 30 fps*/
129         MM_WFD_SINK_RESOLUTION_960x540_P30 = (1 << 2),    /**< W-960, H-540, 30 fps*/
130         MM_WFD_SINK_RESOLUTION_864x480_P30 = (1 << 3),    /**< W-864, H-480, 30 fps*/
131         MM_WFD_SINK_RESOLUTION_720x480_P60 = (1 << 4),    /**< W-720, H-480, 30 fps*/
132         MM_WFD_SINK_RESOLUTION_640x480_P60 = (1 << 5),    /**< W-640, H-480, 60 fps*/
133         MM_WFD_SINK_RESOLUTION_640x360_P30 = (1 << 6),    /**< W-640, H-360, 30 fps*/
134         MM_WFD_SINK_RESOLUTION_MAX = 128,
135 } MMWFDSinkResolution;
136
137 typedef struct {
138         gint codec;
139         gint width;
140         gint height;
141         gint frame_rate;
142 } MMWFDSinkVideoStreamInfo;
143
144 typedef struct {
145         gint codec;
146         gint channels;
147         gint sample_rate;
148         gint bitwidth;
149 } MMWFDSinkAudioStreamInfo;
150
151 typedef struct {
152         MMWFDSinkAudioStreamInfo audio_stream_info;
153         MMWFDSinkVideoStreamInfo video_stream_info;
154 } MMWFDSinkStreamInfo;
155
156
157 typedef struct {
158         gint id;
159         GstElement *gst;
160 } MMWFDSinkGstElement;
161
162 typedef struct {
163         MMWFDSinkGstElement     *mainbin;
164         MMWFDSinkGstElement     *audiobin;
165         MMWFDSinkGstElement     *videobin;
166 } MMWFDSinkGstPipelineInfo;
167
168 typedef struct {
169         MMWFDSinkStateType state;         /* wfd current state */
170         MMWFDSinkStateType prev_state;    /* wfd  previous state */
171         MMWFDSinkStateType pending_state; /* wfd  state which is going to now */
172 } MMWFDSinkState;
173
174 #define MMWFDSINK_GET_ATTRS(x_wfd) ((x_wfd)? ((mm_wfd_sink_t*)x_wfd)->attrs : (MMHandleType)NULL)
175
176 typedef struct {
177         /* gstreamer pipeline */
178         MMWFDSinkGstPipelineInfo *pipeline;
179         gint added_av_pad_num;
180         gboolean audio_bin_is_linked;
181         gboolean video_bin_is_linked;
182         GstPad *prev_audio_dec_src_pad;
183         GstPad *next_audio_dec_sink_pad;
184
185         /* timestamp compensation */
186         gboolean need_to_reset_basetime;
187
188         GstClock *clock;
189         gint64 video_average_gap;
190         gint64 video_accumulated_gap;
191         gint64 video_buffer_count;
192         gint64 audio_average_gap;
193         gint64 audio_accumulated_gap;
194         gint64 audio_buffer_count;
195         GstClockTime last_buffer_timestamp;
196
197         /* attributes */
198         MMHandleType attrs;
199
200         /* state */
201         MMWFDSinkState state;
202
203         /* initialize values */
204         mm_wfd_sink_ini_t ini;
205
206         /* command */
207         MMWFDSinkCommandType cmd;
208         GMutex cmd_lock;
209         gboolean waiting_cmd;
210
211         /* stream information */
212         MMWFDSinkStreamInfo stream_info;
213
214         /* Message handling */
215         MMWFDMessageCallback msg_cb;
216         void *msg_user_data;
217
218         /* audio session manager related variables */
219         GList *resource_list;
220
221         /* video resolution for negotiation */
222         MMWFDSinkResolution supportive_resolution;
223
224         GThread         *manager_thread;
225         GMutex manager_thread_mutex;
226         GCond manager_thread_cond;
227         WFDSinkManagerCMDType manager_thread_cmd;
228 } mm_wfd_sink_t;
229
230
231 int _mm_wfd_sink_create(mm_wfd_sink_t **wfd_sink);
232 int _mm_wfd_sink_destroy(mm_wfd_sink_t *wfd_sink);
233 int _mm_wfd_sink_prepare(mm_wfd_sink_t *wfd_sink);
234 int _mm_wfd_sink_unprepare(mm_wfd_sink_t *wfd_sink);
235 int _mm_wfd_sink_connect(mm_wfd_sink_t *wfd_sink, const char *uri);
236 int _mm_wfd_sink_disconnect(mm_wfd_sink_t *wfd_sink);
237 int _mm_wfd_sink_start(mm_wfd_sink_t *wfd_sink);
238 int _mm_wfd_sink_pause(mm_wfd_sink_t *wfd_sink);
239 int _mm_wfd_sink_resume(mm_wfd_sink_t *wfd_sink);
240 int _mm_wfd_set_message_callback(mm_wfd_sink_t *wfd_sink, MMWFDMessageCallback callback, void *user_data);
241 int _mm_wfd_sink_get_resource(mm_wfd_sink_t *wfd_sink);
242 int _mm_wfd_sink_set_resolution(mm_wfd_sink_t *wfd_sink, MMWFDSinkResolution resolution);
243
244 int __mm_wfd_sink_link_audiobin(mm_wfd_sink_t *wfd_sink);
245 int __mm_wfd_sink_prepare_videobin(mm_wfd_sink_t *wfd_sink);
246 int __mm_wfd_sink_prepare_audiobin(mm_wfd_sink_t *wfd_sink);
247
248 #endif
249