2 * GStreamer MythTV Plug-in Copyright (C) <2006> Rosfran Borges
3 * <rosfran.borges@indt.org.br> This library is free software; you can
4 * redistribute it and/or modify it under the terms of the GNU Library
5 * General Public License as published by the Free Software Foundation;
6 * either version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
10 * General Public License for more details. You should have received a copy
11 * of the GNU Library General Public License along with this library; if
12 * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite
13 * 330, Boston, MA 02111-1307, USA.
16 * SECTION:element-mythtvsrc
20 * MythTVSrc allows to access a remote MythTV backend streaming Video/Audio server,
21 * and to render audio and video content through a TCP/IP connection to a specific
22 * port on this server, and based on a known MythTV protocol that is based on
23 * some message passing, such as REQUEST_BLOCK on a specified number of bytes, to get
24 * some chunk of remote file data.
25 * You should pass the information aboute the remote MythTV backend server
26 * through the <link linkend="GstMythTVSrc--location">location</link> property.
28 * <title>Examples</title>
30 * If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder,
32 * put the following URI:
35 * myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
38 * This URI will say to the gmyth library to configure the Recorder instance (used to
39 * change the channel, start the TV multimedia content transmition, etc.), using
40 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
41 * server, and setting the channel name to "BBC".
43 * To get a already recorded the MythTV NUV file, put the following URI:
46 * myth://xxx.xxx.xxx.xxx:6543/filename.nuv
49 * This URI will say to the gmyth library to configure the Recorder instance (used to
50 * change the channel, start the TV multimedia content transmition, etc.), using
51 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
52 * server, and setting the channel name to "BBC".
54 * Another possible way to use the LiveTV content, and just in the case you want to
55 * use the mysql database, put the location URI in the following format:
58 * myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
61 * Where the first field is the protocol (myth), the second and third are user
62 * name (mythtv) and password (mythtv), then backend host name and port number,
63 * and the last field is the database name (mythconverg).
71 #include "gstmythtvsrc.h"
72 #include <gmyth/gmyth_file.h>
73 #include <gmyth/gmyth_file_transfer.h>
74 #include <gmyth/gmyth_file_local.h>
75 #include <gmyth/gmyth_livetv.h>
77 #include <gmyth/gmyth_socket.h>
78 #include <gmyth/gmyth_tvchain.h>
83 GST_DEBUG_CATEGORY_STATIC(mythtvsrc_debug);
84 #define GST_GMYTHTV_ID_NUM 1
85 #define GST_GMYTHTV_CHANNEL_DEFAULT_NUM (-1)
86 #define GMYTHTV_VERSION_DEFAULT 30
87 #define GMYTHTV_TRANSFER_MAX_WAITS 100
88 #define GMYTHTV_TRANSFER_MAX_RESENDS 2
89 #define GMYTHTV_TRANSFER_MAX_BUFFER (128*1024)
90 #define READ_SIZE (8*1024)
91 #define READ_SIZE_LIVETV (50*1024)
92 #define GST_FLOW_ERROR_NO_DATA (-101)
94 static const GstElementDetails gst_mythtv_src_details =
95 GST_ELEMENT_DETAILS("MythTV client source",
97 "Control and receive data as a client over the network "
98 "via raw socket connections using the MythTV protocol",
99 "Rosfran Borges <rosfran.borges@indt.org.br>");
101 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE("src",
104 GST_STATIC_CAPS_ANY);
106 * GST_STATIC_CAPS ("video/x-nuv"));
112 PROP_GMYTHTV_VERSION,
115 PROP_GMYTHTV_LIVE_CHAINID,
116 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
117 PROP_GMYTHTV_CHANNEL_NUM
120 static void gst_mythtv_src_clear(GstMythtvSrc * mythtv_src);
122 static void gst_mythtv_src_finalize(GObject * gobject);
124 static GstFlowReturn gst_mythtv_src_create(GstPushSrc * psrc,
125 GstBuffer ** outbuf);
127 static gboolean gst_mythtv_src_start(GstBaseSrc * bsrc);
128 static gboolean gst_mythtv_src_stop(GstBaseSrc * bsrc);
129 static gboolean gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size);
130 static gboolean gst_mythtv_src_is_seekable(GstBaseSrc * push_src);
132 static gboolean gst_mythtv_src_do_seek(GstBaseSrc * base,
133 GstSegment * segment);
135 static GstStateChangeReturn
136 gst_mythtv_src_change_state(GstElement * element,
137 GstStateChange transition);
139 static void gst_mythtv_src_set_property(GObject * object,
141 const GValue * value,
143 static void gst_mythtv_src_get_property(GObject * object,
144 guint prop_id, GValue * value,
147 static void gst_mythtv_src_uri_handler_init(gpointer g_iface,
148 gpointer iface_data);
150 static gboolean gst_mythtv_src_handle_query(GstPad * pad,
153 static gboolean gst_mythtv_src_handle_event(GstPad * pad,
156 static GMythFileReadResult do_read_request_response(GstMythtvSrc * src,
158 GByteArray * data_ptr);
161 _urihandler_init(GType type)
163 static const GInterfaceInfo urihandler_info = {
164 gst_mythtv_src_uri_handler_init,
169 g_type_add_interface_static(type, GST_TYPE_URI_HANDLER,
172 GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
175 GST_BOILERPLATE_FULL(GstMythtvSrc, gst_mythtv_src, GstPushSrc,
176 GST_TYPE_PUSH_SRC, _urihandler_init)
177 static void gst_mythtv_src_base_init(gpointer g_class)
179 GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
181 gst_element_class_add_pad_template(element_class,
182 gst_static_pad_template_get
185 gst_element_class_set_details(element_class, &gst_mythtv_src_details);
187 element_class->change_state = gst_mythtv_src_change_state;
192 gst_mythtv_src_class_init(GstMythtvSrcClass * klass)
194 GObjectClass *gobject_class;
195 GstPushSrcClass *gstpushsrc_class;
196 GstBaseSrcClass *gstbasesrc_class;
198 gobject_class = (GObjectClass *) klass;
199 gstbasesrc_class = (GstBaseSrcClass *) klass;
200 gstpushsrc_class = (GstPushSrcClass *) klass;
202 gobject_class->set_property = gst_mythtv_src_set_property;
203 gobject_class->get_property = gst_mythtv_src_get_property;
204 gobject_class->finalize = gst_mythtv_src_finalize;
206 g_object_class_install_property
207 (gobject_class, PROP_LOCATION,
208 g_param_spec_string("location", "Location",
209 "The location. In the form:"
210 "\n\t\t\tmyth://a.com/file.nuv"
211 "\n\t\t\tmyth://a.com:23223/file.nuv "
212 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
213 "", G_PARAM_READWRITE));
215 g_object_class_install_property
216 (gobject_class, PROP_GMYTHTV_VERSION,
217 g_param_spec_int("mythtv-version", "mythtv-version",
218 "Change MythTV version", 26, 30, 26,
221 g_object_class_install_property
222 (gobject_class, PROP_GMYTHTV_LIVEID,
223 g_param_spec_int("mythtv-live-id", "mythtv-live-id",
224 "Change MythTV version",
225 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
227 g_object_class_install_property
228 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
229 g_param_spec_string("mythtv-live-chainid", "mythtv-live-chainid",
230 "Sets the MythTV chain ID (from TV Chain)",
231 "", G_PARAM_READWRITE));
233 g_object_class_install_property
234 (gobject_class, PROP_GMYTHTV_LIVE,
235 g_param_spec_boolean("mythtv-live", "mythtv-live",
236 "Enable MythTV Live TV content streaming",
237 FALSE, G_PARAM_READWRITE));
239 g_object_class_install_property
240 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
241 g_param_spec_boolean("mythtv-enable-timing-position",
242 "mythtv-enable-timing-position",
243 "Enable MythTV Live TV content size continuous updating",
244 FALSE, G_PARAM_READWRITE));
246 g_object_class_install_property
247 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
248 g_param_spec_string("mythtv-channel", "mythtv-channel",
249 "Change MythTV channel number",
250 "", G_PARAM_READWRITE));
252 gstbasesrc_class->start = gst_mythtv_src_start;
253 gstbasesrc_class->stop = gst_mythtv_src_stop;
254 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
255 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
256 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
257 gstpushsrc_class->create = gst_mythtv_src_create;
259 GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0,
260 "MythTV Client Source");
264 gst_mythtv_src_init(GstMythtvSrc * this, GstMythtvSrcClass * g_class)
267 this->unique_setup = FALSE;
268 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
269 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
270 this->bytes_read = 0;
271 this->prev_content_size = 0;
272 this->content_size = 0;
273 this->read_offset = 0;
274 this->content_size_last = 0;
275 this->live_tv = FALSE;
276 this->enable_timing_position = FALSE;
277 this->update_prog_chain = FALSE;
278 this->user_agent = g_strdup("mythtvsrc");
279 this->update_prog_chain = FALSE;
280 this->channel_name = NULL;
282 this->wait_to_transfer = 0;
283 gst_base_src_set_format(GST_BASE_SRC(this), GST_FORMAT_BYTES);
284 gst_pad_set_event_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
285 gst_mythtv_src_handle_event);
286 gst_pad_set_query_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
287 gst_mythtv_src_handle_query);
292 gst_mythtv_src_clear(GstMythtvSrc * mythtv_src)
294 mythtv_src->unique_setup = FALSE;
296 if (mythtv_src->spawn_livetv) {
297 g_object_unref(mythtv_src->spawn_livetv);
298 mythtv_src->spawn_livetv = NULL;
301 if (mythtv_src->file) {
302 g_object_unref(mythtv_src->file);
303 mythtv_src->file = NULL;
306 if (mythtv_src->backend_info) {
307 g_object_unref(mythtv_src->backend_info);
308 mythtv_src->backend_info = NULL;
313 gst_mythtv_src_finalize(GObject * gobject)
315 GstMythtvSrc *this = GST_MYTHTV_SRC(gobject);
317 gst_mythtv_src_clear(this);
319 if (this->uri_name) {
320 g_free(this->uri_name);
321 this->uri_name = NULL;
324 if (this->user_agent) {
325 g_free(this->user_agent);
326 this->user_agent = NULL;
329 G_OBJECT_CLASS(parent_class)->finalize(gobject);
332 static GMythFileReadResult
333 do_read_request_response(GstMythtvSrc * src, guint size,
334 GByteArray * data_ptr)
337 guint sizetoread = size;
338 gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
339 GMythFileReadResult result;
341 GST_LOG_OBJECT(src, "Starting: Reading %d bytes...", sizetoread);
344 * Loop sending the Myth File Transfer request: Retry whilst
345 * authentication fails and we supply it.
348 while (sizetoread == size && --max_iters > 0) {
350 * if ( gmyth_backend_info_is_local_file(src->backend_info) )
352 if (IS_GMYTH_FILE_LOCAL(src->file))
353 result = gmyth_file_local_read(GMYTH_FILE_LOCAL(src->file),
354 data_ptr, sizetoread,
356 else if (IS_GMYTH_FILE_TRANSFER(src->file))
358 gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(src->file),
359 data_ptr, sizetoread,
362 if (data_ptr->len > 0) {
363 read += data_ptr->len;
364 sizetoread -= data_ptr->len;
365 } else if (data_ptr->len <= 0) {
366 if (src->live_tv == FALSE) {
367 result = GMYTH_FILE_READ_EOF;
370 if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
372 "[LiveTV] FileTransfer READ_ERROR!");
378 * else if (data_ptr->len == 0) goto done;
380 if (read == sizetoread)
384 if ((read < 0 && !src->live_tv) || max_iters == 0) {
385 result = GMYTH_FILE_READ_EOF;
399 gst_mythtv_src_create(GstPushSrc * psrc, GstBuffer ** outbuf)
402 GstFlowReturn ret = GST_FLOW_OK;
404 gint buffer_remain = 0;
405 GMythFileReadResult result = GMYTH_FILE_READ_OK;
406 gboolean buffering = FALSE;
408 src = GST_MYTHTV_SRC(psrc);
410 buffer = g_byte_array_new ();
412 result = do_read_request_response(src, READ_SIZE_LIVETV, buffer);
414 result = do_read_request_response(src, READ_SIZE, buffer);
416 if (result == GMYTH_FILE_READ_ERROR)
420 *outbuf = gst_buffer_new();
421 GST_BUFFER_SIZE(*outbuf) = buffer->len;
422 GST_BUFFER_MALLOCDATA(*outbuf) = g_malloc0(GST_BUFFER_SIZE(*outbuf));
423 GST_BUFFER_DATA(*outbuf) = GST_BUFFER_MALLOCDATA(*outbuf);
424 g_memmove(GST_BUFFER_DATA((*outbuf)), buffer->data,
425 GST_BUFFER_SIZE(*outbuf));
426 GST_BUFFER_OFFSET(*outbuf) = src->read_offset;
427 GST_BUFFER_OFFSET_END(*outbuf) =
428 src->read_offset + GST_BUFFER_SIZE(*outbuf);
430 src->read_offset += GST_BUFFER_SIZE(*outbuf);
431 src->bytes_read += GST_BUFFER_SIZE(*outbuf);
433 g_byte_array_free (buffer, TRUE);
435 if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {
438 peer = gst_pad_get_peer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)));
439 gst_pad_send_event (peer,
440 gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
442 gst_object_unref (peer);
446 (!src->live_tv && (src->bytes_read >= src->content_size)))
447 ret = GST_FLOW_UNEXPECTED;
452 GST_ELEMENT_ERROR(src, RESOURCE, READ,
453 (NULL), ("Could not read any bytes (%i, %s)",
454 read, src->uri_name));
455 return GST_FLOW_ERROR;
459 gst_mythtv_src_get_position(GstMythtvSrc * src)
465 if (src->live_tv == TRUE && (abs(src->content_size - src->bytes_read) <
466 GMYTHTV_TRANSFER_MAX_BUFFER)) {
471 gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
472 if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
473 src->content_size = size_tmp;
474 else if (size_tmp > 0 && --max_tries > 0)
476 GST_LOG_OBJECT(src, "GET_POSITION: file_position = %lld",
479 * sets the last content size amount before it can be updated
481 src->prev_content_size = src->content_size;
484 return src->content_size;
489 gst_mythtv_src_do_seek(GstBaseSrc * base, GstSegment * segment)
491 GstMythtvSrc *src = GST_MYTHTV_SRC(base);
492 gint64 new_offset = -1;
493 gint64 actual_seek = segment->start;
496 GST_LOG_OBJECT(src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
498 if (segment->format == GST_FORMAT_TIME) {
502 "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
503 actual_seek, src->read_offset);
505 * verify if it needs to seek
507 if (src->read_offset != actual_seek) {
510 * if ( gmyth_backend_info_is_local_file(src->backend_info) )
512 if (IS_GMYTH_FILE_LOCAL(src->file))
514 gmyth_file_local_seek(GMYTH_FILE_LOCAL(src->file),
515 segment->start, G_SEEK_SET);
516 else if (IS_GMYTH_FILE_TRANSFER(src->file))
518 gmyth_file_transfer_seek(GMYTH_FILE_TRANSFER(src->file),
519 segment->start, SEEK_SET);
522 "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
523 segment->start, src->read_offset, new_offset);
524 if (G_UNLIKELY(new_offset < 0)) {
530 src->read_offset = new_offset;
533 GST_INFO_OBJECT(src, "Failed to set the SEEK on segment!");
543 GST_DEBUG_OBJECT(src, "EOS found on seeking!!!");
550 * create a socket for connecting to remote server
553 gst_mythtv_src_start(GstBaseSrc * bsrc)
555 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
557 GString *chain_id_local = NULL;
558 GMythURI *gmyth_uri = NULL;
562 if (src->unique_setup == FALSE) {
563 src->unique_setup = TRUE;
568 gmyth_uri = gmyth_uri_new_with_value(src->uri_name);
569 src->backend_info = gmyth_backend_info_new_with_uri(src->uri_name);
570 src->live_tv = gmyth_uri_is_livetv(gmyth_uri);
573 src->spawn_livetv = gmyth_livetv_new(src->backend_info);
574 gchar *ch = gmyth_uri_get_channel_name(gmyth_uri);
576 src->channel_name = ch;
578 if (src->channel_name != NULL) {
581 gmyth_livetv_channel_name_setup(src->spawn_livetv,
583 if (result == FALSE) {
584 GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
590 if (gmyth_livetv_setup(src->spawn_livetv) == FALSE) {
591 GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
598 * testing change channel...
601 * gmyth_recorder_change_channel( src->spawn_livetv->recorder,
602 * CHANNEL_DIRECTION_UP );
606 GMYTH_FILE(gmyth_livetv_create_file_transfer
607 (src->spawn_livetv));
610 if (NULL == src->file) {
611 GST_INFO_OBJECT(src, "[LiveTV] FileTransfer equals to NULL");
617 * Check if the file is local to this specific client renderer
619 if (gmyth_uri_is_local_file(gmyth_uri))
620 ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
623 gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
624 src->spawn_livetv->uri !=
625 NULL ? gmyth_uri_get_path(src->
628 src->spawn_livetv->proginfo->
632 * sets the mythtvsrc "location" property
634 g_object_set(src, "location", gmyth_file_get_uri(src->file), NULL);
638 "Error: couldn't open the FileTransfer from LiveTV source!");
639 g_object_unref(src->file);
646 * Check if the file is local to this specific client renderer,
647 * and tries to open a local connection
649 if (gmyth_uri_is_local_file(gmyth_uri)) {
651 GMYTH_FILE(gmyth_file_local_new(src->backend_info));
652 ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
655 GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
657 gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
661 } /* if (else) - recorded FileTransfer */
663 if (NULL == src->file) {
664 GST_INFO_OBJECT(src, "FileTransfer is NULL");
668 * GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file);
673 "MythTV FileTransfer request failed when setting up socket connection!");
674 goto begin_req_failed;
678 "MythTV FileTransfer filesize = %lld, content_size = %lld!",
679 gmyth_file_get_filesize(src->file), src->content_size);
681 src->content_size = gmyth_file_get_filesize(src->file);
684 gst_message_new_duration(GST_OBJECT(src), GST_FORMAT_BYTES,
686 gst_element_post_message(GST_ELEMENT(src), msg);
689 src->do_start = FALSE;
691 gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(src)),
692 gst_event_new_new_segment(TRUE, 1.0,
694 src->content_size, 0));
697 if (gmyth_uri != NULL) {
698 g_object_unref(gmyth_uri);
702 if (chain_id_local != NULL) {
703 g_string_free(chain_id_local, TRUE);
704 chain_id_local = NULL;
713 if (gmyth_uri != NULL) {
714 g_object_unref(gmyth_uri);
718 if (src->spawn_livetv != NULL) {
719 g_object_unref(src->spawn_livetv);
720 src->spawn_livetv = NULL;
723 GST_ELEMENT_ERROR(src, LIBRARY, INIT,
725 ("Could not initialize MythTV library (%i, %s)", ret,
729 gst_mythtv_src_clear(src);
733 if (gmyth_uri != NULL) {
734 g_object_unref(gmyth_uri);
738 GST_ELEMENT_ERROR(src, LIBRARY, INIT,
740 ("Could not begin request sent to MythTV server (%i, %s)",
741 ret, src->uri_name));
747 gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size)
749 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
753 "Differs from previous content size: %d (max.: %d)",
754 abs(src->content_size - src->prev_content_size),
755 GMYTHTV_TRANSFER_MAX_BUFFER);
759 } else if (src->live_tv && src->enable_timing_position
760 && (abs(src->content_size - src->bytes_read) <
761 GMYTHTV_TRANSFER_MAX_BUFFER)) {
764 gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
765 if (new_offset > 0 && new_offset > src->content_size) {
766 src->content_size = new_offset;
767 } else if (new_offset < src->content_size) {
768 src->update_prog_chain = TRUE;
773 *size = src->content_size;
774 GST_LOG_OBJECT(src, "Content size = %lld", src->content_size);
781 * close the socket and associated resources used both to recover from
782 * errors and go to NULL state
785 gst_mythtv_src_stop(GstBaseSrc * bsrc)
787 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
789 gst_mythtv_src_clear(src);
794 gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event)
796 GstMythtvSrc *src = GST_MYTHTV_SRC(GST_PAD_PARENT(pad));
797 gint64 cont_size = 0;
800 switch (GST_EVENT_TYPE(event)) {
803 cont_size = gst_mythtv_src_get_position(src);
804 if (cont_size > src->content_size) {
805 src->content_size = cont_size;
809 gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL);
810 gst_element_set_locked_state(GST_ELEMENT(src), FALSE);
815 ret = gst_pad_event_default(pad, event);
818 GST_DEBUG_OBJECT (src, "HANDLE EVENT %d", ret);
823 gst_mythtv_src_is_seekable(GstBaseSrc * push_src)
829 gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query)
831 gboolean res = FALSE;
832 GstMythtvSrc *myth = GST_MYTHTV_SRC(gst_pad_get_parent(pad));
836 switch (GST_QUERY_TYPE(query)) {
837 case GST_QUERY_POSITION:
838 gst_query_parse_position(query, &formt, NULL);
839 if (formt == GST_FORMAT_BYTES) {
840 gst_query_set_position(query, formt, myth->read_offset);
841 GST_DEBUG_OBJECT(myth, "POS %" G_GINT64_FORMAT,
844 } else if (formt == GST_FORMAT_TIME) {
845 res = gst_pad_query_default(pad, query);
848 case GST_QUERY_DURATION:
849 gst_query_parse_duration(query, &formt, NULL);
850 if (formt == GST_FORMAT_BYTES) {
851 gint64 size = myth->content_size;
853 gst_query_set_duration(query, GST_FORMAT_BYTES, 10);
854 GST_DEBUG_OBJECT(myth, "SIZE %" G_GINT64_FORMAT, size);
856 } else if (formt == GST_FORMAT_TIME) {
857 res = gst_pad_query_default(pad, query);
861 res = gst_pad_query_default(pad, query);
865 gst_object_unref(myth);
870 static GstStateChangeReturn
871 gst_mythtv_src_change_state(GstElement * element,
872 GstStateChange transition)
874 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
875 GstMythtvSrc *src = GST_MYTHTV_SRC(element);
877 switch (transition) {
878 case GST_STATE_CHANGE_NULL_TO_READY:
880 case GST_STATE_CHANGE_READY_TO_PAUSED:
881 if (!src->uri_name) {
882 GST_WARNING_OBJECT (src, "Invalid location");
886 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
888 if (!gmyth_recorder_send_frontend_ready_command
889 (src->spawn_livetv->recorder))
890 GST_WARNING_OBJECT(src,
891 "Couldn't send the FRONTEND_READY message to the backend!");
893 GST_DEBUG_OBJECT(src, "FRONTEND_READY was sent to the backend");
900 ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
901 if (ret == GST_STATE_CHANGE_FAILURE) {
906 switch (transition) {
907 case GST_STATE_CHANGE_READY_TO_NULL:
908 gst_mythtv_src_clear(src);
910 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
911 case GST_STATE_CHANGE_PAUSED_TO_READY:
921 gst_mythtv_src_set_property(GObject * object, guint prop_id,
922 const GValue * value, GParamSpec * pspec)
924 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
926 GST_OBJECT_LOCK(mythtvsrc);
929 if (!g_value_get_string(value)) {
930 GST_WARNING("location property cannot be NULL");
934 if (mythtvsrc->uri_name != NULL) {
935 g_free(mythtvsrc->uri_name);
936 mythtvsrc->uri_name = NULL;
938 mythtvsrc->uri_name = g_value_dup_string(value);
940 case PROP_GMYTHTV_VERSION:
941 mythtvsrc->mythtv_version = g_value_get_int(value);
943 case PROP_GMYTHTV_LIVEID:
944 mythtvsrc->live_tv_id = g_value_get_int(value);
946 case PROP_GMYTHTV_LIVE:
947 mythtvsrc->live_tv = g_value_get_boolean(value);
949 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
950 mythtvsrc->enable_timing_position = g_value_get_boolean(value);
952 case PROP_GMYTHTV_LIVE_CHAINID:
953 if (!g_value_get_string(value)) {
954 GST_WARNING_OBJECT(object, "MythTV Live chainid property cannot be NULL");
958 if (mythtvsrc->live_chain_id != NULL) {
959 g_free(mythtvsrc->live_chain_id);
960 mythtvsrc->live_chain_id = NULL;
962 mythtvsrc->live_chain_id = g_value_dup_string(value);
964 case PROP_GMYTHTV_CHANNEL_NUM:
965 mythtvsrc->channel_name = g_value_dup_string(value);
968 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
972 GST_OBJECT_UNLOCK(mythtvsrc);
976 gst_mythtv_src_get_property(GObject * object, guint prop_id,
977 GValue * value, GParamSpec * pspec)
979 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
981 GST_OBJECT_LOCK(mythtvsrc);
984 g_value_set_string(value, mythtvsrc->uri_name);
986 case PROP_GMYTHTV_VERSION:
987 g_value_set_int(value, mythtvsrc->mythtv_version);
989 case PROP_GMYTHTV_LIVEID:
990 g_value_set_int(value, mythtvsrc->live_tv_id);
992 case PROP_GMYTHTV_LIVE:
993 g_value_set_boolean(value, mythtvsrc->live_tv);
995 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
996 g_value_set_boolean(value, mythtvsrc->enable_timing_position);
998 case PROP_GMYTHTV_LIVE_CHAINID:
999 g_value_set_string(value, mythtvsrc->live_chain_id);
1001 case PROP_GMYTHTV_CHANNEL_NUM:
1002 g_value_set_string(value, mythtvsrc->channel_name);
1005 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1008 GST_OBJECT_UNLOCK(mythtvsrc);
1012 plugin_init(GstPlugin * plugin)
1014 return gst_element_register(plugin, "mythtvsrc", GST_RANK_NONE,
1015 GST_TYPE_MYTHTV_SRC);
1018 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1022 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
1023 GST_PACKAGE_ORIGIN);
1026 /*** GSTURIHANDLER INTERFACE *************************************************/
1028 gst_mythtv_src_uri_get_type(void)
1034 gst_mythtv_src_uri_get_protocols(void)
1036 static gchar *protocols[] = { "myth", "myths", NULL };
1041 static const gchar *
1042 gst_mythtv_src_uri_get_uri(GstURIHandler * handler)
1044 GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1046 return src->uri_name;
1050 gst_mythtv_src_uri_set_uri(GstURIHandler * handler, const gchar * uri)
1052 GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1056 protocol = gst_uri_get_protocol(uri);
1057 if ((strcmp(protocol, "myth") != 0)
1058 && (strcmp(protocol, "myths") != 0)) {
1063 g_object_set(src, "location", uri, NULL);
1069 gst_mythtv_src_uri_handler_init(gpointer g_iface, gpointer iface_data)
1071 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1073 iface->get_type = gst_mythtv_src_uri_get_type;
1074 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1075 iface->get_uri = gst_mythtv_src_uri_get_uri;
1076 iface->set_uri = gst_mythtv_src_uri_set_uri;
1080 size_header_handler(void *userdata, const char *value)
1082 GstMythtvSrc *src = GST_MYTHTV_SRC(userdata);
1084 GST_DEBUG_OBJECT(src, "content size = %lld bytes", src->content_size);