From 08a7bc7464d0952abe31cf44ccb67a035c1f5479 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Tue, 14 Apr 2020 00:25:29 +0800 Subject: [PATCH] translate packet_queue.c into English translate packet_queue.c into English --- app/src/main/cpp/AVpacket_queue.c | 28 +++++++++++++--------------- app/src/main/cpp/AVpacket_queue.h | 24 ++++++++++++++---------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/src/main/cpp/AVpacket_queue.c b/app/src/main/cpp/AVpacket_queue.c index 3ed1f0e..74d9627 100644 --- a/app/src/main/cpp/AVpacket_queue.c +++ b/app/src/main/cpp/AVpacket_queue.c @@ -6,39 +6,38 @@ #include -AVPacketQueue* queue_init(int size){ - AVPacketQueue* queue = malloc(sizeof(AVPacketQueue)); +AVPacketQueue *queue_init(int size) { + AVPacketQueue *queue = malloc(sizeof(AVPacketQueue)); queue->size = size; queue->next_to_read = 0; queue->next_to_write = 0; int i; 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)); } return queue; } -void queue_free(AVPacketQueue *queue){ +void queue_free(AVPacketQueue *queue) { int i; - for(i=0; isize; i++){ + for (i = 0; i < queue->size; i++) { free(queue->packets[i]); } free(queue->packets); free(queue); } -int queue_next(AVPacketQueue* queue, int current){ - return (current+1) % queue->size; +int queue_next(AVPacketQueue *queue, int current) { + 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 next_to_write; - for(;;){ + for (;;) { next_to_write = queue_next(queue, current); - //写的不等于读的,跳出循环 - if(next_to_write != queue->next_to_read){ + if (next_to_write != queue->next_to_read) { break; } 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]; } -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; - for(;;){ - //写的不等于读的,跳出循环 - if(queue->next_to_write != queue->next_to_read){ + for (;;) { + if (queue->next_to_write != queue->next_to_read) { break; } pthread_cond_wait(cond, mutex); diff --git a/app/src/main/cpp/AVpacket_queue.h b/app/src/main/cpp/AVpacket_queue.h index 3e899f8..1497a7d 100644 --- a/app/src/main/cpp/AVpacket_queue.h +++ b/app/src/main/cpp/AVpacket_queue.h @@ -4,22 +4,26 @@ #ifndef VIDEOPLAYER_AVPACKET_QUEUE_H #define VIDEOPLAYER_AVPACKET_QUEUE_H + #include -typedef struct AVPacketQueue{ - //队列大小 +typedef struct AVPacketQueue { + //the size of queue int size; - //指针数组 - void ** packets; - //下一个写入的packet + //packet array + void **packets; + //the packet next to write int next_to_write; - //下一个读取的packet + //the packet next to read int next_to_read; -}AVPacketQueue; +} AVPacketQueue; + +AVPacketQueue *queue_init(int size); -AVPacketQueue* queue_init(int size); void queue_free(AVPacketQueue *queue); -void* queue_push(AVPacketQueue* queue, pthread_mutex_t* mutex, pthread_cond_t* cond); -void* queue_pop(AVPacketQueue* queue, pthread_mutex_t* mutex, pthread_cond_t* cond); + +void *queue_push(AVPacketQueue *queue, pthread_mutex_t *mutex, pthread_cond_t *cond); + +void *queue_pop(AVPacketQueue *queue, pthread_mutex_t *mutex, pthread_cond_t *cond); #endif //VIDEOPLAYER_AVPACKET_QUEUE_H \ No newline at end of file