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