[svn r96] Removed guint8 * buffer, changed to a GstAdapter.
1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 18:18:24 2006 +0000
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 18:39:47 2006 +0000
1.3 @@ -30,7 +30,7 @@
1.4 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
1.5 #define GST_CAT_DEFAULT mythtvsrc_debug
1.6
1.7 -#define GST_GMYTHTV_ID_NUM 1
1.8 +#define GST_GMYTHTV_ID_NUM 1
1.9
1.10 #define GST_GMYTHTV_CHANNEL_NUM 1000
1.11
1.12 @@ -42,12 +42,12 @@
1.13 //( 32*1024 )
1.14
1.15 /* 4*1024 ??? */
1.16 -#define MAX_READ_SIZE 4*1024
1.17 +#define MAX_READ_SIZE 6*1024
1.18 //( 32*1024 )
1.19
1.20 #define GST_FLOW_ERROR_NO_DATA -101
1.21
1.22 -#define INTERNAL_BUFFER_SIZE 28*1024
1.23 +#define INTERNAL_BUFFER_SIZE 30*1024
1.24
1.25 /* stablish a maximum iteration value to the IS_RECORDING message */
1.26 static guint wait_to_transfer = 0;
1.27 @@ -570,121 +570,86 @@
1.28 goto eos;
1.29 if ( G_UNLIKELY (src->update_prog_chain) )
1.30 goto change_progchain;
1.31 -
1.32 +
1.33 //g_static_rec_mutex_lock( &th_mutex );
1.34 g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
1.35
1.36 - while ( src->adapter != NULL && ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) &&
1.37 - --max_adapter_rep > 0 )
1.38 - {
1.39 - g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
1.40 - //GST_TASK_WAIT( src->th_read_ahead );
1.41 + /* just get from the adapter, no network effort... */
1.42 + GstBuffer *buffer;
1.43 + guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.44 +
1.45 + g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
1.46 + (gint) src->buffer_remain);
1.47 +
1.48 + /* Create the buffer. */
1.49 + ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.50 + src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
1.51 + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
1.52 +
1.53 + if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1.54 + if ( src->live_tv )
1.55 + goto change_progchain;
1.56 + else
1.57 + goto done;
1.58 }
1.59
1.60 - g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
1.61 + if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
1.62
1.63 - //gst_task_pause( src->th_read_ahead );
1.64 + buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.65
1.66 - //g_static_rec_mutex_unlock( &th_mutex );
1.67 + read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
1.68
1.69 - /* just get from the adapter, no network effort... */
1.70 - if ( FALSE )
1.71 - {
1.72 - //g_static_rec_mutex_lock( &th_mutex );
1.73 -
1.74 - *outbuf = gst_adapter_take_buffer( src->adapter, adapter_size );
1.75 - // src->read_offset += size;
1.76 - read = adapter_size;
1.77 -
1.78 - gst_adapter_flush( src->adapter, adapter_size );
1.79 - //g_static_rec_mutex_unlock( &th_mutex );
1.80 -
1.81 - } else {
1.82 - GstBuffer *buffer;
1.83 - guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.84 -
1.85 - g_print ( "[%s]\t\tCreate: buffer_offset: %d, buffer_remain: %d\n", __FUNCTION__,
1.86 - (gint) src->buffer_offset,
1.87 - (gint) src->buffer_remain);
1.88 -
1.89 - /* Create the buffer. */
1.90 - ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.91 - src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
1.92 - GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
1.93 -
1.94 - if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1.95 + if (G_UNLIKELY (read < 0)) {
1.96 if ( src->live_tv )
1.97 goto change_progchain;
1.98 else
1.99 - goto done;
1.100 + goto read_error;
1.101 }
1.102
1.103 - if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
1.104 -
1.105 - buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.106 + if ( G_UNLIKELY (src->update_prog_chain) )
1.107 + goto change_progchain;
1.108
1.109 - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
1.110 + gst_adapter_push( src->adapter, buffer );
1.111
1.112 - if (G_UNLIKELY (read < 0)) {
1.113 - if ( src->live_tv )
1.114 - goto change_progchain;
1.115 - else
1.116 - goto read_error;
1.117 - }
1.118 + src->buffer_remain = src->buffer_remain + read;
1.119
1.120 - if ( G_UNLIKELY (src->update_prog_chain) )
1.121 - goto change_progchain;
1.122 -
1.123 - gst_adapter_push( src->adapter, buffer );
1.124 -
1.125 - src->buffer_offset = 0;
1.126 - src->buffer_remain = src->buffer_remain + read;
1.127 -
1.128 - g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.129 - "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.130 - src->read_offset, src->content_size );
1.131 -
1.132 - }
1.133 -
1.134 - size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.135 -
1.136 - buffer = gst_adapter_take_buffer( src->adapter, size );
1.137 -
1.138 - g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
1.139 -
1.140 - GST_BUFFER_SIZE (*outbuf) = size;
1.141 - GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
1.142 - GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
1.143 - g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
1.144 - GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
1.145 - GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
1.146 -
1.147 - src->buffer_offset += GST_BUFFER_SIZE (*outbuf);
1.148 - src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
1.149 -
1.150 - src->read_offset += GST_BUFFER_SIZE (*outbuf);
1.151 - src->bytes_read += GST_BUFFER_SIZE (*outbuf);
1.152 - g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
1.153 -
1.154 - //gst_adapter_flush( src->adapter, size );
1.155 - gst_buffer_unref( buffer );
1.156 -
1.157 - g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
1.158 - "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
1.159 - GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
1.160 -
1.161 - /* just get from the adapter, no network effort... */
1.162 + g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.163 + "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.164 + src->read_offset, src->content_size );
1.165
1.166 }
1.167
1.168 + size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.169 +
1.170 + buffer = gst_adapter_take_buffer( src->adapter, size );
1.171 +
1.172 + g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
1.173 +
1.174 + GST_BUFFER_SIZE (*outbuf) = size;
1.175 + GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
1.176 + GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
1.177 + g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
1.178 + GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
1.179 + GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
1.180 +
1.181 + src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
1.182 +
1.183 + src->read_offset += GST_BUFFER_SIZE (*outbuf);
1.184 + src->bytes_read += GST_BUFFER_SIZE (*outbuf);
1.185 + g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
1.186 +
1.187 + //gst_adapter_flush( src->adapter, size );
1.188 + gst_buffer_unref( buffer );
1.189 +
1.190 + g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
1.191 + "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
1.192 + GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
1.193 +
1.194 + /* just get from the adapter, no network effort... */
1.195 +
1.196 +
1.197 return ret;
1.198
1.199 - //g_static_rec_mutex_lock( &th_mutex );
1.200 -
1.201 - //GST_TASK_SIGNAL( src->th_read_ahead );
1.202 -
1.203 - //g_static_rec_mutex_unlock( &th_mutex );
1.204 -
1.205 done:
1.206 {
1.207 const gchar *reason = gst_flow_get_name (ret);
1.208 @@ -761,11 +726,6 @@
1.209 gboolean ret = TRUE;
1.210
1.211 g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop );
1.212 - //g_static_rec_mutex_lock( &th_mutex );
1.213 -
1.214 - //GST_TASK_WAIT( src->th_read_ahead );
1.215 -
1.216 - //g_static_rec_mutex_unlock( &th_mutex );
1.217
1.218 if ( segment->format == GST_FORMAT_TIME )
1.219 {
1.220 @@ -792,19 +752,18 @@
1.221
1.222 src->read_offset = new_offset;
1.223
1.224 - //gst_segment_set_seek( segment, segment->rate, GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
1.225 - //GST_SEEK_TYPE_CUR, src->read_offset, GST_SEEK_TYPE_CUR, segment->stop, &ret );
1.226 -
1.227 if ( ret == FALSE ) {
1.228 g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ );
1.229 }
1.230
1.231 }
1.232 - //g_static_rec_mutex_lock( &th_mutex );
1.233 + /*
1.234 + g_static_rec_mutex_lock( &th_mutex );
1.235
1.236 - //GST_TASK_SIGNAL( src->th_read_ahead );
1.237 + GST_TASK_SIGNAL( src->th_read_ahead );
1.238
1.239 - //g_static_rec_mutex_unlock( &th_mutex );
1.240 + g_static_rec_mutex_unlock( &th_mutex );
1.241 + */
1.242 done:
1.243 return ret;
1.244
1.245 @@ -970,11 +929,6 @@
1.246 //gst_task_set_lock( src->th_read_ahead, &th_mutex );
1.247 //gst_task_start( src->th_read_ahead );
1.248 // }
1.249 - //gst_pad_push_event ( GST_BASE_SRC_PAD (bsrc),
1.250 - // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) );
1.251 -
1.252 - src->buffer = g_malloc0 (INTERNAL_BUFFER_SIZE);
1.253 - src->buffer_offset = 0;
1.254 src->buffer_remain = 0;
1.255
1.256
2.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.h Fri Nov 17 18:18:24 2006 +0000
2.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.h Fri Nov 17 18:39:47 2006 +0000
2.3 @@ -75,11 +75,7 @@
2.4 gint64 read_offset;
2.5 gint64 adapter_offset;
2.6
2.7 - //guint64 file_size;
2.8 - /* added by melunko */
2.9 - guint8* buffer;
2.10 -
2.11 - gint buffer_offset;
2.12 + /* added by melunko (buffer cache) */
2.13 gint buffer_remain;
2.14
2.15 gboolean eos;