4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, Naveen Cherukuri <naveen.ch@samsung.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Alternatively, the contents of this file may be used under the
27 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 * which case the following provisions apply instead of the ones
31 * This library is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU Library General Public
33 * License as published by the Free Software Foundation; either
34 * version 2 of the License, or (at your option) any later version.
36 * This library is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 * Library General Public License for more details.
41 * You should have received a copy of the GNU Library General Public
42 * License along with this library; if not, write to the
43 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 * Boston, MA 02111-1307, USA.
48 #ifndef __GST_HLSDEMUX2_H__
49 #define __GST_HLSDEMUX2_H__
52 #include <gst/base/gstadapter.h>
53 #include <gst/app/gstappsrc.h>
54 #include <gst/app/gstappsink.h>
58 #define GST_TYPE_HLSDEMUX2 (gst_hlsdemux2_get_type())
59 #define GST_HLSDEMUX2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_HLSDEMUX2, GstHLSDemux2))
60 #define GST_HLSDEMUX2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLSDEMUX2,GstHLSDemux2Class))
61 #define GST_IS_HLSDEMUX2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLSDEMUX2))
62 #define GST_IS_HLSDEMUX2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLSDEMUX2))
64 typedef struct _GstHLSDemux2 GstHLSDemux2;
65 typedef struct _GstHLSDemux2Class GstHLSDemux2Class;
66 typedef struct _GstHLSDemux2Stream GstHLSDemux2Stream;
67 typedef struct _GstHLSDemux2PvtStream GstHLSDemux2PvtStream;
69 #define GST_HLS_DEMUX_AES_BLOCK_SIZE 16
71 #define ON_ERROR_REQUEST_AGAIN // Orange server giving soup errors. so, request for fail count times
73 #define HLSDEMUX2_CHUNK_TIME_DURATION (0.5 * GST_SECOND)
74 #define HLSDEMUX2_NUM_CHUNK_DOWNLOADS_FAST_SWITCH 4
75 #define HLSDEMUX2_MAX_N_PAST_FRAG_DOWNLOADRATES 3
77 #define HLSDEMUX2_FAST_CHECK_CRITICAL_TIME_FACTOR 1.2
78 #define HLSDEMUX2_FAST_CHECK_WARNING_TIME_FACTOR 1
80 #ifdef USING_AVG_PAST_DOWNLOADRATES
81 #define HLSDEMUX2_MAX_N_PAST_DOWNLOADRATES 3
85 #define PLAYLIST_REFRESH_TIMEOUT (20 * GST_SECOND)
87 #define HLSDEMUX2_OVERHEAD (1 * GST_SECOND)
89 #define LATEST_AV_SYNC
93 HLSDEMUX2_STREAM_VIDEO = 0,
94 HLSDEMUX2_STREAM_AUDIO,
95 HLSDEMUX2_STREAM_TEXT,
96 HLSDEMUX2_STREAM_PRIVATE,
98 }HLSDEMUX2_STREAM_TYPE;
102 HLSDEMUX2_DOWNWARD_RECOVERY = 0,
103 HLSDEMUX2_UPWARD_RECOVERY,
104 HLSDEMUX2_NO_RECOVERY,
105 }HLSDEMUX2_RECOVERY_MODE;
109 HLSDEMUX2_MULTI_VARIANT = 0,
110 HLSDEMUX2_SINGLE_VARIANT
111 }HLSDEMUX2_STREAM_CONFIGURATION;
116 GstElement *parser; /*only for .aac stream */
125 GstElement *typefind;
130 guint64 content_size;
131 gboolean applied_fast_switch;
133 gchar *remaining_data;
134 guint remaining_size;
138 gboolean is_encrypted;
141 gboolean get_next_frag; /* on error like NOT_FOUND, request next fragment */
143 guint cur_stream_cnt;
144 gboolean first_buffer;
145 gboolean force_timestamps; /* useful in .aac files playback */
147 gboolean find_mediaseq;
148 GstClockTime seeked_pos;
149 GstClockTime cur_running_dur;
151 /* for fragment download rate calculation */
152 guint64 download_rate;
153 GstClockTime download_start_ts;
154 GstClockTime download_stop_ts;
155 guint64 src_downloaded_size;
156 guint64 queue_downloaded_size;
157 gint ndownloaded; /* number of fragments downloaded */
158 GArray *avg_chunk_drates; /* chunk download rates array */
159 GArray *avg_frag_drates; /* fragment download rates array */
160 guint64 chunk_downloaded_size;
161 GstClockTime chunk_start_ts;
162 }HLSDemux2FragDownloader;
164 /* playlist downloader */
175 HLSDEMUX2_RECOVERY_MODE recovery_mode;
176 GstClockTime download_start_ts;
177 }HLSDemux2PLDownloader;
192 }HLSDemux2KeyDownloader;
197 * Opaque #GstHLSDemux2 data structure.
206 GstM3U8Client *client;
210 HLSDemux2FragDownloader *fdownloader; /* fragment downloader */
211 HLSDemux2PLDownloader *pldownloader; /* playlist downloader */
212 HLSDemux2KeyDownloader *kdownloader; /* key downloader */
217 /* master playlist got from upstream */
220 /* fragment download task */
221 GstTask *download_task;
222 GStaticRecMutex download_lock;
224 /* Playlist updates task for live session */
225 GStaticRecMutex updates_lock;
226 GTimeVal next_update; /* Time of the next update */
228 /* playlist update condition */
229 GCond *pl_update_cond;
230 GMutex *pl_update_lock;
232 /* array of pointers to each stream's list */
233 GstHLSDemux2Stream *streams[HLSDEMUX2_STREAM_NUM];
234 gint active_stream_cnt;
236 gint percent; /* buffering percentage posting */
237 GMutex *buffering_lock;
238 gboolean is_buffering;
239 GThread *buffering_posting_thread;
240 GMutex *post_msg_lock;
241 GCond *post_msg_start;
242 GCond *post_msg_exit;
244 /* HTTP request cookies. */
246 gchar **playlistCookie;
250 gchar *playlistDomain;
257 gfloat bitrate_switch_tol; /* tolerance with respect to the fragment duration to switch the bitarate*/
260 gboolean end_of_playlist;
262 guint64 total_cache_duration;
263 guint64 target_duration;
265 #ifdef ON_ERROR_REQUEST_AGAIN
266 /* requesting the same uron error */
268 gchar *frag_uri; /* NOT supporting YET for fragment download errors*/
272 int soup_request_fail_cnt;
273 /* can be removed [mainly for debugging & testing] */
274 gboolean force_lower_bitrate;
276 GstClockTime cfrag_dur;
277 gboolean error_posted;
279 GstClockTime ns_start;
280 GstClockTime cur_audio_fts;
282 GstHLSDemux2PvtStream * private_stream;
283 gboolean has_image_buffer;
284 HLSDEMUX2_STREAM_CONFIGURATION stream_config;
285 GstBuffer *prev_image_buffer;
286 GstBuffer *prev_video_buffer;
289 struct _GstHLSDemux2Class
291 GstElementClass parent_class;
294 GType gst_hlsdemux2_get_type (void);
297 #endif /* __GST_HLSDEMUX2_H__ */