rpcsx/ps3fw/cellDmux.cpp

1385 lines
32 KiB
C++
Raw Normal View History

2020-12-05 13:08:24 +01:00
#include "stdafx.h"
2020-10-30 21:26:22 +01:00
#include "Emu/System.h"
2015-03-06 23:58:42 +01:00
#include "Emu/IdManager.h"
2016-03-21 20:43:03 +01:00
#include "Emu/Cell/PPUModule.h"
#include "cellos/sys_sync.h"
2014-08-23 22:40:04 +02:00
2014-01-19 11:52:30 +01:00
#include "cellPamf.h"
#include "cellDmux.h"
#include "util/asm.hpp"
2016-05-13 15:55:34 +02:00
2025-02-11 03:00:37 +01:00
#include <thread>
LOG_CHANNEL(cellDmux);
2020-07-16 12:14:57 +02:00
template <>
void fmt_class_string<CellDmuxError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellDmuxError value)
{
switch (value)
{
STR_CASE(CELL_DMUX_ERROR_ARG);
STR_CASE(CELL_DMUX_ERROR_SEQ);
STR_CASE(CELL_DMUX_ERROR_BUSY);
STR_CASE(CELL_DMUX_ERROR_EMPTY);
STR_CASE(CELL_DMUX_ERROR_FATAL);
}
2020-07-16 12:14:57 +02:00
return unknown;
});
2020-07-16 12:14:57 +02:00
}
/* Demuxer Thread Classes */
enum
2014-08-23 22:40:04 +02:00
{
/* http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html */
PACKET_START_CODE_MASK = 0xffffff00,
PACKET_START_CODE_PREFIX = 0x00000100,
PACK_START_CODE = 0x000001ba,
SYSTEM_HEADER_START_CODE = 0x000001bb,
PRIVATE_STREAM_1 = 0x000001bd,
PADDING_STREAM = 0x000001be,
PRIVATE_STREAM_2 = 0x000001bf,
};
struct DemuxerStream
{
u32 addr;
u32 size;
u64 userdata;
bool discontinuity;
template <typename T>
bool get(T& out)
2014-12-12 01:21:34 +01:00
{
if (sizeof(T) > size)
return false;
2019-12-01 18:14:58 +01:00
std::memcpy(&out, vm::base(addr), sizeof(T));
addr += sizeof(T);
size -= sizeof(T);
return true;
2014-12-12 01:21:34 +01:00
}
template <typename T>
bool peek(T& out, u32 shift = 0)
2014-12-12 01:21:34 +01:00
{
if (sizeof(T) + shift > size)
return false;
2019-12-01 18:14:58 +01:00
std::memcpy(&out, vm::base(addr + shift), sizeof(T));
return true;
2014-12-12 01:21:34 +01:00
}
void skip(u32 count)
2014-12-12 01:21:34 +01:00
{
addr += count;
size = size > count ? size - count : 0;
2014-12-12 01:21:34 +01:00
}
bool check(u32 count) const
2014-08-23 22:40:04 +02:00
{
return count <= size;
}
2014-08-23 22:40:04 +02:00
u64 get_ts(u8 c)
{
u8 v[4];
get(v);
return ((u64{c} & 0x0e) << 29) |
((u64{v[0]}) << 21) |
((u64{v[1]} & 0x7e) << 15) |
((u64{v[2]}) << 7) | (u64{v[3]} >> 1);
}
};
2014-12-12 01:21:34 +01:00
struct PesHeader
{
u64 pts;
u64 dts;
u8 size;
bool has_ts;
bool is_ok;
2014-12-12 01:21:34 +01:00
PesHeader(DemuxerStream& stream);
};
2014-12-12 01:21:34 +01:00
class ElementaryStream;
class Demuxer;
2014-12-12 01:21:34 +01:00
enum DemuxerJobType
2014-12-12 01:21:34 +01:00
{
dmuxSetStream,
dmuxResetStream,
dmuxResetStreamAndWaitDone,
dmuxEnableEs,
dmuxDisableEs,
dmuxResetEs,
dmuxFlushEs,
dmuxClose,
};
struct DemuxerTask
2014-08-23 22:40:04 +02:00
{
DemuxerJobType type;
union
2014-08-23 22:40:04 +02:00
{
DemuxerStream stream;
struct
2014-08-23 22:40:04 +02:00
{
u32 es;
u32 auInfo_ptr_addr;
u32 auSpec_ptr_addr;
ElementaryStream* es_ptr;
} es;
};
DemuxerTask()
2014-08-23 22:40:04 +02:00
{
}
DemuxerTask(DemuxerJobType type)
: type(type)
2014-08-23 22:40:04 +02:00
{
}
};
2014-12-03 14:21:58 +01:00
class ElementaryStream
{
std::mutex m_mutex;
squeue_t<u32> entries; // AU starting addresses
u32 put_count = 0; // number of AU written
u32 got_count = 0; // number of AU obtained by GetAu(Ex)
u32 released = 0; // number of AU released
2014-12-03 14:21:58 +01:00
u32 put; // AU that is being written now
2014-12-03 14:21:58 +01:00
bool is_full(u32 space);
2014-12-03 14:21:58 +01:00
public:
2017-01-25 18:50:30 +01:00
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1023;
SAVESTATE_INIT_POS(34);
2017-01-25 18:50:30 +01:00
ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMajor, u32 fidMinor, u32 sup1, u32 sup2, vm::ptr<CellDmuxCbEsMsg> cbFunc, u32 cbArg, u32 spec);
2014-08-23 22:40:04 +02:00
Demuxer* dmux;
2017-01-25 18:50:30 +01:00
const u32 id = idm::last_id();
const u32 memAddr;
const u32 memSize;
const u32 fidMajor;
const u32 fidMinor;
const u32 sup1;
const u32 sup2;
const vm::ptr<CellDmuxCbEsMsg> cbFunc;
const u32 cbArg;
const u32 spec; // addr
2014-08-23 22:40:04 +02:00
std::vector<u8> raw_data; // demultiplexed data stream (managed by demuxer thread)
usz raw_pos = 0; // should be <= raw_data.size()
u64 last_dts = CODEC_TS_INVALID;
u64 last_pts = CODEC_TS_INVALID;
2014-08-23 22:40:04 +02:00
void push(DemuxerStream& stream, u32 size); // called by demuxer thread (not multithread-safe)
2016-03-21 20:43:03 +01:00
bool isfull(u32 space);
2014-08-23 22:40:04 +02:00
void push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool rap, u32 specific);
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-08-23 22:40:04 +02:00
class Demuxer : public ppu_thread
2014-08-23 22:40:04 +02:00
{
public:
squeue_t<DemuxerTask, 32> job;
const u32 memAddr;
const u32 memSize;
const vm::ptr<CellDmuxCbMsg> cbFunc;
const u32 cbArg;
volatile bool is_finished = false;
volatile bool is_closed = false;
atomic_t<bool> is_running = false;
atomic_t<bool> is_working = false;
Demuxer(u32 addr, u32 size, vm::ptr<CellDmuxCbMsg> func, u32 arg)
: ppu_thread({}, "", 0), memAddr(addr), memSize(size), cbFunc(func), cbArg(arg)
2014-08-23 22:40:04 +02:00
{
2014-12-06 10:28:17 +01:00
}
void non_task()
2014-12-06 10:28:17 +01:00
{
DemuxerTask task;
DemuxerStream stream = {};
ElementaryStream* esALL[96]{};
ElementaryStream** esAVC = &esALL[0]; // AVC (max 16 minus M2V count)
// ElementaryStream** esM2V = &esALL[16]; // M2V (max 16 minus AVC count)
// ElementaryStream** esDATA = &esALL[32]; // user data (max 16)
ElementaryStream** esATX = &esALL[48]; // ATRAC3+ (max 16)
// ElementaryStream** esAC3 = &esALL[64]; // AC3 (max 16)
// ElementaryStream** esPCM = &esALL[80]; // LPCM (max 16)
2014-08-23 22:40:04 +02:00
u32 cb_add = 0;
2014-08-23 22:40:04 +02:00
while (true)
{
if (Emu.IsStopped() || is_closed)
{
break;
}
if (!job.try_peek(task) && is_running && stream.addr)
{
// default task (demuxing) (if there is no other work)
be_t<u32> code;
be_t<u16> len;
2014-10-18 19:00:21 +02:00
if (!stream.peek(code))
{
// demuxing finished
is_running = false;
2014-12-06 10:28:17 +01:00
// callback
auto dmuxMsg = vm::ptr<CellDmuxMsg>::make(memAddr + (cb_add ^= 16));
dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE;
dmuxMsg->supplementalInfo = stream.userdata;
cbFunc(*this, id, dmuxMsg, cbArg);
lv2_obj::sleep(*this);
2014-08-23 22:40:04 +02:00
is_working = false;
2015-03-07 18:39:25 +01:00
stream = {};
2014-12-12 01:21:34 +01:00
continue;
}
switch (code)
{
case PACK_START_CODE:
2014-10-18 00:20:03 +02:00
{
2014-12-12 01:21:34 +01:00
if (!stream.check(14))
{
fmt::throw_exception("End of stream (PACK_START_CODE)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(14);
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
case SYSTEM_HEADER_START_CODE:
2014-10-18 00:20:03 +02:00
{
2014-12-12 01:21:34 +01:00
if (!stream.check(18))
{
fmt::throw_exception("End of stream (SYSTEM_HEADER_START_CODE)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(18);
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
case PADDING_STREAM:
2014-10-18 00:20:03 +02:00
{
2014-12-12 01:21:34 +01:00
if (!stream.check(6))
{
fmt::throw_exception("End of stream (PADDING_STREAM)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(4);
stream.get(len);
2014-12-12 01:21:34 +01:00
2015-01-14 00:08:00 +01:00
if (!stream.check(len))
2014-12-12 01:21:34 +01:00
{
fmt::throw_exception("End of stream (PADDING_STREAM, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(len);
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
case PRIVATE_STREAM_2:
{
2014-12-12 01:21:34 +01:00
if (!stream.check(6))
{
fmt::throw_exception("End of stream (PRIVATE_STREAM_2)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(4);
stream.get(len);
2014-12-12 01:21:34 +01:00
cellDmux.notice("PRIVATE_STREAM_2 (%d)", len);
2014-12-12 01:21:34 +01:00
2015-01-14 00:08:00 +01:00
if (!stream.check(len))
2014-12-12 01:21:34 +01:00
{
fmt::throw_exception("End of stream (PRIVATE_STREAM_2, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(len);
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
case PRIVATE_STREAM_1:
{
2014-12-12 01:21:34 +01:00
// audio and user data stream
2014-10-18 00:20:03 +02:00
DemuxerStream backup = stream;
2014-12-12 01:21:34 +01:00
if (!stream.check(6))
{
fmt::throw_exception("End of stream (PRIVATE_STREAM_1)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
stream.skip(4);
stream.get(len);
2015-01-14 00:08:00 +01:00
if (!stream.check(len))
2014-12-12 01:21:34 +01:00
{
fmt::throw_exception("End of stream (PRIVATE_STREAM_1, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
const PesHeader pes(stream);
if (!pes.is_ok)
{
fmt::throw_exception("PesHeader error (PRIVATE_STREAM_1, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
2014-12-12 01:21:34 +01:00
if (len < pes.size + 4)
{
fmt::throw_exception("End of block (PRIVATE_STREAM_1, PesHeader + fid_minor, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
len -= pes.size + 4;
2014-12-12 01:21:34 +01:00
u8 fid_minor;
if (!stream.get(fid_minor))
{
fmt::throw_exception("End of stream (PRIVATE_STREAM1, fid_minor)");
2014-12-12 01:21:34 +01:00
}
2014-10-18 00:20:03 +02:00
2014-12-12 01:21:34 +01:00
const u32 ch = fid_minor % 16;
if ((fid_minor & -0x10) == 0 && esATX[ch])
{
2014-10-18 00:20:03 +02:00
ElementaryStream& es = *esATX[ch];
if (es.raw_data.size() > 1024 * 1024)
2014-10-18 00:20:03 +02:00
{
stream = backup;
2016-05-13 15:55:34 +02:00
std::this_thread::sleep_for(1ms); // hack
2014-10-18 00:20:03 +02:00
continue;
}
2014-12-12 01:21:34 +01:00
if (len < 3 || !stream.check(3))
{
fmt::throw_exception("End of block (ATX, unknown header, len=%d)", len);
2014-12-12 01:21:34 +01:00
}
len -= 3;
stream.skip(3);
2014-10-18 00:20:03 +02:00
if (pes.has_ts)
{
es.last_dts = pes.dts;
es.last_pts = pes.pts;
}
2014-12-12 01:21:34 +01:00
es.push(stream, len);
2014-12-03 14:21:58 +01:00
while (true)
2014-12-03 14:21:58 +01:00
{
auto const size = es.raw_data.size() - es.raw_pos; // size of available new data
auto const data = es.raw_data.data() + es.raw_pos; // pointer to available data
if (size < 8)
break; // skip if cannot read ATS header
2014-12-03 14:21:58 +01:00
if (data[0] != 0x0f || data[1] != 0xd0)
{
fmt::throw_exception("ATX: 0x0fd0 header not found (ats=0x%llx)", *reinterpret_cast<be_t<u64>*>(data));
2014-12-03 14:21:58 +01:00
}
2019-12-01 18:14:58 +01:00
u32 frame_size = (((u32{data[2]} & 0x3) << 8) | u32{data[3]}) * 8 + 8;
2014-12-03 14:21:58 +01:00
if (size < frame_size + 8)
break; // skip non-complete AU
if (es.isfull(frame_size + 8))
break; // skip if cannot push AU
es.push_au(frame_size + 8, es.last_dts, es.last_pts, stream.userdata, false /* TODO: set correct value */, 0);
2014-12-03 14:21:58 +01:00
// cellDmux.notice("ATX AU pushed (ats=0x%llx, frame_size=%d)", *(be_t<u64>*)data, frame_size);
2014-12-12 01:21:34 +01:00
auto esMsg = vm::ptr<CellDmuxEsMsg>::make(memAddr + (cb_add ^= 16));
2014-12-03 14:21:58 +01:00
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this);
2014-12-03 14:21:58 +01:00
}
}
2014-10-18 00:20:03 +02:00
else
{
cellDmux.notice("PRIVATE_STREAM_1 (len=%d, fid_minor=0x%x)", len, fid_minor);
2014-12-12 01:21:34 +01:00
stream.skip(len);
2014-10-18 00:20:03 +02:00
}
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
case 0x1e0:
case 0x1e1:
case 0x1e2:
case 0x1e3:
case 0x1e4:
case 0x1e5:
case 0x1e6:
case 0x1e7:
case 0x1e8:
case 0x1e9:
case 0x1ea:
case 0x1eb:
case 0x1ec:
case 0x1ed:
case 0x1ee:
case 0x1ef:
2014-10-18 00:20:03 +02:00
{
2014-12-12 01:21:34 +01:00
// video stream (AVC or M2V)
DemuxerStream backup = stream;
if (!stream.check(6))
{
fmt::throw_exception("End of stream (video, code=0x%x)", code);
2014-12-12 01:21:34 +01:00
}
stream.skip(4);
stream.get(len);
2015-01-14 00:08:00 +01:00
if (!stream.check(len))
2014-12-12 01:21:34 +01:00
{
fmt::throw_exception("End of stream (video, code=0x%x, len=%d)", code, len);
2014-12-12 01:21:34 +01:00
}
const PesHeader pes(stream);
if (!pes.is_ok)
{
fmt::throw_exception("PesHeader error (video, code=0x%x, len=%d)", code, len);
2014-12-12 01:21:34 +01:00
}
if (len < pes.size + 3)
{
fmt::throw_exception("End of block (video, code=0x%x, PesHeader)", code);
2014-12-12 01:21:34 +01:00
}
len -= pes.size + 3;
2015-01-14 00:08:00 +01:00
const u32 ch = code % 16;
2014-10-18 00:20:03 +02:00
if (esAVC[ch])
{
2014-10-18 00:20:03 +02:00
ElementaryStream& es = *esAVC[ch];
2019-12-01 18:14:58 +01:00
const u32 old_size = ::size32(es.raw_data);
if (es.isfull(old_size))
{
2014-12-03 14:21:58 +01:00
stream = backup;
2016-05-13 15:55:34 +02:00
std::this_thread::sleep_for(1ms); // hack
2014-12-03 14:21:58 +01:00
continue;
}
2014-12-12 01:21:34 +01:00
if ((pes.has_ts && old_size) || old_size >= 0x69800)
{
2014-12-12 01:21:34 +01:00
// push AU if it becomes too big or the next packet contains PTS/DTS
es.push_au(old_size, es.last_dts, es.last_pts, stream.userdata, false /* TODO: set correct value */, 0);
2014-12-03 14:21:58 +01:00
2014-10-18 00:20:03 +02:00
// callback
auto esMsg = vm::ptr<CellDmuxEsMsg>::make(memAddr + (cb_add ^= 16));
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this);
}
2014-12-03 14:21:58 +01:00
if (pes.has_ts)
{
2014-12-03 14:21:58 +01:00
// preserve dts/pts for next AU
es.last_dts = pes.dts;
es.last_pts = pes.pts;
}
2014-10-18 00:20:03 +02:00
// reconstruction of MPEG2-PS stream for vdec module
2015-01-14 00:08:00 +01:00
const u32 size = len + pes.size + 9;
2014-10-18 00:20:03 +02:00
stream = backup;
2014-12-03 14:21:58 +01:00
es.push(stream, size);
}
2014-10-18 00:20:03 +02:00
else
{
cellDmux.notice("Video stream (code=0x%x, len=%d)", code, len);
2014-10-18 00:20:03 +02:00
stream.skip(len);
}
2014-12-12 01:21:34 +01:00
break;
2014-10-18 00:20:03 +02:00
}
default:
2014-10-18 00:20:03 +02:00
{
2015-01-14 00:08:00 +01:00
if ((code & PACKET_START_CODE_MASK) == PACKET_START_CODE_PREFIX)
2014-12-12 01:21:34 +01:00
{
fmt::throw_exception("Unknown code found (0x%x)", code);
2014-12-12 01:21:34 +01:00
}
// search
stream.skip(1);
}
}
continue;
}
// wait for task if no work
if (!job.pop(task, &is_closed))
{
break; // Emu is stopped
}
switch (task.type)
{
case dmuxSetStream:
{
if (task.stream.discontinuity)
{
cellDmux.warning("dmuxSetStream (beginning)");
2018-09-05 22:52:31 +02:00
for (u32 i = 0; i < std::size(esALL); i++)
{
if (esALL[i])
{
esALL[i]->reset();
}
}
}
stream = task.stream;
// cellDmux.notice("*** stream updated(addr=0x%x, size=0x%x, discont=%d, userdata=0x%llx)",
// stream.addr, stream.size, stream.discontinuity, stream.userdata);
break;
}
case dmuxResetStream:
case dmuxResetStreamAndWaitDone:
{
// demuxing stopped
if (is_running.exchange(false))
{
// callback
auto dmuxMsg = vm::ptr<CellDmuxMsg>::make(memAddr + (cb_add ^= 16));
dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE;
dmuxMsg->supplementalInfo = stream.userdata;
cbFunc(*this, id, dmuxMsg, cbArg);
lv2_obj::sleep(*this);
stream = {};
is_working = false;
}
break;
}
case dmuxEnableEs:
{
ElementaryStream& es = *task.es.es_ptr;
// TODO: uncomment when ready to use
// if ((es.fidMajor & -0x10) == 0xe0 && es.fidMinor == 0 && es.sup1 == 1 && !es.sup2)
//{
// esAVC[es.fidMajor % 16] = task.es.es_ptr;
//}
// else if ((es.fidMajor & -0x10) == 0xe0 && es.fidMinor == 0 && !es.sup1 && !es.sup2)
//{
// esM2V[es.fidMajor % 16] = task.es.es_ptr;
//}
// else if (es.fidMajor == 0xbd && (es.fidMinor & -0x10) == 0 && !es.sup1 && !es.sup2)
//{
// esATX[es.fidMinor % 16] = task.es.es_ptr;
//}
// else if (es.fidMajor == 0xbd && (es.fidMinor & -0x10) == 0x20 && !es.sup1 && !es.sup2)
//{
// esDATA[es.fidMinor % 16] = task.es.es_ptr;
//}
// else if (es.fidMajor == 0xbd && (es.fidMinor & -0x10) == 0x30 && !es.sup1 && !es.sup2)
//{
// esAC3[es.fidMinor % 16] = task.es.es_ptr;
//}
// else if (es.fidMajor == 0xbd && (es.fidMinor & -0x10) == 0x40 && !es.sup1 && !es.sup2)
//{
// esPCM[es.fidMinor % 16] = task.es.es_ptr;
//}
// else
{
fmt::throw_exception("dmuxEnableEs: unknown filter (0x%x, 0x%x, 0x%x, 0x%x)", es.fidMajor, es.fidMinor, es.sup1, es.sup2);
}
es.dmux = this;
break;
}
case dmuxDisableEs:
{
ElementaryStream& es = *task.es.es_ptr;
if (es.dmux != this)
{
fmt::throw_exception("dmuxDisableEs: invalid elementary stream");
}
2018-09-05 22:52:31 +02:00
for (u32 i = 0; i < std::size(esALL); i++)
{
if (esALL[i] == &es)
{
esALL[i] = nullptr;
}
}
es.dmux = nullptr;
idm::remove<ElementaryStream>(task.es.es);
break;
}
case dmuxFlushEs:
{
ElementaryStream& es = *task.es.es_ptr;
2019-12-01 18:14:58 +01:00
const u32 old_size = ::size32(es.raw_data);
if (old_size && (es.fidMajor & -0x10) == 0xe0)
{
// TODO (it's only for AVC, some ATX data may be lost)
while (es.isfull(old_size))
{
if (Emu.IsStopped() || is_closed)
break;
std::this_thread::sleep_for(1ms); // hack
}
es.push_au(old_size, es.last_dts, es.last_pts, stream.userdata, false, 0);
// callback
auto esMsg = vm::ptr<CellDmuxEsMsg>::make(memAddr + (cb_add ^= 16));
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this);
}
2020-02-26 21:13:54 +01:00
if (!es.raw_data.empty())
{
2019-12-01 18:14:58 +01:00
cellDmux.error("dmuxFlushEs: 0x%x bytes lost (es_id=%d)", ::size32(es.raw_data), es.id);
}
// callback
auto esMsg = vm::ptr<CellDmuxEsMsg>::make(memAddr + (cb_add ^= 16));
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_FLUSH_DONE;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this);
break;
}
case dmuxResetEs:
{
task.es.es_ptr->reset();
break;
}
case dmuxClose:
{
break;
}
default:
{
fmt::throw_exception("Demuxer thread error: unknown task (0x%x)", +task.type);
}
}
}
is_finished = true;
}
};
PesHeader::PesHeader(DemuxerStream& stream)
: pts(CODEC_TS_INVALID), dts(CODEC_TS_INVALID), size(0), has_ts(false), is_ok(false)
{
u16 header;
if (!stream.get(header))
{
fmt::throw_exception("End of stream (header)");
}
if (!stream.get(size))
{
fmt::throw_exception("End of stream (size)");
}
if (!stream.check(size))
{
fmt::throw_exception("End of stream (size=%d)", size);
}
u8 pos = 0;
while (pos++ < size)
{
u8 v;
if (!stream.get(v))
{
return; // should never occur
}
if (v == 0xff) // skip padding bytes
{
continue;
}
if ((v & 0xf0) == 0x20 && (size - pos) >= 4) // pts only
{
pos += 4;
pts = stream.get_ts(v);
has_ts = true;
}
else if ((v & 0xf0) == 0x30 && (size - pos) >= 9) // pts and dts
{
pos += 5;
pts = stream.get_ts(v);
stream.get(v);
has_ts = true;
if ((v & 0xf0) != 0x10)
{
cellDmux.error("PesHeader(): dts not found (v=0x%x, size=%d, pos=%d)", v, size, pos - 1);
stream.skip(size - pos);
return;
}
pos += 4;
dts = stream.get_ts(v);
}
else
{
cellDmux.warning("PesHeader(): unknown code (v=0x%x, size=%d, pos=%d)", v, size, pos - 1);
stream.skip(size - pos);
pos = size;
break;
}
}
is_ok = true;
}
ElementaryStream::ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMajor, u32 fidMinor, u32 sup1, u32 sup2, vm::ptr<CellDmuxCbEsMsg> cbFunc, u32 cbArg, u32 spec)
: put(utils::align(addr, 128)), dmux(dmux), memAddr(utils::align(addr, 128)), memSize(size - (addr - memAddr)), fidMajor(fidMajor), fidMinor(fidMinor), sup1(sup1), sup2(sup2), cbFunc(cbFunc), cbArg(cbArg), spec(spec)
{
}
bool ElementaryStream::is_full(u32 space)
{
if (released < put_count)
{
if (entries.is_full())
{
return true;
}
u32 first = 0;
if (!entries.peek(first, 0, &dmux->is_closed) || !first)
{
fmt::throw_exception("entries.peek() failed");
}
else if (first >= put)
{
return first - put < space + 128;
}
else if (put + space + 128 > memAddr + memSize)
{
return first - memAddr < space + 128;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool ElementaryStream::isfull(u32 space)
{
std::lock_guard lock(m_mutex);
return is_full(space);
}
void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool rap, u32 specific)
{
u32 addr;
{
std::lock_guard lock(m_mutex);
ensure(!is_full(size));
if (put + size + 128 > memAddr + memSize)
{
put = memAddr;
}
2014-12-12 01:21:34 +01:00
std::memcpy(vm::base(put + 128), raw_data.data(), size);
raw_data.erase(raw_data.begin(), raw_data.begin() + size);
2014-02-24 01:00:42 +01:00
auto info = vm::ptr<CellDmuxAuInfoEx>::make(put);
info->auAddr = put + 128;
info->auSize = size;
2019-12-01 18:14:58 +01:00
info->dts.lower = static_cast<u32>(dts);
info->dts.upper = static_cast<u32>(dts >> 32);
info->pts.lower = static_cast<u32>(pts);
info->pts.upper = static_cast<u32>(pts >> 32);
info->isRap = rap;
info->reserved = 0;
info->userData = userdata;
2014-03-06 12:40:50 +01:00
2018-09-03 17:46:14 +02:00
auto spec = vm::ptr<u32>::make(put + u32{sizeof(CellDmuxAuInfoEx)});
*spec = specific;
2014-03-13 10:17:45 +01:00
auto inf = vm::ptr<CellDmuxAuInfo>::make(put + 64);
inf->auAddr = put + 128;
inf->auSize = size;
2019-12-01 18:14:58 +01:00
inf->dtsLower = static_cast<u32>(dts);
inf->dtsUpper = static_cast<u32>(dts >> 32);
inf->ptsLower = static_cast<u32>(pts);
inf->ptsUpper = static_cast<u32>(pts >> 32);
inf->auMaxSize = 0; // ?????
inf->userData = userdata;
addr = put;
2015-03-07 18:39:25 +01:00
put = utils::align(put + 128 + size, 128);
2015-03-07 18:39:25 +01:00
put_count++;
}
2015-03-07 18:39:25 +01:00
ensure(entries.push(addr, &dmux->is_closed));
}
void ElementaryStream::push(DemuxerStream& stream, u32 size)
{
auto const old_size = raw_data.size();
2014-12-12 01:21:34 +01:00
raw_data.resize(old_size + size);
std::memcpy(raw_data.data() + old_size, vm::base(stream.addr), size); // append bytes
2014-12-12 01:21:34 +01:00
stream.skip(size);
}
2014-10-18 00:20:03 +02:00
bool ElementaryStream::release()
{
std::lock_guard lock(m_mutex);
if (released >= put_count)
{
cellDmux.fatal("es::release() error: buffer is empty");
return false;
}
if (released >= got_count)
{
cellDmux.fatal("es::release() error: buffer has not been seen yet");
return false;
}
u32 addr = 0;
if (!entries.pop(addr, &dmux->is_closed) || !addr)
{
cellDmux.fatal("es::release() error: entries.Pop() failed");
return false;
}
released++;
return true;
}
bool ElementaryStream::peek(u32& out_data, bool no_ex, u32& out_spec, bool update_index)
{
std::lock_guard lock(m_mutex);
if (got_count < released)
{
cellDmux.fatal("es::peek() error: got_count(%d) < released(%d) (put_count=%d)", got_count, released, put_count);
return false;
}
if (got_count >= put_count)
{
return false;
}
2014-12-03 14:21:58 +01:00
u32 addr = 0;
if (!entries.peek(addr, got_count - released, &dmux->is_closed) || !addr)
{
cellDmux.fatal("es::peek() error: entries.Peek() failed");
return false;
}
2014-10-18 00:20:03 +02:00
out_data = no_ex ? addr + 64 : addr;
out_spec = addr + sizeof(CellDmuxAuInfoEx);
if (update_index)
{
got_count++;
}
return true;
}
void ElementaryStream::reset()
{
std::lock_guard lock(m_mutex);
put = memAddr;
entries.clear();
put_count = 0;
got_count = 0;
released = 0;
raw_data.clear();
raw_pos = 0;
}
2014-10-18 00:20:03 +02:00
2021-03-05 20:05:37 +01:00
void dmuxQueryAttr(u32 /* info_addr, may be 0 */, vm::ptr<CellDmuxAttr> attr)
{
attr->demuxerVerLower = 0x280000; // TODO: check values
attr->demuxerVerUpper = 0x260000;
attr->memSize = 0x10000; // 0x3e8e6 from ps3
}
2021-03-05 20:05:37 +01:00
void dmuxQueryEsAttr(u32 /* info, may be 0 */, vm::cptr<CellCodecEsFilterId> esFilterId, u32 /*esSpecificInfo*/, vm::ptr<CellDmuxEsAttr> attr)
{
if (esFilterId->filterIdMajor >= 0xe0)
{
attr->memSize = 0x500000; // 0x45fa49 from ps3
}
else
{
attr->memSize = 0x7000; // 0x73d9 from ps3
}
2015-07-01 00:25:52 +02:00
cellDmux.warning("*** filter(0x%x, 0x%x, 0x%x, 0x%x)", esFilterId->filterIdMajor, esFilterId->filterIdMinor, esFilterId->supplementalInfo1, esFilterId->supplementalInfo2);
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxQueryAttr(vm::cptr<CellDmuxType> type, vm::ptr<CellDmuxAttr> attr)
{
cellDmux.warning("cellDmuxQueryAttr(type=*0x%x, attr=*0x%x)", type, attr);
2015-04-12 22:16:30 +02:00
if (type->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
{
return CELL_DMUX_ERROR_ARG;
}
2015-04-12 22:16:30 +02:00
dmuxQueryAttr(0, attr);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxQueryAttr2(vm::cptr<CellDmuxType2> type2, vm::ptr<CellDmuxAttr> attr)
{
cellDmux.warning("cellDmuxQueryAttr2(demuxerType2=*0x%x, demuxerAttr=*0x%x)", type2, attr);
2015-04-12 22:16:30 +02:00
if (type2->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
{
return CELL_DMUX_ERROR_ARG;
}
2015-04-12 22:16:30 +02:00
dmuxQueryAttr(type2->streamSpecificInfo, attr);
return CELL_OK;
2014-02-24 01:00:42 +01:00
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxOpen(vm::cptr<CellDmuxType> type, vm::cptr<CellDmuxResource> res, vm::cptr<CellDmuxCb> cb, vm::ptr<u32> handle)
{
cellDmux.warning("cellDmuxOpen(type=*0x%x, res=*0x%x, cb=*0x%x, handle=*0x%x)", type, res, cb, handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (type->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check demuxerResource and demuxerCb arguments
fmt::throw_exception("cellDmux disabled, use LLE.");
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxOpenEx(vm::cptr<CellDmuxType> type, vm::cptr<CellDmuxResourceEx> resEx, vm::cptr<CellDmuxCb> cb, vm::ptr<u32> handle)
{
cellDmux.warning("cellDmuxOpenEx(type=*0x%x, resEx=*0x%x, cb=*0x%x, handle=*0x%x)", type, resEx, cb, handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (type->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check demuxerResourceEx and demuxerCb arguments
fmt::throw_exception("cellDmux disabled, use LLE.");
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxOpenExt(vm::cptr<CellDmuxType> type, vm::cptr<CellDmuxResourceEx> resEx, vm::cptr<CellDmuxCb> cb, vm::ptr<u32> handle)
2015-04-17 06:37:13 +02:00
{
cellDmux.warning("cellDmuxOpenExt(type=*0x%x, resEx=*0x%x, cb=*0x%x, handle=*0x%x)", type, resEx, cb, handle);
2015-04-17 06:37:13 +02:00
return cellDmuxOpenEx(type, resEx, cb, handle);
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxOpen2(vm::cptr<CellDmuxType2> type2, vm::cptr<CellDmuxResource2> res2, vm::cptr<CellDmuxCb> cb, vm::ptr<u32> handle)
{
cellDmux.warning("cellDmuxOpen2(type2=*0x%x, res2=*0x%x, cb=*0x%x, handle=*0x%x)", type2, res2, cb, handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (type2->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check demuxerType2, demuxerResource2 and demuxerCb arguments
fmt::throw_exception("cellDmux disabled, use LLE.");
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxClose(u32 handle)
{
cellDmux.warning("cellDmuxClose(handle=0x%x)", handle);
2015-04-12 22:16:30 +02:00
2024-12-22 19:59:48 +01:00
const auto dmux = idm::get_unlocked<Demuxer>(handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (!dmux)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
2014-10-18 00:20:03 +02:00
dmux->is_closed = true;
2014-12-24 23:24:17 +01:00
dmux->job.try_push(DemuxerTask(dmuxClose));
2014-02-24 01:00:42 +01:00
while (!dmux->is_finished)
{
if (Emu.IsStopped())
{
cellDmux.warning("cellDmuxClose(%d) aborted", handle);
2014-02-24 01:00:42 +01:00
return CELL_OK;
}
2016-05-13 15:55:34 +02:00
std::this_thread::sleep_for(1ms); // hack
2014-02-24 01:00:42 +01:00
}
idm::remove<ppu_thread>(handle);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxSetStream(u32 handle, u32 streamAddress, u32 streamSize, b8 discontinuity, u64 userData)
{
cellDmux.trace("cellDmuxSetStream(handle=0x%x, streamAddress=0x%x, streamSize=%d, discontinuity=%d, userData=0x%llx)", handle, streamAddress, streamSize, discontinuity, userData);
2014-02-24 01:00:42 +01:00
2024-12-22 19:59:48 +01:00
const auto dmux = idm::get_unlocked<Demuxer>(handle);
2015-04-12 22:16:30 +02:00
if (!dmux)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
2014-10-23 00:53:44 +02:00
if (dmux->is_running.exchange(true))
2014-02-24 01:00:42 +01:00
{
// std::this_thread::sleep_for(1ms); // hack
2014-03-07 22:31:08 +01:00
return CELL_DMUX_ERROR_BUSY;
2014-02-24 01:00:42 +01:00
}
DemuxerTask task(dmuxSetStream);
auto& info = task.stream;
info.addr = streamAddress;
info.size = streamSize;
info.discontinuity = discontinuity;
info.userdata = userData;
2014-12-24 23:24:17 +01:00
dmux->job.push(task, &dmux->is_closed);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxResetStream(u32 handle)
{
cellDmux.warning("cellDmuxResetStream(handle=0x%x)", handle);
2015-04-12 22:16:30 +02:00
2024-12-22 19:59:48 +01:00
const auto dmux = idm::get_unlocked<Demuxer>(handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (!dmux)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
2014-12-24 23:24:17 +01:00
dmux->job.push(DemuxerTask(dmuxResetStream), &dmux->is_closed);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxResetStreamAndWaitDone(u32 handle)
{
cellDmux.warning("cellDmuxResetStreamAndWaitDone(handle=0x%x)", handle);
2014-02-24 01:00:42 +01:00
2024-12-22 19:59:48 +01:00
const auto dmux = idm::get_unlocked<Demuxer>(handle);
2015-04-12 22:16:30 +02:00
if (!dmux)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
2015-03-07 18:39:25 +01:00
if (!dmux->is_running)
{
return CELL_OK;
}
dmux->is_working = true;
2014-12-24 23:24:17 +01:00
dmux->job.push(DemuxerTask(dmuxResetStreamAndWaitDone), &dmux->is_closed);
2015-03-07 18:39:25 +01:00
while (dmux->is_running && dmux->is_working && !dmux->is_closed) // TODO: ensure that it is safe
{
2014-10-23 00:53:44 +02:00
if (Emu.IsStopped())
{
cellDmux.warning("cellDmuxResetStreamAndWaitDone(%d) aborted", handle);
2014-10-23 00:53:44 +02:00
return CELL_OK;
}
2016-05-13 15:55:34 +02:00
std::this_thread::sleep_for(1ms); // hack
}
2015-03-07 18:39:25 +01:00
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxQueryEsAttr(vm::cptr<CellDmuxType> type, vm::cptr<CellCodecEsFilterId> esFilterId, u32 esSpecificInfo, vm::ptr<CellDmuxEsAttr> esAttr)
{
cellDmux.warning("cellDmuxQueryEsAttr(demuxerType=*0x%x, esFilterId=*0x%x, esSpecificInfo=*0x%x, esAttr=*0x%x)", type, esFilterId, esSpecificInfo, esAttr);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (type->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check esFilterId and esSpecificInfo correctly
2015-04-12 22:16:30 +02:00
dmuxQueryEsAttr(0, esFilterId, esSpecificInfo, esAttr);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxQueryEsAttr2(vm::cptr<CellDmuxType2> type2, vm::cptr<CellCodecEsFilterId> esFilterId, u32 esSpecificInfo, vm::ptr<CellDmuxEsAttr> esAttr)
{
cellDmux.warning("cellDmuxQueryEsAttr2(type2=*0x%x, esFilterId=*0x%x, esSpecificInfo=*0x%x, esAttr=*0x%x)", type2, esFilterId, esSpecificInfo, esAttr);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (type2->streamType != CELL_DMUX_STREAM_TYPE_PAMF)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check demuxerType2, esFilterId and esSpecificInfo correctly
2015-04-12 22:16:30 +02:00
dmuxQueryEsAttr(type2->streamSpecificInfo, esFilterId, esSpecificInfo, esAttr);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxEnableEs(u32 handle, vm::cptr<CellCodecEsFilterId> esFilterId, vm::cptr<CellDmuxEsResource> esResourceInfo, vm::cptr<CellDmuxEsCb> esCb, u32 esSpecificInfo, vm::ptr<u32> esHandle)
{
cellDmux.warning("cellDmuxEnableEs(handle=0x%x, esFilterId=*0x%x, esResourceInfo=*0x%x, esCb=*0x%x, esSpecificInfo=*0x%x, esHandle=*0x%x)", handle, esFilterId, esResourceInfo, esCb, esSpecificInfo, esHandle);
2015-04-12 22:16:30 +02:00
2024-12-22 19:59:48 +01:00
const auto dmux = idm::get_unlocked<Demuxer>(handle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (!dmux)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
// TODO: check esFilterId, esResourceInfo, esCb and esSpecificInfo correctly
const auto es = idm::make_ptr<ElementaryStream>(dmux.get(), esResourceInfo->memAddr, esResourceInfo->memSize,
2014-02-24 01:00:42 +01:00
esFilterId->filterIdMajor, esFilterId->filterIdMinor, esFilterId->supplementalInfo1, esFilterId->supplementalInfo2,
2024-11-23 13:46:15 +01:00
esCb->cbFunc, esCb->cbArg, esSpecificInfo);
2014-02-24 01:00:42 +01:00
2015-07-01 19:09:26 +02:00
*esHandle = es->id;
cellDmux.warning("*** New ES(dmux=0x%x, addr=0x%x, size=0x%x, filter={0x%x, 0x%x, 0x%x, 0x%x}, cb=0x%x, arg=0x%x, spec=0x%x): id = 0x%x",
2015-07-01 19:09:26 +02:00
handle, es->memAddr, es->memSize, es->fidMajor, es->fidMinor, es->sup1, es->sup2, es->cbFunc, es->cbArg, es->spec, es->id);
2014-02-24 01:00:42 +01:00
DemuxerTask task(dmuxEnableEs);
2015-07-01 19:09:26 +02:00
task.es.es = es->id;
2014-12-24 00:38:13 +01:00
task.es.es_ptr = es.get();
2014-02-24 01:00:42 +01:00
2014-12-24 23:24:17 +01:00
dmux->job.push(task, &dmux->is_closed);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxDisableEs(u32 esHandle)
{
cellDmux.warning("cellDmuxDisableEs(esHandle=0x%x)", esHandle);
2014-02-24 01:00:42 +01:00
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
DemuxerTask task(dmuxDisableEs);
task.es.es = esHandle;
2014-12-24 00:38:13 +01:00
task.es.es_ptr = es.get();
2014-02-24 01:00:42 +01:00
2014-12-24 23:24:17 +01:00
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxResetEs(u32 esHandle)
{
cellDmux.trace("cellDmuxResetEs(esHandle=0x%x)", esHandle);
2014-02-24 01:00:42 +01:00
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (!es)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
DemuxerTask task(dmuxResetEs);
task.es.es = esHandle;
2014-12-24 00:38:13 +01:00
task.es.es_ptr = es.get();
2014-02-24 01:00:42 +01:00
2014-12-24 23:24:17 +01:00
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxGetAu(u32 esHandle, vm::ptr<u32> auInfo, vm::ptr<u32> auSpecificInfo)
{
cellDmux.trace("cellDmuxGetAu(esHandle=0x%x, auInfo=**0x%x, auSpecificInfo=**0x%x)", esHandle, auInfo, auSpecificInfo);
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
{
return CELL_DMUX_ERROR_ARG;
}
u32 info;
u32 spec;
if (!es->peek(info, true, spec, true))
{
return CELL_DMUX_ERROR_EMPTY;
}
2015-04-12 22:16:30 +02:00
*auInfo = info;
*auSpecificInfo = spec;
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxPeekAu(u32 esHandle, vm::ptr<u32> auInfo, vm::ptr<u32> auSpecificInfo)
{
cellDmux.trace("cellDmuxPeekAu(esHandle=0x%x, auInfo=**0x%x, auSpecificInfo=**0x%x)", esHandle, auInfo, auSpecificInfo);
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
{
return CELL_DMUX_ERROR_ARG;
}
u32 info;
u32 spec;
if (!es->peek(info, true, spec, false))
{
return CELL_DMUX_ERROR_EMPTY;
}
2015-04-12 22:16:30 +02:00
*auInfo = info;
*auSpecificInfo = spec;
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxGetAuEx(u32 esHandle, vm::ptr<u32> auInfoEx, vm::ptr<u32> auSpecificInfo)
{
cellDmux.trace("cellDmuxGetAuEx(esHandle=0x%x, auInfoEx=**0x%x, auSpecificInfo=**0x%x)", esHandle, auInfoEx, auSpecificInfo);
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
{
return CELL_DMUX_ERROR_ARG;
}
u32 info;
u32 spec;
if (!es->peek(info, false, spec, true))
{
return CELL_DMUX_ERROR_EMPTY;
}
2015-04-12 22:16:30 +02:00
*auInfoEx = info;
*auSpecificInfo = spec;
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxPeekAuEx(u32 esHandle, vm::ptr<u32> auInfoEx, vm::ptr<u32> auSpecificInfo)
{
cellDmux.trace("cellDmuxPeekAuEx(esHandle=0x%x, auInfoEx=**0x%x, auSpecificInfo=**0x%x)", esHandle, auInfoEx, auSpecificInfo);
2015-04-12 22:16:30 +02:00
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
{
return CELL_DMUX_ERROR_ARG;
}
u32 info;
u32 spec;
if (!es->peek(info, false, spec, false))
{
return CELL_DMUX_ERROR_EMPTY;
}
2015-04-12 22:16:30 +02:00
*auInfoEx = info;
*auSpecificInfo = spec;
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxReleaseAu(u32 esHandle)
{
cellDmux.trace("cellDmuxReleaseAu(esHandle=0x%x)", esHandle);
2014-03-01 09:38:50 +01:00
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2015-04-12 22:16:30 +02:00
if (!es)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
2014-03-07 22:31:08 +01:00
if (!es->release())
{
return CELL_DMUX_ERROR_SEQ;
}
return CELL_OK;
}
2020-07-16 12:14:57 +02:00
error_code cellDmuxFlushEs(u32 esHandle)
{
cellDmux.warning("cellDmuxFlushEs(esHandle=0x%x)", esHandle);
2014-02-24 01:00:42 +01:00
2024-12-22 19:59:48 +01:00
const auto es = idm::get_unlocked<ElementaryStream>(esHandle);
2014-02-24 01:00:42 +01:00
2015-04-12 22:16:30 +02:00
if (!es)
2014-02-24 01:00:42 +01:00
{
return CELL_DMUX_ERROR_ARG;
}
DemuxerTask task(dmuxFlushEs);
task.es.es = esHandle;
2014-12-24 00:38:13 +01:00
task.es.es_ptr = es.get();
2014-02-24 01:00:42 +01:00
2014-12-24 23:24:17 +01:00
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}
2016-03-21 20:43:03 +01:00
DECLARE(ppu_module_manager::cellDmux)("cellDmux", []()
{
REG_FUNC(cellDmux, cellDmuxQueryAttr);
REG_FUNC(cellDmux, cellDmuxQueryAttr2);
REG_FUNC(cellDmux, cellDmuxOpen);
REG_FUNC(cellDmux, cellDmuxOpenEx);
REG_FUNC(cellDmux, cellDmuxOpenExt); // 0xe075fabc
REG_FUNC(cellDmux, cellDmuxOpen2);
REG_FUNC(cellDmux, cellDmuxClose);
REG_FUNC(cellDmux, cellDmuxSetStream);
REG_FUNC(cellDmux, cellDmuxResetStream);
REG_FUNC(cellDmux, cellDmuxResetStreamAndWaitDone);
REG_FUNC(cellDmux, cellDmuxQueryEsAttr);
REG_FUNC(cellDmux, cellDmuxQueryEsAttr2);
REG_FUNC(cellDmux, cellDmuxEnableEs);
REG_FUNC(cellDmux, cellDmuxDisableEs);
REG_FUNC(cellDmux, cellDmuxResetEs);
REG_FUNC(cellDmux, cellDmuxGetAu);
REG_FUNC(cellDmux, cellDmuxPeekAu);
REG_FUNC(cellDmux, cellDmuxGetAuEx);
REG_FUNC(cellDmux, cellDmuxPeekAuEx);
REG_FUNC(cellDmux, cellDmuxReleaseAu);
REG_FUNC(cellDmux, cellDmuxFlushEs);
});