| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -6,39 +6,38 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <libavcodec/avcodec.h> | 
					 | 
					 | 
					 | 
					#include <libavcodec/avcodec.h> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					AVPacketQueue* queue_init(int size){ | 
					 | 
					 | 
					 | 
					AVPacketQueue *queue_init(int size) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    AVPacketQueue* queue = malloc(sizeof(AVPacketQueue)); | 
					 | 
					 | 
					 | 
					    AVPacketQueue *queue = malloc(sizeof(AVPacketQueue)); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    queue->size = size; | 
					 | 
					 | 
					 | 
					    queue->size = size; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    queue->next_to_read = 0; | 
					 | 
					 | 
					 | 
					    queue->next_to_read = 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    queue->next_to_write = 0; | 
					 | 
					 | 
					 | 
					    queue->next_to_write = 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    int i; | 
					 | 
					 | 
					 | 
					    int i; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    queue->packets = malloc(sizeof(*queue->packets) * size); | 
					 | 
					 | 
					 | 
					    queue->packets = malloc(sizeof(*queue->packets) * size); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for(i = 0; i < size; i++){ | 
					 | 
					 | 
					 | 
					    for (i = 0; i < size; i++) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        queue->packets[i] = malloc(sizeof(AVPacket)); | 
					 | 
					 | 
					 | 
					        queue->packets[i] = malloc(sizeof(AVPacket)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return queue; | 
					 | 
					 | 
					 | 
					    return queue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					void queue_free(AVPacketQueue *queue){ | 
					 | 
					 | 
					 | 
					void queue_free(AVPacketQueue *queue) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    int i; | 
					 | 
					 | 
					 | 
					    int i; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for(i=0; i<queue->size; i++){ | 
					 | 
					 | 
					 | 
					    for (i = 0; i < queue->size; i++) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        free(queue->packets[i]); | 
					 | 
					 | 
					 | 
					        free(queue->packets[i]); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    free(queue->packets); | 
					 | 
					 | 
					 | 
					    free(queue->packets); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    free(queue); | 
					 | 
					 | 
					 | 
					    free(queue); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					int queue_next(AVPacketQueue* queue, int current){ | 
					 | 
					 | 
					 | 
					int queue_next(AVPacketQueue *queue, int current) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return (current+1) % queue->size; | 
					 | 
					 | 
					 | 
					    return (current + 1) % queue->size; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					void* queue_push(AVPacketQueue* queue, pthread_mutex_t* mutex, pthread_cond_t* cond){ | 
					 | 
					 | 
					 | 
					void *queue_push(AVPacketQueue *queue, pthread_mutex_t *mutex, pthread_cond_t *cond) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    int current = queue->next_to_write; | 
					 | 
					 | 
					 | 
					    int current = queue->next_to_write; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    int next_to_write; | 
					 | 
					 | 
					 | 
					    int next_to_write; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for(;;){ | 
					 | 
					 | 
					 | 
					    for (;;) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        next_to_write = queue_next(queue, current); | 
					 | 
					 | 
					 | 
					        next_to_write = queue_next(queue, current); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //写的不等于读的,跳出循环
 | 
					 | 
					 | 
					 | 
					        if (next_to_write != queue->next_to_read) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if(next_to_write != queue->next_to_read){ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            break; | 
					 | 
					 | 
					 | 
					            break; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        pthread_cond_wait(cond, mutex); | 
					 | 
					 | 
					 | 
					        pthread_cond_wait(cond, mutex); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -48,11 +47,10 @@ void* queue_push(AVPacketQueue* queue, pthread_mutex_t* mutex, pthread_cond_t* c | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return queue->packets[current]; | 
					 | 
					 | 
					 | 
					    return queue->packets[current]; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					void* queue_pop(AVPacketQueue* queue, pthread_mutex_t* mutex, pthread_cond_t* cond){ | 
					 | 
					 | 
					 | 
					void *queue_pop(AVPacketQueue *queue, pthread_mutex_t *mutex, pthread_cond_t *cond) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    int current = queue->next_to_read; | 
					 | 
					 | 
					 | 
					    int current = queue->next_to_read; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for(;;){ | 
					 | 
					 | 
					 | 
					    for (;;) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //写的不等于读的,跳出循环
 | 
					 | 
					 | 
					 | 
					        if (queue->next_to_write != queue->next_to_read) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if(queue->next_to_write != queue->next_to_read){ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            break; | 
					 | 
					 | 
					 | 
					            break; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        pthread_cond_wait(cond, mutex); | 
					 | 
					 | 
					 | 
					        pthread_cond_wait(cond, mutex); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |