rpcsx/rpcs3/Emu/SysCalls/Modules/cellDmux.h

506 lines
8.5 KiB
C
Raw Normal View History

2014-01-19 11:52:30 +01:00
#pragma once
2014-02-24 01:00:42 +01:00
#include "Utilities/SQueue.h"
// align size or address to 128
#define a128(x) ((x + 127) & (~127))
2014-01-19 11:52:30 +01:00
// Error Codes
enum
{
CELL_DMUX_ERROR_ARG = 0x80610201,
CELL_DMUX_ERROR_SEQ = 0x80610202,
CELL_DMUX_ERROR_BUSY = 0x80610203,
CELL_DMUX_ERROR_EMPTY = 0x80610204,
CELL_DMUX_ERROR_FATAL = 0x80610205,
2014-01-19 11:52:30 +01:00
};
enum CellDmuxStreamType
{
CELL_DMUX_STREAM_TYPE_UNDEF = 0,
CELL_DMUX_STREAM_TYPE_PAMF = 1,
CELL_DMUX_STREAM_TYPE_TERMINATOR = 2,
};
enum CellDmuxMsgType
{
CELL_DMUX_MSG_TYPE_DEMUX_DONE = 0,
CELL_DMUX_MSG_TYPE_FATAL_ERR = 1,
CELL_DMUX_MSG_TYPE_PROG_END_CODE = 2,
};
enum CellDmuxEsMsgType
{
CELL_DMUX_ES_MSG_TYPE_AU_FOUND = 0,
CELL_DMUX_ES_MSG_TYPE_FLUSH_DONE = 1,
};
2014-02-24 01:00:42 +01:00
enum CellDmuxPamfM2vLevel
{
CELL_DMUX_PAMF_M2V_MP_LL = 0,
CELL_DMUX_PAMF_M2V_MP_ML,
CELL_DMUX_PAMF_M2V_MP_H14,
CELL_DMUX_PAMF_M2V_MP_HL,
};
enum CellDmuxPamfAvcLevel
{
CELL_DMUX_PAMF_AVC_LEVEL_2P1 = 21,
CELL_DMUX_PAMF_AVC_LEVEL_3P0 = 30,
CELL_DMUX_PAMF_AVC_LEVEL_3P1 = 31,
CELL_DMUX_PAMF_AVC_LEVEL_3P2 = 32,
CELL_DMUX_PAMF_AVC_LEVEL_4P1 = 41,
CELL_DMUX_PAMF_AVC_LEVEL_4P2 = 42,
};
struct CellDmuxPamfAuSpecificInfoM2v
{
be_t<u32> reserved1;
};
struct CellDmuxPamfAuSpecificInfoAvc
{
be_t<u32> reserved1;
};
struct CellDmuxPamfAuSpecificInfoLpcm
{
u8 channelAssignmentInfo;
u8 samplingFreqInfo;
u8 bitsPerSample;
};
struct CellDmuxPamfAuSpecificInfoAc3
{
be_t<u32> reserved1;
};
struct CellDmuxPamfAuSpecificInfoAtrac3plus
{
be_t<u32> reserved1;
};
struct CellDmuxPamfAuSpecificInfoUserData
{
be_t<u32> reserved1;
};
struct CellDmuxPamfEsSpecificInfoM2v
{
be_t<u32> profileLevel;
};
struct CellDmuxPamfEsSpecificInfoAvc
{
be_t<u32> level;
};
struct CellDmuxPamfEsSpecificInfoLpcm
{
be_t<u32> samplingFreq;
be_t<u32> numOfChannels;
be_t<u32> bitsPerSample;
};
struct CellDmuxPamfEsSpecificInfoAc3
{
be_t<u32> reserved1;
};
struct CellDmuxPamfEsSpecificInfoAtrac3plus
{
be_t<u32> reserved1;
};
struct CellDmuxPamfEsSpecificInfoUserData
{
be_t<u32> reserved1;
};
enum CellDmuxPamfSamplingFrequency
{
CELL_DMUX_PAMF_FS_48K = 48000,
};
enum CellDmuxPamfBitsPerSample
{
CELL_DMUX_PAMF_BITS_PER_SAMPLE_16 = 16,
CELL_DMUX_PAMF_BITS_PER_SAMPLE_24 = 24,
};
enum CellDmuxPamfLpcmChannelAssignmentInfo
{
CELL_DMUX_PAMF_LPCM_CH_M1 = 1,
CELL_DMUX_PAMF_LPCM_CH_LR = 3,
CELL_DMUX_PAMF_LPCM_CH_LRCLSRSLFE = 9,
CELL_DMUX_PAMF_LPCM_CH_LRCLSCS1CS2RSLFE = 11,
};
enum CellDmuxPamfLpcmFs
{
CELL_DMUX_PAMF_LPCM_FS_48K = 1,
};
enum CellDmuxPamfLpcmBitsPerSamples
{
CELL_DMUX_PAMF_LPCM_BITS_PER_SAMPLE_16 = 1,
CELL_DMUX_PAMF_LPCM_BITS_PER_SAMPLE_24 = 3,
};
2014-01-19 11:52:30 +01:00
struct CellDmuxMsg
{
be_t<CellDmuxMsgType> msgType; //CellDmuxMsgType enum
be_t<u64> supplementalInfo;
};
struct CellDmuxEsMsg
{
be_t<CellDmuxEsMsgType> msgType; //CellDmuxEsMsgType enum
be_t<u64> supplementalInfo;
};
struct CellDmuxType
{
2014-02-24 01:00:42 +01:00
be_t<CellDmuxStreamType> streamType;
2014-01-19 11:52:30 +01:00
be_t<u32> reserved[2]; //0
};
2014-02-24 01:00:42 +01:00
struct CellDmuxPamfSpecificInfo
{
be_t<u32> thisSize;
bool programEndCodeCb;
};
2014-01-19 11:52:30 +01:00
struct CellDmuxType2
{
2014-02-24 01:00:42 +01:00
be_t<CellDmuxStreamType> streamType;
2014-01-19 11:52:30 +01:00
be_t<u32> streamSpecificInfo_addr;
};
struct CellDmuxResource
{
be_t<u32> memAddr;
be_t<u32> memSize;
be_t<u32> ppuThreadPriority;
be_t<u32> ppuThreadStackSize;
be_t<u32> spuThreadPriority;
be_t<u32> numOfSpus;
};
struct CellDmuxResourceEx
{
be_t<u32> memAddr;
be_t<u32> memSize;
be_t<u32> ppuThreadPriority;
be_t<u32> ppuThreadStackSize;
be_t<u32> spurs_addr;
u8 priority[8];
be_t<u32> maxContention;
};
2014-01-19 22:19:37 +01:00
/*
2014-01-19 11:52:30 +01:00
struct CellDmuxResource2Ex
{
bool isResourceEx; //true
CellDmuxResourceEx resourceEx;
};
struct CellDmuxResource2NoEx
{
bool isResourceEx; //false
CellDmuxResource resource;
};
2014-01-19 22:19:37 +01:00
*/
struct CellDmuxResource2
{
bool isResourceEx;
be_t<u32> memAddr;
be_t<u32> memSize;
be_t<u32> ppuThreadPriority;
be_t<u32> ppuThreadStackSize;
be_t<u32> shit[4];
2014-01-19 22:19:37 +01:00
};
2014-01-19 11:52:30 +01:00
2014-09-01 14:47:26 +02:00
typedef u32(*CellDmuxCbMsg)(u32 demuxerHandle, vm::ptr<CellDmuxMsg> demuxerMsg, u32 cbArg_addr);
2014-02-24 01:00:42 +01:00
2014-01-19 11:52:30 +01:00
struct CellDmuxCb
{
// CellDmuxCbMsg callback
2014-02-24 01:00:42 +01:00
be_t<u32> cbMsgFunc;
2014-01-19 11:52:30 +01:00
be_t<u32> cbArg_addr;
};
2014-09-01 14:47:26 +02:00
typedef u32(*CellDmuxCbEsMsg)(u32 demuxerHandle, u32 esHandle, vm::ptr<CellDmuxEsMsg> esMsg, u32 cbArg_addr);
2014-02-24 01:00:42 +01:00
2014-01-19 11:52:30 +01:00
struct CellDmuxEsCb
{
// CellDmuxCbEsMsg callback
2014-02-24 01:00:42 +01:00
be_t<u32> cbEsMsgFunc;
2014-01-19 11:52:30 +01:00
be_t<u32> cbArg_addr;
};
struct CellDmuxAttr
{
be_t<u32> memSize;
be_t<u32> demuxerVerUpper;
be_t<u32> demuxerVerLower;
};
struct CellDmuxEsAttr
{
be_t<u32> memSize;
};
struct CellDmuxEsResource
{
be_t<u32> memAddr;
be_t<u32> memSize;
2014-01-19 11:52:30 +01:00
};
struct CellDmuxAuInfo
{
be_t<u32> auAddr;
be_t<u32> auSize;
be_t<u32> auMaxSize;
be_t<u64> userData;
2014-01-19 11:52:30 +01:00
be_t<u32> ptsUpper;
be_t<u32> ptsLower;
be_t<u32> dtsUpper;
be_t<u32> dtsLower;
};
struct CellDmuxAuInfoEx
{
be_t<u32> auAddr;
be_t<u32> auSize;
be_t<u32> reserved;
2014-01-23 19:40:49 +01:00
bool isRap;
2014-01-19 11:52:30 +01:00
be_t<u64> userData;
2014-01-23 19:40:49 +01:00
CellCodecTimeStamp pts;
CellCodecTimeStamp dts;
2014-02-24 01:00:42 +01:00
};
/* Demuxer Thread Classes */
enum
{
/* http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html */
PACKET_START_CODE_MASK = 0xffffff00,
PACKET_START_CODE_PREFIX = 0x00000100,
USER_DATA_START_CODE = 0x000001b2,
SEQUENCE_START_CODE = 0x000001b3,
EXT_START_CODE = 0x000001b5,
SEQUENCE_END_CODE = 0x000001b7,
GOP_START_CODE = 0x000001b8,
ISO_11172_END_CODE = 0x000001b9,
PACK_START_CODE = 0x000001ba,
SYSTEM_HEADER_START_CODE = 0x000001bb,
PROGRAM_STREAM_MAP = 0x000001bc,
PRIVATE_STREAM_1 = 0x000001bd,
PADDING_STREAM = 0x000001be,
PRIVATE_STREAM_2 = 0x000001bf,
};
struct DemuxerStream
2014-02-24 01:00:42 +01:00
{
u32 addr;
u32 size;
u64 userdata;
bool discontinuity;
template<typename T>
bool get(T& out)
{
if (sizeof(T) > size) return false;
out = vm::get_ref<T>(addr);
addr += sizeof(T);
size -= sizeof(T);
return true;
}
template<typename T>
bool peek(T& out, u32 shift = 0)
{
if (sizeof(T) + shift > size) return false;
out = vm::get_ref<T>(addr + shift);
return true;
}
void skip(u32 count)
{
addr += count;
size = size > count ? size - count : 0;
}
2014-02-27 19:25:32 +01:00
u64 get_ts(u8 c)
{
2014-02-27 19:25:32 +01:00
u8 v[4]; get((u32&)v);
return
(((u64)c & 0x0e) << 29) |
(((u64)v[0]) << 21) |
(((u64)v[1] & 0x7e) << 15) |
(((u64)v[2]) << 7) | ((u64)v[3] >> 1);
}
2014-02-27 19:25:32 +01:00
u64 get_ts()
{
u8 v; get(v);
return get_ts(v);
}
};
struct PesHeader
{
2014-02-27 19:25:32 +01:00
u64 pts;
u64 dts;
u8 size;
2014-03-01 09:38:50 +01:00
bool new_au;
2014-08-23 22:40:04 +02:00
PesHeader(DemuxerStream& stream);
2014-02-24 01:00:42 +01:00
};
class ElementaryStream;
enum DemuxerJobType
{
dmuxSetStream,
dmuxResetStream,
dmuxResetStreamAndWaitDone,
2014-02-24 01:00:42 +01:00
dmuxEnableEs,
dmuxDisableEs,
dmuxResetEs,
dmuxFlushEs,
dmuxClose,
};
struct DemuxerTask
{
DemuxerJobType type;
union
{
DemuxerStream stream;
2014-02-24 01:00:42 +01:00
struct
{
u32 es;
u32 auInfo_ptr_addr;
u32 auSpec_ptr_addr;
ElementaryStream* es_ptr;
} es;
2014-02-24 01:00:42 +01:00
};
DemuxerTask()
{
}
DemuxerTask(DemuxerJobType type)
: type(type)
{
}
};
class Demuxer
{
public:
2014-03-13 10:17:45 +01:00
SQueue<DemuxerTask, 32> job;
SQueue<u32, 16> fbSetStream;
2014-02-24 01:00:42 +01:00
const u32 memAddr;
const u32 memSize;
const u32 cbFunc;
2014-02-24 01:00:42 +01:00
const u32 cbArg;
u32 id;
2014-03-01 09:38:50 +01:00
volatile bool is_finished;
volatile bool is_running;
2014-02-24 01:00:42 +01:00
CPUThread* dmuxCb;
2014-02-24 01:00:42 +01:00
Demuxer(u32 addr, u32 size, u32 func, u32 arg)
2014-02-24 01:00:42 +01:00
: is_finished(false)
, is_running(false)
2014-02-24 01:00:42 +01:00
, memAddr(addr)
, memSize(size)
, cbFunc(func)
, cbArg(arg)
, dmuxCb(nullptr)
2014-02-24 01:00:42 +01:00
{
}
};
class ElementaryStream
{
std::mutex m_mutex;
2014-03-22 02:08:25 +01:00
SQueue<u32> entries; // AU starting addresses
u32 put_count; // number of AU written
u32 released; // number of AU released
u32 peek_count; // number of AU obtained by GetAu(Ex)
u32 put; // AU that is being written now
u32 size; // number of bytes written (after 128b header)
//u32 first; // AU that will be released
//u32 peek; // AU that will be obtained by GetAu(Ex)/PeekAu(Ex)
2014-03-13 10:17:45 +01:00
2014-08-23 22:40:04 +02:00
bool is_full();
2014-02-24 01:00:42 +01:00
public:
Demuxer* dmux;
u32 id;
2014-02-24 01:00:42 +01:00
const u32 memAddr;
const u32 memSize;
const u32 fidMajor;
const u32 fidMinor;
const u32 sup1;
const u32 sup2;
const u32 cbFunc;
2014-02-24 01:00:42 +01:00
const u32 cbArg;
const u32 spec; //addr
ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMajor, u32 fidMinor, u32 sup1, u32 sup2, u32 cbFunc, u32 cbArg, u32 spec)
2014-02-24 01:00:42 +01:00
: dmux(dmux)
, memAddr(a128(addr))
, memSize(size - (addr - memAddr))
2014-02-24 01:00:42 +01:00
, fidMajor(fidMajor)
, fidMinor(fidMinor)
, sup1(sup1)
, sup2(sup2)
, cbFunc(cbFunc)
, cbArg(cbArg)
, spec(spec)
2014-03-22 02:08:25 +01:00
//, first(0)
//, peek(0)
, put(memAddr)
, size(0)
, put_count(0)
, released(0)
, peek_count(0)
{
}
2014-08-23 22:40:04 +02:00
const u32 GetMaxAU() const;
2014-03-07 22:31:08 +01:00
2014-08-23 22:40:04 +02:00
u32 freespace();
2014-03-22 02:08:25 +01:00
2014-08-23 22:40:04 +02:00
bool hasunseen();
2014-03-07 22:31:08 +01:00
2014-08-23 22:40:04 +02:00
bool hasdata();
2014-03-07 22:31:08 +01:00
2014-08-23 22:40:04 +02:00
bool isfull();
2014-03-22 02:08:25 +01:00
2014-08-23 22:40:04 +02:00
void finish(DemuxerStream& stream);
2014-03-07 22:31:08 +01:00
2014-08-23 22:40:04 +02:00
void push(DemuxerStream& stream, u32 sz, PesHeader& pes);
2014-08-23 22:40:04 +02:00
bool release();
2014-08-23 22:40:04 +02:00
bool peek(u32& out_data, bool no_ex, u32& out_spec, bool update_index);
2014-08-23 22:40:04 +02:00
void reset();
2014-02-26 12:27:06 +01:00
};