[svn r101] Changed it back to GstPushSrc.
1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 12:55:16 2006 +0000
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 14:37:47 2006 +0000
1.3 @@ -83,10 +83,10 @@
1.4
1.5 static void gst_mythtv_src_finalize (GObject * gobject);
1.6
1.7 -static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
1.8 - guint size, GstBuffer ** outbuf);
1.9 +//static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
1.10 +// guint size, GstBuffer ** outbuf);
1.11
1.12 -//static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
1.13 +static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
1.14
1.15 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
1.16 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
1.17 @@ -96,7 +96,7 @@
1.18 //static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
1.19 // GstClockTime * start, GstClockTime * end);
1.20
1.21 -//static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
1.22 +static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
1.23
1.24 static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
1.25
1.26 @@ -137,8 +137,8 @@
1.27 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
1.28 // GST_TYPE_BASE_SRC, _urihandler_init)
1.29
1.30 -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
1.31 - GST_TYPE_BASE_SRC, _urihandler_init)
1.32 +GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
1.33 + GST_TYPE_PUSH_SRC, _urihandler_init)
1.34
1.35 static void
1.36 gst_mythtv_src_base_init (gpointer g_class)
1.37 @@ -158,12 +158,12 @@
1.38 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
1.39 {
1.40 GObjectClass *gobject_class;
1.41 - //GstPushSrcClass *gstpushsrc_class;
1.42 + GstPushSrcClass *gstpushsrc_class;
1.43 GstBaseSrcClass *gstbasesrc_class;
1.44
1.45 gobject_class = (GObjectClass *) klass;
1.46 gstbasesrc_class = (GstBaseSrcClass *) klass;
1.47 - //gstpushsrc_class = (GstPushSrcClass *) klass;
1.48 + gstpushsrc_class = (GstPushSrcClass *) klass;
1.49
1.50 gobject_class->set_property = gst_mythtv_src_set_property;
1.51 gobject_class->get_property = gst_mythtv_src_get_property;
1.52 @@ -235,8 +235,8 @@
1.53
1.54 //gstbasesrc_class->get_times = gst_mythtv_src_get_times;
1.55
1.56 - //gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
1.57 - gstbasesrc_class->create = gst_mythtv_src_create;
1.58 + gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
1.59 + gstpushsrc_class->create = gst_mythtv_src_create;
1.60
1.61 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
1.62 "MythTV Client Source");
1.63 @@ -281,9 +281,6 @@
1.64
1.65 this->th_mutex = NULL;
1.66
1.67 - //this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
1.68 - //gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
1.69 -
1.70 gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
1.71
1.72 //gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
1.73 @@ -327,6 +324,11 @@
1.74 if (this->user_agent) {
1.75 g_free (this->user_agent);
1.76 }
1.77 +
1.78 + if ( this->bytes_queue ) {
1.79 + g_byte_array_free( this->bytes_queue, TRUE );
1.80 + this->bytes_queue = NULL;
1.81 + }
1.82
1.83 G_OBJECT_CLASS (parent_class)->finalize (gobject);
1.84 }
1.85 @@ -343,7 +345,7 @@
1.86 * Retry whilst authentication fails and we supply it. */
1.87 gint len = 0;
1.88
1.89 - //while ( sizetoread > 0 ) {
1.90 + while ( sizetoread > 0 ) {
1.91
1.92 len = gmyth_file_transfer_read( src->file_transfer,
1.93 *data_ptr + offset + read, sizetoread, TRUE );
1.94 @@ -365,20 +367,7 @@
1.95 if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
1.96 src->update_prog_chain = TRUE;
1.97 goto done;
1.98 - } /*if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
1.99 - src->update_prog_chain = TRUE;
1.100 - if ( src->enable_timing_position ) {
1.101 - gint64 size_tmp = 0;
1.102 -get_file_pos:
1.103 - size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1.104 - if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1.105 - src->content_size = size_tmp;
1.106 - else if ( size_tmp > 0 )
1.107 - goto get_file_pos;
1.108 - g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1.109 - __FUNCTION__, size_tmp );
1.110 - }
1.111 - }*/
1.112 + }
1.113 goto done;
1.114 }
1.115
1.116 @@ -386,7 +375,7 @@
1.117
1.118 if ( read == sizetoread )
1.119 goto done;
1.120 - //}
1.121 + }
1.122
1.123 if ( read < 0 && !src->live_tv )
1.124 goto eos;
1.125 @@ -401,15 +390,12 @@
1.126 return read;
1.127 }
1.128
1.129 -#if 0
1.130 static GstFlowReturn
1.131 gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
1.132 {
1.133 GstMythtvSrc *src;
1.134 GstFlowReturn ret = GST_FLOW_OK;
1.135 gint read = -1;
1.136 - gint adapter_size = 0;
1.137 - guint max_adapter_rep = 1;
1.138
1.139 src = GST_MYTHTV_SRC ( psrc );
1.140
1.141 @@ -420,34 +406,17 @@
1.142 goto change_progchain;
1.143
1.144 //g_static_rec_mutex_lock( &th_mutex );
1.145 - g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
1.146 -
1.147 - /* just get from the adapter, no network effort... */
1.148 - GstBuffer *buffer;
1.149 - guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.150 + g_print ( "[%s] offset = %llu, size = %d...\n", __FUNCTION__,
1.151 + src->read_offset, MAX_READ_SIZE );
1.152
1.153 g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
1.154 (gint) src->buffer_remain);
1.155
1.156 - /* Create the buffer. */
1.157 - ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.158 - src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
1.159 - GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
1.160 + /* just get from the byte array, no network effort... */
1.161 + if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
1.162 + guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.163
1.164 - if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1.165 - if ( src->live_tv )
1.166 - goto change_progchain;
1.167 - else
1.168 - goto done;
1.169 - }
1.170 -
1.171 - if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
1.172 -
1.173 - ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.174 - src->read_offset /*GST_BUFFER_OFFSET_NONE*/, INTERNAL_BUFFER_SIZE - src->buffer_remain,
1.175 - GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), &buffer );
1.176 -
1.177 - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
1.178 + read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) );
1.179
1.180 if (G_UNLIKELY (read < 0)) {
1.181 if ( src->live_tv )
1.182 @@ -458,33 +427,41 @@
1.183
1.184 if ( G_UNLIKELY (src->update_prog_chain) )
1.185 goto change_progchain;
1.186 -
1.187 - gst_adapter_push( src->adapter, buffer );
1.188 +
1.189 + src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read );
1.190
1.191 src->buffer_remain = src->buffer_remain + read;
1.192
1.193 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.194 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.195 src->read_offset, src->content_size );
1.196 -
1.197 +
1.198 }
1.199
1.200 - if ( now == -1 )
1.201 - now = gst_element_get_base_time( GST_ELEMENT( src ) );
1.202 - //else
1.203 - // now;
1.204 + guint buffer_size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.205 +
1.206 + /* Create the buffer. */
1.207 + ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.208 + src->read_offset, buffer_size,
1.209 + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
1.210
1.211 - size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.212 + if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1.213 + if ( src->live_tv )
1.214 + goto change_progchain;
1.215 + else
1.216 + goto done;
1.217 + }
1.218 +
1.219 + /* gets the first buffer_size bytes from the byte array buffer variable */
1.220 + guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size );
1.221
1.222 - buffer = gst_adapter_take_buffer( src->adapter, size );
1.223 + g_print( "[%s] read from network? %s!, buffer_remain = %d\n", __FUNCTION__,
1.224 + read == -1 ? "NO, got from buffer" : "YES, go see the backend's log file", src->buffer_remain );
1.225
1.226 - g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
1.227 -
1.228 - GST_BUFFER_SIZE (*outbuf) = size;
1.229 + GST_BUFFER_SIZE (*outbuf) = buffer_size;
1.230 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
1.231 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
1.232 - g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
1.233 - //GST_BUFFER_TIMESTAMP( *outbuf ) = now;
1.234 + g_memmove( GST_BUFFER_DATA( (*outbuf) ), buf, GST_BUFFER_SIZE(*outbuf) );
1.235 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
1.236 GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
1.237
1.238 @@ -493,17 +470,14 @@
1.239 src->read_offset += GST_BUFFER_SIZE (*outbuf);
1.240 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
1.241 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
1.242 -
1.243 - //gst_adapter_flush( src->adapter, size );
1.244 - gst_buffer_unref( buffer );
1.245 +
1.246 + /* flushs the newly buffer got from byte array */
1.247 + src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size );
1.248
1.249 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
1.250 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
1.251 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
1.252
1.253 - /* just get from the adapter, no network effort... */
1.254 -
1.255 -
1.256 return ret;
1.257
1.258 done:
1.259 @@ -546,8 +520,8 @@
1.260 }
1.261
1.262 }
1.263 -#endif
1.264
1.265 +#if 0
1.266 static GstFlowReturn
1.267 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf )
1.268 {
1.269 @@ -566,15 +540,12 @@
1.270 goto change_progchain;
1.271
1.272 //g_static_rec_mutex_lock( &th_mutex );
1.273 - g_print ( "[%s] %d - Adapter size = (%d), offset = %llu, size = %d...\n", __FUNCTION__,
1.274 - max_adapter_rep, adapter_size, offset, size );
1.275 -
1.276 - /* just get from the adapter, no network effort... */
1.277 - //GstBuffer *buffer = NULL;
1.278 + g_print ( "[%s] offset = %llu, size = %d...\n", __FUNCTION__, offset, size );
1.279
1.280 g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
1.281 (gint) src->buffer_remain);
1.282
1.283 + /* just get from the byte array, no network effort... */
1.284 if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
1.285 guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.286
1.287 @@ -631,15 +602,14 @@
1.288 src->read_offset += GST_BUFFER_SIZE (*outbuf);
1.289 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
1.290 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
1.291 -
1.292 +
1.293 + /* flushs the newly buffer got from byte array */
1.294 src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size );
1.295
1.296 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
1.297 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
1.298 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
1.299
1.300 - /* just get from the adapter, no network effort... */
1.301 -
1.302 return ret;
1.303
1.304 done:
1.305 @@ -682,6 +652,7 @@
1.306 }
1.307
1.308 }
1.309 +#endif
1.310
1.311 gint64
1.312 gst_mythtv_src_get_position ( GstMythtvSrc* src )
1.313 @@ -709,7 +680,6 @@
1.314
1.315 }
1.316
1.317 -#if 0
1.318 static gboolean
1.319 gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment )
1.320 {
1.321 @@ -750,13 +720,7 @@
1.322 }
1.323
1.324 }
1.325 - /*
1.326 - g_static_rec_mutex_lock( &th_mutex );
1.327
1.328 - GST_TASK_SIGNAL( src->th_read_ahead );
1.329 -
1.330 - g_static_rec_mutex_unlock( &th_mutex );
1.331 - */
1.332 done:
1.333 return ret;
1.334
1.335 @@ -785,7 +749,6 @@
1.336 }
1.337
1.338 }
1.339 -#endif
1.340
1.341 #if 0
1.342 static void
1.343 @@ -920,15 +883,12 @@
1.344
1.345 src->do_start = FALSE;
1.346
1.347 - //if ( src->live_tv ) {
1.348 - src->bytes_queue = g_byte_array_new();
1.349 + src->bytes_queue = g_byte_array_sized_new( INTERNAL_BUFFER_SIZE );
1.350 //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
1.351 //gst_task_set_lock( src->th_read_ahead, &th_mutex );
1.352 //gst_task_start( src->th_read_ahead );
1.353 - // }
1.354 src->buffer_remain = 0;
1.355
1.356 -
1.357 done:
1.358 return TRUE;
1.359
1.360 @@ -1075,6 +1035,12 @@
1.361
1.362 src->read_offset = 0;
1.363
1.364 + if ( src->bytes_queue != NULL ) {
1.365 + g_byte_array_free( src->bytes_queue, TRUE );
1.366 + }
1.367 +
1.368 + src->bytes_queue = g_byte_array_sized_new( INTERNAL_BUFFER_SIZE );
1.369 +
1.370 done:
1.371 src->update_prog_chain = FALSE;
1.372
1.373 @@ -1109,15 +1075,11 @@
1.374 g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__,
1.375 abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
1.376
1.377 - if ( src->live_tv )
1.378 - //src->content_size = (guint64)-1;
1.379 + if ( src->live_tv ) {
1.380 ret = FALSE;
1.381 - else if (src->content_size == -1) {
1.382 - //ret= FALSE;
1.383 - } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) <
1.384 + } else if ( src->live_tv && src->enable_timing_position && ( abs( src->content_size - src->bytes_read ) <
1.385 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1.386 //g_static_mutex_lock( &update_size_mutex );
1.387 - //GST_OBJECT_LOCK(src);
1.388
1.389 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
1.390 if ( new_offset > 0 && new_offset > src->content_size ) {
1.391 @@ -1126,24 +1088,6 @@
1.392 src->update_prog_chain = TRUE;
1.393 }
1.394
1.395 - if ( src->enable_timing_position ) {
1.396 - gint64 size_tmp = 0;
1.397 - if (src->live_tv == TRUE) {
1.398 -get_file_pos:
1.399 - g_usleep( 5 );
1.400 - size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1.401 - if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1.402 - src->content_size = size_tmp;
1.403 - else if ( size_tmp > 0 )
1.404 - goto get_file_pos;
1.405 - g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1.406 - __FUNCTION__, size_tmp );
1.407 - }
1.408 - }
1.409 -
1.410 - src->prev_content_size = src->content_size;
1.411 -
1.412 - //GST_OBJECT_UNLOCK(src);
1.413 //g_static_mutex_unlock( &update_size_mutex );
1.414 }
1.415
1.416 @@ -1272,7 +1216,7 @@
1.417 static gboolean
1.418 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1.419 {
1.420 - return FALSE;
1.421 + return TRUE;
1.422 }
1.423
1.424 static gboolean
1.425 @@ -1444,7 +1388,7 @@
1.426 return;
1.427 }
1.428
1.429 - static void
1.430 +static void
1.431 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1.432 GValue * value, GParamSpec * pspec)
1.433 {
2.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.h Wed Nov 22 12:55:16 2006 +0000
2.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.h Wed Nov 22 14:37:47 2006 +0000
2.3 @@ -18,7 +18,7 @@
2.4
2.5 #include <gst/gst.h>
2.6 #include <gst/base/gstbasesrc.h>
2.7 -#include <gst/base/gstadapter.h>
2.8 +#include <gst/base/gstpushsrc.h>
2.9 #include <stdio.h>
2.10
2.11 #include <gmyth/gmyth_socket.h>
2.12 @@ -48,7 +48,7 @@
2.13 } GstMythtvState;
2.14
2.15 struct _GstMythtvSrc {
2.16 - GstBaseSrc element;
2.17 + GstPushSrc element;
2.18
2.19 /* MythFileTransfer */
2.20 GMythFileTransfer *file_transfer;
2.21 @@ -73,7 +73,6 @@
2.22 guint64 bytes_read;
2.23
2.24 gint64 read_offset;
2.25 - gint64 adapter_offset;
2.26
2.27 /* added by melunko (buffer cache) */
2.28 gint buffer_remain;
2.29 @@ -98,7 +97,6 @@
2.30 GstCaps *mythtv_caps;
2.31
2.32 GstPad *sinkpad;
2.33 - GstPad *srcpad;
2.34
2.35 GstTask *th_read_ahead;
2.36
2.37 @@ -113,7 +111,7 @@
2.38 };
2.39
2.40 struct _GstMythtvSrcClass {
2.41 - GstBaseSrcClass parent_class;
2.42 + GstPushSrcClass parent_class;
2.43 };
2.44
2.45 GType gst_mythtv_src_get_type (void);