[svn r32] Some adjustments on the performance.
1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Thu Oct 12 01:50:27 2006 +0100
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Tue Oct 17 01:03:06 2006 +0100
1.3 @@ -36,7 +36,7 @@
1.4
1.5 #define MYTHTV_TRANSFER_MAX_WAITS 100
1.6
1.7 -#define MYTHTV_TRANSFER_MAX_BUFFER 32*1024
1.8 +#define MYTHTV_TRANSFER_MAX_BUFFER 4*1024
1.9 //( 32*1024 )
1.10
1.11 /* 4*1024 ??? */
1.12 @@ -98,7 +98,7 @@
1.13
1.14 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
1.15
1.16 -//static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.17 +static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.18 //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
1.19
1.20 static guint do_read_request_response (GstMythtvSrc *src, guint64 offset,
1.21 @@ -237,17 +237,15 @@
1.22 //gst_pad_set_chain_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.23 // gst_mythtv_src_chain );
1.24
1.25 -/*
1.26 gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.27 gst_mythtv_src_handle_event );
1.28 -
1.29 +/*
1.30 gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.31 gst_mythtv_src_query );
1.32 */
1.33 //gst_pad_set_activatepull_function( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.34 // gst_mythtv_src_sink_activate_pull );
1.35
1.36 -
1.37 }
1.38
1.39 static void
1.40 @@ -283,7 +281,7 @@
1.41 {
1.42 guint read = 0;
1.43 guint sizetoread = size; //GST_BUFFER_SIZE (outbuf);
1.44 - GstBuffer *buffer = gst_buffer_new_and_alloc( size );
1.45 + //GstBuffer *buffer = gst_buffer_new_and_alloc( size );
1.46
1.47 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
1.48
1.49 @@ -291,12 +289,12 @@
1.50 * Retry whilst authentication fails and we supply it. */
1.51 guint len = 0;
1.52
1.53 - //GST_OBJECT_LOCK(src);
1.54 + GST_OBJECT_LOCK(src);
1.55
1.56 while ( sizetoread > 0 ) {
1.57 -
1.58 - len = myth_file_transfer_read( src->file_transfer,
1.59 - GST_BUFFER_DATA( buffer ) + read, sizetoread, TRUE );
1.60 +
1.61 + len = myth_file_transfer_read( src->file_transfer,
1.62 + GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
1.63
1.64 if ( len > 0 ) {
1.65 read += len;
1.66 @@ -308,47 +306,44 @@
1.67 goto done;
1.68 } else if ( src->content_size >= src->read_offset &&
1.69 abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
1.70 - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
1.71 - if ( src->content_size < new_offset ) {
1.72 - src->content_size = new_offset;
1.73 - goto done;
1.74 - } else
1.75 - goto eos;
1.76 - } else
1.77 - goto eos;
1.78 + goto done;
1.79 + }
1.80
1.81 }
1.82 -
1.83 +
1.84 if ( read == sizetoread )
1.85 break;
1.86 }
1.87
1.88 if ( read > 0 ) {
1.89 src->bytes_read += read;
1.90 - }
1.91 -
1.92 +
1.93 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.94 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.95 src->read_offset, src->content_size );
1.96 -
1.97 - *outbuf = buffer;
1.98 - memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read );
1.99 - GST_BUFFER_SIZE (buffer) = read;
1.100 - GST_BUFFER_OFFSET (buffer) = offset;
1.101 - GST_BUFFER_OFFSET_END (buffer) = offset + read;
1.102 +
1.103 + //GST_BUFFER_TIMESTAMP( buffer ) = GST_BUFFER_TIMESTAMP ( *outbuf );
1.104 + GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
1.105 + GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
1.106 + GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
1.107 + //*outbuf = buffer;
1.108 + //memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read );
1.109
1.110 g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
1.111 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
1.112 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
1.113 - //GST_OBJECT_UNLOCK(src);
1.114 +
1.115 + } else
1.116 + goto eos;
1.117 +
1.118 goto done;
1.119
1.120 eos:
1.121 - //GST_OBJECT_UNLOCK(src);
1.122 -
1.123 + //GST_OBJECT_UNLOCK(src);
1.124 src->eos = TRUE;
1.125
1.126 done:
1.127 + GST_OBJECT_UNLOCK(src);
1.128
1.129 return read;
1.130 }
1.131 @@ -359,60 +354,82 @@
1.132 GstMythtvSrc *src;
1.133 GstFlowReturn ret = GST_FLOW_OK;
1.134 guint read = 0;
1.135 - //GstBuffer *buffer = NULL;
1.136 - //guint size = MAX_READ_SIZE;
1.137
1.138 src = GST_MYTHTV_SRC (psrc);
1.139 + /* The caller should know the number of bytes and not read beyond EOS. */
1.140 + if (G_UNLIKELY (src->eos))
1.141 + goto eos;
1.142
1.143 - if ( src->content_size >= src->read_offset &&
1.144 - abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
1.145 - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
1.146 - if ( src->content_size < new_offset ) {
1.147 - src->content_size = new_offset;
1.148 - }
1.149 + //GST_OBJECT_LOCK(src);
1.150 + if ( /*src->content_size >= src->read_offset &&
1.151 + abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
1.152 + ( src->content_size <= ( src->read_offset + size ) ) )
1.153 + {
1.154 +#if ENABLE_TIMING_POSITION == 1
1.155 + guint64 size_tmp = 0;
1.156 + if (src->live_tv == TRUE) {
1.157 +get_file_pos:
1.158 + size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
1.159 + if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
1.160 + src->content_size = size_tmp;
1.161 + else
1.162 + goto get_file_pos;
1.163 + g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
1.164 + __FUNCTION__, size_tmp );
1.165 + }
1.166 +#endif
1.167 + //guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
1.168 + //if ( src->content_size < new_offset ) {
1.169 + // src->content_size = new_offset;
1.170 + //}
1.171 }
1.172
1.173 if (G_UNLIKELY (src->read_offset != offset)) {
1.174 guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
1.175
1.176 - if (G_UNLIKELY (new_offset < 0 || new_offset != offset))
1.177 + if (G_UNLIKELY (new_offset < 0 || new_offset != offset)) {
1.178 + //GST_OBJECT_UNLOCK(src);
1.179 goto read_error;
1.180 + }
1.181
1.182 src->read_offset = offset;
1.183 }
1.184 + //GST_OBJECT_UNLOCK(src);
1.185
1.186 - /* The caller should know the number of bytes and not read beyond EOS. */
1.187 - if (G_UNLIKELY (src->eos))
1.188 - goto eos;
1.189 + /* Create the buffer. */
1.190 + ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.191 + src->read_offset, size,
1.192 + //src->icy_caps ? src->icy_caps :
1.193 + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
1.194
1.195 - /* Create the buffer. */
1.196 - //ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.197 - // GST_BUFFER_OFFSET_NONE, size, src->mythtv_caps ? src->mythtv_caps :
1.198 - // GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
1.199 + if (G_UNLIKELY (ret != GST_FLOW_OK))
1.200 + goto done;
1.201
1.202 - //if (G_UNLIKELY (ret != GST_FLOW_OK))
1.203 - // goto eos;
1.204 - //if (G_UNLIKELY (ret == GST_FLOW_ERROR))
1.205 - // goto read_error;
1.206 -
1.207 - g_static_mutex_lock( &update_size_mutex );
1.208 - read = do_read_request_response ( src, 0, size, outbuf );
1.209 - g_static_mutex_unlock( &update_size_mutex );
1.210 + //g_static_mutex_lock( &update_size_mutex );
1.211 + read = do_read_request_response ( src, src->read_offset, size, outbuf );
1.212 + //g_static_mutex_unlock( &update_size_mutex );
1.213
1.214 - if (G_UNLIKELY (read < 0) || *outbuf == NULL)
1.215 + if (G_UNLIKELY (read < 0) || *outbuf == NULL) {
1.216 + //if ( src->live_tv )
1.217 + // goto done;
1.218 + //else
1.219 goto read_error;
1.220 + }
1.221
1.222 - gst_buffer_set_caps( *outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))) );
1.223 -
1.224 - //*outbuf = buffer;
1.225 -
1.226 +/*
1.227 if (G_UNLIKELY(src->eos))
1.228 goto eos;
1.229 else
1.230 goto done;
1.231 +*/
1.232
1.233 done:
1.234 - return ret;
1.235 + {
1.236 + const gchar *reason = gst_flow_get_name (ret);
1.237 +
1.238 + GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
1.239 + return ret;
1.240 + }
1.241 eos:
1.242 {
1.243 const gchar *reason = gst_flow_get_name (ret);
1.244 @@ -540,11 +557,6 @@
1.245 goto init_failed;
1.246 }
1.247
1.248 - if ( src->live_tv ) {
1.249 - g_print ( "[%s] GST MYTHTVSRC: live_chain_id = %s\n", __FUNCTION__, src->live_chain_id );
1.250 - /* sets the MythSocket to the FileTransfer */
1.251 - //ret = myth_file_transfer_livetv_setup( &(src->file_transfer), src->spawn_livetv->remote_encoder->myth_socket );
1.252 - }
1.253 /* sets the Playback monitor connection */
1.254 ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
1.255
1.256 @@ -575,9 +587,7 @@
1.257 if ( src->live_tv ) {
1.258
1.259 //GError* error;
1.260 -
1.261 //update_size_task = g_thread_create( (GThreadFunc)update_size_func, src, FALSE, &error );
1.262 -
1.263 g_print( "[%s] Update Size task = %s\n", __FUNCTION__, update_size_task != NULL ? "OK !" : "ERROR!!!" );
1.264
1.265 }
1.266 @@ -675,22 +685,26 @@
1.267 static gboolean
1.268 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1.269 {
1.270 - GstMythtvSrc *src;
1.271 + GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1.272 gboolean ret = TRUE;
1.273
1.274 - src = GST_MYTHTV_SRC (bsrc);
1.275 -
1.276 if (src->content_size <= 0) {
1.277 ret= FALSE;
1.278 -
1.279 - } else if ( src->live_tv && src->content_size < MYTHTV_TRANSFER_MAX_BUFFER ) {
1.280 + } else if ( src->content_size >= src->read_offset &&
1.281 + abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
1.282 g_static_mutex_lock( &update_size_mutex );
1.283
1.284 + guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
1.285 + if ( src->content_size < new_offset ) {
1.286 + src->content_size = new_offset;
1.287 + }
1.288 +
1.289 +#if 0
1.290 #if ENABLE_TIMING_POSITION == 1
1.291 guint64 size_tmp = 0;
1.292 if (src->live_tv == TRUE) {
1.293 get_file_pos:
1.294 - g_usleep( 50 );
1.295 + g_usleep( 5 );
1.296 size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
1.297 if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
1.298 src->content_size = size_tmp;
1.299 @@ -700,6 +714,7 @@
1.300 __FUNCTION__, size_tmp );
1.301 }
1.302 #endif
1.303 +#endif
1.304 g_static_mutex_unlock( &update_size_mutex );
1.305
1.306 }
1.307 @@ -735,7 +750,6 @@
1.308 return TRUE;
1.309 }
1.310
1.311 -#if 0
1.312 static gboolean
1.313 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1.314 {
1.315 @@ -756,9 +770,10 @@
1.316 #endif
1.317 case GST_EVENT_EOS:
1.318 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
1.319 - src->content_size = gst_mythtv_src_get_position (src);
1.320 + guint64 cont_size = gst_mythtv_src_get_position (src);
1.321 if ( cont_size > src->content_size ) {
1.322 src->content_size = cont_size;
1.323 + src->eos = FALSE;
1.324 } else {
1.325 src->eos = TRUE;
1.326 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1.327 @@ -800,7 +815,6 @@
1.328
1.329 return gst_pad_event_default (pad, event);
1.330 }
1.331 -#endif
1.332
1.333 static gboolean
1.334 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
2.1 --- a/gst-plugins-mythtv/src/myth_file_transfer.c Thu Oct 12 01:50:27 2006 +0100
2.2 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c Tue Oct 17 01:03:06 2006 +0100
2.3 @@ -784,20 +784,21 @@
2.4 //g_static_mutex_lock (&mutex);
2.5 //strlist = gmyth_string_list_new();
2.6
2.7 - g_string_printf ( transfer->query, "%s %d", /*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER,
2.8 + g_string_printf ( transfer->query, "%s %d",
2.9 + /*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER,
2.10 /* transfer->live_tv ? transfer->card_id :*/ transfer->recordernum ); // transfer->recordernum
2.11 g_print( "\t[%s] Transfer_query = %s\n", __FUNCTION__, transfer->query->str );
2.12
2.13 strlist = gmyth_string_list_new();
2.14
2.15 gmyth_string_list_append_char_array( strlist, transfer->query->str );
2.16 - gmyth_string_list_append_char_array( strlist, /*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" );
2.17 + gmyth_string_list_append_char_array( strlist,
2.18 + /*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" );
2.19 gmyth_string_list_append_int( strlist, size );
2.20
2.21 gmyth_socket_write_stringlist( transfer->control_sock, strlist );
2.22 sent = size;
2.23 //g_static_mutex_unlock( &mutex );
2.24 -
2.25 //data = (void*)g_new0( gchar, size );
2.26
2.27 g_io_channel_flush( io_channel_control, NULL );
2.28 @@ -815,12 +816,14 @@
2.29 //usleep(200);
2.30 //
2.31 //io_cond = g_io_channel_get_buffer_condition( io_channel );
2.32 - //
2.33 + //g_static_mutex_lock( &mutex );
2.34
2.35 buf_len = ( sent - recv ) > MYTHTV_BUFFER_SIZE ? MYTHTV_BUFFER_SIZE : ( sent - recv );
2.36
2.37 io_status = g_io_channel_read_chars( io_channel, data + recv,
2.38 buf_len, &bytes_read, &error );
2.39 +
2.40 + //g_static_mutex_unlock( &mutex );
2.41 /*
2.42 GString *sss = g_string_new("");
2.43 sss = g_string_append_len( sss, (gchar*)data+recv, bytes_read );
2.44 @@ -863,8 +866,9 @@
2.45 gmyth_socket_read_stringlist( transfer->control_sock, strlist );
2.46 sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
2.47 g_print( "[%s]\t sent = %d, io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__,
2.48 - sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
2.49 + sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
2.50 response = TRUE;
2.51 + break;
2.52 }
2.53 }
2.54
2.55 @@ -875,24 +879,23 @@
2.56 {
2.57 if ( strlist != NULL && gmyth_string_list_length(strlist) > 0 ) {
2.58 sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
2.59 - g_print( "[%s]\t sent = %d, io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__,
2.60 + g_print( "[%s]\t sent = %d, raw buffer I/O socket %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__,
2.61 sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
2.62 }
2.63 }
2.64 else
2.65 {
2.66 g_printerr ( "myth_file_transfer_read(): No response from control socket.");
2.67 - sent = -1;
2.68 + recv = -1;
2.69 + }
2.70 +
2.71 + } else if ( error!=NULL ) {
2.72 + g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message );
2.73 + //g_error_free( error );
2.74 }
2.75
2.76 - if ( error!=NULL ) {
2.77 - g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message );
2.78 - g_error_free( error );
2.79 - }
2.80 - }
2.81 - //g_static_mutex_unlock( &mutex );
2.82 -
2.83 cleanup:
2.84 + g_static_mutex_unlock (&mutex);
2.85
2.86 if ( trash != NULL )
2.87 g_free( trash );
2.88 @@ -900,8 +903,6 @@
2.89 if ( strlist != NULL )
2.90 g_object_unref( strlist );
2.91
2.92 - g_static_mutex_unlock (&mutex);
2.93 -
2.94 g_print( "myth_file_transfer_read(): reqd=%d, rcvd=%d, rept=%d, "\
2.95 "(rcvd and rept MUST be the same!)\n", size,
2.96 recv, sent );
2.97 @@ -911,7 +912,7 @@
2.98 //}
2.99
2.100 if ( error != NULL ) {
2.101 - g_printerr( "ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
2.102 + g_printerr( "Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
2.103 error->code );
2.104 g_error_free( error );
2.105 }
2.106 @@ -919,7 +920,7 @@
2.107 return recv;
2.108 }
2.109
2.110 - void
2.111 +void
2.112 myth_file_transfer_settimeout( MythFileTransfer *transfer, gboolean fast )
2.113 {
2.114