diff -r abe0ee48d78b -r 6b9c77b9817e 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 Wed Oct 18 20:38:47 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 )