From 928e5f315a401dc7a3b010c75f6763c982d8a3b5 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Sun, 29 Aug 2021 22:47:55 +0800 Subject: [PATCH] move the struct of block to queue --- app/src/main/cpp/visualizer/block_queue.c | 6 +++--- app/src/main/cpp/visualizer/block_queue.h | 17 +++++++++++++++++ app/src/main/cpp/visualizer/execute_fft.c | 3 +-- app/src/main/cpp/visualizer/execute_fft.h | 20 -------------------- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/app/src/main/cpp/visualizer/block_queue.c b/app/src/main/cpp/visualizer/block_queue.c index 6edc3cc..ef730db 100644 --- a/app/src/main/cpp/visualizer/block_queue.c +++ b/app/src/main/cpp/visualizer/block_queue.c @@ -3,8 +3,6 @@ // #include "block_queue.h" #include -#include - vlc_queue_t *vlc_queue_init(int size) { vlc_queue_t *queue = (vlc_queue_t *)(malloc(sizeof(vlc_queue_t))); @@ -14,7 +12,9 @@ vlc_queue_t *vlc_queue_init(int size) { int i; queue->packets = (void **)(malloc(sizeof(*queue->packets) * size)); for (i = 0; i < size; i++) { - queue->packets[i] = malloc(sizeof(AVPacket)); + block_t *packet = malloc(sizeof(block_t)); + packet->i_nb_samples = 0; + queue->packets[i] = packet; } pthread_mutex_init(&queue->mutex, NULL); pthread_cond_init(&queue->cond, NULL); diff --git a/app/src/main/cpp/visualizer/block_queue.h b/app/src/main/cpp/visualizer/block_queue.h index 3f8c2b0..aaa98cf 100644 --- a/app/src/main/cpp/visualizer/block_queue.h +++ b/app/src/main/cpp/visualizer/block_queue.h @@ -11,6 +11,23 @@ extern "C" { #endif +typedef int64_t vlc_tick_t; + +typedef struct FFT_callback { + void (*callback)(void*); +} FFT_callback; + +typedef struct block_t { + uint8_t *p_buffer; /** Payload start */ + + unsigned i_nb_samples; /** Used for audio */ + + vlc_tick_t i_pts; + vlc_tick_t i_length; + + FFT_callback fft_callback; +} block_t; + typedef struct vlc_queue { //the size of queue int size; diff --git a/app/src/main/cpp/visualizer/execute_fft.c b/app/src/main/cpp/visualizer/execute_fft.c index 811d20b..4ef3491 100644 --- a/app/src/main/cpp/visualizer/execute_fft.c +++ b/app/src/main/cpp/visualizer/execute_fft.c @@ -46,8 +46,7 @@ /*static*/ block_t *filter_audio(filter_sys_t *p_sys, block_t *p_in_buf) { - vlc_queue_push(&p_sys->queue, p_in_buf); - return p_in_buf; + return vlc_queue_push(&p_sys->queue, p_in_buf); } /*static*/ void close_visualizer(filter_sys_t *p_filter) diff --git a/app/src/main/cpp/visualizer/execute_fft.h b/app/src/main/cpp/visualizer/execute_fft.h index ae1eaec..400c8f7 100644 --- a/app/src/main/cpp/visualizer/execute_fft.h +++ b/app/src/main/cpp/visualizer/execute_fft.h @@ -19,26 +19,6 @@ /** Not enough memory */ #define VLC_ENOMEM (-2) -typedef int64_t vlc_tick_t; - -typedef struct block_t block_t; - -typedef struct FFT_callback { - void (*callback)(void*); -} FFT_callback; - -struct block_t -{ - uint8_t *p_buffer; /**< Payload start */ - - unsigned i_nb_samples; /* Used for audio */ - - vlc_tick_t i_pts; - vlc_tick_t i_length; - - FFT_callback fft_callback; -}; - typedef struct { pthread_t thread;