2012-11-12 19:53:16 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Simulation of the hardware video/audio decoders.
|
|
|
|
// The idea is high level emulation where we simply use FFMPEG.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// An approximation of what the interface will look like. Similar to JPCSP's.
|
|
|
|
|
2014-01-21 09:16:16 +00:00
|
|
|
#include <map>
|
2013-12-30 09:17:11 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Core/HLE/sceMpeg.h"
|
2013-06-01 17:29:22 +00:00
|
|
|
#include "Core/HW/MpegDemux.h"
|
2014-03-23 18:45:08 +00:00
|
|
|
#include "Core/HW/SimpleAudioDec.h"
|
2012-11-12 19:53:16 +00:00
|
|
|
|
2014-03-15 18:32:57 +00:00
|
|
|
class PointerWrap;
|
2014-06-22 12:01:23 +00:00
|
|
|
class SimpleAudio;
|
2013-10-17 14:00:43 +00:00
|
|
|
|
2013-11-12 07:52:43 +00:00
|
|
|
#ifdef USE_FFMPEG
|
2013-06-02 07:29:45 +00:00
|
|
|
struct SwsContext;
|
2013-06-02 08:37:16 +00:00
|
|
|
struct AVFrame;
|
2013-06-07 06:18:12 +00:00
|
|
|
struct AVIOContext;
|
2013-06-08 07:22:59 +00:00
|
|
|
struct AVFormatContext;
|
|
|
|
struct AVCodecContext;
|
2013-11-12 07:52:43 +00:00
|
|
|
#endif
|
2013-06-02 07:29:45 +00:00
|
|
|
|
2014-05-15 07:05:40 +00:00
|
|
|
inline s64 getMpegTimeStamp(const u8 *buf) {
|
2013-06-09 20:21:36 +00:00
|
|
|
return (s64)buf[5] | ((s64)buf[4] << 8) | ((s64)buf[3] << 16) | ((s64)buf[2] << 24)
|
|
|
|
| ((s64)buf[1] << 32) | ((s64)buf[0] << 36);
|
|
|
|
}
|
|
|
|
|
2013-11-12 07:52:43 +00:00
|
|
|
#ifdef USE_FFMPEG
|
2013-09-16 15:40:38 +00:00
|
|
|
bool InitFFmpeg();
|
2013-11-12 07:52:43 +00:00
|
|
|
#endif
|
2013-09-16 15:40:38 +00:00
|
|
|
|
2012-11-12 19:53:16 +00:00
|
|
|
class MediaEngine
|
|
|
|
{
|
|
|
|
public:
|
2013-06-01 17:29:22 +00:00
|
|
|
MediaEngine();
|
|
|
|
~MediaEngine();
|
|
|
|
|
|
|
|
void closeMedia();
|
2014-05-15 07:05:40 +00:00
|
|
|
bool loadStream(const u8 *buffer, int readSize, int RingbufferSize);
|
2014-08-17 22:46:04 +00:00
|
|
|
bool reloadStream();
|
2020-11-13 10:55:52 +00:00
|
|
|
bool addVideoStream(int streamNum, int streamId = -1);
|
2013-06-11 11:04:14 +00:00
|
|
|
// open the mpeg context
|
2016-06-06 00:54:23 +00:00
|
|
|
bool openContext(bool keepReadPos = false);
|
2014-01-02 04:47:10 +00:00
|
|
|
void closeContext();
|
2013-10-17 10:27:04 +00:00
|
|
|
|
|
|
|
// Returns number of packets actually added. I guess the buffer might be full.
|
2014-05-15 07:05:40 +00:00
|
|
|
int addStreamData(const u8 *buffer, int addSize);
|
2014-05-05 08:24:31 +00:00
|
|
|
bool seekTo(s64 timestamp, int videoPixelMode);
|
2013-06-11 11:04:14 +00:00
|
|
|
|
2014-01-03 17:29:37 +00:00
|
|
|
bool setVideoStream(int streamNum, bool force = false);
|
2014-04-21 06:14:45 +00:00
|
|
|
// TODO: Return false if the stream doesn't exist.
|
|
|
|
bool setAudioStream(int streamNum) { m_audioStream = streamNum; return true; }
|
2013-06-11 11:04:14 +00:00
|
|
|
|
2013-09-18 06:05:09 +00:00
|
|
|
u8 *getFrameImage();
|
2013-06-15 19:27:14 +00:00
|
|
|
int getRemainSize();
|
2014-01-04 09:25:42 +00:00
|
|
|
int getAudioRemainSize();
|
2013-06-01 17:29:22 +00:00
|
|
|
|
2014-05-15 07:28:54 +00:00
|
|
|
bool stepVideo(int videoPixelMode, bool skipFrame = false);
|
2013-12-11 16:21:01 +00:00
|
|
|
int writeVideoImage(u32 bufferPtr, int frameWidth = 512, int videoPixelMode = 3);
|
|
|
|
int writeVideoImageWithRange(u32 bufferPtr, int frameWidth, int videoPixelMode,
|
2013-06-01 17:29:22 +00:00
|
|
|
int xpos, int ypos, int width, int height);
|
2013-12-11 16:21:01 +00:00
|
|
|
int getAudioSamples(u32 bufferPtr);
|
2013-06-01 17:29:22 +00:00
|
|
|
|
|
|
|
s64 getVideoTimeStamp();
|
|
|
|
s64 getAudioTimeStamp();
|
|
|
|
s64 getLastTimeStamp();
|
2012-11-13 17:05:26 +00:00
|
|
|
|
2013-06-08 09:45:58 +00:00
|
|
|
bool IsVideoEnd() { return m_isVideoEnd; }
|
2014-04-26 16:38:13 +00:00
|
|
|
bool IsNoAudioData();
|
2020-02-27 11:21:27 +00:00
|
|
|
bool IsActuallyPlayingAudio();
|
2014-05-24 06:00:01 +00:00
|
|
|
int VideoWidth() { return m_desWidth; }
|
|
|
|
int VideoHeight() { return m_desHeight; }
|
2013-06-04 12:25:03 +00:00
|
|
|
|
2013-06-17 20:08:48 +00:00
|
|
|
void DoState(PointerWrap &p);
|
2012-12-29 11:19:13 +00:00
|
|
|
|
2012-11-12 19:53:16 +00:00
|
|
|
private:
|
2016-06-06 00:54:23 +00:00
|
|
|
bool SetupStreams();
|
|
|
|
bool setVideoDim(int width = 0, int height = 0);
|
2013-06-02 07:29:45 +00:00
|
|
|
void updateSwsFormat(int videoPixelMode);
|
2014-05-05 08:24:31 +00:00
|
|
|
int getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2);
|
2013-06-01 17:29:22 +00:00
|
|
|
|
2013-10-17 10:27:04 +00:00
|
|
|
public: // TODO: Very little of this below should be public.
|
2013-06-01 17:29:22 +00:00
|
|
|
|
2013-10-17 10:27:04 +00:00
|
|
|
// Video ffmpeg context - not used for audio
|
2013-11-12 07:52:43 +00:00
|
|
|
#ifdef USE_FFMPEG
|
2013-06-08 07:22:59 +00:00
|
|
|
AVFormatContext *m_pFormatCtx;
|
2014-01-21 09:16:16 +00:00
|
|
|
std::map<int, AVCodecContext *> m_pCodecCtxs;
|
2013-06-02 08:37:16 +00:00
|
|
|
AVFrame *m_pFrame;
|
|
|
|
AVFrame *m_pFrameRGB;
|
2013-06-07 06:18:12 +00:00
|
|
|
AVIOContext *m_pIOContext;
|
2013-06-02 07:29:45 +00:00
|
|
|
SwsContext *m_sws_ctx;
|
2013-11-12 07:52:43 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-02 09:45:20 +00:00
|
|
|
int m_sws_fmt;
|
2013-06-02 07:29:45 +00:00
|
|
|
u8 *m_buffer;
|
2013-06-11 11:04:14 +00:00
|
|
|
int m_videoStream;
|
2020-11-13 10:55:52 +00:00
|
|
|
int m_expectedVideoStreams;
|
2013-10-17 10:27:04 +00:00
|
|
|
|
|
|
|
// Used by the demuxer.
|
2013-06-11 11:04:14 +00:00
|
|
|
int m_audioStream;
|
2013-06-01 17:29:22 +00:00
|
|
|
|
2013-10-17 10:27:04 +00:00
|
|
|
int m_desWidth;
|
|
|
|
int m_desHeight;
|
2013-06-23 07:36:28 +00:00
|
|
|
int m_decodingsize;
|
2013-06-01 17:29:22 +00:00
|
|
|
int m_bufSize;
|
|
|
|
s64 m_videopts;
|
2013-10-17 10:27:04 +00:00
|
|
|
BufferQueue *m_pdata;
|
|
|
|
|
2013-06-01 17:29:22 +00:00
|
|
|
MpegDemux *m_demux;
|
2014-03-23 18:45:08 +00:00
|
|
|
SimpleAudio *m_audioContext;
|
2013-06-01 17:29:22 +00:00
|
|
|
s64 m_audiopts;
|
2013-06-04 12:25:03 +00:00
|
|
|
|
2013-06-15 19:27:14 +00:00
|
|
|
s64 m_firstTimeStamp;
|
|
|
|
s64 m_lastTimeStamp;
|
|
|
|
|
2013-06-04 12:25:03 +00:00
|
|
|
bool m_isVideoEnd;
|
2013-06-17 20:08:48 +00:00
|
|
|
|
|
|
|
int m_ringbuffersize;
|
2013-10-17 10:27:04 +00:00
|
|
|
u8 m_mpegheader[0x10000]; // TODO: Allocate separately
|
2013-06-17 20:08:48 +00:00
|
|
|
int m_mpegheaderReadPos;
|
2016-06-05 23:22:34 +00:00
|
|
|
int m_mpegheaderSize;
|
2014-03-23 18:45:08 +00:00
|
|
|
|
|
|
|
// used for audio type
|
|
|
|
int m_audioType;
|
2012-11-12 19:53:16 +00:00
|
|
|
};
|