mms_off_t mmsx_get_current_pos (mmsx_t *mmsx) { if(mmsx->connection) return mms_get_current_pos(mmsx->connection); else return mmsh_get_current_pos(mmsx->connection_h); }
static int mms_vfs_fseek_impl (VFSFile * file, int64_t offset, int whence) { MMSHandle * h = vfs_get_handle (file); if (whence == SEEK_CUR) { if (h->mms) offset += mms_get_current_pos (h->mms); else offset += mmsh_get_current_pos (h->mmsh); } else if (whence == SEEK_END) { if (h->mms) offset += mms_get_length (h->mms); else offset += mmsh_get_length (h->mmsh); } int64_t ret; if (h->mms) ret = mms_seek (NULL, h->mms, offset, SEEK_SET); else ret = mmsh_seek (NULL, h->mmsh, offset, SEEK_SET); if (ret < 0 || ret != offset) { fprintf (stderr, "mms: Seek failed.\n"); return -1; } return 0; }
static bool_t mms_vfs_feof_impl (VFSFile * file) { MMSHandle * h = vfs_get_handle (file); if (h->mms) return (mms_get_current_pos (h->mms) < mms_get_length (h->mms)); else return (mmsh_get_current_pos (h->mmsh) < mmsh_get_length (h->mmsh)); }
static int64_t mms_vfs_ftell_impl (VFSFile * file) { MMSHandle * h = vfs_get_handle (file); if (h->mms) return mms_get_current_pos (h->mms); else return mmsh_get_current_pos (h->mmsh); }
static GstFlowReturn gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf) { GstMMS *mmssrc; guint8 *data; guint blocksize; gint result; mmssrc = GST_MMS (psrc); GST_OBJECT_LOCK (mmssrc); blocksize = GST_BASE_SRC (mmssrc)->blocksize; GST_OBJECT_UNLOCK (mmssrc); *buf = gst_buffer_new_and_alloc (blocksize); data = GST_BUFFER_DATA (*buf); GST_BUFFER_SIZE (*buf) = 0; GST_LOG_OBJECT (mmssrc, "reading %d bytes", blocksize); if (mmssrc->connection) { result = mms_read (NULL, mmssrc->connection, (char *) data, blocksize); } else { result = mmsh_read (NULL, mmssrc->connection_h, (char *) data, blocksize); } /* EOS? */ if (result == 0) goto eos; if (mmssrc->connection) { GST_BUFFER_OFFSET (*buf) = mms_get_current_pos (mmssrc->connection) - result; } else { GST_BUFFER_OFFSET (*buf) = mmsh_get_current_pos (mmssrc->connection_h) - result; } GST_BUFFER_SIZE (*buf) = result; GST_LOG_OBJECT (mmssrc, "Returning buffer with offset %" G_GINT64_FORMAT " and size %u", GST_BUFFER_OFFSET (*buf), GST_BUFFER_SIZE (*buf)); gst_buffer_set_caps (*buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (mmssrc))); return GST_FLOW_OK; eos: { GST_DEBUG_OBJECT (mmssrc, "EOS"); gst_buffer_unref (*buf); *buf = NULL; return GST_FLOW_UNEXPECTED; } }
static off_t mms_plugin_get_current_pos (input_plugin_t *this_gen) { mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen; off_t curpos = 0; switch (this->protocol) { case PROTOCOL_MMST: curpos = mms_get_current_pos(this->mms); break; case PROTOCOL_MMSH: curpos = mmsh_get_current_pos(this->mmsh); break; } return curpos; }
static gboolean gst_mms_src_query (GstPad * pad, GstQuery * query) { GstMMS *mmssrc = GST_MMS (gst_pad_get_parent (pad)); gboolean res = TRUE; GstFormat format; gint64 value; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_parse_position (query, &format, &value); if (format != GST_FORMAT_BYTES) { res = FALSE; break; } if (mmssrc->connection) { value = (gint64) mms_get_current_pos (mmssrc->connection); } else { value = (gint64) mmsh_get_current_pos (mmssrc->connection_h); } gst_query_set_position (query, format, value); break; case GST_QUERY_DURATION: gst_query_parse_duration (query, &format, &value); if (format != GST_FORMAT_BYTES) { res = FALSE; break; } if (mmssrc->connection) { value = (gint64) mms_get_length (mmssrc->connection); } else { value = (gint64) mmsh_get_length (mmssrc->connection_h); } gst_query_set_duration (query, format, value); break; default: res = FALSE; break; } gst_object_unref (mmssrc); return res; }
static off_t mms_plugin_seek_time (input_plugin_t *this_gen, int time_offset, int origin) { mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen; off_t curpos = 0; lprintf ("seek_time %d msec, origin %d\n", time_offset, origin); switch (this->protocol) { case PROTOCOL_MMST: if (origin == SEEK_SET) mms_set_start_time (this->mms, time_offset); curpos = mms_get_current_pos (this->mms); break; case PROTOCOL_MMSH: if (origin == SEEK_SET) mmsh_set_start_time (this->mmsh, time_offset); curpos = mmsh_get_current_pos (this->mmsh); break; } return curpos; }
static off_t mms_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin) { mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen; off_t dest = 0; off_t curpos = 0; lprintf ("mms_plugin_seek: %"PRId64" offset, %d origin...\n", offset, origin); switch (this->protocol) { case PROTOCOL_MMST: curpos = mms_get_current_pos (this->mms); break; case PROTOCOL_MMSH: curpos = mmsh_get_current_pos (this->mmsh); break; } switch (origin) { case SEEK_SET: dest = offset; break; case SEEK_CUR: dest = curpos + offset; break; default: printf ("input_mms: unknown origin in seek!\n"); return curpos; } if (curpos > dest) { printf ("input_mms: cannot seek back!\n"); return curpos; } while (curpos < dest) { int n = 0; int diff; diff = dest - curpos; if (diff > 1024) diff = 1024; switch (this->protocol) { case PROTOCOL_MMST: n = mms_read (this->mms, this->scratch, diff); break; case PROTOCOL_MMSH: n = mmsh_read (this->mmsh, this->scratch, diff); break; } curpos += n; if (n < diff) return curpos; } return curpos; }