| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
# include "config.h" |
| 24 |
#endif |
| 25 |
|
| 26 |
#include "gsthlsdemux-preloader.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
GST_DEBUG_CATEGORY_EXTERN (gst_hls_demux2_debug); |
| 32 |
#define GST_CAT_DEFAULT gst_hls_demux2_debug |
| 33 |
|
| 34 |
typedef struct _GstHLSDemuxPreloadRequest GstHLSDemuxPreloadRequest; |
| 35 |
struct _GstHLSDemuxPreloadRequest |
| 36 |
{ |
| 37 |
GstHLSDemuxPreloader *preloader; |
| 38 |
GstM3U8PreloadHint *hint; |
| 39 |
|
| 40 |
|
| 41 |
DownloadRequest *download_request; |
| 42 |
gboolean download_is_finished; |
| 43 |
guint64 download_cur_offset; |
| 44 |
guint64 download_content_length; |
| 45 |
GstClockTime request_latency; |
| 46 |
GstClockTime download_first_data_time; |
| 47 |
guint64 download_first_data_offset; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
guint64 target_cur_offset; |
| 54 |
DownloadRequest *target_request; |
| 55 |
}; |
| 56 |
|
| 57 |
static GstHLSDemuxPreloadRequest * |
| 58 |
gst_hls_demux_preload_request_new (GstHLSDemuxPreloader * preloader, |
| 59 |
GstM3U8PreloadHint * hint) |
| 60 |
{ |
| 61 |
GstHLSDemuxPreloadRequest *req = g_new0 (GstHLSDemuxPreloadRequest, 1); |
| 62 |
req->preloader = preloader; |
| 63 |
req->hint = gst_m3u8_preload_hint_ref (hint); |
| 64 |
req->request_latency = GST_CLOCK_TIME_NONE; |
| 65 |
req->download_first_data_time = GST_CLOCK_TIME_NONE; |
| 66 |
req->download_first_data_offset = GST_BUFFER_OFFSET_NONE; |
| 67 |
|
| 68 |
return req; |
| 69 |
}; |
| 70 |
|
| 71 |
static void |
| 72 |
gst_hls_demux_preload_request_free (GstHLSDemuxPreloadRequest * req) |
| 73 |
{ |
| 74 |
gst_m3u8_preload_hint_unref (req->hint); |
| 75 |
|
| 76 |
if (req->download_request != NULL) { |
| 77 |
|
| 78 |
|
| 79 |
download_request_unref (req->download_request); |
| 80 |
} |
| 81 |
|
| 82 |
if (req->target_request != NULL) { |
| 83 |
download_request_unref (req->target_request); |
| 84 |
} |
| 85 |
|
| 86 |
g_free (req); |
| 87 |
}; |
| 88 |
|
| 89 |
static gboolean |
| 90 |
gst_hls_demux_preloader_submit (GstHLSDemuxPreloader * preloader, |
| 91 |
GstHLSDemuxPreloadRequest * preload_req, const gchar * referrer_uri); |
| 92 |
static void gst_hls_demux_preloader_release_request (GstHLSDemuxPreloader * |
| 93 |
preloader, GstHLSDemuxPreloadRequest * preload_req, |
| 94 |
gboolean cancel_download); |
| 95 |
|
| 96 |
GstHLSDemuxPreloader * |
| 97 |
gst_hls_demux_preloader_new (DownloadHelper * download_helper) |
| 98 |
{ |
| 99 |
GstHLSDemuxPreloader *preloader = g_new0 (GstHLSDemuxPreloader, 1); |
| 100 |
|
| 101 |
preloader->download_helper = download_helper; |
| 102 |
preloader->active_preloads = g_ptr_array_new (); |
| 103 |
|
| 104 |
return preloader; |
| 105 |
} |
| 106 |
|
| 107 |
void |
| 108 |
gst_hls_demux_preloader_free (GstHLSDemuxPreloader * preloader) |
| 109 |
{ |
| 110 |
gst_hls_demux_preloader_cancel (preloader, M3U8_PRELOAD_HINT_ALL); |
| 111 |
g_ptr_array_free (preloader->active_preloads, TRUE); |
| 112 |
g_free (preloader); |
| 113 |
} |
| 114 |
|
| 115 |
void |
| 116 |
gst_hls_demux_preloader_load (GstHLSDemuxPreloader * preloader, |
| 117 |
GstM3U8PreloadHint * hint, const gchar * referrer_uri) |
| 118 |
{ |
| 119 |
|
| 120 |
guint idx; |
| 121 |
for (idx = 0; idx < preloader->active_preloads->len; idx++) { |
| 122 |
GstHLSDemuxPreloadRequest *req = |
| 123 |
g_ptr_array_index (preloader->active_preloads, idx); |
| 124 |
if (hint->hint_type == req->hint->hint_type) { |
| 125 |
|
| 126 |
|
| 127 |
if (gst_m3u8_preload_hint_equal (hint, req->hint)) { |
| 128 |
GST_LOG ("Ignoring pre-existing preload of type %d uri: %s, range:%" |
| 129 |
G_GINT64_FORMAT " size %" G_GINT64_FORMAT, hint->hint_type, |
| 130 |
hint->uri, hint->offset, hint->size); |
| 131 |
return; |
| 132 |
} |
| 133 |
|
| 134 |
gst_hls_demux_preloader_release_request (preloader, req, TRUE); |
| 135 |
g_ptr_array_remove_index_fast (preloader->active_preloads, idx); |
| 136 |
break; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
GstHLSDemuxPreloadRequest *req = |
| 142 |
gst_hls_demux_preload_request_new (preloader, hint); |
| 143 |
|
| 144 |
|
| 145 |
if (gst_hls_demux_preloader_submit (preloader, req, referrer_uri)) { |
| 146 |
g_ptr_array_add (preloader->active_preloads, req); |
| 147 |
} else { |
| 148 |
|
| 149 |
gst_hls_demux_preloader_release_request (preloader, req, TRUE); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
void |
| 154 |
gst_hls_demux_preloader_cancel (GstHLSDemuxPreloader * preloader, |
| 155 |
GstM3U8PreloadHintType hint_types) |
| 156 |
{ |
| 157 |
|
| 158 |
guint idx; |
| 159 |
for (idx = 0; idx < preloader->active_preloads->len;) { |
| 160 |
GstHLSDemuxPreloadRequest *req = |
| 161 |
g_ptr_array_index (preloader->active_preloads, idx); |
| 162 |
if (hint_types & req->hint->hint_type) { |
| 163 |
gst_hls_demux_preloader_release_request (preloader, req, TRUE); |
| 164 |
g_ptr_array_remove_index_fast (preloader->active_preloads, idx); |
| 165 |
continue; |
| 166 |
} |
| 167 |
|
| 168 |
idx++; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
static void |
| 175 |
gst_hls_demux_preloader_despatch (GstHLSDemuxPreloadRequest * preload_req, |
| 176 |
gboolean input_is_finished) |
| 177 |
{ |
| 178 |
GstHLSDemuxPreloader *preloader = preload_req->preloader; |
| 179 |
DownloadRequest *download_req = preload_req->download_request; |
| 180 |
|
| 181 |
if (input_is_finished) |
| 182 |
preload_req->download_is_finished = TRUE; |
| 183 |
else |
| 184 |
input_is_finished = preload_req->download_is_finished; |
| 185 |
|
| 186 |
download_request_lock (download_req); |
| 187 |
|
| 188 |
|
| 189 |
if (preload_req->request_latency == GST_CLOCK_TIME_NONE) { |
| 190 |
if (GST_CLOCK_TIME_IS_VALID (download_req->download_request_time) && |
| 191 |
GST_CLOCK_TIME_IS_VALID (download_req->download_start_time)) { |
| 192 |
|
| 193 |
preload_req->request_latency = |
| 194 |
download_req->download_start_time - |
| 195 |
download_req->download_request_time; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
if (preload_req->download_first_data_time == GST_CLOCK_TIME_NONE && |
| 200 |
download_request_get_bytes_available (download_req) > 0) { |
| 201 |
|
| 202 |
preload_req->download_first_data_time = download_req->download_start_time; |
| 203 |
preload_req->download_first_data_offset = |
| 204 |
download_request_get_cur_offset (download_req); |
| 205 |
} |
| 206 |
|
| 207 |
download_request_unlock (download_req); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
if (preload_req->target_request != NULL) { |
| 212 |
gboolean output_is_finished = input_is_finished; |
| 213 |
gboolean despatch_progress = FALSE; |
| 214 |
DownloadRequest *target_req = preload_req->target_request; |
| 215 |
|
| 216 |
download_request_lock (target_req); |
| 217 |
download_request_lock (download_req); |
| 218 |
|
| 219 |
DownloadRequestState target_state = download_req->state; |
| 220 |
|
| 221 |
|
| 222 |
target_req->status_code = download_req->status_code; |
| 223 |
|
| 224 |
GstBuffer *target_buf = download_request_take_buffer_range (download_req, |
| 225 |
preload_req->target_cur_offset, |
| 226 |
target_req->range_end); |
| 227 |
|
| 228 |
if (target_buf != NULL) { |
| 229 |
|
| 230 |
preload_req->target_cur_offset = |
| 231 |
GST_BUFFER_OFFSET (target_buf) + gst_buffer_get_size (target_buf); |
| 232 |
|
| 233 |
GST_LOG ("Adding %" G_GSIZE_FORMAT " bytes at offset %" G_GUINT64_FORMAT |
| 234 |
" to target download request uri %s range %" G_GINT64_FORMAT " - %" |
| 235 |
G_GINT64_FORMAT, gst_buffer_get_size (target_buf), |
| 236 |
GST_BUFFER_OFFSET (target_buf), target_req->uri, |
| 237 |
target_req->range_start, target_req->range_end); |
| 238 |
|
| 239 |
download_request_add_buffer (target_req, target_buf); |
| 240 |
despatch_progress = TRUE; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
if (target_req->download_start_time == GST_CLOCK_TIME_NONE) { |
| 248 |
if (preload_req->download_first_data_time > |
| 249 |
preload_req->request_latency) { |
| 250 |
target_req->download_request_time = |
| 251 |
preload_req->download_first_data_time - |
| 252 |
preload_req->request_latency; |
| 253 |
} else { |
| 254 |
target_req->download_request_time = 0; |
| 255 |
} |
| 256 |
|
| 257 |
target_req->download_start_time = preload_req->download_first_data_time; |
| 258 |
target_req->download_newest_data_time = |
| 259 |
download_req->download_newest_data_time; |
| 260 |
} |
| 261 |
|
| 262 |
if (target_req->range_end != -1 |
| 263 |
&& preload_req->target_cur_offset > target_req->range_end) { |
| 264 |
|
| 265 |
if (target_state == DOWNLOAD_REQUEST_STATE_LOADING) { |
| 266 |
target_state = DOWNLOAD_REQUEST_STATE_COMPLETE; |
| 267 |
GST_LOG ("target download request uri %s range %" G_GINT64_FORMAT |
| 268 |
" - %" G_GINT64_FORMAT " is fully satisfied. Completing", |
| 269 |
target_req->uri, target_req->range_start, target_req->range_end); |
| 270 |
} |
| 271 |
|
| 272 |
output_is_finished = TRUE; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
guint64 data_avail = |
| 283 |
download_request_get_bytes_available (download_req); |
| 284 |
if (data_avail > 0) { |
| 285 |
|
| 286 |
g_assert (preload_req->download_first_data_offset != |
| 287 |
GST_BUFFER_OFFSET_NONE); |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
guint64 new_cur_offset = |
| 293 |
download_request_get_cur_offset (download_req); |
| 294 |
GstClockTime data_time_offset = |
| 295 |
gst_util_uint64_scale (download_req->download_newest_data_time - |
| 296 |
preload_req->download_first_data_time, |
| 297 |
new_cur_offset - preload_req->download_first_data_offset, |
| 298 |
new_cur_offset + data_avail - |
| 299 |
preload_req->download_first_data_offset); |
| 300 |
|
| 301 |
preload_req->download_first_data_time += data_time_offset; |
| 302 |
preload_req->download_first_data_offset = new_cur_offset; |
| 303 |
|
| 304 |
GST_LOG ("Advancing request timing tracking by %" GST_TIMEP_FORMAT |
| 305 |
" to time %" GST_TIMEP_FORMAT " @ offset %" G_GUINT64_FORMAT, |
| 306 |
&data_time_offset, |
| 307 |
&preload_req->download_first_data_time, |
| 308 |
preload_req->download_first_data_offset); |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
target_req->download_end_time = preload_req->download_first_data_time; |
| 313 |
} else { |
| 314 |
|
| 315 |
preload_req->download_first_data_time = GST_CLOCK_TIME_NONE; |
| 316 |
preload_req->download_first_data_offset = GST_BUFFER_OFFSET_NONE; |
| 317 |
|
| 318 |
|
| 319 |
target_req->download_end_time = |
| 320 |
download_req->download_newest_data_time; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
if (input_is_finished |
| 326 |
&& target_req->download_end_time == GST_CLOCK_TIME_NONE) { |
| 327 |
|
| 328 |
target_req->download_end_time = download_req->download_end_time; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
target_req->state = target_state; |
| 334 |
|
| 335 |
if (target_req->headers == NULL && download_req->headers != NULL) { |
| 336 |
target_req->headers = gst_structure_copy (download_req->headers); |
| 337 |
} |
| 338 |
|
| 339 |
if (target_req->redirect_uri == NULL && download_req->redirect_uri != NULL) { |
| 340 |
target_req->redirect_uri = g_strdup (download_req->redirect_uri); |
| 341 |
target_req->redirect_permanent = download_req->redirect_permanent; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
download_request_unlock (download_req); |
| 346 |
|
| 347 |
if (output_is_finished) { |
| 348 |
GST_DEBUG ("Finishing target preload request uri: %s, start: %" |
| 349 |
G_GINT64_FORMAT " end: %" G_GINT64_FORMAT, target_req->uri, |
| 350 |
target_req->range_start, target_req->range_end); |
| 351 |
|
| 352 |
download_request_despatch_completion (target_req); |
| 353 |
download_request_unlock (target_req); |
| 354 |
|
| 355 |
download_request_unref (target_req); |
| 356 |
preload_req->target_request = NULL; |
| 357 |
} else if (despatch_progress) { |
| 358 |
download_request_despatch_progress (target_req); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
if (preload_req->target_request != NULL) { |
| 363 |
download_request_unlock (preload_req->target_request); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
if (input_is_finished) { |
| 368 |
if (download_req == NULL |
| 369 |
|| download_request_get_bytes_available (download_req) |
| 370 |
== 0) { |
| 371 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 372 |
GST_DEBUG ("Removing finished+drained preload type %d uri: %s, start: %" |
| 373 |
G_GINT64_FORMAT " size: %" G_GINT64_FORMAT, hint->hint_type, |
| 374 |
hint->uri, hint->offset, hint->size); |
| 375 |
|
| 376 |
|
| 377 |
g_ptr_array_remove_fast (preloader->active_preloads, preload_req); |
| 378 |
gst_hls_demux_preloader_release_request (preloader, preload_req, FALSE); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
static void |
| 384 |
on_download_cancellation (DownloadRequest * request, DownloadRequestState state, |
| 385 |
GstHLSDemuxPreloadRequest * preload_req) |
| 386 |
{ |
| 387 |
gst_hls_demux_preloader_despatch (preload_req, TRUE); |
| 388 |
} |
| 389 |
|
| 390 |
static void |
| 391 |
on_download_error (DownloadRequest * request, DownloadRequestState state, |
| 392 |
GstHLSDemuxPreloadRequest * preload_req) |
| 393 |
{ |
| 394 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 395 |
GST_DEBUG ("preload type %d uri: %s download error", hint->hint_type, |
| 396 |
hint->uri); |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
gst_hls_demux_preloader_despatch (preload_req, TRUE); |
| 404 |
} |
| 405 |
|
| 406 |
static void |
| 407 |
on_download_progress (DownloadRequest * request, DownloadRequestState state, |
| 408 |
GstHLSDemuxPreloadRequest * preload_req) |
| 409 |
{ |
| 410 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 411 |
|
| 412 |
GST_DEBUG ("preload type %d uri: %s download progress. position %" |
| 413 |
G_GUINT64_FORMAT " of %" G_GUINT64_FORMAT " bytes", hint->hint_type, |
| 414 |
hint->uri, |
| 415 |
preload_req->download_cur_offset + |
| 416 |
download_request_get_bytes_available (request), request->content_length); |
| 417 |
preload_req->download_content_length = request->content_length; |
| 418 |
|
| 419 |
gst_hls_demux_preloader_despatch (preload_req, FALSE); |
| 420 |
} |
| 421 |
|
| 422 |
static void |
| 423 |
on_download_complete (DownloadRequest * request, DownloadRequestState state, |
| 424 |
GstHLSDemuxPreloadRequest * preload_req) |
| 425 |
{ |
| 426 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 427 |
GST_DEBUG ("preload type %d uri: %s download complete. position %" |
| 428 |
G_GUINT64_FORMAT " of %" G_GUINT64_FORMAT " bytes", hint->hint_type, |
| 429 |
hint->uri, |
| 430 |
preload_req->download_cur_offset + |
| 431 |
download_request_get_bytes_available (request), request->content_length); |
| 432 |
preload_req->download_content_length = request->content_length; |
| 433 |
|
| 434 |
gst_hls_demux_preloader_despatch (preload_req, TRUE); |
| 435 |
} |
| 436 |
|
| 437 |
static gboolean |
| 438 |
gst_hls_demux_preloader_submit (GstHLSDemuxPreloader * preloader, |
| 439 |
GstHLSDemuxPreloadRequest * preload_req, const gchar * referrer_uri) |
| 440 |
{ |
| 441 |
g_assert (preload_req->download_request == NULL); |
| 442 |
|
| 443 |
DownloadRequest *download_req = download_request_new (); |
| 444 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 445 |
|
| 446 |
|
| 447 |
gint64 end = RFC8673_LAST_BYTE_POS; |
| 448 |
if (hint->size > 0) { |
| 449 |
end = hint->offset + hint->size - 1; |
| 450 |
} |
| 451 |
|
| 452 |
download_request_set_uri (download_req, hint->uri, hint->offset, end); |
| 453 |
download_request_set_callbacks (download_req, |
| 454 |
(DownloadRequestEventCallback) on_download_complete, |
| 455 |
(DownloadRequestEventCallback) on_download_error, |
| 456 |
(DownloadRequestEventCallback) on_download_cancellation, |
| 457 |
(DownloadRequestEventCallback) on_download_progress, preload_req); |
| 458 |
|
| 459 |
GST_DEBUG ("Submitting preload type %d uri: %s, range:%" G_GINT64_FORMAT |
| 460 |
" - %" G_GINT64_FORMAT, hint->hint_type, hint->uri, hint->offset, end); |
| 461 |
|
| 462 |
if (!downloadhelper_submit_request (preloader->download_helper, |
| 463 |
referrer_uri, DOWNLOAD_FLAG_NONE, download_req, NULL)) { |
| 464 |
|
| 465 |
download_request_unref (download_req); |
| 466 |
return FALSE; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
preload_req->download_cur_offset = hint->offset; |
| 471 |
preload_req->download_request = download_req; |
| 472 |
preload_req->download_is_finished = FALSE; |
| 473 |
return TRUE; |
| 474 |
} |
| 475 |
|
| 476 |
static void |
| 477 |
gst_hls_demux_preloader_release_request (GstHLSDemuxPreloader * preloader, |
| 478 |
GstHLSDemuxPreloadRequest * preload_req, gboolean cancel_download) |
| 479 |
{ |
| 480 |
if (preload_req->download_request) { |
| 481 |
if (cancel_download) { |
| 482 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 483 |
|
| 484 |
GST_DEBUG ("Cancelling preload type %d uri: %s, range start:%" |
| 485 |
G_GINT64_FORMAT " size %" G_GINT64_FORMAT, hint->hint_type, hint->uri, |
| 486 |
hint->offset, hint->size); |
| 487 |
|
| 488 |
|
| 489 |
download_request_set_callbacks (preload_req->download_request, |
| 490 |
NULL, NULL, NULL, NULL, NULL); |
| 491 |
downloadhelper_cancel_request (preloader->download_helper, |
| 492 |
preload_req->download_request); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
gst_hls_demux_preload_request_free (preload_req); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
gboolean |
| 515 |
gst_hls_demux_preloader_provide_request (GstHLSDemuxPreloader * preloader, |
| 516 |
DownloadRequest * target_req) |
| 517 |
{ |
| 518 |
guint idx; |
| 519 |
for (idx = 0; idx < preloader->active_preloads->len; idx++) { |
| 520 |
GstHLSDemuxPreloadRequest *preload_req = |
| 521 |
g_ptr_array_index (preloader->active_preloads, idx); |
| 522 |
GstM3U8PreloadHint *hint = preload_req->hint; |
| 523 |
|
| 524 |
if (g_strcmp0 (hint->uri, target_req->uri)) |
| 525 |
continue; |
| 526 |
|
| 527 |
GST_LOG ("Possible matching preload type %d uri: %s, range start:%" |
| 528 |
G_GINT64_FORMAT " size %" G_GINT64_FORMAT " (download position %" |
| 529 |
G_GUINT64_FORMAT ") for req with range %" G_GINT64_FORMAT " to %" |
| 530 |
G_GINT64_FORMAT, hint->hint_type, hint->uri, hint->offset, hint->size, |
| 531 |
preload_req->download_cur_offset, target_req->range_start, |
| 532 |
target_req->range_end); |
| 533 |
|
| 534 |
if (target_req->range_start > preload_req->download_cur_offset) { |
| 535 |
|
| 536 |
|
| 537 |
GST_LOG ("Range start didn't match"); |
| 538 |
continue; |
| 539 |
} |
| 540 |
|
| 541 |
if (target_req->range_end != -1) { |
| 542 |
|
| 543 |
|
| 544 |
gint64 content_length = preload_req->download_content_length; |
| 545 |
if (content_length == 0) { |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
if (hint->size != -1) |
| 550 |
content_length = hint->size; |
| 551 |
} |
| 552 |
|
| 553 |
if (content_length != 0) { |
| 554 |
|
| 555 |
|
| 556 |
if (target_req->range_end > hint->offset + content_length - 1) { |
| 557 |
GST_LOG ("Range end %" G_GINT64_FORMAT " is beyond the end (%" |
| 558 |
G_GINT64_FORMAT ") of this preload", target_req->range_end, |
| 559 |
hint->offset + content_length - 1); |
| 560 |
continue; |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
GST_DEBUG ("Found a matching preload type %d uri: %s, range start:%" |
| 566 |
G_GINT64_FORMAT " size %" G_GINT64_FORMAT, hint->hint_type, hint->uri, |
| 567 |
hint->offset, hint->size); |
| 568 |
|
| 569 |
if (preload_req->target_request != NULL) { |
| 570 |
DownloadRequest *old_request = preload_req->target_request; |
| 571 |
|
| 572 |
|
| 573 |
if (old_request != target_req) { |
| 574 |
download_request_lock (old_request); |
| 575 |
old_request->state = DOWNLOAD_REQUEST_STATE_UNSENT; |
| 576 |
download_request_despatch_completion (old_request); |
| 577 |
download_request_unlock (old_request); |
| 578 |
} |
| 579 |
|
| 580 |
download_request_unref (old_request); |
| 581 |
preload_req->target_request = NULL; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
preload_req->target_cur_offset = target_req->range_start; |
| 586 |
preload_req->target_request = download_request_ref (target_req); |
| 587 |
|
| 588 |
download_request_lock (target_req); |
| 589 |
target_req->state = DOWNLOAD_REQUEST_STATE_UNSENT; |
| 590 |
download_request_begin_download (target_req); |
| 591 |
download_request_unlock (target_req); |
| 592 |
|
| 593 |
gst_hls_demux_preloader_despatch (preload_req, FALSE); |
| 594 |
return TRUE; |
| 595 |
} |
| 596 |
|
| 597 |
return FALSE; |
| 598 |
} |