Пример #1
0
// -------------------------------------------------------- //
// implementation for BMediaEventLooper
// -------------------------------------------------------- //
// protected:
status_t MediaReader::HandleBuffer(
				const media_timed_event *event,
				bigtime_t lateness,
				bool realTimeEvent)
{
	CALLED();

	if (output.destination == media_destination::null)
		return B_MEDIA_NOT_CONNECTED;

	status_t status = B_OK;
	BBuffer * buffer = fBufferGroup->RequestBuffer(output.format.u.multistream.max_chunk_size,fBufferPeriod);
	if (buffer != 0) {
	    status = FillFileBuffer(buffer);
	    if (status != B_OK) {
			PRINT("MediaReader::HandleEvent got an error from FillFileBuffer.\n");
			buffer->Recycle();
		} else {
			if (fOutputEnabled) {
				status = SendBuffer(buffer,output.destination);
				if (status != B_OK) {
					PRINT("MediaReader::HandleEvent got an error from SendBuffer.\n");
					buffer->Recycle();
				}
			} else {
				buffer->Recycle();
			}
		}
	}
	bigtime_t nextEventTime = event->event_time+fBufferPeriod;
	media_timed_event nextBufferEvent(nextEventTime, BTimedEventQueue::B_HANDLE_BUFFER);
	EventQueue()->AddEvent(nextBufferEvent);
	return status;
}
Пример #2
0
void
Core::PlayFileBuffer(void* cookie, void* buffer, size_t size,
	const media_raw_audio_format& format)
{
	size_t limit = (kLimit/gCronoSettings.Speed);
	bool stereo = format.channel_count == 2;

	off_t s;
	kBuf->GetSize(&s);
	kTicLen = s;

	if (kSize + size > limit)
		size -= kSize + size - limit;

	if (kSize >= limit) { 
		kSize -= limit;
		kSem = 0;
	}

	 if (kSem == 1) {
		memset(buffer, 0, size);
		kSize += size;
	} else if (kSem == 0) {
		FillFileBuffer((float*)buffer, size);

		if (size <  kFileFormat.u.raw_audio.buffer_size)
			size -= kSize + size - limit;

		kSize += size;
		if (kSize >= kTicLen)
			kSem = 1;
	}
}
Пример #3
0
void AdcWriteFile()
{
	if(!FileCreated)return;
	//if(!fCreateNew)return;
	if(FillFileBuffer(0, 512))
		{
			UartSendString("ADC store 512 \n");
			FileWriteString(FileWriteBuff,512);
		}
}
Пример #4
0
// protected:
status_t MediaReader::GetFilledBuffer(
				BBuffer ** outBuffer)
{
	CALLED();

	BBuffer * buffer = fBufferGroup->RequestBuffer(output.format.u.multistream.max_chunk_size,-1);
	if (buffer == 0) {
		// XXX: add a new buffer and get it
		PRINT("MediaReader::GetFilledBuffer needs a new buffer.\n");
		return B_ERROR; // don't send the buffer
	}

	status_t status = FillFileBuffer(buffer);
	*outBuffer = buffer;
	return status;
}		
Пример #5
0
void MediaReader::Connect(
				status_t error, 
				const media_source & source,
				const media_destination & destination,
				const media_format & format,
				char * io_name)
{
	CALLED();

	if (error != B_OK) {
		PRINT("\t<- error already\n");
		output.destination = media_destination::null;
		GetFormat(&output.format);
		return;
	}
	if (output.source != source) {
		PRINT("\t<- B_MEDIA_BAD_SOURCE\n");
		output.destination = media_destination::null;
		GetFormat(&output.format);
		return;
	}	
	
	// record the agreed upon values
	output.destination = destination;
	output.format = format;
	strncpy(io_name,output.name,B_MEDIA_NAME_LENGTH-1);
	io_name[B_MEDIA_NAME_LENGTH-1] = '\0';

	// determine our downstream latency
	media_node_id id;
	FindLatencyFor(output.destination, &fDownstreamLatency, &id);

	// compute the buffer period (must be done before setbuffergroup)
	fBufferPeriod = bigtime_t(1000 * 8000000 / 1024
	                     * output.format.u.multistream.max_chunk_size
			             / output.format.u.multistream.max_bit_rate);

	PRINT("\tmax chunk size = %ld, max bit rate = %f, buffer period = %lld\n",
			output.format.u.multistream.max_chunk_size,
			output.format.u.multistream.max_bit_rate,fBufferPeriod);

	// setup the buffers if they aren't setup yet
	if (fBufferGroup == 0) {
		status_t status = SetBufferGroup(output.source,0);
		if (status != B_OK) {
			PRINT("\t<- SetBufferGroup failed\n");
			output.destination = media_destination::null;
			GetFormat(&output.format);
			return;
		}
	}

	SetBufferDuration(fBufferPeriod);

	if (GetCurrentFile() != 0) {
		bigtime_t start, end;
		// buffer group buffer size
		uint8 * data = new uint8[output.format.u.multistream.max_chunk_size];
		BBuffer * buffer = 0;
		ssize_t bytesRead = 0;
		{ // timed section
			start = TimeSource()->RealTime();
			// first we try to use a real BBuffer
			buffer = fBufferGroup->RequestBuffer(
					output.format.u.multistream.max_chunk_size,fBufferPeriod);
			if (buffer != 0) {
				FillFileBuffer(buffer);
			} else {
				// didn't get a real BBuffer, try simulation by just a read from the disk
				bytesRead = GetCurrentFile()->Read(
						data, output.format.u.multistream.max_chunk_size);
			}
			end = TimeSource()->RealTime();
		}
		bytesRead = buffer->SizeUsed();
		delete data;
		if (buffer != 0) {
			buffer->Recycle();
		}
		GetCurrentFile()->Seek(-bytesRead,SEEK_CUR); // put it back where we found it
	
		fInternalLatency = end - start;
		
		PRINT("\tinternal latency from disk read = %lld\n", fInternalLatency);
	} else {
		fInternalLatency = 100; // just guess
		PRINT("\tinternal latency guessed = %lld\n", fInternalLatency);
	}
	
	SetEventLatency(fDownstreamLatency + fInternalLatency);
	
	// XXX: do anything else?
}