Beispiel #1
0
void create_pipe(int fdi, int fdo) {
	int p[2];
	if (is_opened(fdi) || is_opened(fdo))
		die();
	if (dup2(2, fdi) < 0 || dup2(2, fdo) < 0)
		die();
	if (pipe(p) < 0)
		die();
	if (dup2(p[0], fdi) < 0 || dup2(p[1], fdo) < 0)
		die();
	if (close(p[0]) < 0 || close(p[1]) < 0)
		die();
}
Beispiel #2
0
XCamReturn
V4l2Device::open ()
{
    struct v4l2_streamparm param;

    if (is_opened()) {
        XCAM_LOG_DEBUG ("device(%s) was already opened", XCAM_STR(_name));
        return XCAM_RETURN_NO_ERROR;
    }

    if (!_name) {
        XCAM_LOG_DEBUG ("v4l2 device open failed, there's no device name");
        return XCAM_RETURN_ERROR_PARAM;
    }
    _fd = ::open (_name, O_RDWR);
    if (_fd == -1) {
        XCAM_LOG_DEBUG ("open device(%s) failed", _name);
        return XCAM_RETURN_ERROR_IOCTL;
    }

    // set sensor id
    if (io_control (VIDIOC_S_INPUT, &_sensor_id) < 0) {
        XCAM_LOG_WARNING ("set sensor id(%d) failed but continue", _sensor_id);
    }

    // set capture mode
    xcam_mem_clear (param);
    param.type = _capture_buf_type;
    param.parm.capture.capturemode = _capture_mode;
    if (io_control (VIDIOC_S_PARM, &param) < 0) {
        XCAM_LOG_WARNING ("set capture mode(0x%08x) failed but continue", _capture_mode);
    }

    return XCAM_RETURN_NO_ERROR;
}
Beispiel #3
0
      bool file_operation::pwrite(void *buffer, size_t size, off_t offset)
      {
        if(!is_opened())
          return false;

        if(offset < 0)
          offset = get_position();

        log_debug("sizeof(off_t): %lu, write[%s]: size [%lu] at offset [%lu]",
                  sizeof(off_t), file_name, size, offset);

        if(is_mapped && (offset + size) > map_file->get_size()) {
          map_file->remap();
        }

        if(is_mapped && (offset + size) <= map_file->get_size()) {
          // use mmap first
          log_debug("pwrite data use mmap at offset [%lu] with size [%lu]",
                    offset, size);
          memcpy((char *) map_file->get_data() + offset, buffer, size);
          return true;
        }

        return::pwrite(fd, buffer, size, offset) == (ssize_t) size;
      }
Beispiel #4
0
static inline bool is_manager(struct i2s_dai *i2s)
{
	if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
		return true;
	else
		return false;
}
vogl_trace_file_reader::trace_file_reader_status_t vogl_trace_file_reader::read_frame_packets(uint32_t frame_index, uint32_t num_frames, vogl_trace_packet_array &packets, uint32_t &actual_frames_read)
{
    VOGL_FUNC_TRACER

    actual_frames_read = 0;

    if (!is_opened())
    {
        vogl_error_printf("%s: Trace file is not open\n", VOGL_FUNCTION_INFO_CSTR);

        VOGL_ASSERT_ALWAYS;

        return cFailed;
    }

    if (!num_frames)
    {
        actual_frames_read = 0;
        return c*K;
    }

    vogl_scoped_location_saver saved_loc(*this);

    if (!seek_to_frame(frame_index))
    {
        vogl_error_printf("%s: Failed seeking to frame %u\n", VOGL_FUNCTION_INFO_CSTR, frame_index);
        return cFailed;
    }

    uint32_t total_frames_read = 0;

    packets.reserve(packets.size() + num_frames * 1000);

    trace_file_reader_status_t status = c*K;
    for (;;)
    {
        status = read_next_packet();
        if (status == cFailed)
        {
            vogl_error_printf("%s: Failed reading from trace file\n", VOGL_FUNCTION_INFO_CSTR);
            break;
        }

        packets.push_back(get_packet_buf());

        if (is_eof_packet())
            break;

        if (is_swap_buffers_packet())
        {
            if (++total_frames_read == num_frames)
                break;
        }
    }

    actual_frames_read = total_frames_read;

    return c*K;
}
Beispiel #6
0
 int32_t FileLogDevice::close(void* param) {
     (void)param;
     if (true == is_opened()) {
         fclose(_fp);
         _fp = NULL;
     }
     return 0;
 }
Beispiel #7
0
XCamReturn V4l2SubDevice::start ()
{
    if (!is_opened())
        return XCAM_RETURN_ERROR_PARAM;

    _active = true;
    return XCAM_RETURN_NO_ERROR;
}
Beispiel #8
0
XCamReturn
V4l2Device::close ()
{
    if (!is_opened())
        return XCAM_RETURN_NO_ERROR;
    ::close (_fd);
    _fd = -1;
    return XCAM_RETURN_NO_ERROR;
}
Beispiel #9
0
bool
V4l2Device::set_sensor_id (int id)
{
    if (is_opened()) {
        XCAM_LOG_WARNING ("can't set sensor id since device opened");
        return false;
    }
    _sensor_id = id;
    return true;
}
Beispiel #10
0
bool
V4l2Device::set_capture_mode (uint32_t capture_mode)
{
    if (is_opened()) {
        XCAM_LOG_WARNING ("can't set sensor id since device opened");
        return false;
    }
    _capture_mode = capture_mode;
    return true;
}
Beispiel #11
0
int db_mysql::affect_count() const
{
	if (!is_opened())
	{
		logger_error("mysql not opened yet");
		return -1;
	}

	return (int) __mysql_affected_rows(conn_);
}
Beispiel #12
0
    int32_t FileLogDevice::write(const struct log_message_t& log_message) {
        if (get_loglevel() > log_message.loglevel) {
            return 0;
        }

        char buffer[1024] = {0};
        int32_t split_policy;
        int32_t nformated;

        nformated = format_log_message(buffer, 1022, log_message);
        split_policy = get_split_policy();

        {
            Guard<Mutex> guard(&_mutex);

            if (!is_opened()) {
                return -1;
            }

            if (BGCC_LOG_SPLIT_POLICY_BY_TIME == split_policy) {
                if (exec_time_split_policy() != 0) {
                    return -1;
                }
            } else {
                if (exec_size_split_policy(nformated) != 0) {
                    return -1;
                }
            }

            if (!is_opened()) {
                return -1;
            }

            fwrite(buffer, nformated, 1, _fp);
            _file_size += nformated;

            fflush(_fp);
        }

        return 0;
    }
Beispiel #13
0
      bool file_operation::sync(void)
      {
        if(!is_opened())
          return false;

        if(is_mapped) {
          return map_file->sync_file();
        }
        else {
          return fsync(fd) == 0;
        }
      }
Beispiel #14
0
void FastaReader::readNext() {
	if(!is_opened()) {
		//throw GenericException("File is not opened");
	}

	if(is_eof()) {
		//throw GenericException("End of file reached");
	}

	if (kseq_read(seq) < 0) {
		is_eof_ = true;
	}
}
Beispiel #15
0
    int32_t FileLogDevice::get_file_stat(struct stat& state) const {
        int32_t fd;

        if (!is_opened()) {
            return -1;
        }

        fd = fileno(_fp);
        if (-1 == fstat(fd, &state)) {
            return errno;
        }
        return 0;
    }
Beispiel #16
0
bool
V4l2Device::set_device_name (const char *name)
{
    XCAM_ASSERT (name);

    if (is_opened()) {
        XCAM_LOG_WARNING ("can't set device name since device opened");
        return false;
    }
    if (_name)
        xcam_free (_name);
    _name = strndup (name, XCAM_MAX_STR_SIZE);
    return true;
}
Beispiel #17
0
XCamReturn
V4l2SubDevice::dequeue_event (struct v4l2_event &event)
{
    int ret = 0;
    XCAM_ASSERT (is_opened());

    ret = this->io_control (VIDIOC_DQEVENT, &event);
    if (ret < 0) {
        XCAM_LOG_DEBUG ("subdev(%s) dequeue event failed", XCAM_STR(_name));
        return XCAM_RETURN_ERROR_IOCTL;
    }

    return XCAM_RETURN_NO_ERROR;
}
Beispiel #18
0
      bool file_operation::close()
      {
        if(!is_opened()) {
          log_info("file [%s] not opened, need not close", file_name);
          return true;
        }

        if(::close(fd) == -1) {
          log_error("close file [%s] failed: %s", file_name, strerror(errno));
          return false;
        }

        return true;
      }
Beispiel #19
0
    int32_t FileLogDevice::open(void* param) {
        char buffer[BUFSIZ];

        if (false == is_opened()) {
            if (NULL != param) {
                strncat(_file_path, (char*)param, MAX_FILE_PATH_LEN);
            }

            snprintf(buffer, BUFSIZ, "%s", _file_path);
            char* p = strrchr(buffer, '/');
            if (NULL != p) {
                *p = '\0';
                if (0 != FileUtil::create_directories(buffer)) {
                    return -1;
                }
            }

            _fp = fopen(_file_path, "a");
            if (NULL == _fp) {
                return errno;
            }
            struct stat state;
            get_file_stat(state);
            _file_size = state.st_size;

			TimeUtil::gettimeofday(&_create_time, NULL);
        }

		snprintf(buffer, BUFSIZ, "%s", _file_path);
		struct log_message_t log_message = {
			BGCC_LOGLEVEL_NOTICE, 
			"BGCC Version:"VERSION, "=ver=", 
			__FILE__, 
#ifndef _WIN32			
			STR(__LINE__), 
#else
			itoa(__LINE__, buffer, 10),
#endif
            __FUNCTION__,
			_create_time, bgcc::ThreadUtil::self_id()
		};

		write(log_message);

        return 0;
    }
Beispiel #20
0
      ssize_t file_operation::read(void *buffer, size_t size, off_t offset)
      {
        if(!is_opened())
          return false;
        if(is_mapped && (offset + size) > map_file->get_size())
          map_file->remap();

        if(is_mapped && (offset + size) <= map_file->get_size()) {
          // use mmap first
          log_debug("read data from mmap[%s], offset [%lu], size [%lu]",
                    file_name, offset, size);
          memcpy(buffer, (char *) map_file->get_data() + offset, size);
          return size;
        }
        log_debug("read from [%s], offset: [%lu], size: [%lu]", file_name,
                  offset, size);
        return::pread(fd, buffer, size, offset);
      }
Beispiel #21
0
      bool file_operation::mmap(int map_size)
      {
        if(map_size == 0)
          return true;

        if(!is_opened()) {
          log_warn("file not opened");
          return false;
        }

        if(!is_mapped) {
          // do map if not mapped yet
          map_file = new mmap_file(map_size, fd);
          is_mapped = map_file->map_file(true);
        }

        return is_mapped;
      }
Beispiel #22
0
XCamReturn
V4l2SubDevice::unsubscribe_event (int event)
{
    struct v4l2_event_subscription sub;
    int ret = 0;

    XCAM_ASSERT (is_opened());

    xcam_mem_clear (sub);
    sub.type = event;

    ret = this->io_control (VIDIOC_UNSUBSCRIBE_EVENT, &sub);
    if (ret < 0) {
        XCAM_LOG_DEBUG ("subdev(%s) unsubscribe event(%d) failed", XCAM_STR(_name), event);
        return XCAM_RETURN_ERROR_IOCTL;
    }
    return XCAM_RETURN_NO_ERROR;
}
t_tag		*check_all_lines(char **conf)
{
  int		i;
  t_tag		*list;

  i = 1;
  list = NULL;
  while (i < (my_strslen(conf) - 1))
    {
      if (conf[i][0] == '<' && conf[i][1] != '/')
	is_closed(conf[i], conf, i);
      else if (conf[i][0] == '<' && conf[i][1] == '/')
	is_opened(conf[i], conf, i);
      else
	list = is_value_good(conf[i], conf, i, list);
      i = i + 1;
    }
  return (list);
}
Beispiel #24
0
      bool file_operation::lock(off_t offset, size_t size, bool write)
      {
        if(!is_opened())
          return false;

        bool rc = false;
        struct flock lock;
        memset(&lock, 0, sizeof(lock));

        lock.l_start = offset;
        lock.l_len = size;
        lock.l_pid = 0;
        lock.l_whence = SEEK_SET;
        lock.l_type = write ? F_WRLCK : F_RDLCK;

        rc = (fcntl(fd, F_SETLK, &lock) != -1);

        return rc;
      }
Beispiel #25
0
      bool file_operation::unlock(off_t offset, size_t length)
      {
        if(!is_opened())
          return false;

        bool rc = false;
        struct flock lock;
        memset(&lock, 0, sizeof(lock));

        lock.l_start = offset;
        lock.l_len = length;
        lock.l_pid = 0;
        lock.l_whence = SEEK_SET;
        lock.l_type = F_UNLCK;

        rc = (fcntl(fd, F_SETLK, &lock) != -1);

        return rc;
      }
Beispiel #26
0
      bool file_operation::write(void *buffer, size_t size)
      {
        if(!is_opened())
          return false;

        log_debug("write data into with size of [%lu] at offset [%lu]", size,
                  get_position());

        off_t offset = get_position();
        if(is_mapped && (offset + size) > map_file->get_size()) {
          map_file->remap();
        }

        if(is_mapped && (offset + size) <= map_file->get_size()) {
          log_debug("write data use mmap at offset [%lu] with size [%lu]",
                    offset, size);
          memcpy((char *) map_file->get_data() + offset, buffer, size);
          return true;
        }

        return::write(fd, buffer, size) == (ssize_t) size;
      }
Beispiel #27
0
XCamReturn
V4l2Device::get_format (struct v4l2_format &format)
{
    if (is_activated ()) {
        format = _format;
        return XCAM_RETURN_NO_ERROR;
    }

    if (!is_opened ())
        return XCAM_RETURN_ERROR_IOCTL;

    xcam_mem_clear (format);
    format.type = _capture_buf_type;

    if (this->io_control (VIDIOC_G_FMT, &format) < 0) {
        // FIXME: also log the device name?
        XCAM_LOG_ERROR("Fail to get format via ioctl VIDVIO_G_FMT.");
        return XCAM_RETURN_ERROR_IOCTL;
    }

    return XCAM_RETURN_NO_ERROR;
}
void Gpackage::close()
{
    if (is_opened())
        CloseHandle(pack_file_);
    entries_.clear();
}
Beispiel #29
0
bool
DPXOutput::open (const std::string &name, const ImageSpec &userspec,
                 OpenMode mode)
{
    if (mode == Create) {
        m_subimage = 0;
        if (m_subimage_specs.size() < 1) {
            m_subimage_specs.resize (1);
            m_subimage_specs[0] = userspec;
            m_subimages_to_write = 1;
        }
    } else if (mode == AppendSubimage) {
        if (m_write_pending)
            write_buffer ();
        ++m_subimage;
        if (m_subimage >= m_subimages_to_write) {
            error ("Exceeded the pre-declared number of subimages (%d)",
                   m_subimages_to_write);
            return false;
        }
        return prep_subimage (m_subimage, true);
        // Nothing else to do, the header taken care of when we opened with
        // Create.
    } else if (mode == AppendMIPLevel) {
        error ("DPX does not support MIP-maps");
        return false;
    }

    // From here out, all the heavy lifting is done for Create
    ASSERT (mode == Create);

    if (is_opened())
        close ();  // Close any already-opened file
    m_stream = new OutStream();
    if (! m_stream->Open(name.c_str ())) {
        error ("Could not open file \"%s\"", name.c_str ());
        return false;
    }
    m_dpx.SetOutStream (m_stream);
    m_dpx.Start ();
    m_subimage = 0;

    ImageSpec &m_spec (m_subimage_specs[m_subimage]); // alias the spec

    // Check for things this format doesn't support
    if (m_spec.width < 1 || m_spec.height < 1) {
        error ("Image resolution must be at least 1x1, you asked for %d x %d",
               m_spec.width, m_spec.height);
        return false;
    }

    if (m_spec.depth < 1)
        m_spec.depth = 1;
    else if (m_spec.depth > 1) {
        error ("DPX does not support volume images (depth > 1)");
        return false;
    }

    // some metadata
    std::string software = m_spec.get_string_attribute ("Software", "");
    std::string project = m_spec.get_string_attribute ("DocumentName", "");
    std::string copyright = m_spec.get_string_attribute ("Copyright", "");
    std::string datestr = m_spec.get_string_attribute ("DateTime", "");
    if (datestr.size () >= 19) {
        // libdpx's date/time format is pretty close to OIIO's (libdpx uses
        // %Y:%m:%d:%H:%M:%S%Z)
        // NOTE: the following code relies on the DateTime attribute being properly
        // formatted!
        // assume UTC for simplicity's sake, fix it if someone complains
        datestr[10] = ':';
        datestr.replace (19, -1, "Z");
    }

    // check if the client wants endianness reverse to native
    // assume big endian per Jeremy's request, unless little endian is
    // explicitly specified
    std::string endian = m_spec.get_string_attribute ("oiio:Endian", littleendian() ? "little" : "big");
    m_wantSwap = (littleendian() != Strutil::iequals (endian, "little"));

    m_dpx.SetFileInfo (name.c_str (),                               // filename
        datestr.c_str (),                                           // cr. date
        software.empty () ? OIIO_INTRO_STRING : software.c_str (),  // creator
        project.empty () ? NULL : project.c_str (),                 // project
        copyright.empty () ? NULL : copyright.c_str (),             // copyright
        m_spec.get_int_attribute ("dpx:EncryptKey", ~0),            // encryption key
        m_wantSwap);

    // image info
    m_dpx.SetImageInfo (m_spec.width, m_spec.height);

    for (int s = 0;  s < m_subimages_to_write;  ++s) {
        prep_subimage (s, false);
        m_dpx.header.SetBitDepth (s, m_bitdepth);
        ImageSpec &spec (m_subimage_specs[s]);
        bool datasign = (spec.format == TypeDesc::INT8 ||
                         spec.format == TypeDesc::INT16);
        m_dpx.SetElement (s, m_desc, m_bitdepth, m_transfer, m_cmetr,
                          m_packing, dpx::kNone, datasign,
                          spec.get_int_attribute ("dpx:LowData", 0xFFFFFFFF),
                          spec.get_float_attribute ("dpx:LowQuantity", std::numeric_limits<float>::quiet_NaN()),
                          spec.get_int_attribute ("dpx:HighData", 0xFFFFFFFF),
                          spec.get_float_attribute ("dpx:HighQuantity", std::numeric_limits<float>::quiet_NaN()),
                          spec.get_int_attribute ("dpx:EndOfLinePadding", 0),
                          spec.get_int_attribute ("dpx:EndOfImagePadding", 0));
        std::string desc = spec.get_string_attribute ("ImageDescription", "");
        m_dpx.header.SetDescription (s, desc.c_str());
    }

    m_dpx.header.SetXScannedSize (m_spec.get_float_attribute
        ("dpx:XScannedSize", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetYScannedSize (m_spec.get_float_attribute
        ("dpx:YScannedSize", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetFramePosition (m_spec.get_int_attribute
        ("dpx:FramePosition", 0xFFFFFFFF));
    m_dpx.header.SetSequenceLength (m_spec.get_int_attribute
        ("dpx:SequenceLength", 0xFFFFFFFF));
    m_dpx.header.SetHeldCount (m_spec.get_int_attribute
        ("dpx:HeldCount", 0xFFFFFFFF));
    m_dpx.header.SetFrameRate (m_spec.get_float_attribute
        ("dpx:FrameRate", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetShutterAngle (m_spec.get_float_attribute
        ("dpx:ShutterAngle", std::numeric_limits<float>::quiet_NaN()));
    // FIXME: should we write the input version through or always default to 2.0?
    /*tmpstr = m_spec.get_string_attribute ("dpx:Version", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetVersion (tmpstr.c_str ());*/
    std::string tmpstr;
    tmpstr = m_spec.get_string_attribute ("dpx:FrameId", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetFrameId (tmpstr.c_str ());
    tmpstr = m_spec.get_string_attribute ("dpx:SlateInfo", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetSlateInfo (tmpstr.c_str ());
    tmpstr = m_spec.get_string_attribute ("dpx:SourceImageFileName", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetSourceImageFileName (tmpstr.c_str ());
    tmpstr = m_spec.get_string_attribute ("dpx:InputDevice", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetInputDevice (tmpstr.c_str ());
    tmpstr = m_spec.get_string_attribute ("dpx:InputDeviceSerialNumber", "");
    if (tmpstr.size () > 0)
        m_dpx.header.SetInputDeviceSerialNumber (tmpstr.c_str ());
    m_dpx.header.SetInterlace (m_spec.get_int_attribute ("dpx:Interlace", 0xFF));
    m_dpx.header.SetFieldNumber (m_spec.get_int_attribute ("dpx:FieldNumber", 0xFF));
    m_dpx.header.SetHorizontalSampleRate (m_spec.get_float_attribute
        ("dpx:HorizontalSampleRate", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetVerticalSampleRate (m_spec.get_float_attribute
        ("dpx:VerticalSampleRate", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetTemporalFrameRate (m_spec.get_float_attribute
        ("dpx:TemporalFrameRate", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetTimeOffset (m_spec.get_float_attribute
        ("dpx:TimeOffset", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetBlackLevel (m_spec.get_float_attribute
        ("dpx:BlackLevel", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetBlackGain (m_spec.get_float_attribute
        ("dpx:BlackGain", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetBreakPoint (m_spec.get_float_attribute
        ("dpx:BreakPoint", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetWhiteLevel (m_spec.get_float_attribute
        ("dpx:WhiteLevel", std::numeric_limits<float>::quiet_NaN()));
    m_dpx.header.SetIntegrationTimes (m_spec.get_float_attribute
        ("dpx:IntegrationTimes", std::numeric_limits<float>::quiet_NaN()));
    float aspect = m_spec.get_float_attribute ("PixelAspectRatio", 1.0f);
    int aspect_num, aspect_den;
    float_to_rational (aspect, aspect_num, aspect_den);
    m_dpx.header.SetAspectRatio (0, aspect_num);
    m_dpx.header.SetAspectRatio (1, aspect_den);
    m_dpx.header.SetXOffset ((unsigned int)std::max (0, m_spec.x));
    m_dpx.header.SetYOffset ((unsigned int)std::max (0, m_spec.y));
    m_dpx.header.SetXOriginalSize ((unsigned int)m_spec.full_width);
    m_dpx.header.SetYOriginalSize ((unsigned int)m_spec.full_height);

    static int DpxOrientations[] = { 0,
        dpx::kLeftToRightTopToBottom, dpx::kRightToLeftTopToBottom,
        dpx::kLeftToRightBottomToTop, dpx::kRightToLeftBottomToTop,
        dpx::kTopToBottomLeftToRight, dpx::kTopToBottomRightToLeft,
        dpx::kBottomToTopLeftToRight, dpx::kBottomToTopRightToLeft };
    int orient = m_spec.get_int_attribute ("Orientation", 0);
    orient = DpxOrientations[clamp (orient, 0, 8)];
    m_dpx.header.SetImageOrientation ((dpx::Orientation)orient);

    ImageIOParameter *tc = m_spec.find_attribute("smpte:TimeCode", TypeDesc::TypeTimeCode, false);
    if (tc) {
        unsigned int *timecode = (unsigned int*) tc->data();
        m_dpx.header.timeCode = timecode[0];
        m_dpx.header.userBits = timecode[1];
    }
    else {
        std::string timecode = m_spec.get_string_attribute ("dpx:TimeCode", "");
        int tmpint = m_spec.get_int_attribute ("dpx:TimeCode", ~0);
        if (timecode.size () > 0)
            m_dpx.header.SetTimeCode (timecode.c_str ());
        else if (tmpint != ~0)
        m_dpx.header.timeCode = tmpint;
        m_dpx.header.userBits = m_spec.get_int_attribute ("dpx:UserBits", ~0);
    }

    ImageIOParameter *kc = m_spec.find_attribute("smpte:KeyCode", TypeDesc::TypeKeyCode, false);
    if (kc) {
        int *array = (int*) kc->data();
        set_keycode_values(array);

        // See if there is an overloaded dpx:Format
        std::string format = m_spec.get_string_attribute ("dpx:Format", "");
        if (format.size () > 0)
            m_dpx.header.SetFormat (format.c_str ());
    }

    std::string srcdate = m_spec.get_string_attribute ("dpx:SourceDateTime", "");
    if (srcdate.size () >= 19) {
        // libdpx's date/time format is pretty close to OIIO's (libdpx uses
        // %Y:%m:%d:%H:%M:%S%Z)
        // NOTE: the following code relies on the DateTime attribute being properly
        // formatted!
        // assume UTC for simplicity's sake, fix it if someone complains
        srcdate[10] = ':';
        srcdate.replace (19, -1, "Z");
        m_dpx.header.SetSourceTimeDate (srcdate.c_str ());
    }

    // set the user data size
    ImageIOParameter *user = m_spec.find_attribute ("dpx:UserData");
    if (user && user->datasize () > 0 && user->datasize () <= 1024 * 1024) {
        m_dpx.SetUserData (user->datasize ());
    }

    // commit!
    if (!m_dpx.WriteHeader ()) {
        error ("Failed to write DPX header");
        return false;
    }

    // write the user data
    if (user && user->datasize () > 0 && user->datasize() <= 1024 * 1024) {
        if (!m_dpx.WriteUserData ((void *)user->data ())) {
            error ("Failed to write user data");
            return false;
        }
    }

    m_dither = (m_spec.format == TypeDesc::UINT8) ?
                    m_spec.get_int_attribute ("oiio:dither", 0) : 0;

    // If user asked for tiles -- which this format doesn't support, emulate
    // it by buffering the whole image.
    if (m_spec.tile_width && m_spec.tile_height)
        m_tilebuffer.resize (m_spec.image_bytes());

    return prep_subimage (m_subimage, true);
}
Beispiel #30
0
XCamReturn
V4l2Device::set_format (struct v4l2_format &format)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    XCAM_FAIL_RETURN (ERROR, !is_activated (), XCAM_RETURN_ERROR_PARAM,
                      "Cannot set format to v4l2 device while it is active.");

    XCAM_FAIL_RETURN (ERROR, is_opened (), XCAM_RETURN_ERROR_FILE,
                      "Cannot set format to v4l2 device while it is closed.");

    struct v4l2_format tmp_format = format;

    ret = pre_set_format (format);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("device(%s) pre_set_format failed", XCAM_STR (_name));
        return ret;
    }

    if (io_control (VIDIOC_S_FMT, &format) < 0) {
        if (errno == EBUSY) {
            // TODO log device name
            XCAM_LOG_ERROR("Video device is busy, fail to set format.");
        } else {
            // TODO log format details and errno
            XCAM_LOG_ERROR("Fail to set format: %s", strerror(errno));
        }

        return XCAM_RETURN_ERROR_IOCTL;
    }

    if (tmp_format.fmt.pix.width != format.fmt.pix.width || tmp_format.fmt.pix.height != format.fmt.pix.height) {
        XCAM_LOG_ERROR (
            "device(%s) set v4l2 format failed, supported format: width:%d, height:%d",
            XCAM_STR (_name),
            format.fmt.pix.width,
            format.fmt.pix.height);

        return XCAM_RETURN_ERROR_PARAM;
    }

    while (_fps_n && _fps_d) {
        struct v4l2_streamparm param;
        xcam_mem_clear (param);
        param.type = _capture_buf_type;
        if (io_control (VIDIOC_G_PARM, &param) < 0) {
            XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_G_PARM but continue", XCAM_STR (_name));
            break;
        }

        if (!(param.parm.capture.capability & V4L2_CAP_TIMEPERFRAME))
            break;

        param.parm.capture.timeperframe.numerator = _fps_d;
        param.parm.capture.timeperframe.denominator = _fps_n;

        if (io_control (VIDIOC_S_PARM, &param) < 0) {
            XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_S_PARM but continue", XCAM_STR (_name));
            break;
        }
        _fps_n = param.parm.capture.timeperframe.denominator;
        _fps_d = param.parm.capture.timeperframe.numerator;
        XCAM_LOG_INFO ("device(%s) set framerate(%d/%d)", XCAM_STR (_name), _fps_n, _fps_d);

        // exit here, otherwise it is an infinite loop
        break;
    }

    ret = post_set_format (format);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("device(%s) post_set_format failed", XCAM_STR (_name));
        return ret;
    }

    _format = format;
    XCAM_LOG_INFO (
        "device(%s) set format(w:%d, h:%d, pixelformat:%s, bytesperline:%d,image_size:%d)",
        XCAM_STR (_name),
        format.fmt.pix.width, format.fmt.pix.height,
        xcam_fourcc_to_string (format.fmt.pix.pixelformat),
        format.fmt.pix.bytesperline,
        format.fmt.pix.sizeimage);

    return XCAM_RETURN_NO_ERROR;
}