冉冉说
创建一个VideoPicture结构体用来保存解码出来12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091/* * SDL_Lesson.c * * Created on: Aug 12, 2014 * Author: clarck */#include <jni.h>#include <android/native_window_jni.h>#include "SDL.h"#include "SDL_thread.h"#include "SDL_events.h"#include "../include/logger.h"#include "../ffmpeg/includebavcodec/avcodec.h"#include "../ffmpeg/includebavformat/avformat.h"#include "../ffmpeg/includebavutil/pixfmt.h"#include "../ffmpeg/includebswscale/swscale.h"#include "../ffmpeg/includebswresample/swresample.h" #define SDL_AUDIO_BUFFER_SIZE 1024 #define MAX_AUDIO_SIZE (5 * 16 * 1024)#define MAX_VIDEO_SIZE (5 * 256 * 1024) #define FF_ALLOC_EVENT (SDL_USEREVENT)#define FF_REFRESH_EVENT (SDL_USEREVENT + 1)#define FF_QUIT_EVENT (SDL_USEREVENT + 2) #define VIDEO_PICTURE_QUEUE_SIZE 1#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio typedef struct PacketQueue { AVPacketList *first_pkt, *last_pkt; int nb_packets; int size; SDL_mutex *mutex; SDL_cond *cond;} PacketQueue; typedef struct VideoPicture { SDL_Window *screen; SDL_Renderer *renderer; SDL_Texture *bmp; AVFrame* rawdata; int width, height; /*source height & width*/ int allocated;} VideoPicture; typedef struct VideoState { char filename[1024]; AVFormatContext *ic; int videoStream, audioStream; AVStream *audio_st; AVFrame *audio_frame; PacketQueue audioq; unsigned int audio_buf_size; unsigned int audio_buf_index; AVPacket audio_pkt; uint8_t *audio_pkt_data; int audio_pkt_size; uint8_t *audio_buf; DECLARE_ALIGNED(16,uint8_t,audio_buf2) [AVCODEC_MAX_AUDIO_FRAME_SIZE * 4]; enum AVSampleFormat audio_src_fmt; enum AVSampleFormat audio_tgt_fmt; int audio_src_channels; int audio_tgt_channels; int64_t audio_src_channel_layout; int64_t audio_tgt_channel_layout; int audio_src_freq; int audio_tgt_freq; struct SwrContext *swr_ctx; AVStream *video_st; PacketQueue videoq; VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; int pictq_size, pictq_rindex, pictq_windex; SDL_mutex *pictq_mutex; SDL_cond *pictq_cond; SDL_Thread *parse_tid; SDL_Thread *audio_tid; SDL_Thread *video_tid; AVIOContext *io_ctx; struct SwsContext *sws_ctx; int quit;} VideoState; VideoState *global_video_state;