gst-plugins-mythtv/src/gstmythtvsrc.c
author rosfran
Wed Nov 15 14:37:59 2006 +0000 (2006-11-15)
branchtrunk
changeset 86 ac9a990a5733
parent 71 55c7f31b85aa
child 87 9ea342c364de
permissions -rwxr-xr-x
[svn r87] Minor fix on reading function.
leo_sobral@2
     1
/* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2 -*- */
leo_sobral@2
     2
/* GStreamer MythTV Plug-in
leo_sobral@2
     3
 * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
leo_sobral@2
     4
 *
leo_sobral@2
     5
 * This library is free software; you can redistribute it and/or
rosfran@30
     6
 * modify it under the terms of the GNU Library Lesser General 
rosfran@30
     7
 * Public License as published by the Free Software Foundation; either
leo_sobral@2
     8
 * version 2 of the License, or (at your option) any later version.
leo_sobral@2
     9
 *
leo_sobral@2
    10
 * This library is distributed in the hope that it will be useful,
leo_sobral@2
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
leo_sobral@2
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
leo_sobral@2
    13
 * Library General Public License for more 
leo_sobral@2
    14
 */
leo_sobral@2
    15
leo_sobral@2
    16
#ifdef HAVE_CONFIG_H
leo_sobral@2
    17
#include "config.h"
leo_sobral@2
    18
#endif
leo_sobral@2
    19
leo_sobral@2
    20
#include "gstmythtvsrc.h"
rosfran@52
    21
#include <gmyth/gmyth_file_transfer.h>
rosfran@52
    22
#include <gmyth/gmyth_livetv.h>
leo_sobral@2
    23
leo_sobral@2
    24
#include <gmyth/gmyth_socket.h>
leo_sobral@2
    25
#include <gmyth/gmyth_tvchain.h>
leo_sobral@2
    26
leo_sobral@2
    27
#include <string.h>
leo_sobral@2
    28
#include <unistd.h>
leo_sobral@2
    29
leo_sobral@2
    30
GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
leo_sobral@2
    31
#define GST_CAT_DEFAULT mythtvsrc_debug
leo_sobral@2
    32
rosfran@70
    33
#define GST_GMYTHTV_ID_NUM					1
rosfran@70
    34
rosfran@70
    35
#define GST_GMYTHTV_CHANNEL_NUM			1000
leo_sobral@2
    36
rosfran@52
    37
#define GMYTHTV_VERSION_DEFAULT			30
rosfran@61
    38
 
rosfran@40
    39
#define GMYTHTV_TRANSFER_MAX_WAITS	100
leo_sobral@2
    40
rosfran@81
    41
#define GMYTHTV_TRANSFER_MAX_BUFFER	128*1024
rosfran@30
    42
//( 32*1024  )
leo_sobral@2
    43
leo_sobral@2
    44
/* 4*1024 ??? */
rosfran@81
    45
#define MAX_READ_SIZE              	2*1024
rosfran@30
    46
//( 32*1024 )
leo_sobral@2
    47
rosfran@81
    48
#define GST_FLOW_ERROR_NO_DATA  		-101
rosfran@70
    49
leo_sobral@2
    50
/* stablish a maximum iteration value to the IS_RECORDING message */
leo_sobral@2
    51
static guint wait_to_transfer = 0;
leo_sobral@2
    52
leo_sobral@2
    53
static const GstElementDetails gst_mythtv_src_details =
rosfran@30
    54
GST_ELEMENT_DETAILS ( "MythTV client source",
leo_sobral@2
    55
    "Source/Network",
leo_sobral@2
    56
    "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
rosfran@30
    57
    "Rosfran Borges <rosfran.borges@indt.org.br>" );
leo_sobral@2
    58
rosfran@81
    59
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ( "src",
leo_sobral@2
    60
    GST_PAD_SRC,
leo_sobral@2
    61
    GST_PAD_ALWAYS,
rosfran@30
    62
    GST_STATIC_CAPS ("video/x-nuv") );
rosfran@81
    63
    
leo_sobral@2
    64
enum
leo_sobral@2
    65
{
leo_sobral@2
    66
  PROP_0,
leo_sobral@2
    67
  PROP_LOCATION,
leo_sobral@2
    68
  PROP_URI,
leo_sobral@2
    69
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
    70
  PROP_GMYTHTV_DBG,
leo_sobral@2
    71
#endif
rosfran@40
    72
  PROP_GMYTHTV_VERSION,
rosfran@40
    73
  PROP_GMYTHTV_LIVE,
rosfran@40
    74
  PROP_GMYTHTV_LIVEID,
rosfran@52
    75
  PROP_GMYTHTV_LIVE_CHAINID,
rosfran@70
    76
  PROP_GMYTHTV_ENABLE_TIMING_POSITION,
rosfran@70
    77
  PROP_GMYTHTV_CHANNEL_NUM
leo_sobral@2
    78
};
leo_sobral@2
    79
leo_sobral@2
    80
static void gst_mythtv_src_finalize (GObject * gobject);
leo_sobral@2
    81
rosfran@81
    82
/*
rosfran@30
    83
static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, 
rosfran@30
    84
	guint size, GstBuffer ** outbuf);
rosfran@81
    85
*/
rosfran@81
    86
rosfran@81
    87
//static GstFlowReturn gst_mythtv_src_chain ( GstPad* pad, GstBuffer* outbuf );
rosfran@81
    88
static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
rosfran@52
    89
leo_sobral@2
    90
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
leo_sobral@2
    91
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
leo_sobral@2
    92
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
rosfran@81
    93
//static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
rosfran@52
    94
rosfran@52
    95
static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
rosfran@52
    96
rosfran@52
    97
static GstStateChangeReturn
rosfran@52
    98
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
leo_sobral@2
    99
leo_sobral@2
   100
static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
   101
    const GValue * value, GParamSpec * pspec);
leo_sobral@2
   102
static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
   103
    GValue * value, GParamSpec * pspec);
leo_sobral@2
   104
rosfran@30
   105
static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
rosfran@30
   106
rosfran@71
   107
//static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
rosfran@30
   108
//static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
rosfran@30
   109
rosfran@37
   110
static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, 
rosfran@30
   111
		guint size, GstBuffer **outbuf);
leo_sobral@2
   112
rosfran@52
   113
static void
leo_sobral@2
   114
_urihandler_init (GType type)
leo_sobral@2
   115
{
leo_sobral@2
   116
  static const GInterfaceInfo urihandler_info = {
leo_sobral@2
   117
    gst_mythtv_src_uri_handler_init,
leo_sobral@2
   118
    NULL,
leo_sobral@2
   119
    NULL
leo_sobral@2
   120
  };
leo_sobral@2
   121
leo_sobral@2
   122
  g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
leo_sobral@2
   123
leo_sobral@2
   124
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   125
      "MythTV src");
leo_sobral@2
   126
}
leo_sobral@2
   127
rosfran@81
   128
//GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
rosfran@81
   129
//    GST_TYPE_BASE_SRC, _urihandler_init)
rosfran@30
   130
    
rosfran@81
   131
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
rosfran@81
   132
    GST_TYPE_PUSH_SRC, _urihandler_init)
rosfran@30
   133
    
leo_sobral@2
   134
  static void
leo_sobral@2
   135
gst_mythtv_src_base_init (gpointer g_class)
leo_sobral@2
   136
{
leo_sobral@2
   137
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
leo_sobral@2
   138
leo_sobral@2
   139
  gst_element_class_add_pad_template (element_class,
leo_sobral@2
   140
      gst_static_pad_template_get (&srctemplate));
rosfran@81
   141
      
leo_sobral@2
   142
  gst_element_class_set_details (element_class, &gst_mythtv_src_details);
rosfran@52
   143
  
rosfran@52
   144
  element_class->change_state = gst_mythtv_src_change_state;
rosfran@81
   145
  
leo_sobral@2
   146
}
leo_sobral@2
   147
rosfran@30
   148
static void
leo_sobral@2
   149
gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
leo_sobral@2
   150
{
rosfran@63
   151
  GObjectClass *gobject_class; 
rosfran@81
   152
  GstPushSrcClass *gstpushsrc_class;
leo_sobral@2
   153
  GstBaseSrcClass *gstbasesrc_class;
leo_sobral@2
   154
leo_sobral@2
   155
  gobject_class = (GObjectClass *) klass;
leo_sobral@2
   156
  gstbasesrc_class = (GstBaseSrcClass *) klass;
rosfran@81
   157
  gstpushsrc_class = (GstPushSrcClass *) klass;
leo_sobral@2
   158
leo_sobral@2
   159
  gobject_class->set_property = gst_mythtv_src_set_property;
leo_sobral@2
   160
  gobject_class->get_property = gst_mythtv_src_get_property;
leo_sobral@2
   161
  gobject_class->finalize = gst_mythtv_src_finalize;
leo_sobral@2
   162
leo_sobral@2
   163
  g_object_class_install_property
leo_sobral@2
   164
    (gobject_class, PROP_LOCATION,
leo_sobral@2
   165
     g_param_spec_string ("location", "Location",
leo_sobral@2
   166
       "The location. In the form:"
leo_sobral@2
   167
       "\n\t\t\tmyth://a.com/file.nuv"
leo_sobral@2
   168
       "\n\t\t\tmyth://a.com:23223/file.nuv "
leo_sobral@2
   169
       "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
leo_sobral@2
   170
       "", G_PARAM_READWRITE));
leo_sobral@2
   171
leo_sobral@2
   172
  g_object_class_install_property
leo_sobral@2
   173
    (gobject_class, PROP_URI,
leo_sobral@2
   174
     g_param_spec_string ("uri", "Uri",
leo_sobral@2
   175
       "The location in form of a URI (deprecated; use location)",
leo_sobral@2
   176
       "", G_PARAM_READWRITE));
leo_sobral@2
   177
leo_sobral@2
   178
  g_object_class_install_property
rosfran@40
   179
    (gobject_class, PROP_GMYTHTV_VERSION,
leo_sobral@2
   180
     g_param_spec_int ("mythtv-version", "mythtv-version",
rosfran@70
   181
       "Change MythTV version",
leo_sobral@2
   182
       26, 30, 26, G_PARAM_READWRITE));
leo_sobral@2
   183
leo_sobral@2
   184
  g_object_class_install_property
rosfran@40
   185
    (gobject_class, PROP_GMYTHTV_LIVEID,
leo_sobral@2
   186
     g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
rosfran@70
   187
       "Change MythTV version",
rosfran@40
   188
       0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
leo_sobral@2
   189
leo_sobral@2
   190
  g_object_class_install_property
rosfran@40
   191
    (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
leo_sobral@2
   192
     g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
rosfran@70
   193
       "Sets the MythTV chain ID (from TV Chain)",
leo_sobral@2
   194
       "", G_PARAM_READWRITE));
leo_sobral@2
   195
leo_sobral@2
   196
  g_object_class_install_property
rosfran@40
   197
    (gobject_class, PROP_GMYTHTV_LIVE,
leo_sobral@2
   198
     g_param_spec_boolean ("mythtv-live", "mythtv-live",
leo_sobral@2
   199
       "Enable MythTV Live TV content streaming",
leo_sobral@2
   200
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   201
rosfran@52
   202
  g_object_class_install_property
rosfran@52
   203
    (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
rosfran@52
   204
     g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
rosfran@52
   205
       "Enable MythTV Live TV content size continuous updating",
rosfran@52
   206
       FALSE, G_PARAM_READWRITE));
rosfran@70
   207
       
rosfran@70
   208
  g_object_class_install_property
rosfran@70
   209
    (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
rosfran@70
   210
     g_param_spec_int ("mythtv-channel", "mythtv-channel",
rosfran@70
   211
       "Change MythTV channel number",
rosfran@71
   212
       0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
rosfran@52
   213
leo_sobral@2
   214
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   215
  g_object_class_install_property
rosfran@40
   216
    (gobject_class, PROP_GMYTHTV_DBG,
leo_sobral@2
   217
     g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
leo_sobral@2
   218
       "Enable MythTV debug messages",
leo_sobral@2
   219
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   220
#endif
leo_sobral@2
   221
leo_sobral@2
   222
  gstbasesrc_class->start = gst_mythtv_src_start;
leo_sobral@2
   223
  gstbasesrc_class->stop = gst_mythtv_src_stop;
leo_sobral@2
   224
  gstbasesrc_class->get_size = gst_mythtv_src_get_size;
rosfran@81
   225
  //gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
rosfran@81
   226
  
rosfran@81
   227
  //gstbasesrc_class->create = gst_mythtv_src_create;
rosfran@81
   228
  gstpushsrc_class->create = gst_mythtv_src_create;
rosfran@52
   229
    
leo_sobral@2
   230
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   231
      "MythTV Client Source");
leo_sobral@2
   232
}
leo_sobral@2
   233
rosfran@30
   234
static void
leo_sobral@2
   235
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
leo_sobral@2
   236
{
leo_sobral@2
   237
  this->file_transfer = NULL;
leo_sobral@2
   238
leo_sobral@2
   239
  this->unique_setup = FALSE;
leo_sobral@2
   240
rosfran@40
   241
  this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
rosfran@70
   242
  
rosfran@70
   243
  this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
leo_sobral@2
   244
leo_sobral@2
   245
  this->bytes_read = 0;
rosfran@63
   246
  
rosfran@63
   247
  this->prev_content_size = 0;
leo_sobral@2
   248
rosfran@52
   249
  this->content_size = 0;
leo_sobral@2
   250
  this->read_offset = 0;
leo_sobral@2
   251
rosfran@61
   252
  this->content_size_last = 0;
rosfran@61
   253
leo_sobral@2
   254
  this->live_tv = FALSE;
rosfran@52
   255
  
rosfran@52
   256
  this->enable_timing_position = FALSE;
rosfran@52
   257
  this->update_prog_chain = FALSE;    
leo_sobral@2
   258
leo_sobral@2
   259
  this->user_agent = g_strdup ("mythtvsrc");
rosfran@52
   260
  this->mythtv_caps = NULL;
rosfran@52
   261
  this->update_prog_chain = FALSE;
rosfran@52
   262
  
rosfran@70
   263
  this->channel_num = 0;
rosfran@70
   264
  
rosfran@52
   265
  this->eos = FALSE;
rosfran@30
   266
  
rosfran@70
   267
  this->adapter = NULL;
rosfran@70
   268
  
rosfran@81
   269
  //this->th_read_ahead = NULL;
rosfran@70
   270
  
rosfran@81
   271
  this->th_mutex = NULL;
rosfran@81
   272
  
rosfran@70
   273
  this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
rosfran@81
   274
  //gst_pad_set_chain_function ( GST_BASE_SRC_PAD( GST_BASE_SRC( this ) ), 
rosfran@81
   275
  //		GST_DEBUG_FUNCPTR ( gst_mythtv_src_chain ) );
rosfran@70
   276
  gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
rosfran@70
   277
  
rosfran@81
   278
  //gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );  
leo_sobral@2
   279
rosfran@59
   280
  gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
rosfran@81
   281
  
rosfran@71
   282
 // gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
rosfran@71
   283
  //    gst_mythtv_src_handle_event );
rosfran@30
   284
leo_sobral@2
   285
}
leo_sobral@2
   286
rosfran@30
   287
static void
leo_sobral@2
   288
gst_mythtv_src_finalize (GObject * gobject)
leo_sobral@2
   289
{
leo_sobral@2
   290
  GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
rosfran@81
   291
  
rosfran@81
   292
  if ( this->th_mutex != NULL ) {
rosfran@81
   293
  	g_static_rec_mutex_free( this->th_mutex );
rosfran@81
   294
  	this->th_mutex = NULL;
rosfran@81
   295
  }
rosfran@81
   296
rosfran@81
   297
  if ( this->th_read_ahead != NULL ) {
rosfran@81
   298
  	gst_task_stop( this->th_read_ahead );
rosfran@81
   299
  	this->th_read_ahead = NULL;
rosfran@81
   300
  }
leo_sobral@2
   301
leo_sobral@2
   302
  if (this->mythtv_caps) {
leo_sobral@2
   303
    gst_caps_unref (this->mythtv_caps);
leo_sobral@2
   304
    this->mythtv_caps = NULL;
leo_sobral@2
   305
  }
leo_sobral@2
   306
leo_sobral@2
   307
  if (this->file_transfer) {
leo_sobral@2
   308
    g_object_unref (this->file_transfer);
leo_sobral@2
   309
    this->file_transfer = NULL;
leo_sobral@2
   310
  }
leo_sobral@2
   311
rosfran@52
   312
	if (this->spawn_livetv) {
rosfran@70
   313
    g_object_unref (this->spawn_livetv);
rosfran@52
   314
    this->spawn_livetv = NULL;
rosfran@52
   315
  }
rosfran@52
   316
leo_sobral@2
   317
  if (this->uri_name) {
leo_sobral@2
   318
    g_free (this->uri_name);
leo_sobral@2
   319
  }
leo_sobral@2
   320
leo_sobral@2
   321
  if (this->user_agent) {
leo_sobral@2
   322
    g_free (this->user_agent);
leo_sobral@2
   323
  }
leo_sobral@2
   324
leo_sobral@2
   325
  G_OBJECT_CLASS (parent_class)->finalize (gobject);
leo_sobral@2
   326
}
leo_sobral@2
   327
rosfran@37
   328
static gint
rosfran@30
   329
do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
leo_sobral@2
   330
{
rosfran@37
   331
  gint read = 0;
rosfran@52
   332
  guint sizetoread = size;
leo_sobral@2
   333
rosfran@30
   334
  g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
leo_sobral@2
   335
rosfran@30
   336
  /* Loop sending the Myth File Transfer request:
leo_sobral@2
   337
   * Retry whilst authentication fails and we supply it. */
rosfran@37
   338
  gint len = 0;
rosfran@81
   339
  gint8 *data_ptr = g_malloc0( size );
rosfran@70
   340
  
rosfran@81
   341
  //GST_OBJECT_LOCK(src);
leo_sobral@2
   342
leo_sobral@2
   343
  while ( sizetoread > 0 ) {
rosfran@61
   344
rosfran@61
   345
    len = gmyth_file_transfer_read( src->file_transfer,
rosfran@81
   346
						data_ptr + read, sizetoread, TRUE );
leo_sobral@2
   347
leo_sobral@2
   348
    if ( len > 0 ) {
rosfran@81
   349
      read += len;
leo_sobral@2
   350
      sizetoread -= len;
rosfran@52
   351
    } 
rosfran@81
   352
    else if ( len <= 0 )
rosfran@52
   353
    {
rosfran@70
   354
    	read = -1;
rosfran@61
   355
rosfran@52
   356
      if ( src->live_tv == FALSE ) 
rosfran@52
   357
      {
rosfran@70
   358
				goto eos;
rosfran@52
   359
      } 
rosfran@52
   360
      else  
rosfran@52
   361
      {
rosfran@70
   362
				if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
rosfran@70
   363
				  src->update_prog_chain = TRUE;
rosfran@71
   364
					goto done;	  	
rosfran@70
   365
				} else 
rosfran@70
   366
				  if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
rosfran@70
   367
				    src->update_prog_chain = TRUE;
rosfran@70
   368
				    if ( src->enable_timing_position ) {
rosfran@70
   369
				      gint64 size_tmp = 0;
rosfran@70
   370
			get_file_pos:
rosfran@70
   371
					size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@70
   372
					if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@70
   373
					  src->content_size = size_tmp;
rosfran@70
   374
					else if ( size_tmp > 0 )
rosfran@70
   375
					  goto get_file_pos;
rosfran@70
   376
					g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@70
   377
					    __FUNCTION__, size_tmp );
rosfran@81
   378
				    } /*else {				      
rosfran@70
   379
				      gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@70
   380
				      if ( new_offset > 0 && src->content_size <= new_offset ) {
rosfran@70
   381
								  src->content_size = new_offset;
rosfran@70
   382
				      } else {
rosfran@70
   383
								src->update_prog_chain = TRUE;
rosfran@70
   384
				      }
rosfran@81
   385
				      src->prev_content_size = src->content_size;
rosfran@81
   386
				    }*/
rosfran@70
   387
				  }
rosfran@70
   388
			goto done;
rosfran@70
   389
    }
rosfran@30
   390
rosfran@61
   391
    }
rosfran@61
   392
rosfran@30
   393
    if ( read == sizetoread )
leo_sobral@2
   394
      break;
leo_sobral@2
   395
  }
rosfran@61
   396
leo_sobral@2
   397
  if ( read > 0 ) {
rosfran@61
   398
    src->read_offset += read;
leo_sobral@2
   399
    src->bytes_read += read;
rosfran@61
   400
rosfran@61
   401
    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
rosfran@81
   402
			"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
rosfran@81
   403
			src->read_offset, src->content_size );
rosfran@61
   404
rosfran@61
   405
    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
rosfran@81
   406
    GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
rosfran@81
   407
    GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
rosfran@81
   408
    g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
rosfran@61
   409
    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
rosfran@61
   410
    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
rosfran@61
   411
rosfran@61
   412
    g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
rosfran@81
   413
			"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
rosfran@81
   414
			GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
rosfran@61
   415
rosfran@34
   416
  } else if ( !src->live_tv )
rosfran@61
   417
    goto eos;
rosfran@61
   418
rosfran@30
   419
  goto done;
leo_sobral@2
   420
leo_sobral@2
   421
eos:
leo_sobral@2
   422
  src->eos = TRUE;
rosfran@61
   423
leo_sobral@2
   424
done:
rosfran@81
   425
  //GST_OBJECT_UNLOCK(src);
leo_sobral@2
   426
leo_sobral@2
   427
  return read;
leo_sobral@2
   428
}
leo_sobral@2
   429
rosfran@81
   430
#if 0
rosfran@30
   431
static GstFlowReturn
rosfran@30
   432
gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
leo_sobral@2
   433
{
leo_sobral@2
   434
  GstMythtvSrc *src;
leo_sobral@2
   435
  GstFlowReturn ret = GST_FLOW_OK;
rosfran@37
   436
  gint read = -1;
rosfran@81
   437
  gint adapter_size = -1;
rosfran@81
   438
  
rosfran@81
   439
  guint max_adapter_rep = 40;
rosfran@30
   440
  
rosfran@30
   441
  src = GST_MYTHTV_SRC (psrc);
rosfran@81
   442
  
rosfran@31
   443
  /* The caller should know the number of bytes and not read beyond EOS. */
rosfran@31
   444
  if (G_UNLIKELY (src->eos))
rosfran@31
   445
    goto eos;
rosfran@40
   446
  if ( G_UNLIKELY (src->update_prog_chain) )
rosfran@40
   447
    goto change_progchain;
rosfran@81
   448
rosfran@81
   449
  g_static_rec_mutex_lock( src->th_mutex );
rosfran@30
   450
  
rosfran@81
   451
  while ( ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < size ) &&
rosfran@81
   452
  		--max_adapter_rep > 0 )
rosfran@81
   453
  {
rosfran@81
   454
  	g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
rosfran@81
   455
  	GST_TASK_WAIT( src->th_read_ahead );
rosfran@81
   456
  }
rosfran@81
   457
  	
rosfran@81
   458
  g_static_rec_mutex_unlock( src->th_mutex );
leo_sobral@2
   459
rosfran@81
   460
	gint64 new_offset = -1;
rosfran@81
   461
	/* just get from the adapter, no network effort... */
rosfran@81
   462
	if ( offset > src->adapter_offset && size <= adapter_size )	
rosfran@81
   463
	{
rosfran@81
   464
		
rosfran@81
   465
		GstBuffer *buf = gst_adapter_take_buffer( src->adapter, size );
rosfran@81
   466
		*outbuf = gst_buffer_create_sub( buf, offset, size );
rosfran@81
   467
		src->read_offset = new_offset = offset;
rosfran@81
   468
		read = size;
rosfran@81
   469
		
rosfran@81
   470
		gst_adapter_flush( src->adapter, size );
rosfran@81
   471
		
rosfran@81
   472
	} else {
rosfran@81
   473
		/* no data on adapter... do all these mythtv network calls! */
rosfran@81
   474
		
rosfran@81
   475
		/* verify if it needs to seek */
rosfran@81
   476
		if ( src->read_offset != offset ) 
rosfran@81
   477
  	{
rosfran@81
   478
		
rosfran@81
   479
	  	new_offset = gmyth_file_transfer_seek( src->file_transfer, offset, SEEK_SET );
rosfran@81
   480
	  	
rosfran@81
   481
	    g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
rosfran@81
   482
	    	__FUNCTION__, src->read_offset, new_offset );
rosfran@81
   483
	    if ( G_UNLIKELY (new_offset < 0 ) )
rosfran@81
   484
	    {
rosfran@81
   485
	      if ( src->live_tv )
rosfran@81
   486
	      	goto change_progchain;
rosfran@81
   487
	      else
rosfran@81
   488
	      	goto eos;
rosfran@81
   489
	    }
rosfran@81
   490
	    
rosfran@81
   491
  	}
rosfran@81
   492
	
rosfran@30
   493
    src->read_offset = offset;
rosfran@81
   494
  	
rosfran@81
   495
	  /* Create the buffer. */
rosfran@81
   496
	  ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
rosfran@81
   497
	      src->read_offset, size,
rosfran@81
   498
	      GST_PAD_CAPS ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)) ), outbuf);
rosfran@81
   499
	
rosfran@81
   500
	  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
rosfran@81
   501
	    if ( src->live_tv )
rosfran@81
   502
	    	goto change_progchain;
rosfran@81
   503
	    else
rosfran@81
   504
	    	goto done;
rosfran@81
   505
	  }
rosfran@81
   506
	  
rosfran@81
   507
	  read = do_read_request_response ( src, src->read_offset, size, outbuf ); 
rosfran@81
   508
  	
rosfran@81
   509
	}
leo_sobral@2
   510
rosfran@40
   511
  if (G_UNLIKELY (src->update_prog_chain) )
rosfran@40
   512
    goto change_progchain;
rosfran@40
   513
rosfran@52
   514
  if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
rosfran@52
   515
  	if ( src->live_tv )
rosfran@52
   516
    	goto change_progchain;
rosfran@52
   517
    else
rosfran@52
   518
    	goto read_error;
rosfran@31
   519
  }
rosfran@81
   520
  
rosfran@81
   521
  if ( read > 0 ) {
rosfran@81
   522
    src->read_offset += read;
rosfran@81
   523
    src->bytes_read += read;
rosfran@81
   524
    
rosfran@81
   525
    #if 0
rosfran@81
   526
    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
rosfran@81
   527
			"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
rosfran@81
   528
			src->read_offset, src->content_size );
rosfran@81
   529
rosfran@81
   530
    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
rosfran@81
   531
    //GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
rosfran@81
   532
    //GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
rosfran@81
   533
    //g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
rosfran@81
   534
    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
rosfran@81
   535
    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
rosfran@81
   536
rosfran@81
   537
    g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
rosfran@81
   538
			"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
rosfran@81
   539
			GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
rosfran@81
   540
		#endif
rosfran@81
   541
			
rosfran@81
   542
  }
leo_sobral@2
   543
leo_sobral@2
   544
done:
rosfran@31
   545
 {
rosfran@31
   546
    const gchar *reason = gst_flow_get_name (ret);
rosfran@31
   547
rosfran@31
   548
    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
rosfran@31
   549
  	return ret;
rosfran@31
   550
 }
leo_sobral@2
   551
eos:
leo_sobral@2
   552
  {
rosfran@30
   553
    const gchar *reason = gst_flow_get_name (ret);
rosfran@30
   554
rosfran@30
   555
    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
leo_sobral@2
   556
    return GST_FLOW_UNEXPECTED;
leo_sobral@2
   557
  }
leo_sobral@2
   558
  /* ERRORS */
leo_sobral@2
   559
read_error:
leo_sobral@2
   560
  {
leo_sobral@2
   561
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
leo_sobral@2
   562
	(NULL), ("Could not read any bytes (%i, %s)", read,
leo_sobral@2
   563
	  src->uri_name));
leo_sobral@2
   564
    return GST_FLOW_ERROR;
leo_sobral@2
   565
  }
rosfran@40
   566
change_progchain:
rosfran@37
   567
  {
rosfran@37
   568
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@52
   569
		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
rosfran@52
   570
		  src->uri_name));
rosfran@81
   571
		  
rosfran@81
   572
		gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
rosfran@81
   573
  			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
rosfran@52
   574
		// go to the next program chain
rosfran@52
   575
		src->unique_setup = FALSE;
rosfran@52
   576
		src->update_prog_chain = TRUE;
rosfran@70
   577
		
rosfran@70
   578
		gst_mythtv_src_next_program_chain( src );
rosfran@81
   579
		
rosfran@81
   580
    return GST_FLOW_ERROR_NO_DATA;
rosfran@81
   581
  }
rosfran@81
   582
rosfran@81
   583
}
rosfran@81
   584
#endif
rosfran@81
   585
rosfran@81
   586
static GstFlowReturn
rosfran@81
   587
gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
rosfran@81
   588
{
rosfran@81
   589
  GstMythtvSrc *src;
rosfran@81
   590
  GstFlowReturn ret = GST_FLOW_OK;
rosfran@81
   591
  gint read = -1;
rosfran@81
   592
  
rosfran@81
   593
  src = GST_MYTHTV_SRC ( psrc );
rosfran@81
   594
  
rosfran@81
   595
  /* The caller should know the number of bytes and not read beyond EOS. */
rosfran@81
   596
  if (G_UNLIKELY (src->eos))
rosfran@81
   597
    goto eos;
rosfran@81
   598
  if ( G_UNLIKELY (src->update_prog_chain) )
rosfran@81
   599
    goto change_progchain;
rosfran@81
   600
rosfran@81
   601
	//gint64 new_offset = -1;
rosfran@81
   602
	/* just get from the adapter, no network effort... */
rosfran@81
   603
	//do	
rosfran@81
   604
	//{		
rosfran@81
   605
	/* Create the buffer. */
rosfran@81
   606
  ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
rosfran@81
   607
      GST_BUFFER_OFFSET_NONE, MAX_READ_SIZE,
rosfran@81
   608
      GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
rosfran@81
   609
rosfran@81
   610
  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
rosfran@81
   611
    if ( src->live_tv )
rosfran@81
   612
    	goto change_progchain;
rosfran@81
   613
    else
rosfran@81
   614
    	goto done;
rosfran@81
   615
  }
rosfran@81
   616
  
rosfran@81
   617
  read = do_read_request_response ( src, src->read_offset, MAX_READ_SIZE, outbuf );	  
rosfran@81
   618
  
rosfran@81
   619
  if (G_UNLIKELY (src->update_prog_chain) )
rosfran@81
   620
    goto change_progchain;
rosfran@81
   621
rosfran@81
   622
  if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
rosfran@81
   623
  	if ( src->live_tv )
rosfran@81
   624
    	goto change_progchain;
rosfran@81
   625
    else
rosfran@81
   626
    	goto read_error;
rosfran@81
   627
  }
rosfran@81
   628
	  							
rosfran@81
   629
	//} while ( TRUE );
rosfran@81
   630
rosfran@81
   631
done:
rosfran@81
   632
 {
rosfran@81
   633
    const gchar *reason = gst_flow_get_name (ret);
rosfran@81
   634
rosfran@81
   635
    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
rosfran@81
   636
  	return ret;
rosfran@81
   637
 }
rosfran@81
   638
eos:
rosfran@81
   639
  {
rosfran@81
   640
    const gchar *reason = gst_flow_get_name (ret);
rosfran@81
   641
rosfran@81
   642
    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
rosfran@81
   643
    return GST_FLOW_UNEXPECTED;
rosfran@81
   644
  }
rosfran@81
   645
  /* ERRORS */
rosfran@81
   646
read_error:
rosfran@81
   647
  {
rosfran@81
   648
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@81
   649
	(NULL), ("Could not read any bytes (%i, %s)", read,
rosfran@81
   650
	  src->uri_name));
rosfran@81
   651
    return GST_FLOW_ERROR;
rosfran@81
   652
  }
rosfran@81
   653
change_progchain:
rosfran@81
   654
  {
rosfran@81
   655
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@81
   656
		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
rosfran@81
   657
		  src->uri_name));
rosfran@81
   658
		  
rosfran@81
   659
		gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
rosfran@81
   660
  			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
rosfran@81
   661
		// go to the next program chain
rosfran@81
   662
		src->unique_setup = FALSE;
rosfran@81
   663
		src->update_prog_chain = TRUE;
rosfran@81
   664
		
rosfran@81
   665
		gst_mythtv_src_next_program_chain( src );
rosfran@70
   666
		
rosfran@70
   667
    return GST_FLOW_ERROR_NO_DATA;
rosfran@37
   668
  }
rosfran@30
   669
leo_sobral@2
   670
}
leo_sobral@2
   671
rosfran@52
   672
gint64
rosfran@30
   673
gst_mythtv_src_get_position ( GstMythtvSrc* src ) 
leo_sobral@2
   674
{
rosfran@30
   675
rosfran@52
   676
  gint64 size_tmp = 0;
rosfran@71
   677
  guint max_tries = 2;
rosfran@71
   678
  if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) < 
rosfran@71
   679
		GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
rosfran@71
   680
rosfran@30
   681
get_file_pos:
rosfran@61
   682
    g_usleep( 10 );
rosfran@52
   683
    size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@52
   684
    if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
   685
      src->content_size = size_tmp;
rosfran@61
   686
    else if ( size_tmp > 0 && --max_tries > 0 )
rosfran@61
   687
      goto get_file_pos;
rosfran@52
   688
    g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
   689
	__FUNCTION__, size_tmp );
rosfran@71
   690
    /* sets the last content size amount before it can be updated */
rosfran@71
   691
    src->prev_content_size = src->content_size;
rosfran@30
   692
  }
rosfran@52
   693
rosfran@30
   694
  return src->content_size;	
rosfran@30
   695
leo_sobral@2
   696
}
leo_sobral@2
   697
rosfran@81
   698
#if 0
rosfran@81
   699
static void 
rosfran@81
   700
gst_mythtv_src_read_ahead ( void *data ) {
rosfran@81
   701
	
rosfran@81
   702
	GstMythtvSrc *src = NULL;
rosfran@81
   703
	
rosfran@81
   704
	GstBuffer *buffer = NULL;
rosfran@81
   705
	
rosfran@81
   706
	guint size = 512;
rosfran@81
   707
	
rosfran@81
   708
	gint read = 0;
rosfran@81
   709
	
rosfran@81
   710
	src = GST_MYTHTV_SRC( data );
rosfran@81
   711
	
rosfran@81
   712
	GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
rosfran@81
   713
	
rosfran@81
   714
	/*if ( gst_adapter_available( src->adapter ) ) && ( read < MAX_READ_SIZE )) */
rosfran@81
   715
	do {
rosfran@81
   716
		buffer = gst_buffer_new_and_alloc( size );
rosfran@81
   717
rosfran@81
   718
		read += do_read_request_response ( src, src->adapter_offset, size, &buffer );
rosfran@81
   719
		
rosfran@81
   720
		gst_adapter_push( src->adapter, buffer );
rosfran@81
   721
		
rosfran@81
   722
		//gst_buffer_unref( buffer );		
rosfran@81
   723
	} while ( read < MAX_READ_SIZE );
rosfran@81
   724
	
rosfran@81
   725
	GST_PAD_BLOCK_SIGNAL( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
rosfran@81
   726
	
rosfran@81
   727
	GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
rosfran@81
   728
	
rosfran@81
   729
	gst_object_unref( src );
rosfran@81
   730
	
rosfran@81
   731
	return;	
rosfran@81
   732
}
rosfran@81
   733
#endif
rosfran@81
   734
leo_sobral@2
   735
/* create a socket for connecting to remote server */
rosfran@30
   736
static gboolean
leo_sobral@2
   737
gst_mythtv_src_start ( GstBaseSrc * bsrc )
leo_sobral@2
   738
{
leo_sobral@2
   739
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   740
leo_sobral@2
   741
  GString *chain_id_local = NULL;
leo_sobral@2
   742
leo_sobral@2
   743
  gboolean ret = TRUE;
rosfran@52
   744
  
rosfran@71
   745
  if ( G_UNLIKELY (src->update_prog_chain) )
rosfran@71
   746
    goto change_progchain;
rosfran@30
   747
leo_sobral@2
   748
  if (src->unique_setup == FALSE) {
leo_sobral@2
   749
    src->unique_setup = TRUE;
leo_sobral@2
   750
  } else {
leo_sobral@2
   751
    goto done;
leo_sobral@2
   752
  }
leo_sobral@2
   753
rosfran@81
   754
  //GST_OBJECT_LOCK(src);
leo_sobral@2
   755
leo_sobral@2
   756
  if ( src->live_tv ) {
rosfran@40
   757
    src->spawn_livetv = gmyth_livetv_new( );
rosfran@40
   758
    if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
rosfran@30
   759
      ret = FALSE;
rosfran@81
   760
      //GST_OBJECT_UNLOCK( src );
rosfran@30
   761
      goto init_failed;
rosfran@70
   762
    }    
rosfran@52
   763
leo_sobral@2
   764
    /* set up the uri variable */
leo_sobral@2
   765
    src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
leo_sobral@2
   766
    chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
leo_sobral@2
   767
    if ( chain_id_local != NULL ) {
leo_sobral@2
   768
      src->live_chain_id = g_strdup( chain_id_local->str );
leo_sobral@2
   769
      g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
leo_sobral@2
   770
    }
rosfran@70
   771
    src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
rosfran@70
   772
    g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name ); 
leo_sobral@2
   773
  }
leo_sobral@2
   774
rosfran@40
   775
  src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
leo_sobral@2
   776
      g_string_new( src->uri_name ), -1, src->mythtv_version );
leo_sobral@2
   777
leo_sobral@2
   778
  if ( src->file_transfer == NULL ) {
rosfran@81
   779
    //GST_OBJECT_UNLOCK(src);
leo_sobral@2
   780
leo_sobral@2
   781
    goto init_failed;
leo_sobral@2
   782
  }
leo_sobral@2
   783
leo_sobral@2
   784
  /* sets the Playback monitor connection */
rosfran@40
   785
  ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   786
leo_sobral@2
   787
  if ( src->live_tv == TRUE && ret == TRUE ) {
leo_sobral@2
   788
    /* loop finished, set the max tries variable to zero again... */
leo_sobral@2
   789
    wait_to_transfer = 0;
leo_sobral@2
   790
rosfran@70
   791
    while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
rosfran@70
   792
    		( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE 
rosfran@40
   793
	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
leo_sobral@2
   794
      g_usleep( 100 );
leo_sobral@2
   795
  }
leo_sobral@2
   796
leo_sobral@2
   797
  /* sets the FileTransfer instance connection (video/audio download) */
rosfran@40
   798
  ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   799
leo_sobral@2
   800
  if ( ret == FALSE ) {
rosfran@81
   801
    //GST_OBJECT_UNLOCK(src);
leo_sobral@2
   802
#ifndef GST_DISABLE_GST_DEBUG  
leo_sobral@2
   803
    if ( src->mythtv_msgs_dbg )
leo_sobral@2
   804
      g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
leo_sobral@2
   805
#endif
leo_sobral@2
   806
    goto begin_req_failed;
leo_sobral@2
   807
  }
leo_sobral@2
   808
leo_sobral@2
   809
  src->content_size = src->file_transfer->filesize;
leo_sobral@2
   810
rosfran@71
   811
  src->do_start = FALSE;
rosfran@81
   812
  
rosfran@81
   813
  if ( src->live_tv ) {
rosfran@81
   814
  	//src->adapter = gst_adapter_new();
rosfran@81
   815
  	//g_static_rec_mutex_init( src->th_mutex );
rosfran@81
   816
  	//src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
rosfran@81
   817
  }  	
rosfran@71
   818
rosfran@81
   819
  //GST_OBJECT_UNLOCK(src);
rosfran@30
   820
rosfran@30
   821
done:
rosfran@30
   822
  return TRUE;
rosfran@30
   823
rosfran@30
   824
  /* ERRORS */
rosfran@30
   825
init_failed:
rosfran@30
   826
  {
rosfran@30
   827
    if (src->spawn_livetv != NULL )
rosfran@30
   828
      g_object_unref( src->spawn_livetv );
rosfran@30
   829
rosfran@30
   830
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@30
   831
	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
rosfran@30
   832
    return FALSE;
rosfran@30
   833
  }
rosfran@30
   834
begin_req_failed:
rosfran@30
   835
  {
rosfran@30
   836
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@30
   837
	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
rosfran@30
   838
    return FALSE;
rosfran@30
   839
  }
rosfran@71
   840
change_progchain:
rosfran@71
   841
  {
rosfran@71
   842
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@71
   843
		(NULL), ("Seek failed, go to the next program info... (%s)",
rosfran@71
   844
		  src->uri_name));
rosfran@81
   845
		  
rosfran@81
   846
		gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
rosfran@81
   847
  			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
rosfran@81
   848
  			
rosfran@71
   849
		// go to the next program chain
rosfran@71
   850
		src->unique_setup = FALSE;
rosfran@71
   851
		src->update_prog_chain = TRUE;
rosfran@71
   852
		
rosfran@71
   853
		gst_mythtv_src_next_program_chain( src );
rosfran@71
   854
		
rosfran@71
   855
    return TRUE;
rosfran@71
   856
  }
rosfran@30
   857
}
leo_sobral@2
   858
rosfran@52
   859
/* create a new socket for connecting to the next program chain */
rosfran@52
   860
static gboolean
rosfran@52
   861
gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
rosfran@52
   862
{
rosfran@52
   863
  GString *chain_id_local = NULL;
rosfran@52
   864
rosfran@52
   865
  gboolean ret = TRUE;
rosfran@61
   866
rosfran@52
   867
  if ( !src->live_tv )
rosfran@61
   868
    goto init_failed;
rosfran@70
   869
    
rosfran@70
   870
  if (src->unique_setup == FALSE) {
rosfran@70
   871
    src->unique_setup = TRUE;
rosfran@70
   872
  } else {
rosfran@70
   873
    goto done;
rosfran@70
   874
  }
rosfran@81
   875
  
rosfran@81
   876
	GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
rosfran@61
   877
rosfran@52
   878
  if (src->file_transfer) {
rosfran@52
   879
    g_object_unref (src->file_transfer);
rosfran@52
   880
    src->file_transfer = NULL;
rosfran@52
   881
  }
rosfran@61
   882
rosfran@52
   883
  if (src->uri_name) {
rosfran@52
   884
    g_free (src->uri_name);
rosfran@52
   885
  }
rosfran@61
   886
rosfran@52
   887
  if ( src->live_tv ) {
rosfran@61
   888
    if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
rosfran@70
   889
    	g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ );
rosfran@61
   890
      ret = FALSE;
rosfran@61
   891
      goto init_failed;
rosfran@52
   892
    }
rosfran@52
   893
    /* set up the uri variable */
rosfran@52
   894
    src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
rosfran@52
   895
    chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
rosfran@52
   896
    if ( chain_id_local != NULL ) {
rosfran@52
   897
      src->live_chain_id = g_strdup( chain_id_local->str );
rosfran@52
   898
      g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
rosfran@52
   899
    }
rosfran@70
   900
    src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
rosfran@52
   901
    g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
rosfran@52
   902
  }
rosfran@52
   903
rosfran@52
   904
  src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
rosfran@52
   905
      g_string_new( src->uri_name ), -1, src->mythtv_version );
rosfran@52
   906
rosfran@52
   907
  if ( src->file_transfer == NULL ) {
rosfran@52
   908
    goto init_failed;
rosfran@52
   909
  }
rosfran@52
   910
rosfran@52
   911
  /* sets the Playback monitor connection */
rosfran@52
   912
  ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
rosfran@52
   913
rosfran@52
   914
  if ( src->live_tv == TRUE && ret == TRUE ) {
rosfran@52
   915
    /* loop finished, set the max tries variable to zero again... */
rosfran@52
   916
    wait_to_transfer = 0;
rosfran@61
   917
rosfran@61
   918
    g_usleep( 200 );
rosfran@52
   919
rosfran@52
   920
    while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && 
rosfran@70
   921
				( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
rosfran@61
   922
      g_usleep( 1000 );
rosfran@52
   923
  }
rosfran@52
   924
rosfran@52
   925
  /* sets the FileTransfer instance connection (video/audio download) */
rosfran@52
   926
  ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
rosfran@52
   927
rosfran@52
   928
  if ( ret == FALSE ) {
rosfran@52
   929
#ifndef GST_DISABLE_GST_DEBUG  
rosfran@52
   930
    if ( src->mythtv_msgs_dbg )
rosfran@52
   931
      g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
rosfran@52
   932
#endif
rosfran@52
   933
    goto begin_req_failed;
rosfran@52
   934
  }
rosfran@61
   935
  src->content_size_last = src->content_size;
rosfran@61
   936
rosfran@61
   937
#if 0
rosfran@52
   938
  if ( src->content_size < src->file_transfer->filesize ) {
rosfran@61
   939
    src->content_size = src->file_transfer->filesize;
rosfran@52
   940
  } else {
rosfran@61
   941
    //gint64 pos = gst_mythtv_src_get_position(src);
rosfran@61
   942
    //if ( pos > src->file_transfer->filesize )
rosfran@61
   943
    //	src->content_size = pos;  	
rosfran@61
   944
rosfran@52
   945
  }
rosfran@61
   946
#endif
rosfran@61
   947
rosfran@61
   948
  src->content_size = src->file_transfer->filesize;
rosfran@71
   949
  while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 )
rosfran@63
   950
    src->content_size = gst_mythtv_src_get_position( src );
rosfran@63
   951
rosfran@81
   952
  src->read_offset = 0;  
rosfran@70
   953
  
rosfran@70
   954
done:
rosfran@81
   955
	src->update_prog_chain = FALSE;
rosfran@81
   956
	
rosfran@81
   957
	GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
rosfran@81
   958
	
rosfran@52
   959
  return TRUE;
rosfran@52
   960
rosfran@52
   961
  /* ERRORS */
rosfran@52
   962
init_failed:
rosfran@52
   963
  {
rosfran@52
   964
    if (src->spawn_livetv != NULL )
rosfran@52
   965
      g_object_unref( src->spawn_livetv );
rosfran@52
   966
rosfran@52
   967
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@52
   968
	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
rosfran@52
   969
    return FALSE;
rosfran@52
   970
  }
rosfran@52
   971
begin_req_failed:
rosfran@52
   972
  {
rosfran@52
   973
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@52
   974
	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
rosfran@52
   975
    return FALSE;
rosfran@52
   976
  }
rosfran@61
   977
rosfran@52
   978
}
rosfran@52
   979
leo_sobral@2
   980
#if 0
rosfran@30
   981
/* handles queries for location in the stream in the requested format */
rosfran@30
   982
static gboolean
rosfran@30
   983
gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
rosfran@30
   984
{
rosfran@30
   985
  gboolean res = TRUE;
rosfran@30
   986
  GstMythtvSrc *mythtv;
leo_sobral@2
   987
rosfran@30
   988
  guint64 size = 0;
rosfran@30
   989
rosfran@40
   990
  mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
rosfran@30
   991
rosfran@30
   992
  size = gst_mythtv_src_get_position (mythtv);
rosfran@30
   993
rosfran@30
   994
  switch (GST_QUERY_TYPE (query)) {
rosfran@30
   995
rosfran@30
   996
    case GST_QUERY_POSITION:
rosfran@30
   997
      {
rosfran@30
   998
rosfran@30
   999
	//GstFormat format;
rosfran@30
  1000
	gint64 cur = 0;
rosfran@30
  1001
rosfran@30
  1002
	/* save requested format */
rosfran@30
  1003
	gst_query_parse_position (query, NULL, &cur);
rosfran@30
  1004
rosfran@30
  1005
	/* query peer for current position in time */
rosfran@30
  1006
	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
rosfran@30
  1007
	    ( size > cur ) ? "greater" : "lower", size, cur );
rosfran@30
  1008
	gst_query_set_position (query, GST_FORMAT_BYTES, size);
rosfran@30
  1009
	if ( size < cur )
rosfran@30
  1010
	  goto error;
rosfran@30
  1011
rosfran@30
  1012
	break;
leo_sobral@2
  1013
      }
rosfran@30
  1014
     #if 0
rosfran@30
  1015
    case GST_QUERY_DURATION:
rosfran@30
  1016
      {
rosfran@30
  1017
	//GstFormat format;
rosfran@30
  1018
	gint64 cur = 0;
rosfran@30
  1019
rosfran@30
  1020
	/* save requested format */
rosfran@30
  1021
	gst_query_parse_position (query, NULL, &cur);
rosfran@30
  1022
rosfran@30
  1023
	/* query peer for current position in time */
rosfran@30
  1024
	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
rosfran@30
  1025
	    ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND, 
rosfran@30
  1026
	    cur * GST_SECOND );
rosfran@30
  1027
	gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
rosfran@30
  1028
rosfran@30
  1029
	if ( size * GST_SECOND < cur * GST_SECOND )
rosfran@30
  1030
	  goto error;
rosfran@30
  1031
rosfran@30
  1032
	break;
rosfran@30
  1033
      }
rosfran@30
  1034
	#endif
rosfran@30
  1035
    default:
rosfran@30
  1036
      res = FALSE;
rosfran@30
  1037
      break;
rosfran@30
  1038
  }
rosfran@30
  1039
rosfran@30
  1040
  return res;
rosfran@30
  1041
rosfran@30
  1042
error:
rosfran@30
  1043
rosfran@30
  1044
  return FALSE;
rosfran@30
  1045
}
leo_sobral@2
  1046
#endif
leo_sobral@2
  1047
rosfran@30
  1048
static gboolean
leo_sobral@2
  1049
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
leo_sobral@2
  1050
{
rosfran@31
  1051
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
rosfran@30
  1052
  gboolean ret = TRUE;
rosfran@70
  1053
  g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__, 
rosfran@63
  1054
  			abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
leo_sobral@2
  1055
rosfran@30
  1056
  if (src->content_size <= 0) {
rosfran@30
  1057
    ret= FALSE;
rosfran@63
  1058
  } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) < 
rosfran@70
  1059
				GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
rosfran@61
  1060
    //g_static_mutex_lock( &update_size_mutex );
rosfran@61
  1061
    //GST_OBJECT_LOCK(src);
rosfran@70
  1062
    
rosfran@61
  1063
    gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@70
  1064
    if ( new_offset > 0 && new_offset > src->content_size ) {
rosfran@70
  1065
			src->content_size = new_offset;
rosfran@70
  1066
    } else if ( new_offset < src->content_size ) {
rosfran@70
  1067
			src->update_prog_chain = TRUE;
rosfran@70
  1068
	  }
rosfran@61
  1069
rosfran@61
  1070
    if ( src->enable_timing_position ) {
rosfran@61
  1071
      gint64 size_tmp = 0;
rosfran@61
  1072
      if (src->live_tv == TRUE) {
rosfran@61
  1073
get_file_pos:
rosfran@61
  1074
	g_usleep( 5 );
rosfran@61
  1075
	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
  1076
	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
  1077
	  src->content_size = size_tmp;
rosfran@61
  1078
	else if ( size_tmp > 0  )
rosfran@61
  1079
	  goto get_file_pos;
rosfran@61
  1080
	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
  1081
	    __FUNCTION__, size_tmp );
rosfran@61
  1082
      }
rosfran@61
  1083
    }
rosfran@70
  1084
    
rosfran@70
  1085
    src->prev_content_size = src->content_size;
rosfran@70
  1086
    
rosfran@61
  1087
    //GST_OBJECT_UNLOCK(src);
rosfran@61
  1088
    //g_static_mutex_unlock( &update_size_mutex );
leo_sobral@2
  1089
  }
leo_sobral@2
  1090
leo_sobral@2
  1091
  *size = src->content_size;
rosfran@52
  1092
  g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
leo_sobral@2
  1093
rosfran@30
  1094
  return ret;
rosfran@30
  1095
leo_sobral@2
  1096
}
leo_sobral@2
  1097
leo_sobral@2
  1098
/* close the socket and associated resources
leo_sobral@2
  1099
 * used both to recover from errors and go to NULL state */
rosfran@52
  1100
static gboolean
leo_sobral@2
  1101
gst_mythtv_src_stop (GstBaseSrc * bsrc)
leo_sobral@2
  1102
{
leo_sobral@2
  1103
  GstMythtvSrc *src;
leo_sobral@2
  1104
leo_sobral@2
  1105
  src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
  1106
leo_sobral@2
  1107
  if (src->uri_name) {
leo_sobral@2
  1108
    g_free (src->uri_name);
leo_sobral@2
  1109
    src->uri_name = NULL;
leo_sobral@2
  1110
  }
leo_sobral@2
  1111
leo_sobral@2
  1112
  if (src->mythtv_caps) {
leo_sobral@2
  1113
    gst_caps_unref (src->mythtv_caps);
leo_sobral@2
  1114
    src->mythtv_caps = NULL;
leo_sobral@2
  1115
  }
leo_sobral@2
  1116
leo_sobral@2
  1117
  src->eos = FALSE;
leo_sobral@2
  1118
leo_sobral@2
  1119
  return TRUE;
leo_sobral@2
  1120
}
leo_sobral@2
  1121
rosfran@71
  1122
#if 0
rosfran@30
  1123
static gboolean
leo_sobral@2
  1124
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
leo_sobral@2
  1125
{
leo_sobral@2
  1126
  GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
rosfran@52
  1127
  gint64 cont_size = 0;
leo_sobral@2
  1128
leo_sobral@2
  1129
  switch (GST_EVENT_TYPE (event)) {
rosfran@30
  1130
#if 0
leo_sobral@2
  1131
    case GST_EVENT_FLUSH_START:
rosfran@52
  1132
      //src->eos = FALSE;
rosfran@52
  1133
      g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
rosfran@61
  1134
      cont_size = gst_mythtv_src_get_position (src);
rosfran@61
  1135
      if ( !src->live_tv ) {
rosfran@61
  1136
	if ( cont_size > src->content_size ) {
rosfran@61
  1137
	  src->content_size = cont_size;
rosfran@61
  1138
	  src->eos = FALSE;
rosfran@61
  1139
	} else {
rosfran@61
  1140
	  src->eos = TRUE;
rosfran@61
  1141
	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
rosfran@61
  1142
	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
rosfran@61
  1143
	}
rosfran@61
  1144
      } else {
rosfran@61
  1145
	if ( cont_size <= 0 ) {
rosfran@61
  1146
	  src->update_prog_chain = TRUE;
rosfran@61
  1147
	  src->eos = TRUE;
rosfran@61
  1148
	  src->unique_setup = FALSE;
rosfran@61
  1149
	  src->do_start = TRUE;		  				  		
rosfran@61
  1150
	}		  	
rosfran@61
  1151
      }
rosfran@61
  1152
      break;
leo_sobral@2
  1153
    case GST_EVENT_FLUSH_STOP:
leo_sobral@2
  1154
      src->do_start = TRUE;
leo_sobral@2
  1155
      src->eos = FALSE;
leo_sobral@2
  1156
      gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
rosfran@30
  1157
      //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
rosfran@30
  1158
      break;
rosfran@30
  1159
#endif
rosfran@30
  1160
    case GST_EVENT_EOS:
rosfran@30
  1161
      g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
rosfran@61
  1162
rosfran@61
  1163
      if ( src->live_tv ) {
rosfran@61
  1164
	cont_size = gst_mythtv_src_get_position (src);
rosfran@61
  1165
	if ( cont_size > src->content_size ) {
rosfran@61
  1166
	  src->content_size = cont_size;
rosfran@61
  1167
	  src->eos = FALSE;
rosfran@61
  1168
	} else {
rosfran@61
  1169
	  src->eos = TRUE;
rosfran@61
  1170
	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
rosfran@61
  1171
	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
rosfran@61
  1172
	}
rosfran@61
  1173
      } else 
rosfran@61
  1174
	src->eos = TRUE;
rosfran@30
  1175
      break;
rosfran@30
  1176
#if 0
rosfran@30
  1177
    case GST_EVENT_NEWSEGMENT:
rosfran@30
  1178
      g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
rosfran@30
  1179
      src->eos = FALSE;
leo_sobral@2
  1180
      break;
leo_sobral@2
  1181
    case GST_EVENT_SEEK:  	  
leo_sobral@2
  1182
      {
rosfran@30
  1183
	g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
leo_sobral@2
  1184
	gdouble rate;
leo_sobral@2
  1185
	//gboolean update = TRUE;
leo_sobral@2
  1186
	GstFormat format;
leo_sobral@2
  1187
	GstSeekType cur_type, stop_type;
leo_sobral@2
  1188
	GstSeekFlags flags;
leo_sobral@2
  1189
	gint64 cur = 0, stop = 0;
leo_sobral@2
  1190
	gst_event_parse_seek ( event, &rate, &format,
leo_sobral@2
  1191
	    &flags, &cur_type, &cur,
leo_sobral@2
  1192
	    &stop_type, &stop );
leo_sobral@2
  1193
leo_sobral@2
  1194
	g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
leo_sobral@2
  1195
	if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
leo_sobral@2
  1196
	  g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
leo_sobral@2
  1197
	}
leo_sobral@2
  1198
	//gboolean ret = gst_event_parse_new_segment ( event,
leo_sobral@2
  1199
	//    &update, &rate, &format, &start, &stop,
leo_sobral@2
  1200
	//    &position );
leo_sobral@2
  1201
	//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ), 
leo_sobral@2
  1202
	//			cur, stop - cur + 1, GstBuffer)
rosfran@30
  1203
      }
rosfran@30
  1204
#endif
leo_sobral@2
  1205
    default:
leo_sobral@2
  1206
      return gst_pad_event_default (pad, event);
leo_sobral@2
  1207
  }
leo_sobral@2
  1208
leo_sobral@2
  1209
  return gst_pad_event_default (pad, event);
leo_sobral@2
  1210
}
rosfran@71
  1211
#endif
leo_sobral@2
  1212
rosfran@81
  1213
#if 0
rosfran@30
  1214
static gboolean
rosfran@30
  1215
gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
leo_sobral@2
  1216
{
leo_sobral@2
  1217
  return TRUE;
leo_sobral@2
  1218
}
rosfran@81
  1219
#endif
leo_sobral@2
  1220
rosfran@61
  1221
#if 0
rosfran@70
  1222
static GstFlowReturn
rosfran@70
  1223
gst_mythtv_src_file_transfer( GstMythtvSrc *src )
rosfran@61
  1224
{
rosfran@70
  1225
	GstFlowReturn ret = GST_FLOW_OK;
rosfran@70
  1226
  GstBuffer *buf = NULL;
rosfran@70
  1227
  gint read = -1;
rosfran@70
  1228
  
rosfran@70
  1229
  /* The caller should know the number of bytes and not read beyond EOS. */
rosfran@70
  1230
  if ( G_UNLIKELY (src->eos) )
rosfran@70
  1231
    goto eos;
rosfran@70
  1232
  if ( G_UNLIKELY (src->update_prog_chain) )
rosfran@70
  1233
    goto change_progchain;
rosfran@61
  1234
rosfran@70
  1235
  do {
rosfran@70
  1236
  
rosfran@70
  1237
	  /* Create the buffer. */
rosfran@70
  1238
	  buf = gst_buffer_new_and_alloc (4096);
rosfran@70
  1239
	  
rosfran@70
  1240
	  ret = gst_mythtv_src_read_bytes( src, GST_BUFFER_SIZE(buf), TRUE, &buf );	  
rosfran@70
  1241
		if ( ret != GST_FLOW_OK )
rosfran@70
  1242
			return ret;
rosfran@70
  1243
	  
rosfran@70
  1244
	  read = do_read_request_response ( src, src->read_offset, GST_BUFFER_SIZE(buf), &buf );
rosfran@70
  1245
	  
rosfran@70
  1246
	  if (G_UNLIKELY (src->update_prog_chain) )
rosfran@70
  1247
	    goto change_progchain;
rosfran@70
  1248
	
rosfran@70
  1249
	  if (G_UNLIKELY (read <= 0) || buf == NULL) {
rosfran@70
  1250
	  	if ( src->live_tv )
rosfran@70
  1251
	    	goto change_progchain;
rosfran@70
  1252
	    else
rosfran@70
  1253
	    	goto read_error;
rosfran@70
  1254
	  }
rosfran@70
  1255
	  
rosfran@71
  1256
	  if ( GST_FLOW_OK != ( ret = gst_pad_push ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), buf ) ) ) {
rosfran@70
  1257
	    goto done;
rosfran@70
  1258
	  }  
rosfran@70
  1259
  
rosfran@70
  1260
	} while(TRUE);
rosfran@70
  1261
rosfran@70
  1262
done:
rosfran@70
  1263
 {
rosfran@70
  1264
    const gchar *reason = gst_flow_get_name (ret);
rosfran@70
  1265
rosfran@70
  1266
    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
rosfran@70
  1267
  	return ret;
rosfran@70
  1268
 }
rosfran@70
  1269
eos:
rosfran@70
  1270
  {
rosfran@70
  1271
    const gchar *reason = gst_flow_get_name (ret);
rosfran@70
  1272
rosfran@70
  1273
    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
rosfran@70
  1274
    return GST_FLOW_UNEXPECTED;
rosfran@61
  1275
  }
rosfran@70
  1276
  /* ERRORS */
rosfran@70
  1277
read_error:
rosfran@70
  1278
  {
rosfran@70
  1279
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@70
  1280
	(NULL), ("Could not read any bytes (%i, %s)", read,
rosfran@70
  1281
	  src->uri_name));
rosfran@70
  1282
    return GST_FLOW_ERROR;
rosfran@61
  1283
  }
rosfran@70
  1284
change_progchain:
rosfran@70
  1285
  {
rosfran@70
  1286
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@70
  1287
		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
rosfran@70
  1288
		  src->uri_name));
rosfran@70
  1289
		// go to the next program chain
rosfran@70
  1290
		src->unique_setup = FALSE;
rosfran@70
  1291
		src->update_prog_chain = TRUE;
rosfran@70
  1292
		src->mode = GST_MYTHTV_SRC_NEXT_PROGRAM_CHAIN;
rosfran@70
  1293
		
rosfran@70
  1294
		//GST_OBJECT_LOCK(src);
rosfran@70
  1295
		//gst_mythtv_src_next_program_chain( src );
rosfran@70
  1296
		//GST_OBJECT_UNLOCK(src);		  
rosfran@70
  1297
    return GST_FLOW_OK;//GST_FLOW_ERROR_NO_DATA;
rosfran@70
  1298
  }
rosfran@61
  1299
}
rosfran@61
  1300
rosfran@61
  1301
static GstFlowReturn
rosfran@70
  1302
gst_mythtv_src_play (GstPad * pad)
rosfran@61
  1303
{
rosfran@70
  1304
  GstFlowReturn res = GST_FLOW_OK;
rosfran@70
  1305
  GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
rosfran@70
  1306
  
rosfran@70
  1307
	switch ( src->state ) {
rosfran@70
  1308
    case GST_MYTHTV_SRC_FILE_TRANSFER:
rosfran@70
  1309
    	res = gst_mythtv_src_file_transfer( src );
rosfran@70
  1310
			if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
rosfran@70
  1311
      	goto pause;
rosfran@70
  1312
      }
rosfran@70
  1313
      break;
rosfran@70
  1314
    case GST_MYTHTV_SRC_NEXT_PROGRAM_CHAIN:
rosfran@70
  1315
      src->read_offset = 0;
rosfran@70
  1316
			src->bytes_read = 0;
rosfran@70
  1317
			src->unique_setup = FALSE;
rosfran@70
  1318
			if ( !gst_mythtv_src_next_program_chain( src ) ) {
rosfran@70
  1319
        goto pause;
rosfran@70
  1320
      }
rosfran@70
  1321
      src->state = GST_MYTHTV_SRC_FILE_TRANSFER;
rosfran@70
  1322
      break;
rosfran@70
  1323
    case GST_MYTHTV_SRC_INVALID_DATA:
rosfran@70
  1324
      goto pause;
rosfran@70
  1325
      break;
rosfran@70
  1326
    default:
rosfran@70
  1327
      g_assert_not_reached ();
rosfran@70
  1328
  }
rosfran@61
  1329
rosfran@70
  1330
  GST_DEBUG_OBJECT (src, "state: %d res:%s", src->state,
rosfran@70
  1331
      gst_flow_get_name (res));
rosfran@61
  1332
rosfran@70
  1333
  return GST_FLOW_OK;
rosfran@61
  1334
rosfran@70
  1335
pause:
rosfran@70
  1336
  GST_LOG_OBJECT (src, "pausing task, reason %s", gst_flow_get_name (res));
rosfran@70
  1337
  gst_pad_pause_task (src->srcpad);
rosfran@70
  1338
  if (GST_FLOW_IS_FATAL (res)) {
rosfran@70
  1339
    GST_ELEMENT_ERROR (src, STREAM, FAILED,
rosfran@70
  1340
        ("Internal data stream error."),
rosfran@70
  1341
        ("streaming stopped, reason %s", gst_flow_get_name (res)));
rosfran@71
  1342
    gst_pad_send_event( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_eos() );
rosfran@70
  1343
  }
rosfran@70
  1344
  return res;
rosfran@61
  1345
}
rosfran@61
  1346
#endif
rosfran@61
  1347
rosfran@52
  1348
static GstStateChangeReturn
rosfran@52
  1349
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
rosfran@52
  1350
{
rosfran@71
  1351
  GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;//GST_STATE_CHANGE_NO_PREROLL;
rosfran@52
  1352
  GstMythtvSrc *src = GST_MYTHTV_SRC (element);
rosfran@52
  1353
rosfran@52
  1354
  switch (transition) {
rosfran@52
  1355
    case GST_STATE_CHANGE_NULL_TO_READY:
rosfran@52
  1356
      src->do_start = TRUE;
rosfran@70
  1357
      src->unique_setup = FALSE;
rosfran@52
  1358
      break;
rosfran@52
  1359
    case GST_STATE_CHANGE_READY_TO_PAUSED:
rosfran@52
  1360
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
rosfran@52
  1361
      src->eos = FALSE;
rosfran@52
  1362
      break;
rosfran@52
  1363
    default:
rosfran@52
  1364
      break;
rosfran@52
  1365
  }
rosfran@61
  1366
rosfran@61
  1367
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
rosfran@52
  1368
  if (ret == GST_STATE_CHANGE_FAILURE)
rosfran@52
  1369
    return ret;
rosfran@52
  1370
rosfran@52
  1371
  switch (transition) {
rosfran@52
  1372
    case GST_STATE_CHANGE_READY_TO_NULL:
rosfran@63
  1373
      g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
rosfran@52
  1374
      break;
rosfran@61
  1375
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
rosfran@63
  1376
      g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
rosfran@52
  1377
    case GST_STATE_CHANGE_PAUSED_TO_READY:
rosfran@63
  1378
      g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
rosfran@61
  1379
      if ( src->live_tv && src->update_prog_chain ) {
rosfran@81
  1380
      	
rosfran@81
  1381
  			gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
rosfran@81
  1382
      			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
rosfran@81
  1383
rosfran@70
  1384
				src->read_offset = 0;
rosfran@70
  1385
				src->bytes_read = 0;
rosfran@81
  1386
				src->unique_setup = FALSE;				
rosfran@70
  1387
				gst_mythtv_src_next_program_chain( src );
rosfran@61
  1388
      }
rosfran@61
  1389
      break;
rosfran@52
  1390
    default:
rosfran@52
  1391
      break;
rosfran@52
  1392
  }
rosfran@52
  1393
rosfran@52
  1394
  return ret;
rosfran@52
  1395
}
rosfran@52
  1396
rosfran@30
  1397
static void
leo_sobral@2
  1398
gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
  1399
    const GValue * value, GParamSpec * pspec)
leo_sobral@2
  1400
{
leo_sobral@2
  1401
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1402
leo_sobral@2
  1403
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1404
  switch (prop_id) {
leo_sobral@2
  1405
    case PROP_URI:
leo_sobral@2
  1406
    case PROP_LOCATION:
leo_sobral@2
  1407
      {
leo_sobral@2
  1408
	if (!g_value_get_string (value)) {
leo_sobral@2
  1409
	  GST_WARNING ("location property cannot be NULL");
leo_sobral@2
  1410
	  goto done;
leo_sobral@2
  1411
	}
leo_sobral@2
  1412
leo_sobral@2
  1413
	if (mythtvsrc->uri_name != NULL) {
leo_sobral@2
  1414
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
  1415
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
  1416
	}
leo_sobral@2
  1417
	mythtvsrc->uri_name = g_value_dup_string (value);
leo_sobral@2
  1418
leo_sobral@2
  1419
	break;
leo_sobral@2
  1420
      }
leo_sobral@2
  1421
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1422
    case PROP_GMYTHTV_DBG:
leo_sobral@2
  1423
      {
leo_sobral@2
  1424
	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
leo_sobral@2
  1425
	break;
leo_sobral@2
  1426
      }
leo_sobral@2
  1427
#endif
rosfran@40
  1428
    case PROP_GMYTHTV_VERSION:
leo_sobral@2
  1429
      {
leo_sobral@2
  1430
	mythtvsrc->mythtv_version = g_value_get_int (value);
leo_sobral@2
  1431
	break;
leo_sobral@2
  1432
      }
rosfran@40
  1433
    case PROP_GMYTHTV_LIVEID:
leo_sobral@2
  1434
      {
leo_sobral@2
  1435
	mythtvsrc->live_tv_id = g_value_get_int (value);
leo_sobral@2
  1436
	break;
leo_sobral@2
  1437
      }
rosfran@40
  1438
    case PROP_GMYTHTV_LIVE:
leo_sobral@2
  1439
      {
leo_sobral@2
  1440
	mythtvsrc->live_tv = g_value_get_boolean (value);
leo_sobral@2
  1441
	break;
leo_sobral@2
  1442
      }
rosfran@52
  1443
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@52
  1444
      {
rosfran@52
  1445
	mythtvsrc->enable_timing_position = g_value_get_boolean (value);
rosfran@52
  1446
	break;
rosfran@52
  1447
      }      
rosfran@40
  1448
    case PROP_GMYTHTV_LIVE_CHAINID:
leo_sobral@2
  1449
      {
leo_sobral@2
  1450
	if (!g_value_get_string (value)) {
leo_sobral@2
  1451
	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
leo_sobral@2
  1452
	  goto done;
leo_sobral@2
  1453
	}
leo_sobral@2
  1454
leo_sobral@2
  1455
	if (mythtvsrc->live_chain_id != NULL) {
leo_sobral@2
  1456
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
  1457
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
  1458
	}
leo_sobral@2
  1459
	mythtvsrc->live_chain_id = g_value_dup_string (value);
leo_sobral@2
  1460
	break;
leo_sobral@2
  1461
      }
rosfran@70
  1462
    case PROP_GMYTHTV_CHANNEL_NUM:
rosfran@70
  1463
      {
rosfran@70
  1464
	mythtvsrc->channel_num = g_value_get_int (value);
rosfran@70
  1465
	break;
rosfran@70
  1466
      }
leo_sobral@2
  1467
    default:
leo_sobral@2
  1468
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1469
      break;
leo_sobral@2
  1470
  }
leo_sobral@2
  1471
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1472
done:
leo_sobral@2
  1473
  return;
leo_sobral@2
  1474
}
leo_sobral@2
  1475
leo_sobral@2
  1476
  static void
leo_sobral@2
  1477
gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
  1478
    GValue * value, GParamSpec * pspec)
leo_sobral@2
  1479
{
leo_sobral@2
  1480
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1481
leo_sobral@2
  1482
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1483
  switch (prop_id) {
leo_sobral@2
  1484
    case PROP_URI:
leo_sobral@2
  1485
    case PROP_LOCATION:
leo_sobral@2
  1486
      {
leo_sobral@2
  1487
	gchar *str = g_strdup( "" );
leo_sobral@2
  1488
leo_sobral@2
  1489
	if ( mythtvsrc->uri_name == NULL ) {
leo_sobral@2
  1490
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
  1491
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
  1492
	} else {
leo_sobral@2
  1493
	  str = g_strdup( mythtvsrc->uri_name );
leo_sobral@2
  1494
	}
leo_sobral@2
  1495
	g_value_set_string ( value, str );
leo_sobral@2
  1496
	break;
leo_sobral@2
  1497
      }
leo_sobral@2
  1498
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1499
    case PROP_GMYTHTV_DBG:
leo_sobral@2
  1500
      g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
leo_sobral@2
  1501
      break;
leo_sobral@2
  1502
#endif
rosfran@40
  1503
    case PROP_GMYTHTV_VERSION:
leo_sobral@2
  1504
      {
leo_sobral@2
  1505
	g_value_set_int ( value, mythtvsrc->mythtv_version );
leo_sobral@2
  1506
	break;
leo_sobral@2
  1507
      }
rosfran@40
  1508
    case PROP_GMYTHTV_LIVEID:
leo_sobral@2
  1509
      {
leo_sobral@2
  1510
	g_value_set_int ( value, mythtvsrc->live_tv_id );
leo_sobral@2
  1511
	break;
leo_sobral@2
  1512
      }
rosfran@40
  1513
    case PROP_GMYTHTV_LIVE:
leo_sobral@2
  1514
      g_value_set_boolean ( value, mythtvsrc->live_tv );
leo_sobral@2
  1515
      break;
rosfran@52
  1516
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@52
  1517
      g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
rosfran@52
  1518
      break;
rosfran@40
  1519
    case PROP_GMYTHTV_LIVE_CHAINID:
leo_sobral@2
  1520
      {
leo_sobral@2
  1521
	gchar *str = g_strdup( "" );
leo_sobral@2
  1522
leo_sobral@2
  1523
	if ( mythtvsrc->live_chain_id == NULL ) {
leo_sobral@2
  1524
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
  1525
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
  1526
	} else {
leo_sobral@2
  1527
	  str = g_strdup( mythtvsrc->live_chain_id );
leo_sobral@2
  1528
	}
leo_sobral@2
  1529
	g_value_set_string ( value, str );
leo_sobral@2
  1530
	break;
leo_sobral@2
  1531
      }
rosfran@70
  1532
    case PROP_GMYTHTV_CHANNEL_NUM:
rosfran@70
  1533
      {
rosfran@70
  1534
	g_value_set_int ( value, mythtvsrc->channel_num );
rosfran@70
  1535
	break;
rosfran@70
  1536
      }
leo_sobral@2
  1537
    default:
leo_sobral@2
  1538
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1539
      break;
leo_sobral@2
  1540
  }
leo_sobral@2
  1541
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1542
}
leo_sobral@2
  1543
leo_sobral@2
  1544
/* entry point to initialize the plug-in
leo_sobral@2
  1545
 * initialize the plug-in itself
leo_sobral@2
  1546
 * register the element factories and pad templates
leo_sobral@2
  1547
 * register the features
leo_sobral@2
  1548
 */
rosfran@40
  1549
static gboolean
leo_sobral@2
  1550
plugin_init (GstPlugin * plugin)
leo_sobral@2
  1551
{
leo_sobral@2
  1552
  return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
leo_sobral@2
  1553
      GST_TYPE_MYTHTV_SRC);
leo_sobral@2
  1554
}
leo_sobral@2
  1555
leo_sobral@2
  1556
/* this is the structure that gst-register looks for
leo_sobral@2
  1557
 * so keep the name plugin_desc, or you cannot get your plug-in registered */
leo_sobral@2
  1558
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
leo_sobral@2
  1559
    GST_VERSION_MINOR,
leo_sobral@2
  1560
    "mythtv",
leo_sobral@2
  1561
    "lib MythTV src",
leo_sobral@2
  1562
    plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
leo_sobral@2
  1563
leo_sobral@2
  1564
leo_sobral@2
  1565
/*** GSTURIHANDLER INTERFACE *************************************************/
leo_sobral@2
  1566
  static guint 
leo_sobral@2
  1567
gst_mythtv_src_uri_get_type (void)
leo_sobral@2
  1568
{
leo_sobral@2
  1569
  return GST_URI_SRC;
leo_sobral@2
  1570
}
leo_sobral@2
  1571
leo_sobral@2
  1572
  static gchar **
leo_sobral@2
  1573
gst_mythtv_src_uri_get_protocols (void)
leo_sobral@2
  1574
{
leo_sobral@2
  1575
  static gchar *protocols[] = { "myth", "myths", NULL };
leo_sobral@2
  1576
leo_sobral@2
  1577
  return protocols;
leo_sobral@2
  1578
}
leo_sobral@2
  1579
leo_sobral@2
  1580
  static const gchar *
leo_sobral@2
  1581
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
leo_sobral@2
  1582
{
leo_sobral@2
  1583
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1584
leo_sobral@2
  1585
  return src->uri_name;
leo_sobral@2
  1586
}
leo_sobral@2
  1587
leo_sobral@2
  1588
  static gboolean
leo_sobral@2
  1589
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
leo_sobral@2
  1590
{
leo_sobral@2
  1591
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1592
leo_sobral@2
  1593
  gchar *protocol;
leo_sobral@2
  1594
leo_sobral@2
  1595
  protocol = gst_uri_get_protocol (uri);
leo_sobral@2
  1596
  if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
leo_sobral@2
  1597
    g_free (protocol);
leo_sobral@2
  1598
    return FALSE;
leo_sobral@2
  1599
  }
leo_sobral@2
  1600
  g_free (protocol);
leo_sobral@2
  1601
  g_object_set (src, "location", uri, NULL);
leo_sobral@2
  1602
leo_sobral@2
  1603
  return TRUE;
leo_sobral@2
  1604
}
leo_sobral@2
  1605
leo_sobral@2
  1606
  static void
leo_sobral@2
  1607
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
leo_sobral@2
  1608
{
leo_sobral@2
  1609
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
leo_sobral@2
  1610
leo_sobral@2
  1611
  iface->get_type = gst_mythtv_src_uri_get_type;
leo_sobral@2
  1612
  iface->get_protocols = gst_mythtv_src_uri_get_protocols;
leo_sobral@2
  1613
  iface->get_uri = gst_mythtv_src_uri_get_uri;
leo_sobral@2
  1614
  iface->set_uri = gst_mythtv_src_uri_set_uri;
leo_sobral@2
  1615
}
leo_sobral@2
  1616
leo_sobral@2
  1617
  void
leo_sobral@2
  1618
size_header_handler (void *userdata, const char *value)
leo_sobral@2
  1619
{
leo_sobral@2
  1620
  GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
leo_sobral@2
  1621
leo_sobral@2
  1622
  //src->content_size = g_ascii_strtoull (value, NULL, 10);
leo_sobral@2
  1623
leo_sobral@2
  1624
  GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
leo_sobral@2
  1625
}