1 // Copyright (c) 2012- PPSSPP Project.
2 
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.
6 
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.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17 
18 #pragma once
19 
20 #include "Common/Common.h"
21 #include "Common/Swap.h"
22 
23 class PointerWrap;
24 
25 enum {
26 	ERROR_MPEG_BAD_VERSION                              = 0x80610002,
27 	ERROR_MPEG_NO_MEMORY                                = 0x80610022,
28 	ERROR_MPEG_INVALID_ADDR                             = 0x80610103,
29 	ERROR_MPEG_INVALID_VALUE                            = 0x806101fe,
30 	ERROR_MPEG_NO_DATA                                  = 0x80618001,
31 	ERROR_MPEG_ALREADY_INIT                             = 0x80618005,
32 	ERROR_MPEG_NOT_YET_INIT                             = 0x80618009,
33 	ERROR_MPEG_AVC_INVALID_VALUE                        = 0x806201fe,
34 	ERROR_MPEG_AVC_DECODE_FATAL                         = 0x80628002,
35 	ERROR_JPEG_INVALID_VALUE                            = 0x80650051,
36 };
37 
38 // MPEG statics.
39 static const u32 PSMF_MAGIC = 0x464D5350;
40 static const int PSMF_STREAM_VERSION_OFFSET = 0x4;
41 static const int PSMF_STREAM_OFFSET_OFFSET = 0x8;
42 static const int PSMF_STREAM_SIZE_OFFSET = 0xC;
43 static const int PSMF_FIRST_TIMESTAMP_OFFSET = 0x54;
44 static const int PSMF_LAST_TIMESTAMP_OFFSET = 0x5A;
45 
46 static const int PSMF_VIDEO_STREAM_ID = 0xE0;
47 static const int PSMF_AUDIO_STREAM_ID = 0xBD;
48 
49 struct SceMpegAu {
50 	s64_le pts;  // presentation time stamp
51 	s64_le dts;  // decode time stamp
52 	u32_le esBuffer;  // WARNING: We abuse this to keep track of the stream number!
53 	u32_le esSize;
54 
55 	void read(u32 addr);
56 	void write(u32 addr);
57 };
58 
59 // As native in PSP ram
60 struct SceMpegRingBuffer {
61 	// PSP info
62 	s32_le packets;
63 	// Misused: this is used as total read, but should be read offset (within ring.)
64 	s32_le packetsRead;
65 	s32_le packetsWritePos;
66 	s32_le packetsAvail; // pspsdk: unk2, noxa: iUnk0
67 	s32_le packetSize; // 2048
68 	u32_le data; // address, ring buffer
69 	u32_le callback_addr; // see sceMpegRingbufferPut
70 	s32_le callback_args;
71 	s32_le dataUpperBound;
72 	s32_le semaID; // unused?
73 	u32_le mpeg; // pointer to mpeg struct, fixed up in sceMpegCreate
74 	// Note: not available in all versions.
75 	u32_le gp;
76 };
77 
78 void __MpegInit();
79 void __MpegDoState(PointerWrap &p);
80 void __MpegShutdown();
81 
82 void __MpegLoadModule(int version);
83 
84 void Register_sceMpeg();
85 
86 void Register_sceMpegbase();
87 
88 void __VideoPmpInit();
89 void __VideoPmpDoState(PointerWrap &p);
90 void __VideoPmpShutdown();
91