forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_file_transfer.c
131 lines (113 loc) · 3.49 KB
/
task_file_transfer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <file/nbio.h>
#include <compat/strl.h>
#include <retro_miscellaneous.h>
#include <string/stdstring.h>
#ifdef HAVE_AUDIOMIXER
#include "task_audio_mixer.h"
#endif
#include "task_file_transfer.h"
#include "tasks_internal.h"
bool task_image_load_handler(retro_task_t *task);
static int task_file_transfer_iterate_transfer(nbio_handle_t *nbio)
{
size_t i;
nbio->pos_increment = 5;
if (nbio->is_finished)
return 0;
for (i = 0; i < nbio->pos_increment; i++)
{
if (nbio_iterate(nbio->handle))
return -1;
}
return 0;
}
static int task_file_transfer_iterate_parse(nbio_handle_t *nbio)
{
if (nbio->cb)
{
int len = 0;
if (nbio->cb(nbio, len) == -1)
return -1;
}
return 0;
}
void task_file_load_handler(retro_task_t *task)
{
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
if (nbio)
{
switch (nbio->status)
{
case NBIO_STATUS_INIT:
if (nbio && !string_is_empty(nbio->path))
{
struct nbio_t *handle = (struct nbio_t*)nbio_open(nbio->path, NBIO_READ);
if (handle)
{
nbio->handle = handle;
nbio->status = NBIO_STATUS_TRANSFER;
nbio_begin_read(handle);
return;
}
task_set_cancelled(task, true);
}
break;
case NBIO_STATUS_TRANSFER_PARSE:
if (!nbio || task_file_transfer_iterate_parse(nbio) == -1)
task_set_cancelled(task, true);
nbio->status = NBIO_STATUS_TRANSFER_FINISHED;
break;
case NBIO_STATUS_TRANSFER:
if (!nbio || task_file_transfer_iterate_transfer(nbio) == -1)
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
break;
case NBIO_STATUS_TRANSFER_FINISHED:
break;
}
switch (nbio->type)
{
case NBIO_TYPE_PNG:
case NBIO_TYPE_JPEG:
case NBIO_TYPE_TGA:
case NBIO_TYPE_BMP:
if (!task_image_load_handler(task))
task_set_finished(task, true);
break;
case NBIO_TYPE_MP3:
case NBIO_TYPE_FLAC:
case NBIO_TYPE_OGG:
case NBIO_TYPE_MOD:
case NBIO_TYPE_WAV:
#ifdef HAVE_AUDIOMIXER
if (!task_audio_mixer_load_handler(task))
task_set_finished(task, true);
#endif
break;
case NBIO_TYPE_NONE:
default:
if (nbio->is_finished)
task_set_finished(task, true);
break;
}
}
if (task_get_cancelled(task))
{
task_set_error(task, strldup("Task canceled.", sizeof("Task canceled.")));
task_set_finished(task, true);
}
}