CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/HW/MediaEngine.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.16171819// Simulation of the hardware video/audio decoders.20// The idea is high level emulation where we simply use FFMPEG.2122#pragma once2324// An approximation of what the interface will look like. Similar to JPCSP's.2526#include <map>27#include "Common/CommonTypes.h"28#include "Core/HLE/sceMpeg.h"29#include "Core/HW/MpegDemux.h"30#include "Core/HW/SimpleAudioDec.h"3132class PointerWrap;33class AudioDecoder;3435#ifdef USE_FFMPEG36struct SwsContext;37struct AVFrame;38struct AVIOContext;39struct AVFormatContext;40struct AVCodecContext;41#endif4243inline s64 getMpegTimeStamp(const u8 *buf) {44return (s64)buf[5] | ((s64)buf[4] << 8) | ((s64)buf[3] << 16) | ((s64)buf[2] << 24)45| ((s64)buf[1] << 32) | ((s64)buf[0] << 36);46}4748#ifdef USE_FFMPEG49bool InitFFmpeg();50#endif5152class MediaEngine {53public:54MediaEngine();55~MediaEngine();5657void closeMedia();58bool loadStream(const u8 *buffer, int readSize, int RingbufferSize);59bool reloadStream();60bool addVideoStream(int streamNum, int streamId = -1);61// open the mpeg context62bool openContext(bool keepReadPos = false);63void closeContext();6465// Returns number of packets actually added. I guess the buffer might be full.66int addStreamData(const u8 *buffer, int addSize);67bool seekTo(s64 timestamp, int videoPixelMode);6869bool setVideoStream(int streamNum, bool force = false);70// TODO: Return false if the stream doesn't exist.71bool setAudioStream(int streamNum) { m_audioStream = streamNum; return true; }7273u8 *getFrameImage();74int getRemainSize();75int getAudioRemainSize();7677bool stepVideo(int videoPixelMode, bool skipFrame = false);78int writeVideoImage(u32 bufferPtr, int frameWidth = 512, int videoPixelMode = 3);79int writeVideoImageWithRange(u32 bufferPtr, int frameWidth, int videoPixelMode,80int xpos, int ypos, int width, int height);81int getAudioSamples(u32 bufferPtr);8283s64 getVideoTimeStamp();84s64 getAudioTimeStamp();85s64 getLastTimeStamp();8687bool IsVideoEnd() { return m_isVideoEnd; }88bool IsNoAudioData();89bool IsActuallyPlayingAudio();90int VideoWidth() { return m_desWidth; }91int VideoHeight() { return m_desHeight; }9293void DoState(PointerWrap &p);9495private:96bool SetupStreams();97bool setVideoDim(int width = 0, int height = 0);98void updateSwsFormat(int videoPixelMode);99int getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2);100101static int MpegReadbuffer(void *opaque, uint8_t *buf, int buf_size);102103public: // TODO: Very little of this below should be public.104105#ifdef USE_FFMPEG106std::map<int, AVCodecContext *> m_pCodecCtxs;107AVFrame *m_pFrame = nullptr;108AVFrame *m_pFrameRGB = nullptr;109#endif110111u8 *m_buffer = nullptr;112113int m_desWidth = 0;114int m_desHeight = 0;115int m_bufSize;116s64 m_videopts = 0;117118s64 m_firstTimeStamp = 0;119s64 m_lastTimeStamp = 0;120121bool m_isVideoEnd = false;122123private:124#ifdef USE_FFMPEG125// Video ffmpeg context - not used for audio126AVFormatContext *m_pFormatCtx = nullptr;127std::vector<AVCodecContext *> m_codecsToClose;128AVIOContext *m_pIOContext = nullptr;129SwsContext *m_sws_ctx = nullptr;130#endif131132int m_sws_fmt = 0;133int m_videoStream = -1;134int m_expectedVideoStreams = 0;135136// Used by the demuxer.137int m_audioStream = -1;138139int m_decodingsize = 0;140BufferQueue *m_pdata = nullptr;141142s64 m_lastPts = -1;143144MpegDemux *m_demux = nullptr;145AudioDecoder *m_audioContext = nullptr;146s64 m_audiopts = 0;147148// used for audio type149int m_audioType;150151int m_ringbuffersize;152153u8 m_mpegheader[0x10000]; // TODO: Allocate separately154int m_mpegheaderReadPos = 0;155int m_mpegheaderSize = 0;156};157158159