1.1 --- a/gst-gmyth/mythsrc/gstmythtvsrc.c Thu May 31 16:02:53 2007 +0100
1.2 +++ b/gst-gmyth/mythsrc/gstmythtvsrc.c Thu Jun 14 18:21:08 2007 +0100
1.3 @@ -84,7 +84,7 @@
1.4 #include <string.h>
1.5 #include <unistd.h>
1.6
1.7 -GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
1.8 +GST_DEBUG_CATEGORY_STATIC(mythtvsrc_debug);
1.9 #define GST_CAT_DEFAULT mythtvsrc_debug
1.10
1.11 #define GST_GMYTHTV_ID_NUM 1
1.12 @@ -108,17 +108,17 @@
1.13 #define INTERNAL_BUFFER_SIZE (90*1024)
1.14
1.15 static const GstElementDetails gst_mythtv_src_details =
1.16 -GST_ELEMENT_DETAILS ("MythTV client source",
1.17 - "Source/Network",
1.18 - "Control and receive data as a client over the network "
1.19 - "via raw socket connections using the MythTV protocol",
1.20 - "Rosfran Borges <rosfran.borges@indt.org.br>");
1.21 +GST_ELEMENT_DETAILS("MythTV client source",
1.22 + "Source/Network",
1.23 + "Control and receive data as a client over the network "
1.24 + "via raw socket connections using the MythTV protocol",
1.25 + "Rosfran Borges <rosfran.borges@indt.org.br>");
1.26
1.27 -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
1.28 - GST_PAD_SRC,
1.29 - GST_PAD_ALWAYS,
1.30 - GST_STATIC_CAPS_ANY );
1.31 - /* GST_STATIC_CAPS ("video/x-nuv")); */
1.32 +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE("src",
1.33 + GST_PAD_SRC,
1.34 + GST_PAD_ALWAYS,
1.35 + GST_STATIC_CAPS_ANY);
1.36 + /* GST_STATIC_CAPS ("video/x-nuv")); */
1.37
1.38 enum
1.39 {
1.40 @@ -136,71 +136,73 @@
1.41 PROP_GMYTHTV_MAX_TRY
1.42 };
1.43
1.44 -static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
1.45 +static void gst_mythtv_src_clear(GstMythtvSrc * mythtv_src);
1.46
1.47 -static void gst_mythtv_src_finalize (GObject * gobject);
1.48 +static void gst_mythtv_src_finalize(GObject * gobject);
1.49
1.50 -static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
1.51 - GstBuffer ** outbuf);
1.52 +static GstFlowReturn gst_mythtv_src_create(GstPushSrc * psrc,
1.53 + GstBuffer ** outbuf);
1.54
1.55 -static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
1.56 -static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
1.57 -static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
1.58 -static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
1.59 +static gboolean gst_mythtv_src_start(GstBaseSrc * bsrc);
1.60 +static gboolean gst_mythtv_src_stop(GstBaseSrc * bsrc);
1.61 +static gboolean gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size);
1.62 +static gboolean gst_mythtv_src_is_seekable(GstBaseSrc * push_src);
1.63
1.64 -static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
1.65 - GstSegment * segment);
1.66 +static gboolean gst_mythtv_src_do_seek(GstBaseSrc * base,
1.67 + GstSegment * segment);
1.68
1.69 static GstStateChangeReturn
1.70 -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
1.71 +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition);
1.72
1.73 -static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
1.74 - const GValue * value, GParamSpec * pspec);
1.75 -static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
1.76 - GValue * value, GParamSpec * pspec);
1.77 +static void gst_mythtv_src_set_property(GObject * object, guint prop_id,
1.78 + const GValue * value,
1.79 + GParamSpec * pspec);
1.80 +static void gst_mythtv_src_get_property(GObject * object, guint prop_id,
1.81 + GValue * value, GParamSpec * pspec);
1.82
1.83 -static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
1.84 - gpointer iface_data);
1.85 +static void gst_mythtv_src_uri_handler_init(gpointer g_iface,
1.86 + gpointer iface_data);
1.87
1.88 -static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
1.89 +static gboolean gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query);
1.90
1.91 -static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.92 +static gboolean gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event);
1.93
1.94 -static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
1.95 - GByteArray * data_ptr);
1.96 +static GMythFileReadResult do_read_request_response(GstMythtvSrc * src,
1.97 + guint size,
1.98 + GByteArray * data_ptr);
1.99
1.100 static void
1.101 -_urihandler_init (GType type)
1.102 +_urihandler_init(GType type)
1.103 {
1.104 static const GInterfaceInfo urihandler_info = {
1.105 - gst_mythtv_src_uri_handler_init,
1.106 - NULL,
1.107 - NULL
1.108 + gst_mythtv_src_uri_handler_init,
1.109 + NULL,
1.110 + NULL
1.111 };
1.112
1.113 - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
1.114 + g_type_add_interface_static(type, GST_TYPE_URI_HANDLER, &urihandler_info);
1.115
1.116 - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
1.117 + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
1.118 }
1.119
1.120 -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
1.121 - GST_TYPE_PUSH_SRC, _urihandler_init)
1.122 +GST_BOILERPLATE_FULL(GstMythtvSrc, gst_mythtv_src, GstPushSrc,
1.123 + GST_TYPE_PUSH_SRC, _urihandler_init)
1.124 + static void gst_mythtv_src_base_init(gpointer g_class)
1.125 +{
1.126 + GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
1.127
1.128 - static void gst_mythtv_src_base_init (gpointer g_class)
1.129 -{
1.130 - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
1.131 + gst_element_class_add_pad_template(element_class,
1.132 + gst_static_pad_template_get
1.133 + (&srctemplate));
1.134
1.135 - gst_element_class_add_pad_template (element_class,
1.136 - gst_static_pad_template_get (&srctemplate));
1.137 -
1.138 - gst_element_class_set_details (element_class, &gst_mythtv_src_details);
1.139 + gst_element_class_set_details(element_class, &gst_mythtv_src_details);
1.140
1.141 element_class->change_state = gst_mythtv_src_change_state;
1.142
1.143 }
1.144
1.145 static void
1.146 -gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
1.147 +gst_mythtv_src_class_init(GstMythtvSrcClass * klass)
1.148 {
1.149 GObjectClass *gobject_class;
1.150 GstPushSrcClass *gstpushsrc_class;
1.151 @@ -215,60 +217,64 @@
1.152 gobject_class->finalize = gst_mythtv_src_finalize;
1.153
1.154 g_object_class_install_property
1.155 - (gobject_class, PROP_LOCATION,
1.156 - g_param_spec_string ("location", "Location",
1.157 - "The location. In the form:"
1.158 - "\n\t\t\tmyth://a.com/file.nuv"
1.159 - "\n\t\t\tmyth://a.com:23223/file.nuv "
1.160 - "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
1.161 - "", G_PARAM_READWRITE));
1.162 + (gobject_class, PROP_LOCATION,
1.163 + g_param_spec_string("location", "Location",
1.164 + "The location. In the form:"
1.165 + "\n\t\t\tmyth://a.com/file.nuv"
1.166 + "\n\t\t\tmyth://a.com:23223/file.nuv "
1.167 + "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
1.168 + "", G_PARAM_READWRITE));
1.169
1.170 g_object_class_install_property
1.171 - (gobject_class, PROP_GMYTHTV_VERSION,
1.172 - g_param_spec_int ("mythtv-version", "mythtv-version",
1.173 - "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
1.174 + (gobject_class, PROP_GMYTHTV_VERSION,
1.175 + g_param_spec_int("mythtv-version", "mythtv-version",
1.176 + "Change MythTV version", 26, 30, 26,
1.177 + G_PARAM_READWRITE));
1.178
1.179 g_object_class_install_property
1.180 - (gobject_class, PROP_GMYTHTV_LIVEID,
1.181 - g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
1.182 - "Change MythTV version",
1.183 - 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
1.184 + (gobject_class, PROP_GMYTHTV_LIVEID,
1.185 + g_param_spec_int("mythtv-live-id", "mythtv-live-id",
1.186 + "Change MythTV version",
1.187 + 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
1.188
1.189 g_object_class_install_property
1.190 - (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
1.191 - g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
1.192 - "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
1.193 + (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
1.194 + g_param_spec_string("mythtv-live-chainid", "mythtv-live-chainid",
1.195 + "Sets the MythTV chain ID (from TV Chain)", "",
1.196 + G_PARAM_READWRITE));
1.197
1.198 g_object_class_install_property
1.199 - (gobject_class, PROP_GMYTHTV_LIVE,
1.200 - g_param_spec_boolean ("mythtv-live", "mythtv-live",
1.201 - "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
1.202 + (gobject_class, PROP_GMYTHTV_LIVE,
1.203 + g_param_spec_boolean("mythtv-live", "mythtv-live",
1.204 + "Enable MythTV Live TV content streaming", FALSE,
1.205 + G_PARAM_READWRITE));
1.206
1.207 g_object_class_install_property
1.208 - (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
1.209 - g_param_spec_boolean ("mythtv-enable-timing-position",
1.210 - "mythtv-enable-timing-position",
1.211 - "Enable MythTV Live TV content size continuous updating", FALSE,
1.212 - G_PARAM_READWRITE));
1.213 + (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
1.214 + g_param_spec_boolean("mythtv-enable-timing-position",
1.215 + "mythtv-enable-timing-position",
1.216 + "Enable MythTV Live TV content size continuous updating",
1.217 + FALSE, G_PARAM_READWRITE));
1.218
1.219 g_object_class_install_property
1.220 - (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
1.221 - g_param_spec_string ("mythtv-channel", "mythtv-channel",
1.222 - "Change MythTV channel number",
1.223 - "", G_PARAM_READWRITE));
1.224 + (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
1.225 + g_param_spec_string("mythtv-channel", "mythtv-channel",
1.226 + "Change MythTV channel number",
1.227 + "", G_PARAM_READWRITE));
1.228
1.229 g_object_class_install_property
1.230 - (gobject_class, PROP_GMYTHTV_MAX_TRY,
1.231 - g_param_spec_int ("max-try", "max-try",
1.232 - "Set the max try for get MythTV free recorder",
1.233 - 0, G_MAXINT, 10, G_PARAM_READWRITE));
1.234 + (gobject_class, PROP_GMYTHTV_MAX_TRY,
1.235 + g_param_spec_int("max-try", "max-try",
1.236 + "Set the max try for get MythTV free recorder",
1.237 + 0, G_MAXINT, 10, G_PARAM_READWRITE));
1.238
1.239
1.240 #ifndef GST_DISABLE_GST_DEBUG
1.241 g_object_class_install_property
1.242 - (gobject_class, PROP_GMYTHTV_DBG,
1.243 - g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
1.244 - "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
1.245 + (gobject_class, PROP_GMYTHTV_DBG,
1.246 + g_param_spec_boolean("mythtv-debug", "mythtv-debug",
1.247 + "Enable MythTV debug messages", FALSE,
1.248 + G_PARAM_READWRITE));
1.249 #endif
1.250
1.251 gstbasesrc_class->start = gst_mythtv_src_start;
1.252 @@ -279,12 +285,12 @@
1.253 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
1.254 gstpushsrc_class->create = gst_mythtv_src_create;
1.255
1.256 - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
1.257 - "MythTV Client Source");
1.258 + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0,
1.259 + "MythTV Client Source");
1.260 }
1.261
1.262 static void
1.263 -gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
1.264 +gst_mythtv_src_init(GstMythtvSrc * this, GstMythtvSrcClass * g_class)
1.265 {
1.266 this->file = NULL;
1.267
1.268 @@ -308,7 +314,7 @@
1.269 this->enable_timing_position = FALSE;
1.270 this->update_prog_chain = FALSE;
1.271
1.272 - this->user_agent = g_strdup ("mythtvsrc");
1.273 + this->user_agent = g_strdup("mythtvsrc");
1.274 this->update_prog_chain = FALSE;
1.275
1.276 this->channel_name = NULL;
1.277 @@ -319,114 +325,132 @@
1.278
1.279 this->wait_to_transfer = 0;
1.280
1.281 - gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
1.282 + gst_base_src_set_format(GST_BASE_SRC(this), GST_FORMAT_BYTES);
1.283
1.284 - gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
1.285 - gst_mythtv_src_handle_event);
1.286 - gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
1.287 - gst_mythtv_src_handle_query);
1.288 + gst_pad_set_event_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.289 + gst_mythtv_src_handle_event);
1.290 + gst_pad_set_query_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
1.291 + gst_mythtv_src_handle_query);
1.292
1.293 }
1.294
1.295 static void
1.296 -gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
1.297 +gst_mythtv_src_clear(GstMythtvSrc * mythtv_src)
1.298 {
1.299 mythtv_src->unique_setup = FALSE;
1.300
1.301 - if (mythtv_src->spawn_livetv) {
1.302 - g_object_unref (mythtv_src->spawn_livetv);
1.303 - mythtv_src->spawn_livetv = NULL;
1.304 - }
1.305 + if (mythtv_src->spawn_livetv)
1.306 + {
1.307 + g_object_unref(mythtv_src->spawn_livetv);
1.308 + mythtv_src->spawn_livetv = NULL;
1.309 + }
1.310
1.311 - if (mythtv_src->file) {
1.312 - g_object_unref (mythtv_src->file);
1.313 - mythtv_src->file = NULL;
1.314 - }
1.315 + if (mythtv_src->file)
1.316 + {
1.317 + g_object_unref(mythtv_src->file);
1.318 + mythtv_src->file = NULL;
1.319 + }
1.320
1.321 - if (mythtv_src->backend_info) {
1.322 - g_object_unref (mythtv_src->backend_info);
1.323 - mythtv_src->backend_info = NULL;
1.324 - }
1.325 + if (mythtv_src->backend_info)
1.326 + {
1.327 + g_object_unref(mythtv_src->backend_info);
1.328 + mythtv_src->backend_info = NULL;
1.329 + }
1.330
1.331 - if (mythtv_src->bytes_queue) {
1.332 - g_byte_array_free (mythtv_src->bytes_queue, TRUE);
1.333 - mythtv_src->bytes_queue = NULL;
1.334 - }
1.335 + if (mythtv_src->bytes_queue)
1.336 + {
1.337 + g_byte_array_free(mythtv_src->bytes_queue, TRUE);
1.338 + mythtv_src->bytes_queue = NULL;
1.339 + }
1.340 }
1.341
1.342 static void
1.343 -gst_mythtv_src_finalize (GObject * gobject)
1.344 +gst_mythtv_src_finalize(GObject * gobject)
1.345 {
1.346 - GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
1.347 + GstMythtvSrc *this = GST_MYTHTV_SRC(gobject);
1.348
1.349 - gst_mythtv_src_clear (this);
1.350 + gst_mythtv_src_clear(this);
1.351
1.352 - if (this->uri_name) {
1.353 - g_free (this->uri_name);
1.354 - this->uri_name = NULL;
1.355 - }
1.356 + if (this->uri_name)
1.357 + {
1.358 + g_free(this->uri_name);
1.359 + this->uri_name = NULL;
1.360 + }
1.361
1.362 - if (this->user_agent) {
1.363 - g_free (this->user_agent);
1.364 - this->user_agent = NULL;
1.365 - }
1.366 + if (this->user_agent)
1.367 + {
1.368 + g_free(this->user_agent);
1.369 + this->user_agent = NULL;
1.370 + }
1.371
1.372 - G_OBJECT_CLASS (parent_class)->finalize (gobject);
1.373 + G_OBJECT_CLASS(parent_class)->finalize(gobject);
1.374 }
1.375
1.376 static GMythFileReadResult
1.377 -do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
1.378 +do_read_request_response(GstMythtvSrc * src, guint size,
1.379 + GByteArray * data_ptr)
1.380 {
1.381 gint read = 0;
1.382 guint sizetoread = size;
1.383 gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
1.384 GMythFileReadResult result;
1.385
1.386 - GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
1.387 + GST_LOG_OBJECT(src, "Starting: Reading %d bytes...", sizetoread);
1.388
1.389 - /* Loop sending the Myth File Transfer request:
1.390 - * Retry whilst authentication fails and we supply it. */
1.391 + /* Loop sending the Myth File Transfer request:
1.392 + * Retry whilst authentication fails and we supply it. */
1.393
1.394 - while (sizetoread == size && --max_iters > 0) {
1.395 - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
1.396 - if ( IS_GMYTH_FILE_LOCAL(src->file) )
1.397 - result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
1.398 - data_ptr, sizetoread, src->live_tv);
1.399 - else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
1.400 - result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
1.401 - data_ptr, sizetoread, src->live_tv );
1.402 + while (sizetoread == size && --max_iters > 0)
1.403 + {
1.404 + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
1.405 + if (IS_GMYTH_FILE_LOCAL(src->file))
1.406 + result = gmyth_file_local_read(GMYTH_FILE_LOCAL(src->file),
1.407 + data_ptr, sizetoread, src->live_tv);
1.408 + else if (IS_GMYTH_FILE_TRANSFER(src->file))
1.409 + result = gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(src->file),
1.410 + data_ptr, sizetoread, src->live_tv);
1.411
1.412 - if (data_ptr->len > 0) {
1.413 - read += data_ptr->len;
1.414 - sizetoread -= data_ptr->len;
1.415 - } else if (data_ptr->len <= 0) {
1.416 - if (src->live_tv == FALSE) {
1.417 - result = GMYTH_FILE_READ_EOF;
1.418 - goto eos;
1.419 - } else {
1.420 - if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
1.421 - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
1.422 - goto done;
1.423 - } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */
1.424 - GST_INFO_OBJECT (src,
1.425 - "[LiveTV] FileTransfer - Go to athe next program chain!");
1.426 - src->update_prog_chain = TRUE;
1.427 - continue;
1.428 - }
1.429 - goto done;
1.430 - }
1.431 + if (data_ptr->len > 0)
1.432 + {
1.433 + read += data_ptr->len;
1.434 + sizetoread -= data_ptr->len;
1.435 + }
1.436 + else if (data_ptr->len <= 0)
1.437 + {
1.438 + if (src->live_tv == FALSE)
1.439 + {
1.440 + result = GMYTH_FILE_READ_EOF;
1.441 + goto eos;
1.442 + }
1.443 + else
1.444 + {
1.445 + if (result == GMYTH_FILE_READ_ERROR)
1.446 + { /* -314 */
1.447 + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer READ_ERROR!");
1.448 + goto done;
1.449 + }
1.450 + else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)
1.451 + { /* -315 */
1.452 + GST_INFO_OBJECT(src,
1.453 + "[LiveTV] FileTransfer - Go to athe next program chain!");
1.454 + src->update_prog_chain = TRUE;
1.455 + continue;
1.456 + }
1.457 + goto done;
1.458 + }
1.459
1.460 - } /* else if (data_ptr->len == 0)
1.461 - goto done;*/
1.462 + } /* else if (data_ptr->len == 0)
1.463 + goto done; */
1.464
1.465 - if (read == sizetoread)
1.466 - goto done;
1.467 - }
1.468 + if (read == sizetoread)
1.469 + goto done;
1.470 + }
1.471
1.472 - if ((read < 0 && !src->live_tv) || max_iters == 0) {
1.473 - result = GMYTH_FILE_READ_EOF;
1.474 - goto eos;
1.475 - }
1.476 + if ((read < 0 && !src->live_tv) || max_iters == 0)
1.477 + {
1.478 + result = GMYTH_FILE_READ_EOF;
1.479 + goto eos;
1.480 + }
1.481
1.482 goto done;
1.483
1.484 @@ -438,471 +462,532 @@
1.485 }
1.486
1.487 static GstFlowReturn
1.488 -gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
1.489 +gst_mythtv_src_create(GstPushSrc * psrc, GstBuffer ** outbuf)
1.490 {
1.491 GstMythtvSrc *src;
1.492 GstFlowReturn ret = GST_FLOW_OK;
1.493 guint buffer_size_inter = 0;
1.494
1.495 - src = GST_MYTHTV_SRC (psrc);
1.496 + src = GST_MYTHTV_SRC(psrc);
1.497
1.498 - /* The caller should know the number of bytes and not read beyond EOS. */
1.499 - if (G_UNLIKELY (src->eos))
1.500 - goto eos;
1.501 - GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
1.502 - src->read_offset, MAX_READ_SIZE);
1.503 + /* The caller should know the number of bytes and not read beyond EOS. */
1.504 + if (G_UNLIKELY(src->eos))
1.505 + goto eos;
1.506 + GST_DEBUG_OBJECT(src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
1.507 + src->read_offset, MAX_READ_SIZE);
1.508
1.509 - GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
1.510 - (gint) src->buffer_remain, src->bytes_queue->len);
1.511 + GST_DEBUG_OBJECT(src, "Create: buffer_remain: %d, buffer_size = %d.",
1.512 + (gint) src->buffer_remain, src->bytes_queue->len);
1.513
1.514 program_chain_changed:
1.515 - /* just get from the byte array, no network effort... */
1.516 - if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
1.517 - GByteArray *buffer;
1.518 - GMythFileReadResult result = GMYTH_FILE_READ_OK;
1.519 -
1.520 - buffer = NULL;
1.521 - buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
1.522 + /* just get from the byte array, no network effort... */
1.523 + if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE)
1.524 + {
1.525 + GByteArray *buffer;
1.526 + GMythFileReadResult result = GMYTH_FILE_READ_OK;
1.527
1.528 - if (buffer_size_inter > REQUEST_MAX_SIZE)
1.529 - buffer_size_inter = REQUEST_MAX_SIZE;
1.530 + buffer = NULL;
1.531 + buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
1.532
1.533 - buffer = g_byte_array_new ();
1.534 + if (buffer_size_inter > REQUEST_MAX_SIZE)
1.535 + buffer_size_inter = REQUEST_MAX_SIZE;
1.536
1.537 - result = do_read_request_response (src, buffer_size_inter, buffer);
1.538 + buffer = g_byte_array_new();
1.539
1.540 - /* got the next program info? */
1.541 - if (G_UNLIKELY (src->update_prog_chain) || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) {
1.542 - GST_DEBUG_OBJECT (src, "Update PROGRAM CHAIN!!! buffer_size = %d.",
1.543 - src->bytes_queue->len);
1.544 - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.545 - gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, NULL));
1.546 + result = do_read_request_response(src, buffer_size_inter, buffer);
1.547 +
1.548 + /* got the next program info? */
1.549 + if (G_UNLIKELY(src->update_prog_chain)
1.550 + || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN))
1.551 + {
1.552 + GST_DEBUG_OBJECT(src, "Update PROGRAM CHAIN!!! buffer_size = %d.",
1.553 + src->bytes_queue->len);
1.554 + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)),
1.555 + gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM,
1.556 + NULL));
1.557 /*
1.558 gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.559 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
1.560 */
1.561 - src->update_prog_chain = FALSE;
1.562 - src->eos = FALSE;
1.563 + src->update_prog_chain = FALSE;
1.564 + src->eos = FALSE;
1.565
1.566 - if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {
1.567 - /*
1.568 - if (buffer != NULL) {
1.569 - g_byte_array_free (buffer, TRUE);
1.570 - buffer = NULL;
1.571 - }
1.572 - goto program_chain_changed; */
1.573 - } else if (result == GMYTH_FILE_READ_OK) {
1.574 - /* remove wasteful, NUV file header data */
1.575 - /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */
1.576 - /* TODO: need to send a new segment event to NUVDemux? */
1.577 - //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.578 - // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
1.579 + if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)
1.580 + {
1.581 + /*
1.582 + if (buffer != NULL) {
1.583 + g_byte_array_free (buffer, TRUE);
1.584 + buffer = NULL;
1.585 + }
1.586 + goto program_chain_changed; */
1.587 + }
1.588 + else if (result == GMYTH_FILE_READ_OK)
1.589 + {
1.590 + /* remove wasteful, NUV file header data */
1.591 + /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */
1.592 + /* TODO: need to send a new segment event to NUVDemux? */
1.593 + //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.594 + // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
1.595
1.596 - /* goto change_progchain; */
1.597 - }
1.598 + /* goto change_progchain; */
1.599 + }
1.600
1.601 - } /* */
1.602 + } /* */
1.603
1.604 - if (G_UNLIKELY (buffer->len < 0)) {
1.605 -
1.606 - if (buffer != NULL) {
1.607 - g_byte_array_free (buffer, TRUE);
1.608 - buffer = NULL;
1.609 - }
1.610 -
1.611 - if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
1.612 - goto change_progchain;
1.613 - else
1.614 - goto read_error;
1.615 - } else if (G_UNLIKELY (buffer->len == 0)) {
1.616 -
1.617 - if (buffer != NULL) {
1.618 - g_byte_array_free (buffer, TRUE);
1.619 - buffer = NULL;
1.620 - }
1.621 -
1.622 - if (!src->live_tv)
1.623 - goto done;
1.624 - else
1.625 - goto program_chain_changed;
1.626 - }
1.627 + if (G_UNLIKELY(buffer->len < 0))
1.628 + {
1.629
1.630 - src->bytes_queue =
1.631 - g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
1.632 - if (buffer->len > buffer_size_inter)
1.633 - GST_WARNING_OBJECT (src,
1.634 - "INCREASED buffer size! Backend sent more than we ask him... (%d)",
1.635 - abs (buffer->len - buffer_size_inter));
1.636 + if (buffer != NULL)
1.637 + {
1.638 + g_byte_array_free(buffer, TRUE);
1.639 + buffer = NULL;
1.640 + }
1.641
1.642 - src->buffer_remain += buffer->len;
1.643 + if (src->live_tv || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN))
1.644 + goto change_progchain;
1.645 + else
1.646 + goto read_error;
1.647 + }
1.648 + else if (G_UNLIKELY(buffer->len == 0))
1.649 + {
1.650
1.651 - if (buffer != NULL) {
1.652 - g_byte_array_free (buffer, TRUE);
1.653 - buffer = NULL;
1.654 - }
1.655 + if (buffer != NULL)
1.656 + {
1.657 + g_byte_array_free(buffer, TRUE);
1.658 + buffer = NULL;
1.659 + }
1.660
1.661 - /*
1.662 - GST_DEBUG_OBJECT (src,
1.663 - "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
1.664 - "OFFSET = %llu, CONTENT SIZE = %llu.", read,
1.665 - src->bytes_read, src->read_offset, src->content_size);
1.666 - */
1.667 - }
1.668 + if (!src->live_tv)
1.669 + goto done;
1.670 + else
1.671 + goto program_chain_changed;
1.672 + }
1.673 +
1.674 + src->bytes_queue =
1.675 + g_byte_array_append(src->bytes_queue, buffer->data, buffer->len);
1.676 + if (buffer->len > buffer_size_inter)
1.677 + GST_WARNING_OBJECT(src,
1.678 + "INCREASED buffer size! Backend sent more than we ask him... (%d)",
1.679 + abs(buffer->len - buffer_size_inter));
1.680 +
1.681 + src->buffer_remain += buffer->len;
1.682 +
1.683 + if (buffer != NULL)
1.684 + {
1.685 + g_byte_array_free(buffer, TRUE);
1.686 + buffer = NULL;
1.687 + }
1.688 +
1.689 + /*
1.690 + GST_DEBUG_OBJECT (src,
1.691 + "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
1.692 + "OFFSET = %llu, CONTENT SIZE = %llu.", read,
1.693 + src->bytes_read, src->read_offset, src->content_size);
1.694 + */
1.695 + }
1.696
1.697 guint buffer_size =
1.698 - (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.699 + (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
1.700
1.701 - *outbuf = gst_buffer_new ();
1.702 + *outbuf = gst_buffer_new();
1.703
1.704 - /*
1.705 - GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
1.706 - (buffer_size_inter ==
1.707 - 0) ? "NO, got from buffer" : "YES, go see the backend's log file",
1.708 - src->buffer_remain);
1.709 - */
1.710 + /*
1.711 + GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
1.712 + (buffer_size_inter ==
1.713 + 0) ? "NO, got from buffer" : "YES, go see the backend's log file",
1.714 + src->buffer_remain);
1.715 + */
1.716
1.717 - GST_BUFFER_SIZE (*outbuf) = buffer_size;
1.718 - GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
1.719 - GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
1.720 - g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
1.721 - GST_BUFFER_SIZE (*outbuf));
1.722 - GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
1.723 - GST_BUFFER_OFFSET_END (*outbuf) =
1.724 - src->read_offset + GST_BUFFER_SIZE (*outbuf);
1.725 + GST_BUFFER_SIZE(*outbuf) = buffer_size;
1.726 + GST_BUFFER_MALLOCDATA(*outbuf) = g_malloc0(GST_BUFFER_SIZE(*outbuf));
1.727 + GST_BUFFER_DATA(*outbuf) = GST_BUFFER_MALLOCDATA(*outbuf);
1.728 + g_memmove(GST_BUFFER_DATA((*outbuf)), src->bytes_queue->data,
1.729 + GST_BUFFER_SIZE(*outbuf));
1.730 + GST_BUFFER_OFFSET(*outbuf) = src->read_offset;
1.731 + GST_BUFFER_OFFSET_END(*outbuf) =
1.732 + src->read_offset + GST_BUFFER_SIZE(*outbuf);
1.733
1.734 - src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
1.735 + src->buffer_remain -= GST_BUFFER_SIZE(*outbuf);
1.736
1.737 - src->read_offset += GST_BUFFER_SIZE (*outbuf);
1.738 - src->bytes_read += GST_BUFFER_SIZE (*outbuf);
1.739 - //GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
1.740 - // GST_BUFFER_SIZE (*outbuf));
1.741 + src->read_offset += GST_BUFFER_SIZE(*outbuf);
1.742 + src->bytes_read += GST_BUFFER_SIZE(*outbuf);
1.743 + //GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
1.744 + // GST_BUFFER_SIZE (*outbuf));
1.745
1.746 - /* flushs the newly buffer got from byte array */
1.747 + /* flushs the newly buffer got from byte array */
1.748 src->bytes_queue =
1.749 - g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
1.750 + g_byte_array_remove_range(src->bytes_queue, 0, buffer_size);
1.751
1.752 - if ( G_UNLIKELY (src->eos) || ( !src->live_tv
1.753 - && ( src->bytes_read >= src->content_size ) ) )
1.754 - goto eos;
1.755 + if (G_UNLIKELY(src->eos) || (!src->live_tv
1.756 + && (src->bytes_read >= src->content_size)))
1.757 + goto eos;
1.758
1.759 done:
1.760 {
1.761 - const gchar *reason = gst_flow_get_name (ret);
1.762 - return ret;
1.763 + const gchar *reason = gst_flow_get_name(ret);
1.764 + return ret;
1.765 }
1.766 eos:
1.767 {
1.768 - const gchar *reason = gst_flow_get_name (ret);
1.769 + const gchar *reason = gst_flow_get_name(ret);
1.770
1.771 - GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
1.772 - return GST_FLOW_UNEXPECTED;
1.773 + GST_DEBUG_OBJECT(src, "pausing task, reason %s", reason);
1.774 + return GST_FLOW_UNEXPECTED;
1.775 }
1.776 - /* ERRORS */
1.777 + /* ERRORS */
1.778 read_error:
1.779 {
1.780 - GST_ELEMENT_ERROR (src, RESOURCE, READ,
1.781 - (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
1.782 - return GST_FLOW_ERROR;
1.783 + GST_ELEMENT_ERROR(src, RESOURCE, READ,
1.784 + (NULL), ("Could not read any bytes (%i, %s)", read,
1.785 + src->uri_name));
1.786 + return GST_FLOW_ERROR;
1.787 }
1.788 change_progchain:
1.789 {
1.790 - GST_ELEMENT_ERROR (src, RESOURCE, READ,
1.791 - (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
1.792 - src->uri_name));
1.793 + GST_ELEMENT_ERROR(src, RESOURCE, READ,
1.794 + (NULL),
1.795 + ("Seek failed, go to the next program info... (%i, %s)",
1.796 + read, src->uri_name));
1.797
1.798 /* TODO: need to send a new segment event to NUVDemux? */
1.799 - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
1.800 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
1.801 + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)),
1.802 + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME,
1.803 + 0, -1, 0));
1.804
1.805 - goto program_chain_changed;
1.806 + goto program_chain_changed;
1.807 }
1.808
1.809 }
1.810
1.811 gint64
1.812 -gst_mythtv_src_get_position (GstMythtvSrc * src)
1.813 +gst_mythtv_src_get_position(GstMythtvSrc * src)
1.814 {
1.815
1.816 gint64 size_tmp = 0;
1.817 guint max_tries = 2;
1.818
1.819 - if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
1.820 - GMYTHTV_TRANSFER_MAX_BUFFER)) {
1.821 + if (src->live_tv == TRUE && (abs(src->content_size - src->bytes_read) <
1.822 + GMYTHTV_TRANSFER_MAX_BUFFER))
1.823 + {
1.824
1.825 - get_file_pos:
1.826 - g_usleep (10);
1.827 - size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
1.828 - if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
1.829 - src->content_size = size_tmp;
1.830 - else if (size_tmp > 0 && --max_tries > 0)
1.831 - goto get_file_pos;
1.832 - GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
1.833 - /* sets the last content size amount before it can be updated */
1.834 - src->prev_content_size = src->content_size;
1.835 - }
1.836 + get_file_pos:
1.837 + g_usleep(10);
1.838 + size_tmp =
1.839 + gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
1.840 + if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
1.841 + src->content_size = size_tmp;
1.842 + else if (size_tmp > 0 && --max_tries > 0)
1.843 + goto get_file_pos;
1.844 + GST_LOG_OBJECT(src, "GET_POSITION: file_position = %lld", size_tmp);
1.845 + /* sets the last content size amount before it can be updated */
1.846 + src->prev_content_size = src->content_size;
1.847 + }
1.848
1.849 return src->content_size;
1.850
1.851 }
1.852
1.853 static gboolean
1.854 -gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
1.855 +gst_mythtv_src_do_seek(GstBaseSrc * base, GstSegment * segment)
1.856 {
1.857 - GstMythtvSrc *src = GST_MYTHTV_SRC (base);
1.858 + GstMythtvSrc *src = GST_MYTHTV_SRC(base);
1.859 gint64 new_offset = -1;
1.860 gint64 actual_seek = segment->start;
1.861 gboolean ret = TRUE;
1.862
1.863 - GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
1.864 + GST_LOG_OBJECT(src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
1.865
1.866 - if (segment->format == GST_FORMAT_TIME) {
1.867 - goto done;
1.868 - }
1.869 - GST_LOG_OBJECT (src,
1.870 - "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
1.871 - actual_seek, src->read_offset);
1.872 - /* verify if it needs to seek */
1.873 - if (src->read_offset != actual_seek) {
1.874 -
1.875 - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
1.876 - if ( IS_GMYTH_FILE_LOCAL(src->file) )
1.877 - new_offset =
1.878 - gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
1.879 - else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
1.880 - new_offset =
1.881 - gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
1.882 + if (segment->format == GST_FORMAT_TIME)
1.883 + {
1.884 + goto done;
1.885 + }
1.886 + GST_LOG_OBJECT(src,
1.887 + "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
1.888 + actual_seek, src->read_offset);
1.889 + /* verify if it needs to seek */
1.890 + if (src->read_offset != actual_seek)
1.891 + {
1.892
1.893 - GST_LOG_OBJECT (src,
1.894 - "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
1.895 - segment->start, src->read_offset, new_offset);
1.896 - if (G_UNLIKELY (new_offset < 0)) {
1.897 - ret = FALSE;
1.898 - if (!src->live_tv)
1.899 - goto eos;
1.900 - }
1.901 + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
1.902 + if (IS_GMYTH_FILE_LOCAL(src->file))
1.903 + new_offset =
1.904 + gmyth_file_local_seek(GMYTH_FILE_LOCAL(src->file), segment->start,
1.905 + G_SEEK_SET);
1.906 + else if (IS_GMYTH_FILE_TRANSFER(src->file))
1.907 + new_offset =
1.908 + gmyth_file_transfer_seek(GMYTH_FILE_TRANSFER(src->file),
1.909 + segment->start, SEEK_SET);
1.910
1.911 - src->read_offset = new_offset;
1.912 + GST_LOG_OBJECT(src,
1.913 + "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
1.914 + segment->start, src->read_offset, new_offset);
1.915 + if (G_UNLIKELY(new_offset < 0))
1.916 + {
1.917 + ret = FALSE;
1.918 + if (!src->live_tv)
1.919 + goto eos;
1.920 + }
1.921
1.922 - if (ret == FALSE) {
1.923 - GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
1.924 - }
1.925 + src->read_offset = new_offset;
1.926
1.927 - }
1.928 + if (ret == FALSE)
1.929 + {
1.930 + GST_INFO_OBJECT(src, "Failed to set the SEEK on segment!");
1.931 + }
1.932 +
1.933 + }
1.934
1.935 done:
1.936 return ret;
1.937
1.938 eos:
1.939 {
1.940 - GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
1.941 - return FALSE;
1.942 + GST_DEBUG_OBJECT(src, "EOS found on seeking!!!");
1.943 + return FALSE;
1.944 }
1.945
1.946 }
1.947
1.948 /* create a socket for connecting to remote server */
1.949 static gboolean
1.950 -gst_mythtv_src_start (GstBaseSrc * bsrc)
1.951 +gst_mythtv_src_start(GstBaseSrc * bsrc)
1.952 {
1.953 - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1.954 + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
1.955
1.956 - GString *chain_id_local = NULL;
1.957 + GString *chain_id_local = NULL;
1.958 GMythURI *gmyth_uri = NULL;
1.959 gboolean ret = TRUE;
1.960 GstMessage *msg;
1.961
1.962 - if (src->unique_setup == FALSE) {
1.963 - src->unique_setup = TRUE;
1.964 - } else {
1.965 - goto done;
1.966 - }
1.967 -
1.968 - gmyth_uri = gmyth_uri_new_with_value (src->uri_name);
1.969 - src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
1.970 - src->live_tv = gmyth_uri_is_livetv( gmyth_uri );
1.971 - /* testing UPnP... */
1.972 - /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
1.973 - if ( src->live_tv ) {
1.974 - src->spawn_livetv = gmyth_livetv_new (src->backend_info);
1.975 -
1.976 - gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
1.977 - if ( ch != NULL )
1.978 - src->channel_name = ch;
1.979 -
1.980 - if (src->channel_name != NULL) {
1.981 - gboolean result;
1.982 - result = gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name);
1.983 - if (result == FALSE) {
1.984 - GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
1.985 - ret = FALSE;
1.986 - goto init_failed;
1.987 - }
1.988 + if (src->unique_setup == FALSE)
1.989 + {
1.990 + src->unique_setup = TRUE;
1.991 + }
1.992 + else
1.993 + {
1.994 + goto done;
1.995 + }
1.996
1.997 - } else {
1.998 - if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
1.999 - GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
1.1000 - ret = FALSE;
1.1001 - goto init_failed;
1.1002 - }
1.1003 - }
1.1004 + gmyth_uri = gmyth_uri_new_with_value(src->uri_name);
1.1005 + src->backend_info = gmyth_backend_info_new_with_uri(src->uri_name);
1.1006 + src->live_tv = gmyth_uri_is_livetv(gmyth_uri);
1.1007 + /* testing UPnP... */
1.1008 + /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
1.1009 + if (src->live_tv)
1.1010 + {
1.1011 + src->spawn_livetv = gmyth_livetv_new(src->backend_info);
1.1012
1.1013 - /* testing change channel... */
1.1014 - /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
1.1015 + gchar *ch = gmyth_uri_get_channel_name(gmyth_uri);
1.1016 + if (ch != NULL)
1.1017 + src->channel_name = ch;
1.1018
1.1019 - src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
1.1020 + if (src->channel_name != NULL)
1.1021 + {
1.1022 + gboolean result;
1.1023 + result =
1.1024 + gmyth_livetv_channel_name_setup(src->spawn_livetv,
1.1025 + src->channel_name);
1.1026 + if (result == FALSE)
1.1027 + {
1.1028 + GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
1.1029 + ret = FALSE;
1.1030 + goto init_failed;
1.1031 + }
1.1032
1.1033 - if (NULL == src->file) {
1.1034 - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
1.1035 - ret = FALSE;
1.1036 - goto init_failed;
1.1037 - }
1.1038 -
1.1039 - /* Check if the file is local to this specific client renderer */
1.1040 - if ( gmyth_uri_is_local_file(gmyth_uri) )
1.1041 - ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
1.1042 - else
1.1043 - ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ?
1.1044 - gmyth_uri_get_path(src->spawn_livetv->uri) :
1.1045 - src->spawn_livetv->proginfo->pathname->str );
1.1046 -
1.1047 - /* sets the mythtvsrc "location" property */
1.1048 - g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
1.1049 + }
1.1050 + else
1.1051 + {
1.1052 + if (gmyth_livetv_setup(src->spawn_livetv) == FALSE)
1.1053 + {
1.1054 + GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
1.1055 + ret = FALSE;
1.1056 + goto init_failed;
1.1057 + }
1.1058 + }
1.1059
1.1060 - if ( !ret )
1.1061 + /* testing change channel... */
1.1062 + /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
1.1063 +
1.1064 + src->file =
1.1065 + GMYTH_FILE(gmyth_livetv_create_file_transfer(src->spawn_livetv));
1.1066 +
1.1067 + if (NULL == src->file)
1.1068 {
1.1069 - GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
1.1070 - g_object_unref( src->file );
1.1071 - src->file = NULL;
1.1072 - goto init_failed;
1.1073 + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer equals to NULL");
1.1074 + ret = FALSE;
1.1075 + goto init_failed;
1.1076 }
1.1077 - } else {
1.1078 -
1.1079 - /* Check if the file is local to this specific client renderer, and tries to open
1.1080 - * a local connection
1.1081 - */
1.1082 - if ( gmyth_uri_is_local_file(gmyth_uri) )
1.1083 - {
1.1084 - src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
1.1085 - ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
1.1086 - } else {
1.1087 - src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
1.1088 - ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
1.1089 - }
1.1090
1.1091 - } /* if (else) - recorded FileTransfer */
1.1092 + /* Check if the file is local to this specific client renderer */
1.1093 + if (gmyth_uri_is_local_file(gmyth_uri))
1.1094 + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
1.1095 + else
1.1096 + ret =
1.1097 + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
1.1098 + src->spawn_livetv->uri !=
1.1099 + NULL ? gmyth_uri_get_path(src->
1.1100 + spawn_livetv->
1.1101 + uri) : src->
1.1102 + spawn_livetv->proginfo->pathname->str);
1.1103
1.1104 - if (NULL == src->file) {
1.1105 - GST_INFO_OBJECT (src, "FileTransfer is NULL");
1.1106 - goto init_failed;
1.1107 - }
1.1108 - /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
1.1109 + /* sets the mythtvsrc "location" property */
1.1110 + g_object_set(src, "location", gmyth_file_get_uri(src->file), NULL);
1.1111
1.1112 - if (ret == FALSE) {
1.1113 + if (!ret)
1.1114 + {
1.1115 + GST_INFO_OBJECT(src,
1.1116 + "Error: couldn't open the FileTransfer from LiveTV source!");
1.1117 + g_object_unref(src->file);
1.1118 + src->file = NULL;
1.1119 + goto init_failed;
1.1120 + }
1.1121 + }
1.1122 + else
1.1123 + {
1.1124 +
1.1125 + /* Check if the file is local to this specific client renderer, and tries to open
1.1126 + * a local connection
1.1127 + */
1.1128 + if (gmyth_uri_is_local_file(gmyth_uri))
1.1129 + {
1.1130 + src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
1.1131 + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
1.1132 + }
1.1133 + else
1.1134 + {
1.1135 + src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
1.1136 + ret =
1.1137 + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
1.1138 + src->uri_name);
1.1139 + }
1.1140 +
1.1141 + } /* if (else) - recorded FileTransfer */
1.1142 +
1.1143 + if (NULL == src->file)
1.1144 + {
1.1145 + GST_INFO_OBJECT(src, "FileTransfer is NULL");
1.1146 + goto init_failed;
1.1147 + }
1.1148 + /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
1.1149 +
1.1150 + if (ret == FALSE)
1.1151 + {
1.1152 #ifndef GST_DISABLE_GST_DEBUG
1.1153 - if (src->mythtv_msgs_dbg)
1.1154 - GST_INFO_OBJECT (src,
1.1155 - "MythTV FileTransfer request failed when setting up socket connection!");
1.1156 + if (src->mythtv_msgs_dbg)
1.1157 + GST_INFO_OBJECT(src,
1.1158 + "MythTV FileTransfer request failed when setting up socket connection!");
1.1159 #endif
1.1160 - goto begin_req_failed;
1.1161 - }
1.1162 + goto begin_req_failed;
1.1163 + }
1.1164
1.1165 - GST_INFO_OBJECT (src,
1.1166 - "MythTV FileTransfer filesize = %lld, content_size = %lld!",
1.1167 - gmyth_file_get_filesize( src->file ), src->content_size);
1.1168 + GST_INFO_OBJECT(src,
1.1169 + "MythTV FileTransfer filesize = %lld, content_size = %lld!",
1.1170 + gmyth_file_get_filesize(src->file), src->content_size);
1.1171
1.1172 - src->content_size = gmyth_file_get_filesize (src->file);
1.1173 + src->content_size = gmyth_file_get_filesize(src->file);
1.1174
1.1175 - msg = gst_message_new_duration (GST_OBJECT (src), GST_FORMAT_BYTES, src->content_size);
1.1176 - gst_element_post_message (GST_ELEMENT (src), msg);
1.1177 + msg =
1.1178 + gst_message_new_duration(GST_OBJECT(src), GST_FORMAT_BYTES,
1.1179 + src->content_size);
1.1180 + gst_element_post_message(GST_ELEMENT(src), msg);
1.1181
1.1182
1.1183 src->do_start = FALSE;
1.1184
1.1185 - /* this is used for the buffer cache */
1.1186 - src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
1.1187 + /* this is used for the buffer cache */
1.1188 + src->bytes_queue = g_byte_array_sized_new(INTERNAL_BUFFER_SIZE);
1.1189 src->buffer_remain = 0;
1.1190 -
1.1191 - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1.1192 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
1.1193 - src->content_size, 0));
1.1194 +
1.1195 + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(src)),
1.1196 + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME, 0,
1.1197 + src->content_size, 0));
1.1198
1.1199 done:
1.1200 - if (gmyth_uri != NULL)
1.1201 + if (gmyth_uri != NULL)
1.1202 {
1.1203 - g_object_unref (gmyth_uri);
1.1204 - gmyth_uri = NULL;
1.1205 + g_object_unref(gmyth_uri);
1.1206 + gmyth_uri = NULL;
1.1207 }
1.1208
1.1209 - if (chain_id_local != NULL) {
1.1210 - g_string_free (chain_id_local, TRUE);
1.1211 - chain_id_local = NULL;
1.1212 - }
1.1213 -
1.1214 - return TRUE;
1.1215 -
1.1216 - /* ERRORS */
1.1217 -init_failed:
1.1218 - if (gmyth_uri != NULL)
1.1219 + if (chain_id_local != NULL)
1.1220 {
1.1221 - g_object_unref (gmyth_uri);
1.1222 - gmyth_uri = NULL;
1.1223 + g_string_free(chain_id_local, TRUE);
1.1224 + chain_id_local = NULL;
1.1225 }
1.1226
1.1227 - if (src->spawn_livetv != NULL) {
1.1228 - g_object_unref (src->spawn_livetv);
1.1229 - src->spawn_livetv = NULL;
1.1230 - }
1.1231 -
1.1232 - GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1.1233 - (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
1.1234 - src->uri_name));
1.1235 + return TRUE;
1.1236
1.1237 -
1.1238 - gst_mythtv_src_clear (src);
1.1239 -
1.1240 - return FALSE;
1.1241 -begin_req_failed:
1.1242 - if (gmyth_uri != NULL)
1.1243 + /* ERRORS */
1.1244 +init_failed:
1.1245 + if (gmyth_uri != NULL)
1.1246 {
1.1247 - g_object_unref (gmyth_uri);
1.1248 - gmyth_uri = NULL;
1.1249 + g_object_unref(gmyth_uri);
1.1250 + gmyth_uri = NULL;
1.1251 }
1.1252
1.1253 - GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1.1254 - (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
1.1255 - src->uri_name));
1.1256 - return FALSE;
1.1257 + if (src->spawn_livetv != NULL)
1.1258 + {
1.1259 + g_object_unref(src->spawn_livetv);
1.1260 + src->spawn_livetv = NULL;
1.1261 + }
1.1262 +
1.1263 + GST_ELEMENT_ERROR(src, LIBRARY, INIT,
1.1264 + (NULL), ("Could not initialize MythTV library (%i, %s)",
1.1265 + ret, src->uri_name));
1.1266 +
1.1267 +
1.1268 + gst_mythtv_src_clear(src);
1.1269 +
1.1270 + return FALSE;
1.1271 +begin_req_failed:
1.1272 + if (gmyth_uri != NULL)
1.1273 + {
1.1274 + g_object_unref(gmyth_uri);
1.1275 + gmyth_uri = NULL;
1.1276 + }
1.1277 +
1.1278 + GST_ELEMENT_ERROR(src, LIBRARY, INIT,
1.1279 + (NULL),
1.1280 + ("Could not begin request sent to MythTV server (%i, %s)",
1.1281 + ret, src->uri_name));
1.1282 + return FALSE;
1.1283
1.1284 }
1.1285
1.1286 static gboolean
1.1287 -gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1.1288 +gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size)
1.1289 {
1.1290 - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1.1291 + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
1.1292 gboolean ret = TRUE;
1.1293
1.1294 - GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
1.1295 - abs (src->content_size - src->prev_content_size),
1.1296 - GMYTHTV_TRANSFER_MAX_BUFFER);
1.1297 + GST_LOG_OBJECT(src, "Differs from previous content size: %d (max.: %d)",
1.1298 + abs(src->content_size - src->prev_content_size),
1.1299 + GMYTHTV_TRANSFER_MAX_BUFFER);
1.1300
1.1301 - if (src->live_tv) {
1.1302 - ret = FALSE;
1.1303 - } else if (src->live_tv && src->enable_timing_position
1.1304 - && (abs (src->content_size - src->bytes_read) <
1.1305 - GMYTHTV_TRANSFER_MAX_BUFFER)) {
1.1306 + if (src->live_tv)
1.1307 + {
1.1308 + ret = FALSE;
1.1309 + }
1.1310 + else if (src->live_tv && src->enable_timing_position
1.1311 + && (abs(src->content_size - src->bytes_read) <
1.1312 + GMYTHTV_TRANSFER_MAX_BUFFER))
1.1313 + {
1.1314
1.1315 - gint64 new_offset =
1.1316 - gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
1.1317 - if (new_offset > 0 && new_offset > src->content_size) {
1.1318 - src->content_size = new_offset;
1.1319 - } else if (new_offset < src->content_size) {
1.1320 - src->update_prog_chain = TRUE;
1.1321 - }
1.1322 + gint64 new_offset =
1.1323 + gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
1.1324 + if (new_offset > 0 && new_offset > src->content_size)
1.1325 + {
1.1326 + src->content_size = new_offset;
1.1327 + }
1.1328 + else if (new_offset < src->content_size)
1.1329 + {
1.1330 + src->update_prog_chain = TRUE;
1.1331 + }
1.1332
1.1333 - }
1.1334 + }
1.1335
1.1336 *size = src->content_size;
1.1337 - GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
1.1338 + GST_LOG_OBJECT(src, "Content size = %lld", src->content_size);
1.1339
1.1340 return ret;
1.1341
1.1342 @@ -911,312 +996,328 @@
1.1343 /* close the socket and associated resources
1.1344 * used both to recover from errors and go to NULL state */
1.1345 static gboolean
1.1346 -gst_mythtv_src_stop (GstBaseSrc * bsrc)
1.1347 +gst_mythtv_src_stop(GstBaseSrc * bsrc)
1.1348 {
1.1349 - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1.1350 -
1.1351 - gst_mythtv_src_clear (src);
1.1352 + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
1.1353
1.1354 - /* src->eos = FALSE; */
1.1355 + gst_mythtv_src_clear(src);
1.1356 +
1.1357 + /* src->eos = FALSE; */
1.1358
1.1359 return TRUE;
1.1360 }
1.1361
1.1362 static gboolean
1.1363 -gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1.1364 +gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event)
1.1365 {
1.1366 - GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1.1367 + GstMythtvSrc *src = GST_MYTHTV_SRC(GST_PAD_PARENT(pad));
1.1368 gint64 cont_size = 0;
1.1369 gboolean ret = FALSE;
1.1370
1.1371 - switch (GST_EVENT_TYPE (event)) {
1.1372 - case GST_EVENT_EOS:
1.1373 - GST_WARNING_OBJECT (src, "Got EOS event");
1.1374 + switch (GST_EVENT_TYPE(event))
1.1375 + {
1.1376 + case GST_EVENT_EOS:
1.1377 + GST_WARNING_OBJECT(src, "Got EOS event");
1.1378
1.1379 - if (src->live_tv) {
1.1380 - cont_size = gst_mythtv_src_get_position (src);
1.1381 - if (cont_size > src->content_size) {
1.1382 - src->content_size = cont_size;
1.1383 - src->eos = FALSE;
1.1384 - } else {
1.1385 - src->eos = TRUE;
1.1386 - gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
1.1387 - gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
1.1388 - }
1.1389 - }
1.1390 - break;
1.1391 - default:
1.1392 - ret = gst_pad_event_default (pad, event);
1.1393 - }
1.1394 + if (src->live_tv)
1.1395 + {
1.1396 + cont_size = gst_mythtv_src_get_position(src);
1.1397 + if (cont_size > src->content_size)
1.1398 + {
1.1399 + src->content_size = cont_size;
1.1400 + src->eos = FALSE;
1.1401 + }
1.1402 + else
1.1403 + {
1.1404 + src->eos = TRUE;
1.1405 + gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL);
1.1406 + gst_element_set_locked_state(GST_ELEMENT(src), FALSE);
1.1407 + }
1.1408 + }
1.1409 + break;
1.1410 + default:
1.1411 + ret = gst_pad_event_default(pad, event);
1.1412 + }
1.1413
1.1414 return ret;
1.1415 }
1.1416
1.1417 static gboolean
1.1418 -gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
1.1419 +gst_mythtv_src_is_seekable(GstBaseSrc * push_src)
1.1420 {
1.1421 return TRUE;
1.1422 }
1.1423
1.1424 static gboolean
1.1425 -gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
1.1426 +gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query)
1.1427 {
1.1428 gboolean res = FALSE;
1.1429 - GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
1.1430 + GstMythtvSrc *myth = GST_MYTHTV_SRC(gst_pad_get_parent(pad));
1.1431 GstFormat formt;
1.1432
1.1433
1.1434 - switch (GST_QUERY_TYPE (query)) {
1.1435 - case GST_QUERY_POSITION:
1.1436 - {
1.1437 - gst_query_parse_position (query, &formt, NULL);
1.1438 - if (formt == GST_FORMAT_BYTES) {
1.1439 - gst_query_set_position (query, formt, myth->read_offset);
1.1440 - GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
1.1441 - res = TRUE;
1.1442 - } else if (formt == GST_FORMAT_TIME) {
1.1443 - res = gst_pad_query_default (pad, query);
1.1444 - }
1.1445 - break;
1.1446 - }
1.1447 - case GST_QUERY_DURATION:
1.1448 - {
1.1449 - gst_query_parse_duration (query, &formt, NULL);
1.1450 - if (formt == GST_FORMAT_BYTES) {
1.1451 - gint64 size = myth->content_size;
1.1452 - gst_query_set_duration (query, GST_FORMAT_BYTES, 10);
1.1453 - GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, size);
1.1454 - res = TRUE;
1.1455 - } else if (formt == GST_FORMAT_TIME) {
1.1456 - res = gst_pad_query_default (pad, query);
1.1457 - }
1.1458 - break;
1.1459 - }
1.1460 - default:
1.1461 - {
1.1462 - res = gst_pad_query_default (pad, query);
1.1463 - break;
1.1464 - }
1.1465 - }
1.1466 + switch (GST_QUERY_TYPE(query))
1.1467 + {
1.1468 + case GST_QUERY_POSITION:
1.1469 + {
1.1470 + gst_query_parse_position(query, &formt, NULL);
1.1471 + if (formt == GST_FORMAT_BYTES)
1.1472 + {
1.1473 + gst_query_set_position(query, formt, myth->read_offset);
1.1474 + GST_DEBUG_OBJECT(myth, "POS %" G_GINT64_FORMAT,
1.1475 + myth->read_offset);
1.1476 + res = TRUE;
1.1477 + }
1.1478 + else if (formt == GST_FORMAT_TIME)
1.1479 + {
1.1480 + res = gst_pad_query_default(pad, query);
1.1481 + }
1.1482 + break;
1.1483 + }
1.1484 + case GST_QUERY_DURATION:
1.1485 + {
1.1486 + gst_query_parse_duration(query, &formt, NULL);
1.1487 + if (formt == GST_FORMAT_BYTES)
1.1488 + {
1.1489 + gint64 size = myth->content_size;
1.1490 + gst_query_set_duration(query, GST_FORMAT_BYTES, 10);
1.1491 + GST_DEBUG_OBJECT(myth, "SIZE %" G_GINT64_FORMAT, size);
1.1492 + res = TRUE;
1.1493 + }
1.1494 + else if (formt == GST_FORMAT_TIME)
1.1495 + {
1.1496 + res = gst_pad_query_default(pad, query);
1.1497 + }
1.1498 + break;
1.1499 + }
1.1500 + default:
1.1501 + {
1.1502 + res = gst_pad_query_default(pad, query);
1.1503 + break;
1.1504 + }
1.1505 + }
1.1506
1.1507 - gst_object_unref (myth);
1.1508 + gst_object_unref(myth);
1.1509
1.1510 return res;
1.1511 }
1.1512
1.1513 static GstStateChangeReturn
1.1514 -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1.1515 +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition)
1.1516 {
1.1517 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
1.1518 - GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1.1519 + GstMythtvSrc *src = GST_MYTHTV_SRC(element);
1.1520
1.1521 - g_debug ("MYTHSRC: state_changed");
1.1522 + switch (transition)
1.1523 + {
1.1524 + case GST_STATE_CHANGE_NULL_TO_READY:
1.1525 + break;
1.1526 + case GST_STATE_CHANGE_READY_TO_PAUSED:
1.1527 + case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1.1528 + if (src->live_tv)
1.1529 + {
1.1530 + if (!gmyth_recorder_send_frontend_ready_command(src->spawn_livetv->
1.1531 + recorder))
1.1532 + GST_WARNING_OBJECT(src,
1.1533 + "Couldn't send the FRONTEND_READY message to the backend!");
1.1534 + else
1.1535 + GST_DEBUG_OBJECT(src, "FRONTEND_READY was sent to the backend");
1.1536 + }
1.1537 + break;
1.1538 + default:
1.1539 + break;
1.1540 + }
1.1541
1.1542 - switch (transition) {
1.1543 - case GST_STATE_CHANGE_NULL_TO_READY:
1.1544 - break;
1.1545 - case GST_STATE_CHANGE_READY_TO_PAUSED:
1.1546 - case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1.1547 - if (src->live_tv) {
1.1548 - if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
1.1549 - recorder))
1.1550 - GST_WARNING_OBJECT (src,
1.1551 - "Couldn't send the FRONTEND_READY message to the backend!");
1.1552 - else
1.1553 - GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
1.1554 - }
1.1555 - break;
1.1556 - default:
1.1557 - break;
1.1558 - }
1.1559
1.1560 + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1.1561 + if (ret == GST_STATE_CHANGE_FAILURE)
1.1562 + return ret;
1.1563
1.1564 - g_debug ("MYTHSRC: state_changed 1");
1.1565
1.1566 - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1.1567 - if (ret == GST_STATE_CHANGE_FAILURE)
1.1568 - return ret;
1.1569 + switch (transition)
1.1570 + {
1.1571 + case GST_STATE_CHANGE_READY_TO_NULL:
1.1572 + gst_mythtv_src_clear(src);
1.1573 + break;
1.1574 + case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1.1575 + case GST_STATE_CHANGE_PAUSED_TO_READY:
1.1576 + break;
1.1577 + default:
1.1578 + break;
1.1579 + }
1.1580
1.1581 -
1.1582 - g_debug ("MYTHSRC: state_changed2");
1.1583 -
1.1584 - switch (transition) {
1.1585 - case GST_STATE_CHANGE_READY_TO_NULL:
1.1586 - gst_mythtv_src_clear (src);
1.1587 - break;
1.1588 - case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1.1589 - case GST_STATE_CHANGE_PAUSED_TO_READY:
1.1590 - break;
1.1591 - default:
1.1592 - break;
1.1593 - }
1.1594 -
1.1595 - g_debug ("MYTHSRC: state_changed: DONE");
1.1596 return ret;
1.1597 }
1.1598
1.1599 static void
1.1600 -gst_mythtv_src_set_property (GObject * object, guint prop_id,
1.1601 - const GValue * value, GParamSpec * pspec)
1.1602 +gst_mythtv_src_set_property(GObject * object, guint prop_id,
1.1603 + const GValue * value, GParamSpec * pspec)
1.1604 {
1.1605 - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1.1606 + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
1.1607
1.1608 - GST_OBJECT_LOCK (mythtvsrc);
1.1609 - switch (prop_id) {
1.1610 - case PROP_LOCATION:
1.1611 - {
1.1612 - if (!g_value_get_string (value)) {
1.1613 - GST_WARNING ("location property cannot be NULL");
1.1614 - break;
1.1615 - }
1.1616 + GST_OBJECT_LOCK(mythtvsrc);
1.1617 + switch (prop_id)
1.1618 + {
1.1619 + case PROP_LOCATION:
1.1620 + {
1.1621 + if (!g_value_get_string(value))
1.1622 + {
1.1623 + GST_WARNING("location property cannot be NULL");
1.1624 + break;
1.1625 + }
1.1626
1.1627 - if (mythtvsrc->uri_name != NULL) {
1.1628 - g_free (mythtvsrc->uri_name);
1.1629 - mythtvsrc->uri_name = NULL;
1.1630 - }
1.1631 - mythtvsrc->uri_name = g_value_dup_string (value);
1.1632 + if (mythtvsrc->uri_name != NULL)
1.1633 + {
1.1634 + g_free(mythtvsrc->uri_name);
1.1635 + mythtvsrc->uri_name = NULL;
1.1636 + }
1.1637 + mythtvsrc->uri_name = g_value_dup_string(value);
1.1638
1.1639 - break;
1.1640 - }
1.1641 + break;
1.1642 + }
1.1643 #ifndef GST_DISABLE_GST_DEBUG
1.1644 - case PROP_GMYTHTV_DBG:
1.1645 - {
1.1646 - mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1.1647 - break;
1.1648 - }
1.1649 + case PROP_GMYTHTV_DBG:
1.1650 + {
1.1651 + mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean(value);
1.1652 + break;
1.1653 + }
1.1654 #endif
1.1655 - case PROP_GMYTHTV_VERSION:
1.1656 - {
1.1657 - mythtvsrc->mythtv_version = g_value_get_int (value);
1.1658 - break;
1.1659 - }
1.1660 - case PROP_GMYTHTV_LIVEID:
1.1661 - {
1.1662 - mythtvsrc->live_tv_id = g_value_get_int (value);
1.1663 - break;
1.1664 - }
1.1665 - case PROP_GMYTHTV_LIVE:
1.1666 - {
1.1667 - mythtvsrc->live_tv = g_value_get_boolean (value);
1.1668 - break;
1.1669 - }
1.1670 - case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1.1671 - {
1.1672 - mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1.1673 - break;
1.1674 - }
1.1675 - case PROP_GMYTHTV_LIVE_CHAINID:
1.1676 - {
1.1677 - if (!g_value_get_string (value)) {
1.1678 - GST_WARNING ("MythTV Live chainid property cannot be NULL");
1.1679 - break;
1.1680 - }
1.1681 + case PROP_GMYTHTV_VERSION:
1.1682 + {
1.1683 + mythtvsrc->mythtv_version = g_value_get_int(value);
1.1684 + break;
1.1685 + }
1.1686 + case PROP_GMYTHTV_LIVEID:
1.1687 + {
1.1688 + mythtvsrc->live_tv_id = g_value_get_int(value);
1.1689 + break;
1.1690 + }
1.1691 + case PROP_GMYTHTV_LIVE:
1.1692 + {
1.1693 + mythtvsrc->live_tv = g_value_get_boolean(value);
1.1694 + break;
1.1695 + }
1.1696 + case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1.1697 + {
1.1698 + mythtvsrc->enable_timing_position = g_value_get_boolean(value);
1.1699 + break;
1.1700 + }
1.1701 + case PROP_GMYTHTV_LIVE_CHAINID:
1.1702 + {
1.1703 + if (!g_value_get_string(value))
1.1704 + {
1.1705 + GST_WARNING("MythTV Live chainid property cannot be NULL");
1.1706 + break;
1.1707 + }
1.1708
1.1709 - if (mythtvsrc->live_chain_id != NULL) {
1.1710 - g_free (mythtvsrc->live_chain_id);
1.1711 - mythtvsrc->live_chain_id = NULL;
1.1712 - }
1.1713 - mythtvsrc->live_chain_id = g_value_dup_string (value);
1.1714 - break;
1.1715 - }
1.1716 - case PROP_GMYTHTV_CHANNEL_NUM:
1.1717 - {
1.1718 - mythtvsrc->channel_name = g_value_dup_string (value);
1.1719 - break;
1.1720 - }
1.1721 - case PROP_GMYTHTV_MAX_TRY:
1.1722 - {
1.1723 - mythtvsrc->max_try = g_value_get_int (value);
1.1724 - break;
1.1725 - }
1.1726 - default:
1.1727 - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1.1728 - break;
1.1729 - }
1.1730 + if (mythtvsrc->live_chain_id != NULL)
1.1731 + {
1.1732 + g_free(mythtvsrc->live_chain_id);
1.1733 + mythtvsrc->live_chain_id = NULL;
1.1734 + }
1.1735 + mythtvsrc->live_chain_id = g_value_dup_string(value);
1.1736 + break;
1.1737 + }
1.1738 + case PROP_GMYTHTV_CHANNEL_NUM:
1.1739 + {
1.1740 + mythtvsrc->channel_name = g_value_dup_string(value);
1.1741 + break;
1.1742 + }
1.1743 + case PROP_GMYTHTV_MAX_TRY:
1.1744 + {
1.1745 + mythtvsrc->max_try = g_value_get_int(value);
1.1746 + break;
1.1747 + }
1.1748 + default:
1.1749 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1.1750 + break;
1.1751 + }
1.1752
1.1753 - GST_OBJECT_UNLOCK (mythtvsrc);
1.1754 + GST_OBJECT_UNLOCK(mythtvsrc);
1.1755 }
1.1756
1.1757 static void
1.1758 -gst_mythtv_src_get_property (GObject * object, guint prop_id,
1.1759 - GValue * value, GParamSpec * pspec)
1.1760 +gst_mythtv_src_get_property(GObject * object, guint prop_id,
1.1761 + GValue * value, GParamSpec * pspec)
1.1762 {
1.1763 - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1.1764 + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
1.1765
1.1766 - GST_OBJECT_LOCK (mythtvsrc);
1.1767 - switch (prop_id) {
1.1768 - case PROP_LOCATION:
1.1769 - {
1.1770 - g_value_set_string (value, mythtvsrc->uri_name);
1.1771 - break;
1.1772 - }
1.1773 + GST_OBJECT_LOCK(mythtvsrc);
1.1774 + switch (prop_id)
1.1775 + {
1.1776 + case PROP_LOCATION:
1.1777 + {
1.1778 + g_value_set_string(value, mythtvsrc->uri_name);
1.1779 + break;
1.1780 + }
1.1781 #ifndef GST_DISABLE_GST_DEBUG
1.1782 - case PROP_GMYTHTV_DBG:
1.1783 - g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
1.1784 - break;
1.1785 + case PROP_GMYTHTV_DBG:
1.1786 + g_value_set_boolean(value, mythtvsrc->mythtv_msgs_dbg);
1.1787 + break;
1.1788 #endif
1.1789 - case PROP_GMYTHTV_VERSION:
1.1790 - {
1.1791 - g_value_set_int (value, mythtvsrc->mythtv_version);
1.1792 - break;
1.1793 - }
1.1794 - case PROP_GMYTHTV_LIVEID:
1.1795 - {
1.1796 - g_value_set_int (value, mythtvsrc->live_tv_id);
1.1797 - break;
1.1798 - }
1.1799 - case PROP_GMYTHTV_LIVE:
1.1800 - g_value_set_boolean (value, mythtvsrc->live_tv);
1.1801 - break;
1.1802 - case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1.1803 - g_value_set_boolean (value, mythtvsrc->enable_timing_position);
1.1804 - break;
1.1805 - case PROP_GMYTHTV_LIVE_CHAINID:
1.1806 - {
1.1807 - g_value_set_string (value, mythtvsrc->live_chain_id);
1.1808 - break;
1.1809 - }
1.1810 - case PROP_GMYTHTV_CHANNEL_NUM:
1.1811 - {
1.1812 - g_value_set_string (value, mythtvsrc->channel_name);
1.1813 - break;
1.1814 - }
1.1815 - case PROP_GMYTHTV_MAX_TRY:
1.1816 - {
1.1817 - g_value_set_int (value, mythtvsrc->max_try);
1.1818 - break;
1.1819 - }
1.1820 + case PROP_GMYTHTV_VERSION:
1.1821 + {
1.1822 + g_value_set_int(value, mythtvsrc->mythtv_version);
1.1823 + break;
1.1824 + }
1.1825 + case PROP_GMYTHTV_LIVEID:
1.1826 + {
1.1827 + g_value_set_int(value, mythtvsrc->live_tv_id);
1.1828 + break;
1.1829 + }
1.1830 + case PROP_GMYTHTV_LIVE:
1.1831 + g_value_set_boolean(value, mythtvsrc->live_tv);
1.1832 + break;
1.1833 + case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1.1834 + g_value_set_boolean(value, mythtvsrc->enable_timing_position);
1.1835 + break;
1.1836 + case PROP_GMYTHTV_LIVE_CHAINID:
1.1837 + {
1.1838 + g_value_set_string(value, mythtvsrc->live_chain_id);
1.1839 + break;
1.1840 + }
1.1841 + case PROP_GMYTHTV_CHANNEL_NUM:
1.1842 + {
1.1843 + g_value_set_string(value, mythtvsrc->channel_name);
1.1844 + break;
1.1845 + }
1.1846 + case PROP_GMYTHTV_MAX_TRY:
1.1847 + {
1.1848 + g_value_set_int(value, mythtvsrc->max_try);
1.1849 + break;
1.1850 + }
1.1851
1.1852 - default:
1.1853 - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1.1854 - break;
1.1855 - }
1.1856 - GST_OBJECT_UNLOCK (mythtvsrc);
1.1857 + default:
1.1858 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1.1859 + break;
1.1860 + }
1.1861 + GST_OBJECT_UNLOCK(mythtvsrc);
1.1862 }
1.1863
1.1864 static gboolean
1.1865 -plugin_init (GstPlugin * plugin)
1.1866 +plugin_init(GstPlugin * plugin)
1.1867 {
1.1868 - return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1.1869 - GST_TYPE_MYTHTV_SRC);
1.1870 + return gst_element_register(plugin, "mythtvsrc", GST_RANK_NONE,
1.1871 + GST_TYPE_MYTHTV_SRC);
1.1872 }
1.1873
1.1874 -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1.1875 - GST_VERSION_MINOR,
1.1876 - "mythtv",
1.1877 - "lib MythTV src",
1.1878 - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
1.1879 +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1.1880 + GST_VERSION_MINOR,
1.1881 + "mythtv",
1.1882 + "lib MythTV src",
1.1883 + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
1.1884 + GST_PACKAGE_ORIGIN);
1.1885
1.1886
1.1887 /*** GSTURIHANDLER INTERFACE *************************************************/
1.1888 static guint
1.1889 -gst_mythtv_src_uri_get_type (void)
1.1890 +gst_mythtv_src_uri_get_type(void)
1.1891 {
1.1892 return GST_URI_SRC;
1.1893 }
1.1894
1.1895 static gchar **
1.1896 -gst_mythtv_src_uri_get_protocols (void)
1.1897 +gst_mythtv_src_uri_get_protocols(void)
1.1898 {
1.1899 static gchar *protocols[] = { "myth", "myths", NULL };
1.1900
1.1901 @@ -1224,33 +1325,34 @@
1.1902 }
1.1903
1.1904 static const gchar *
1.1905 -gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1.1906 +gst_mythtv_src_uri_get_uri(GstURIHandler * handler)
1.1907 {
1.1908 - GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1.1909 + GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1.1910
1.1911 return src->uri_name;
1.1912 }
1.1913
1.1914 static gboolean
1.1915 -gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1.1916 +gst_mythtv_src_uri_set_uri(GstURIHandler * handler, const gchar * uri)
1.1917 {
1.1918 - GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1.1919 + GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1.1920
1.1921 gchar *protocol;
1.1922
1.1923 - protocol = gst_uri_get_protocol (uri);
1.1924 - if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1.1925 - g_free (protocol);
1.1926 - return FALSE;
1.1927 - }
1.1928 - g_free (protocol);
1.1929 - g_object_set (src, "location", uri, NULL);
1.1930 + protocol = gst_uri_get_protocol(uri);
1.1931 + if ((strcmp(protocol, "myth") != 0) && (strcmp(protocol, "myths") != 0))
1.1932 + {
1.1933 + g_free(protocol);
1.1934 + return FALSE;
1.1935 + }
1.1936 + g_free(protocol);
1.1937 + g_object_set(src, "location", uri, NULL);
1.1938
1.1939 return TRUE;
1.1940 }
1.1941
1.1942 static void
1.1943 -gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1.1944 +gst_mythtv_src_uri_handler_init(gpointer g_iface, gpointer iface_data)
1.1945 {
1.1946 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1.1947
1.1948 @@ -1261,9 +1363,9 @@
1.1949 }
1.1950
1.1951 void
1.1952 -size_header_handler (void *userdata, const char *value)
1.1953 +size_header_handler(void *userdata, const char *value)
1.1954 {
1.1955 - GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1.1956 + GstMythtvSrc *src = GST_MYTHTV_SRC(userdata);
1.1957
1.1958 - GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
1.1959 + GST_DEBUG_OBJECT(src, "content size = %lld bytes", src->content_size);
1.1960 }