mythtv_plugin/gstmythtvsrc.c
author leo_sobral
Wed Sep 20 23:59:48 2006 +0100 (2006-09-20)
branchtrunk
changeset 2 bd3829c2e9c9
permissions -rwxr-xr-x
[svn r3] imported to sf repository
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
leo_sobral@2
     6
 * modify it under the terms of the GNU Library General Public
leo_sobral@2
     7
 * 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"
leo_sobral@2
    21
#include "myth_file_transfer.h"
leo_sobral@2
    22
#include "myth_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
leo_sobral@2
    33
#define GST_MYTHTV_ID_NUM		1
leo_sobral@2
    34
leo_sobral@2
    35
#define MYTHTV_VERSION_DEFAULT		30
leo_sobral@2
    36
leo_sobral@2
    37
#define MYTHTV_TRANSFER_MAX_WAITS	100
leo_sobral@2
    38
leo_sobral@2
    39
#define MYTHTV_TRANSFER_MAX_BUFFER	( 32*1024  )
leo_sobral@2
    40
leo_sobral@2
    41
/* 4*1024 ??? */
leo_sobral@2
    42
#define MAX_READ_SIZE                   ( 32*1024 )
leo_sobral@2
    43
leo_sobral@2
    44
#define ENABLE_TIMING_POSITION		1
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 =
leo_sobral@2
    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",
leo_sobral@2
    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,
leo_sobral@2
    58
    GST_STATIC_CAPS_ANY);
leo_sobral@2
    59
leo_sobral@2
    60
enum
leo_sobral@2
    61
{
leo_sobral@2
    62
  PROP_0,
leo_sobral@2
    63
  PROP_LOCATION,
leo_sobral@2
    64
  PROP_URI,
leo_sobral@2
    65
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
    66
  PROP_MYTHTV_DBG,
leo_sobral@2
    67
#endif
leo_sobral@2
    68
  PROP_MYTHTV_VERSION,
leo_sobral@2
    69
  PROP_MYTHTV_LIVE,
leo_sobral@2
    70
  PROP_MYTHTV_LIVEID,
leo_sobral@2
    71
  PROP_MYTHTV_LIVE_CHAINID
leo_sobral@2
    72
};
leo_sobral@2
    73
leo_sobral@2
    74
static void gst_mythtv_src_finalize (GObject * gobject);
leo_sobral@2
    75
leo_sobral@2
    76
static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc,
leo_sobral@2
    77
    guint64 offset, guint size, GstBuffer ** outbuf);
leo_sobral@2
    78
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
leo_sobral@2
    79
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
leo_sobral@2
    80
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
leo_sobral@2
    81
static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *base_src );
leo_sobral@2
    82
leo_sobral@2
    83
static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
    84
    const GValue * value, GParamSpec * pspec);
leo_sobral@2
    85
static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
    86
    GValue * value, GParamSpec * pspec);
leo_sobral@2
    87
leo_sobral@2
    88
static void
leo_sobral@2
    89
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
leo_sobral@2
    90
leo_sobral@2
    91
static gboolean
leo_sobral@2
    92
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
leo_sobral@2
    93
leo_sobral@2
    94
  static void
leo_sobral@2
    95
_urihandler_init (GType type)
leo_sobral@2
    96
{
leo_sobral@2
    97
  static const GInterfaceInfo urihandler_info = {
leo_sobral@2
    98
    gst_mythtv_src_uri_handler_init,
leo_sobral@2
    99
    NULL,
leo_sobral@2
   100
    NULL
leo_sobral@2
   101
  };
leo_sobral@2
   102
leo_sobral@2
   103
  g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
leo_sobral@2
   104
leo_sobral@2
   105
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   106
      "MythTV src");
leo_sobral@2
   107
}
leo_sobral@2
   108
leo_sobral@2
   109
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
leo_sobral@2
   110
    GST_TYPE_BASE_SRC, _urihandler_init);
leo_sobral@2
   111
leo_sobral@2
   112
  static void
leo_sobral@2
   113
gst_mythtv_src_base_init (gpointer g_class)
leo_sobral@2
   114
{
leo_sobral@2
   115
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
leo_sobral@2
   116
leo_sobral@2
   117
  gst_element_class_add_pad_template (element_class,
leo_sobral@2
   118
      gst_static_pad_template_get (&srctemplate));
leo_sobral@2
   119
leo_sobral@2
   120
  gst_element_class_set_details (element_class, &gst_mythtv_src_details);
leo_sobral@2
   121
}
leo_sobral@2
   122
leo_sobral@2
   123
  static void
leo_sobral@2
   124
gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
leo_sobral@2
   125
{
leo_sobral@2
   126
  GObjectClass *gobject_class;
leo_sobral@2
   127
  GstBaseSrcClass *gstbasesrc_class;
leo_sobral@2
   128
leo_sobral@2
   129
  gobject_class = (GObjectClass *) klass;
leo_sobral@2
   130
  gstbasesrc_class = (GstBaseSrcClass *) klass;
leo_sobral@2
   131
leo_sobral@2
   132
  gobject_class->set_property = gst_mythtv_src_set_property;
leo_sobral@2
   133
  gobject_class->get_property = gst_mythtv_src_get_property;
leo_sobral@2
   134
  gobject_class->finalize = gst_mythtv_src_finalize;
leo_sobral@2
   135
leo_sobral@2
   136
  g_object_class_install_property
leo_sobral@2
   137
    (gobject_class, PROP_LOCATION,
leo_sobral@2
   138
     g_param_spec_string ("location", "Location",
leo_sobral@2
   139
       "The location. In the form:"
leo_sobral@2
   140
       "\n\t\t\tmyth://a.com/file.nuv"
leo_sobral@2
   141
       "\n\t\t\tmyth://a.com:23223/file.nuv "
leo_sobral@2
   142
       "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
leo_sobral@2
   143
       "", G_PARAM_READWRITE));
leo_sobral@2
   144
leo_sobral@2
   145
  g_object_class_install_property
leo_sobral@2
   146
    (gobject_class, PROP_URI,
leo_sobral@2
   147
     g_param_spec_string ("uri", "Uri",
leo_sobral@2
   148
       "The location in form of a URI (deprecated; use location)",
leo_sobral@2
   149
       "", G_PARAM_READWRITE));
leo_sobral@2
   150
leo_sobral@2
   151
  g_object_class_install_property
leo_sobral@2
   152
    (gobject_class, PROP_MYTHTV_VERSION,
leo_sobral@2
   153
     g_param_spec_int ("mythtv-version", "mythtv-version",
leo_sobral@2
   154
       "Change Myth TV version",
leo_sobral@2
   155
       26, 30, 26, G_PARAM_READWRITE));
leo_sobral@2
   156
leo_sobral@2
   157
  g_object_class_install_property
leo_sobral@2
   158
    (gobject_class, PROP_MYTHTV_LIVEID,
leo_sobral@2
   159
     g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
leo_sobral@2
   160
       "Change Myth TV version",
leo_sobral@2
   161
       0, 200, GST_MYTHTV_ID_NUM, G_PARAM_READWRITE));
leo_sobral@2
   162
leo_sobral@2
   163
  g_object_class_install_property
leo_sobral@2
   164
    (gobject_class, PROP_MYTHTV_LIVE_CHAINID,
leo_sobral@2
   165
     g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
leo_sobral@2
   166
       "Sets the Myth TV chain ID (from TV Chain)",
leo_sobral@2
   167
       "", G_PARAM_READWRITE));
leo_sobral@2
   168
leo_sobral@2
   169
  g_object_class_install_property
leo_sobral@2
   170
    (gobject_class, PROP_MYTHTV_LIVE,
leo_sobral@2
   171
     g_param_spec_boolean ("mythtv-live", "mythtv-live",
leo_sobral@2
   172
       "Enable MythTV Live TV content streaming",
leo_sobral@2
   173
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   174
leo_sobral@2
   175
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   176
  g_object_class_install_property
leo_sobral@2
   177
    (gobject_class, PROP_MYTHTV_DBG,
leo_sobral@2
   178
     g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
leo_sobral@2
   179
       "Enable MythTV debug messages",
leo_sobral@2
   180
       FALSE, G_PARAM_READWRITE));
leo_sobral@2
   181
#endif
leo_sobral@2
   182
leo_sobral@2
   183
  gstbasesrc_class->start = gst_mythtv_src_start;
leo_sobral@2
   184
  gstbasesrc_class->stop = gst_mythtv_src_stop;
leo_sobral@2
   185
  gstbasesrc_class->get_size = gst_mythtv_src_get_size;
leo_sobral@2
   186
  gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
leo_sobral@2
   187
leo_sobral@2
   188
  gstbasesrc_class->create = gst_mythtv_src_create;
leo_sobral@2
   189
leo_sobral@2
   190
leo_sobral@2
   191
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   192
      "MythTV Client Source");
leo_sobral@2
   193
}
leo_sobral@2
   194
leo_sobral@2
   195
  static void
leo_sobral@2
   196
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
leo_sobral@2
   197
{
leo_sobral@2
   198
  this->file_transfer = NULL;
leo_sobral@2
   199
leo_sobral@2
   200
  this->unique_setup = FALSE;
leo_sobral@2
   201
leo_sobral@2
   202
  this->mythtv_version = MYTHTV_VERSION_DEFAULT;
leo_sobral@2
   203
leo_sobral@2
   204
  this->bytes_read = 0;
leo_sobral@2
   205
leo_sobral@2
   206
  this->content_size = -1;
leo_sobral@2
   207
  this->read_offset = 0;
leo_sobral@2
   208
leo_sobral@2
   209
  this->live_tv = FALSE;
leo_sobral@2
   210
leo_sobral@2
   211
  this->user_agent = g_strdup ("mythtvsrc");
leo_sobral@2
   212
  this->mythtv_caps = NULL;    
leo_sobral@2
   213
leo_sobral@2
   214
  gst_pad_set_event_function (GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
leo_sobral@2
   215
      GST_DEBUG_FUNCPTR (gst_mythtv_src_handle_event));
leo_sobral@2
   216
leo_sobral@2
   217
}
leo_sobral@2
   218
leo_sobral@2
   219
  static void
leo_sobral@2
   220
gst_mythtv_src_finalize (GObject * gobject)
leo_sobral@2
   221
{
leo_sobral@2
   222
  GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
leo_sobral@2
   223
leo_sobral@2
   224
  g_free (this->user_agent);
leo_sobral@2
   225
leo_sobral@2
   226
  if (this->mythtv_caps) {
leo_sobral@2
   227
    gst_caps_unref (this->mythtv_caps);
leo_sobral@2
   228
    this->mythtv_caps = NULL;
leo_sobral@2
   229
  }
leo_sobral@2
   230
leo_sobral@2
   231
  if (this->file_transfer) {
leo_sobral@2
   232
    g_object_unref (this->file_transfer);
leo_sobral@2
   233
    this->file_transfer = NULL;
leo_sobral@2
   234
  }
leo_sobral@2
   235
leo_sobral@2
   236
  if (this->uri_name) {
leo_sobral@2
   237
    g_free (this->uri_name);
leo_sobral@2
   238
  }
leo_sobral@2
   239
leo_sobral@2
   240
  if (this->user_agent) {
leo_sobral@2
   241
    g_free (this->user_agent);
leo_sobral@2
   242
  }
leo_sobral@2
   243
leo_sobral@2
   244
  G_OBJECT_CLASS (parent_class)->finalize (gobject);
leo_sobral@2
   245
}
leo_sobral@2
   246
leo_sobral@2
   247
#if 0
leo_sobral@2
   248
  static guint
leo_sobral@2
   249
do_seek( GstMythtvSrc *src, guint64 offset, guint size, GstBuffer *outbuf )
leo_sobral@2
   250
{
leo_sobral@2
   251
  guint64 off_uint64 = myth_file_transfer_seek(src->file_transfer, offset, 1);
leo_sobral@2
   252
leo_sobral@2
   253
  g_print( "[%s] Call MythTV SEEK with offset %llu, got a new one %llu...\n", __FUNCTION__, 
leo_sobral@2
   254
      offset, off_uint64 );
leo_sobral@2
   255
leo_sobral@2
   256
  return off_uint64;
leo_sobral@2
   257
leo_sobral@2
   258
}
leo_sobral@2
   259
#endif
leo_sobral@2
   260
leo_sobral@2
   261
  static guint
leo_sobral@2
   262
do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer * outbuf)
leo_sobral@2
   263
{
leo_sobral@2
   264
  guint read = 0;
leo_sobral@2
   265
  guint sizetoread = size; //GST_BUFFER_SIZE (outbuf);
leo_sobral@2
   266
leo_sobral@2
   267
  g_print( "[%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
leo_sobral@2
   268
leo_sobral@2
   269
  /* Loop sending the request:
leo_sobral@2
   270
   * Retry whilst authentication fails and we supply it. */
leo_sobral@2
   271
leo_sobral@2
   272
  ssize_t len = 0;
leo_sobral@2
   273
leo_sobral@2
   274
  GST_OBJECT_LOCK(src);
leo_sobral@2
   275
leo_sobral@2
   276
  while ( sizetoread > 0 ) {
leo_sobral@2
   277
leo_sobral@2
   278
    len = myth_file_transfer_read( src->file_transfer,
leo_sobral@2
   279
	GST_BUFFER_DATA (outbuf) + read, sizetoread, TRUE );
leo_sobral@2
   280
leo_sobral@2
   281
    if ( len > 0 ) {
leo_sobral@2
   282
      read += len;
leo_sobral@2
   283
      src->read_offset += read;
leo_sobral@2
   284
      sizetoread -= len;
leo_sobral@2
   285
    } else if ( len < 0 ) {
leo_sobral@2
   286
      goto done;
leo_sobral@2
   287
    }
leo_sobral@2
   288
    /*else if ( len == 0 ) {
leo_sobral@2
   289
      goto eos;
leo_sobral@2
   290
    }*/
leo_sobral@2
   291
leo_sobral@2
   292
    if ( len == sizetoread )
leo_sobral@2
   293
      break;
leo_sobral@2
   294
leo_sobral@2
   295
  }
leo_sobral@2
   296
leo_sobral@2
   297
  if ( read > 0 ) {
leo_sobral@2
   298
    src->bytes_read += read;
leo_sobral@2
   299
leo_sobral@2
   300
    GST_BUFFER_SIZE (outbuf) = read;
leo_sobral@2
   301
  } else if ( read <= 0 || len <= 0 ) {
leo_sobral@2
   302
    if ( src->live_tv == FALSE )
leo_sobral@2
   303
      goto eos;
leo_sobral@2
   304
    else
leo_sobral@2
   305
      goto done;
leo_sobral@2
   306
  }
leo_sobral@2
   307
  //GST_BUFFER_OFFSET (outbuf) = src->read_offset;
leo_sobral@2
   308
leo_sobral@2
   309
  g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
leo_sobral@2
   310
      "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
leo_sobral@2
   311
      src->read_offset, src->content_size );
leo_sobral@2
   312
leo_sobral@2
   313
  GST_OBJECT_UNLOCK(src);
leo_sobral@2
   314
leo_sobral@2
   315
  if ( len < 0 ) {
leo_sobral@2
   316
    read = len;
leo_sobral@2
   317
    if ( src->live_tv == FALSE ) 
leo_sobral@2
   318
      goto eos;
leo_sobral@2
   319
    else
leo_sobral@2
   320
      goto done;
leo_sobral@2
   321
  }
leo_sobral@2
   322
leo_sobral@2
   323
  if ( src->bytes_read < src->content_size )
leo_sobral@2
   324
    goto done;
leo_sobral@2
   325
leo_sobral@2
   326
eos:
leo_sobral@2
   327
  GST_OBJECT_UNLOCK(src);
leo_sobral@2
   328
leo_sobral@2
   329
  src->eos = TRUE;
leo_sobral@2
   330
done:
leo_sobral@2
   331
  GST_OBJECT_UNLOCK(src);
leo_sobral@2
   332
leo_sobral@2
   333
  return read;
leo_sobral@2
   334
}
leo_sobral@2
   335
leo_sobral@2
   336
  static GstFlowReturn
leo_sobral@2
   337
gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, 
leo_sobral@2
   338
    guint size, GstBuffer **outbuf )
leo_sobral@2
   339
{
leo_sobral@2
   340
  GstMythtvSrc *src;
leo_sobral@2
   341
  GstFlowReturn ret = GST_FLOW_OK;
leo_sobral@2
   342
  guint read;
leo_sobral@2
   343
  guint64 size_tmp = 0;
leo_sobral@2
   344
leo_sobral@2
   345
  src = GST_MYTHTV_SRC (psrc);
leo_sobral@2
   346
leo_sobral@2
   347
  g_print( "[%s]\tBUFFER OFFSET = %llu, BUFFER SIZE = %d.\n", __FUNCTION__, offset, 
leo_sobral@2
   348
      size );
leo_sobral@2
   349
leo_sobral@2
   350
leo_sobral@2
   351
  /* The caller should know the number of bytes and not read beyond EOS. */
leo_sobral@2
   352
  if (G_UNLIKELY (src->eos))
leo_sobral@2
   353
    goto eos;
leo_sobral@2
   354
leo_sobral@2
   355
  /* Create the buffer. */
leo_sobral@2
   356
  ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
leo_sobral@2
   357
      //      GST_BUFFER_OFFSET_NONE, GST_BASE_SRC (psrc)->blocksize,
leo_sobral@2
   358
      offset, size,
leo_sobral@2
   359
      src->mythtv_caps ? src->mythtv_caps :
leo_sobral@2
   360
      GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
leo_sobral@2
   361
leo_sobral@2
   362
  if (G_UNLIKELY (ret == GST_FLOW_UNEXPECTED))
leo_sobral@2
   363
    goto eos;
leo_sobral@2
   364
leo_sobral@2
   365
  if (G_UNLIKELY (ret != GST_FLOW_OK))
leo_sobral@2
   366
    goto done;
leo_sobral@2
   367
leo_sobral@2
   368
  read = do_read_request_response ( src, offset, size, *outbuf );
leo_sobral@2
   369
leo_sobral@2
   370
#if ENABLE_TIMING_POSITION == 1
leo_sobral@2
   371
  if (src->live_tv == TRUE) {
leo_sobral@2
   372
    g_usleep( 1000 );
leo_sobral@2
   373
get_file_pos:
leo_sobral@2
   374
    g_usleep( 100 );
leo_sobral@2
   375
    size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
leo_sobral@2
   376
    if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
leo_sobral@2
   377
      src->content_size = size_tmp;
leo_sobral@2
   378
    else
leo_sobral@2
   379
      goto get_file_pos;
leo_sobral@2
   380
    g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", 
leo_sobral@2
   381
	__FUNCTION__, size_tmp);
leo_sobral@2
   382
leo_sobral@2
   383
  }
leo_sobral@2
   384
#endif
leo_sobral@2
   385
leo_sobral@2
   386
  if (G_UNLIKELY (read < 0))
leo_sobral@2
   387
    goto read_error;
leo_sobral@2
   388
leo_sobral@2
   389
  if (G_UNLIKELY(src->eos))
leo_sobral@2
   390
    goto eos;
leo_sobral@2
   391
leo_sobral@2
   392
done:
leo_sobral@2
   393
  return ret;
leo_sobral@2
   394
eos:
leo_sobral@2
   395
#if ENABLE_TIMING_POSITION == 1
leo_sobral@2
   396
  if (src->live_tv == TRUE) {
leo_sobral@2
   397
    g_usleep( 1000 );
leo_sobral@2
   398
    guint64 size_tmp = 0;
leo_sobral@2
   399
get_file_pos_eos:
leo_sobral@2
   400
    g_usleep( 100 );
leo_sobral@2
   401
    size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
leo_sobral@2
   402
    if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
leo_sobral@2
   403
      src->content_size = size_tmp;
leo_sobral@2
   404
    else
leo_sobral@2
   405
      goto get_file_pos_eos;
leo_sobral@2
   406
    g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", 
leo_sobral@2
   407
	__FUNCTION__, size_tmp);
leo_sobral@2
   408
    goto done;
leo_sobral@2
   409
  } else 
leo_sobral@2
   410
#endif
leo_sobral@2
   411
  {
leo_sobral@2
   412
    GST_DEBUG_OBJECT (src, "EOS reached");
leo_sobral@2
   413
    return GST_FLOW_UNEXPECTED;
leo_sobral@2
   414
  }
leo_sobral@2
   415
  /* ERRORS */
leo_sobral@2
   416
read_error:
leo_sobral@2
   417
  {
leo_sobral@2
   418
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
leo_sobral@2
   419
	(NULL), ("Could not read any bytes (%i, %s)", read,
leo_sobral@2
   420
	  src->uri_name));
leo_sobral@2
   421
    return GST_FLOW_ERROR;
leo_sobral@2
   422
  }
leo_sobral@2
   423
}
leo_sobral@2
   424
leo_sobral@2
   425
#if 0
leo_sobral@2
   426
/* The following two charset mangling functions were copied from gnomevfssrc.
leo_sobral@2
   427
 * Preserve them under the unverified assumption that they do something vaguely
leo_sobral@2
   428
 * worthwhile.
leo_sobral@2
   429
 */
leo_sobral@2
   430
  static char *
leo_sobral@2
   431
unicodify (const char *str, int len, ...)
leo_sobral@2
   432
{
leo_sobral@2
   433
  char *ret = NULL, *cset;
leo_sobral@2
   434
  va_list args;
leo_sobral@2
   435
  gsize bytes_read, bytes_written;
leo_sobral@2
   436
leo_sobral@2
   437
  if (g_utf8_validate (str, len, NULL))
leo_sobral@2
   438
    return g_strndup (str, len >= 0 ? len : strlen (str));
leo_sobral@2
   439
leo_sobral@2
   440
  va_start (args, len);
leo_sobral@2
   441
  while ((cset = va_arg (args, char *)) != NULL)
leo_sobral@2
   442
  {
leo_sobral@2
   443
    if (!strcmp (cset, "locale"))
leo_sobral@2
   444
      ret = g_locale_to_utf8 (str, len, &bytes_read, &bytes_written, NULL);
leo_sobral@2
   445
    else
leo_sobral@2
   446
      ret = g_convert (str, len, "UTF-8", cset,
leo_sobral@2
   447
	  &bytes_read, &bytes_written, NULL);
leo_sobral@2
   448
    if (ret)
leo_sobral@2
   449
      break;
leo_sobral@2
   450
  }
leo_sobral@2
   451
  va_end (args);
leo_sobral@2
   452
leo_sobral@2
   453
  return ret;
leo_sobral@2
   454
}
leo_sobral@2
   455
leo_sobral@2
   456
  static char *
leo_sobral@2
   457
gst_mythtv_src_unicodify (const char *str)
leo_sobral@2
   458
{
leo_sobral@2
   459
  return unicodify (str, -1, "locale", "ISO-8859-1", NULL);
leo_sobral@2
   460
}
leo_sobral@2
   461
#endif
leo_sobral@2
   462
leo_sobral@2
   463
/* create a socket for connecting to remote server */
leo_sobral@2
   464
  static gboolean
leo_sobral@2
   465
gst_mythtv_src_start ( GstBaseSrc * bsrc )
leo_sobral@2
   466
{
leo_sobral@2
   467
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   468
leo_sobral@2
   469
  GString *chain_id_local = NULL;
leo_sobral@2
   470
leo_sobral@2
   471
  gboolean ret = TRUE;
leo_sobral@2
   472
#if 0
leo_sobral@2
   473
  if (src->live_tv == TRUE && src->file_transfer != NULL) {
leo_sobral@2
   474
    guint64 size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
leo_sobral@2
   475
    if (size_tmp > src->content_size)
leo_sobral@2
   476
      src->content_size = size_tmp;
leo_sobral@2
   477
    g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", 
leo_sobral@2
   478
	__FUNCTION__, size_tmp);
leo_sobral@2
   479
  }
leo_sobral@2
   480
#endif
leo_sobral@2
   481
  if (src->unique_setup == FALSE) {
leo_sobral@2
   482
    src->unique_setup = TRUE;
leo_sobral@2
   483
  } else {
leo_sobral@2
   484
    goto done;
leo_sobral@2
   485
  }
leo_sobral@2
   486
leo_sobral@2
   487
  GST_OBJECT_LOCK(src);
leo_sobral@2
   488
leo_sobral@2
   489
  if ( src->live_tv ) {
leo_sobral@2
   490
    src->spawn_livetv = myth_livetv_new( );
leo_sobral@2
   491
    if ( myth_livetv_setup( src->spawn_livetv ) == FALSE ) {
leo_sobral@2
   492
    	ret = FALSE;
leo_sobral@2
   493
    	goto init_failed;
leo_sobral@2
   494
    }
leo_sobral@2
   495
    /* set up the uri variable */
leo_sobral@2
   496
    src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
leo_sobral@2
   497
    chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
leo_sobral@2
   498
    if ( chain_id_local != NULL ) {
leo_sobral@2
   499
      src->live_chain_id = g_strdup( chain_id_local->str );
leo_sobral@2
   500
      g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
leo_sobral@2
   501
    }
leo_sobral@2
   502
    src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
leo_sobral@2
   503
    g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
leo_sobral@2
   504
  }
leo_sobral@2
   505
leo_sobral@2
   506
  src->file_transfer = myth_file_transfer_new( src->live_tv_id, 
leo_sobral@2
   507
      g_string_new( src->uri_name ), -1, src->mythtv_version );
leo_sobral@2
   508
leo_sobral@2
   509
  if ( src->file_transfer == NULL ) {
leo_sobral@2
   510
    GST_OBJECT_UNLOCK(src);
leo_sobral@2
   511
leo_sobral@2
   512
    goto init_failed;
leo_sobral@2
   513
  }
leo_sobral@2
   514
leo_sobral@2
   515
  if ( src->live_tv ) {
leo_sobral@2
   516
    g_print ( "[%s] GST MYTHTVSRC: live_chain_id = %s\n", __FUNCTION__, src->live_chain_id );
leo_sobral@2
   517
    /* sets the MythSocket to the FileTransfer */
leo_sobral@2
   518
    //ret = myth_file_transfer_livetv_setup( &(src->file_transfer), src->spawn_livetv->remote_encoder->myth_socket );
leo_sobral@2
   519
  }
leo_sobral@2
   520
  /* sets the Playback monitor connection */
leo_sobral@2
   521
  ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   522
leo_sobral@2
   523
  if ( src->live_tv == TRUE && ret == TRUE ) {
leo_sobral@2
   524
    /* loop finished, set the max tries variable to zero again... */
leo_sobral@2
   525
    wait_to_transfer = 0;
leo_sobral@2
   526
leo_sobral@2
   527
    while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && ( myth_file_transfer_is_recording( src->file_transfer ) == FALSE 
leo_sobral@2
   528
	  /*|| ( myth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
leo_sobral@2
   529
      g_usleep( 100 );
leo_sobral@2
   530
  }
leo_sobral@2
   531
leo_sobral@2
   532
  /* sets the FileTransfer instance connection (video/audio download) */
leo_sobral@2
   533
  ret = myth_file_transfer_setup( &(src->file_transfer), src->live_tv );
leo_sobral@2
   534
leo_sobral@2
   535
  if ( ret == FALSE ) {
leo_sobral@2
   536
    GST_OBJECT_UNLOCK(src);
leo_sobral@2
   537
#ifndef GST_DISABLE_GST_DEBUG  
leo_sobral@2
   538
    if ( src->mythtv_msgs_dbg )
leo_sobral@2
   539
      g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
leo_sobral@2
   540
#endif
leo_sobral@2
   541
    goto begin_req_failed;
leo_sobral@2
   542
  }
leo_sobral@2
   543
leo_sobral@2
   544
  src->content_size = src->file_transfer->filesize;
leo_sobral@2
   545
leo_sobral@2
   546
  GST_OBJECT_UNLOCK(src);
leo_sobral@2
   547
leo_sobral@2
   548
#if 0
leo_sobral@2
   549
  const char *str_value;
leo_sobral@2
   550
  gint gint_value;
leo_sobral@2
   551
leo_sobral@2
   552
  str_value = ne_get_response_header (src->request, "myth-metaint");
leo_sobral@2
   553
  if (str_value) {
leo_sobral@2
   554
    if ( sscanf (str_value, "%d", &gint_value) == 1 ) {
leo_sobral@2
   555
      if (src->myth_caps) {
leo_sobral@2
   556
	gst_caps_unref (src->myth_caps);
leo_sobral@2
   557
	src->myth_caps = NULL;
leo_sobral@2
   558
      }
leo_sobral@2
   559
      src->myth_metaint = gint_value;
leo_sobral@2
   560
#endif
leo_sobral@2
   561
      //src->mythtv_caps = gst_caps_new_simple ("application/x-gst_ff-nuv", NULL);
leo_sobral@2
   562
      //   }
leo_sobral@2
   563
      // }
leo_sobral@2
   564
done:
leo_sobral@2
   565
      return TRUE;
leo_sobral@2
   566
leo_sobral@2
   567
      /* ERRORS */
leo_sobral@2
   568
init_failed:
leo_sobral@2
   569
      {
leo_sobral@2
   570
      	if (src->spawn_livetv != NULL )
leo_sobral@2
   571
	  g_object_unref( src->spawn_livetv );
leo_sobral@2
   572
leo_sobral@2
   573
	GST_ELEMENT_ERROR (src, LIBRARY, INIT,
leo_sobral@2
   574
	    (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
leo_sobral@2
   575
	return FALSE;
leo_sobral@2
   576
      }
leo_sobral@2
   577
begin_req_failed:
leo_sobral@2
   578
      {
leo_sobral@2
   579
	GST_ELEMENT_ERROR (src, LIBRARY, INIT,
leo_sobral@2
   580
	    (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
leo_sobral@2
   581
	return FALSE;
leo_sobral@2
   582
      }
leo_sobral@2
   583
}
leo_sobral@2
   584
leo_sobral@2
   585
  static gboolean
leo_sobral@2
   586
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
leo_sobral@2
   587
{
leo_sobral@2
   588
  GstMythtvSrc *src;
leo_sobral@2
   589
leo_sobral@2
   590
  src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   591
#if ENABLE_TIMING_POSITION == 1
leo_sobral@2
   592
  if (src->live_tv == TRUE) {
leo_sobral@2
   593
get_file_pos:
leo_sobral@2
   594
    g_usleep( 100 );
leo_sobral@2
   595
    guint64 size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
leo_sobral@2
   596
    if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
leo_sobral@2
   597
      src->content_size = size_tmp;
leo_sobral@2
   598
    else
leo_sobral@2
   599
      goto get_file_pos;
leo_sobral@2
   600
    g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", 
leo_sobral@2
   601
	__FUNCTION__, size_tmp);
leo_sobral@2
   602
  }
leo_sobral@2
   603
#endif
leo_sobral@2
   604
  if (src->content_size <= 0)
leo_sobral@2
   605
    return FALSE;
leo_sobral@2
   606
leo_sobral@2
   607
  *size = src->content_size;
leo_sobral@2
   608
leo_sobral@2
   609
  return TRUE;
leo_sobral@2
   610
}
leo_sobral@2
   611
leo_sobral@2
   612
/* close the socket and associated resources
leo_sobral@2
   613
 * used both to recover from errors and go to NULL state */
leo_sobral@2
   614
  static gboolean
leo_sobral@2
   615
gst_mythtv_src_stop (GstBaseSrc * bsrc)
leo_sobral@2
   616
{
leo_sobral@2
   617
  GstMythtvSrc *src;
leo_sobral@2
   618
leo_sobral@2
   619
  src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   620
leo_sobral@2
   621
  if (src->uri_name) {
leo_sobral@2
   622
    g_free (src->uri_name);
leo_sobral@2
   623
    src->uri_name = NULL;
leo_sobral@2
   624
  }
leo_sobral@2
   625
leo_sobral@2
   626
  if (src->mythtv_caps) {
leo_sobral@2
   627
    gst_caps_unref (src->mythtv_caps);
leo_sobral@2
   628
    src->mythtv_caps = NULL;
leo_sobral@2
   629
  }
leo_sobral@2
   630
leo_sobral@2
   631
  src->eos = FALSE;
leo_sobral@2
   632
leo_sobral@2
   633
  return TRUE;
leo_sobral@2
   634
}
leo_sobral@2
   635
leo_sobral@2
   636
  static gboolean
leo_sobral@2
   637
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
leo_sobral@2
   638
{
leo_sobral@2
   639
  GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
leo_sobral@2
   640
leo_sobral@2
   641
  switch (GST_EVENT_TYPE (event)) {
leo_sobral@2
   642
    case GST_EVENT_FLUSH_START:
leo_sobral@2
   643
      src->eos = FALSE;
leo_sobral@2
   644
      break;
leo_sobral@2
   645
      //return TRUE;
leo_sobral@2
   646
    case GST_EVENT_FLUSH_STOP:
leo_sobral@2
   647
      src->do_start = TRUE;
leo_sobral@2
   648
      src->eos = FALSE;
leo_sobral@2
   649
      gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
leo_sobral@2
   650
      gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
leo_sobral@2
   651
      break;
leo_sobral@2
   652
    case GST_EVENT_SEEK:  	  
leo_sobral@2
   653
      {
leo_sobral@2
   654
	gdouble rate;
leo_sobral@2
   655
	//gboolean update = TRUE;
leo_sobral@2
   656
	GstFormat format;
leo_sobral@2
   657
	GstSeekType cur_type, stop_type;
leo_sobral@2
   658
	GstSeekFlags flags;
leo_sobral@2
   659
	gint64 cur = 0, stop = 0;
leo_sobral@2
   660
	gst_event_parse_seek ( event, &rate, &format,
leo_sobral@2
   661
	    &flags, &cur_type, &cur,
leo_sobral@2
   662
	    &stop_type, &stop );
leo_sobral@2
   663
leo_sobral@2
   664
	g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
leo_sobral@2
   665
	if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
leo_sobral@2
   666
	  g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
leo_sobral@2
   667
	}
leo_sobral@2
   668
	//gboolean ret = gst_event_parse_new_segment ( event,
leo_sobral@2
   669
	//    &update, &rate, &format, &start, &stop,
leo_sobral@2
   670
	//    &position );
leo_sobral@2
   671
	//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ), 
leo_sobral@2
   672
	//			cur, stop - cur + 1, GstBuffer)
leo_sobral@2
   673
leo_sobral@2
   674
      } 
leo_sobral@2
   675
    default:
leo_sobral@2
   676
      return gst_pad_event_default (pad, event);
leo_sobral@2
   677
  }
leo_sobral@2
   678
leo_sobral@2
   679
  return gst_pad_event_default (pad, event);
leo_sobral@2
   680
}
leo_sobral@2
   681
leo_sobral@2
   682
  static gboolean
leo_sobral@2
   683
gst_mythtv_src_is_seekable( GstBaseSrc *base_src )
leo_sobral@2
   684
{
leo_sobral@2
   685
  return TRUE;
leo_sobral@2
   686
}
leo_sobral@2
   687
leo_sobral@2
   688
  static void
leo_sobral@2
   689
gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
   690
    const GValue * value, GParamSpec * pspec)
leo_sobral@2
   691
{
leo_sobral@2
   692
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
   693
leo_sobral@2
   694
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
   695
  switch (prop_id) {
leo_sobral@2
   696
    case PROP_URI:
leo_sobral@2
   697
    case PROP_LOCATION:
leo_sobral@2
   698
      {
leo_sobral@2
   699
	if (!g_value_get_string (value)) {
leo_sobral@2
   700
	  GST_WARNING ("location property cannot be NULL");
leo_sobral@2
   701
	  goto done;
leo_sobral@2
   702
	}
leo_sobral@2
   703
leo_sobral@2
   704
	if (mythtvsrc->uri_name != NULL) {
leo_sobral@2
   705
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
   706
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
   707
	}
leo_sobral@2
   708
	mythtvsrc->uri_name = g_value_dup_string (value);
leo_sobral@2
   709
leo_sobral@2
   710
	break;
leo_sobral@2
   711
      }
leo_sobral@2
   712
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   713
    case PROP_MYTHTV_DBG:
leo_sobral@2
   714
      {
leo_sobral@2
   715
	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
leo_sobral@2
   716
	break;
leo_sobral@2
   717
      }
leo_sobral@2
   718
#endif
leo_sobral@2
   719
    case PROP_MYTHTV_VERSION:
leo_sobral@2
   720
      {
leo_sobral@2
   721
	mythtvsrc->mythtv_version = g_value_get_int (value);
leo_sobral@2
   722
	break;
leo_sobral@2
   723
      }
leo_sobral@2
   724
    case PROP_MYTHTV_LIVEID:
leo_sobral@2
   725
      {
leo_sobral@2
   726
	mythtvsrc->live_tv_id = g_value_get_int (value);
leo_sobral@2
   727
	break;
leo_sobral@2
   728
      }
leo_sobral@2
   729
    case PROP_MYTHTV_LIVE:
leo_sobral@2
   730
      {
leo_sobral@2
   731
	mythtvsrc->live_tv = g_value_get_boolean (value);
leo_sobral@2
   732
	break;
leo_sobral@2
   733
      }
leo_sobral@2
   734
    case PROP_MYTHTV_LIVE_CHAINID:
leo_sobral@2
   735
      {
leo_sobral@2
   736
	if (!g_value_get_string (value)) {
leo_sobral@2
   737
	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
leo_sobral@2
   738
	  goto done;
leo_sobral@2
   739
	}
leo_sobral@2
   740
leo_sobral@2
   741
	if (mythtvsrc->live_chain_id != NULL) {
leo_sobral@2
   742
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
   743
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
   744
	}
leo_sobral@2
   745
	mythtvsrc->live_chain_id = g_value_dup_string (value);
leo_sobral@2
   746
leo_sobral@2
   747
	break;
leo_sobral@2
   748
      }
leo_sobral@2
   749
leo_sobral@2
   750
    default:
leo_sobral@2
   751
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
   752
      break;
leo_sobral@2
   753
  }
leo_sobral@2
   754
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
   755
done:
leo_sobral@2
   756
  return;
leo_sobral@2
   757
}
leo_sobral@2
   758
leo_sobral@2
   759
  static void
leo_sobral@2
   760
gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
   761
    GValue * value, GParamSpec * pspec)
leo_sobral@2
   762
{
leo_sobral@2
   763
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
   764
leo_sobral@2
   765
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
   766
  switch (prop_id) {
leo_sobral@2
   767
    case PROP_URI:
leo_sobral@2
   768
    case PROP_LOCATION:
leo_sobral@2
   769
      {
leo_sobral@2
   770
	gchar *str = g_strdup( "" );
leo_sobral@2
   771
leo_sobral@2
   772
	if ( mythtvsrc->uri_name == NULL ) {
leo_sobral@2
   773
	  g_free (mythtvsrc->uri_name);
leo_sobral@2
   774
	  mythtvsrc->uri_name = NULL;
leo_sobral@2
   775
	} else {
leo_sobral@2
   776
	  str = g_strdup( mythtvsrc->uri_name );
leo_sobral@2
   777
	}
leo_sobral@2
   778
	g_value_set_string ( value, str );
leo_sobral@2
   779
	break;
leo_sobral@2
   780
      }
leo_sobral@2
   781
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   782
    case PROP_MYTHTV_DBG:
leo_sobral@2
   783
      g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
leo_sobral@2
   784
      break;
leo_sobral@2
   785
#endif
leo_sobral@2
   786
    case PROP_MYTHTV_VERSION:
leo_sobral@2
   787
      {
leo_sobral@2
   788
	g_value_set_int ( value, mythtvsrc->mythtv_version );
leo_sobral@2
   789
	break;
leo_sobral@2
   790
      }
leo_sobral@2
   791
    case PROP_MYTHTV_LIVEID:
leo_sobral@2
   792
      {
leo_sobral@2
   793
	g_value_set_int ( value, mythtvsrc->live_tv_id );
leo_sobral@2
   794
	break;
leo_sobral@2
   795
      }
leo_sobral@2
   796
    case PROP_MYTHTV_LIVE:
leo_sobral@2
   797
      g_value_set_boolean ( value, mythtvsrc->live_tv );
leo_sobral@2
   798
      break;
leo_sobral@2
   799
    case PROP_MYTHTV_LIVE_CHAINID:
leo_sobral@2
   800
      {
leo_sobral@2
   801
	gchar *str = g_strdup( "" );
leo_sobral@2
   802
leo_sobral@2
   803
	if ( mythtvsrc->live_chain_id == NULL ) {
leo_sobral@2
   804
	  g_free (mythtvsrc->live_chain_id);
leo_sobral@2
   805
	  mythtvsrc->live_chain_id = NULL;
leo_sobral@2
   806
	} else {
leo_sobral@2
   807
	  str = g_strdup( mythtvsrc->live_chain_id );
leo_sobral@2
   808
	}
leo_sobral@2
   809
	g_value_set_string ( value, str );
leo_sobral@2
   810
	break;
leo_sobral@2
   811
      }
leo_sobral@2
   812
    default:
leo_sobral@2
   813
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
   814
      break;
leo_sobral@2
   815
  }
leo_sobral@2
   816
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
   817
}
leo_sobral@2
   818
leo_sobral@2
   819
/* entry point to initialize the plug-in
leo_sobral@2
   820
 * initialize the plug-in itself
leo_sobral@2
   821
 * register the element factories and pad templates
leo_sobral@2
   822
 * register the features
leo_sobral@2
   823
 */
leo_sobral@2
   824
  static gboolean
leo_sobral@2
   825
plugin_init (GstPlugin * plugin)
leo_sobral@2
   826
{
leo_sobral@2
   827
  return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
leo_sobral@2
   828
      GST_TYPE_MYTHTV_SRC);
leo_sobral@2
   829
}
leo_sobral@2
   830
leo_sobral@2
   831
/* this is the structure that gst-register looks for
leo_sobral@2
   832
 * so keep the name plugin_desc, or you cannot get your plug-in registered */
leo_sobral@2
   833
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
leo_sobral@2
   834
    GST_VERSION_MINOR,
leo_sobral@2
   835
    "mythtv",
leo_sobral@2
   836
    "lib MythTV src",
leo_sobral@2
   837
    plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
leo_sobral@2
   838
leo_sobral@2
   839
leo_sobral@2
   840
/*** GSTURIHANDLER INTERFACE *************************************************/
leo_sobral@2
   841
  static guint 
leo_sobral@2
   842
gst_mythtv_src_uri_get_type (void)
leo_sobral@2
   843
{
leo_sobral@2
   844
  return GST_URI_SRC;
leo_sobral@2
   845
}
leo_sobral@2
   846
leo_sobral@2
   847
  static gchar **
leo_sobral@2
   848
gst_mythtv_src_uri_get_protocols (void)
leo_sobral@2
   849
{
leo_sobral@2
   850
  static gchar *protocols[] = { "myth", "myths", NULL };
leo_sobral@2
   851
leo_sobral@2
   852
  return protocols;
leo_sobral@2
   853
}
leo_sobral@2
   854
leo_sobral@2
   855
  static const gchar *
leo_sobral@2
   856
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
leo_sobral@2
   857
{
leo_sobral@2
   858
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
   859
leo_sobral@2
   860
  return src->uri_name;
leo_sobral@2
   861
}
leo_sobral@2
   862
leo_sobral@2
   863
  static gboolean
leo_sobral@2
   864
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
leo_sobral@2
   865
{
leo_sobral@2
   866
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
   867
leo_sobral@2
   868
  gchar *protocol;
leo_sobral@2
   869
leo_sobral@2
   870
  protocol = gst_uri_get_protocol (uri);
leo_sobral@2
   871
  if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
leo_sobral@2
   872
    g_free (protocol);
leo_sobral@2
   873
    return FALSE;
leo_sobral@2
   874
  }
leo_sobral@2
   875
  g_free (protocol);
leo_sobral@2
   876
  g_object_set (src, "location", uri, NULL);
leo_sobral@2
   877
leo_sobral@2
   878
  return TRUE;
leo_sobral@2
   879
}
leo_sobral@2
   880
leo_sobral@2
   881
  static void
leo_sobral@2
   882
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
leo_sobral@2
   883
{
leo_sobral@2
   884
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
leo_sobral@2
   885
leo_sobral@2
   886
  iface->get_type = gst_mythtv_src_uri_get_type;
leo_sobral@2
   887
  iface->get_protocols = gst_mythtv_src_uri_get_protocols;
leo_sobral@2
   888
  iface->get_uri = gst_mythtv_src_uri_get_uri;
leo_sobral@2
   889
  iface->set_uri = gst_mythtv_src_uri_set_uri;
leo_sobral@2
   890
}
leo_sobral@2
   891
leo_sobral@2
   892
  void
leo_sobral@2
   893
size_header_handler (void *userdata, const char *value)
leo_sobral@2
   894
{
leo_sobral@2
   895
  GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
leo_sobral@2
   896
leo_sobral@2
   897
  //src->content_size = g_ascii_strtoull (value, NULL, 10);
leo_sobral@2
   898
leo_sobral@2
   899
  GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
leo_sobral@2
   900
}