mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Added appletCreateMovieMaker. Added support for grc MovieMaker. Improved grc docs.
This commit is contained in:
parent
e7209bbcf5
commit
318f2b33b6
@ -1476,6 +1476,14 @@ Result appletGetPreviousProgramIndex(s32 *programIndex);
|
||||
*/
|
||||
Result appletGetGpuErrorDetectedSystemEvent(Event *out_event);
|
||||
|
||||
/**
|
||||
* @brief CreateMovieMaker. Do not use this directly, use \ref grcCreateMovieMaker instead.
|
||||
* @note Only available with AppletType_*Application on [5.0.0+].
|
||||
* @param[out] srv_out Output Service for applet IMovieMaker.
|
||||
* @param[in] tmem TransferMemory
|
||||
*/
|
||||
Result appletCreateMovieMaker(Service* srv_out, TransferMemory *tmem);
|
||||
|
||||
/**
|
||||
* @brief Launches the jit-sysmodule when it was not previously launched by this cmd. Returns 0 when it was previously launched.
|
||||
* @note Only available with AppletType_*Application on [5.0.0+].
|
||||
|
@ -10,18 +10,7 @@
|
||||
#include "../services/caps.h"
|
||||
#include "../kernel/event.h"
|
||||
#include "../kernel/tmem.h"
|
||||
|
||||
/// GameMovieTrimmer
|
||||
typedef struct {
|
||||
Service s; ///< IGameMovieTrimmer
|
||||
TransferMemory tmem; ///< TransferMemory
|
||||
} GrcGameMovieTrimmer;
|
||||
|
||||
/// GameMovieId
|
||||
typedef struct {
|
||||
CapsAlbumEntryId album_id; ///< \ref CapsAlbumEntryId
|
||||
u8 reserved[0x28]; ///< Unused, always zero.
|
||||
} GrcGameMovieId;
|
||||
#include "../display/native_window.h"
|
||||
|
||||
/// Stream type values for \ref grcdRead.
|
||||
typedef enum {
|
||||
@ -29,7 +18,58 @@ typedef enum {
|
||||
GrcStream_Audio = 1, ///< Audio stream with PcmFormat_Int16, 2 channels, and samplerate = 48000Hz. Official sw uses buffer size 0x1000.
|
||||
} GrcStream;
|
||||
|
||||
// Trimming
|
||||
/// GameMovieTrimmer
|
||||
typedef struct {
|
||||
Service s; ///< IGameMovieTrimmer
|
||||
TransferMemory tmem; ///< TransferMemory
|
||||
} GrcGameMovieTrimmer;
|
||||
|
||||
/// IMovieMaker
|
||||
typedef struct {
|
||||
Service a; ///< applet IMovieMaker
|
||||
Service s; ///< grc IMovieMaker
|
||||
Service video_proxy; ///< IHOSBinderDriver VideoProxy
|
||||
Event recording_event; ///< Output Event from GetOffscreenLayerRecordingFinishReadyEvent with autoclear=false.
|
||||
Event audio_event; ///< Output Event from GetOffscreenLayerAudioEncodeReadyEvent with autoclear=false.
|
||||
TransferMemory tmem; ///< TransferMemory
|
||||
NWindow win; ///< \ref NWindow
|
||||
u64 layer_handle; ///< LayerHandle
|
||||
bool layer_open; ///< Whether OpenOffscreenLayer was used successfully, indicating that CloseOffscreenLayer should be used during \ref grcMovieMakerClose.
|
||||
bool started_flag; ///< Whether \ref grcMovieMakerStart was used successfully. This is also used by \ref grcMovieMakerAbort.
|
||||
} GrcMovieMaker;
|
||||
|
||||
/// GameMovieId
|
||||
typedef struct {
|
||||
CapsAlbumEntryId album_id; ///< \ref CapsAlbumEntryId
|
||||
u8 reserved[0x28]; ///< Unused, always zero.
|
||||
} GrcGameMovieId;
|
||||
|
||||
/// OffscreenRecordingParameter
|
||||
typedef struct {
|
||||
u8 unk_x0[0x10]; ///< Unknown. Default value is 0.
|
||||
u32 unk_x10; ///< Unknown. Default value is 0x103.
|
||||
|
||||
s32 video_bitrate; ///< VideoBitRate. Default value is 8000000.
|
||||
s32 video_width; ///< VideoWidth. Default value is 1280.
|
||||
s32 video_height; ///< VideoHeight. Default value is 720.
|
||||
s32 video_framerate; ///< VideoFrameRate. Default value is 30.
|
||||
s32 video_keyFrameInterval; ///< VideoKeyFrameInterval. Default value is 30.
|
||||
|
||||
s32 audio_bitrate; ///< AudioBitRate. Default value is 128000 ([5.0.0-5.1.0] 1536000).
|
||||
s32 audio_samplerate; ///< AudioSampleRate. Default value is 48000.
|
||||
s32 audio_channel_count; ///< AudioChannelCount. Default value is 2.
|
||||
s32 audio_sample_format; ///< \ref PcmFormat AudioSampleFormat. Default value is PcmFormat_Int16.
|
||||
|
||||
s32 video_imageOrientation; ///< \ref AlbumImageOrientation VideoImageOrientation. Default value is ::AlbumImageOrientation_Unknown0.
|
||||
|
||||
u8 unk_x3c[0x44]; ///< Unknown. Default value is 0.
|
||||
} GrcOffscreenRecordingParameter;
|
||||
|
||||
/// Default size for \ref grcCreateMovieMaker, this is the size used by official sw.
|
||||
#define GRC_MOVIEMAKER_WORKMEMORY_SIZE_DEFAULT 0x6000000
|
||||
|
||||
///@name Trimming
|
||||
///@{
|
||||
|
||||
/**
|
||||
* @brief Creates a \ref GrcGameMovieTrimmer using \ref appletCreateGameMovieTrimmer, uses the cmds from it to trim the specified video, then closes it.
|
||||
@ -44,7 +84,90 @@ typedef enum {
|
||||
*/
|
||||
Result grcTrimGameMovie(GrcGameMovieId *dst_movieid, const GrcGameMovieId *src_movieid, size_t tmem_size, const void* thumbnail, s32 start, s32 end);
|
||||
|
||||
// grc:d
|
||||
///@}
|
||||
|
||||
///@name IMovieMaker
|
||||
///@{
|
||||
|
||||
/**
|
||||
* @brief Creates a \ref GrcOffscreenRecordingParameter with the default values, see \ref GrcOffscreenRecordingParameter for the default values.
|
||||
* @param[out] param \ref GrcOffscreenRecordingParameter
|
||||
*/
|
||||
void grcCreateOffscreenRecordingParameter(GrcOffscreenRecordingParameter *param);
|
||||
|
||||
/**
|
||||
* @brief Creates a \ref GrcMovieMaker using \ref appletCreateMovieMaker, and does the required initialization.
|
||||
* @note See \ref appletCreateMovieMaker for the requirements for using this.
|
||||
* @param[out] m \ref GrcMovieMaker
|
||||
* @param[in] size TransferMemory WorkMemory size. See \ref GRC_MOVIEMAKER_WORKMEMORY_SIZE_DEFAULT.
|
||||
*/
|
||||
Result grcCreateMovieMaker(GrcMovieMaker *m, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Closes a \ref GrcMovieMaker.
|
||||
* @note This also uses \ref grcMovieMakerAbort.
|
||||
* @param m \ref GrcMovieMaker
|
||||
*/
|
||||
void grcMovieMakerClose(GrcMovieMaker *m);
|
||||
|
||||
/**
|
||||
* @brief Gets the \ref NWindow for the specified MovieMaker.
|
||||
* @param m \ref GrcMovieMaker
|
||||
*/
|
||||
static inline NWindow* grcMovieMakerGetNWindow(GrcMovieMaker *m) {
|
||||
return &m->win;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts recording with the specified MovieMaker and \ref GrcOffscreenRecordingParameter.
|
||||
* @param m \ref GrcMovieMaker
|
||||
* @param[in] param \ref GrcOffscreenRecordingParameter
|
||||
*/
|
||||
Result grcMovieMakerStart(GrcMovieMaker *m, const GrcOffscreenRecordingParameter *param);
|
||||
|
||||
/**
|
||||
* @brief Aborts recording with the specified MovieMaker.
|
||||
* @note This is used automatically by \ref grcMovieMakerClose.
|
||||
* @note This will throw an error if \ref grcMovieMakerStart was not used previously, with the flag used for this being cleared afterwards on success.
|
||||
* @param m \ref GrcMovieMaker
|
||||
*/
|
||||
Result grcMovieMakerAbort(GrcMovieMaker *m);
|
||||
|
||||
/**
|
||||
* @brief Finishes recording with the specified MovieMaker.
|
||||
* @note This automatically uses \ref grcMovieMakerAbort on error.
|
||||
* @note The recorded video will not be accessible via the Album-applet since it's stored separately from other Album data.
|
||||
* @param m \ref GrcMovieMaker
|
||||
* @param width Width for the thumbnail, must be 1280.
|
||||
* @param height Height for the thumbnail, must be 720.
|
||||
* @param[in] appdata UserData input buffer for the JPEG thumbnail. Optional, can be NULL.
|
||||
* @param[in] appdata_size Size of the UserData input buffer. Optional, can be 0. Must be <=0x400.
|
||||
* @param[in] thumbnail RGBA8 image buffer containing the thumbnail. Optional, can be NULL.
|
||||
* @param[in] thumbnail_size Size of the thumbnail buffer. Optional, can be 0.
|
||||
* @param[out] entry Output \ref CapsApplicationAlbumEntry for the recorded video. Optional, can be NULL. Only available on [7.0.0+], if this is not NULL on pre-7.0.0 an error is thrown.
|
||||
*/
|
||||
Result grcMovieMakerFinish(GrcMovieMaker *m, s32 width, s32 height, const void* appdata, size_t appdata_size, const void* thumbnail, size_t thumbnail_size, CapsApplicationAlbumEntry *entry);
|
||||
|
||||
/**
|
||||
* @brief Gets the recording error with the specified MovieMaker.
|
||||
* @param m \ref GrcMovieMaker
|
||||
*/
|
||||
Result grcMovieMakerGetError(GrcMovieMaker *m);
|
||||
|
||||
/**
|
||||
* @brief Encodes audio sample data with the specified MovieMaker.
|
||||
* @note This waits on the event and uses the cmd repeatedly until the entire input buffer is handled.
|
||||
* @note If you don't use this the recorded video will be missing audio.
|
||||
* @param m \ref GrcMovieMaker
|
||||
* @param[in] buffer Audio buffer.
|
||||
* @param[in] size Size of the buffer.
|
||||
*/
|
||||
Result grcMovieMakerEncodeAudioSample(GrcMovieMaker *m, const void* buffer, size_t size);
|
||||
|
||||
///@}
|
||||
|
||||
///@name grc:d
|
||||
///@{
|
||||
|
||||
/// Initialize grc:d.
|
||||
Result grcdInitialize(void);
|
||||
@ -70,3 +193,5 @@ Result grcdBegin(void);
|
||||
*/
|
||||
Result grcdRead(GrcStream stream, void* buffer, size_t size, u32 *unk, u32 *data_size, u64 *timestamp);
|
||||
|
||||
///@}
|
||||
|
||||
|
@ -1321,6 +1321,46 @@ static Result _appletGetResolution(Service* srv, s32 *width, s32 *height, u64 cm
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _appletCreateMovieSession(Service* srv, Service* srv_out, u64 cmd_id, TransferMemory *tmem) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcSendHandleCopy(&c, tmem->handle);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 size;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->size = tmem->size;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && srv_out) {
|
||||
serviceCreateSubservice(srv_out, srv, &r, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
// ICommonStateGetter
|
||||
|
||||
static Result _appletReceiveMessage(u32 *out) {
|
||||
@ -4329,6 +4369,15 @@ Result appletGetGpuErrorDetectedSystemEvent(Event *out_event) {
|
||||
return _appletGetEvent(&g_appletIFunctions, out_event, 130, false);
|
||||
}
|
||||
|
||||
Result appletCreateMovieMaker(Service* srv_out, TransferMemory *tmem) {
|
||||
if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication())
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
if (hosversionBefore(5,0,0))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
|
||||
return _appletCreateMovieSession(&g_appletIFunctions, srv_out, 1000, tmem);
|
||||
}
|
||||
|
||||
Result appletPrepareForJit(void) {
|
||||
if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication())
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
@ -5218,43 +5267,7 @@ Result appletCreateGameMovieTrimmer(Service* srv_out, TransferMemory *tmem) {
|
||||
if (hosversionBefore(4,0,0))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcSendHandleCopy(&c, tmem->handle);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 size;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&g_appletILibraryAppletSelfAccessor, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 100;
|
||||
raw->size = tmem->size;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_appletILibraryAppletSelfAccessor);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&g_appletILibraryAppletSelfAccessor, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && srv_out) {
|
||||
serviceCreateSubservice(srv_out, &g_appletILibraryAppletSelfAccessor, &r, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
return _appletCreateMovieSession(&g_appletILibraryAppletSelfAccessor, srv_out, 100, tmem);
|
||||
}
|
||||
|
||||
Result appletReserveResourceForMovieOperation(void) {
|
||||
|
@ -7,7 +7,10 @@
|
||||
#include "kernel/tmem.h"
|
||||
#include "services/sm.h"
|
||||
#include "services/grc.h"
|
||||
#include "services/caps.h"
|
||||
#include "services/applet.h"
|
||||
#include "display/native_window.h"
|
||||
#include "audio/audio.h"
|
||||
#include "runtime/hosversion.h"
|
||||
|
||||
static void _grcGameMovieTrimmerClose(GrcGameMovieTrimmer *t);
|
||||
@ -44,6 +47,114 @@ static Result _grcCmdNoIO(Service* srv, u64 cmd_id) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcCmdInU64(Service* srv, u64 inval, u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 inval;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->inval = inval;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcCmdInU64Out32(Service* srv, u64 inval, u32 *out, u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 inval;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->inval = inval;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 out;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && out) *out = resp->out;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcCmdNoInOut64(Service* srv, u64 *out, u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 out;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && out) {
|
||||
*out = resp->out;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcGetEvent(Service* srv, Event* out_event, u64 cmd_id, bool autoclear) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
@ -80,6 +191,80 @@ static Result _grcGetEvent(Service* srv, Event* out_event, u64 cmd_id, bool auto
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcCmdInU64OutEvent(Service* srv, u64 inval, Event* out_event, u64 cmd_id, bool autoclear) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 inval;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
raw->inval = inval;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
eventLoadRemote(out_event, r.Handles[0], autoclear);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcGetSession(Service* srv, Service* srv_out, u64 cmd_id) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = cmd_id;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(srv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
serviceCreateSubservice(srv_out, srv, &r, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcCreateGameMovieTrimmer(GrcGameMovieTrimmer *t, size_t size) {
|
||||
Result rc=0;
|
||||
Result retryrc = MAKERESULT(212, 4);
|
||||
@ -260,6 +445,314 @@ Result grcTrimGameMovie(GrcGameMovieId *dst_movieid, const GrcGameMovieId *src_m
|
||||
return rc;
|
||||
}
|
||||
|
||||
// IMovieMaker
|
||||
|
||||
void grcCreateOffscreenRecordingParameter(GrcOffscreenRecordingParameter *param) {
|
||||
memset(param, 0, sizeof(*param));
|
||||
param->unk_x10 = 0x103;
|
||||
|
||||
param->video_bitrate = 8000000;
|
||||
param->video_width = 1280;
|
||||
param->video_height = 720;
|
||||
param->video_framerate = 30;
|
||||
param->video_keyFrameInterval = 30;
|
||||
|
||||
param->audio_bitrate = hosversionAtLeast(6,0,0) ? 128000 : 1536000;
|
||||
param->audio_samplerate = 48000;
|
||||
param->audio_channel_count = 2;
|
||||
param->audio_sample_format = PcmFormat_Int16;
|
||||
|
||||
param->video_imageOrientation = AlbumImageOrientation_Unknown0;
|
||||
}
|
||||
|
||||
Result grcCreateMovieMaker(GrcMovieMaker *m, size_t size) {
|
||||
Result rc=0;
|
||||
Result retryrc = MAKERESULT(212, 4);
|
||||
s32 binder_id=0;
|
||||
|
||||
memset(m, 0, sizeof(*m));
|
||||
|
||||
rc = tmemCreate(&m->tmem, size, Perm_None);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = appletCreateMovieMaker(&m->a, &m->tmem);
|
||||
|
||||
while(rc == retryrc) {
|
||||
svcSleepThread(100000000);
|
||||
rc = appletCreateMovieMaker(&m->a, &m->tmem);
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = _grcGetSession(&m->a, &m->s, 0); // GetGrcMovieMaker
|
||||
|
||||
if (R_SUCCEEDED(rc) && hosversionAtLeast(7,0,0)) rc = _grcCmdInU64(&m->s, capsGetShimLibraryVersion(), 9); // SetAlbumShimLibraryVersion
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = _grcCmdNoInOut64(&m->a, &m->layer_handle, 1); // GetLayerHandle
|
||||
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = _grcGetSession(&m->s, &m->video_proxy, 2); // CreateVideoProxy
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = _grcCmdInU64Out32(&m->s, m->layer_handle, (u32*)&binder_id, 10); // OpenOffscreenLayer
|
||||
if (R_SUCCEEDED(rc)) m->layer_open = true;
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = nwindowCreate(&m->win, &m->video_proxy, binder_id, false);
|
||||
if (R_SUCCEEDED(rc)) rc = nwindowSetDimensions(&m->win, 1280, 720);
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = _grcCmdInU64OutEvent(&m->s, m->layer_handle, &m->recording_event, 50, false); // GetOffscreenLayerRecordingFinishReadyEvent
|
||||
if (R_SUCCEEDED(rc)) rc = _grcCmdInU64OutEvent(&m->s, m->layer_handle, &m->audio_event, 52, false); // GetOffscreenLayerAudioEncodeReadyEvent
|
||||
|
||||
if (R_FAILED(rc)) grcMovieMakerClose(m);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void grcMovieMakerClose(GrcMovieMaker *m) {
|
||||
grcMovieMakerAbort(m);
|
||||
|
||||
eventClose(&m->audio_event);
|
||||
eventClose(&m->recording_event);
|
||||
|
||||
nwindowClose(&m->win);
|
||||
if (m->layer_open) {
|
||||
_grcCmdInU64(&m->s, m->layer_handle, 11); // CloseOffscreenLayer
|
||||
m->layer_open = false;
|
||||
}
|
||||
|
||||
serviceClose(&m->video_proxy);
|
||||
serviceClose(&m->s);
|
||||
serviceClose(&m->a);
|
||||
tmemClose(&m->tmem);
|
||||
}
|
||||
|
||||
Result grcMovieMakerStart(GrcMovieMaker *m, const GrcOffscreenRecordingParameter *param) {
|
||||
if (!serviceIsActive(&m->s))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 layer_handle;
|
||||
GrcOffscreenRecordingParameter param;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&m->s, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 24;
|
||||
raw->layer_handle = m->layer_handle;
|
||||
memcpy(&raw->param, param, sizeof(GrcOffscreenRecordingParameter));
|
||||
|
||||
Result rc = serviceIpcDispatch(&m->s);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&m->s, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) m->started_flag = true;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result grcMovieMakerAbort(GrcMovieMaker *m) {
|
||||
Result rc=0;
|
||||
|
||||
if (!serviceIsActive(&m->s))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
if (!m->started_flag)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
rc = _grcCmdInU64(&m->s, m->layer_handle, 21); // AbortOffscreenRecording
|
||||
if (R_SUCCEEDED(rc)) m->started_flag = false;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcMovieMakerCompleteOffscreenRecordingFinishEx0(GrcMovieMaker *m, s32 width, s32 height, const void* buffer0, size_t size0, const void* buffer1, size_t size1) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcAddSendBuffer(&c, buffer0, size0, BufferType_Normal);
|
||||
ipcAddSendBuffer(&c, buffer1, size1, BufferType_Normal);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
s32 width;
|
||||
s32 height;
|
||||
u64 layer_handle;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&m->s, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 25;
|
||||
raw->width = width;
|
||||
raw->height = height;
|
||||
raw->layer_handle = m->layer_handle;
|
||||
|
||||
Result rc = serviceIpcDispatch(&m->s);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
CapsApplicationAlbumEntry entry;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&m->s, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _grcMovieMakerCompleteOffscreenRecordingFinishEx1(GrcMovieMaker *m, s32 width, s32 height, const void* buffer0, size_t size0, const void* buffer1, size_t size1, CapsApplicationAlbumEntry *entry) {
|
||||
if (hosversionBefore(7,0,0))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcAddSendBuffer(&c, buffer0, size0, BufferType_Normal);
|
||||
ipcAddSendBuffer(&c, buffer1, size1, BufferType_Normal);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
s32 width;
|
||||
s32 height;
|
||||
u64 layer_handle;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&m->s, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 26;
|
||||
raw->width = width;
|
||||
raw->height = height;
|
||||
raw->layer_handle = m->layer_handle;
|
||||
|
||||
Result rc = serviceIpcDispatch(&m->s);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
CapsApplicationAlbumEntry entry;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&m->s, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && entry) *entry = resp->entry;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result grcMovieMakerFinish(GrcMovieMaker *m, s32 width, s32 height, const void* buffer0, size_t size0, const void* buffer1, size_t size1, CapsApplicationAlbumEntry *entry) {
|
||||
Result rc=0;
|
||||
|
||||
if (!serviceIsActive(&m->s))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
if (hosversionBefore(7,0,0) && entry)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
|
||||
rc = _grcCmdInU64(&m->s, m->layer_handle, 22); // RequestOffscreenRecordingFinishReady
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = eventWait(&m->recording_event, U64_MAX);
|
||||
|
||||
if (hosversionAtLeast(7,0,0))
|
||||
rc = _grcMovieMakerCompleteOffscreenRecordingFinishEx1(m, width, height, buffer0, size0, buffer1, size1, entry);
|
||||
else
|
||||
rc = _grcMovieMakerCompleteOffscreenRecordingFinishEx0(m, width, height, buffer0, size0, buffer1, size1);
|
||||
|
||||
if (R_FAILED(rc)) grcMovieMakerAbort(m);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result grcMovieMakerGetError(GrcMovieMaker *m) {
|
||||
if (!serviceIsActive(&m->s))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return _grcCmdInU64(&m->s, m->layer_handle, 30); // GetOffscreenLayerError
|
||||
}
|
||||
|
||||
static Result _grcMovieMakerEncodeOffscreenLayerAudioSample(GrcMovieMaker *m, const void* buffer, size_t size, u64 *out_size) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcAddSendBuffer(&c, buffer, size, BufferType_Normal);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 layer_handle;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&m->s, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 41;
|
||||
raw->layer_handle = m->layer_handle;
|
||||
|
||||
Result rc = serviceIpcDispatch(&m->s);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 out_size;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&m->s, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && out_size) *out_size = resp->out_size;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result grcMovieMakerEncodeAudioSample(GrcMovieMaker *m, const void* buffer, size_t size) {
|
||||
Result rc=0;
|
||||
u64 out_size=0;
|
||||
u8 *bufptr = (u8*)buffer;
|
||||
|
||||
if (!serviceIsActive(&m->s))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
for (u64 pos=0; size!=0; pos+=out_size, size-=out_size) {
|
||||
rc = eventWait(&m->audio_event, U64_MAX);
|
||||
if (R_FAILED(rc)) break;
|
||||
|
||||
rc = _grcMovieMakerEncodeOffscreenLayerAudioSample(m, &bufptr[pos], size, &out_size);
|
||||
if (R_FAILED(rc)) break;
|
||||
if (out_size > size) out_size = size;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
// grc:d
|
||||
|
||||
static Service g_grcdSrv;
|
||||
|
Loading…
Reference in New Issue
Block a user