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.
25 // An approximation of what the interface will look like. Similar to JPCSP's.
28 #include "Common/CommonTypes.h"
29 #include "Core/HLE/sceMpeg.h"
30 #include "Core/HW/MpegDemux.h"
31 #include "Core/HW/SimpleAudioDec.h"
40 struct AVFormatContext
;
41 struct AVCodecContext
;
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);
60 bool loadStream(const u8
*buffer
, int readSize
, int RingbufferSize
);
62 // open the mpeg context
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; }
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
; }
91 int VideoWidth() { return m_desWidth
; }
92 int VideoHeight() { return m_desHeight
; }
94 void DoState(PointerWrap
&p
);
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
104 AVFormatContext
*m_pFormatCtx
;
105 std::map
<int, AVCodecContext
*> m_pCodecCtxs
;
107 AVFrame
*m_pFrameRGB
;
108 AVIOContext
*m_pIOContext
;
109 SwsContext
*m_sws_ctx
;
116 // Used by the demuxer.
124 BufferQueue
*m_pdata
;
127 SimpleAudio
*m_audioContext
;
130 s64 m_firstTimeStamp
;
135 int m_ringbuffersize
;
136 u8 m_mpegheader
[0x10000]; // TODO: Allocate separately
137 int m_mpegheaderReadPos
;
139 // used for audio type