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


C++ PacketQueue::pop方法代码示例

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


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

示例1: router

TEST_F( RelayTest, CollectPacket ) {

   PacketQueue queue;
   PacketRouter router(&queue);
   TestPacketSubscriber subscriber_1;
   TestPacketSubscriber subscriber_2;
   TestPacketRelay relay;

   EXPECT_EQ( -1, router.count( kFirstChannel ) );
   EXPECT_EQ( -1, router.count( kSecondChannel ) );

   // Test registeration
   EXPECT_FALSE( subscriber_1.isSubscribed() );
   EXPECT_FALSE( subscriber_2.isSubscribed() );

   EXPECT_EQ( true, router.subscribe( RELAY_PIPE, &relay, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, relay.subscribe( kFirstChannel, &subscriber_1, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, relay.subscribe( kSecondChannel, &subscriber_2, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, subscriber_1.isSubscribed() );
   EXPECT_EQ( true, subscriber_2.isSubscribed() );
   EXPECT_EQ( 1, relay.count( kFirstChannel ) );
   EXPECT_EQ( 1, relay.count( kSecondChannel ) );

   // Route some packets.
   EXPECT_EQ( true, subscriber_1.sendPacket( kFirstChannel ) );
   EXPECT_EQ( true, subscriber_2.sendPacket( kSecondChannel ) );

   PacketContainer* container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( RELAY_PIPE, container_ptr->destination_id_ );
   NetAppPacket::Data* header_ptr = (NetAppPacket::Data*)container_ptr->packet_ptr_->basePtr();
   EXPECT_EQ( kFirstChannel, (DestinationID)header_ptr->type );

   container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( RELAY_PIPE, container_ptr->destination_id_ );
   header_ptr = (NetAppPacket::Data*)container_ptr->packet_ptr_->basePtr();
   EXPECT_EQ( kSecondChannel, (DestinationID)header_ptr->type );

   // Test unregisteration
   EXPECT_EQ( true, relay.unsubscribe( kFirstChannel, &subscriber_1 ) );
   EXPECT_EQ( true, relay.unsubscribe( kSecondChannel, &subscriber_2 ) );
   EXPECT_EQ( true, router.unsubscribe( RELAY_PIPE, &relay ) );
   EXPECT_FALSE( subscriber_1.isSubscribed() );
   EXPECT_FALSE( subscriber_2.isSubscribed() );
   EXPECT_EQ( 0, relay.count( kFirstChannel ) );
   EXPECT_EQ( 0, relay.count( kSecondChannel ) );
   EXPECT_EQ( 0, router.count( RELAY_PIPE ) );
}
开发者ID:rgmann,项目名称:coral,代码行数:49,代码来源:packet_relay_test.cpp

示例2: dvbsub_ass_clear

void dvbsub_ass_clear(void)
{
	OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(ass_mutex);

	while(ass_queue.size()) {
		ass_data *a = (ass_data *) ass_queue.pop();
		if (a) {
			avsubtitle_free(&a->sub);
			delete a;
		}
	}
	while(!sem_trywait(&ass_sem));

	ass_track = NULL;
	for(std::map<int,ASS_Track*>::iterator it = ass_map.begin(); it != ass_map.end(); ++it)
		ass_free_track(it->second);
	ass_map.clear();
	if (ass_renderer) {
		ass_renderer_done(ass_renderer);
		ass_renderer = NULL;
	}
	if (ass_library) {
		ass_library_done(ass_library);
		ass_library = NULL;
	}
	clear_queue();
}
开发者ID:j00zek,项目名称:j00zeks-neutrino-mp-cst-next,代码行数:27,代码来源:dvbsub.cpp

示例3: clear_queue

static void clear_queue()
{
	uint8_t* packet;
	cDvbSubtitleBitmaps *Bitmaps;

	pthread_mutex_lock(&packetMutex);
	while(packet_queue.size()) {
		packet = packet_queue.pop();
		free(packet);
	}
	while(bitmap_queue.size()) {
		Bitmaps = (cDvbSubtitleBitmaps *) bitmap_queue.pop();
		delete Bitmaps;
	}
	pthread_mutex_unlock(&packetMutex);
}
开发者ID:j00zek,项目名称:j00zeks-neutrino-mp-cst-next,代码行数:16,代码来源:dvbsub.cpp

示例4: sendPacket

TEST_F( PacketTest, SendPacket ) {
   const DestinationID kFirstChannel  = 5;
   const DestinationID kSecondChannel = 10;

   class TestPacketSubscriber : public PacketSubscriber {
   public:

      bool sendPacket( DestinationID destination_id )
      {
         NetAppPacket* packet_ptr = new NetAppPacket( destination_id, 100 );
         bool success = sendTo( destination_id, packet_ptr );
         if ( success == false )
         {
            delete packet_ptr;
         }
         return success;
      }

      bool put( DestinationID destination_id, const void* data_ptr, ui32 length )
      {
         return true;
      }
   };

   PacketQueue queue;
   PacketRouter router(&queue);
   TestPacketSubscriber subscriber;

   EXPECT_EQ( -1, router.count( kFirstChannel ) );
   EXPECT_EQ( -1, router.count( kSecondChannel ) );

   // Test registeration
   EXPECT_FALSE( subscriber.isSubscribed() );
   EXPECT_EQ( true, router.subscribe( kFirstChannel, &subscriber, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, router.subscribe( kSecondChannel, &subscriber, kSubscriberModeReadOnly ) );
   EXPECT_EQ( true, subscriber.isSubscribed() );
   EXPECT_EQ( 1, router.count( kFirstChannel ) );
   EXPECT_EQ( 1, router.count( kSecondChannel ) );

   // Send a packet on the first channel.
   EXPECT_EQ( true, subscriber.sendPacket( kFirstChannel ) );
   PacketContainer* container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( kFirstChannel, container_ptr->destination_id_ );
   EXPECT_EQ( 108, container_ptr->packet_ptr_->allocatedSize() );
   // delete container_ptr->packet_ptr_;
   // delete container_ptr;


   // Test unregisteration
   EXPECT_EQ( true, router.unsubscribe( kFirstChannel, &subscriber ) );
   EXPECT_EQ( true, router.unsubscribe( kSecondChannel, &subscriber ) );
   EXPECT_FALSE( subscriber.isSubscribed() );

   EXPECT_EQ( 0, router.count( kFirstChannel ) );
   EXPECT_EQ( 0, router.count( kSecondChannel ) );
}
开发者ID:rgmann,项目名称:coral,代码行数:57,代码来源:packet_router_test.cpp

示例5: clear_queue

static void clear_queue()
{
	uint8_t* packet;

	pthread_mutex_lock(&packetMutex);
	while(packet_queue.size()) {
		packet = packet_queue.pop();
		free(packet);
	}
	pthread_mutex_unlock(&packetMutex);
}
开发者ID:n3wb13,项目名称:neutrinohd2,代码行数:11,代码来源:dvbsub.cpp

示例6: strlen

static void *ass_reader_thread(void *)
{
	set_threadname("ass_reader_thread");
	while (!sem_wait(&ass_sem)) {
		if (!ass_reader_running)
			break;

		ass_data *a = (ass_data *) ass_queue.pop();
		if (!a) {
			if (!ass_reader_running)
				break;
			continue;
		}

		OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(ass_mutex);
		std::map<int,ASS_Track*>::iterator it = ass_map.find(a->pid);
		ASS_Track *track;
		if (it == ass_map.end()) {
			CFrameBuffer *fb = CFrameBuffer::getInstance();
			int xres = fb->getScreenWidth(true);
			int yres = fb->getScreenHeight(true);
			if (!ass_library) {
				ass_library = ass_library_init();
				ass_set_extract_fonts(ass_library, 1);
				ass_set_style_overrides(ass_library, NULL);
				ass_renderer = ass_renderer_init(ass_library);
				ass_set_frame_size(ass_renderer, xres, yres);
				ass_set_margins(ass_renderer, 3 * yres / 100, 3 * yres / 100, 3 * xres / 100, 3 * xres / 100);
				ass_set_use_margins(ass_renderer, 1);
				ass_set_hinting(ass_renderer, ASS_HINTING_LIGHT);
				ass_set_aspect_ratio(ass_renderer, 1.0, 1.0);
				ass_font = *sub_font_file;
				ass_set_fonts(ass_renderer, ass_font.c_str(), "Arial", 0, NULL, 1);
			}
			track = ass_new_track(ass_library);
			track->PlayResX = xres;
			track->PlayResY = yres;
			ass_size = sub_font_size;
			ass_set_font_scale(ass_renderer, ((double) ass_size)/ASS_CUSTOM_FONT_SIZE);
			if (a->c->subtitle_header) {
				std::string ass_hdr = ass_subtitle_header_default();
				if (ass_hdr.compare((char*) a->c->subtitle_header)) {
					ass_process_codec_private(track, (char *) a->c->subtitle_header, a->c->subtitle_header_size);
				} else {
					// This is the FFMPEG default ASS header. Use something more suitable instead:
					ass_hdr = ass_subtitle_header_custom();
					ass_process_codec_private(track, (char *) ass_hdr.c_str(), ass_hdr.length());
				}
			}
			ass_map[a->pid] = track;
			if (a->pid == dvbsub_pid)
				ass_track = track;
//fprintf(stderr, "### got subtitle track %d, subtitle header: \n---\n%s\n---\n", pid, c->subtitle_header);
		} else
			track = it->second;
		for (unsigned int i = 0; i < a->sub.num_rects; i++)
			if (a->sub.rects[i]->ass)
				ass_process_data(track, a->sub.rects[i]->ass, strlen(a->sub.rects[i]->ass));
		avsubtitle_free(&a->sub);
		delete a;
	}
	ass_reader_running = false;
	pthread_exit(NULL);
}
开发者ID:j00zek,项目名称:j00zeks-neutrino-mp-cst-next,代码行数:64,代码来源:dvbsub.cpp

示例7: dvbsub_thread

static void* dvbsub_thread(void* /*arg*/)
{
	struct timespec restartWait;
	struct timeval now;

	sub_debug.print(Debug::VERBOSE, "%s started\n", __FUNCTION__);
	if (!dvbSubtitleConverter)
		dvbSubtitleConverter = new cDvbSubtitleConverter;

	int timeout = 1000000;
	while(dvbsub_running) 
	{
		uint8_t* packet;
		int64_t pts;
		int dataoffset;
		int packlen;

		gettimeofday(&now, NULL);

		int ret = 0;
		now.tv_usec += (timeout == 0) ? 1000000 : timeout;   // add the timeout
		while (now.tv_usec >= 1000000) 
		{   
			// take care of an overflow
			now.tv_sec++;
			now.tv_usec -= 1000000;
		}
		restartWait.tv_sec = now.tv_sec;          // seconds
		restartWait.tv_nsec = now.tv_usec * 1000; // nano seconds

		pthread_mutex_lock( &packetMutex );
		ret = pthread_cond_timedwait( &packetCond, &packetMutex, &restartWait );
		pthread_mutex_unlock( &packetMutex );

		timeout = dvbSubtitleConverter->Action();

		if(packet_queue.size() == 0) {
			continue;
		}
#if 1
		sub_debug.print(Debug::VERBOSE, "PES: Wakeup, queue size %d\n\n", packet_queue.size());
#endif
		if(dvbsub_stopped /*dvbsub_paused*/) 
		{
			clear_queue();
			continue;
		}

		pthread_mutex_lock(&packetMutex);
		packet = packet_queue.pop();
		pthread_mutex_unlock(&packetMutex);

		if (!packet) {
			sub_debug.print(Debug::VERBOSE, "Error no packet found\n");
			continue;
		}
		packlen = (packet[4] << 8 | packet[5]) + 6;

		pts = get_pts(packet);

		dataoffset = packet[8] + 8 + 1;
		if (packet[dataoffset] != 0x20) 
		{
#if 1
			sub_debug.print(Debug::VERBOSE, "Not a dvb subtitle packet, discard it (len %d)\n", packlen);

			for(int i = 0; i < packlen; i++)
				printf("%02X ", packet[i]);
			printf("\n");
#endif
			goto next_round;
		}

#if 1
		sub_debug.print(Debug::VERBOSE, "PES packet: len %d data len %d PTS=%Ld (%02d:%02d:%02d.%d) diff %lld\n", packlen, packlen - (dataoffset + 2), pts, (int)(pts/324000000), (int)((pts/5400000)%60), (int)((pts/90000)%60), (int)(pts%90000), get_pts_stc_delta(pts));
#endif

		if (packlen <= dataoffset + 3) 
		{
			sub_debug.print(Debug::INFO, "Packet too short, discard\n");
			
			goto next_round;
		}

		if (packet[dataoffset + 2] == 0x0f) 
		{
			dvbSubtitleConverter->Convert(&packet[dataoffset + 2], packlen - (dataoffset + 2), pts);
		} 
		else 
		{
			sub_debug.print(Debug::INFO, "End_of_PES is missing\n");
		}
		timeout = dvbSubtitleConverter->Action();

next_round:
		free(packet);
	}

	delete dvbSubtitleConverter;

//.........这里部分代码省略.........
开发者ID:n3wb13,项目名称:neutrinohd2,代码行数:101,代码来源:dvbsub.cpp

示例8: dvbsub_thread

void* dvbsub_thread(void* arg)
{
    struct timespec to;
    struct timespec restartWait;
    struct timeval now;

    debug.print(Debug::DEBUG, "%s started\n", __FUNCTION__);
    if (!dvbSubtitleConverter)
        dvbSubtitleConverter = new cDvbSubtitleConverter;

    while(dvbsub_running) {
        uint8_t* packet;
        int64_t pts;
        int pts_dts_flag;
        int dataoffset;
        int packlen;
//		int err = 0;
#if 0
        int64_t current_time = get_time();

        /* Check screen updates */
        if ((page.prev_page.cleartime > 0) &&
                (page.prev_page.cleartime < current_time)) {
            // clear_page(page.prev_page);
            page.prev_page.cleartime = -1;
        }
        if ((page.prev_page.cleartime > 0) &&
                (page.timestamp > 0) &&
                (page.timestamp < current_time)) {
            // draw_page(page);
            page.timestamp = -1;
        }

        if (page.timestamp == -1) {
#endif
            gettimeofday(&now, NULL);
            TIMEVAL_TO_TIMESPEC(&now, &restartWait);
            restartWait.tv_sec += 1;

            pthread_mutex_lock( &packetMutex );
            int ret = pthread_cond_timedwait( &packetCond, &packetMutex, &restartWait );
            pthread_mutex_unlock( &packetMutex );
            if (ret == ETIMEDOUT)
            {
                continue;
            }
            else if (ret == EINTR)
            {
                debug.print(Debug::DEBUG, "pthread_cond_timedwait fails with %s\n", strerror(errno));
            }
            packet = packet_queue.pop();
            if (!packet) {
                debug.print(Debug::DEBUG, "Error no packet found\n");
                continue;
            }
            packlen = (packet[4] << 8 | packet[5]) + 6;

            /* Get PTS */
            pts_dts_flag = getbits(packet, 7*8, 2);
            if ((pts_dts_flag == 2) || (pts_dts_flag == 3)) {
                pts = (uint64_t)getbits(packet, 9*8+4, 3) << 30;  /* PTS[32..30] */
                pts |= getbits(packet, 10*8, 15) << 15;           /* PTS[29..15] */
                pts |= getbits(packet, 12*8, 15);                 /* PTS[14..0] */
            } else {
                pts = 0;
            }

            dataoffset = packet[8] + 8 + 1;
            if (packet[dataoffset] != 0x20) {
                debug.print(Debug::DEBUG, "Not a dvb subtitle packet, discard it\n");
                goto next_round;
            }

            debug.print(Debug::DEBUG, "PES packet PTS=%Ld (%02d:%02d:%02d.%d)\n",
                        pts, (int)(pts/324000000), (int)((pts/5400000)%60),
                        (int)((pts/90000)%60), (int)(pts%90000));

            if (packlen <= dataoffset + 3) {
                debug.print(Debug::INFO, "Packet too short, discard\n");
                goto next_round;
            }

#if 0
            while (packet[dataoffset + 2] == 0x0f) {
                err = subtitling_segment(&packet[dataoffset + 2],
                                         packlen - (dataoffset + 2), pts);
                if (err < 0) {
                    break;
                }
                dataoffset += err;
            }
            if (err >= 0) {
                if (dataoffset + 2 >= packlen) {
                    debug.print(Debug::INFO, "Packet too short, discard it\n",
                                dataoffset, packlen);
                } else if (packet[dataoffset + 2] != 0xFF) {
                    debug.print(Debug::INFO, "End_of_PES is missing\n");
                }
            }
#endif
//.........这里部分代码省略.........
开发者ID:OpenAR-P,项目名称:neutrino-mp-plugins,代码行数:101,代码来源:dvbsub_thread.cpp


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