gst-plugins-mythtv/src/gstmythtvsrc.c
author melunko
Fri Apr 20 20:29:46 2007 +0100 (2007-04-20)
branchtrunk
changeset 582 27872a83abaa
parent 559 994917e6cadf
permissions -rwxr-xr-x
[svn r587] Added README for gmyth/samples
leo_sobral@2
     1
/* GStreamer MythTV Plug-in
leo_sobral@2
     2
 * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
leo_sobral@2
     3
 *
leo_sobral@2
     4
 * This library is free software; you can redistribute it and/or
rosfran@289
     5
 * modify it under the terms of the GNU Library General Public
rosfran@289
     6
 * License as published by the Free Software Foundation; either
leo_sobral@2
     7
 * version 2 of the License, or (at your option) any later version.
leo_sobral@2
     8
 *
leo_sobral@2
     9
 * This library is distributed in the hope that it will be useful,
leo_sobral@2
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
leo_sobral@2
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rosfran@289
    12
 * Library General Public License for more details.
rosfran@289
    13
 *
rosfran@289
    14
 * You should have received a copy of the GNU Library General Public
rosfran@289
    15
 * License along with this library; if not, write to the
rosfran@289
    16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rosfran@289
    17
 * Boston, MA 02111-1307, USA.
leo_sobral@2
    18
 */
rosfran@289
    19
/**
rosfran@559
    20
 * SECTION:element-mythtvsrc
rosfran@559
    21
 *
rosfran@559
    22
 * <refsect2>
rosfran@559
    23
 * <para>
rosfran@559
    24
 * MythTVSrc allows to access a remote MythTV backend streaming Video/Audio server,
rosfran@559
    25
 * and to render audio and video content through a TCP/IP connection to a specific
rosfran@559
    26
 * port on this server, and based on a known MythTV protocol that is based on 
rosfran@559
    27
 * some message passing, such as REQUEST_BLOCK on a specified number of bytes, to get
rosfran@559
    28
 * some chunk of remote file data.
rosfran@559
    29
 * You should pass the information aboute the remote MythTV backend server 
rosfran@559
    30
 * through the <link linkend="GstMythTVSrc--location">location</link> property.
rosfran@559
    31
 * </para>
rosfran@559
    32
 * <title>Examples</title>
rosfran@559
    33
 * <para>
rosfran@371
    34
 * If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder, 
rosfran@371
    35
 * Recorder),
rosfran@371
    36
 * put the following URI:
rosfran@289
    37
 * 
rosfran@559
    38
 * <programlisting> 
rosfran@559
    39
 *  myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
rosfran@559
    40
 * </programlisting>
rosfran@559
    41
 *
rosfran@371
    42
 * This URI will say to the gmyth library to configure the Recorder instance (used to
rosfran@371
    43
 * change the channel, start the TV multimedia content transmition, etc.), using
rosfran@371
    44
 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend 
rosfran@371
    45
 * server, and setting the channel name to "BBC". 
rosfran@371
    46
 * 
rosfran@371
    47
 * To get a already recorded the MythTV NUV file, put the following URI:
rosfran@371
    48
 * 
rosfran@559
    49
 * <programlisting>
rosfran@559
    50
 *  myth://xxx.xxx.xxx.xxx:6543/filename.nuv
rosfran@559
    51
 * </programlisting>
rosfran@559
    52
 *
rosfran@371
    53
 * This URI will say to the gmyth library to configure the Recorder instance (used to
rosfran@371
    54
 * change the channel, start the TV multimedia content transmition, etc.), using
rosfran@371
    55
 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend 
rosfran@371
    56
 * server, and setting the channel name to "BBC".
rosfran@371
    57
 * 
rosfran@371
    58
 * Another possible way to use the LiveTV content, and just in the case you want to 
rosfran@371
    59
 * use the mysql database, put the location URI in the following format:
rosfran@371
    60
 * 
rosfran@559
    61
 * <programlisting> 
rosfran@559
    62
 *  myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
rosfran@559
    63
 * </programlisting>
rosfran@289
    64
 * 
rosfran@289
    65
 * Where the first field is the protocol (myth), the second and third are user 
rosfran@289
    66
 * name (mythtv) and password (mythtv), then backend host name and port number, 
rosfran@289
    67
 * and the last field is the database name (mythconverg).
rosfran@559
    68
 * </para>
rosfran@559
    69
 * </refsect2>
rosfran@289
    70
 */
leo_sobral@2
    71
#ifdef HAVE_CONFIG_H
leo_sobral@2
    72
#include "config.h"
leo_sobral@2
    73
#endif
leo_sobral@2
    74
leo_sobral@2
    75
#include "gstmythtvsrc.h"
rosfran@528
    76
#include <gmyth/gmyth_file.h>
rosfran@52
    77
#include <gmyth/gmyth_file_transfer.h>
rosfran@528
    78
#include <gmyth/gmyth_file_local.h>
rosfran@52
    79
#include <gmyth/gmyth_livetv.h>
leo_sobral@2
    80
leo_sobral@2
    81
#include <gmyth/gmyth_socket.h>
leo_sobral@2
    82
#include <gmyth/gmyth_tvchain.h>
leo_sobral@2
    83
leo_sobral@2
    84
#include <string.h>
leo_sobral@2
    85
#include <unistd.h>
leo_sobral@2
    86
leo_sobral@2
    87
GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
leo_sobral@2
    88
#define GST_CAT_DEFAULT mythtvsrc_debug
leo_sobral@2
    89
rosfran@559
    90
#define GST_GMYTHTV_ID_NUM                  1
rosfran@70
    91
rosfran@559
    92
#define GST_GMYTHTV_CHANNEL_DEFAULT_NUM     (-1)
leo_sobral@2
    93
rosfran@289
    94
#define GMYTHTV_VERSION_DEFAULT			        30
leo_sobral@2
    95
rosfran@559
    96
#define GMYTHTV_TRANSFER_MAX_WAITS          100
rosfran@102
    97
rosfran@559
    98
#define GMYTHTV_TRANSFER_MAX_RESENDS        2
leo_sobral@2
    99
rosfran@559
   100
#define GMYTHTV_TRANSFER_MAX_BUFFER         (128*1024)
leo_sobral@2
   101
rosfran@559
   102
#define MAX_READ_SIZE                       (4*1024)
rosfran@70
   103
rosfran@559
   104
#define GST_FLOW_ERROR_NO_DATA              (-101)
rosfran@124
   105
rosfran@559
   106
#define REQUEST_MAX_SIZE                    (64*1024)
rosfran@90
   107
rosfran@559
   108
#define INTERNAL_BUFFER_SIZE                (90*1024)
leo_sobral@2
   109
leo_sobral@2
   110
static const GstElementDetails gst_mythtv_src_details =
rosfran@289
   111
GST_ELEMENT_DETAILS ("MythTV client source",
leo_sobral@2
   112
    "Source/Network",
rosfran@289
   113
    "Control and receive data as a client over the network "
rosfran@289
   114
    "via raw socket connections using the MythTV protocol",
rosfran@289
   115
    "Rosfran Borges <rosfran.borges@indt.org.br>");
leo_sobral@2
   116
rosfran@289
   117
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
leo_sobral@2
   118
    GST_PAD_SRC,
leo_sobral@2
   119
    GST_PAD_ALWAYS,
rosfran@289
   120
    GST_STATIC_CAPS ("video/x-nuv"));
rosfran@289
   121
leo_sobral@2
   122
enum
leo_sobral@2
   123
{
leo_sobral@2
   124
  PROP_0,
leo_sobral@2
   125
  PROP_LOCATION,
leo_sobral@2
   126
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
   127
  PROP_GMYTHTV_DBG,
leo_sobral@2
   128
#endif
rosfran@40
   129
  PROP_GMYTHTV_VERSION,
rosfran@40
   130
  PROP_GMYTHTV_LIVE,
rosfran@40
   131
  PROP_GMYTHTV_LIVEID,
rosfran@52
   132
  PROP_GMYTHTV_LIVE_CHAINID,
rosfran@70
   133
  PROP_GMYTHTV_ENABLE_TIMING_POSITION,
renatofilho@575
   134
  PROP_GMYTHTV_CHANNEL_NUM,
renatofilho@575
   135
  PROP_GMYTHTV_MAX_TRY
leo_sobral@2
   136
};
leo_sobral@2
   137
rosfran@548
   138
static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
rosfran@548
   139
leo_sobral@2
   140
static void gst_mythtv_src_finalize (GObject * gobject);
leo_sobral@2
   141
rosfran@289
   142
static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
rosfran@289
   143
    GstBuffer ** outbuf);
rosfran@52
   144
leo_sobral@2
   145
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
leo_sobral@2
   146
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
leo_sobral@2
   147
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
rosfran@289
   148
static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
rosfran@87
   149
rosfran@289
   150
static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
rosfran@289
   151
    GstSegment * segment);
rosfran@98
   152
rosfran@52
   153
static GstStateChangeReturn
rosfran@52
   154
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
leo_sobral@2
   155
leo_sobral@2
   156
static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
   157
    const GValue * value, GParamSpec * pspec);
leo_sobral@2
   158
static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
   159
    GValue * value, GParamSpec * pspec);
leo_sobral@2
   160
rosfran@289
   161
static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
rosfran@289
   162
    gpointer iface_data);
rosfran@30
   163
rosfran@87
   164
static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
rosfran@87
   165
rosfran@90
   166
static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
rosfran@30
   167
rosfran@528
   168
static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
rosfran@289
   169
    GByteArray * data_ptr);
leo_sobral@2
   170
rosfran@52
   171
static void
leo_sobral@2
   172
_urihandler_init (GType type)
leo_sobral@2
   173
{
leo_sobral@2
   174
  static const GInterfaceInfo urihandler_info = {
leo_sobral@2
   175
    gst_mythtv_src_uri_handler_init,
leo_sobral@2
   176
    NULL,
leo_sobral@2
   177
    NULL
leo_sobral@2
   178
  };
leo_sobral@2
   179
leo_sobral@2
   180
  g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
leo_sobral@2
   181
rosfran@289
   182
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
leo_sobral@2
   183
}
leo_sobral@2
   184
rosfran@100
   185
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
rosfran@100
   186
    GST_TYPE_PUSH_SRC, _urihandler_init)
rosfran@289
   187
rosfran@289
   188
     static void gst_mythtv_src_base_init (gpointer g_class)
leo_sobral@2
   189
{
leo_sobral@2
   190
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
leo_sobral@2
   191
leo_sobral@2
   192
  gst_element_class_add_pad_template (element_class,
leo_sobral@2
   193
      gst_static_pad_template_get (&srctemplate));
rosfran@289
   194
leo_sobral@2
   195
  gst_element_class_set_details (element_class, &gst_mythtv_src_details);
rosfran@289
   196
rosfran@52
   197
  element_class->change_state = gst_mythtv_src_change_state;
rosfran@289
   198
leo_sobral@2
   199
}
leo_sobral@2
   200
rosfran@30
   201
static void
leo_sobral@2
   202
gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
leo_sobral@2
   203
{
rosfran@289
   204
  GObjectClass *gobject_class;
rosfran@100
   205
  GstPushSrcClass *gstpushsrc_class;
leo_sobral@2
   206
  GstBaseSrcClass *gstbasesrc_class;
leo_sobral@2
   207
leo_sobral@2
   208
  gobject_class = (GObjectClass *) klass;
leo_sobral@2
   209
  gstbasesrc_class = (GstBaseSrcClass *) klass;
rosfran@100
   210
  gstpushsrc_class = (GstPushSrcClass *) klass;
leo_sobral@2
   211
leo_sobral@2
   212
  gobject_class->set_property = gst_mythtv_src_set_property;
leo_sobral@2
   213
  gobject_class->get_property = gst_mythtv_src_get_property;
leo_sobral@2
   214
  gobject_class->finalize = gst_mythtv_src_finalize;
leo_sobral@2
   215
leo_sobral@2
   216
  g_object_class_install_property
rosfran@289
   217
      (gobject_class, PROP_LOCATION,
rosfran@289
   218
      g_param_spec_string ("location", "Location",
rosfran@289
   219
          "The location. In the form:"
rosfran@289
   220
          "\n\t\t\tmyth://a.com/file.nuv"
rosfran@289
   221
          "\n\t\t\tmyth://a.com:23223/file.nuv "
rosfran@289
   222
          "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
rosfran@289
   223
          "", G_PARAM_READWRITE));
leo_sobral@2
   224
leo_sobral@2
   225
  g_object_class_install_property
rosfran@289
   226
      (gobject_class, PROP_GMYTHTV_VERSION,
rosfran@289
   227
      g_param_spec_int ("mythtv-version", "mythtv-version",
rosfran@289
   228
          "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
leo_sobral@2
   229
leo_sobral@2
   230
  g_object_class_install_property
rosfran@289
   231
      (gobject_class, PROP_GMYTHTV_LIVEID,
rosfran@289
   232
      g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
rosfran@289
   233
          "Change MythTV version",
rosfran@289
   234
          0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
leo_sobral@2
   235
leo_sobral@2
   236
  g_object_class_install_property
rosfran@289
   237
      (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
rosfran@289
   238
      g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
rosfran@289
   239
          "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
leo_sobral@2
   240
leo_sobral@2
   241
  g_object_class_install_property
rosfran@289
   242
      (gobject_class, PROP_GMYTHTV_LIVE,
rosfran@289
   243
      g_param_spec_boolean ("mythtv-live", "mythtv-live",
rosfran@289
   244
          "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
leo_sobral@2
   245
leo_sobral@2
   246
  g_object_class_install_property
rosfran@289
   247
      (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
rosfran@289
   248
      g_param_spec_boolean ("mythtv-enable-timing-position",
rosfran@289
   249
          "mythtv-enable-timing-position",
rosfran@289
   250
          "Enable MythTV Live TV content size continuous updating", FALSE,
rosfran@289
   251
          G_PARAM_READWRITE));
leo_sobral@2
   252
rosfran@52
   253
  g_object_class_install_property
rosfran@289
   254
      (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
rosfran@308
   255
      g_param_spec_string ("mythtv-channel", "mythtv-channel",
rosfran@289
   256
          "Change MythTV channel number",
rosfran@308
   257
          "", G_PARAM_READWRITE));
rosfran@52
   258
renatofilho@575
   259
  g_object_class_install_property
renatofilho@575
   260
      (gobject_class, PROP_GMYTHTV_MAX_TRY,
renatofilho@575
   261
      g_param_spec_int ("max-try", "max-try",
renatofilho@575
   262
          "Set the max try for get MythTV free recorder",
renatofilho@575
   263
          0, G_MAXINT, 10,  G_PARAM_READWRITE));
renatofilho@575
   264
renatofilho@575
   265
leo_sobral@2
   266
#ifndef GST_DISABLE_GST_DEBUG
leo_sobral@2
   267
  g_object_class_install_property
rosfran@289
   268
      (gobject_class, PROP_GMYTHTV_DBG,
rosfran@289
   269
      g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
rosfran@289
   270
          "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
leo_sobral@2
   271
#endif
leo_sobral@2
   272
leo_sobral@2
   273
  gstbasesrc_class->start = gst_mythtv_src_start;
leo_sobral@2
   274
  gstbasesrc_class->stop = gst_mythtv_src_stop;
leo_sobral@2
   275
  gstbasesrc_class->get_size = gst_mythtv_src_get_size;
rosfran@87
   276
  gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
rosfran@289
   277
rosfran@100
   278
  gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
rosfran@100
   279
  gstpushsrc_class->create = gst_mythtv_src_create;
rosfran@289
   280
leo_sobral@2
   281
  GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
leo_sobral@2
   282
      "MythTV Client Source");
leo_sobral@2
   283
}
leo_sobral@2
   284
rosfran@30
   285
static void
leo_sobral@2
   286
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
leo_sobral@2
   287
{
rosfran@546
   288
  this->file = NULL;
leo_sobral@2
   289
leo_sobral@2
   290
  this->unique_setup = FALSE;
leo_sobral@2
   291
rosfran@40
   292
  this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
rosfran@289
   293
rosfran@70
   294
  this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
leo_sobral@2
   295
leo_sobral@2
   296
  this->bytes_read = 0;
rosfran@289
   297
rosfran@63
   298
  this->prev_content_size = 0;
leo_sobral@2
   299
rosfran@52
   300
  this->content_size = 0;
leo_sobral@2
   301
  this->read_offset = 0;
leo_sobral@2
   302
rosfran@61
   303
  this->content_size_last = 0;
rosfran@61
   304
leo_sobral@2
   305
  this->live_tv = FALSE;
rosfran@289
   306
rosfran@52
   307
  this->enable_timing_position = FALSE;
rosfran@289
   308
  this->update_prog_chain = FALSE;
leo_sobral@2
   309
leo_sobral@2
   310
  this->user_agent = g_strdup ("mythtvsrc");
rosfran@52
   311
  this->update_prog_chain = FALSE;
rosfran@289
   312
rosfran@308
   313
  this->channel_name = NULL;
rosfran@289
   314
rosfran@52
   315
  this->eos = FALSE;
rosfran@289
   316
rosfran@98
   317
  this->bytes_queue = NULL;
leo_sobral@2
   318
rosfran@289
   319
  this->wait_to_transfer = 0;
renatofilho@575
   320
  this->try_number = 0;
renatofilho@575
   321
  this->max_try = 10;
rosfran@289
   322
rosfran@289
   323
  gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
rosfran@289
   324
rosfran@289
   325
  gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
rosfran@289
   326
      gst_mythtv_src_handle_event);
rosfran@289
   327
  gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
rosfran@289
   328
      gst_mythtv_src_handle_query);
rosfran@30
   329
leo_sobral@2
   330
}
leo_sobral@2
   331
rosfran@30
   332
static void
rosfran@548
   333
gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
rosfran@548
   334
{
renatofilho@575
   335
  mythtv_src->unique_setup = FALSE;
renatofilho@575
   336
  mythtv_src->try_number = 0;
renatofilho@575
   337
rosfran@548
   338
  if (mythtv_src->spawn_livetv) {
rosfran@548
   339
    g_object_unref (mythtv_src->spawn_livetv);
rosfran@548
   340
    mythtv_src->spawn_livetv = NULL;
rosfran@548
   341
  }
rosfran@548
   342
rosfran@548
   343
  if (mythtv_src->file) {
rosfran@548
   344
    g_object_unref (mythtv_src->file);
rosfran@548
   345
    mythtv_src->file = NULL;
rosfran@548
   346
  }
rosfran@548
   347
rosfran@548
   348
  if (mythtv_src->backend_info) {
rosfran@548
   349
    g_object_unref (mythtv_src->backend_info);
rosfran@548
   350
    mythtv_src->backend_info = NULL;
rosfran@548
   351
  }
rosfran@548
   352
rosfran@548
   353
  if (mythtv_src->bytes_queue) {
rosfran@548
   354
    g_byte_array_free (mythtv_src->bytes_queue, TRUE);
rosfran@548
   355
    mythtv_src->bytes_queue = NULL;
rosfran@548
   356
  }
rosfran@548
   357
  
rosfran@548
   358
}
rosfran@548
   359
rosfran@548
   360
static void
leo_sobral@2
   361
gst_mythtv_src_finalize (GObject * gobject)
leo_sobral@2
   362
{
leo_sobral@2
   363
  GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
rosfran@114
   364
rosfran@548
   365
  gst_mythtv_src_clear (this);
leo_sobral@2
   366
renatofilho@575
   367
  if (this->uri_name) {
renatofilho@575
   368
    g_free (this->uri_name);
renatofilho@575
   369
    this->uri_name = NULL;
renatofilho@575
   370
  }
renatofilho@575
   371
renatofilho@575
   372
  if (this->user_agent) {
renatofilho@575
   373
    g_free (this->user_agent);
renatofilho@575
   374
    this->user_agent = NULL;
renatofilho@575
   375
  }
renatofilho@575
   376
leo_sobral@2
   377
  G_OBJECT_CLASS (parent_class)->finalize (gobject);
leo_sobral@2
   378
}
leo_sobral@2
   379
rosfran@528
   380
static GMythFileReadResult
renatofilho@506
   381
do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
leo_sobral@2
   382
{
rosfran@37
   383
  gint read = 0;
rosfran@52
   384
  guint sizetoread = size;
rosfran@142
   385
  gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
rosfran@528
   386
  GMythFileReadResult result;
rosfran@289
   387
rosfran@289
   388
  GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
leo_sobral@2
   389
rosfran@30
   390
  /* Loop sending the Myth File Transfer request:
leo_sobral@2
   391
   * Retry whilst authentication fails and we supply it. */
rosfran@61
   392
rosfran@289
   393
  while (sizetoread == size && --max_iters > 0) {
rosfran@546
   394
    /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
rosfran@546
   395
    if ( IS_GMYTH_FILE_LOCAL(src->file) )
rosfran@546
   396
      result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
rosfran@528
   397
          data_ptr, sizetoread, src->live_tv);      
rosfran@546
   398
    else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
rosfran@546
   399
      result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
rosfran@528
   400
          data_ptr, sizetoread, src->live_tv);
rosfran@289
   401
renatofilho@506
   402
    if (data_ptr->len > 0) {
renatofilho@503
   403
      read += data_ptr->len;
renatofilho@503
   404
      sizetoread -= data_ptr->len;
renatofilho@506
   405
    } else if (data_ptr->len < 0) {
rosfran@289
   406
      if (src->live_tv == FALSE) {
rosfran@528
   407
        result = GMYTH_FILE_READ_EOF;
rosfran@289
   408
        goto eos;
rosfran@289
   409
      } else {
rosfran@528
   410
        if (result == GMYTH_FILE_READ_ERROR) {  /* -314 */
rosfran@289
   411
          GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
rosfran@289
   412
          goto done;
rosfran@528
   413
        } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {      /* -315 */
rosfran@289
   414
          GST_INFO_OBJECT (src,
rosfran@289
   415
              "[LiveTV] FileTransfer - Go to the next program chain!");
rosfran@289
   416
          continue;
rosfran@289
   417
        }
rosfran@289
   418
        goto done;
rosfran@90
   419
      }
rosfran@30
   420
renatofilho@503
   421
    } else if (data_ptr->len == 0)
rosfran@289
   422
      goto done;
rosfran@61
   423
rosfran@289
   424
    if (read == sizetoread)
rosfran@90
   425
      goto done;
rosfran@100
   426
  }
rosfran@61
   427
renatofilho@506
   428
  if ((read < 0 && !src->live_tv) || max_iters == 0){
rosfran@528
   429
    result = GMYTH_FILE_READ_EOF;
rosfran@61
   430
    goto eos;
renatofilho@506
   431
  }
rosfran@61
   432
rosfran@30
   433
  goto done;
leo_sobral@2
   434
leo_sobral@2
   435
eos:
leo_sobral@2
   436
  src->eos = TRUE;
rosfran@61
   437
leo_sobral@2
   438
done:
renatofilho@506
   439
  return result;
leo_sobral@2
   440
}
leo_sobral@2
   441
rosfran@30
   442
static GstFlowReturn
rosfran@289
   443
gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
rosfran@81
   444
{
rosfran@81
   445
  GstMythtvSrc *src;
rosfran@81
   446
  GstFlowReturn ret = GST_FLOW_OK;
rosfran@528
   447
  guint buffer_size_inter = 0;
rosfran@90
   448
rosfran@289
   449
  src = GST_MYTHTV_SRC (psrc);
rosfran@90
   450
rosfran@81
   451
  /* The caller should know the number of bytes and not read beyond EOS. */
rosfran@289
   452
  if (G_UNLIKELY (src->eos))
rosfran@81
   453
    goto eos;
rosfran@289
   454
  if (G_UNLIKELY (src->update_prog_chain))
rosfran@81
   455
    goto change_progchain;
rosfran@95
   456
rosfran@289
   457
  GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
rosfran@289
   458
      src->read_offset, MAX_READ_SIZE);
rosfran@95
   459
rosfran@289
   460
  GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
rosfran@289
   461
      (gint) src->buffer_remain, src->bytes_queue->len);
rosfran@95
   462
rosfran@429
   463
program_chain_changed:
rosfran@100
   464
  /* just get from the byte array, no network effort... */
rosfran@289
   465
  if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
rosfran@364
   466
  	GByteArray *buffer;
rosfran@528
   467
    GMythFileReadResult result = GMYTH_FILE_READ_OK;
rosfran@359
   468
  	
rosfran@364
   469
    buffer = NULL;
rosfran@528
   470
    buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
rosfran@95
   471
rosfran@289
   472
    if (buffer_size_inter > REQUEST_MAX_SIZE)
rosfran@289
   473
      buffer_size_inter = REQUEST_MAX_SIZE;
rosfran@289
   474
rosfran@289
   475
    buffer = g_byte_array_new ();
rosfran@289
   476
renatofilho@503
   477
    result = do_read_request_response (src, buffer_size_inter, buffer);
rosfran@142
   478
renatofilho@503
   479
    if (G_UNLIKELY (buffer->len < 0)) {
rosfran@359
   480
    	
rosfran@359
   481
    	if (buffer != NULL) {
rosfran@359
   482
	      g_byte_array_free (buffer, TRUE);
rosfran@359
   483
	      buffer = NULL;
rosfran@359
   484
	    }
rosfran@359
   485
	    
rosfran@528
   486
      if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
rosfran@289
   487
        goto change_progchain;
rosfran@142
   488
      else
rosfran@289
   489
        goto read_error;
rosfran@289
   490
    } else if (G_UNLIKELY (read == 0)) {
rosfran@359
   491
    	
rosfran@359
   492
    	if (buffer != NULL) {
rosfran@359
   493
	      g_byte_array_free (buffer, TRUE);
rosfran@359
   494
	      buffer = NULL;
rosfran@359
   495
	    }
rosfran@359
   496
	    
rosfran@289
   497
      if (!src->live_tv)
rosfran@303
   498
        goto done;
rosfran@289
   499
      else
rosfran@429
   500
        goto program_chain_changed;
rosfran@174
   501
    }
rosfran@142
   502
rosfran@289
   503
    if (G_UNLIKELY (src->update_prog_chain))
rosfran@359
   504
    {
rosfran@359
   505
    	if (buffer != NULL) {
rosfran@359
   506
	      g_byte_array_free (buffer, TRUE);
rosfran@359
   507
	      buffer = NULL;
rosfran@359
   508
	    }
rosfran@359
   509
      goto change_progchain;      
rosfran@359
   510
    }
rosfran@289
   511
rosfran@289
   512
    src->bytes_queue =
renatofilho@503
   513
        g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
renatofilho@503
   514
    if (buffer->len > buffer_size_inter)
rosfran@289
   515
      GST_WARNING_OBJECT (src,
rosfran@289
   516
          "INCREASED buffer size! Backend sent more than we ask him... (%d)",
rosfran@528
   517
          abs (buffer->len - buffer_size_inter));
rosfran@142
   518
renatofilho@503
   519
    src->buffer_remain += buffer->len;
rosfran@142
   520
rosfran@289
   521
    if (buffer != NULL) {
rosfran@289
   522
      g_byte_array_free (buffer, TRUE);
rosfran@289
   523
      buffer = NULL;
rosfran@142
   524
    }
rosfran@289
   525
rosfran@289
   526
    GST_DEBUG_OBJECT (src,
rosfran@289
   527
        "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
rosfran@289
   528
        "OFFSET = %llu, CONTENT SIZE = %llu.", read,
rosfran@289
   529
        src->bytes_read, src->read_offset, src->content_size);
rosfran@289
   530
rosfran@81
   531
  }
rosfran@289
   532
rosfran@289
   533
  guint buffer_size =
rosfran@289
   534
      (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
rosfran@289
   535
rosfran@289
   536
  *outbuf = gst_buffer_new ();
rosfran@289
   537
rosfran@289
   538
  /* gets the first buffer_size bytes from the byte array buffer variable */
rosfran@235
   539
  /* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
rosfran@95
   540
rosfran@289
   541
  GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
rosfran@528
   542
      (buffer_size_inter ==
rosfran@528
   543
          0) ? "NO, got from buffer" : "YES, go see the backend's log file",
rosfran@289
   544
      src->buffer_remain);
rosfran@95
   545
rosfran@100
   546
  GST_BUFFER_SIZE (*outbuf) = buffer_size;
rosfran@289
   547
  GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
rosfran@289
   548
  GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
rosfran@289
   549
  g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
rosfran@289
   550
      GST_BUFFER_SIZE (*outbuf));
rosfran@95
   551
  GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
rosfran@289
   552
  GST_BUFFER_OFFSET_END (*outbuf) =
rosfran@289
   553
      src->read_offset + GST_BUFFER_SIZE (*outbuf);
rosfran@95
   554
rosfran@95
   555
  src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
rosfran@95
   556
rosfran@95
   557
  src->read_offset += GST_BUFFER_SIZE (*outbuf);
rosfran@95
   558
  src->bytes_read += GST_BUFFER_SIZE (*outbuf);
rosfran@289
   559
  GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
rosfran@289
   560
      GST_BUFFER_SIZE (*outbuf));
rosfran@289
   561
rosfran@100
   562
  /* flushs the newly buffer got from byte array */
rosfran@289
   563
  src->bytes_queue =
rosfran@289
   564
      g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
rosfran@95
   565
rosfran@359
   566
  GST_DEBUG_OBJECT ( src, "Got buffer: BUFFER --->SIZE = %d, OFFSET = %llu, "
rosfran@289
   567
      "OFFSET_END = %llu.", GST_BUFFER_SIZE (*outbuf),
rosfran@359
   568
      GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
rosfran@95
   569
rosfran@289
   570
  GST_DEBUG_OBJECT (src, "CONTENT_SIZE = %llu, BYTES_READ = %llu.",
rosfran@289
   571
      src->content_size, src->bytes_read);
rosfran@289
   572
rosfran@359
   573
  if ( G_UNLIKELY (src->eos) || ( !src->live_tv
rosfran@359
   574
          && ( src->bytes_read >= src->content_size ) ) )
rosfran@289
   575
    goto eos;
rosfran@90
   576
rosfran@81
   577
done:
rosfran@90
   578
  {
rosfran@81
   579
    const gchar *reason = gst_flow_get_name (ret);
rosfran@81
   580
rosfran@81
   581
    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
rosfran@90
   582
    return ret;
rosfran@90
   583
  }
rosfran@81
   584
eos:
rosfran@81
   585
  {
rosfran@81
   586
    const gchar *reason = gst_flow_get_name (ret);
rosfran@81
   587
rosfran@81
   588
    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
rosfran@81
   589
    return GST_FLOW_UNEXPECTED;
rosfran@81
   590
  }
rosfran@81
   591
  /* ERRORS */
rosfran@81
   592
read_error:
rosfran@81
   593
  {
rosfran@81
   594
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@289
   595
        (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
rosfran@81
   596
    return GST_FLOW_ERROR;
rosfran@81
   597
  }
rosfran@81
   598
change_progchain:
rosfran@81
   599
  {
rosfran@81
   600
    GST_ELEMENT_ERROR (src, RESOURCE, READ,
rosfran@289
   601
        (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
rosfran@289
   602
            src->uri_name));
rosfran@90
   603
rosfran@375
   604
/*
rosfran@429
   605
    TODO: need to send a new segment event to NUVDemux? 
rosfran@289
   606
    gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
rosfran@289
   607
        gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
rosfran@375
   608
*/
rosfran@303
   609
rosfran@359
   610
    goto program_chain_changed;
rosfran@37
   611
  }
rosfran@30
   612
leo_sobral@2
   613
}
rosfran@98
   614
rosfran@52
   615
gint64
rosfran@289
   616
gst_mythtv_src_get_position (GstMythtvSrc * src)
leo_sobral@2
   617
{
rosfran@30
   618
rosfran@52
   619
  gint64 size_tmp = 0;
rosfran@71
   620
  guint max_tries = 2;
rosfran@71
   621
rosfran@289
   622
  if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
rosfran@289
   623
          GMYTHTV_TRANSFER_MAX_BUFFER)) {
rosfran@289
   624
rosfran@289
   625
  get_file_pos:
rosfran@289
   626
    g_usleep (10);
rosfran@289
   627
    size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
rosfran@289
   628
    if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
rosfran@61
   629
      src->content_size = size_tmp;
rosfran@289
   630
    else if (size_tmp > 0 && --max_tries > 0)
rosfran@61
   631
      goto get_file_pos;
rosfran@289
   632
    GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
rosfran@71
   633
    /* sets the last content size amount before it can be updated */
rosfran@71
   634
    src->prev_content_size = src->content_size;
rosfran@30
   635
  }
rosfran@52
   636
rosfran@289
   637
  return src->content_size;
rosfran@30
   638
leo_sobral@2
   639
}
leo_sobral@2
   640
rosfran@87
   641
static gboolean
rosfran@289
   642
gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
rosfran@87
   643
{
rosfran@289
   644
  GstMythtvSrc *src = GST_MYTHTV_SRC (base);
rosfran@90
   645
  gint64 new_offset = -1;
rosfran@90
   646
  gint64 actual_seek = segment->start;
rosfran@87
   647
  gboolean ret = TRUE;
rosfran@87
   648
rosfran@289
   649
  GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
rosfran@90
   650
rosfran@289
   651
  if (segment->format == GST_FORMAT_TIME) {
rosfran@289
   652
    goto done;
rosfran@90
   653
  }
rosfran@289
   654
  GST_LOG_OBJECT (src,
rosfran@289
   655
      "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
rosfran@289
   656
      actual_seek, src->read_offset);
rosfran@87
   657
  /* verify if it needs to seek */
rosfran@289
   658
  if (src->read_offset != actual_seek) {
rosfran@528
   659
    
rosfran@546
   660
    /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
rosfran@546
   661
    if ( IS_GMYTH_FILE_LOCAL(src->file) )
rosfran@528
   662
      new_offset =
rosfran@546
   663
          gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
rosfran@546
   664
    else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
rosfran@528
   665
      new_offset =
rosfran@546
   666
          gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
rosfran@87
   667
rosfran@289
   668
    GST_LOG_OBJECT (src,
rosfran@289
   669
        "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
rosfran@289
   670
        segment->start, src->read_offset, new_offset);
rosfran@289
   671
    if (G_UNLIKELY (new_offset < 0)) {
rosfran@87
   672
      ret = FALSE;
rosfran@371
   673
      if (!src->live_tv)
rosfran@289
   674
        goto eos;
rosfran@87
   675
    }
rosfran@87
   676
rosfran@87
   677
    src->read_offset = new_offset;
rosfran@87
   678
rosfran@289
   679
    if (ret == FALSE) {
rosfran@289
   680
      GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
rosfran@90
   681
    }
rosfran@90
   682
rosfran@87
   683
  }
rosfran@90
   684
rosfran@90
   685
done:
rosfran@289
   686
  return ret;
rosfran@87
   687
rosfran@87
   688
eos:
rosfran@87
   689
  {
rosfran@87
   690
    GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
rosfran@87
   691
    return FALSE;
rosfran@87
   692
  }
rosfran@87
   693
rosfran@87
   694
}
rosfran@87
   695
leo_sobral@2
   696
/* create a socket for connecting to remote server */
rosfran@30
   697
static gboolean
rosfran@289
   698
gst_mythtv_src_start (GstBaseSrc * bsrc)
leo_sobral@2
   699
{
leo_sobral@2
   700
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
leo_sobral@2
   701
rosfran@293
   702
  GString *chain_id_local = NULL;  
rosfran@293
   703
  GMythURI *gmyth_uri = NULL;
leo_sobral@2
   704
  gboolean ret = TRUE;
rosfran@90
   705
leo_sobral@2
   706
  if (src->unique_setup == FALSE) {
leo_sobral@2
   707
    src->unique_setup = TRUE;
leo_sobral@2
   708
  } else {
leo_sobral@2
   709
    goto done;
leo_sobral@2
   710
  }
rosfran@174
   711
  
renatofilho@575
   712
  gmyth_uri = gmyth_uri_new_with_value (src->uri_name);
rosfran@289
   713
  src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
renatofilho@575
   714
  src->live_tv = gmyth_uri_is_livetv( gmyth_uri );
rosfran@289
   715
  /* testing UPnP... */
rosfran@289
   716
  /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
rosfran@304
   717
  if ( src->live_tv ) {
rosfran@448
   718
    src->spawn_livetv = gmyth_livetv_new (src->backend_info);
rosfran@236
   719
    
rosfran@308
   720
    gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
rosfran@308
   721
    if ( ch != NULL )
rosfran@308
   722
    	src->channel_name = ch;
rosfran@289
   723
    	
rosfran@308
   724
    if (src->channel_name != NULL) {
rosfran@448
   725
      if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
rosfran@289
   726
        GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
rosfran@289
   727
        ret = FALSE;
rosfran@289
   728
        goto init_failed;
rosfran@289
   729
      }
rosfran@236
   730
    } else {
rosfran@448
   731
      if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
rosfran@289
   732
        GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
rosfran@289
   733
        ret = FALSE;
rosfran@289
   734
        goto init_failed;
rosfran@289
   735
      }
rosfran@236
   736
    }
rosfran@546
   737
rosfran@311
   738
    /* testing change channel... */
rosfran@311
   739
    /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
rosfran@52
   740
rosfran@546
   741
    src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
rosfran@289
   742
rosfran@546
   743
    if (NULL == src->file) {
rosfran@289
   744
      GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
rosfran@289
   745
      ret = FALSE;
rosfran@289
   746
      goto init_failed;
leo_sobral@2
   747
    }
rosfran@325
   748
    
rosfran@553
   749
    /* Check if the file is local to this specific client renderer */
rosfran@551
   750
    if ( gmyth_uri_is_local_file(gmyth_uri) )
rosfran@551
   751
      ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
rosfran@551
   752
    else
rosfran@551
   753
      ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ? 
rosfran@551
   754
                gmyth_uri_get_path(src->spawn_livetv->uri) : 
rosfran@551
   755
                src->spawn_livetv->proginfo->pathname->str );
rosfran@553
   756
    
rosfran@553
   757
    /* sets the mythtvsrc "location" property */
rosfran@553
   758
    g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
rosfran@551
   759
rosfran@551
   760
		if ( !ret )
rosfran@325
   761
		{
rosfran@325
   762
			GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
rosfran@546
   763
			g_object_unref( src->file );
rosfran@546
   764
			src->file = NULL;
rosfran@325
   765
			goto init_failed;
rosfran@325
   766
		}
rosfran@217
   767
  } else {
rosfran@553
   768
    
rosfran@553
   769
    /* Check if the file is local to this specific client renderer, and tries to open
rosfran@553
   770
     * a local connection
rosfran@553
   771
     */
rosfran@546
   772
    if ( gmyth_uri_is_local_file(gmyth_uri) )
rosfran@528
   773
    {
rosfran@546
   774
      src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
rosfran@546
   775
      ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
rosfran@546
   776
    } else {
rosfran@546
   777
      src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
rosfran@553
   778
      ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
rosfran@546
   779
    }
leo_sobral@2
   780
rosfran@528
   781
  } /* if (else) - recorded FileTransfer */
leo_sobral@2
   782
rosfran@546
   783
  if (NULL == src->file) {
rosfran@289
   784
    GST_INFO_OBJECT (src, "FileTransfer is NULL");
rosfran@289
   785
    goto init_failed;
rosfran@289
   786
  }
rosfran@546
   787
  /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
rosfran@289
   788
rosfran@289
   789
  if (ret == FALSE) {
rosfran@289
   790
#ifndef GST_DISABLE_GST_DEBUG
rosfran@289
   791
    if (src->mythtv_msgs_dbg)
rosfran@289
   792
      GST_INFO_OBJECT (src,
rosfran@289
   793
          "MythTV FileTransfer request failed when setting up socket connection!");
leo_sobral@2
   794
#endif
leo_sobral@2
   795
    goto begin_req_failed;
leo_sobral@2
   796
  }
rosfran@289
   797
rosfran@289
   798
  GST_INFO_OBJECT (src,
rosfran@289
   799
      "MythTV FileTransfer filesize = %lld, content_size = %lld!",
rosfran@546
   800
      gmyth_file_get_filesize( src->file ), src->content_size);
leo_sobral@2
   801
rosfran@546
   802
  src->content_size = gmyth_file_get_filesize (src->file);
leo_sobral@2
   803
rosfran@71
   804
  src->do_start = FALSE;
rosfran@289
   805
rosfran@114
   806
  /* this is used for the buffer cache */
rosfran@289
   807
  src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
rosfran@90
   808
  src->buffer_remain = 0;
rosfran@114
   809
  
rosfran@289
   810
  gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
rosfran@289
   811
      gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
rosfran@289
   812
          src->content_size, 0));
rosfran@90
   813
rosfran@30
   814
done:
renatofilho@575
   815
	if (gmyth_uri != NULL)
rosfran@289
   816
	{
renatofilho@575
   817
  	    g_object_unref (gmyth_uri);
renatofilho@575
   818
      	gmyth_uri = NULL;
renatofilho@575
   819
	}
rosfran@210
   820
renatofilho@575
   821
    if (chain_id_local != NULL) {
renatofilho@575
   822
        g_string_free (chain_id_local, TRUE);
renatofilho@575
   823
        chain_id_local = NULL;
renatofilho@575
   824
    }
rosfran@289
   825
renatofilho@575
   826
    return TRUE;
rosfran@30
   827
renatofilho@575
   828
    /* ERRORS */
rosfran@30
   829
init_failed:
renatofilho@575
   830
	if (gmyth_uri != NULL)
renatofilho@575
   831
	{
renatofilho@575
   832
  	    g_object_unref (gmyth_uri);
renatofilho@575
   833
      	gmyth_uri = NULL;
renatofilho@575
   834
	}
rosfran@30
   835
renatofilho@575
   836
    if (src->spawn_livetv != NULL) {
renatofilho@575
   837
        g_object_unref (src->spawn_livetv);
renatofilho@575
   838
        src->spawn_livetv = NULL;
renatofilho@575
   839
    }
renatofilho@575
   840
    
renatofilho@575
   841
    /*
rosfran@30
   842
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
renatofilho@575
   843
            (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
rosfran@289
   844
            src->uri_name));
renatofilho@575
   845
    */            
renatofilho@575
   846
renatofilho@575
   847
    if  (++src->try_number <= src->max_try) {
renatofilho@575
   848
       gst_mythtv_src_clear (src);
renatofilho@575
   849
       GST_DEBUG_OBJECT (src, "Starting new try for get free recorder on MythTV");
renatofilho@575
   850
       g_usleep (0.5 * G_USEC_PER_SEC);
renatofilho@575
   851
       return gst_mythtv_src_start (bsrc);
renatofilho@575
   852
    }
renatofilho@575
   853
rosfran@30
   854
    return FALSE;
rosfran@30
   855
begin_req_failed:
renatofilho@575
   856
	if (gmyth_uri != NULL)
renatofilho@575
   857
	{
renatofilho@575
   858
  	    g_object_unref (gmyth_uri);
renatofilho@575
   859
      	gmyth_uri = NULL;
renatofilho@575
   860
	}
renatofilho@575
   861
rosfran@30
   862
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
rosfran@289
   863
        (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
rosfran@289
   864
            src->uri_name));
rosfran@30
   865
    return FALSE;
rosfran@61
   866
rosfran@52
   867
}
rosfran@52
   868
rosfran@30
   869
static gboolean
leo_sobral@2
   870
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
leo_sobral@2
   871
{
rosfran@31
   872
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
rosfran@30
   873
  gboolean ret = TRUE;
rosfran@289
   874
rosfran@289
   875
  GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
rosfran@289
   876
      abs (src->content_size - src->prev_content_size),
rosfran@289
   877
      GMYTHTV_TRANSFER_MAX_BUFFER);
rosfran@289
   878
rosfran@289
   879
  if (src->live_tv) {
rosfran@289
   880
    ret = FALSE;
rosfran@289
   881
  } else if (src->live_tv && src->enable_timing_position
rosfran@289
   882
      && (abs (src->content_size - src->bytes_read) <
rosfran@289
   883
          GMYTHTV_TRANSFER_MAX_BUFFER)) {
rosfran@289
   884
rosfran@289
   885
    gint64 new_offset =
rosfran@289
   886
        gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
rosfran@289
   887
    if (new_offset > 0 && new_offset > src->content_size) {
rosfran@289
   888
      src->content_size = new_offset;
rosfran@289
   889
    } else if (new_offset < src->content_size) {
rosfran@289
   890
      src->update_prog_chain = TRUE;
rosfran@289
   891
    }
rosfran@61
   892
leo_sobral@2
   893
  }
leo_sobral@2
   894
leo_sobral@2
   895
  *size = src->content_size;
rosfran@289
   896
  GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
rosfran@289
   897
rosfran@30
   898
  return ret;
rosfran@30
   899
leo_sobral@2
   900
}
leo_sobral@2
   901
leo_sobral@2
   902
/* close the socket and associated resources
leo_sobral@2
   903
 * used both to recover from errors and go to NULL state */
rosfran@52
   904
static gboolean
leo_sobral@2
   905
gst_mythtv_src_stop (GstBaseSrc * bsrc)
leo_sobral@2
   906
{
rosfran@548
   907
  GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
rosfran@548
   908
  
rosfran@548
   909
  gst_mythtv_src_clear (src);
leo_sobral@2
   910
rosfran@548
   911
  /* src->eos = FALSE; */
leo_sobral@2
   912
leo_sobral@2
   913
  return TRUE;
leo_sobral@2
   914
}
leo_sobral@2
   915
rosfran@30
   916
static gboolean
leo_sobral@2
   917
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
leo_sobral@2
   918
{
leo_sobral@2
   919
  GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
rosfran@52
   920
  gint64 cont_size = 0;
rosfran@90
   921
  gboolean ret = FALSE;
leo_sobral@2
   922
leo_sobral@2
   923
  switch (GST_EVENT_TYPE (event)) {
rosfran@30
   924
    case GST_EVENT_EOS:
rosfran@289
   925
      GST_WARNING_OBJECT (src, "Got EOS event");
rosfran@61
   926
rosfran@289
   927
      if (src->live_tv) {
rosfran@289
   928
        cont_size = gst_mythtv_src_get_position (src);
rosfran@289
   929
        if (cont_size > src->content_size) {
rosfran@289
   930
          src->content_size = cont_size;
rosfran@289
   931
          src->eos = FALSE;
rosfran@289
   932
        } else {
rosfran@289
   933
          src->eos = TRUE;
rosfran@289
   934
          gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
rosfran@289
   935
          gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
rosfran@289
   936
        }
rosfran@114
   937
      }
rosfran@30
   938
      break;
leo_sobral@2
   939
    default:
rosfran@90
   940
      ret = gst_pad_event_default (pad, event);
leo_sobral@2
   941
  }
leo_sobral@2
   942
rosfran@90
   943
  return ret;
leo_sobral@2
   944
}
leo_sobral@2
   945
rosfran@30
   946
static gboolean
rosfran@289
   947
gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
leo_sobral@2
   948
{
rosfran@100
   949
  return TRUE;
leo_sobral@2
   950
}
rosfran@87
   951
rosfran@87
   952
static gboolean
rosfran@87
   953
gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
rosfran@87
   954
{
rosfran@87
   955
  gboolean res = FALSE;
rosfran@87
   956
  GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
rosfran@114
   957
  GstFormat formt;
rosfran@87
   958
rosfran@87
   959
  switch (GST_QUERY_TYPE (query)) {
rosfran@87
   960
    case GST_QUERY_POSITION:
rosfran@114
   961
    {
rosfran@289
   962
      gst_query_parse_position (query, &formt, NULL);
rosfran@289
   963
      if (formt == GST_FORMAT_BYTES) {
rosfran@289
   964
        gst_query_set_position (query, formt, myth->read_offset);
rosfran@289
   965
        GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
rosfran@289
   966
        res = TRUE;
rosfran@289
   967
      } else if (formt == GST_FORMAT_TIME) {
rosfran@289
   968
        res = gst_pad_query_default (pad, query);
rosfran@124
   969
      }
rosfran@87
   970
      break;
rosfran@114
   971
    }
rosfran@87
   972
    case GST_QUERY_DURATION:
rosfran@114
   973
    {
rosfran@87
   974
#if 0
rosfran@87
   975
      if (myth->duration != 0) {
rosfran@289
   976
        gint64 total;
rosfran@289
   977
        gint64 fps;
rosfran@87
   978
rosfran@289
   979
        fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
rosfran@289
   980
        total =
rosfran@289
   981
            gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
rosfran@114
   982
      }
rosfran@81
   983
#endif
rosfran@289
   984
rosfran@289
   985
      gst_query_parse_duration (query, &formt, NULL);
rosfran@289
   986
      if (formt == GST_FORMAT_BYTES) {
rosfran@289
   987
        gst_query_set_duration (query, formt, myth->content_size);
rosfran@289
   988
        GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, myth->content_size);
rosfran@289
   989
        res = TRUE;
rosfran@289
   990
      } else if (formt == GST_FORMAT_TIME) {
rosfran@289
   991
        res = gst_pad_query_default (pad, query);
rosfran@289
   992
      }
rosfran@70
   993
      break;
rosfran@114
   994
    }
rosfran@70
   995
    default:
rosfran@114
   996
    {
rosfran@289
   997
      res = gst_pad_query_default (pad, query);
rosfran@87
   998
      break;
rosfran@114
   999
    }
rosfran@70
  1000
  }
rosfran@61
  1001
rosfran@87
  1002
  gst_object_unref (myth);
rosfran@61
  1003
rosfran@70
  1004
  return res;
rosfran@61
  1005
}
rosfran@61
  1006
rosfran@52
  1007
static GstStateChangeReturn
rosfran@52
  1008
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
rosfran@52
  1009
{
rosfran@289
  1010
  GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
rosfran@52
  1011
  GstMythtvSrc *src = GST_MYTHTV_SRC (element);
rosfran@52
  1012
rosfran@52
  1013
  switch (transition) {
rosfran@52
  1014
    case GST_STATE_CHANGE_NULL_TO_READY:
rosfran@52
  1015
      break;
rosfran@52
  1016
    case GST_STATE_CHANGE_READY_TO_PAUSED:
rosfran@52
  1017
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
rosfran@289
  1018
      if (src->live_tv) {
rosfran@289
  1019
        if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
rosfran@289
  1020
                recorder))
rosfran@289
  1021
          GST_WARNING_OBJECT (src,
rosfran@289
  1022
              "Couldn't send the FRONTEND_READY message to the backend!");
rosfran@289
  1023
        else
rosfran@289
  1024
          GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
rosfran@124
  1025
      }
rosfran@52
  1026
      break;
rosfran@52
  1027
    default:
rosfran@52
  1028
      break;
rosfran@52
  1029
  }
rosfran@61
  1030
rosfran@61
  1031
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
rosfran@52
  1032
  if (ret == GST_STATE_CHANGE_FAILURE)
rosfran@52
  1033
    return ret;
rosfran@52
  1034
rosfran@52
  1035
  switch (transition) {
rosfran@52
  1036
    case GST_STATE_CHANGE_READY_TO_NULL:
rosfran@52
  1037
      break;
rosfran@61
  1038
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
rosfran@52
  1039
    case GST_STATE_CHANGE_PAUSED_TO_READY:
rosfran@61
  1040
      break;
rosfran@52
  1041
    default:
rosfran@52
  1042
      break;
rosfran@52
  1043
  }
rosfran@52
  1044
rosfran@52
  1045
  return ret;
rosfran@52
  1046
}
rosfran@52
  1047
rosfran@30
  1048
static void
leo_sobral@2
  1049
gst_mythtv_src_set_property (GObject * object, guint prop_id,
leo_sobral@2
  1050
    const GValue * value, GParamSpec * pspec)
leo_sobral@2
  1051
{
leo_sobral@2
  1052
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1053
leo_sobral@2
  1054
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1055
  switch (prop_id) {
leo_sobral@2
  1056
    case PROP_LOCATION:
rosfran@289
  1057
    {
rosfran@289
  1058
      if (!g_value_get_string (value)) {
rosfran@289
  1059
        GST_WARNING ("location property cannot be NULL");
leo_sobral@2
  1060
	break;
leo_sobral@2
  1061
      }
rosfran@289
  1062
rosfran@289
  1063
      if (mythtvsrc->uri_name != NULL) {
rosfran@289
  1064
        g_free (mythtvsrc->uri_name);
rosfran@289
  1065
        mythtvsrc->uri_name = NULL;
rosfran@289
  1066
      }
rosfran@289
  1067
      mythtvsrc->uri_name = g_value_dup_string (value);
rosfran@289
  1068
rosfran@289
  1069
      break;
rosfran@289
  1070
    }
leo_sobral@2
  1071
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1072
    case PROP_GMYTHTV_DBG:
rosfran@289
  1073
    {
rosfran@289
  1074
      mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
rosfran@289
  1075
      break;
rosfran@289
  1076
    }
rosfran@289
  1077
#endif
rosfran@289
  1078
    case PROP_GMYTHTV_VERSION:
rosfran@289
  1079
    {
rosfran@289
  1080
      mythtvsrc->mythtv_version = g_value_get_int (value);
rosfran@289
  1081
      break;
rosfran@289
  1082
    }
rosfran@289
  1083
    case PROP_GMYTHTV_LIVEID:
rosfran@289
  1084
    {
rosfran@289
  1085
      mythtvsrc->live_tv_id = g_value_get_int (value);
rosfran@289
  1086
      break;
rosfran@289
  1087
    }
rosfran@289
  1088
    case PROP_GMYTHTV_LIVE:
rosfran@289
  1089
    {
rosfran@289
  1090
      mythtvsrc->live_tv = g_value_get_boolean (value);
rosfran@289
  1091
      break;
rosfran@289
  1092
    }
rosfran@289
  1093
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@289
  1094
    {
rosfran@289
  1095
      mythtvsrc->enable_timing_position = g_value_get_boolean (value);
rosfran@289
  1096
      break;
rosfran@289
  1097
    }
rosfran@289
  1098
    case PROP_GMYTHTV_LIVE_CHAINID:
rosfran@289
  1099
    {
rosfran@289
  1100
      if (!g_value_get_string (value)) {
rosfran@289
  1101
        GST_WARNING ("MythTV Live chainid property cannot be NULL");
leo_sobral@2
  1102
	break;
leo_sobral@2
  1103
      }
rosfran@289
  1104
rosfran@289
  1105
      if (mythtvsrc->live_chain_id != NULL) {
rosfran@289
  1106
        g_free (mythtvsrc->live_chain_id);
rosfran@289
  1107
        mythtvsrc->live_chain_id = NULL;
leo_sobral@2
  1108
      }
rosfran@289
  1109
      mythtvsrc->live_chain_id = g_value_dup_string (value);
rosfran@289
  1110
      break;
rosfran@289
  1111
    }
rosfran@70
  1112
    case PROP_GMYTHTV_CHANNEL_NUM:
rosfran@289
  1113
    {
rosfran@308
  1114
      mythtvsrc->channel_name = g_value_dup_string (value);
rosfran@289
  1115
      break;
rosfran@289
  1116
    }
renatofilho@575
  1117
    case PROP_GMYTHTV_MAX_TRY:
renatofilho@575
  1118
    {
renatofilho@575
  1119
      mythtvsrc->max_try = g_value_get_int (value);
renatofilho@575
  1120
      break;
renatofilho@575
  1121
    }
leo_sobral@2
  1122
    default:
leo_sobral@2
  1123
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1124
      break;
leo_sobral@2
  1125
  }
rosfran@289
  1126
leo_sobral@2
  1127
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1128
}
leo_sobral@2
  1129
rosfran@100
  1130
static void
leo_sobral@2
  1131
gst_mythtv_src_get_property (GObject * object, guint prop_id,
leo_sobral@2
  1132
    GValue * value, GParamSpec * pspec)
leo_sobral@2
  1133
{
leo_sobral@2
  1134
  GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
leo_sobral@2
  1135
leo_sobral@2
  1136
  GST_OBJECT_LOCK (mythtvsrc);
leo_sobral@2
  1137
  switch (prop_id) {
leo_sobral@2
  1138
    case PROP_LOCATION:
rosfran@289
  1139
    {
rosfran@528
  1140
      g_value_set_string (value, mythtvsrc->uri_name);
rosfran@289
  1141
      break;
rosfran@289
  1142
    }
leo_sobral@2
  1143
#ifndef GST_DISABLE_GST_DEBUG
rosfran@40
  1144
    case PROP_GMYTHTV_DBG:
rosfran@289
  1145
      g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
leo_sobral@2
  1146
      break;
leo_sobral@2
  1147
#endif
rosfran@40
  1148
    case PROP_GMYTHTV_VERSION:
rosfran@289
  1149
    {
rosfran@289
  1150
      g_value_set_int (value, mythtvsrc->mythtv_version);
rosfran@289
  1151
      break;
rosfran@289
  1152
    }
rosfran@40
  1153
    case PROP_GMYTHTV_LIVEID:
rosfran@289
  1154
    {
rosfran@289
  1155
      g_value_set_int (value, mythtvsrc->live_tv_id);
rosfran@289
  1156
      break;
rosfran@289
  1157
    }
rosfran@40
  1158
    case PROP_GMYTHTV_LIVE:
rosfran@289
  1159
      g_value_set_boolean (value, mythtvsrc->live_tv);
leo_sobral@2
  1160
      break;
rosfran@52
  1161
    case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
rosfran@289
  1162
      g_value_set_boolean (value, mythtvsrc->enable_timing_position);
rosfran@52
  1163
      break;
rosfran@40
  1164
    case PROP_GMYTHTV_LIVE_CHAINID:
rosfran@289
  1165
    {
rosfran@528
  1166
      g_value_set_string (value, mythtvsrc->live_chain_id);
rosfran@289
  1167
      break;
rosfran@289
  1168
    }
rosfran@70
  1169
    case PROP_GMYTHTV_CHANNEL_NUM:
rosfran@289
  1170
    {
rosfran@308
  1171
      g_value_set_string (value, mythtvsrc->channel_name);
rosfran@289
  1172
      break;
rosfran@289
  1173
    }
renatofilho@575
  1174
    case PROP_GMYTHTV_MAX_TRY:
renatofilho@575
  1175
    {
renatofilho@575
  1176
      g_value_set_int (value, mythtvsrc->max_try);
renatofilho@575
  1177
      break;
renatofilho@575
  1178
    }
renatofilho@575
  1179
leo_sobral@2
  1180
    default:
leo_sobral@2
  1181
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
leo_sobral@2
  1182
      break;
leo_sobral@2
  1183
  }
leo_sobral@2
  1184
  GST_OBJECT_UNLOCK (mythtvsrc);
leo_sobral@2
  1185
}
leo_sobral@2
  1186
rosfran@40
  1187
static gboolean
leo_sobral@2
  1188
plugin_init (GstPlugin * plugin)
leo_sobral@2
  1189
{
leo_sobral@2
  1190
  return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
leo_sobral@2
  1191
      GST_TYPE_MYTHTV_SRC);
leo_sobral@2
  1192
}
leo_sobral@2
  1193
leo_sobral@2
  1194
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
leo_sobral@2
  1195
    GST_VERSION_MINOR,
leo_sobral@2
  1196
    "mythtv",
leo_sobral@2
  1197
    "lib MythTV src",
rosfran@312
  1198
    plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
leo_sobral@2
  1199
leo_sobral@2
  1200
leo_sobral@2
  1201
/*** GSTURIHANDLER INTERFACE *************************************************/
rosfran@289
  1202
static guint
leo_sobral@2
  1203
gst_mythtv_src_uri_get_type (void)
leo_sobral@2
  1204
{
leo_sobral@2
  1205
  return GST_URI_SRC;
leo_sobral@2
  1206
}
leo_sobral@2
  1207
rosfran@289
  1208
static gchar **
leo_sobral@2
  1209
gst_mythtv_src_uri_get_protocols (void)
leo_sobral@2
  1210
{
leo_sobral@2
  1211
  static gchar *protocols[] = { "myth", "myths", NULL };
leo_sobral@2
  1212
leo_sobral@2
  1213
  return protocols;
leo_sobral@2
  1214
}
leo_sobral@2
  1215
rosfran@289
  1216
static const gchar *
leo_sobral@2
  1217
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
leo_sobral@2
  1218
{
leo_sobral@2
  1219
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1220
leo_sobral@2
  1221
  return src->uri_name;
leo_sobral@2
  1222
}
leo_sobral@2
  1223
rosfran@289
  1224
static gboolean
leo_sobral@2
  1225
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
leo_sobral@2
  1226
{
leo_sobral@2
  1227
  GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
leo_sobral@2
  1228
leo_sobral@2
  1229
  gchar *protocol;
leo_sobral@2
  1230
leo_sobral@2
  1231
  protocol = gst_uri_get_protocol (uri);
leo_sobral@2
  1232
  if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
leo_sobral@2
  1233
    g_free (protocol);
leo_sobral@2
  1234
    return FALSE;
leo_sobral@2
  1235
  }
leo_sobral@2
  1236
  g_free (protocol);
leo_sobral@2
  1237
  g_object_set (src, "location", uri, NULL);
leo_sobral@2
  1238
leo_sobral@2
  1239
  return TRUE;
leo_sobral@2
  1240
}
leo_sobral@2
  1241
rosfran@289
  1242
static void
leo_sobral@2
  1243
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
leo_sobral@2
  1244
{
leo_sobral@2
  1245
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
leo_sobral@2
  1246
leo_sobral@2
  1247
  iface->get_type = gst_mythtv_src_uri_get_type;
leo_sobral@2
  1248
  iface->get_protocols = gst_mythtv_src_uri_get_protocols;
leo_sobral@2
  1249
  iface->get_uri = gst_mythtv_src_uri_get_uri;
leo_sobral@2
  1250
  iface->set_uri = gst_mythtv_src_uri_set_uri;
leo_sobral@2
  1251
}
leo_sobral@2
  1252
rosfran@289
  1253
void
leo_sobral@2
  1254
size_header_handler (void *userdata, const char *value)
leo_sobral@2
  1255
{
leo_sobral@2
  1256
  GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
leo_sobral@2
  1257
leo_sobral@2
  1258
  GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
leo_sobral@2
  1259
}