1 /* GStreamer 2 * Copyright (C) 2014 Wim Taymans <wim.taymans@gmail.com> 3 * 4 * gstdownloadbuffer.h: 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 #ifndef __GST_DOWNLOAD_BUFFER_H__ 22 #define __GST_DOWNLOAD_BUFFER_H__ 23 24 #include <gst/gst.h> 25 #include <stdio.h> 26 27 #include "gstsparsefile.h" 28 29 G_BEGIN_DECLS 30 31 #define GST_TYPE_DOWNLOAD_BUFFER \ 32 (gst_download_buffer_get_type()) 33 #define GST_DOWNLOAD_BUFFER(obj) \ 34 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DOWNLOAD_BUFFER,GstDownloadBuffer)) 35 #define GST_DOWNLOAD_BUFFER_CLASS(klass) \ 36 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DOWNLOAD_BUFFER,GstDownloadBufferClass)) 37 #define GST_IS_DOWNLOAD_BUFFER(obj) \ 38 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DOWNLOAD_BUFFER)) 39 #define GST_IS_DOWNLOAD_BUFFER_CLASS(klass) \ 40 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DOWNLOAD_BUFFER)) 41 #define GST_DOWNLOAD_BUFFER_CAST(obj) \ 42 ((GstDownloadBuffer *)(obj)) 43 44 typedef struct _GstDownloadBuffer GstDownloadBuffer; 45 typedef struct _GstDownloadBufferClass GstDownloadBufferClass; 46 typedef struct _GstDownloadBufferSize GstDownloadBufferSize; 47 48 /* used to keep track of sizes (current and max) */ 49 struct _GstDownloadBufferSize 50 { 51 guint bytes; 52 guint64 time; 53 }; 54 55 struct _GstDownloadBuffer 56 { 57 GstElement element; 58 59 /*< private > */ 60 GstPad *sinkpad; 61 GstPad *srcpad; 62 63 /* upstream size in bytes (if downstream is operating in pull mode) */ 64 guint64 upstream_size; 65 66 /* flowreturn when srcpad is paused */ 67 GstFlowReturn srcresult; 68 GstFlowReturn sinkresult; 69 gboolean unexpected; 70 71 /* the queue of data we're keeping our hands on */ 72 GstSparseFile *file; 73 guint64 write_pos; 74 guint64 read_pos; 75 gboolean filling; 76 77 GstDownloadBufferSize cur_level; 78 GstDownloadBufferSize max_level; 79 gint low_percent; /* low/high watermarks for buffering */ 80 gint high_percent; 81 82 /* current buffering state */ 83 gboolean is_buffering; 84 gint buffering_percent; 85 86 /* for measuring input/output rates */ 87 GTimer *in_timer; 88 gboolean in_timer_started; 89 gdouble last_in_elapsed; 90 guint64 bytes_in; 91 gdouble byte_in_rate; 92 gdouble byte_in_period; 93 94 GTimer *out_timer; 95 gboolean out_timer_started; 96 gdouble last_out_elapsed; 97 guint64 bytes_out; 98 gdouble byte_out_rate; 99 100 GMutex qlock; /* lock for queue (vs object lock) */ 101 gboolean waiting_add; 102 GCond item_add; /* signals buffers now available for reading */ 103 guint64 waiting_offset; 104 105 /* temp location stuff */ 106 gchar *temp_template; 107 gboolean temp_location_set; 108 gchar *temp_location; 109 gboolean temp_remove; 110 gint temp_fd; 111 gboolean seeking; 112 113 GstEvent *stream_start_event; 114 GstEvent *segment_event; 115 }; 116 117 struct _GstDownloadBufferClass 118 { 119 GstElementClass parent_class; 120 }; 121 122 G_GNUC_INTERNAL GType gst_download_buffer_get_type (void); 123 124 G_END_DECLS 125 126 #endif /* __GST_DOWNLOAD_BUFFER_H__ */ 127