Skip to content

Commit

Permalink
merged SACD Daemon into SACD Ripper
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 3, 2012
1 parent eb7bc0e commit c512456
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 1,366 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lrsx -lgcm_sys -lio -lsysmodule -lsysutil -lrt -llv2 -lm -lunself -lpatchutils -lsacd -lsysfs -lcommon -lid3 -lz -liconv -lnet
LIBS := -lrsx -lgcm_sys -lio -lsysmodule -lsysutil -lrt -llv2 -lm -lunself -lpatchutils -lsacd -lsysfs -lcommon -lid3 -lz -liconv -lnet -lnetctl

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
1 change: 1 addition & 0 deletions libs/libcommon/sys/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern "C" {
#define GPCMD_READ_TOC_PMA_ATIP 0x43
#define GPCMD_REPORT_KEY 0xa4
#define GPCMD_SEND_KEY 0xa3
#define GPCMD_START_STOP_UNIT 0x1b

#define LV2_STORAGE_SEND_ATAPI_COMMAND (1)

Expand Down
17 changes: 17 additions & 0 deletions libs/libsacd/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
#include <sys/storage.h>
#include "ioctl.h"

int ioctl_eject(int fd)
{
int res;
struct lv2_atapi_cmnd_block atapi_cmnd;
static uint8_t buffer[256];
memset(buffer, 0, sizeof(buffer));

sys_storage_init_atapi_cmnd(&atapi_cmnd, 0, ATAPI_PIO_DATA_OUT_PROTO, ATAPI_DIR_WRITE);

atapi_cmnd.pkt[0] = GPCMD_START_STOP_UNIT;
atapi_cmnd.pkt[4] = 0x02; /* eject */

res = sys_storage_send_atapi_command(fd, &atapi_cmnd, buffer);

return res;
}

int ioctl_get_configuration(int fd, uint8_t *buffer)
{
int res;
Expand Down
1 change: 1 addition & 0 deletions libs/libsacd/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
extern "C" {
#endif

extern int ioctl_eject(int fd);
extern int ioctl_init(int fd, uint8_t *buffer);
extern int ioctl_enable_encryption(int fd, uint8_t *buffer, uint32_t lba);
extern int ioctl_get_configuration(int fd, uint8_t *buffer);
Expand Down
39 changes: 38 additions & 1 deletion libs/libsacd/sacd_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ uint32_t (*sacd_input_total_sectors)(sacd_input_t);
struct sacd_input_s
{
int fd;
uint8_t *input_buffer;
#if defined(__lv2ppu__)
device_info_t device_info;
#endif
Expand Down Expand Up @@ -339,6 +340,13 @@ static sacd_input_t sacd_net_input_open(const char *target)
return NULL;
}

dev->input_buffer = (uint8_t *) malloc(MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE + 1024);
if (dev->input_buffer == NULL)
{
fprintf(stderr, "libsacdread: Could not allocate memory.\n");
goto error;
}

socket_open();

socket_create(&dev->fd, AF_INET, SOCK_STREAM, 0);
Expand Down Expand Up @@ -380,6 +388,7 @@ static sacd_input_t sacd_net_input_open(const char *target)
error:

sacd_input_close(dev);
free(dev->input_buffer);
free(dev);

return 0;
Expand Down Expand Up @@ -425,6 +434,10 @@ static int sacd_net_input_close(sacd_input_t dev)

socket_destroy(&dev->fd);
socket_close();
if (dev->input_buffer)
{
free(dev->input_buffer);
}
free(dev);

return 0;
Expand Down Expand Up @@ -505,12 +518,36 @@ static ssize_t sacd_net_input_read(sacd_input_t dev, int pos, int blocks, void *
return 0;
}

#if 0
response.data.bytes = buffer;
{
size_t got;
uint8_t *buf_ptr = dev->input_buffer;
size_t buf_left = blocks * SACD_LSN_SIZE + 16;

input = pb_istream_from_buffer(dev->input_buffer, MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE + 1024);

if (socket_recv(&dev->fd, (char *) buf_ptr, buf_left, &got, MSG_PARTIAL, 0) != IO_DONE)
return 0;

while(got > 0 && !pb_decode(&input, ServerResponse_fields, &response))
{
buf_ptr += got;
buf_left -= got;

if (socket_recv(&dev->fd, (char *) buf_ptr, buf_left, &got, MSG_PARTIAL, 0) != IO_DONE)
return 0;

input = pb_istream_from_buffer(dev->input_buffer, MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE + 1024);
}
}
#else
response.data.bytes = buffer;
if (!pb_decode(&input, ServerResponse_fields, &response))
{
return 0;
}

#endif
if (response.type != ServerResponse_Type_DISC_READ)
{
return 0;
Expand Down
136 changes: 128 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include <sys/thread.h>
#include <sys/spu.h>

#include <net/net.h>
#include <net/netctl.h>

#include <sys/storage.h>
#include <ioctl.h>
#include <patch-utils.h>
Expand All @@ -52,9 +55,11 @@
#include "exit_handler.h"
#include "install.h"
#include "output_device.h"
#include "server.h"
#include "ripping.h"

#include <logging.h>
#include <version.h>

#define MAX_PHYSICAL_SPU 6
#define MAX_RAW_SPU 1
Expand Down Expand Up @@ -278,6 +283,58 @@ static void bd_insert_disc_callback(uint32_t disc_type, char *title_id)
}
}

void server_loop(void)
{
int client_connected;
msgType dialog_type;
char *message = (char *) malloc(512);

// did the disc change?
if (bd_contains_sacd_disc && bd_disc_changed)
{
bd_contains_sacd_disc = 0;
}

// by default we have no user controls
dialog_type = (MSG_DIALOG_NORMAL | MSG_DIALOG_DISABLE_CANCEL_ON);

if (!bd_contains_sacd_disc)
{
union net_ctl_info info;

if(netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info) == 0)
{
sprintf(message, " SACD Daemon %s\n\n"
"Status: Active\n"
"IP Address: %s (port 2002)\n"
"Client: %s\n"
"Disc: %s",
SACD_RIPPER_VERSION_STRING, info.ip_address,
(is_client_connected() ? "connected" : "none"),
(bd_disc_changed == -1 ? "empty" : "inserted"));
}
else
{
sprintf(message, "No active network connection was detected.\n\nPress OK to refresh.");
dialog_type |= MSG_DIALOG_BTN_TYPE_OK;
}
}

msgDialogOpen2(dialog_type, message, dialog_handler, NULL, NULL);

dialog_action = 0;
bd_disc_changed = 0;
client_connected = is_client_connected();
while (!dialog_action && !user_requested_exit() && bd_disc_changed == 0 && client_connected == is_client_connected())
{
sysUtilCheckCallback();
flip();
}
msgDialogAbort();

free(message);
}

void main_loop(void)
{
msgType dialog_type;
Expand Down Expand Up @@ -498,16 +555,37 @@ void show_version(void)
msgDialogAbort();
}

int user_select_server_mode(void)
{
msgType dialog_type = (MSG_DIALOG_NORMAL | MSG_DIALOG_BTN_TYPE_YESNO | MSG_DIALOG_DISABLE_CANCEL_ON);
msgDialogOpen2(dialog_type, "Would you like to run in server mode?", dialog_handler, NULL, NULL);
msgDialogClose(5000.0f);

dialog_action = 0;
while (!dialog_action && !user_requested_exit())
{
sysUtilCheckCallback();
flip();
}
msgDialogAbort();

return dialog_action != 2;
}

int main(int argc, char *argv[])
{
int ret;
int ret, server_mode;
void *host_addr = memalign(1024 * 1024, HOST_SIZE);
msgType dialog_type;
sys_ppu_thread_t id; // start server thread

load_modules();

init_logging();

netInitialize();
netCtlInit();

// Initialize SPUs
LOG(lm_main, LOG_DEBUG, ("Initializing SPUs\n"));
ret = sysSpuInitialize(MAX_PHYSICAL_SPU, MAX_RAW_SPU);
Expand Down Expand Up @@ -592,19 +670,60 @@ int main(int argc, char *argv[])
sys_storage_reset_bd();
sys_storage_authenticate_bd();

// eject current disc
{
int fd;
ret = sys_storage_open(BD_DEVICE, &fd);
if (ret == 0)
{
ioctl_eject(fd);
sys_storage_close(fd);
}
}

ret = sysDiscRegisterDiscChangeCallback(&bd_eject_disc_callback, &bd_insert_disc_callback);

// poll for an output_device
poll_output_devices();

while (1)
{
// main loop
main_loop();
server_mode = user_select_server_mode();

// break out of the loop when requested
if (user_requested_exit())
break;
if (user_requested_exit())
goto quit;

if (server_mode)
{
#ifdef ENABLE_LOGGING
if (output_device)
{
char file_path[100];
sprintf(file_path, "%s/daemon_log.txt", output_device);
set_log_file(file_path);
}
#endif
sysThreadCreate(&id, listener_thread, NULL, 1500, 0x400, 0, "listener");

while (1)
{
// server loop
server_loop();

// break out of the loop when requested
if (user_requested_exit())
break;
}
}
else
{
while (1)
{
// main loop
main_loop();

// break out of the loop when requested
if (user_requested_exit())
break;
}
}

ret = sysDiscUnregisterDiscChangeCallback();
Expand All @@ -614,6 +733,7 @@ int main(int argc, char *argv[])
unpatch_lv1_ss_services();

destroy_logging();
netDeinitialize();
unload_modules();

free(host_addr);
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGETS := analysis_dump sacd_daemon
TARGETS := analysis_dump

all:
@for TARGET in $(TARGETS); do $(MAKE) --no-print-directory -C $$TARGET; done
Expand Down
Loading

0 comments on commit c512456

Please sign in to comment.