Beispiel #1
0
static gboolean
bus_message (GstBus * bus, GstMessage * message, gpointer data)
{
  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_EOS:
      g_print ("EOS\n");
      break;
    case GST_MESSAGE_ERROR:
    case GST_MESSAGE_WARNING:
      print_message (message);
      break;
    case GST_MESSAGE_SEGMENT_START:
      break;
    case GST_MESSAGE_SEGMENT_DONE:
      GST_DEBUG ("segment_done, doing next seek");
      if (!do_seek (hscale, FALSE, update_id == 0)) {
        if (changed_id == 0) {
          changed_id = gtk_signal_connect (GTK_OBJECT (hscale),
              "value_changed", G_CALLBACK (seek_cb), pipeline);
        }
      }
      break;
    default:
      break;
  }

  return TRUE;
}
Beispiel #2
0
static int sel_do_select(str* result, str *query_name, int row_no, int field_no, struct sip_msg* msg) {
	struct dbops_action *a;
	int cur_row_no, res;

	a = find_action_by_name(query_name->s, query_name->len);
	if (!a) {
		ERR(MODULE_NAME": select: query: %.*s not declared using declare_query param\n", query_name->len, query_name->s);
		return -1;
	}
	if (a->operation != OPEN_QUERY_OPS) {
		ERR(MODULE_NAME": select: query: %.*s is not select\n", query_name->len, query_name->s);
		return -1;
	}

	if (row_no < 0) {
		ERR(MODULE_NAME": select: Row number must not be negative: %d\n", row_no);
		return -1;
	}

	res = dbops_func(msg, a);
	if (res < 0) return res;
	cur_row_no = -1;
	if (field_no >= 0) {
		if (do_seek(a->result, &cur_row_no, row_no) < 0)
			return -1;
	}

	res = sel_get_field(result, &cur_row_no, field_no, a->result);
	db_res_free(a->result);
	return res;
}
Beispiel #3
0
static gboolean ui_slider_button_release_cb(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
{
    if (slider_seek_time != -1)
        do_seek (slider_seek_time);

    slider_is_moving = FALSE;
    return FALSE;
}
Beispiel #4
0
static int myth_read(const char *path, char *buf, size_t size, off_t offset,
		     struct fuse_file_info *fi)
{
	int tot, len = 0;

	pthread_mutex_lock(&mutex);

	debug("%s(): path '%s' size %lld\n", __FUNCTION__, path,
	      (long long)size);

	if (strcmp(path, README_PATH) == 0) {
		pthread_mutex_unlock(&mutex);
		return readme_read(path, buf, size, offset, fi);
	}

	if ((int)fi->fh == -1) {
		pthread_mutex_unlock(&mutex);
		return -ENOENT;
	}

	if (files[fi->fh].offset != offset) {
		if (do_seek(fi->fh, offset, SEEK_SET) < 0) {
			goto fail;
		}
	}

	tot = 0;
	while (size > 0) {
		len = (size > MAX_BSIZE) ? MAX_BSIZE : size;
		if ((len=fill_buffer(fi->fh, buf+tot, len)) <= 0)
			break;
		size -= len;
		tot += len;
	}

	files[fi->fh].offset = offset + tot;

	debug("%s(): read %d bytes at %lld (len %d)\n", __FUNCTION__,
	      tot, (long long)offset, len);

	if (len < 0) {
		goto fail;
	}

	pthread_mutex_unlock(&mutex);

	return tot;

fail:
	debug("%s(): shutting down file connection!\n", __FUNCTION__);

	ref_release(files[fi->fh].file);
	memset(files+fi->fh, 0, sizeof(files[0]));
	pthread_mutex_unlock(&mutex);

	return -ENOENT;
}
Beispiel #5
0
void WinFileStream::setEof(uint64_t newSize)
{
	assert(INVALID_HANDLE_VALUE != m_hFile);
	uint64_t oldPos = do_seek(newSize, FILE_BEGIN);
	BOOL bRet = SetEndOfFile(m_hFile);
	seek(oldPos, FILE_BEGIN);
	if (!bRet)
		throw IOException(ErrorText(GetLastError()).c_str());
}
Beispiel #6
0
void task_fs(){
#ifdef DEBUG_FS
    printl("in task_fs\n");
#endif
    init_fs();
    MESSAGE message;
    memset(&message,0,sizeof(message));
    while(TRUE){
        send_receive(RECEIVE,ANY,&message);
        
        int source_pid=message.source_pid;
        int fd;
	
        switch(message.type){
        case INFO_FS_CREATE:
            message.res_bool=do_create(&message);
            break;
        case INFO_FS_UNLINK:
            message.res_bool=do_unlink(&message);
            break;
        case INFO_FS_LS:
            message.res_int=do_ls(&message);
            break;
        case INFO_FS_OPEN:
            fd=do_open(&message);
            message.fd=fd;
            break;
        case INFO_FS_READ:
            do_read(&message);
            break;
        case INFO_FS_WRITE:
            do_write(&message);
            break;
        case INFO_FS_SEEK:
            do_seek(&message);
            break;
        case INFO_FS_CLOSE:
            message.res_int=do_close(&message);
            break;
        default:
            printl("\n\n\nunknown message type:%d\n",message.type);
            assert(FALSE,"unknown message type!");
        }
        if(message.type!=INFO_SUSPEND_PROCESS){
            send_receive(SEND,source_pid,&message);
        }else{
            printl("inof_suspend_process\n");
        }
    }
#ifndef _FS_H_
#define _FS_H_
    
#endif /* _FS_H_ */
    while(1)
        ;
    spin("never here");
}
Beispiel #7
0
static int dbops_next_func(struct sip_msg* m, char* handle, char* row_no) {
	int res;
	struct dbops_handle *a = (void *) handle;
	res = check_query_opened(a, "next");
	if (res < 0) return res;
	
	res = do_seek(a->result, &a->cur_row_no, a->cur_row_no+1);
	if (res < 0) return res;
	return 1;
}
Beispiel #8
0
static int dbops_first_func(struct sip_msg* m, char* handle, char* row_no) {
	int res;
	struct dbops_handle *a = (void *) handle;
	res = check_query_opened(a, "first");
	if (res < 0) return res;
	
	a->cur_row_no = -1; /* force seek */
	res = do_seek(a->result, &a->cur_row_no, 0);
	if (res < 0) return res;
	return 1;
}
Beispiel #9
0
static void
seek_cb (GtkWidget * widget)
{
  if (changed_id) {
    GST_DEBUG ("seek because of slider move");

    if (do_seek (widget, TRUE, TRUE)) {
      g_source_remove (changed_id);
      changed_id = 0;
    }
  }
}
Beispiel #10
0
static int dbops_seek_func(struct sip_msg* m, char* handle, char* row_no) {
	int res, n;
	struct dbops_handle *a = (void *) handle;
	res = check_query_opened(a, "seek");
	if (res < 0) return res;

	if (get_int_fparam(&n, m, (fparam_t*) row_no) < 0) {
		return -1;
	}
	res = do_seek(a->result, &a->cur_row_no, n);
	if (res < 0) return res;
	return 1;
}
Beispiel #11
0
static gboolean ui_slider_change_value_cb (GtkRange * range,
 GtkScrollType scroll, gdouble value)
{
    gint length = aud_drct_get_length ();
    gint time = CLAMP ((gint) value, 0, length);

    set_time_label (time, length);

    if (slider_is_moving)
        slider_seek_time = time;
    else if (time != slider_seek_time)  // avoid seeking twice
        do_seek (time);

    return FALSE;
}
Beispiel #12
0
static int
loader_22dsk_seek(libdisk_prop_t *prop)
{
  long offset;
  int a, h, c, s;
  dsk_data_t *data;

  if (prop == NULL)
    return -1;

  if (prop->data == NULL)
    return -1;

  h = prop->head;
  c = prop->cylinder;
  s = prop->sector;

  if ((h < 0) || (h > 1))
    return -1;

  if ((c < 0) || (c > 79))
    return -1;

  if ((s < 1) || (s > 5))
    return -1;

  data = (dsk_data_t *)prop->data;

  offset = -1;
  for (a = 0;a < data->len;a++)
    {
      if ((h == data->offset[a].head) &&
          (c == data->offset[a].cylinder) &&
          (s == data->offset[a].sector))
        {
	  offset = data->offset[a].offset;
	  break;
        }
    }

  if (offset == -1)
    return -1;

  if (do_seek(data, offset) < 0)
    return -1;

  return 0;
}
Beispiel #13
0
static gboolean
stop_seek (GtkWidget * widget, gpointer user_data)
{
  update_id =
      g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);

  GST_DEBUG ("stop seek");

  if (changed_id) {
    g_source_remove (changed_id);
    changed_id = 0;
  }

  do_seek (hscale, FALSE, FALSE);

  return FALSE;
}
Beispiel #14
0
 int File::read(vector<unsigned char>& buf, char delim)
 {
     if (writable_) { throw logic_error("File not readable"); }
     
     vector<unsigned char> buffer;
     vector<unsigned char>::iterator it;
     while (!eof_) {
         do_read(buffer, 1024);
         it = find(buffer.begin(), buffer.end(), delim);
         buf.insert(buf.end(), buffer.begin(), it);
         if (it != buffer.end()) { // Found delim
             do_seek(static_cast<int>(-(distance(it, buffer.end()) - 1)), 0);
             break;
         }
     }
     return (int)buf.size();
 }
Beispiel #15
0
static int dbops_query_func(struct sip_msg* m, char* dbops_action, char* handle) {
	if ( ((struct dbops_action*) dbops_action)->operation == OPEN_QUERY_OPS ) {
		int res;
		struct dbops_handle *a = (void*) handle;
		dbops_close_query_func(m, handle, 0);
		res = dbops_func(m, (void*) dbops_action);
		if (res < 0) return res;
		a->action = (struct dbops_action*) dbops_action;
		a->cur_row_no = -1;
		a->result = ((struct dbops_action*) dbops_action)->result;
		res = do_seek(((struct dbops_action*) dbops_action)->result, &a->cur_row_no, 0);
		if (res < 0) return res;
		return 1;
	}
	else
		return dbops_func(m, (void*) dbops_action);
}
Beispiel #16
0
int main(int argc, char *argv[]) {

    init();

    anvil_name_reg("/initrd", 1, 0);

    while (1) {

        anvil_msginfo_t     msg_info;
        char                buf[100];
        int                 err;

        err = msg_receive(buf, sizeof buf, &msg_info);

        switch (msg_info.type) {

            case ANVIL_OPEN:
                do_open(buf, &msg_info);
                break;
            case ANVIL_CLOSE:
                do_close(buf, &msg_info);
                break;
            case ANVIL_READ:
                do_read(buf, &msg_info);
                break;
            case ANVIL_SEEK:
                do_seek(buf, &msg_info);
                break;
            case ANVIL_STAT:
                do_stat(buf, &msg_info);
                break;
            default:
                break;

        }
    }

    return 0;
}
OMX_ERRORTYPE cmd_process(HTEST *hTest)
{
    char rep[10];
    OMX_BOOL bExit = OMX_FALSE;

    while(bExit == OMX_FALSE) {
        printf("Input test cmd:\n");
        printf("[f]flush\n");
        printf("[x]exit\n");
        scanf("%s", rep);
        if(rep[0] == 'l')
            load_component(hTest);
        else if(rep[0] == 's') {
            OMX_U32 state = 0;
            printf("State trans to:\n");
            printf("0 -- Invalid\n");
            printf("1 -- Loaded\n");
            printf("2 -- Idle\n");
            printf("3 -- Executing\n");
            printf("4 -- Pause\n");
            printf("5 -- WaitForResources\n");
            scanf("%d", &state);
            StateTrans(hTest, (OMX_STATETYPE)state);
        }
        else if(rep[0] == 'f') {
            OMX_U32 nPortIndex = 0;
            printf("Want to flush port number:\n");
            scanf("%d", &nPortIndex);
            port_flush(hTest, nPortIndex);
        }
        else if(rep[0] == 'd') {
            OMX_U32 nPortIndex = 0;
            printf("Want to disbale port number:\n");
            scanf("%d", &nPortIndex);
            port_disable(hTest, nPortIndex);
        }
        else if(rep[0] == 'e') {
            OMX_U32 nPortIndex = 0;
            printf("Want to enable port number:\n");
            scanf("%d", &nPortIndex);
            port_enable(hTest, nPortIndex);
        }
        else if(rep[0] == 'k') {
            OMX_U32 nSeekPos = 0;
            printf("seek to second:\n");
            scanf("%d", &nSeekPos);
            OMX_U32 nSeekMode = 0;
            printf("seek mode [0:Fast,1:Accurate]:\n");
            scanf("%d", &nSeekMode);
            do_seek(hTest, nSeekPos, (OMX_TIME_SEEKMODETYPE)nSeekMode);
        }
        else if(rep[0] == 'x') {
            MSG sMsg;
            sMsg.type = EXIT;
            hTest->pMsgQ->Add(&sMsg);
            hTest->bStop = OMX_TRUE;
            bExit = OMX_TRUE;
            StateTrans(hTest, (OMX_STATETYPE)2);
            StateTrans(hTest, (OMX_STATETYPE)1);
            unload_component(hTest);
        }
    }

    return OMX_ErrorNone;
}
Beispiel #18
0
int main(int argc, char **argv)
{
	int opt;
	int len, rc;
	struct sigaction sigact;
	char *rest;
	int oflags = 0;
	int no_tag;

	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_handler = sighandler;

	if (sigaction(SIGALRM, &sigact, NULL) == -1)
		return 1;

	if (sigaction(SIGPIPE, &sigact, NULL) == -1)
		return 1;

	input = stdin;
	output = stdout;
	/* now parsing options with getopt */
	while ((opt = getopt(argc, argv, options)) != EOF) {
		switch (opt) {
		case 'c':
			rc = chdir(optarg);
			if (rc == -1) {
				fprintf(stderr,
					"Can not change dir to %s errno = %d \"%s\"\n",
					optarg, errno, strerror(errno));
				exit(1);
			}
			break;

		case 'q':
			quiet = true;
			break;

		case 'd':
			duperrors = true;
			break;

		case 's':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -s\n");

			oflags |= 1;
			script = true;
			strncpy(server, optarg, MAXSTR);
			break;

		case 'x':
			if ((oflags & 7) != 0)
				show_usage(1,
					   "Can not combine -x and -s/-p/-n\n");

			oflags |= 8;
			script = true;
			input = fopen(optarg, "r");

			if (input == NULL)
				fatal("Could not open %s\n", optarg);
			break;

		case 'n':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -n\n");

			oflags |= 2;
			strncpy(name, optarg, MAXSTR);
			break;

		case 'p':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -p\n");

			oflags |= 4;
			strncpy(portstr, optarg, MAXSTR);
			port = atoi(optarg);
			break;

		case '?':
		case 'h':
		default:
			/* display the help */
			show_usage(0, "Help\n");
		}
	}

	if (oflags > 0 && oflags < 7)
		show_usage(1, "Must specify -s, -p, and -n together\n");

	if (oflags == 7)
		openserver();

	while (1) {
		len = readln(input, line, MAXSTR * 2);
		if (len < 0) {
			if (script)
				fatal("End of file on input\n");
			else
				break;
		} else {
			struct response resp;

			lno++;
			memset(&resp, 0, sizeof(resp));

			rest = SkipWhite(line, REQUIRES_MORE, "Invalid line");

			/* Skip totally blank line */
			if (rest == NULL)
				continue;

			if (script && !quiet)
				fprintf(stdout, "%s\n", rest);

			/* If line doesn't start with a tag, that's ok */
			no_tag = (!isdigit(*rest) && (*rest != '$'));

			/* Parse request into response structure */
			rest = parse_request(rest, &resp, no_tag);

			if (rest == NULL) {
				resp.r_status = STATUS_ERRNO;
				resp.r_errno = errno;
			} else {
				/* Make sure default status is ok */
				resp.r_status = STATUS_OK;

				if (*rest != '\0' && *rest != '#')
					fprintf_stderr(
					     "Command line not consumed, rest=\"%s\"\n",
					     rest);

				switch (resp.r_cmd) {
				case CMD_OPEN:
					do_open(&resp);
					break;
				case CMD_CLOSE:
					do_close(&resp);
					break;
				case CMD_LOCKW:
					do_lock(&resp);
					break;
				case CMD_LOCK:
					do_lock(&resp);
					break;
				case CMD_UNLOCK:
					do_unlock(&resp);
					break;
				case CMD_TEST:
					do_test(&resp);
					break;
				case CMD_LIST:
					do_list(&resp);
					break;
				case CMD_HOP:
					do_hop(&resp);
					break;
				case CMD_UNHOP:
					do_unhop(&resp);
					break;
				case CMD_SEEK:
					do_seek(&resp);
					break;
				case CMD_READ:
					do_read(&resp);
					break;
				case CMD_WRITE:
					do_write(&resp);
					break;
				case CMD_ALARM:
					do_alarm(&resp);
					break;

				case CMD_HELLO:
				case CMD_COMMENT:
				case CMD_QUIT:
					resp.r_status = STATUS_OK;
					break;

				case NUM_COMMANDS:
					fprintf_stderr("Invalid command %s\n",
						       line);
					continue;
				}
			}

			respond(&resp);

			if (resp.r_cmd == CMD_QUIT)
				exit(0);
		}
	}

	return 0;
}
Beispiel #19
0
static gboolean window_keypress_cb (GtkWidget * widget, GdkEventKey * event, void * unused)
{
    switch (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK))
    {
      case 0:;
        GtkWidget * focused = gtk_window_get_focus ((GtkWindow *) window);

        /* escape key returns focus to playlist */
        if (event->keyval == GDK_KEY_Escape)
        {
            if (! focused || ! gtk_widget_is_ancestor (focused, (GtkWidget *) UI_PLAYLIST_NOTEBOOK))
                gtk_widget_grab_focus (playlist_get_treeview (aud_playlist_get_active ()));

            return FALSE;
        }

        /* single-key shortcuts; must not interfere with text entry */
        if (focused && GTK_IS_ENTRY (focused))
            return FALSE;

        switch (event->keyval)
        {
        case 'z':
            aud_drct_pl_prev ();
            return TRUE;
        case 'x':
            aud_drct_play ();
            return TRUE;
        case 'c':
        case ' ':
            aud_drct_pause ();
            return TRUE;
        case 'v':
            aud_drct_stop ();
            return TRUE;
        case 'b':
            aud_drct_pl_next ();
            return TRUE;
        case GDK_KEY_Left:
            if (aud_drct_get_playing ())
                do_seek (aud_drct_get_time () - 5000);
            return TRUE;
        case GDK_KEY_Right:
            if (aud_drct_get_playing ())
                do_seek (aud_drct_get_time () + 5000);
            return TRUE;
        }

        return FALSE;

      case GDK_CONTROL_MASK:
        switch (event->keyval)
        {
          case GDK_KEY_ISO_Left_Tab:
          case GDK_KEY_Tab:
            aud_playlist_set_active ((aud_playlist_get_active () + 1) %
             aud_playlist_count ());
            break;

          default:
            return FALSE;
        }
        break;
      case (GDK_CONTROL_MASK | GDK_SHIFT_MASK):
        switch (event->keyval)
        {
          case GDK_KEY_ISO_Left_Tab:
          case GDK_KEY_Tab:
            aud_playlist_set_active (aud_playlist_get_active () ?
             aud_playlist_get_active () - 1 : aud_playlist_count () - 1);
            break;
          default:
            return FALSE;
        }
        break;
      case GDK_MOD1_MASK:
        switch (event->keyval)
        {
          case GDK_KEY_Left:
            if (aud_drct_get_playing ())
                do_seek (aud_drct_get_time () - 5000);
            break;
          case GDK_KEY_Right:
            if (aud_drct_get_playing ())
                do_seek (aud_drct_get_time () + 5000);
            break;
          default:
            return FALSE;
        }
      default:
        return FALSE;
    }

    return TRUE;
}
Beispiel #20
0
/* Reads N bytes from EA at byte offset OFFSET into DATA.
   Returns true if successful, false on failure.  */
bool
ext_array_read (const struct ext_array *ea, off_t offset, size_t n, void *data)
{
  return do_seek (ea, offset) && do_read (ea, data, n);
}
Beispiel #21
0
/* Writes the N bytes in DATA to EA at byte offset OFFSET.
   Returns true if successful, false on failure.  */
bool
ext_array_write (struct ext_array *ea, off_t offset, size_t n,
                 const void *data)
{
  return do_seek (ea, offset) && do_write (ea, data, n);
}
Beispiel #22
0
void WinFileStream::seek(int64_t offset, int origin)
{
	(void)do_seek(offset, origin);
}
Beispiel #23
0
static gboolean
bus_message (GstBus * bus, GstMessage * message, App * app)
{
    gchar *sourceName;
    GstObject *source;
    gchar *string;
    GstState current_state;

    if (!message)
        return FALSE;
    source = GST_MESSAGE_SRC (message);
    if (!GST_IS_OBJECT (source))
        return FALSE;
    sourceName = gst_object_get_name (source);

    if (gst_message_get_structure (message))
        string = gst_structure_to_string (gst_message_get_structure (message));
    else
        string = g_strdup (GST_MESSAGE_TYPE_NAME (message));
    GST_DEBUG("gst_message from %s: %s", sourceName, string);
    g_free (string);

    switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:
    {
        GError *gerror;
        gchar *debug;

        gst_message_parse_error (message, &gerror, &debug);
        gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
        g_error_free (gerror);
        g_free (debug);

        g_main_loop_quit (app->loop);
        break;
    }
    case GST_MESSAGE_WARNING:
    {
        GError *gerror;
        gchar *debug;

        gst_message_parse_warning (message, &gerror, &debug);
        gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
        g_error_free (gerror);
        g_free (debug);

//       g_main_loop_quit (app->loop);
        break;
    }
    case GST_MESSAGE_EOS:
        g_message ("received EOS");
        g_main_loop_quit (app->loop);
        break;
    case GST_MESSAGE_ASYNC_DONE:
        break;
    case GST_MESSAGE_ELEMENT:
    {
        const GstStructure *msgstruct = gst_message_get_structure (message);
        if (msgstruct) {
            const gchar *eventname = gst_structure_get_name (msgstruct);
            if (!strcmp (eventname, "seekable"))
                app->is_seekable = TRUE;
        }
        break;
    }
    case GST_MESSAGE_STATE_CHANGED:
    {
        GstState old_state, new_state;
        GstStateChange transition;
        if (GST_MESSAGE_SRC (message) != GST_OBJECT (app->tsdemux))
            break;

        gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
        transition = (GstStateChange) GST_STATE_TRANSITION (old_state, new_state);

        switch (transition) {
        case GST_STATE_CHANGE_NULL_TO_READY:
            break;
        case GST_STATE_CHANGE_READY_TO_PAUSED:
            break;
        case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
        {

        }
        break;
        case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
            break;
        case GST_STATE_CHANGE_PAUSED_TO_READY:
            break;
        case GST_STATE_CHANGE_READY_TO_NULL:
            break;
        }
        break;
    }
    case GST_MESSAGE_SEGMENT_DONE:
    {
        GST_DEBUG ("GST_MESSAGE_SEGMENT_DONE!!!");
        do_seek (app);
    }
    default:
        break;
    }
    gst_element_get_state (app->pipeline, &current_state, NULL, 0);
    if (app->current_segment == 0 && app->segment_count /*&& app->is_seekable*/
            && current_state == GST_STATE_PLAYING)
        do_seek (app);
    GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(app->pipeline),GST_DEBUG_GRAPH_SHOW_ALL,"bdremux_pipelinegraph_message");
    return TRUE;
}
Beispiel #24
0
static int dvd_seek_to_time(stream_t *stream, ifo_handle_t *vts_file, double sec)
{
    unsigned int i, j, k, timeunit, ac_time, tmap_sector=0, cell_sector=0, vobu_sector=0;
    int t=0;
    double tm, duration;
    int64_t pos = -1;
    dvd_priv_t *d = stream->priv;
    vts_tmapt_t *vts_tmapt = vts_file->vts_tmapt;

    if(!vts_file->vts_tmapt || sec < 0)
        return 0;

    duration = (double) mp_get_titleset_length(d->vts_file, d->tt_srpt, d->cur_title) / 1000.0f;
    if(sec > duration)
      return 0;

    i=d->cur_pgc_idx;
    timeunit = vts_tmapt->tmap[i].tmu;
    for(j = 0; j < vts_tmapt->tmap[i].nr_of_entries; j++) {
      ac_time = timeunit * (j + 1);
      if(ac_time >= sec)
        break;
      tmap_sector = vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff;
    }
    //search enclosing cell
    for(i=0; i<d->cur_pgc->nr_of_cells; i++) {
      if(tmap_sector >= d->cur_pgc->cell_playback[i].first_sector && tmap_sector <= d->cur_pgc->cell_playback[i].last_sector) {
        cell_sector = d->cur_pgc->cell_playback[i].first_sector;
        break;
      }
    }

    pos = ((int64_t)cell_sector)<<11;
    do_seek(stream, pos);
    do {
      char buf[2048];
      if (dvd_read_sector(stream, stream->priv, buf) < 0) // skip
          break;
      t = mp_dvdtimetomsec(&d->dsi_pack.dsi_gi.c_eltm);
    } while(!t);
    tm = dvd_get_current_time(stream, -1);

    pos = ((int64_t)tmap_sector)<<11;
    do_seek(stream, pos);
    //now get current time in terms of the cell+cell time offset
    memset(&d->dsi_pack.dsi_gi.c_eltm, 0, sizeof(dvd_time_t));
    while(tm <= sec) {
        char buf[2048];
        if (dvd_read_sector(stream, stream->priv, buf) < 0) // skip
            break;
        pos += 2048;
        tm = dvd_get_current_time(stream, -1);
    };
    tmap_sector = pos >> 11;

    //search closest VOBU sector
    k=(vts_file->vts_vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE)/4; //entries in the vobu admap
    for(i=1; i<k; i++) {
      if(vts_file->vts_vobu_admap->vobu_start_sectors[i] > tmap_sector)
        break;
    }
    vobu_sector = vts_file->vts_vobu_admap->vobu_start_sectors[i-1];
    pos = ((int64_t)vobu_sector) << 11;
    do_seek(stream, pos);

    return 1;
}
int
main (int argc, char **argv)
{
	int exit = 0;
	char *buffer = g_new (char, 1024) ;
	GIOChannel *ioc;
	guint watch_id = 0;
	GOptionContext *ctx = NULL;
	GError *error = NULL;

	/* default to interactive on a terminal */
	interactive = isatty (0);

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	files = g_hash_table_new (g_str_hash, g_str_equal);

	if (noninteractive)
		interactive = FALSE;

	if (interactive)
		vfserr = stderr;
	else
		vfserr = stdout;

	if (!mate_vfs_init ()) {
		fprintf (vfserr, "Cannot initialize mate-vfs.\n");
		return 1;
	}
	mate_vfs_module_callback_push
		(MATE_VFS_MODULE_CALLBACK_AUTHENTICATION,
		 authentication_callback, NULL, NULL);

	if (argc == 1)
		cur_dir = g_get_current_dir ();
	else
		cur_dir = g_strdup(argv[1]);

	if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1]))
		cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL);

	if (interactive == TRUE) {
		main_loop = g_main_loop_new (NULL, TRUE);
		ioc = g_io_channel_unix_new (0 /* stdin */);
		g_io_channel_set_encoding (ioc, NULL, NULL);
		g_io_channel_set_buffered (ioc, FALSE);
		watch_id = g_io_add_watch (ioc,
					   G_IO_IN | G_IO_HUP | G_IO_ERR,
					   callback, buffer);
		g_io_channel_unref (ioc);
	}

	while (!exit) {
		char *ptr;

		if (interactive) {
			fprintf (stdout,"\n%s > ", cur_dir);
			fflush (stdout);

			strcpy (buffer, "");
			g_main_loop_run (main_loop);
		} else {
			/* In non-interactive mode we just do this evil
			 * thingie */
			buffer[0] = '\0';
			fgets (buffer, 1023, stdin);
			if (!buffer [0]) {
				exit = 1;
				continue;
			}
		}

		if (!buffer || buffer [0] == '#')
			continue;

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if ((!arg_data || !arg_data[0]) && interactive) continue;
		if (!interactive)
			printf ("Command : '%s'\n", arg_data [0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_ascii_strcasecmp (ptr, "ls") == 0)
			do_ls ();
		else if (g_ascii_strcasecmp (ptr, "cd") == 0)
			do_cd ();
		else if (g_ascii_strcasecmp (ptr, "dump") == 0)
			do_dump ();
		else if (g_ascii_strcasecmp (ptr, "type") == 0 ||
			 g_ascii_strcasecmp (ptr, "cat") == 0)
			do_cat ();
		else if (g_ascii_strcasecmp (ptr, "cp") == 0)
			do_cp ();
		else if (g_ascii_strcasecmp (ptr, "rm") == 0)
			do_rm ();
		else if (g_ascii_strcasecmp (ptr, "mkdir") == 0)
			do_mkdir ();
		else if (g_ascii_strcasecmp (ptr, "rmdir") == 0)
			do_rmdir ();
		else if (g_ascii_strcasecmp (ptr, "mv") == 0)
			do_mv ();
		else if (g_ascii_strcasecmp (ptr, "info") == 0 ||
			 g_ascii_strcasecmp (ptr, "stat") == 0)
			do_info ();
		else if (g_ascii_strcasecmp (ptr, "findtrash") == 0)
			do_findtrash ();
		else if (g_ascii_strcasecmp (ptr, "ssl") == 0)
			do_ssl ();
		else if (g_ascii_strcasecmp (ptr, "sync") == 0)
			fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n");
		else if (g_ascii_strcasecmp (ptr,"help") == 0 ||
			 g_ascii_strcasecmp (ptr,"?")    == 0 ||
			 g_ascii_strcasecmp (ptr,"info") == 0 ||
			 g_ascii_strcasecmp (ptr,"man")  == 0)
			list_commands ();
		else if (g_ascii_strcasecmp (ptr,"exit") == 0 ||
			 g_ascii_strcasecmp (ptr,"quit") == 0 ||
			 g_ascii_strcasecmp (ptr,"q")    == 0 ||
			 g_ascii_strcasecmp (ptr,"bye") == 0)
			exit = 1;

		/* File ops */
		else if (g_ascii_strcasecmp (ptr, "open") == 0)
			do_open ();
		else if (g_ascii_strcasecmp (ptr, "create") == 0)
			do_create ();
		else if (g_ascii_strcasecmp (ptr, "close") == 0)
			do_close ();
		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
			do_handleinfo ();
		else if (g_ascii_strcasecmp (ptr, "read") == 0)
			do_read ();
		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
			do_seek ();
		
		else
			fprintf (vfserr, "Unknown command '%s'", ptr);

		g_strfreev (arg_data);
		arg_data = NULL;
	}

	if (interactive) {
		g_source_remove (watch_id);
		g_main_loop_unref (main_loop);
		main_loop = NULL;
	}

	g_free (buffer);
	g_free (cur_dir);

	close_files ();

	return 0;
}
Beispiel #26
0
void*
video_read_start(void *arg)
{
	pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
	int ret;
	int n = 0, len = 0, reset = 1;
	int sent_idle_notify;
	demux_attr_t *attr;
	video_info_t *vi;
	int set_aspect = 1;
	char *inbuf = inbuf_static;
	char *tsbuf;
	int tslen;
	int tsmode = TS_MODE_UNKNOWN;
	av_state_t state;

	pthread_mutex_lock(&mutex);

	printf("mpeg read thread started (pid %d)\n", getpid());
	pthread_cond_wait(&video_cond, &mutex);

	while (1) {
		sent_idle_notify = 0;
		while (!video_playing) {
			demux_reset(handle);
			ts_demux_reset(tshandle);
			demux_seek(handle);
			vid_event_discontinuity_possible();
			if ( !(sent_idle_notify) ) {
				if ( video_functions != NULL &&
				     video_functions->notify != NULL ) {
					video_functions->notify(MVP_READ_THREAD_IDLE);
				}
				printf("mpeg read thread sleeping...\n");
				sent_idle_notify = 1;
			}
			pthread_cond_wait(&video_cond, &mutex);
			TRC("%s: past pthread_cond_wait(&video_cond, &mutex)\n", __FUNCTION__);
		}

#ifdef STREAM_TEST
		if ( stream_test_started == 0 ) {
			stream_test_started = 1;
			//Get start time
			gettimeofday(&start_tv, NULL);
		}
#endif

		if (video_reopen) {
		        vid_event_clear();
			if (video_functions->open() == 0) {
				/* Jump to the start of the new file */
				jump_target = 0;
				jumping = 1;
				video_reopen = 0;
				tsmode = TS_MODE_UNKNOWN;
			} else {
				fprintf(stderr, "video open failed!\n");
				video_playing = 0;
				continue;
			}
			len = 0;
			reset = 1;
			set_aspect = 1;
		}

		if ((seeking && reset) || jumping) {
			demux_reset(handle);
			ts_demux_reset(tshandle);
			demux_seek(handle);
			av_get_state(&state);
			av_reset();
			av_reset_stc();
			vid_event_discontinuity_possible();
			if (seeking)
				reset = 0;
			if (state.mute)
				av_set_mute(1);
			if (paused) {
				av_play();
				paused = 0;
				mvpw_hide(pause_widget);
				screensaver_disable();
			}
			pcm_decoded = 0;
			ac3len = 0;
			len = 0;
			if (jumping) {
				while (jump_target < 0)
					usleep(1000);
				video_functions->seek(jump_target, SEEK_SET);
			}
			jumping = 0;
		}

		if ( !video_playing ) {
			continue;
		}

		if (len == 0) {

			if ( video_functions->read_dynb != NULL ){
				tslen = video_functions->read_dynb(&tsbuf, 1024 * 256);
			}
			else {
				tsbuf = tsbuf_static;
				do {
					tslen = video_functions->read(tsbuf,
						      sizeof(tsbuf_static));
				} while ( tslen==-1 && errno==EAGAIN);
			}
			thruput_count += tslen;
			inbuf = inbuf_static;

			if (tsmode == TS_MODE_UNKNOWN) {
				if (tslen > 0) {
					tsmode = ts_demux_is_ts(tshandle, tsbuf, tslen);
					printf("auto detection transport stream returned %d\n", tsmode);
					if (tsmode == TS_MODE_NO)
						len = tslen;
			    	}
			} else if (tsmode == TS_MODE_NO) {
				len = tslen;
			} else {
				len = ts_demux_transform(tshandle, tsbuf, tslen, inbuf, sizeof(inbuf_static));
				int resyncs = ts_demux_resync_count(tshandle);
				if (resyncs > 50) {
					printf("resync count = %d, switch back to unknown mode\n", resyncs);
					tsmode = TS_MODE_UNKNOWN;
					ts_demux_reset(tshandle);
				}
			}
			n = 0;
			if (len == 0 && playlist ) {
				video_reopen = 2;
				playlist_next();
			}
		}

		if ( !video_playing ) {
			continue;
		}

#ifdef STREAM_TEST
		stream_test_cnt += len;
		len = 0;

		if ( stream_test_cnt > 1024*1024*20 ) {
			unsigned int delta_ms;

			gettimeofday(&done_tv, NULL);
			if ( done_tv.tv_usec < start_tv.tv_usec ) {
				done_tv.tv_usec += 1000000;
				done_tv.tv_sec	 -= 1;
			}
			delta_ms = (done_tv.tv_sec - start_tv.tv_sec) * 1000;
			delta_ms += (done_tv.tv_usec - start_tv.tv_usec) / 1000;
			printf("Test Done\n");
			printf("Bytes transferred: %u\n", stream_test_cnt);
			printf("Elapsed time %u mS\n", delta_ms);
			while ( 1 ) {
				sleep(10);
				printf("Test Done....\n");
			}
		}
		continue;
#else
		if (tsmode == TS_MODE_YES)
			ret = DEMUX_PUT(handle, inbuf+n, len-n);
		else
			ret = DEMUX_PUT(handle, tsbuf+n, len-n);
#endif

		if ((ret <= 0) && (!seeking)) {
			pthread_cond_broadcast(&video_cond);
			usleep(1000);
			continue;
		}

		if (seeking) { 
			if (do_seek()) {
				len = 0;
				continue;
			} else {
				reset = 1;
			}
		}

		n += ret;
		if (n == len)
			len = 0;

		pthread_cond_broadcast(&video_cond);

		attr = demux_get_attr(handle);
		vi = &attr->video.stats.info.video;
		if (attr->audio.type != audio_type) {
			audio_type = attr->audio.type;
			switch (audio_type) {
			case AUDIO_MODE_AC3:
				if (audio_output_mode == AUD_OUTPUT_PASSTHRU ) {
					if (av_set_audio_output(AV_AUDIO_AC3) < 0) {
						/* revert to downmixing */
						audio_output_mode = AUD_OUTPUT_STEREO;
					    // fall through to PCM
					} else {
                                    // don't set audio_type
						audio_output = AV_AUDIO_AC3;
						printf("switch to AC3 Passthru\n");
						break;
					}
				}
			case AUDIO_MODE_PCM:
				audio_output = AV_AUDIO_PCM;
				printf("switch to PCM audio output device\n");
				break;
			default:
				av_set_audio_type(audio_type);
				audio_output = AV_AUDIO_MPEG;
				printf("switch to MPEG audio output device\n");
				break;
			}
			av_set_audio_output(audio_output);
		} else {
			if (audio_type==AUDIO_MODE_AC3){
				sync_ac3_audio();
			}
		}

	} //while

	return NULL;
}