Fix to unify add track info function for audio only case
[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         bool need_codec_data;
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         GMainContext *thread_default;
91         gulong signal_handoff;
92         guint bus_watch_id;
93         bool is_valid_container;
94         track_info info;
95         int state_change_timeout;
96         bool *selected_tracks;
97         int total_tracks;
98         GMutex *mutex;
99         /* for user cb */
100         void *user_cb[_GST_EVENT_TYPE_NUM];
101         void *user_data[_GST_EVENT_TYPE_NUM];
102
103 } mdgst_handle_t;
104
105 /**
106  * @brief Called when the error has occured.
107  * @since_tizen 3.0
108  * @details It will be invoked when the error has occured.
109  * @param[in] error_code  The error code
110  * @param[in] user_data  The user data passed from the callback registration function
111  * @pre It will be invoked when the error has occured if user register this callback using mediademuxer_set_error_cb().
112  * @see mediademuxer_set_error_cb()
113  * @see mediademuxer_unset_error_cb()
114  */
115 typedef void (*gst_error_cb)(mediademuxer_error_e error, void *user_data);
116
117 /**
118  * @brief Called when the eos has occured.
119  * @since_tizen 3.0
120  * @details It will be invoked when the eos has occured.
121  * @param[in] track_num  track number to indicate eos
122  * @param[in] user_data  The user data passed from the callback registration function
123  * @pre It will be invoked when the eos has occured if user register this callback using mediademuxer_set_eos_cb().
124  * @see mediademuxer_set_eos_cb()
125  * @see mediademuxer_unset_eos_cb()
126  */
127 typedef void (*gst_eos_cb)(int track_num, void *user_data);
128
129 #ifdef __cplusplus
130 }
131 #endif
132 #endif  /* __TIZEN_MEDIADEMUXER_PORT_GST_H__ */