1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Nov 27 22:07:09 2006 +0000
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Tue Nov 28 15:14:16 2006 +0000
1.3 @@ -12,6 +12,16 @@
1.4 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.5 * Library General Public License for more
1.6 */
1.7 + /**
1.8 + * When using the LiveTV content, put the location URI in the following
1.9 + * format:
1.10 + *
1.11 + * myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/#mythconverg
1.12 + *
1.13 + * Where the first field is the protocol (myth), the second and third are user
1.14 + * name (mythtv) and password (mythtv), then backend host name and port number,
1.15 + * and the last field is the database name (mythconverg).
1.16 + */
1.17
1.18 #ifdef HAVE_CONFIG_H
1.19 #include "config.h"
1.20 @@ -49,7 +59,9 @@
1.21
1.22 #define GST_FLOW_ERROR_NO_DATA -101
1.23
1.24 -#define INTERNAL_BUFFER_SIZE 40*1024
1.25 +#define REQUEST_MAX_SIZE 64*1024
1.26 +
1.27 +#define INTERNAL_BUFFER_SIZE 200*1024
1.28
1.29 /* stablish a maximum iteration value to the IS_RECORDING message */
1.30 static guint wait_to_transfer = 0;
1.31 @@ -411,38 +423,50 @@
1.32 (gint) src->buffer_remain, src->bytes_queue->len );
1.33
1.34 /* just get from the byte array, no network effort... */
1.35 - if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
1.36 - //if ( src->buffer_remain ) {
1.37 - guint buffer_size_inter = INTERNAL_BUFFER_SIZE - src->buffer_remain;
1.38 - GByteArray *buffer = g_byte_array_new();
1.39 + if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
1.40 + //( ( INTERNAL_BUFFER_SIZE - src->buffer_remain ) >= REQUEST_MAX_SIZE ) ) {
1.41 + GByteArray *buffer = NULL;
1.42 + guint amount_to_fill = ( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.43 + guint buffer_size_inter = 0;
1.44 +
1.45 + //do {
1.46 + if ( amount_to_fill < REQUEST_MAX_SIZE )
1.47 + buffer_size_inter = amount_to_fill;
1.48 + else
1.49 + buffer_size_inter = REQUEST_MAX_SIZE;
1.50
1.51 - read = do_read_request_response( src, buffer_size_inter, buffer );
1.52 -
1.53 - if (G_UNLIKELY (read < 0)) {
1.54 - if ( src->live_tv )
1.55 - goto change_progchain;
1.56 - else
1.57 - goto read_error;
1.58 - }
1.59 -
1.60 - if ( G_UNLIKELY (src->update_prog_chain) )
1.61 - goto change_progchain;
1.62 -
1.63 - src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read );
1.64 - if ( read > buffer_size_inter )
1.65 - GST_WARNING_OBJECT( src, "[%s] INCREASED buffer size! Backend sent more than we ask him... (%d)\n",
1.66 - __FUNCTION__, abs( read - buffer_size_inter ) );
1.67 -
1.68 - src->buffer_remain = src->buffer_remain + read;
1.69 -
1.70 - if ( buffer != NULL ) {
1.71 - g_byte_array_free( buffer, TRUE );
1.72 - buffer = NULL;
1.73 - }
1.74 -
1.75 - GST_DEBUG_OBJECT( src, "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.76 - "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.77 - src->read_offset, src->content_size );
1.78 + buffer = g_byte_array_new();
1.79 +
1.80 + read = do_read_request_response( src, buffer_size_inter, buffer );
1.81 +
1.82 + if (G_UNLIKELY (read < 0)) {
1.83 + if ( src->live_tv )
1.84 + goto change_progchain;
1.85 + else
1.86 + goto read_error;
1.87 + }
1.88 +
1.89 + if ( G_UNLIKELY (src->update_prog_chain) )
1.90 + goto change_progchain;
1.91 +
1.92 + src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read );
1.93 + if ( read > buffer_size_inter )
1.94 + GST_WARNING_OBJECT( src, "[%s] INCREASED buffer size! Backend sent more than we ask him... (%d)\n",
1.95 + __FUNCTION__, abs( read - buffer_size_inter ) );
1.96 +
1.97 + src->buffer_remain += read;
1.98 + amount_to_fill -= read;
1.99 +
1.100 + //} while ( amount_to_fill > 0 );
1.101 +
1.102 + if ( buffer != NULL ) {
1.103 + g_byte_array_free( buffer, TRUE );
1.104 + buffer = NULL;
1.105 + }
1.106 +
1.107 + GST_DEBUG_OBJECT( src, "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.108 + "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
1.109 + src->read_offset, src->content_size );
1.110
1.111 }
1.112
1.113 @@ -673,6 +697,7 @@
1.114 if ( src->file_transfer == NULL ) {
1.115 goto init_failed;
1.116 }
1.117 + GST_INFO_OBJECT( src, "[%s] uri = %s.\n", __FUNCTION__, src->uri_name );
1.118
1.119 ret = gmyth_file_transfer_open( src->file_transfer, g_string_new( src->uri_name ) );
1.120
1.121 @@ -690,7 +715,7 @@
1.122 /* IS_RECORDING again, just like the MythTV backend does... */
1.123 gmyth_livetv_is_recording( src->spawn_livetv );
1.124
1.125 - sleep( 4 );
1.126 + sleep( 3 );
1.127
1.128 }
1.129 /* sets the FileTransfer instance connection (video/audio download) */
1.130 @@ -712,8 +737,8 @@
1.131 src->bytes_queue = g_byte_array_sized_new( INTERNAL_BUFFER_SIZE );
1.132 src->buffer_remain = 0;
1.133
1.134 - //gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1.135 - // gst_event_new_new_segment ( TRUE, 1.0, GST_FORMAT_TIME, 0, src->content_size, 0 ) );
1.136 + gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1.137 + gst_event_new_new_segment ( TRUE, 1.0, GST_FORMAT_TIME, 0, src->content_size, 0 ) );
1.138
1.139 done:
1.140 return TRUE;
1.141 @@ -978,10 +1003,13 @@
1.142 gint64 pos = -1;
1.143 gst_query_parse_position (query, &formt, &pos );
1.144 res = TRUE;
1.145 - if ( formt == GST_FORMAT_BYTES )
1.146 + if ( formt == GST_FORMAT_BYTES ) {
1.147 + gst_query_set_position (query, formt, pos = myth->read_offset );
1.148 GST_DEBUG_OBJECT (myth, "POS %lld (BYTES).\n", pos );
1.149 - else if ( formt == GST_FORMAT_TIME )
1.150 + } else if ( formt == GST_FORMAT_TIME ) {
1.151 GST_DEBUG_OBJECT (myth, "POS %lld (TIME).\n", pos );
1.152 + res = gst_pad_query_default(pad, query);
1.153 + }
1.154 break;
1.155 }
1.156 case GST_QUERY_DURATION:
1.157 @@ -996,18 +1024,21 @@
1.158 }
1.159 #endif
1.160 gint64 dur = -1;
1.161 - gst_query_parse_duration( query, &formt, &dur );
1.162 - //gst_query_set_duration (query, GST_FORMAT_TIME, myth->content_size);
1.163 - if ( formt == GST_FORMAT_BYTES )
1.164 + gst_query_parse_duration ( query, &formt, &dur );
1.165 + if ( formt == GST_FORMAT_BYTES ) {
1.166 + gst_query_set_duration (query, formt, dur = myth->content_size);
1.167 GST_DEBUG_OBJECT (myth, "DURATION %lld (BYTES).\n", dur );
1.168 - else if ( formt == GST_FORMAT_TIME )
1.169 + } else if ( formt == GST_FORMAT_TIME ) {
1.170 GST_DEBUG_OBJECT (myth, "DURATION %lld (TIME).\n", dur );
1.171 + gst_query_ref(query);
1.172 + res = gst_pad_query_default(pad, query);
1.173 + }
1.174 res = TRUE;
1.175 break;
1.176 }
1.177 default:
1.178 {
1.179 - res = FALSE;
1.180 + res = gst_pad_query_default(pad, query);
1.181 break;
1.182 }
1.183 }
1.184 @@ -1029,8 +1060,17 @@
1.185 //src->unique_setup = FALSE;
1.186 break;
1.187 case GST_STATE_CHANGE_READY_TO_PAUSED:
1.188 + GST_INFO_OBJECT( src, "[%s] READY to PAUSED called!\n", __FUNCTION__ );
1.189 + break;
1.190 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1.191 - //src->eos = FALSE;
1.192 + GST_INFO_OBJECT( src, "[%s] PAUSED to PLAYING called!\n", __FUNCTION__ );
1.193 + if ( src->live_tv ) {
1.194 + if ( !gmyth_recorder_send_frontend_ready_command( src->spawn_livetv->recorder ) )
1.195 + GST_WARNING_OBJECT( src, "[%s] Couldn't send the FRONTEND_READY message to the backend!", __FUNCTION__ );
1.196 + else
1.197 + GST_DEBUG_OBJECT( src, "[%s] Message FRONTEND_READY was sent to the backend!", __FUNCTION__ );
1.198 + }
1.199 +
1.200 break;
1.201 default:
1.202 break;
1.203 @@ -1048,7 +1088,7 @@
1.204 GST_INFO_OBJECT( src, "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1.205 case GST_STATE_CHANGE_PAUSED_TO_READY:
1.206 GST_INFO_OBJECT( src, "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1.207 - if ( src->live_tv && src->update_prog_chain ) {
1.208 + if ( src->live_tv ) {
1.209 if ( !gmyth_recorder_send_frontend_ready_command( src->spawn_livetv->recorder ) )
1.210 GST_WARNING_OBJECT( src, "[%s] Couldn't send the FRONTEND_READY message to the backend!", __FUNCTION__ );
1.211 else