当前位置: 首页>>代码示例>>C++>>正文


C++ BPositionIO::GetSize方法代码示例

本文整理汇总了C++中BPositionIO::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BPositionIO::GetSize方法的具体用法?C++ BPositionIO::GetSize怎么用?C++ BPositionIO::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BPositionIO的用法示例。


在下文中一共展示了BPositionIO::GetSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: new

/*static*/ status_t
FSUtils::CompareFileContent(BPositionIO& content1, BPositionIO& content2,
                            bool& _equal)
{
    // get and compare content size
    off_t size1;
    status_t error = content1.GetSize(&size1);
    if (error != B_OK)
        return error;

    off_t size2;
    error = content2.GetSize(&size2);
    if (error != B_OK)
        return error;

    if (size1 != size2) {
        _equal = false;
        return B_OK;
    }

    if (size1 == 0) {
        _equal = true;
        return B_OK;
    }

    // allocate a data buffer
    uint8* buffer1 = new(std::nothrow) uint8[2 * kCompareDataBufferSize];
    if (buffer1 == NULL)
        return B_NO_MEMORY;
    ArrayDeleter<uint8> bufferDeleter(buffer1);
    uint8* buffer2 = buffer1 + kCompareDataBufferSize;

    // compare the data
    off_t offset = 0;
    while (offset < size1) {
        size_t toCompare = std::min(size_t(size1 - offset),
                                    kCompareDataBufferSize);
        ssize_t bytesRead = content1.ReadAt(offset, buffer1, toCompare);
        if (bytesRead < 0)
            return bytesRead;
        if ((size_t)bytesRead != toCompare)
            return B_ERROR;

        bytesRead = content2.ReadAt(offset, buffer2, toCompare);
        if (bytesRead < 0)
            return bytesRead;
        if ((size_t)bytesRead != toCompare)
            return B_ERROR;

        if (memcmp(buffer1, buffer2, toCompare) != 0) {
            _equal = false;
            return B_OK;
        }

        offset += bytesRead;
    }

    _equal = true;
    return B_OK;
}
开发者ID:yunxiaoxiao110,项目名称:haiku,代码行数:60,代码来源:FSUtils.cpp

示例2:

/*static*/ off_t
AVFormatWriter::_Seek(void* cookie, off_t offset, int whence)
{
	TRACE_IO("AVFormatWriter::_Seek(%p, %lld, %d)\n",
		cookie, offset, whence);

	AVFormatWriter* writer = reinterpret_cast<AVFormatWriter*>(cookie);

	BPositionIO* positionIO = dynamic_cast<BPositionIO*>(writer->fTarget);
	if (positionIO == NULL)
		return -1;

	// Support for special file size retrieval API without seeking anywhere:
	if (whence == AVSEEK_SIZE) {
		off_t size;
		if (positionIO->GetSize(&size) == B_OK)
			return size;
		return -1;
	}

	off_t position = positionIO->Seek(offset, whence);
	TRACE_IO("  position: %lld\n", position);
	if (position < 0)
		return -1;

	return position;
}
开发者ID:luciang,项目名称:haiku,代码行数:27,代码来源:AVFormatWriter.cpp

示例3: _

status_t
StreamBase::Seek(uint32 flags, int64* frame, bigtime_t* time)
{
	BAutolock _(fStreamLock);

	if (fContext == NULL || fStream == NULL)
		return B_NO_INIT;

	TRACE_SEEK("StreamBase::Seek(%ld,%s%s%s%s, %lld, "
		"%lld)\n", VirtualIndex(),
		(flags & B_MEDIA_SEEK_TO_FRAME) ? " B_MEDIA_SEEK_TO_FRAME" : "",
		(flags & B_MEDIA_SEEK_TO_TIME) ? " B_MEDIA_SEEK_TO_TIME" : "",
		(flags & B_MEDIA_SEEK_CLOSEST_BACKWARD)
			? " B_MEDIA_SEEK_CLOSEST_BACKWARD" : "",
		(flags & B_MEDIA_SEEK_CLOSEST_FORWARD)
			? " B_MEDIA_SEEK_CLOSEST_FORWARD" : "",
		*frame, *time);

	double frameRate = FrameRate();
	if ((flags & B_MEDIA_SEEK_TO_FRAME) != 0) {
		// Seeking is always based on time, initialize it when client seeks
		// based on frame.
		*time = (bigtime_t)(*frame * 1000000.0 / frameRate + 0.5);
	}

	int64_t timeStamp = *time;

	int searchFlags = AVSEEK_FLAG_BACKWARD;
	if ((flags & B_MEDIA_SEEK_CLOSEST_FORWARD) != 0)
		searchFlags = 0;

	if (fSeekByBytes) {
		searchFlags |= AVSEEK_FLAG_BYTE;

		BAutolock _(fSourceLock);
		int64_t fileSize;
		if (fSource->GetSize(&fileSize) != B_OK)
			return B_NOT_SUPPORTED;
		int64_t duration = Duration();
		if (duration == 0)
			return B_NOT_SUPPORTED;

		timeStamp = int64_t(fileSize * ((double)timeStamp / duration));
		if ((flags & B_MEDIA_SEEK_CLOSEST_BACKWARD) != 0) {
			timeStamp -= 65536;
			if (timeStamp < 0)
				timeStamp = 0;
		}

		bool seekAgain = true;
		bool seekForward = true;
		bigtime_t lastFoundTime = -1;
		int64_t closestTimeStampBackwards = -1;
		while (seekAgain) {
			if (avformat_seek_file(fContext, -1, INT64_MIN, timeStamp,
				INT64_MAX, searchFlags) < 0) {
				TRACE("  avformat_seek_file() (by bytes) failed.\n");
				return B_ERROR;
			}
			seekAgain = false;

			// Our last packet is toast in any case. Read the next one so we
			// know where we really seeked.
			fReusePacket = false;
			if (_NextPacket(true) == B_OK) {
				while (fPacket.pts == kNoPTSValue) {
					fReusePacket = false;
					if (_NextPacket(true) != B_OK)
						return B_ERROR;
				}
				if (fPacket.pos >= 0)
					timeStamp = fPacket.pos;
				bigtime_t foundTime
					= _ConvertFromStreamTimeBase(fPacket.pts);
				if (foundTime != lastFoundTime) {
					lastFoundTime = foundTime;
					if (foundTime > *time) {
						if (closestTimeStampBackwards >= 0) {
							timeStamp = closestTimeStampBackwards;
							seekAgain = true;
							seekForward = false;
							continue;
						}
						int64_t diff = int64_t(fileSize
							* ((double)(foundTime - *time) / (2 * duration)));
						if (diff < 8192)
							break;
						timeStamp -= diff;
						TRACE_SEEK("  need to seek back (%lld) (time: %.2f "
							"-> %.2f)\n", timeStamp, *time / 1000000.0,
							foundTime / 1000000.0);
						if (timeStamp < 0)
							foundTime = 0;
						else {
							seekAgain = true;
							continue;
						}
					} else if (seekForward && foundTime < *time - 100000) {
						closestTimeStampBackwards = timeStamp;
						int64_t diff = int64_t(fileSize
//.........这里部分代码省略.........
开发者ID:RAZVOR,项目名称:haiku,代码行数:101,代码来源:AVFormatReader.cpp


注:本文中的BPositionIO::GetSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。