コード例 #1
0
void AudioStreamDecoder::PacketCallback(UInt32 byteCount, UInt32 packetCount, const void* data, AudioStreamPacketDescription* packetDescriptions)
{
	long err;

	// Constant bit rate audio arrives without packet descriptions.
	while (!packetDescriptions && !mFinished && byteCount)
	{
		unsigned int copyCount = byteCount;
		if (copyCount > (*mCurrentBuffer)->mAudioDataBytesCapacity - (*mCurrentBuffer)->mAudioDataByteSize)
			copyCount = (*mCurrentBuffer)->mAudioDataBytesCapacity - (*mCurrentBuffer)->mAudioDataByteSize;

		memcpy((unsigned char*)(*mCurrentBuffer)->mAudioData + (*mCurrentBuffer)->mAudioDataByteSize, data, copyCount);
		byteCount -= copyCount;
		(*mCurrentBuffer)->mAudioDataByteSize += copyCount;

		if ((*mCurrentBuffer)->mAudioDataByteSize == (*mCurrentBuffer)->mAudioDataBytesCapacity)
		{
			err = EnqueueBuffer();
			BAIL_IF(err, "EnqueueBuffer returned %ld\n", err);
		}
	}

	if (!packetDescriptions)
		return;

	// Variable bit rate audio has a description for every packet.
	for (unsigned int i = 0; !mFinished && i < packetCount; i++)
	{
		if (packetDescriptions[i].mDataByteSize > (*mCurrentBuffer)->mAudioDataBytesCapacity - (*mCurrentBuffer)->mAudioDataByteSize)
		{
			err = EnqueueBuffer();
			BAIL_IF(err, "EnqueueBuffer returned %ld\n", err);
		}

		if (mFinished)
			break;

		memcpy((unsigned char*)(*mCurrentBuffer)->mAudioData + (*mCurrentBuffer)->mAudioDataByteSize,
			   (const unsigned char*)data + packetDescriptions[i].mStartOffset,
			   packetDescriptions[i].mDataByteSize);
		(*mCurrentBuffer)->mPacketDescriptions[(*mCurrentBuffer)->mPacketDescriptionCount] = packetDescriptions[i];
		(*mCurrentBuffer)->mPacketDescriptions[(*mCurrentBuffer)->mPacketDescriptionCount].mStartOffset = (*mCurrentBuffer)->mAudioDataByteSize;
		(*mCurrentBuffer)->mAudioDataByteSize += packetDescriptions[i].mDataByteSize;
		(*mCurrentBuffer)->mPacketDescriptionCount++;

		if ((*mCurrentBuffer)->mPacketDescriptionCount == (*mCurrentBuffer)->mPacketDescriptionCapacity)
		{
			err = EnqueueBuffer();
			BAIL_IF(err, "EnqueueBuffer returned %ld\n", err);
		}
	}

bail:
	return;
}
コード例 #2
0
ファイル: mac_audio.c プロジェクト: stevestreza/pianobar
void StreamPacketsProc(void * inClientData,
                       UInt32 inNumberBytes,
                       UInt32 inNumberPackets,
                       const void * inInputData,
                       AudioStreamPacketDescription	*inPacketDescriptions)
{
    // this is called by audio file stream when it finds packets of audio
    struct audioPlayer* player = (struct audioPlayer*)inClientData;

    // the following code assumes we're streaming VBR data. for CBR data, you'd need another code branch here.


    for (int i = 0; i < inNumberPackets; ++i) {
        SInt64 packetOffset = inPacketDescriptions[i].mStartOffset;
        SInt64 packetSize   = inPacketDescriptions[i].mDataByteSize;

        player->processedPacketsSize += packetSize;
        player->processedPacketCount += 1;

        // if the space remaining in the buffer is not enough for this packet, then enqueue the buffer.
        size_t bufSpaceRemaining = kAQBufSize - player->bytesFilled;
        if (bufSpaceRemaining < packetSize) {
            EnqueueBuffer(player);
            WaitForFreeBuffer(player);
        }

        // copy data to the audio queue buffer
        AudioQueueBufferRef fillBuf = player->audioQueueBuffer[player->fillBufferIndex];
        memcpy((char*)fillBuf->mAudioData + player->bytesFilled, (const char*)inInputData + packetOffset, packetSize);
        // fill out packet description
        player->packetDescs[player->packetsFilled] = inPacketDescriptions[i];
        player->packetDescs[player->packetsFilled].mStartOffset = player->bytesFilled;
        // keep track of bytes filled and packets filled
        player->bytesFilled += packetSize;
        player->packetsFilled += 1;
        player->dSongPlayed += player->packetDuration * 1000.0f;
        player->songPlayed = (unsigned long int)player->dSongPlayed;
        // if that was the last free packet description, then enqueue the buffer.
        size_t packetsDescsRemaining = kAQMaxPacketDescs - player->packetsFilled;
        if (packetsDescsRemaining == 0) {
            EnqueueBuffer(player);
            WaitForFreeBuffer(player);
        }
    }
}
コード例 #3
0
ファイル: vncspu.c プロジェクト: alown/chromium
/**
 * Called by the RFB encoder thread to unlock access to 0th screen_buffer.
 */
void
vncspuUnlockFrameBuffer(void)
{
	CRASSERT(vnc_spu.serverBuffer);
	/* put server buffer into empty queue */
	vnc_spu.serverBuffer->regionSent = GL_TRUE;
	REGION_EMPTY(&vnc_spu.serverBuffer->dirtyRegion);

#if DB
	crDebug("Putting sent buffer %p into empty queue",
					(void *) vnc_spu.serverBuffer);
#endif
	EnqueueBuffer(vnc_spu.serverBuffer, &vnc_spu.emptyQueue);
	vnc_spu.serverBuffer = NULL;
}
コード例 #4
0
ファイル: v4l2.cpp プロジェクト: JdeRobot4Air/v4l2server
void Camera::Start() throw (std::string) {
  if (!initialized_) {
    throw std::string("Camera not initialized");
  }
  unsigned int i;
  enum v4l2_buf_type type;
  /* Enqueue all buffers */
  for (i = 0; i < (unsigned int) num_buffers_; ++i) {
    EnqueueBuffer(i);
  }
  /* Final and more important step: start streaming images */
  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (xioctl(VIDIOC_STREAMON, &type) == -1) {
    throw std::string("Error in VIDIOC_STREAMON");
  }
  current_buffer_.length = 0;
}
コード例 #5
0
ファイル: vncspu.c プロジェクト: alown/chromium
void
vncspuInitialize(void)
{
#if defined(HAVE_XCLIPLIST_EXT) || defined(HAVE_VNC_EXT)
	char *dpyStr = NULL;

	vnc_spu.dpy = XOpenDisplay(vnc_spu.display_string);
	if (!vnc_spu.dpy)
		vnc_spu.dpy = XOpenDisplay(":0");

	CRASSERT(vnc_spu.dpy);
	dpyStr = DisplayString(vnc_spu.dpy);
#endif

	/*
	 * XClipList extension - get clip rects for an X window.
	 */
#if defined(HAVE_XCLIPLIST_EXT)
	{
		 int eventBase, errorBase;
		 vnc_spu.haveXClipListExt = XClipListQueryExtension(vnc_spu.dpy,
																												&eventBase,
																												&errorBase);
		 if (vnc_spu.haveXClipListExt) {
				crDebug("VNC SPU: XClipList extension present on %s", dpyStr);
		 }
		 else {
				crWarning("VNC SPU: The display %s doesn't support the XClipList extension", dpyStr);
		 }
		 /* Note: not checking XClipList extension version at this time */
	}
#else
	crWarning("VNC SPU: Not compiled with HAVE_XCLIPLIST_EXT=1");
#endif /* HAVE_XCLIPLIST_EXT */

	/*
	 * XClipList extension - get clip rects for an X window.
	 */
#if defined(HAVE_VNC_EXT)
	{
		int major, minor;
		vnc_spu.haveVncExt = XVncQueryExtension(vnc_spu.dpy, &major, &minor);
		if (vnc_spu.haveVncExt) {
			crDebug("VNC SPU: XVnc extension present on %s", dpyStr);
		}
		else {
			crWarning("VNC SPU: The display %s doesn't support the VNC extension", dpyStr);
		}
	}
#else
	crWarning("VNC SPU: Not compiled with HAVE_VNC_EXT=1");
#endif /* HAVE_VNC_EXT */

	vnc_spu.timer = crTimerNewTimer();

	crDebug("VNC SPU: double buffering: %d", vnc_spu.double_buffer);

	InitScreenBufferQueue(&vnc_spu.emptyQueue, "empty");
	InitScreenBufferQueue(&vnc_spu.filledQueue, "filled");
	{
		int i;
		/* create screen buffers and put them into the 'empty buffer' queue */
		crDebug("VNC SPU: Creating %d screen buffers", vnc_spu.double_buffer + 1);
		for (i = 0; i <= vnc_spu.double_buffer; i++) {
			ScreenBuffer *b = AllocScreenBuffer();
			EnqueueBuffer(b, &vnc_spu.emptyQueue);
		}
	}
}