# HG changeset patch # User rosfran # Date 1161043386 -3600 # Node ID eb4a812d407364ce15556dca429602116fffcad2 # Parent abe0ee48d78b4380c200e6337b54f60f08311317 [svn r32] Some adjustments on the performance. diff -r abe0ee48d78b -r eb4a812d4073 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Thu Oct 12 01:50:27 2006 +0100 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Tue Oct 17 01:03:06 2006 +0100 @@ -36,7 +36,7 @@ #define MYTHTV_TRANSFER_MAX_WAITS 100 -#define MYTHTV_TRANSFER_MAX_BUFFER 32*1024 +#define MYTHTV_TRANSFER_MAX_BUFFER 4*1024 //( 32*1024 ) /* 4*1024 ??? */ @@ -98,7 +98,7 @@ static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data); -//static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); +static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query ); static guint do_read_request_response (GstMythtvSrc *src, guint64 offset, @@ -237,17 +237,15 @@ //gst_pad_set_chain_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), // gst_mythtv_src_chain ); -/* gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), gst_mythtv_src_handle_event ); - +/* gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), gst_mythtv_src_query ); */ //gst_pad_set_activatepull_function( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), // gst_mythtv_src_sink_activate_pull ); - } static void @@ -283,7 +281,7 @@ { guint read = 0; guint sizetoread = size; //GST_BUFFER_SIZE (outbuf); - GstBuffer *buffer = gst_buffer_new_and_alloc( size ); + //GstBuffer *buffer = gst_buffer_new_and_alloc( size ); g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); @@ -291,12 +289,12 @@ * Retry whilst authentication fails and we supply it. */ guint len = 0; - //GST_OBJECT_LOCK(src); + GST_OBJECT_LOCK(src); while ( sizetoread > 0 ) { - - len = myth_file_transfer_read( src->file_transfer, - GST_BUFFER_DATA( buffer ) + read, sizetoread, TRUE ); + + len = myth_file_transfer_read( src->file_transfer, + GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE ); if ( len > 0 ) { read += len; @@ -308,47 +306,44 @@ goto done; } else if ( src->content_size >= src->read_offset && abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) { - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - goto done; - } else - goto eos; - } else - goto eos; + goto done; + } } - + if ( read == sizetoread ) break; } if ( read > 0 ) { src->bytes_read += read; - } - + g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, src->read_offset, src->content_size ); - - *outbuf = buffer; - memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read ); - GST_BUFFER_SIZE (buffer) = read; - GST_BUFFER_OFFSET (buffer) = offset; - GST_BUFFER_OFFSET_END (buffer) = offset + read; + + //GST_BUFFER_TIMESTAMP( buffer ) = GST_BUFFER_TIMESTAMP ( *outbuf ); + GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read; + GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset; + GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read; + //*outbuf = buffer; + //memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read ); g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); - //GST_OBJECT_UNLOCK(src); + + } else + goto eos; + goto done; eos: - //GST_OBJECT_UNLOCK(src); - + //GST_OBJECT_UNLOCK(src); src->eos = TRUE; done: + GST_OBJECT_UNLOCK(src); return read; } @@ -359,60 +354,82 @@ GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; guint read = 0; - //GstBuffer *buffer = NULL; - //guint size = MAX_READ_SIZE; src = GST_MYTHTV_SRC (psrc); + /* The caller should know the number of bytes and not read beyond EOS. */ + if (G_UNLIKELY (src->eos)) + goto eos; - if ( src->content_size >= src->read_offset && - abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) { - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - } + //GST_OBJECT_LOCK(src); + if ( /*src->content_size >= src->read_offset && + abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/ + ( src->content_size <= ( src->read_offset + size ) ) ) + { +#if ENABLE_TIMING_POSITION == 1 + guint64 size_tmp = 0; + if (src->live_tv == TRUE) { +get_file_pos: + size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); + if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) + src->content_size = size_tmp; + else + goto get_file_pos; + g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", + __FUNCTION__, size_tmp ); + } +#endif + //guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); + //if ( src->content_size < new_offset ) { + // src->content_size = new_offset; + //} } if (G_UNLIKELY (src->read_offset != offset)) { guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET); - if (G_UNLIKELY (new_offset < 0 || new_offset != offset)) + if (G_UNLIKELY (new_offset < 0 || new_offset != offset)) { + //GST_OBJECT_UNLOCK(src); goto read_error; + } src->read_offset = offset; } + //GST_OBJECT_UNLOCK(src); - /* The caller should know the number of bytes and not read beyond EOS. */ - if (G_UNLIKELY (src->eos)) - goto eos; + /* Create the buffer. */ + ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), + src->read_offset, size, + //src->icy_caps ? src->icy_caps : + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf); - /* Create the buffer. */ - //ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - // GST_BUFFER_OFFSET_NONE, size, src->mythtv_caps ? src->mythtv_caps : - // GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); + if (G_UNLIKELY (ret != GST_FLOW_OK)) + goto done; - //if (G_UNLIKELY (ret != GST_FLOW_OK)) - // goto eos; - //if (G_UNLIKELY (ret == GST_FLOW_ERROR)) - // goto read_error; - - g_static_mutex_lock( &update_size_mutex ); - read = do_read_request_response ( src, 0, size, outbuf ); - g_static_mutex_unlock( &update_size_mutex ); + //g_static_mutex_lock( &update_size_mutex ); + read = do_read_request_response ( src, src->read_offset, size, outbuf ); + //g_static_mutex_unlock( &update_size_mutex ); - if (G_UNLIKELY (read < 0) || *outbuf == NULL) + if (G_UNLIKELY (read < 0) || *outbuf == NULL) { + //if ( src->live_tv ) + // goto done; + //else goto read_error; + } - gst_buffer_set_caps( *outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))) ); - - //*outbuf = buffer; - +/* if (G_UNLIKELY(src->eos)) goto eos; else goto done; +*/ done: - return ret; + { + const gchar *reason = gst_flow_get_name (ret); + + GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason); + return ret; + } eos: { const gchar *reason = gst_flow_get_name (ret); @@ -540,11 +557,6 @@ goto init_failed; } - if ( src->live_tv ) { - g_print ( "[%s] GST MYTHTVSRC: live_chain_id = %s\n", __FUNCTION__, src->live_chain_id ); - /* sets the MythSocket to the FileTransfer */ - //ret = myth_file_transfer_livetv_setup( &(src->file_transfer), src->spawn_livetv->remote_encoder->myth_socket ); - } /* sets the Playback monitor connection */ ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv ); @@ -575,9 +587,7 @@ if ( src->live_tv ) { //GError* error; - //update_size_task = g_thread_create( (GThreadFunc)update_size_func, src, FALSE, &error ); - g_print( "[%s] Update Size task = %s\n", __FUNCTION__, update_size_task != NULL ? "OK !" : "ERROR!!!" ); } @@ -675,22 +685,26 @@ static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size) { - GstMythtvSrc *src; + GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); gboolean ret = TRUE; - src = GST_MYTHTV_SRC (bsrc); - if (src->content_size <= 0) { ret= FALSE; - - } else if ( src->live_tv && src->content_size < MYTHTV_TRANSFER_MAX_BUFFER ) { + } else if ( src->content_size >= src->read_offset && + abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) { g_static_mutex_lock( &update_size_mutex ); + guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); + if ( src->content_size < new_offset ) { + src->content_size = new_offset; + } + +#if 0 #if ENABLE_TIMING_POSITION == 1 guint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: - g_usleep( 50 ); + g_usleep( 5 ); size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) src->content_size = size_tmp; @@ -700,6 +714,7 @@ __FUNCTION__, size_tmp ); } #endif +#endif g_static_mutex_unlock( &update_size_mutex ); } @@ -735,7 +750,6 @@ return TRUE; } -#if 0 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event) { @@ -756,9 +770,10 @@ #endif case GST_EVENT_EOS: g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ ); - src->content_size = gst_mythtv_src_get_position (src); + guint64 cont_size = gst_mythtv_src_get_position (src); if ( cont_size > src->content_size ) { src->content_size = cont_size; + src->eos = FALSE; } else { src->eos = TRUE; gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); @@ -800,7 +815,6 @@ return gst_pad_event_default (pad, event); } -#endif static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src ) diff -r abe0ee48d78b -r eb4a812d4073 gst-plugins-mythtv/src/myth_file_transfer.c --- a/gst-plugins-mythtv/src/myth_file_transfer.c Thu Oct 12 01:50:27 2006 +0100 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c Tue Oct 17 01:03:06 2006 +0100 @@ -784,20 +784,21 @@ //g_static_mutex_lock (&mutex); //strlist = gmyth_string_list_new(); - g_string_printf ( transfer->query, "%s %d", /*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER, + g_string_printf ( transfer->query, "%s %d", + /*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER, /* transfer->live_tv ? transfer->card_id :*/ transfer->recordernum ); // transfer->recordernum g_print( "\t[%s] Transfer_query = %s\n", __FUNCTION__, transfer->query->str ); strlist = gmyth_string_list_new(); gmyth_string_list_append_char_array( strlist, transfer->query->str ); - gmyth_string_list_append_char_array( strlist, /*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" ); + gmyth_string_list_append_char_array( strlist, + /*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" ); gmyth_string_list_append_int( strlist, size ); gmyth_socket_write_stringlist( transfer->control_sock, strlist ); sent = size; //g_static_mutex_unlock( &mutex ); - //data = (void*)g_new0( gchar, size ); g_io_channel_flush( io_channel_control, NULL ); @@ -815,12 +816,14 @@ //usleep(200); // //io_cond = g_io_channel_get_buffer_condition( io_channel ); - // + //g_static_mutex_lock( &mutex ); buf_len = ( sent - recv ) > MYTHTV_BUFFER_SIZE ? MYTHTV_BUFFER_SIZE : ( sent - recv ); io_status = g_io_channel_read_chars( io_channel, data + recv, buf_len, &bytes_read, &error ); + + //g_static_mutex_unlock( &mutex ); /* GString *sss = g_string_new(""); sss = g_string_append_len( sss, (gchar*)data+recv, bytes_read ); @@ -863,8 +866,9 @@ gmyth_socket_read_stringlist( transfer->control_sock, strlist ); sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error g_print( "[%s]\t sent = %d, io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, - sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); + sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); response = TRUE; + break; } } @@ -875,24 +879,23 @@ { if ( strlist != NULL && gmyth_string_list_length(strlist) > 0 ) { sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error - g_print( "[%s]\t sent = %d, io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, + g_print( "[%s]\t sent = %d, raw buffer I/O socket %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); } } else { g_printerr ( "myth_file_transfer_read(): No response from control socket."); - sent = -1; + recv = -1; + } + + } else if ( error!=NULL ) { + g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message ); + //g_error_free( error ); } - if ( error!=NULL ) { - g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message ); - g_error_free( error ); - } - } - //g_static_mutex_unlock( &mutex ); - cleanup: + g_static_mutex_unlock (&mutex); if ( trash != NULL ) g_free( trash ); @@ -900,8 +903,6 @@ if ( strlist != NULL ) g_object_unref( strlist ); - g_static_mutex_unlock (&mutex); - g_print( "myth_file_transfer_read(): reqd=%d, rcvd=%d, rept=%d, "\ "(rcvd and rept MUST be the same!)\n", size, recv, sent ); @@ -911,7 +912,7 @@ //} if ( error != NULL ) { - g_printerr( "ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message, + g_printerr( "Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message, error->code ); g_error_free( error ); } @@ -919,7 +920,7 @@ return recv; } - void +void myth_file_transfer_settimeout( MythFileTransfer *transfer, gboolean fast ) {