Merge pull request #90 from gizmo98/patch-2
[libretro-ppsspp.git] / Core / HW / MediaEngine.h
blobc384fafb8e5873e88843838dbdffb675267d4aea
1 // Copyright (c) 2012- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
20 // Simulation of the hardware video/audio decoders.
21 // The idea is high level emulation where we simply use FFMPEG.
23 #pragma once
25 // An approximation of what the interface will look like. Similar to JPCSP's.
27 #include <map>
28 #include "Common/CommonTypes.h"
29 #include "Core/HLE/sceMpeg.h"
30 #include "Core/HW/MpegDemux.h"
31 #include "Core/HW/SimpleAudioDec.h"
33 class PointerWrap;
34 class SimpleAudio;
36 #ifdef USE_FFMPEG
37 struct SwsContext;
38 struct AVFrame;
39 struct AVIOContext;
40 struct AVFormatContext;
41 struct AVCodecContext;
42 #endif
44 inline s64 getMpegTimeStamp(const u8 *buf) {
45 return (s64)buf[5] | ((s64)buf[4] << 8) | ((s64)buf[3] << 16) | ((s64)buf[2] << 24)
46 | ((s64)buf[1] << 32) | ((s64)buf[0] << 36);
49 #ifdef USE_FFMPEG
50 bool InitFFmpeg();
51 #endif
53 class MediaEngine
55 public:
56 MediaEngine();
57 ~MediaEngine();
59 void closeMedia();
60 bool loadStream(const u8 *buffer, int readSize, int RingbufferSize);
61 bool reloadStream();
62 // open the mpeg context
63 bool openContext();
64 void closeContext();
66 // Returns number of packets actually added. I guess the buffer might be full.
67 int addStreamData(const u8 *buffer, int addSize);
68 bool seekTo(s64 timestamp, int videoPixelMode);
70 bool setVideoStream(int streamNum, bool force = false);
71 // TODO: Return false if the stream doesn't exist.
72 bool setAudioStream(int streamNum) { m_audioStream = streamNum; return true; }
74 u8 *getFrameImage();
75 int getRemainSize();
76 int getAudioRemainSize();
78 bool stepVideo(int videoPixelMode, bool skipFrame = false);
79 int writeVideoImage(u32 bufferPtr, int frameWidth = 512, int videoPixelMode = 3);
80 int writeVideoImageWithRange(u32 bufferPtr, int frameWidth, int videoPixelMode,
81 int xpos, int ypos, int width, int height);
82 int getAudioSamples(u32 bufferPtr);
84 bool setVideoDim(int width = 0, int height = 0);
85 s64 getVideoTimeStamp();
86 s64 getAudioTimeStamp();
87 s64 getLastTimeStamp();
89 bool IsVideoEnd() { return m_isVideoEnd; }
90 bool IsNoAudioData();
91 int VideoWidth() { return m_desWidth; }
92 int VideoHeight() { return m_desHeight; }
94 void DoState(PointerWrap &p);
96 private:
97 void updateSwsFormat(int videoPixelMode);
98 int getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2);
100 public: // TODO: Very little of this below should be public.
102 // Video ffmpeg context - not used for audio
103 #ifdef USE_FFMPEG
104 AVFormatContext *m_pFormatCtx;
105 std::map<int, AVCodecContext *> m_pCodecCtxs;
106 AVFrame *m_pFrame;
107 AVFrame *m_pFrameRGB;
108 AVIOContext *m_pIOContext;
109 SwsContext *m_sws_ctx;
110 #endif
112 int m_sws_fmt;
113 u8 *m_buffer;
114 int m_videoStream;
116 // Used by the demuxer.
117 int m_audioStream;
119 int m_desWidth;
120 int m_desHeight;
121 int m_decodingsize;
122 int m_bufSize;
123 s64 m_videopts;
124 BufferQueue *m_pdata;
126 MpegDemux *m_demux;
127 SimpleAudio *m_audioContext;
128 s64 m_audiopts;
130 s64 m_firstTimeStamp;
131 s64 m_lastTimeStamp;
133 bool m_isVideoEnd;
135 int m_ringbuffersize;
136 u8 m_mpegheader[0x10000]; // TODO: Allocate separately
137 int m_mpegheaderReadPos;
139 // used for audio type
140 int m_audioType;