gst-plugins-mythtv/src/gstmythtvsrc.c
author rosfran
Fri Oct 27 23:32:24 2006 +0100 (2006-10-27)
branchtrunk
changeset 61 dedcca2fe529
parent 59 b2b0169716dc
child 63 957b55b3f630
permissions -rwxr-xr-x
[svn r62] Some fixes.
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@40
    33
#define GST_GMYTHTV_ID_NUM		1
leo_sobral@2
    34
rosfran@52
    35
#define GMYTHTV_VERSION_DEFAULT			30
rosfran@61
    36
 
rosfran@40
    37
#define GMYTHTV_TRANSFER_MAX_WAITS	100
leo_sobral@2
    38
rosfran@58
    39
#define GMYTHTV_TRANSFER_MAX_BUFFER	512*1024
rosfran@30
    40
//( 32*1024  )
leo_sobral@2
    41
leo_sobral@2
    42
/* 4*1024 ??? */
rosfran@30
    43
#define MAX_READ_SIZE              	12*1024
rosfran@30
    44
//( 32*1024 )
leo_sobral@2
    45
leo_sobral@2
    46
/* stablish a maximum iteration value to the IS_RECORDING message */
leo_sobral@2
    47
static guint wait_to_transfer = 0;
leo_sobral@2
    48
leo_sobral@2
    49
static const GstElementDetails gst_mythtv_src_details =
rosfran@30
    50
GST_ELEMENT_DETAILS ( "MythTV client source",
leo_sobral@2
    51
    "Source/Network",
leo_sobral@2
    52
    "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
rosfran@30
    53
    "Rosfran Borges <rosfran.borges@indt.org.br>" );
leo_sobral@2
    54
leo_sobral@2
    55
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
leo_sobral@2
    56
    GST_PAD_SRC,
leo_sobral@2
    57
    GST_PAD_ALWAYS,
rosfran@30
    58
    GST_STATIC_CAPS ("video/x-nuv") );
rosfran@30
    59
rosfran@30
    60
static GStaticMutex update_size_mutex = G_STATIC_MUTEX_INIT;
leo_sobral@2
    61
leo_sobral@2
    62
enum
leo_sobral@2
    63
{
leo_sobral@2
    64
  PROP_0,
leo_sobral@2
    65
  PROP_LOCATION,
leo_sobral@2
    66
  PROP_URI,
leo_sobral@2
    67
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
    68
  PROP_GMYTHTV_DBG,
leo_sobral@2
    69
#endif
rosfran@40
    70
  PROP_GMYTHTV_VERSION,
rosfran@40
    71
  PROP_GMYTHTV_LIVE,
rosfran@40
    72
  PROP_GMYTHTV_LIVEID,
rosfran@52
    73
  PROP_GMYTHTV_LIVE_CHAINID,
rosfran@52
    74
  PROP_GMYTHTV_ENABLE_TIMING_POSITION
leo_sobral@2
    75
};
leo_sobral@2
    76
leo_sobral@2
    77
static void gst_mythtv_src_finalize (GObject * gobject);
leo_sobral@2
    78
rosfran@30
    79
static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, 
rosfran@30
    80
	guint size, GstBuffer ** outbuf);
rosfran@52
    81
leo_sobral@2
    82
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
leo_sobral@2
    83
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
leo_sobral@2
    84
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
rosfran@30
    85
static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
rosfran@52
    86
rosfran@52
    87
static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
rosfran@52
    88
rosfran@52
    89
static GstStateChangeReturn
rosfran@52
    90
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
leo_sobral@2
    91
leo_sobral@2
    92
static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
    93
    const GValue * value, GParamSpec * pspec);
leo_sobral@2
    94
static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
    95
    GValue * value, GParamSpec * pspec);
leo_sobral@2
    96
rosfran@30
    97
static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
rosfran@30
    98
rosfran@31
    99
static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
rosfran@30
   100
//static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
rosfran@30
   101
rosfran@37
   102
static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, 
rosfran@30
   103
		guint size, GstBuffer **outbuf);
rosfran@30
   104
//static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active);
leo_sobral@2
   105
rosfran@52
   106
static void
leo_sobral@2
   107
_urihandler_init (GType type)
leo_sobral@2
   108
{
leo_sobral@2
   109
  static const GInterfaceInfo urihandler_info = {
leo_sobral@2
   110
    gst_mythtv_src_uri_handler_init,
leo_sobral@2
   111
    NULL,
leo_sobral@2
   112
    NULL
leo_sobral@2
   113
  };
leo_sobral@2
   114
leo_sobral@2
   115
  g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
leo_sobral@2
   116
leo_sobral@2
   117
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   118
      "MythTV src");
leo_sobral@2
   119
}
leo_sobral@2
   120
leo_sobral@2
   121
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
rosfran@30
   122
    GST_TYPE_BASE_SRC, _urihandler_init)
rosfran@30
   123
    
rosfran@30
   124
//GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
rosfran@30
   125
//    GST_TYPE_PUSH_SRC, _urihandler_init)
rosfran@30
   126
    
leo_sobral@2
   127
  static void
leo_sobral@2
   128
gst_mythtv_src_base_init (gpointer g_class)
leo_sobral@2
   129
{
leo_sobral@2
   130
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
leo_sobral@2
   131
leo_sobral@2
   132
  gst_element_class_add_pad_template (element_class,
leo_sobral@2
   133
      gst_static_pad_template_get (&srctemplate));
leo_sobral@2
   134
leo_sobral@2
   135
  gst_element_class_set_details (element_class, &gst_mythtv_src_details);
rosfran@52
   136
  
rosfran@52
   137
  element_class->change_state = gst_mythtv_src_change_state;
leo_sobral@2
   138
}
leo_sobral@2
   139
rosfran@30
   140
static void
leo_sobral@2
   141
gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
leo_sobral@2
   142
{
leo_sobral@2
   143
  GObjectClass *gobject_class;
rosfran@30
   144
  //GstPushSrcClass *gstpushsrc_class;
leo_sobral@2
   145
  GstBaseSrcClass *gstbasesrc_class;
leo_sobral@2
   146
leo_sobral@2
   147
  gobject_class = (GObjectClass *) klass;
leo_sobral@2
   148
  gstbasesrc_class = (GstBaseSrcClass *) klass;
leo_sobral@2
   149
leo_sobral@2
   150
  gobject_class->set_property = gst_mythtv_src_set_property;
leo_sobral@2
   151
  gobject_class->get_property = gst_mythtv_src_get_property;
leo_sobral@2
   152
  gobject_class->finalize = gst_mythtv_src_finalize;
leo_sobral@2
   153
leo_sobral@2
   154
  g_object_class_install_property
leo_sobral@2
   155
    (gobject_class, PROP_LOCATION,
leo_sobral@2
   156
     g_param_spec_string ("location", "Location",
leo_sobral@2
   157
       "The location. In the form:"
leo_sobral@2
   158
       "\n\t\t\tmyth://a.com/file.nuv"
leo_sobral@2
   159
       "\n\t\t\tmyth://a.com:23223/file.nuv "
leo_sobral@2
   160
       "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
leo_sobral@2
   161
       "", G_PARAM_READWRITE));
leo_sobral@2
   162
leo_sobral@2
   163
  g_object_class_install_property
leo_sobral@2
   164
    (gobject_class, PROP_URI,
leo_sobral@2
   165
     g_param_spec_string ("uri", "Uri",
leo_sobral@2
   166
       "The location in form of a URI (deprecated; use location)",
leo_sobral@2
   167
       "", G_PARAM_READWRITE));
leo_sobral@2
   168
leo_sobral@2
   169
  g_object_class_install_property
rosfran@40
   170
    (gobject_class, PROP_GMYTHTV_VERSION,
leo_sobral@2
   171
     g_param_spec_int ("mythtv-version", "mythtv-version",
leo_sobral@2
   172
       "Change Myth TV version",
leo_sobral@2
   173
       26, 30, 26, G_PARAM_READWRITE));
leo_sobral@2
   174
leo_sobral@2
   175
  g_object_class_install_property
rosfran@40
   176
    (gobject_class, PROP_GMYTHTV_LIVEID,
leo_sobral@2
   177
     g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
leo_sobral@2
   178
       "Change Myth TV version",
rosfran@40
   179
       0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
leo_sobral@2
   180
leo_sobral@2
   181
  g_object_class_install_property
rosfran@40
   182
    (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
leo_sobral@2
   183
     g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
leo_sobral@2
   184
       "Sets the Myth TV chain ID (from TV Chain)",
leo_sobral@2
   185
       "", G_PARAM_READWRITE));
leo_sobral@2
   186
leo_sobral@2
   187
  g_object_class_install_property
rosfran@40
   188
    (gobject_class, PROP_GMYTHTV_LIVE,
leo_sobral@2
   189
     g_param_spec_boolean ("mythtv-live", "mythtv-live",
leo_sobral@2
   190
       "Enable MythTV Live TV content streaming",
leo_sobral@2
   191
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   192
rosfran@52
   193
  g_object_class_install_property
rosfran@52
   194
    (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
rosfran@52
   195
     g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
rosfran@52
   196
       "Enable MythTV Live TV content size continuous updating",
rosfran@52
   197
       FALSE, G_PARAM_READWRITE));
rosfran@52
   198
leo_sobral@2
   199
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   200
  g_object_class_install_property
rosfran@40
   201
    (gobject_class, PROP_GMYTHTV_DBG,
leo_sobral@2
   202
     g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
leo_sobral@2
   203
       "Enable MythTV debug messages",
leo_sobral@2
   204
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   205
#endif
leo_sobral@2
   206
leo_sobral@2
   207
  gstbasesrc_class->start = gst_mythtv_src_start;
leo_sobral@2
   208
  gstbasesrc_class->stop = gst_mythtv_src_stop;
leo_sobral@2
   209
  gstbasesrc_class->get_size = gst_mythtv_src_get_size;
leo_sobral@2
   210
  gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
leo_sobral@2
   211
leo_sobral@2
   212
  gstbasesrc_class->create = gst_mythtv_src_create;
rosfran@52
   213
    
leo_sobral@2
   214
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   215
      "MythTV Client Source");
leo_sobral@2
   216
}
leo_sobral@2
   217
rosfran@30
   218
static void
leo_sobral@2
   219
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
leo_sobral@2
   220
{
leo_sobral@2
   221
  this->file_transfer = NULL;
leo_sobral@2
   222
leo_sobral@2
   223
  this->unique_setup = FALSE;
leo_sobral@2
   224
rosfran@40
   225
  this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
leo_sobral@2
   226
leo_sobral@2
   227
  this->bytes_read = 0;
leo_sobral@2
   228
rosfran@52
   229
  this->content_size = 0;
leo_sobral@2
   230
  this->read_offset = 0;
leo_sobral@2
   231
rosfran@61
   232
  this->content_size_last = 0;
rosfran@61
   233
leo_sobral@2
   234
  this->live_tv = FALSE;
rosfran@52
   235
  
rosfran@52
   236
  this->enable_timing_position = FALSE;
rosfran@52
   237
  this->update_prog_chain = FALSE;    
leo_sobral@2
   238
leo_sobral@2
   239
  this->user_agent = g_strdup ("mythtvsrc");
rosfran@52
   240
  this->mythtv_caps = NULL;
rosfran@52
   241
  this->update_prog_chain = FALSE;
rosfran@52
   242
  
rosfran@52
   243
  this->eos = FALSE;
rosfran@30
   244
  
rosfran@30
   245
  gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );  
leo_sobral@2
   246
rosfran@59
   247
  gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
rosfran@30
   248
rosfran@30
   249
  gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
rosfran@30
   250
      gst_mythtv_src_handle_event );
rosfran@31
   251
/*
rosfran@30
   252
  gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
rosfran@30
   253
      gst_mythtv_src_query );
rosfran@30
   254
*/
rosfran@30
   255
leo_sobral@2
   256
}
leo_sobral@2
   257
rosfran@30
   258
static void
leo_sobral@2
   259
gst_mythtv_src_finalize (GObject * gobject)
leo_sobral@2
   260
{
leo_sobral@2
   261
  GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
leo_sobral@2
   262
leo_sobral@2
   263
  if (this->mythtv_caps) {
leo_sobral@2
   264
    gst_caps_unref (this->mythtv_caps);
leo_sobral@2
   265
    this->mythtv_caps = NULL;
leo_sobral@2
   266
  }
leo_sobral@2
   267
leo_sobral@2
   268
  if (this->file_transfer) {
leo_sobral@2
   269
    g_object_unref (this->file_transfer);
leo_sobral@2
   270
    this->file_transfer = NULL;
leo_sobral@2
   271
  }
leo_sobral@2
   272
rosfran@52
   273
	if (this->spawn_livetv) {
rosfran@52
   274
    //g_object_unref (this->spawn_livetv);
rosfran@52
   275
    this->spawn_livetv = NULL;
rosfran@52
   276
  }
rosfran@52
   277
leo_sobral@2
   278
  if (this->uri_name) {
leo_sobral@2
   279
    g_free (this->uri_name);
leo_sobral@2
   280
  }
leo_sobral@2
   281
leo_sobral@2
   282
  if (this->user_agent) {
leo_sobral@2
   283
    g_free (this->user_agent);
leo_sobral@2
   284
  }
leo_sobral@2
   285
leo_sobral@2
   286
  G_OBJECT_CLASS (parent_class)->finalize (gobject);
leo_sobral@2
   287
}
leo_sobral@2
   288
rosfran@37
   289
static gint
rosfran@30
   290
do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
leo_sobral@2
   291
{
rosfran@37
   292
  gint read = 0;
rosfran@52
   293
  guint sizetoread = size;
leo_sobral@2
   294
rosfran@30
   295
  g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
leo_sobral@2
   296
rosfran@30
   297
  /* Loop sending the Myth File Transfer request:
leo_sobral@2
   298
   * Retry whilst authentication fails and we supply it. */
rosfran@37
   299
  gint len = 0;
leo_sobral@2
   300
rosfran@37
   301
  GST_OBJECT_LOCK(src);
leo_sobral@2
   302
leo_sobral@2
   303
  while ( sizetoread > 0 ) {
rosfran@61
   304
rosfran@61
   305
    len = gmyth_file_transfer_read( src->file_transfer,
rosfran@61
   306
	GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
leo_sobral@2
   307
leo_sobral@2
   308
    if ( len > 0 ) {
rosfran@34
   309
      read += len;      
leo_sobral@2
   310
      sizetoread -= len;
rosfran@52
   311
    } 
rosfran@52
   312
    else if ( len <= 0 ) 
rosfran@52
   313
    {
rosfran@61
   314
rosfran@52
   315
      if ( src->live_tv == FALSE ) 
rosfran@52
   316
      {
rosfran@61
   317
	goto done;
rosfran@52
   318
      } 
rosfran@52
   319
      else  
rosfran@52
   320
      {
rosfran@61
   321
	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
rosfran@61
   322
	  src->update_prog_chain = TRUE;
rosfran@61
   323
	  if ( gst_mythtv_src_next_program_chain ( src ) )
rosfran@61
   324
	    continue;
rosfran@61
   325
	  else
rosfran@61
   326
	    goto done;
rosfran@61
   327
	} else 
rosfran@61
   328
	  if ( src->content_size <= 
rosfran@61
   329
	      ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
rosfran@61
   330
	    src->update_prog_chain = TRUE;
rosfran@61
   331
	    if ( src->enable_timing_position ) {
rosfran@61
   332
	      gint64 size_tmp = 0;
rosfran@61
   333
	      if (src->live_tv == TRUE) {
rosfran@61
   334
get_file_pos:
rosfran@61
   335
		size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
   336
		if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
   337
		  src->content_size = size_tmp;
rosfran@61
   338
		else if ( size_tmp > 0 )
rosfran@61
   339
		  goto get_file_pos;
rosfran@61
   340
		g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
   341
		    __FUNCTION__, size_tmp );
rosfran@52
   342
	      }
rosfran@61
   343
	    } else {
rosfran@61
   344
	      gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
   345
	      if ( new_offset > 0 ) {
rosfran@61
   346
		if ( src->content_size < new_offset ) {
rosfran@61
   347
		  src->content_size = new_offset;
rosfran@61
   348
		}
rosfran@61
   349
	      } else {
rosfran@61
   350
		src->update_prog_chain = TRUE;
rosfran@61
   351
	      }
rosfran@61
   352
	    }
rosfran@61
   353
	    goto done;
rosfran@61
   354
	  }
rosfran@61
   355
      }
rosfran@30
   356
rosfran@61
   357
    }
rosfran@61
   358
rosfran@30
   359
    if ( read == sizetoread )
leo_sobral@2
   360
      break;
leo_sobral@2
   361
  }
rosfran@61
   362
leo_sobral@2
   363
  if ( read > 0 ) {
rosfran@61
   364
    src->read_offset += read;
leo_sobral@2
   365
    src->bytes_read += read;
rosfran@61
   366
rosfran@61
   367
    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
rosfran@61
   368
	"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
rosfran@61
   369
	src->read_offset, src->content_size );
rosfran@61
   370
rosfran@61
   371
    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
rosfran@61
   372
    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
rosfran@61
   373
    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
rosfran@61
   374
rosfran@61
   375
    g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
rosfran@61
   376
	"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
rosfran@61
   377
	GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
rosfran@61
   378
rosfran@34
   379
  } else if ( !src->live_tv )
rosfran@61
   380
    goto eos;
rosfran@61
   381
rosfran@30
   382
  goto done;
leo_sobral@2
   383
leo_sobral@2
   384
eos:
leo_sobral@2
   385
  src->eos = TRUE;
rosfran@61
   386
leo_sobral@2
   387
done:
rosfran@37
   388
  GST_OBJECT_UNLOCK(src);
leo_sobral@2
   389
leo_sobral@2
   390
  return read;
leo_sobral@2
   391
}
leo_sobral@2
   392
rosfran@30
   393
static GstFlowReturn
rosfran@30
   394
gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
leo_sobral@2
   395
{
leo_sobral@2
   396
  GstMythtvSrc *src;
leo_sobral@2
   397
  GstFlowReturn ret = GST_FLOW_OK;
rosfran@37
   398
  gint read = -1;
rosfran@30
   399
  
rosfran@30
   400
  src = GST_MYTHTV_SRC (psrc);
rosfran@31
   401
  /* The caller should know the number of bytes and not read beyond EOS. */
rosfran@31
   402
  if (G_UNLIKELY (src->eos))
rosfran@31
   403
    goto eos;
rosfran@40
   404
  if ( G_UNLIKELY (src->update_prog_chain) )
rosfran@40
   405
    goto change_progchain;
rosfran@30
   406
  
rosfran@52
   407
  GST_OBJECT_LOCK(src);
leo_sobral@2
   408
rosfran@30
   409
  if (G_UNLIKELY (src->read_offset != offset)) {
rosfran@61
   410
    gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, SEEK_SET);
rosfran@40
   411
    g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
rosfran@34
   412
    	__FUNCTION__, src->read_offset, new_offset );
rosfran@34
   413
    if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
rosfran@34
   414
    {
rosfran@52
   415
      GST_OBJECT_UNLOCK(src);
rosfran@52
   416
      if ( src->live_tv )
rosfran@52
   417
      	goto change_progchain;
rosfran@52
   418
      else
rosfran@52
   419
      	goto eos;
rosfran@31
   420
    }
leo_sobral@2
   421
rosfran@30
   422
    src->read_offset = offset;
rosfran@30
   423
  }
rosfran@52
   424
  GST_OBJECT_UNLOCK(src);
rosfran@30
   425
  
rosfran@31
   426
  /* Create the buffer. */
rosfran@31
   427
  ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
rosfran@31
   428
      src->read_offset, size,
rosfran@31
   429
      //src->icy_caps ? src->icy_caps :
rosfran@31
   430
      GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
leo_sobral@2
   431
rosfran@31
   432
  if (G_UNLIKELY (ret != GST_FLOW_OK))
rosfran@31
   433
    goto done;
rosfran@30
   434
  
rosfran@31
   435
  read = do_read_request_response ( src, src->read_offset, size, outbuf );
leo_sobral@2
   436
rosfran@40
   437
  if (G_UNLIKELY (src->update_prog_chain) )
rosfran@40
   438
    goto change_progchain;
rosfran@40
   439
rosfran@52
   440
  if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
rosfran@52
   441
  	if ( src->live_tv )
rosfran@52
   442
    	goto change_progchain;
rosfran@52
   443
    else
rosfran@52
   444
    	goto read_error;
rosfran@31
   445
  }
leo_sobral@2
   446
leo_sobral@2
   447
done:
rosfran@31
   448
 {
rosfran@31
   449
    const gchar *reason = gst_flow_get_name (ret);
rosfran@31
   450
rosfran@31
   451
    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
rosfran@31
   452
  	return ret;
rosfran@31
   453
 }
leo_sobral@2
   454
eos:
leo_sobral@2
   455
  {
rosfran@30
   456
    const gchar *reason = gst_flow_get_name (ret);
rosfran@30
   457
rosfran@30
   458
    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
leo_sobral@2
   459
    return GST_FLOW_UNEXPECTED;
leo_sobral@2
   460
  }
leo_sobral@2
   461
  /* ERRORS */
leo_sobral@2
   462
read_error:
leo_sobral@2
   463
  {
leo_sobral@2
   464
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
leo_sobral@2
   465
	(NULL), ("Could not read any bytes (%i, %s)", read,
leo_sobral@2
   466
	  src->uri_name));
leo_sobral@2
   467
    return GST_FLOW_ERROR;
leo_sobral@2
   468
  }
rosfran@40
   469
change_progchain:
rosfran@37
   470
  {
rosfran@37
   471
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@52
   472
		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
rosfran@52
   473
		  src->uri_name));
rosfran@52
   474
		// go to the next program chain
rosfran@52
   475
		src->unique_setup = FALSE;
rosfran@52
   476
		src->update_prog_chain = TRUE;
rosfran@52
   477
		gst_mythtv_src_next_program_chain( src );  
rosfran@52
   478
    return -101;
rosfran@37
   479
  }
rosfran@30
   480
leo_sobral@2
   481
}
leo_sobral@2
   482
rosfran@30
   483
void
rosfran@30
   484
update_size_func( void *mythtv_data ) 
leo_sobral@2
   485
{
rosfran@30
   486
  GstMythtvSrc *src;
leo_sobral@2
   487
rosfran@30
   488
  g_return_if_fail( mythtv_data != NULL );
leo_sobral@2
   489
rosfran@30
   490
  src = GST_MYTHTV_SRC ( mythtv_data );
rosfran@30
   491
rosfran@30
   492
  g_static_mutex_lock( &update_size_mutex );
rosfran@30
   493
rosfran@30
   494
  if ( src->do_start ) {
rosfran@61
   495
    if ( src->enable_timing_position ) {
rosfran@61
   496
      gint64 size_tmp = 0;
rosfran@61
   497
      if (src->live_tv == TRUE) {
rosfran@61
   498
get_file_pos:
rosfran@61
   499
	g_usleep( 50 );
rosfran@61
   500
	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
   501
	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
   502
	  src->content_size = size_tmp;
rosfran@61
   503
	else if ( size_tmp > 0 )
rosfran@61
   504
	  goto get_file_pos;
rosfran@61
   505
	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
   506
	    __FUNCTION__, size_tmp );
rosfran@61
   507
      }
rosfran@61
   508
    }
leo_sobral@2
   509
  }
rosfran@30
   510
  g_static_mutex_unlock( &update_size_mutex );
leo_sobral@2
   511
leo_sobral@2
   512
}
leo_sobral@2
   513
rosfran@52
   514
gint64
rosfran@30
   515
gst_mythtv_src_get_position ( GstMythtvSrc* src ) 
leo_sobral@2
   516
{
rosfran@30
   517
rosfran@52
   518
  gint64 size_tmp = 0;
rosfran@61
   519
  guint max_tries = 3;
rosfran@52
   520
  if (src->live_tv == TRUE) {
rosfran@30
   521
get_file_pos:
rosfran@61
   522
    g_usleep( 10 );
rosfran@52
   523
    size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@52
   524
    if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
   525
      src->content_size = size_tmp;
rosfran@61
   526
    else if ( size_tmp > 0 && --max_tries > 0 )
rosfran@61
   527
      goto get_file_pos;
rosfran@52
   528
    g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
   529
	__FUNCTION__, size_tmp );
rosfran@30
   530
  }
rosfran@52
   531
rosfran@30
   532
  return src->content_size;	
rosfran@30
   533
leo_sobral@2
   534
}
leo_sobral@2
   535
leo_sobral@2
   536
/* create a socket for connecting to remote server */
rosfran@30
   537
static gboolean
leo_sobral@2
   538
gst_mythtv_src_start ( GstBaseSrc * bsrc )
leo_sobral@2
   539
{
leo_sobral@2
   540
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   541
leo_sobral@2
   542
  GString *chain_id_local = NULL;
leo_sobral@2
   543
leo_sobral@2
   544
  gboolean ret = TRUE;
rosfran@52
   545
  
rosfran@52
   546
  if ( !src->do_start )
rosfran@52
   547
  	goto done;
rosfran@30
   548
leo_sobral@2
   549
  if (src->unique_setup == FALSE) {
leo_sobral@2
   550
    src->unique_setup = TRUE;
leo_sobral@2
   551
  } else {
leo_sobral@2
   552
    goto done;
leo_sobral@2
   553
  }
leo_sobral@2
   554
leo_sobral@2
   555
  GST_OBJECT_LOCK(src);
leo_sobral@2
   556
leo_sobral@2
   557
  if ( src->live_tv ) {
rosfran@40
   558
    src->spawn_livetv = gmyth_livetv_new( );
rosfran@40
   559
    if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
rosfran@30
   560
      ret = FALSE;
rosfran@52
   561
      GST_OBJECT_UNLOCK( src );
rosfran@30
   562
      goto init_failed;
leo_sobral@2
   563
    }
rosfran@52
   564
leo_sobral@2
   565
    /* set up the uri variable */
leo_sobral@2
   566
    src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
leo_sobral@2
   567
    chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
leo_sobral@2
   568
    if ( chain_id_local != NULL ) {
leo_sobral@2
   569
      src->live_chain_id = g_strdup( chain_id_local->str );
leo_sobral@2
   570
      g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
leo_sobral@2
   571
    }
leo_sobral@2
   572
    src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
leo_sobral@2
   573
    g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
leo_sobral@2
   574
  }
leo_sobral@2
   575
rosfran@40
   576
  src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
leo_sobral@2
   577
      g_string_new( src->uri_name ), -1, src->mythtv_version );
leo_sobral@2
   578
leo_sobral@2
   579
  if ( src->file_transfer == NULL ) {
leo_sobral@2
   580
    GST_OBJECT_UNLOCK(src);
leo_sobral@2
   581
leo_sobral@2
   582
    goto init_failed;
leo_sobral@2
   583
  }
leo_sobral@2
   584
leo_sobral@2
   585
  /* sets the Playback monitor connection */
rosfran@40
   586
  ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   587
leo_sobral@2
   588
  if ( src->live_tv == TRUE && ret == TRUE ) {
leo_sobral@2
   589
    /* loop finished, set the max tries variable to zero again... */
leo_sobral@2
   590
    wait_to_transfer = 0;
leo_sobral@2
   591
rosfran@40
   592
    while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE 
rosfran@40
   593
	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
leo_sobral@2
   594
      g_usleep( 100 );
leo_sobral@2
   595
  }
leo_sobral@2
   596
leo_sobral@2
   597
  /* sets the FileTransfer instance connection (video/audio download) */
rosfran@40
   598
  ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   599
leo_sobral@2
   600
  if ( ret == FALSE ) {
leo_sobral@2
   601
    GST_OBJECT_UNLOCK(src);
leo_sobral@2
   602
#ifndef GST_DISABLE_GST_DEBUG  
leo_sobral@2
   603
    if ( src->mythtv_msgs_dbg )
leo_sobral@2
   604
      g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
leo_sobral@2
   605
#endif
leo_sobral@2
   606
    goto begin_req_failed;
leo_sobral@2
   607
  }
leo_sobral@2
   608
leo_sobral@2
   609
  src->content_size = src->file_transfer->filesize;
leo_sobral@2
   610
leo_sobral@2
   611
  GST_OBJECT_UNLOCK(src);
rosfran@30
   612
rosfran@52
   613
  src->do_start = FALSE;
rosfran@30
   614
rosfran@30
   615
done:
rosfran@30
   616
  return TRUE;
rosfran@30
   617
rosfran@30
   618
  /* ERRORS */
rosfran@30
   619
init_failed:
rosfran@30
   620
  {
rosfran@30
   621
    if (src->spawn_livetv != NULL )
rosfran@30
   622
      g_object_unref( src->spawn_livetv );
rosfran@30
   623
rosfran@30
   624
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@30
   625
	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
rosfran@30
   626
    return FALSE;
rosfran@30
   627
  }
rosfran@30
   628
begin_req_failed:
rosfran@30
   629
  {
rosfran@30
   630
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@30
   631
	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
rosfran@30
   632
    return FALSE;
rosfran@30
   633
  }
rosfran@30
   634
}
leo_sobral@2
   635
rosfran@52
   636
/* create a new socket for connecting to the next program chain */
rosfran@52
   637
static gboolean
rosfran@52
   638
gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
rosfran@52
   639
{
rosfran@52
   640
  GString *chain_id_local = NULL;
rosfran@52
   641
rosfran@52
   642
  gboolean ret = TRUE;
rosfran@61
   643
rosfran@52
   644
  if ( !src->live_tv )
rosfran@61
   645
    goto init_failed;
rosfran@61
   646
rosfran@61
   647
  src->update_prog_chain = FALSE;
rosfran@61
   648
rosfran@52
   649
  if (src->file_transfer) {
rosfran@52
   650
    g_object_unref (src->file_transfer);
rosfran@52
   651
    src->file_transfer = NULL;
rosfran@52
   652
  }
rosfran@61
   653
rosfran@52
   654
  if (src->uri_name) {
rosfran@52
   655
    g_free (src->uri_name);
rosfran@52
   656
  }
rosfran@61
   657
rosfran@52
   658
  if ( src->live_tv ) {
rosfran@61
   659
    if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
rosfran@61
   660
      ret = FALSE;
rosfran@61
   661
      goto init_failed;
rosfran@52
   662
    }
rosfran@52
   663
    /* set up the uri variable */
rosfran@52
   664
    src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
rosfran@52
   665
    chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
rosfran@52
   666
    if ( chain_id_local != NULL ) {
rosfran@52
   667
      src->live_chain_id = g_strdup( chain_id_local->str );
rosfran@52
   668
      g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
rosfran@52
   669
    }
rosfran@52
   670
    src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
rosfran@52
   671
    g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
rosfran@52
   672
  }
rosfran@52
   673
rosfran@52
   674
  src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
rosfran@52
   675
      g_string_new( src->uri_name ), -1, src->mythtv_version );
rosfran@52
   676
rosfran@52
   677
  if ( src->file_transfer == NULL ) {
rosfran@52
   678
    goto init_failed;
rosfran@52
   679
  }
rosfran@52
   680
rosfran@52
   681
  /* sets the Playback monitor connection */
rosfran@52
   682
  ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
rosfran@52
   683
rosfran@52
   684
  if ( src->live_tv == TRUE && ret == TRUE ) {
rosfran@52
   685
    /* loop finished, set the max tries variable to zero again... */
rosfran@52
   686
    wait_to_transfer = 0;
rosfran@61
   687
rosfran@61
   688
    g_usleep( 200 );
rosfran@52
   689
rosfran@52
   690
    while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && 
rosfran@61
   691
	( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
rosfran@61
   692
      g_usleep( 1000 );
rosfran@52
   693
  }
rosfran@52
   694
rosfran@52
   695
  /* sets the FileTransfer instance connection (video/audio download) */
rosfran@52
   696
  ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
rosfran@52
   697
rosfran@52
   698
  if ( ret == FALSE ) {
rosfran@52
   699
#ifndef GST_DISABLE_GST_DEBUG  
rosfran@52
   700
    if ( src->mythtv_msgs_dbg )
rosfran@52
   701
      g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
rosfran@52
   702
#endif
rosfran@52
   703
    goto begin_req_failed;
rosfran@52
   704
  }
rosfran@61
   705
  src->content_size_last = src->content_size;
rosfran@61
   706
rosfran@61
   707
#if 0
rosfran@52
   708
  if ( src->content_size < src->file_transfer->filesize ) {
rosfran@61
   709
    src->content_size = src->file_transfer->filesize;
rosfran@52
   710
  } else {
rosfran@61
   711
    //gint64 pos = gst_mythtv_src_get_position(src);
rosfran@61
   712
    //if ( pos > src->file_transfer->filesize )
rosfran@61
   713
    //	src->content_size = pos;  	
rosfran@61
   714
rosfran@52
   715
  }
rosfran@61
   716
#endif
rosfran@61
   717
rosfran@61
   718
  src->content_size = src->file_transfer->filesize;
rosfran@61
   719
  //src->read_offset = 0;
rosfran@61
   720
rosfran@61
   721
  //src->update_prog_chain = FALSE;
rosfran@52
   722
rosfran@52
   723
  return TRUE;
rosfran@52
   724
rosfran@52
   725
  /* ERRORS */
rosfran@52
   726
init_failed:
rosfran@52
   727
  {
rosfran@52
   728
    if (src->spawn_livetv != NULL )
rosfran@52
   729
      g_object_unref( src->spawn_livetv );
rosfran@52
   730
rosfran@52
   731
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@52
   732
	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
rosfran@52
   733
    return FALSE;
rosfran@52
   734
  }
rosfran@52
   735
begin_req_failed:
rosfran@52
   736
  {
rosfran@52
   737
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@52
   738
	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
rosfran@52
   739
    return FALSE;
rosfran@52
   740
  }
rosfran@61
   741
rosfran@52
   742
}
rosfran@52
   743
leo_sobral@2
   744
#if 0
rosfran@30
   745
/* handles queries for location in the stream in the requested format */
rosfran@30
   746
static gboolean
rosfran@30
   747
gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
rosfran@30
   748
{
rosfran@30
   749
  gboolean res = TRUE;
rosfran@30
   750
  GstMythtvSrc *mythtv;
leo_sobral@2
   751
rosfran@30
   752
  guint64 size = 0;
rosfran@30
   753
rosfran@40
   754
  mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
rosfran@30
   755
rosfran@30
   756
  size = gst_mythtv_src_get_position (mythtv);
rosfran@30
   757
rosfran@30
   758
  switch (GST_QUERY_TYPE (query)) {
rosfran@30
   759
rosfran@30
   760
    case GST_QUERY_POSITION:
rosfran@30
   761
      {
rosfran@30
   762
rosfran@30
   763
	//GstFormat format;
rosfran@30
   764
	gint64 cur = 0;
rosfran@30
   765
rosfran@30
   766
	/* save requested format */
rosfran@30
   767
	gst_query_parse_position (query, NULL, &cur);
rosfran@30
   768
rosfran@30
   769
	/* query peer for current position in time */
rosfran@30
   770
	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
rosfran@30
   771
	    ( size > cur ) ? "greater" : "lower", size, cur );
rosfran@30
   772
	gst_query_set_position (query, GST_FORMAT_BYTES, size);
rosfran@30
   773
	if ( size < cur )
rosfran@30
   774
	  goto error;
rosfran@30
   775
rosfran@30
   776
	break;
leo_sobral@2
   777
      }
rosfran@30
   778
     #if 0
rosfran@30
   779
    case GST_QUERY_DURATION:
rosfran@30
   780
      {
rosfran@30
   781
	//GstFormat format;
rosfran@30
   782
	gint64 cur = 0;
rosfran@30
   783
rosfran@30
   784
	/* save requested format */
rosfran@30
   785
	gst_query_parse_position (query, NULL, &cur);
rosfran@30
   786
rosfran@30
   787
	/* query peer for current position in time */
rosfran@30
   788
	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
rosfran@30
   789
	    ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND, 
rosfran@30
   790
	    cur * GST_SECOND );
rosfran@30
   791
	gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
rosfran@30
   792
rosfran@30
   793
	if ( size * GST_SECOND < cur * GST_SECOND )
rosfran@30
   794
	  goto error;
rosfran@30
   795
rosfran@30
   796
	break;
rosfran@30
   797
      }
rosfran@30
   798
	#endif
rosfran@30
   799
    default:
rosfran@30
   800
      res = FALSE;
rosfran@30
   801
      break;
rosfran@30
   802
  }
rosfran@30
   803
rosfran@30
   804
  return res;
rosfran@30
   805
rosfran@30
   806
error:
rosfran@30
   807
rosfran@30
   808
  return FALSE;
rosfran@30
   809
}
leo_sobral@2
   810
#endif
leo_sobral@2
   811
rosfran@30
   812
static gboolean
leo_sobral@2
   813
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
leo_sobral@2
   814
{
rosfran@31
   815
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
rosfran@30
   816
  gboolean ret = TRUE;
leo_sobral@2
   817
rosfran@30
   818
  if (src->content_size <= 0) {
rosfran@30
   819
    ret= FALSE;
rosfran@61
   820
  } else if ( src->live_tv ) {
rosfran@61
   821
    //g_static_mutex_lock( &update_size_mutex );
rosfran@61
   822
    //GST_OBJECT_LOCK(src);
rosfran@30
   823
rosfran@61
   824
    gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
   825
    if ( new_offset > 0 ) {
rosfran@61
   826
      if ( src->content_size < new_offset ) {
rosfran@61
   827
	src->content_size = new_offset;
rosfran@61
   828
      }
rosfran@61
   829
    } else {
rosfran@61
   830
      if ( src->live_tv )
rosfran@61
   831
	src->update_prog_chain = TRUE;
rosfran@61
   832
    }
rosfran@61
   833
rosfran@61
   834
    if ( src->enable_timing_position ) {
rosfran@61
   835
      gint64 size_tmp = 0;
rosfran@61
   836
      if (src->live_tv == TRUE) {
rosfran@61
   837
get_file_pos:
rosfran@61
   838
	g_usleep( 5 );
rosfran@61
   839
	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
rosfran@61
   840
	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
rosfran@61
   841
	  src->content_size = size_tmp;
rosfran@61
   842
	else if ( size_tmp > 0  )
rosfran@61
   843
	  goto get_file_pos;
rosfran@61
   844
	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
rosfran@61
   845
	    __FUNCTION__, size_tmp );
rosfran@61
   846
      }
rosfran@61
   847
    }
rosfran@61
   848
    //GST_OBJECT_UNLOCK(src);
rosfran@61
   849
    //g_static_mutex_unlock( &update_size_mutex );
leo_sobral@2
   850
  }
leo_sobral@2
   851
leo_sobral@2
   852
  *size = src->content_size;
rosfran@52
   853
  g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
leo_sobral@2
   854
rosfran@30
   855
  return ret;
rosfran@30
   856
leo_sobral@2
   857
}
leo_sobral@2
   858
leo_sobral@2
   859
/* close the socket and associated resources
leo_sobral@2
   860
 * used both to recover from errors and go to NULL state */
rosfran@52
   861
static gboolean
leo_sobral@2
   862
gst_mythtv_src_stop (GstBaseSrc * bsrc)
leo_sobral@2
   863
{
leo_sobral@2
   864
  GstMythtvSrc *src;
leo_sobral@2
   865
leo_sobral@2
   866
  src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   867
leo_sobral@2
   868
  if (src->uri_name) {
leo_sobral@2
   869
    g_free (src->uri_name);
leo_sobral@2
   870
    src->uri_name = NULL;
leo_sobral@2
   871
  }
leo_sobral@2
   872
leo_sobral@2
   873
  if (src->mythtv_caps) {
leo_sobral@2
   874
    gst_caps_unref (src->mythtv_caps);
leo_sobral@2
   875
    src->mythtv_caps = NULL;
leo_sobral@2
   876
  }
leo_sobral@2
   877
leo_sobral@2
   878
  src->eos = FALSE;
leo_sobral@2
   879
leo_sobral@2
   880
  return TRUE;
leo_sobral@2
   881
}
leo_sobral@2
   882
rosfran@30
   883
static gboolean
leo_sobral@2
   884
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
leo_sobral@2
   885
{
leo_sobral@2
   886
  GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
rosfran@52
   887
  gint64 cont_size = 0;
leo_sobral@2
   888
leo_sobral@2
   889
  switch (GST_EVENT_TYPE (event)) {
rosfran@30
   890
#if 0
leo_sobral@2
   891
    case GST_EVENT_FLUSH_START:
rosfran@52
   892
      //src->eos = FALSE;
rosfran@52
   893
      g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
rosfran@61
   894
      cont_size = gst_mythtv_src_get_position (src);
rosfran@61
   895
      if ( !src->live_tv ) {
rosfran@61
   896
	if ( cont_size > src->content_size ) {
rosfran@61
   897
	  src->content_size = cont_size;
rosfran@61
   898
	  src->eos = FALSE;
rosfran@61
   899
	} else {
rosfran@61
   900
	  src->eos = TRUE;
rosfran@61
   901
	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
rosfran@61
   902
	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
rosfran@61
   903
	}
rosfran@61
   904
      } else {
rosfran@61
   905
	if ( cont_size <= 0 ) {
rosfran@61
   906
	  src->update_prog_chain = TRUE;
rosfran@61
   907
	  src->eos = TRUE;
rosfran@61
   908
	  src->unique_setup = FALSE;
rosfran@61
   909
	  src->do_start = TRUE;		  				  		
rosfran@61
   910
	}		  	
rosfran@61
   911
      }
rosfran@61
   912
      break;
leo_sobral@2
   913
    case GST_EVENT_FLUSH_STOP:
leo_sobral@2
   914
      src->do_start = TRUE;
leo_sobral@2
   915
      src->eos = FALSE;
leo_sobral@2
   916
      gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
rosfran@30
   917
      //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
rosfran@30
   918
      break;
rosfran@30
   919
#endif
rosfran@30
   920
    case GST_EVENT_EOS:
rosfran@30
   921
      g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
rosfran@61
   922
rosfran@61
   923
      if ( src->live_tv ) {
rosfran@61
   924
	cont_size = gst_mythtv_src_get_position (src);
rosfran@61
   925
	if ( cont_size > src->content_size ) {
rosfran@61
   926
	  src->content_size = cont_size;
rosfran@61
   927
	  src->eos = FALSE;
rosfran@61
   928
	} else {
rosfran@61
   929
	  src->eos = TRUE;
rosfran@61
   930
	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
rosfran@61
   931
	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
rosfran@61
   932
	}
rosfran@61
   933
      } else 
rosfran@61
   934
	src->eos = TRUE;
rosfran@30
   935
      break;
rosfran@30
   936
#if 0
rosfran@30
   937
    case GST_EVENT_NEWSEGMENT:
rosfran@30
   938
      g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
rosfran@30
   939
      src->eos = FALSE;
leo_sobral@2
   940
      break;
leo_sobral@2
   941
    case GST_EVENT_SEEK:  	  
leo_sobral@2
   942
      {
rosfran@30
   943
	g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
leo_sobral@2
   944
	gdouble rate;
leo_sobral@2
   945
	//gboolean update = TRUE;
leo_sobral@2
   946
	GstFormat format;
leo_sobral@2
   947
	GstSeekType cur_type, stop_type;
leo_sobral@2
   948
	GstSeekFlags flags;
leo_sobral@2
   949
	gint64 cur = 0, stop = 0;
leo_sobral@2
   950
	gst_event_parse_seek ( event, &rate, &format,
leo_sobral@2
   951
	    &flags, &cur_type, &cur,
leo_sobral@2
   952
	    &stop_type, &stop );
leo_sobral@2
   953
leo_sobral@2
   954
	g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
leo_sobral@2
   955
	if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
leo_sobral@2
   956
	  g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
leo_sobral@2
   957
	}
leo_sobral@2
   958
	//gboolean ret = gst_event_parse_new_segment ( event,
leo_sobral@2
   959
	//    &update, &rate, &format, &start, &stop,
leo_sobral@2
   960
	//    &position );
leo_sobral@2
   961
	//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ), 
leo_sobral@2
   962
	//			cur, stop - cur + 1, GstBuffer)
rosfran@30
   963
      }
rosfran@30
   964
#endif
leo_sobral@2
   965
    default:
leo_sobral@2
   966
      return gst_pad_event_default (pad, event);
leo_sobral@2
   967
  }
leo_sobral@2
   968
leo_sobral@2
   969
  return gst_pad_event_default (pad, event);
leo_sobral@2
   970
}
leo_sobral@2
   971
rosfran@30
   972
static gboolean
rosfran@30
   973
gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
leo_sobral@2
   974
{
leo_sobral@2
   975
  return TRUE;
leo_sobral@2
   976
}
leo_sobral@2
   977
rosfran@61
   978
#if 0
rosfran@61
   979
static gboolean
rosfran@61
   980
gst_nuv_demux_sink_activate (GstPad * sinkpad)
rosfran@61
   981
{
rosfran@61
   982
  gboolean res = TRUE;
rosfran@61
   983
  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
rosfran@61
   984
rosfran@61
   985
  if (gst_pad_check_pull_range (sinkpad)) {
rosfran@61
   986
    nuv->mode = 0;
rosfran@61
   987
    nuv->adapter = NULL;
rosfran@61
   988
    res = gst_pad_activate_pull (sinkpad, TRUE);
rosfran@61
   989
  } else {
rosfran@61
   990
    nuv->mode = 1;
rosfran@61
   991
    nuv->adapter = gst_adapter_new ();
rosfran@61
   992
    res = gst_pad_activate_push (sinkpad, TRUE);
rosfran@61
   993
  }
rosfran@61
   994
rosfran@61
   995
  g_object_unref (nuv);
rosfran@61
   996
  return res;
rosfran@61
   997
}
rosfran@61
   998
rosfran@61
   999
static gboolean
rosfran@61
  1000
gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
rosfran@61
  1001
{
rosfran@61
  1002
  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
rosfran@61
  1003
rosfran@61
  1004
  if (active) {
rosfran@61
  1005
    gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
rosfran@61
  1006
  } else {
rosfran@61
  1007
    gst_pad_stop_task (sinkpad);
rosfran@61
  1008
  }
rosfran@61
  1009
  gst_object_unref (nuv);
rosfran@61
  1010
rosfran@61
  1011
  return TRUE;
rosfran@61
  1012
}
rosfran@61
  1013
rosfran@61
  1014
static GstFlowReturn
rosfran@61
  1015
gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
rosfran@61
  1016
{
rosfran@61
  1017
  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
rosfran@61
  1018
rosfran@61
  1019
  gst_adapter_push (nuv->adapter, buf);
rosfran@61
  1020
rosfran@61
  1021
  return gst_nuv_demux_play (pad);
rosfran@61
  1022
}
rosfran@61
  1023
rosfran@61
  1024
static void
rosfran@61
  1025
gst_nuv_demux_loop (GstPad * pad)
rosfran@61
  1026
{
rosfran@61
  1027
  gst_nuv_demux_play (pad);
rosfran@61
  1028
}
rosfran@61
  1029
#endif
rosfran@61
  1030
rosfran@52
  1031
static GstStateChangeReturn
rosfran@52
  1032
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
rosfran@52
  1033
{
rosfran@52
  1034
  GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
rosfran@52
  1035
  GstMythtvSrc *src = GST_MYTHTV_SRC (element);
rosfran@52
  1036
rosfran@52
  1037
  switch (transition) {
rosfran@52
  1038
    case GST_STATE_CHANGE_NULL_TO_READY:
rosfran@52
  1039
      src->do_start = TRUE;
rosfran@52
  1040
      src->unique_setup = FALSE;      
rosfran@52
  1041
      break;
rosfran@52
  1042
    case GST_STATE_CHANGE_READY_TO_PAUSED:
rosfran@52
  1043
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
rosfran@52
  1044
      src->eos = FALSE;
rosfran@52
  1045
      break;
rosfran@52
  1046
    default:
rosfran@52
  1047
      break;
rosfran@52
  1048
  }
rosfran@61
  1049
rosfran@61
  1050
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
rosfran@52
  1051
  if (ret == GST_STATE_CHANGE_FAILURE)
rosfran@52
  1052
    return ret;
rosfran@52
  1053
rosfran@52
  1054
  switch (transition) {
rosfran@52
  1055
    case GST_STATE_CHANGE_READY_TO_NULL:
rosfran@52
  1056
      break;
rosfran@61
  1057
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
rosfran@52
  1058
    case GST_STATE_CHANGE_PAUSED_TO_READY:
rosfran@61
  1059
      if ( src->live_tv && src->update_prog_chain ) {
rosfran@61
  1060
	src->read_offset = 0;
rosfran@61
  1061
	src->bytes_read = 0;
rosfran@61
  1062
	gst_mythtv_src_next_program_chain( src );
rosfran@61
  1063
      }
rosfran@61
  1064
      break;
rosfran@52
  1065
    default:
rosfran@52
  1066
      break;
rosfran@52
  1067
  }
rosfran@52
  1068
rosfran@52
  1069
  return ret;
rosfran@52
  1070
}
rosfran@52
  1071
rosfran@30
  1072
static void
leo_sobral@2
  1073
gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
  1074
    const GValue * value, GParamSpec * pspec)
leo_sobral@2
  1075
{
leo_sobral@2
  1076
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1077
leo_sobral@2
  1078
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1079
  switch (prop_id) {
leo_sobral@2
  1080
    case PROP_URI:
leo_sobral@2
  1081
    case PROP_LOCATION:
leo_sobral@2
  1082
      {
leo_sobral@2
  1083
	if (!g_value_get_string (value)) {
leo_sobral@2
  1084
	  GST_WARNING ("location property cannot be NULL");
leo_sobral@2
  1085
	  goto done;
leo_sobral@2
  1086
	}
leo_sobral@2
  1087
leo_sobral@2
  1088
	if (mythtvsrc->uri_name != NULL) {
leo_sobral@2
  1089
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
  1090
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
  1091
	}
leo_sobral@2
  1092
	mythtvsrc->uri_name = g_value_dup_string (value);
leo_sobral@2
  1093
leo_sobral@2
  1094
	break;
leo_sobral@2
  1095
      }
leo_sobral@2
  1096
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1097
    case PROP_GMYTHTV_DBG:
leo_sobral@2
  1098
      {
leo_sobral@2
  1099
	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
leo_sobral@2
  1100
	break;
leo_sobral@2
  1101
      }
leo_sobral@2
  1102
#endif
rosfran@40
  1103
    case PROP_GMYTHTV_VERSION:
leo_sobral@2
  1104
      {
leo_sobral@2
  1105
	mythtvsrc->mythtv_version = g_value_get_int (value);
leo_sobral@2
  1106
	break;
leo_sobral@2
  1107
      }
rosfran@40
  1108
    case PROP_GMYTHTV_LIVEID:
leo_sobral@2
  1109
      {
leo_sobral@2
  1110
	mythtvsrc->live_tv_id = g_value_get_int (value);
leo_sobral@2
  1111
	break;
leo_sobral@2
  1112
      }
rosfran@40
  1113
    case PROP_GMYTHTV_LIVE:
leo_sobral@2
  1114
      {
leo_sobral@2
  1115
	mythtvsrc->live_tv = g_value_get_boolean (value);
leo_sobral@2
  1116
	break;
leo_sobral@2
  1117
      }
rosfran@52
  1118
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@52
  1119
      {
rosfran@52
  1120
	mythtvsrc->enable_timing_position = g_value_get_boolean (value);
rosfran@52
  1121
	break;
rosfran@52
  1122
      }      
rosfran@40
  1123
    case PROP_GMYTHTV_LIVE_CHAINID:
leo_sobral@2
  1124
      {
leo_sobral@2
  1125
	if (!g_value_get_string (value)) {
leo_sobral@2
  1126
	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
leo_sobral@2
  1127
	  goto done;
leo_sobral@2
  1128
	}
leo_sobral@2
  1129
leo_sobral@2
  1130
	if (mythtvsrc->live_chain_id != NULL) {
leo_sobral@2
  1131
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
  1132
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
  1133
	}
leo_sobral@2
  1134
	mythtvsrc->live_chain_id = g_value_dup_string (value);
leo_sobral@2
  1135
	break;
leo_sobral@2
  1136
      }
leo_sobral@2
  1137
leo_sobral@2
  1138
    default:
leo_sobral@2
  1139
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1140
      break;
leo_sobral@2
  1141
  }
leo_sobral@2
  1142
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1143
done:
leo_sobral@2
  1144
  return;
leo_sobral@2
  1145
}
leo_sobral@2
  1146
leo_sobral@2
  1147
  static void
leo_sobral@2
  1148
gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
  1149
    GValue * value, GParamSpec * pspec)
leo_sobral@2
  1150
{
leo_sobral@2
  1151
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1152
leo_sobral@2
  1153
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1154
  switch (prop_id) {
leo_sobral@2
  1155
    case PROP_URI:
leo_sobral@2
  1156
    case PROP_LOCATION:
leo_sobral@2
  1157
      {
leo_sobral@2
  1158
	gchar *str = g_strdup( "" );
leo_sobral@2
  1159
leo_sobral@2
  1160
	if ( mythtvsrc->uri_name == NULL ) {
leo_sobral@2
  1161
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
  1162
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
  1163
	} else {
leo_sobral@2
  1164
	  str = g_strdup( mythtvsrc->uri_name );
leo_sobral@2
  1165
	}
leo_sobral@2
  1166
	g_value_set_string ( value, str );
leo_sobral@2
  1167
	break;
leo_sobral@2
  1168
      }
leo_sobral@2
  1169
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1170
    case PROP_GMYTHTV_DBG:
leo_sobral@2
  1171
      g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
leo_sobral@2
  1172
      break;
leo_sobral@2
  1173
#endif
rosfran@40
  1174
    case PROP_GMYTHTV_VERSION:
leo_sobral@2
  1175
      {
leo_sobral@2
  1176
	g_value_set_int ( value, mythtvsrc->mythtv_version );
leo_sobral@2
  1177
	break;
leo_sobral@2
  1178
      }
rosfran@40
  1179
    case PROP_GMYTHTV_LIVEID:
leo_sobral@2
  1180
      {
leo_sobral@2
  1181
	g_value_set_int ( value, mythtvsrc->live_tv_id );
leo_sobral@2
  1182
	break;
leo_sobral@2
  1183
      }
rosfran@40
  1184
    case PROP_GMYTHTV_LIVE:
leo_sobral@2
  1185
      g_value_set_boolean ( value, mythtvsrc->live_tv );
leo_sobral@2
  1186
      break;
rosfran@52
  1187
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@52
  1188
      g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
rosfran@52
  1189
      break;
rosfran@40
  1190
    case PROP_GMYTHTV_LIVE_CHAINID:
leo_sobral@2
  1191
      {
leo_sobral@2
  1192
	gchar *str = g_strdup( "" );
leo_sobral@2
  1193
leo_sobral@2
  1194
	if ( mythtvsrc->live_chain_id == NULL ) {
leo_sobral@2
  1195
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
  1196
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
  1197
	} else {
leo_sobral@2
  1198
	  str = g_strdup( mythtvsrc->live_chain_id );
leo_sobral@2
  1199
	}
leo_sobral@2
  1200
	g_value_set_string ( value, str );
leo_sobral@2
  1201
	break;
leo_sobral@2
  1202
      }
leo_sobral@2
  1203
    default:
leo_sobral@2
  1204
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1205
      break;
leo_sobral@2
  1206
  }
leo_sobral@2
  1207
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1208
}
leo_sobral@2
  1209
leo_sobral@2
  1210
/* entry point to initialize the plug-in
leo_sobral@2
  1211
 * initialize the plug-in itself
leo_sobral@2
  1212
 * register the element factories and pad templates
leo_sobral@2
  1213
 * register the features
leo_sobral@2
  1214
 */
rosfran@40
  1215
static gboolean
leo_sobral@2
  1216
plugin_init (GstPlugin * plugin)
leo_sobral@2
  1217
{
leo_sobral@2
  1218
  return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
leo_sobral@2
  1219
      GST_TYPE_MYTHTV_SRC);
leo_sobral@2
  1220
}
leo_sobral@2
  1221
leo_sobral@2
  1222
/* this is the structure that gst-register looks for
leo_sobral@2
  1223
 * so keep the name plugin_desc, or you cannot get your plug-in registered */
leo_sobral@2
  1224
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
leo_sobral@2
  1225
    GST_VERSION_MINOR,
leo_sobral@2
  1226
    "mythtv",
leo_sobral@2
  1227
    "lib MythTV src",
leo_sobral@2
  1228
    plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
leo_sobral@2
  1229
leo_sobral@2
  1230
leo_sobral@2
  1231
/*** GSTURIHANDLER INTERFACE *************************************************/
leo_sobral@2
  1232
  static guint 
leo_sobral@2
  1233
gst_mythtv_src_uri_get_type (void)
leo_sobral@2
  1234
{
leo_sobral@2
  1235
  return GST_URI_SRC;
leo_sobral@2
  1236
}
leo_sobral@2
  1237
leo_sobral@2
  1238
  static gchar **
leo_sobral@2
  1239
gst_mythtv_src_uri_get_protocols (void)
leo_sobral@2
  1240
{
leo_sobral@2
  1241
  static gchar *protocols[] = { "myth", "myths", NULL };
leo_sobral@2
  1242
leo_sobral@2
  1243
  return protocols;
leo_sobral@2
  1244
}
leo_sobral@2
  1245
leo_sobral@2
  1246
  static const gchar *
leo_sobral@2
  1247
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
leo_sobral@2
  1248
{
leo_sobral@2
  1249
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1250
leo_sobral@2
  1251
  return src->uri_name;
leo_sobral@2
  1252
}
leo_sobral@2
  1253
leo_sobral@2
  1254
  static gboolean
leo_sobral@2
  1255
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
leo_sobral@2
  1256
{
leo_sobral@2
  1257
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1258
leo_sobral@2
  1259
  gchar *protocol;
leo_sobral@2
  1260
leo_sobral@2
  1261
  protocol = gst_uri_get_protocol (uri);
leo_sobral@2
  1262
  if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
leo_sobral@2
  1263
    g_free (protocol);
leo_sobral@2
  1264
    return FALSE;
leo_sobral@2
  1265
  }
leo_sobral@2
  1266
  g_free (protocol);
leo_sobral@2
  1267
  g_object_set (src, "location", uri, NULL);
leo_sobral@2
  1268
leo_sobral@2
  1269
  return TRUE;
leo_sobral@2
  1270
}
leo_sobral@2
  1271
leo_sobral@2
  1272
  static void
leo_sobral@2
  1273
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
leo_sobral@2
  1274
{
leo_sobral@2
  1275
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
leo_sobral@2
  1276
leo_sobral@2
  1277
  iface->get_type = gst_mythtv_src_uri_get_type;
leo_sobral@2
  1278
  iface->get_protocols = gst_mythtv_src_uri_get_protocols;
leo_sobral@2
  1279
  iface->get_uri = gst_mythtv_src_uri_get_uri;
leo_sobral@2
  1280
  iface->set_uri = gst_mythtv_src_uri_set_uri;
leo_sobral@2
  1281
}
leo_sobral@2
  1282
leo_sobral@2
  1283
  void
leo_sobral@2
  1284
size_header_handler (void *userdata, const char *value)
leo_sobral@2
  1285
{
leo_sobral@2
  1286
  GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
leo_sobral@2
  1287
leo_sobral@2
  1288
  //src->content_size = g_ascii_strtoull (value, NULL, 10);
leo_sobral@2
  1289
leo_sobral@2
  1290
  GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
leo_sobral@2
  1291
}