[svn r836] - Cleanup of svn (deleted old versions of gms as they are on repository)
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 (100*1024)
91 #define GST_FLOW_ERROR_NO_DATA (-101)
93 static const GstElementDetails gst_mythtv_src_details =
94 GST_ELEMENT_DETAILS("MythTV client source",
96 "Control and receive data as a client over the network "
97 "via raw socket connections using the MythTV protocol",
98 "Rosfran Borges <rosfran.borges@indt.org.br>");
100 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE("src",
103 GST_STATIC_CAPS_ANY);
105 * GST_STATIC_CAPS ("video/x-nuv"));
111 PROP_GMYTHTV_VERSION,
114 PROP_GMYTHTV_LIVE_CHAINID,
115 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
116 PROP_GMYTHTV_CHANNEL_NUM
119 static void gst_mythtv_src_clear(GstMythtvSrc * mythtv_src);
121 static void gst_mythtv_src_finalize(GObject * gobject);
123 static GstFlowReturn gst_mythtv_src_create(GstPushSrc * psrc,
124 GstBuffer ** outbuf);
126 static gboolean gst_mythtv_src_start(GstBaseSrc * bsrc);
127 static gboolean gst_mythtv_src_stop(GstBaseSrc * bsrc);
128 static gboolean gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size);
129 static gboolean gst_mythtv_src_is_seekable(GstBaseSrc * push_src);
131 static gboolean gst_mythtv_src_do_seek(GstBaseSrc * base,
132 GstSegment * segment);
134 static GstStateChangeReturn
135 gst_mythtv_src_change_state(GstElement * element,
136 GstStateChange transition);
138 static void gst_mythtv_src_set_property(GObject * object,
140 const GValue * value,
142 static void gst_mythtv_src_get_property(GObject * object,
143 guint prop_id, GValue * value,
146 static void gst_mythtv_src_uri_handler_init(gpointer g_iface,
147 gpointer iface_data);
149 static gboolean gst_mythtv_src_handle_query(GstPad * pad,
152 static gboolean gst_mythtv_src_handle_event(GstPad * pad,
155 static GMythFileReadResult do_read_request_response(GstMythtvSrc * src,
157 GByteArray * data_ptr);
160 _urihandler_init(GType type)
162 static const GInterfaceInfo urihandler_info = {
163 gst_mythtv_src_uri_handler_init,
168 g_type_add_interface_static(type, GST_TYPE_URI_HANDLER,
171 GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
174 GST_BOILERPLATE_FULL(GstMythtvSrc, gst_mythtv_src, GstPushSrc,
175 GST_TYPE_PUSH_SRC, _urihandler_init)
176 static void gst_mythtv_src_base_init(gpointer g_class)
178 GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
180 gst_element_class_add_pad_template(element_class,
181 gst_static_pad_template_get
184 gst_element_class_set_details(element_class, &gst_mythtv_src_details);
186 element_class->change_state = gst_mythtv_src_change_state;
191 gst_mythtv_src_class_init(GstMythtvSrcClass * klass)
193 GObjectClass *gobject_class;
194 GstPushSrcClass *gstpushsrc_class;
195 GstBaseSrcClass *gstbasesrc_class;
197 gobject_class = (GObjectClass *) klass;
198 gstbasesrc_class = (GstBaseSrcClass *) klass;
199 gstpushsrc_class = (GstPushSrcClass *) klass;
201 gobject_class->set_property = gst_mythtv_src_set_property;
202 gobject_class->get_property = gst_mythtv_src_get_property;
203 gobject_class->finalize = gst_mythtv_src_finalize;
205 g_object_class_install_property
206 (gobject_class, PROP_LOCATION,
207 g_param_spec_string("location", "Location",
208 "The location. In the form:"
209 "\n\t\t\tmyth://a.com/file.nuv"
210 "\n\t\t\tmyth://a.com:23223/file.nuv "
211 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
212 "", G_PARAM_READWRITE));
214 g_object_class_install_property
215 (gobject_class, PROP_GMYTHTV_VERSION,
216 g_param_spec_int("mythtv-version", "mythtv-version",
217 "Change MythTV version", 26, 30, 26,
220 g_object_class_install_property
221 (gobject_class, PROP_GMYTHTV_LIVEID,
222 g_param_spec_int("mythtv-live-id", "mythtv-live-id",
223 "Change MythTV version",
224 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
226 g_object_class_install_property
227 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
228 g_param_spec_string("mythtv-live-chainid", "mythtv-live-chainid",
229 "Sets the MythTV chain ID (from TV Chain)",
230 "", G_PARAM_READWRITE));
232 g_object_class_install_property
233 (gobject_class, PROP_GMYTHTV_LIVE,
234 g_param_spec_boolean("mythtv-live", "mythtv-live",
235 "Enable MythTV Live TV content streaming",
236 FALSE, G_PARAM_READWRITE));
238 g_object_class_install_property
239 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
240 g_param_spec_boolean("mythtv-enable-timing-position",
241 "mythtv-enable-timing-position",
242 "Enable MythTV Live TV content size continuous updating",
243 FALSE, G_PARAM_READWRITE));
245 g_object_class_install_property
246 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
247 g_param_spec_string("mythtv-channel", "mythtv-channel",
248 "Change MythTV channel number",
249 "", G_PARAM_READWRITE));
251 gstbasesrc_class->start = gst_mythtv_src_start;
252 gstbasesrc_class->stop = gst_mythtv_src_stop;
253 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
254 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
255 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
256 gstpushsrc_class->create = gst_mythtv_src_create;
258 GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0,
259 "MythTV Client Source");
263 gst_mythtv_src_init(GstMythtvSrc * this, GstMythtvSrcClass * g_class)
266 this->unique_setup = FALSE;
267 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
268 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
269 this->bytes_read = 0;
270 this->prev_content_size = 0;
271 this->content_size = 0;
272 this->read_offset = 0;
273 this->content_size_last = 0;
274 this->live_tv = FALSE;
275 this->enable_timing_position = FALSE;
276 this->update_prog_chain = FALSE;
277 this->user_agent = g_strdup("mythtvsrc");
278 this->update_prog_chain = FALSE;
279 this->channel_name = NULL;
281 this->wait_to_transfer = 0;
282 gst_base_src_set_format(GST_BASE_SRC(this), GST_FORMAT_BYTES);
283 gst_pad_set_event_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
284 gst_mythtv_src_handle_event);
285 gst_pad_set_query_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
286 gst_mythtv_src_handle_query);
291 gst_mythtv_src_clear(GstMythtvSrc * mythtv_src)
293 mythtv_src->unique_setup = FALSE;
295 if (mythtv_src->spawn_livetv) {
296 g_object_unref(mythtv_src->spawn_livetv);
297 mythtv_src->spawn_livetv = NULL;
300 if (mythtv_src->file) {
301 g_object_unref(mythtv_src->file);
302 mythtv_src->file = NULL;
305 if (mythtv_src->backend_info) {
306 g_object_unref(mythtv_src->backend_info);
307 mythtv_src->backend_info = NULL;
312 gst_mythtv_src_finalize(GObject * gobject)
314 GstMythtvSrc *this = GST_MYTHTV_SRC(gobject);
316 gst_mythtv_src_clear(this);
318 if (this->uri_name) {
319 g_free(this->uri_name);
320 this->uri_name = NULL;
323 if (this->user_agent) {
324 g_free(this->user_agent);
325 this->user_agent = NULL;
328 G_OBJECT_CLASS(parent_class)->finalize(gobject);
331 static GMythFileReadResult
332 do_read_request_response(GstMythtvSrc * src, guint size,
333 GByteArray * data_ptr)
336 guint sizetoread = size;
337 gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
338 GMythFileReadResult result;
340 GST_LOG_OBJECT(src, "Starting: Reading %d bytes...", sizetoread);
343 * Loop sending the Myth File Transfer request: Retry whilst
344 * authentication fails and we supply it.
347 while (sizetoread == size && --max_iters > 0) {
349 * if ( gmyth_backend_info_is_local_file(src->backend_info) )
351 if (IS_GMYTH_FILE_LOCAL(src->file))
352 result = gmyth_file_local_read(GMYTH_FILE_LOCAL(src->file),
353 data_ptr, sizetoread,
355 else if (IS_GMYTH_FILE_TRANSFER(src->file))
357 gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(src->file),
358 data_ptr, sizetoread,
361 if (data_ptr->len > 0) {
362 read += data_ptr->len;
363 sizetoread -= data_ptr->len;
364 } else if (data_ptr->len <= 0) {
365 if (src->live_tv == FALSE) {
366 result = GMYTH_FILE_READ_EOF;
369 if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
371 "[LiveTV] FileTransfer READ_ERROR!");
377 * else if (data_ptr->len == 0) goto done;
379 if (read == sizetoread)
383 if ((read < 0 && !src->live_tv) || max_iters == 0) {
384 result = GMYTH_FILE_READ_EOF;
398 gst_mythtv_src_create(GstPushSrc * psrc, GstBuffer ** outbuf)
401 GstFlowReturn ret = GST_FLOW_OK;
403 gint buffer_remain = 0;
404 GMythFileReadResult result = GMYTH_FILE_READ_OK;
405 gboolean buffering = FALSE;
407 src = GST_MYTHTV_SRC(psrc);
409 buffer = g_byte_array_new ();
410 result = do_read_request_response(src, READ_SIZE, buffer);
411 if (result == GMYTH_FILE_READ_ERROR)
415 *outbuf = gst_buffer_new();
416 GST_BUFFER_SIZE(*outbuf) = buffer->len;
417 GST_BUFFER_MALLOCDATA(*outbuf) = g_malloc0(GST_BUFFER_SIZE(*outbuf));
418 GST_BUFFER_DATA(*outbuf) = GST_BUFFER_MALLOCDATA(*outbuf);
419 g_memmove(GST_BUFFER_DATA((*outbuf)), buffer->data,
420 GST_BUFFER_SIZE(*outbuf));
421 GST_BUFFER_OFFSET(*outbuf) = src->read_offset;
422 GST_BUFFER_OFFSET_END(*outbuf) =
423 src->read_offset + GST_BUFFER_SIZE(*outbuf);
425 src->read_offset += GST_BUFFER_SIZE(*outbuf);
426 src->bytes_read += GST_BUFFER_SIZE(*outbuf);
428 g_byte_array_free (buffer, TRUE);
430 if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {
433 peer = gst_pad_get_peer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)));
434 gst_pad_send_event (peer,
435 gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
437 gst_object_unref (peer);
441 (!src->live_tv && (src->bytes_read >= src->content_size)))
442 ret = GST_FLOW_UNEXPECTED;
447 GST_ELEMENT_ERROR(src, RESOURCE, READ,
448 (NULL), ("Could not read any bytes (%i, %s)",
449 read, src->uri_name));
450 return GST_FLOW_ERROR;
454 gst_mythtv_src_get_position(GstMythtvSrc * src)
460 if (src->live_tv == TRUE && (abs(src->content_size - src->bytes_read) <
461 GMYTHTV_TRANSFER_MAX_BUFFER)) {
466 gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
467 if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
468 src->content_size = size_tmp;
469 else if (size_tmp > 0 && --max_tries > 0)
471 GST_LOG_OBJECT(src, "GET_POSITION: file_position = %lld",
474 * sets the last content size amount before it can be updated
476 src->prev_content_size = src->content_size;
479 return src->content_size;
484 gst_mythtv_src_do_seek(GstBaseSrc * base, GstSegment * segment)
486 GstMythtvSrc *src = GST_MYTHTV_SRC(base);
487 gint64 new_offset = -1;
488 gint64 actual_seek = segment->start;
491 GST_LOG_OBJECT(src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
493 if (segment->format == GST_FORMAT_TIME) {
497 "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
498 actual_seek, src->read_offset);
500 * verify if it needs to seek
502 if (src->read_offset != actual_seek) {
505 * if ( gmyth_backend_info_is_local_file(src->backend_info) )
507 if (IS_GMYTH_FILE_LOCAL(src->file))
509 gmyth_file_local_seek(GMYTH_FILE_LOCAL(src->file),
510 segment->start, G_SEEK_SET);
511 else if (IS_GMYTH_FILE_TRANSFER(src->file))
513 gmyth_file_transfer_seek(GMYTH_FILE_TRANSFER(src->file),
514 segment->start, SEEK_SET);
517 "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
518 segment->start, src->read_offset, new_offset);
519 if (G_UNLIKELY(new_offset < 0)) {
525 src->read_offset = new_offset;
528 GST_INFO_OBJECT(src, "Failed to set the SEEK on segment!");
538 GST_DEBUG_OBJECT(src, "EOS found on seeking!!!");
545 * create a socket for connecting to remote server
548 gst_mythtv_src_start(GstBaseSrc * bsrc)
550 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
552 GString *chain_id_local = NULL;
553 GMythURI *gmyth_uri = NULL;
557 if (src->unique_setup == FALSE) {
558 src->unique_setup = TRUE;
563 gmyth_uri = gmyth_uri_new_with_value(src->uri_name);
564 src->backend_info = gmyth_backend_info_new_with_uri(src->uri_name);
565 src->live_tv = gmyth_uri_is_livetv(gmyth_uri);
568 src->spawn_livetv = gmyth_livetv_new(src->backend_info);
569 gchar *ch = gmyth_uri_get_channel_name(gmyth_uri);
571 src->channel_name = ch;
573 if (src->channel_name != NULL) {
576 gmyth_livetv_channel_name_setup(src->spawn_livetv,
578 if (result == FALSE) {
579 GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
585 if (gmyth_livetv_setup(src->spawn_livetv) == FALSE) {
586 GST_INFO_OBJECT(src, "LiveTV setup felt down on error");
593 * testing change channel...
596 * gmyth_recorder_change_channel( src->spawn_livetv->recorder,
597 * CHANNEL_DIRECTION_UP );
601 GMYTH_FILE(gmyth_livetv_create_file_transfer
602 (src->spawn_livetv));
605 if (NULL == src->file) {
606 GST_INFO_OBJECT(src, "[LiveTV] FileTransfer equals to NULL");
612 * Check if the file is local to this specific client renderer
614 if (gmyth_uri_is_local_file(gmyth_uri))
615 ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
618 gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
619 src->spawn_livetv->uri !=
620 NULL ? gmyth_uri_get_path(src->
623 src->spawn_livetv->proginfo->
627 * sets the mythtvsrc "location" property
629 g_object_set(src, "location", gmyth_file_get_uri(src->file), NULL);
633 "Error: couldn't open the FileTransfer from LiveTV source!");
634 g_object_unref(src->file);
641 * Check if the file is local to this specific client renderer,
642 * and tries to open a local connection
644 if (gmyth_uri_is_local_file(gmyth_uri)) {
646 GMYTH_FILE(gmyth_file_local_new(src->backend_info));
647 ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file));
650 GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
652 gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file),
656 } /* if (else) - recorded FileTransfer */
658 if (NULL == src->file) {
659 GST_INFO_OBJECT(src, "FileTransfer is NULL");
663 * GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file);
668 "MythTV FileTransfer request failed when setting up socket connection!");
669 goto begin_req_failed;
673 "MythTV FileTransfer filesize = %lld, content_size = %lld!",
674 gmyth_file_get_filesize(src->file), src->content_size);
676 src->content_size = gmyth_file_get_filesize(src->file);
679 gst_message_new_duration(GST_OBJECT(src), GST_FORMAT_BYTES,
681 gst_element_post_message(GST_ELEMENT(src), msg);
684 src->do_start = FALSE;
686 gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(src)),
687 gst_event_new_new_segment(TRUE, 1.0,
689 src->content_size, 0));
692 if (gmyth_uri != NULL) {
693 g_object_unref(gmyth_uri);
697 if (chain_id_local != NULL) {
698 g_string_free(chain_id_local, TRUE);
699 chain_id_local = NULL;
708 if (gmyth_uri != NULL) {
709 g_object_unref(gmyth_uri);
713 if (src->spawn_livetv != NULL) {
714 g_object_unref(src->spawn_livetv);
715 src->spawn_livetv = NULL;
718 GST_ELEMENT_ERROR(src, LIBRARY, INIT,
720 ("Could not initialize MythTV library (%i, %s)", ret,
724 gst_mythtv_src_clear(src);
728 if (gmyth_uri != NULL) {
729 g_object_unref(gmyth_uri);
733 GST_ELEMENT_ERROR(src, LIBRARY, INIT,
735 ("Could not begin request sent to MythTV server (%i, %s)",
736 ret, src->uri_name));
742 gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size)
744 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
748 "Differs from previous content size: %d (max.: %d)",
749 abs(src->content_size - src->prev_content_size),
750 GMYTHTV_TRANSFER_MAX_BUFFER);
754 } else if (src->live_tv && src->enable_timing_position
755 && (abs(src->content_size - src->bytes_read) <
756 GMYTHTV_TRANSFER_MAX_BUFFER)) {
759 gmyth_recorder_get_file_position(src->spawn_livetv->recorder);
760 if (new_offset > 0 && new_offset > src->content_size) {
761 src->content_size = new_offset;
762 } else if (new_offset < src->content_size) {
763 src->update_prog_chain = TRUE;
768 *size = src->content_size;
769 GST_LOG_OBJECT(src, "Content size = %lld", src->content_size);
776 * close the socket and associated resources used both to recover from
777 * errors and go to NULL state
780 gst_mythtv_src_stop(GstBaseSrc * bsrc)
782 GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc);
784 gst_mythtv_src_clear(src);
789 gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event)
791 GstMythtvSrc *src = GST_MYTHTV_SRC(GST_PAD_PARENT(pad));
792 gint64 cont_size = 0;
795 switch (GST_EVENT_TYPE(event)) {
798 cont_size = gst_mythtv_src_get_position(src);
799 if (cont_size > src->content_size) {
800 src->content_size = cont_size;
804 gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL);
805 gst_element_set_locked_state(GST_ELEMENT(src), FALSE);
810 ret = gst_pad_event_default(pad, event);
813 GST_DEBUG_OBJECT (src, "HANDLE EVENT %d", ret);
818 gst_mythtv_src_is_seekable(GstBaseSrc * push_src)
824 gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query)
826 gboolean res = FALSE;
827 GstMythtvSrc *myth = GST_MYTHTV_SRC(gst_pad_get_parent(pad));
831 switch (GST_QUERY_TYPE(query)) {
832 case GST_QUERY_POSITION:
833 gst_query_parse_position(query, &formt, NULL);
834 if (formt == GST_FORMAT_BYTES) {
835 gst_query_set_position(query, formt, myth->read_offset);
836 GST_DEBUG_OBJECT(myth, "POS %" G_GINT64_FORMAT,
839 } else if (formt == GST_FORMAT_TIME) {
840 res = gst_pad_query_default(pad, query);
843 case GST_QUERY_DURATION:
844 gst_query_parse_duration(query, &formt, NULL);
845 if (formt == GST_FORMAT_BYTES) {
846 gint64 size = myth->content_size;
848 gst_query_set_duration(query, GST_FORMAT_BYTES, 10);
849 GST_DEBUG_OBJECT(myth, "SIZE %" G_GINT64_FORMAT, size);
851 } else if (formt == GST_FORMAT_TIME) {
852 res = gst_pad_query_default(pad, query);
856 res = gst_pad_query_default(pad, query);
860 gst_object_unref(myth);
865 static GstStateChangeReturn
866 gst_mythtv_src_change_state(GstElement * element,
867 GstStateChange transition)
869 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
870 GstMythtvSrc *src = GST_MYTHTV_SRC(element);
872 switch (transition) {
873 case GST_STATE_CHANGE_NULL_TO_READY:
875 case GST_STATE_CHANGE_READY_TO_PAUSED:
876 if (!src->uri_name) {
877 GST_WARNING_OBJECT (src, "Invalid location");
881 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
883 if (!gmyth_recorder_send_frontend_ready_command
884 (src->spawn_livetv->recorder))
885 GST_WARNING_OBJECT(src,
886 "Couldn't send the FRONTEND_READY message to the backend!");
888 GST_DEBUG_OBJECT(src, "FRONTEND_READY was sent to the backend");
895 ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
896 if (ret == GST_STATE_CHANGE_FAILURE) {
901 switch (transition) {
902 case GST_STATE_CHANGE_READY_TO_NULL:
903 gst_mythtv_src_clear(src);
905 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
906 case GST_STATE_CHANGE_PAUSED_TO_READY:
916 gst_mythtv_src_set_property(GObject * object, guint prop_id,
917 const GValue * value, GParamSpec * pspec)
919 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
921 GST_OBJECT_LOCK(mythtvsrc);
924 if (!g_value_get_string(value)) {
925 GST_WARNING("location property cannot be NULL");
929 if (mythtvsrc->uri_name != NULL) {
930 g_free(mythtvsrc->uri_name);
931 mythtvsrc->uri_name = NULL;
933 mythtvsrc->uri_name = g_value_dup_string(value);
935 case PROP_GMYTHTV_VERSION:
936 mythtvsrc->mythtv_version = g_value_get_int(value);
938 case PROP_GMYTHTV_LIVEID:
939 mythtvsrc->live_tv_id = g_value_get_int(value);
941 case PROP_GMYTHTV_LIVE:
942 mythtvsrc->live_tv = g_value_get_boolean(value);
944 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
945 mythtvsrc->enable_timing_position = g_value_get_boolean(value);
947 case PROP_GMYTHTV_LIVE_CHAINID:
948 if (!g_value_get_string(value)) {
949 GST_WARNING_OBJECT(object, "MythTV Live chainid property cannot be NULL");
953 if (mythtvsrc->live_chain_id != NULL) {
954 g_free(mythtvsrc->live_chain_id);
955 mythtvsrc->live_chain_id = NULL;
957 mythtvsrc->live_chain_id = g_value_dup_string(value);
959 case PROP_GMYTHTV_CHANNEL_NUM:
960 mythtvsrc->channel_name = g_value_dup_string(value);
963 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
967 GST_OBJECT_UNLOCK(mythtvsrc);
971 gst_mythtv_src_get_property(GObject * object, guint prop_id,
972 GValue * value, GParamSpec * pspec)
974 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object);
976 GST_OBJECT_LOCK(mythtvsrc);
979 g_value_set_string(value, mythtvsrc->uri_name);
981 case PROP_GMYTHTV_VERSION:
982 g_value_set_int(value, mythtvsrc->mythtv_version);
984 case PROP_GMYTHTV_LIVEID:
985 g_value_set_int(value, mythtvsrc->live_tv_id);
987 case PROP_GMYTHTV_LIVE:
988 g_value_set_boolean(value, mythtvsrc->live_tv);
990 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
991 g_value_set_boolean(value, mythtvsrc->enable_timing_position);
993 case PROP_GMYTHTV_LIVE_CHAINID:
994 g_value_set_string(value, mythtvsrc->live_chain_id);
996 case PROP_GMYTHTV_CHANNEL_NUM:
997 g_value_set_string(value, mythtvsrc->channel_name);
1000 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1003 GST_OBJECT_UNLOCK(mythtvsrc);
1007 plugin_init(GstPlugin * plugin)
1009 return gst_element_register(plugin, "mythtvsrc", GST_RANK_NONE,
1010 GST_TYPE_MYTHTV_SRC);
1013 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1017 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
1018 GST_PACKAGE_ORIGIN);
1021 /*** GSTURIHANDLER INTERFACE *************************************************/
1023 gst_mythtv_src_uri_get_type(void)
1029 gst_mythtv_src_uri_get_protocols(void)
1031 static gchar *protocols[] = { "myth", "myths", NULL };
1036 static const gchar *
1037 gst_mythtv_src_uri_get_uri(GstURIHandler * handler)
1039 GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1041 return src->uri_name;
1045 gst_mythtv_src_uri_set_uri(GstURIHandler * handler, const gchar * uri)
1047 GstMythtvSrc *src = GST_MYTHTV_SRC(handler);
1051 protocol = gst_uri_get_protocol(uri);
1052 if ((strcmp(protocol, "myth") != 0)
1053 && (strcmp(protocol, "myths") != 0)) {
1058 g_object_set(src, "location", uri, NULL);
1064 gst_mythtv_src_uri_handler_init(gpointer g_iface, gpointer iface_data)
1066 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1068 iface->get_type = gst_mythtv_src_uri_get_type;
1069 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1070 iface->get_uri = gst_mythtv_src_uri_get_uri;
1071 iface->set_uri = gst_mythtv_src_uri_set_uri;
1075 size_header_handler(void *userdata, const char *value)
1077 GstMythtvSrc *src = GST_MYTHTV_SRC(userdata);
1079 GST_DEBUG_OBJECT(src, "content size = %lld bytes", src->content_size);