Sync with 2.4 [Fixed prevent issues].
[platform/core/api/mediademuxer.git] / include / port_gst / mediademuxer_port_gst.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file mediademuxer_port_gst.h
19  * @brief Handling for GST Port
20  */
21
22 #ifndef __TIZEN_MEDIADEMUXER_PORT_GST_H__
23 #define __TIZEN_MEDIADEMUXER_PORT_GST_H__
24
25 #include <tizen.h>
26 #include <gst/gst.h>
27 #include <media_format.h>
28 #include <gst/app/gstappsink.h>
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define POLLING_INTERVAL 10000
34 #define MAX_APP_BUFFER 100
35
36 #define MEDIADEMUXER_SET_STATE(x_element, x_state, error) \
37         do { \
38                 MD_I("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \
39                 if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) { \
40                         MD_E("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \
41                         goto error; \
42                 } \
43         } while (0)
44
45 #define MEDIADEMUXER_LINK_PAD(srcpad, sinkpad, error) \
46         do { \
47                 if (GST_PAD_LINK_OK != gst_pad_link(srcpad, sinkpad)) { \
48                         MD_E("failed to linkpad\n"); \
49                         goto error; \
50                 } \
51         } while (0)
52
53 typedef enum {
54         _GST_EVENT_TYPE_COMPLETE,
55         _GST_EVENT_TYPE_ERROR,
56         _GST_EVENT_TYPE_EOS,
57         _GST_EVENT_TYPE_NUM
58 } _gst_event_e;
59
60 typedef struct track {
61         GstPad *pad;
62         GstCaps *caps;
63         gchar *name;
64         gchar *caps_string;
65         GstElement *appsink;
66         GstElement *fakesink;
67         GstElement *queue;
68         media_format_h format;
69         struct track *next;
70 } track;
71
72 typedef struct track_info {
73         int num_audio_track;
74         int num_video_track;
75         int num_subtitle_track;
76         int num_other_track;
77         track *head;
78 } track_info;
79
80 /* GST port Private data */
81 typedef struct _mdgst_handle_t {
82         void *hdemux;   /*< demux handle */
83         int state;      /*< demux current state */
84         bool is_prepared;
85         GstElement *pipeline;
86         GstElement *filesrc;
87         GstElement *typefind;
88         GstElement *demux;
89         GstElement *fakesink;
90         gulong signal_handoff;
91         gint bus_whatch_id;
92         bool is_valid_container;
93         track_info info;
94         int state_change_timeout;
95         bool *selected_tracks;
96         int total_tracks;
97         GMutex *mutex;
98         /* for user cb */
99         void *user_cb[_GST_EVENT_TYPE_NUM];
100         void *user_data[_GST_EVENT_TYPE_NUM];
101
102 } mdgst_handle_t;
103
104 /**
105  * @brief Called when the error has occured.
106  * @since_tizen 3.0
107  * @details It will be invoked when the error has occured.
108  * @param[in] error_code  The error code
109  * @param[in] user_data  The user data passed from the callback registration function
110  * @pre It will be invoked when the error has occured if user register this callback using mediademuxer_set_error_cb().
111  * @see mediademuxer_set_error_cb()
112  * @see mediademuxer_unset_error_cb()
113  */
114 typedef void (*gst_error_cb)(mediademuxer_error_e error, void *user_data);
115
116 #ifdef __cplusplus
117 }
118 #endif
119 #endif  /* __TIZEN_MEDIADEMUXER_PORT_GST_H__ */