Esempio n. 1
0
 std::shared_ptr<stream_profile_interface> stream_profile_base::clone() const
 {
     auto res = std::make_shared<stream_profile_base>(get_backend_profile());
     res->set_unique_id(environment::get_instance().generate_stream_id());
     res->set_framerate(get_framerate());
     return res;
 }
Esempio n. 2
0
    std::shared_ptr<stream_profile_interface> software_sensor::add_video_stream(rs2_video_stream video_stream)
    {
        auto exist = (std::find_if(_profiles.begin(), _profiles.end(), [&](std::shared_ptr<stream_profile_interface> profile)
        {
            if (profile->get_unique_id() == video_stream.uid)
            {
                return true;
            }
            return false;
        } ) != _profiles.end());

        if (exist)
        {
            LOG_WARNING("Stream unique ID already exist!");
            throw rs2::error("Stream unique ID already exist!");
        }

        auto profile = std::make_shared<video_stream_profile>(
            platform::stream_profile{ (uint32_t)video_stream.width, (uint32_t)video_stream.height, (uint32_t)video_stream.fps, 0 });
        profile->set_dims(video_stream.width, video_stream.height);
        profile->set_format(video_stream.fmt);
        profile->set_framerate(video_stream.fps);
        profile->set_stream_index(video_stream.index);
        profile->set_stream_type(video_stream.type);
        profile->set_unique_id(video_stream.uid);
        profile->set_intrinsics([=]() {return video_stream.intrinsics; });
        _profiles.push_back(profile);

        return profile;
    }
    std::shared_ptr<stream_profile_interface> software_sensor::add_motion_stream(rs2_motion_stream motion_stream)
    {
        auto exist = (std::find_if(_profiles.begin(), _profiles.end(), [&](std::shared_ptr<stream_profile_interface> profile)
        {
            return profile->get_unique_id() == motion_stream.uid;
        }) != _profiles.end());

        if (exist)
        {
            LOG_WARNING("Motion stream unique ID already exist!");
            throw rs2::error("Stream unique ID already exist!");
        }

        auto profile = std::make_shared<motion_stream_profile>(
            platform::stream_profile{ 0, 0, (uint32_t)motion_stream.fps, 0 });
        profile->set_format(motion_stream.fmt);
        profile->set_framerate(motion_stream.fps);
        profile->set_stream_index(motion_stream.index);
        profile->set_stream_type(motion_stream.type);
        profile->set_unique_id(motion_stream.uid);
        profile->set_intrinsics([=]() {return motion_stream.intrinsics; });
        _profiles.push_back(profile);

        return profile;
    }
int set_data_source_l(State **ps, const char* path) {
    printf("set_data_source\n");
    int audio_index = -1;
    int video_index = -1;
    int i;
    
    State *state = *ps;
    
    printf("Path: %s\n", path);
    
    AVDictionary *options = NULL;
    av_dict_set(&options, "icy", "1", 0);
    av_dict_set(&options, "user-agent", "FFmpegMediaMetadataRetriever", 0);
    
    if (state->headers) {
        av_dict_set(&options, "headers", state->headers, 0);
    }
    
    if (state->offset > 0) {
        state->pFormatCtx = avformat_alloc_context();
        state->pFormatCtx->skip_initial_bytes = state->offset;
    }
    
    if (avformat_open_input(&state->pFormatCtx, path, NULL, &options) != 0) {
        printf("Metadata could not be retrieved\n");
        *ps = NULL;
        return FAILURE;
    }
    
    if (avformat_find_stream_info(state->pFormatCtx, NULL) < 0) {
        printf("Metadata could not be retrieved\n");
        avformat_close_input(&state->pFormatCtx);
        *ps = NULL;
        return FAILURE;
    }
    
    set_duration(state->pFormatCtx);
    
    set_shoutcast_metadata(state->pFormatCtx);
    
    //av_dump_format(state->pFormatCtx, 0, path, 0);
    
    // Find the first audio and video stream
    for (i = 0; i < state->pFormatCtx->nb_streams; i++) {
        if (state->pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_index < 0) {
            video_index = i;
        }
        
        if (state->pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_index < 0) {
            audio_index = i;
        }
        
        set_codec(state->pFormatCtx, i);
    }
    
    if (audio_index >= 0) {
        stream_component_open(state, audio_index);
    }
    
    if (video_index >= 0) {
        stream_component_open(state, video_index);
    }
    
    /*if(state->video_stream < 0 || state->audio_stream < 0) {
	    avformat_close_input(&state->pFormatCtx);
     *ps = NULL;
     return FAILURE;
     }*/
    
    set_rotation(state->pFormatCtx, state->audio_st, state->video_st);
    set_framerate(state->pFormatCtx, state->audio_st, state->video_st);
    set_filesize(state->pFormatCtx);
    set_chapter_count(state->pFormatCtx);
    
    /*printf("Found metadata\n");
     AVDictionaryEntry *tag = NULL;
     while ((tag = av_dict_get(state->pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
    	printf("Key %s: \n", tag->key);
    	printf("Value %s: \n", tag->value);
     }*/
    
    *ps = state;
    return SUCCESS;
}
Esempio n. 5
0
void GameManager::init()
{
#ifdef CHOWDREN_USER_PROFILER
    user_log.open("log.txt", "w");
#endif

#ifdef CHOWDREN_USE_PROFILER
    PROFILE_SET_DAMPING(0.0);
#endif
    frame = &static_frames;

#ifdef CHOWDREN_IS_DEMO
    idle_timer_started = false;
    global_time = show_build_timer = reset_timer = manual_reset_timer = 0.0;
#endif

#ifdef CHOWDREN_USE_JOYTOKEY
    simulate_count = 0;
    axis_moved = false;
    last_axis = -1;
    deadzone = 0.4f;
    pad_selected = false;
    pad_disconnected = false;
    for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++)
        key_mappings[i] = -1;
    for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) {
        axis_pos_mappings[i] = -1;
        axis_neg_mappings[i] = -1;
        axis_values[i] = 0;
    }
#endif
    platform_init();
    media.init();
    set_window(false);

    // application setup
    preload_images();
    reset_globals();
    setup_keys(this);

    // setup random generator from start
    cross_srand((unsigned int)platform_get_global_time());

    fps_limit.start();
    set_framerate(FRAMERATE);

    int start_frame = 0;
#if defined(CHOWDREN_IS_AVGN)
    start_frame = 0;
#elif defined(CHOWDREN_IS_HFA)
    start_frame = 0;
#elif defined(CHOWDREN_IS_FP)
    player_died = false;
    lives = 3;
    start_frame = 0;
    // values->set(1, 2);
    // values->set(12, 2);
#elif defined(CHOWDREN_IS_NAH)
    platform_set_scale_type(2);
    // start_frame = 3;
    // set_local("fre");
    // values->set(13, 25);
    // strings->set(23, "OBJETS");
    // strings->set(9, "-fre");
#else
    start_frame = 0;
#endif

#ifdef NDEBUG
    set_frame(0);
#else
    set_frame(start_frame);
#endif
}
Esempio n. 6
0
static int v4l2_case_vary_frame_rate(void* user_ptr, int test_num)
{
	v4l2_data* data = (v4l2_data*)user_ptr;
	int ret = 0;

	float initial_fps = 0.0;
	float initial_cfps = 0.0; /* calculated fps for original value */

	float target_fps = data->device->frame_rate;
	float target_cfps = 0.0; /* calculated fps for new value */

	boolean reset = FALSE;

	if (!open_device(data->device))
	{
		BLTS_DEBUG("Can't open device %s\n", data->device->dev_name);
		return -1;
	}

	/* find out initial frame rate */
	if(get_framerate_fps(data->device, &initial_fps) != 0)
	{
		BLTS_DEBUG("Can't get initial fps\n");
		goto err;
	}

	/* test frame rate with initial values */
	if(test_frame_rate(data->device, &initial_fps, &initial_cfps) != 0)
	{
		BLTS_DEBUG("Can't test initial frame rate\n");
		goto err;
	}

	/* try to set new frame rate values */
	if(set_framerate_fps(data->device, &target_fps) != 0)
	{
		BLTS_DEBUG("Can't set new frame rate\n");
		reset = TRUE;
		goto err;
	}

	/* test frame rate with new values */
	if(test_frame_rate(data->device, &target_fps, &target_cfps) != 0)
	{
		BLTS_DEBUG("Can't test new frame rate\n");
		reset = TRUE;
		goto err;
	}

	/* sanity check for test times */
	if(initial_fps < target_fps)
		ret = ((initial_cfps < target_cfps))?0:-1;
	else if (initial_fps > target_fps)
		ret = ((initial_cfps > target_cfps))?0:-1;
	else
		ret = 0;

	/* reset initial frame rate */
	set_framerate(data->device, 0, 0, &initial_fps);
	close_device(data->device);

	return ret;
err:
	if(reset)
		set_framerate(data->device, 0, 0, &initial_fps);
	close_device(data->device);
	return -1;
}
int decode_thread(void *arg) {

  VideoState *is = (VideoState *)arg;
  AVPacket pkt1, *packet = &pkt1;

  AVDictionary *io_dict = NULL;
  AVIOInterruptCB callback;

  int video_index = -1;
  int audio_index = -1;
  int i;

  int ret;
  int eof = 0;

  is->videoStream=-1;
  is->audioStream=-1;

  AVDictionary *options = NULL;
  av_dict_set(&options, "icy", "1", 0);
  av_dict_set(&options, "user-agent", "FFmpegMediaPlayer", 0);
    
  if (is->headers) {
    av_dict_set(&options, "headers", is->headers, 0);
  }

  if (is->offset > 0) {
    is->pFormatCtx = avformat_alloc_context();
    is->pFormatCtx->skip_initial_bytes = is->offset;
    //is->pFormatCtx->iformat = av_find_input_format("mp3");
  }

  // will interrupt blocking functions if we quit!
  callback.callback = decode_interrupt_cb;
  callback.opaque = is;
  if (avio_open2(&is->io_context, is->filename, 0, &callback, &io_dict))
  {
    fprintf(stderr, "Unable to open I/O for %s\n", is->filename);
    return -1;
  }

  // Open video file
  if(avformat_open_input(&is->pFormatCtx, is->filename, NULL, &options)!=0)
    return -1; // Couldn't open file

  // Retrieve stream information
  if(avformat_find_stream_info(is->pFormatCtx, NULL)<0)
    return -1; // Couldn't find stream information

  // Dump information about file onto standard error
  av_dump_format(is->pFormatCtx, 0, is->filename, 0);

  // Find the first video stream
  for(i=0; i<is->pFormatCtx->nb_streams; i++) {
    if(is->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO &&
       video_index < 0) {
      video_index=i;
    }
    if(is->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
       audio_index < 0) {
      audio_index=i;
    }
      
    set_codec(is->pFormatCtx, i);
  }
  if(audio_index >= 0) {
    stream_component_open(is, audio_index);
  }
  if(video_index >= 0) {
    stream_component_open(is, video_index);
  }

  if(is->videoStream < 0 && is->audioStream < 0) {
  //if(is->videoStream < 0 || is->audioStream < 0) {
    fprintf(stderr, "%s: could not open codecs\n", is->filename);
    notify(is, MEDIA_ERROR, 0, 0);
    return 0;
  }

  set_rotation(is->pFormatCtx, is->audio_st, is->video_st);
  set_framerate(is->pFormatCtx, is->audio_st, is->video_st);
  set_filesize(is->pFormatCtx);
  set_chapter_count(is->pFormatCtx);

  // main decode loop

  for(;;) {
    if(is->quit) {
      break;
    }

    /*if (is->paused != is->last_paused) {
        is->last_paused = is->paused;
        if (is->paused)
            is->read_pause_return = av_read_pause(is->pFormatCtx);
        else
            av_read_play(is->pFormatCtx);
    }*/

    // seek stuff goes here
    if(is->seek_req) {
		int64_t seek_target = is->seek_pos;
		int64_t seek_min    = is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN;
		int64_t seek_max    = is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX;

		int ret = avformat_seek_file(is->pFormatCtx, -1, seek_min, seek_target, seek_max, is->seek_flags);
      if(ret < 0) {
	fprintf(stderr, "%s: error while seeking\n", is->pFormatCtx->filename);
      } else {
	if(is->audioStream >= 0) {
	  packet_queue_flush(&is->audioq);
	  packet_queue_put(is, &is->audioq, &is->flush_pkt);
	}
	if(is->videoStream >= 0) {
	  packet_queue_flush(&is->videoq);
	  packet_queue_put(is, &is->videoq, &is->flush_pkt);
	}
	notify(is, MEDIA_SEEK_COMPLETE, 0, 0);

      }
      is->seek_req = 0;
      eof = 0;
    }

    if (is->audioq.size >= MAX_AUDIOQ_SIZE && !is->prepared) {
        queueAudioSamples(&is->audio_player, is);

		notify(is, MEDIA_PREPARED, 0, 0);
    	is->prepared = 1;
    }

    if(is->audioq.size > MAX_AUDIOQ_SIZE ||
       is->videoq.size > MAX_VIDEOQ_SIZE) {
      SDL_Delay(10);
      continue;
    }
    if((ret = av_read_frame(is->pFormatCtx, packet)) < 0) {
      if (ret == AVERROR_EOF || !is->pFormatCtx->pb->eof_reached) {
          eof = 1;
    	  break;
      }

      if(is->pFormatCtx->pb->error == 0) {
	SDL_Delay(100); /* no error; wait for user input */
	continue;
      } else {
	break;
      }
    }
    // Is this a packet from the video stream?
    if(packet->stream_index == is->videoStream) {
      packet_queue_put(is, &is->videoq, packet);
    } else if(packet->stream_index == is->audioStream) {
      packet_queue_put(is, &is->audioq, packet);
    } else {
      av_free_packet(packet);
    }

	if (eof) {
		break;
	}
  }

  if (eof) {
      notify(is, MEDIA_PLAYBACK_COMPLETE, 0, 0);
  }
  return 0;
}
Esempio n. 8
0
static void init_device(){
	struct v4l2_capability cap;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_format fmt;
	unsigned int min;
	
	if(-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)){
		if(EINVAL == errno){
			fprintf(stderr, "%s is no V4L2 device\n", dev_name);
			exit(EXIT_FAILURE);
		}else{
			errno_exit("VIDIOC_QUERYCAP");
		}
	}
	
	printf("Card: %s\n", cap.card);
	
	if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)){
		fprintf(stderr, "%s is no video capture device\n", dev_name);
		exit(EXIT_FAILURE);
	}
	
	/*if(!(cap.capabilities & V4L2_CAP_READWRITE)){
	 fprintf(stderr, "%s does not support read i/o\n", dev_name);
	 exit(EXIT_FAILURE);
	 }*/
	
	if(!(cap.capabilities & V4L2_CAP_STREAMING)){
		fprintf(stderr, "%s does not support streaming i/o\n", dev_name);
		exit(EXIT_FAILURE);
	}
	
	/* Select video input, video standard and tune here. */
	CLEAR(cropcap);
	
	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	
	if(0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)){
		crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		crop.c = cropcap.defrect; /* reset to default */
		
		if(-1 == xioctl(fd, VIDIOC_S_CROP, &crop)){
			switch(errno){
				case EINVAL:
					/* Cropping not supported. */
					break;
				default:
					/* Errors ignored. */
					break;
			}
		}
	}else{
		/* Errors ignored. */
	}
	
	CLEAR(fmt);
	
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width = 2592;
	fmt.fmt.pix.height = 1944;
	fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_Y16 ;
	fmt.fmt.pix.field = V4L2_FIELD_NONE;
	
	if(-1 == xioctl(fd, VIDIOC_S_FMT, &fmt)){
		errno_exit("VIDIOC_S_FMT");
	}
	
	/* Note VIDIOC_S_FMT may change width and height. */
	
	/* Buggy driver paranoia. */
	min = fmt.fmt.pix.width;
	if(fmt.fmt.pix.bytesperline < min){
		fmt.fmt.pix.bytesperline = min;
	}
	min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
	if(fmt.fmt.pix.sizeimage < min){
		fmt.fmt.pix.sizeimage = min;
	}
	
	width = fmt.fmt.pix.width;
	height = fmt.fmt.pix.height;
	bytesperline = fmt.fmt.pix.bytesperline;
	
	//init_read(fmt.fmt.pix.sizeimage);
	init_mmap();
	
	// Set frame rate to 12 FPS
	set_framerate(1, 12);
}