forked from lmshao/Media-Player
/
Core.h
75 lines (53 loc) · 1.4 KB
/
Core.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// Created by Liming Shao on 2018/7/8.
//
#ifndef MEDIA_PLAYER_CORE_H
#define MEDIA_PLAYER_CORE_H
#include "SDL2/SDL.h"
#include "SDL2/SDL_thread.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
}
class SDL_Env{
public:
SDL_Env() : window(nullptr), renderer(nullptr), texture(nullptr), rectangle(nullptr) {
rectangle = new SDL_Rect;
};
virtual ~SDL_Env() {
delete rectangle;
}
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Rect *rectangle;
};
class Core {
public:
Core();
virtual ~Core();
bool openMediaFile(const char* file);
bool preprocessStream();
AVCodecContext* openCodecContext(int index);
bool initSDL();
bool playMedia();
void cleanUp();
private:
bool allocImage(AVFrame *image);
void displayImage(AVFrame *data);
static int decodeAudioPacket();
static void sdlAudioCallback(void *userdata, Uint8 *stream, int len);
AVFormatContext *mFormatCtx;
SDL_Env *mSDLEnv;
struct CodecInfo{
CodecInfo(int index, AVCodecContext *codec):
index(index), codec(codec) {}
int index;
AVCodecContext *codec;
};
CodecInfo *mAudioInfo, *mVideoInfo;
};
#endif //MEDIA_PLAYER_CORE_H