1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Nov 06 23:12:21 2006 +0000
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Thu Nov 09 19:45:27 2006 +0000
1.3 @@ -38,7 +38,7 @@
1.4
1.5 #define GMYTHTV_TRANSFER_MAX_WAITS 100
1.6
1.7 -#define GMYTHTV_TRANSFER_MAX_BUFFER 64*1024
1.8 +#define GMYTHTV_TRANSFER_MAX_BUFFER 4*1024
1.9 //( 32*1024 )
1.10
1.11 /* 4*1024 ??? */
1.12 @@ -61,10 +61,12 @@
1.13 GST_PAD_ALWAYS,
1.14 GST_STATIC_CAPS ("video/x-nuv") );
1.15
1.16 +/*
1.17 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
1.18 GST_PAD_SINK,
1.19 - GST_PAD_ALWAYS,
1.20 + GST_PAD_SOMETIMES,
1.21 GST_STATIC_CAPS ("video/x-nuv") );
1.22 +*/
1.23
1.24 enum
1.25 {
1.26 @@ -104,7 +106,7 @@
1.27
1.28 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
1.29
1.30 -static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.31 +//static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.32 //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
1.33
1.34 static gint do_read_request_response (GstMythtvSrc *src, guint64 offset,
1.35 @@ -207,7 +209,7 @@
1.36 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
1.37 g_param_spec_int ("mythtv-channel", "mythtv-channel",
1.38 "Change MythTV channel number",
1.39 - 0, 200, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
1.40 + 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
1.41
1.42 #ifndef GST_DISABLE_GST_DEBUG
1.43 g_object_class_install_property
1.44 @@ -263,8 +265,8 @@
1.45
1.46 this->adapter = NULL;
1.47
1.48 - this->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
1.49 - gst_element_add_pad (GST_ELEMENT (this), this->sinkpad);
1.50 + //this->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
1.51 + //gst_element_add_pad (GST_ELEMENT (this), this->sinkpad);
1.52
1.53 /*
1.54 this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
1.55 @@ -275,8 +277,8 @@
1.56
1.57 gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
1.58
1.59 - gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.60 - gst_mythtv_src_handle_event );
1.61 + // gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.62 + // gst_mythtv_src_handle_event );
1.63 /*
1.64 gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.65 gst_mythtv_src_query );
1.66 @@ -327,9 +329,6 @@
1.67 * Retry whilst authentication fails and we supply it. */
1.68 gint len = 0;
1.69
1.70 - /* max number of buffer resend interactions */
1.71 - //guint max_tries = 3;
1.72 -
1.73 GST_OBJECT_LOCK(src);
1.74
1.75 while ( sizetoread > 0 ) {
1.76 @@ -353,7 +352,7 @@
1.77 {
1.78 if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
1.79 src->update_prog_chain = TRUE;
1.80 - goto done;
1.81 + goto done;
1.82 } else
1.83 if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
1.84 src->update_prog_chain = TRUE;
1.85 @@ -435,7 +434,7 @@
1.86 GST_OBJECT_LOCK(src);
1.87
1.88 if (G_UNLIKELY (src->read_offset != offset)) {
1.89 - gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, SEEK_SET);
1.90 + gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
1.91 g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
1.92 __FUNCTION__, src->read_offset, new_offset );
1.93 if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
1.94 @@ -521,11 +520,10 @@
1.95 {
1.96
1.97 gint64 size_tmp = 0;
1.98 - guint max_tries = 3;
1.99 - if (src->live_tv == TRUE && ( abs( src->content_size - src->prev_content_size ) <
1.100 - GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1.101 - /* sets the last content size amount before it can be updated */
1.102 - src->prev_content_size = src->content_size;
1.103 + guint max_tries = 2;
1.104 + if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) <
1.105 + GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1.106 +
1.107 get_file_pos:
1.108 g_usleep( 10 );
1.109 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1.110 @@ -535,6 +533,8 @@
1.111 goto get_file_pos;
1.112 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1.113 __FUNCTION__, size_tmp );
1.114 + /* sets the last content size amount before it can be updated */
1.115 + src->prev_content_size = src->content_size;
1.116 }
1.117
1.118 return src->content_size;
1.119 @@ -551,8 +551,8 @@
1.120
1.121 gboolean ret = TRUE;
1.122
1.123 - if ( !src->do_start )
1.124 - goto done;
1.125 + if ( G_UNLIKELY (src->update_prog_chain) )
1.126 + goto change_progchain;
1.127
1.128 if (src->unique_setup == FALSE) {
1.129 src->unique_setup = TRUE;
1.130 @@ -617,10 +617,10 @@
1.131
1.132 src->content_size = src->file_transfer->filesize;
1.133
1.134 + src->do_start = FALSE;
1.135 +
1.136 GST_OBJECT_UNLOCK(src);
1.137
1.138 - src->do_start = FALSE;
1.139 -
1.140 done:
1.141 return TRUE;
1.142
1.143 @@ -640,6 +640,21 @@
1.144 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
1.145 return FALSE;
1.146 }
1.147 +change_progchain:
1.148 + {
1.149 + GST_ELEMENT_ERROR (src, RESOURCE, READ,
1.150 + (NULL), ("Seek failed, go to the next program info... (%s)",
1.151 + src->uri_name));
1.152 + // go to the next program chain
1.153 + src->unique_setup = FALSE;
1.154 + src->update_prog_chain = TRUE;
1.155 +
1.156 + //GST_OBJECT_LOCK(src);
1.157 + gst_mythtv_src_next_program_chain( src );
1.158 + //GST_OBJECT_UNLOCK(src);
1.159 +
1.160 + return TRUE;
1.161 + }
1.162 }
1.163
1.164 /* create a new socket for connecting to the next program chain */
1.165 @@ -730,16 +745,13 @@
1.166 #endif
1.167
1.168 src->content_size = src->file_transfer->filesize;
1.169 - while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 )
1.170 + while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 )
1.171 src->content_size = gst_mythtv_src_get_position( src );
1.172
1.173 src->read_offset = 0;
1.174
1.175 src->update_prog_chain = FALSE;
1.176
1.177 - gst_pad_push_event ( src->sinkpad,
1.178 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) );
1.179 -
1.180 done:
1.181 return TRUE;
1.182
1.183 @@ -904,6 +916,7 @@
1.184 return TRUE;
1.185 }
1.186
1.187 +#if 0
1.188 static gboolean
1.189 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1.190 {
1.191 @@ -992,6 +1005,7 @@
1.192
1.193 return gst_pad_event_default (pad, event);
1.194 }
1.195 +#endif
1.196
1.197 static gboolean
1.198 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1.199 @@ -1034,7 +1048,7 @@
1.200 goto read_error;
1.201 }
1.202
1.203 - if ( GST_FLOW_OK != ( ret = gst_pad_push ( src->sinkpad, buf ) ) ) {
1.204 + if ( GST_FLOW_OK != ( ret = gst_pad_push ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), buf ) ) ) {
1.205 goto done;
1.206 }
1.207
1.208 @@ -1120,7 +1134,7 @@
1.209 GST_ELEMENT_ERROR (src, STREAM, FAILED,
1.210 ("Internal data stream error."),
1.211 ("streaming stopped, reason %s", gst_flow_get_name (res)));
1.212 - gst_pad_send_event( src->sinkpad, gst_event_new_eos() );
1.213 + gst_pad_send_event( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_eos() );
1.214 }
1.215 return res;
1.216 }
1.217 @@ -1129,7 +1143,7 @@
1.218 static GstStateChangeReturn
1.219 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1.220 {
1.221 - GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; //GST_STATE_CHANGE_NO_PREROLL;
1.222 + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;//GST_STATE_CHANGE_NO_PREROLL;
1.223 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1.224
1.225 switch (transition) {
1.226 @@ -1152,23 +1166,21 @@
1.227 switch (transition) {
1.228 case GST_STATE_CHANGE_READY_TO_NULL:
1.229 g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
1.230 - if ( src->live_tv && src->update_prog_chain ) {
1.231 - gst_pad_push_event ( src->sinkpad,
1.232 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) );
1.233 - gst_element_set_state ( GST_ELEMENT (src), GST_STATE_READY );
1.234 - }
1.235 break;
1.236 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1.237 g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1.238 case GST_STATE_CHANGE_PAUSED_TO_READY:
1.239 g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1.240 if ( src->live_tv && src->update_prog_chain ) {
1.241 + GstPad *pad_peer;
1.242 + gst_pad_push_event ( pad_peer = gst_pad_get_peer( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ),
1.243 + gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0 ) );
1.244 src->read_offset = 0;
1.245 src->bytes_read = 0;
1.246 src->unique_setup = FALSE;
1.247 - //GST_OBJECT_LOCK( src );
1.248 + GST_OBJECT_LOCK( src );
1.249 gst_mythtv_src_next_program_chain( src );
1.250 - //GST_OBJECT_UNLOCK( src );
1.251 + GST_OBJECT_UNLOCK( src );
1.252 }
1.253 break;
1.254 default: