mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Properly flush packet queues when at EOF
Note: the previous flush method was renamed to clear. Flushing a queue allows consumers to retrieve queued packets, but not expect any more to come in.
This commit is contained in:
		
							parent
							
								
									6bc526b74d
								
							
						
					
					
						commit
						c92cde2be9
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		|  | @ -29,12 +29,13 @@ enum { | ||||||
| 
 | 
 | ||||||
| struct PacketQueue { | struct PacketQueue { | ||||||
|     PacketQueue() |     PacketQueue() | ||||||
|       : first_pkt(NULL), last_pkt(NULL), nb_packets(0), size(0) |       : first_pkt(NULL), last_pkt(NULL), flushing(false), nb_packets(0), size(0) | ||||||
|     { } |     { } | ||||||
|     ~PacketQueue() |     ~PacketQueue() | ||||||
|     { flush(); } |     { clear(); } | ||||||
| 
 | 
 | ||||||
|     AVPacketList *first_pkt, *last_pkt; |     AVPacketList *first_pkt, *last_pkt; | ||||||
|  |     volatile bool flushing; | ||||||
|     int nb_packets; |     int nb_packets; | ||||||
|     int size; |     int size; | ||||||
| 
 | 
 | ||||||
|  | @ -45,6 +46,7 @@ struct PacketQueue { | ||||||
|     int get(AVPacket *pkt, VideoState *is); |     int get(AVPacket *pkt, VideoState *is); | ||||||
| 
 | 
 | ||||||
|     void flush(); |     void flush(); | ||||||
|  |     void clear(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct VideoPicture { | struct VideoPicture { | ||||||
|  | @ -202,6 +204,8 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is) | ||||||
|             return 1; |             return 1; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         if(this->flushing) | ||||||
|  |             break; | ||||||
|         this->cond.wait(lock); |         this->cond.wait(lock); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -209,6 +213,12 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PacketQueue::flush() | void PacketQueue::flush() | ||||||
|  | { | ||||||
|  |     this->flushing = true; | ||||||
|  |     this->cond.notify_one(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void PacketQueue::clear() | ||||||
| { | { | ||||||
|     AVPacketList *pkt, *pkt1; |     AVPacketList *pkt, *pkt1; | ||||||
| 
 | 
 | ||||||
|  | @ -753,7 +763,10 @@ void VideoState::decode_thread_loop(VideoState *self) | ||||||
|             else |             else | ||||||
|                 av_free_packet(packet); |                 av_free_packet(packet); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|         /* all done - wait for it */ |         /* all done - wait for it */ | ||||||
|  |         self->videoq.flush(); | ||||||
|  |         self->audioq.flush(); | ||||||
|         while(!self->quit) |         while(!self->quit) | ||||||
|         { |         { | ||||||
|             // EOF reached, all packets processed, we can exit now
 |             // EOF reached, all packets processed, we can exit now
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue