static int64_t mms_vfs_fread_impl (void * buf, int64_t size, int64_t count, VFSFile * file) { MMSHandle * h = vfs_get_handle (file); int64_t bytes_total = size * count; int64_t bytes_read = 0; while (bytes_read < bytes_total) { int64_t readsize; if (h->mms) readsize = mms_read (NULL, h->mms, (char *) buf + bytes_read, bytes_total - bytes_read); else readsize = mmsh_read (NULL, h->mmsh, (char *) buf + bytes_read, bytes_total - bytes_read); if (readsize < 0) fprintf (stderr, "mms: Read failed.\n"); if (readsize <= 0) break; bytes_read += readsize; } return size ? bytes_read / size : 0; }
int mmsx_read (mms_io_t *io, mmsx_t *mmsx, char *data, int len) { if(mmsx->connection) return mms_read(io, mmsx->connection, data, len); else return mmsh_read(io, mmsx->connection_h, data, len); }
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_read (input_plugin_t *this_gen, void *buf_gen, off_t len) { mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen; char *buf = (char *)buf_gen; off_t n = 0; lprintf ("mms_plugin_read: %"PRId64" bytes ...\n", len); switch (this->protocol) { case PROTOCOL_MMST: n = mms_read (this->mms, buf, len); break; case PROTOCOL_MMSH: n = mmsh_read (this->mmsh, buf, len); break; } return n; }
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; }