Exemplo n.º 1
0
void netcdf::set_unlimited_dim(dim_vector::iterator dim_it, int32_t default_dim_length) {

    for (auto it = dims.begin(); it != dims.end(); it++) {

        if (it->is_record())
            it->dim_length = default_dim_length;

        if (it == dim_it)
            it->dim_length = 0;
    }
}
Exemplo n.º 2
0
var_vector::iterator netcdf::add_var(var const & theVar) {

    // Record variables go at the end of the vector.
    var_vector::iterator where_it = vars.end();

    // Non-record variables go at the end of the non-record variables.
    if (!theVar.is_record(dims)) {
        for (auto it = vars.begin(); it != vars.end(); it++)
            if (!it->is_record(dims)) where_it = it;
    }

    return vars.insert(where_it, theVar);
}
Exemplo n.º 3
0
static void rec_state_reset(channel_t *channel)
{
	rec_driver_t *driver = (rec_driver_t *)channel->rec_driver;

	if (is_record(channel->rec_state)) {
		driver->rmd_di_rec_stop_record(channel->rec_handle);
		set_unrecord(channel->rec_state);
	}

	if (is_logined(channel->rec_state)) {
		single_logout(sl, logout_storage, channel->storage_ip, 
				channel->storage_port, (void *)channel);
		set_unlogined(channel->rec_state);
	}
}
Exemplo n.º 4
0
static inline int record_callback(char *buff, int bytes, void *param)
{
	channel_t *channel = (channel_t *)param;
	rec_driver_t *driver = (rec_driver_t *)channel->rec_driver;
	int ret;

	if (!is_record(channel->rec_state) || channel->rec_error == 1)
		return -1;

	channel->bgn_time = channel->end_time;
	channel->end_time = time(NULL);
	channel->last_data_time = get_runtime();
	if (channel->end_time < channel->bgn_time)
		channel->end_time = channel->bgn_time;

	if (channel->is_rtp_packet) {
		char out_buff[OUT_BUFF_SIZE];
		int out_bytes;

		if (channel->payload_type == RTP_PT_H264) {
			out_bytes = rtp_get_h264_data(buff, bytes, out_buff, 
					OUT_BUFF_SIZE);
			if (out_bytes <= 0)
				return -1;
		} else if (channel->payload_type == RTP_PT_MJPEG) {
			return -1;	/* TODO */
		} else {
			return -1;	/* TODO */
		}

		ret = driver->rmd_di_rec_record(channel->rec_handle, 
				out_buff, out_bytes, channel->bgn_time, 
				channel->end_time);
	} else {
		ret = driver->rmd_di_rec_record(channel->rec_handle, buff, 
				bytes, channel->bgn_time, channel->end_time);
	}

	if (ret != 0) {
		syslog(LOG_DEBUG, "record [%s] error: %lu", channel->rec_name, 
				driver->rmd_di_rec_geterror());
		channel->rec_error = 1;
		return -1;
	}

	return 0;
}
Exemplo n.º 5
0
static int task_run_callback(void *data, void *param)
{
	channel_t *channel = (channel_t *)data;
	rec_driver_t *driver = (rec_driver_t *)channel->rec_driver;
	start_record_info_t info;
	int dev_type = ((driver_t *)channel->pdriver)->type;

	/*
	syslog(LOG_DEBUG, "[REC TASK] %s %d %d %d", channel->rec_name, 
			is_applied(channel->rec_state),
			is_logined(channel->rec_state),
			is_record(channel->rec_state));
			*/

	if (!is_applied(channel->rec_state)) {
		if (rmd_sessmgr_play_by_rec(channel) != 0)
			return -1;
		set_applied(channel->rec_state);
	}

	if (is_logined(channel->rec_state)) {
		if (channel->rec_error == 1) {
			syslog(LOG_DEBUG, "interrupt cause record error [%s]",
					channel->rec_name);
			rec_state_reset(channel);
#ifdef RMD_HAS_UDS
			notify_rec_stat(channel->rec_name, REC_FAILED);
#endif
		} else if ((get_runtime() - channel->last_data_time) > 
				INTERRUPT_TIMEOUT) {
			syslog(LOG_DEBUG, "interrupt cause camera error [%s]", 
					channel->rec_name);
			rec_state_reset(channel);
#ifdef RMD_HAS_UDS
			notify_rec_stat(channel->rec_name, REC_FAILED);
#endif
		}
	}

	if (channel->camera_state == 0)
		return -1;	/* no action, until camera become OK */

	if (!is_logined(channel->rec_state)) {
		channel->rec_loginid = single_login(sl, login_storage, 
				channel->storage_ip, channel->storage_port,
				channel->storage_user, channel->storage_pwd,
				(void *)channel);
		if (channel->rec_loginid == -1)
			return -1;
		set_logined(channel->rec_state);
	}

	if (!is_record(channel->rec_state)) {
		if (channel->hdr_buff && channel->hdr_length == 0)
			return -1;  /* the media header not coming yet */

		info.login_id = channel->rec_loginid;
		snprintf(info.record_name, sizeof(info.record_name), 
				channel->rec_name);
		snprintf(info.record_alias, sizeof(info.record_alias), 
				channel->rec_name);
		info.record_type = record_type;
		info.disk_no = channel->storage_disk;
		if (channel->hdr_length > 0) {
			info.hdr_len = channel->hdr_length;
			memcpy(info.hdr_buff, channel->hdr_buff, 
					channel->hdr_length);
		} else {
			/* if the device have no media header, put device type
			 * at the begin (4 bytes). */
			info.hdr_len = 4;
			sprintf(info.hdr_buff, "%04d", dev_type);
		}
		snprintf(info.desc, sizeof(info.desc), channel->rec_name);

		channel->rec_handle = driver->rmd_di_rec_start_record(&info);
		if (channel->rec_handle == -1) {
			syslog(LOG_DEBUG, "start_record [%s] error: %lu", 
					channel->rec_name, 
					driver->rmd_di_rec_geterror());
			rec_state_reset(channel);
			return -1;
		}
		syslog(LOG_DEBUG, "[REC START] %s", channel->rec_name);
		set_record(channel->rec_state);
		channel->end_time = time(NULL);
		channel->rec_error = 0;
		channel->last_data_time = get_runtime();

#ifdef RMD_HAS_UDS
		notify_rec_stat(channel->rec_name, REC_SUCC);
#endif
	}

	return 0;
}