NetSurf
dt_sound.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \file
20 * DataTypes sound handler (implementation)
21*/
22
23#ifdef WITH_AMIGA_DATATYPES
24#include "amiga/os3support.h"
25
26#include <string.h>
27
28#include <proto/datatypes.h>
29#include <proto/dos.h>
30#include <proto/intuition.h>
31#include <datatypes/soundclass.h>
32#include <intuition/classusr.h>
33
34#include "utils/log.h"
35#include "utils/messages.h"
36#include "netsurf/plotters.h"
37#include "netsurf/content.h"
38#include "html/box.h"
39#include "content/llcache.h"
42
43#include "amiga/filetype.h"
44#include "amiga/datatypes.h"
45
46
47typedef struct amiga_dt_sound_content {
48 struct content base;
49
50 Object *dto;
51 bool immediate;
52} amiga_dt_sound_content;
53
54static nserror amiga_dt_sound_create(const content_handler *handler,
55 lwc_string *imime_type, const struct http_parameter *params,
57 bool quirks, struct content **c);
58static bool amiga_dt_sound_convert(struct content *c);
59static void amiga_dt_sound_destroy(struct content *c);
60static bool amiga_dt_sound_redraw(struct content *c,
61 struct content_redraw_data *data, const struct rect *clip,
62 const struct redraw_context *ctx);
63static nserror amiga_dt_sound_open(struct content *c, struct browser_window *bw,
64 struct content *page, struct object_params *params);
65static nserror amiga_dt_sound_clone(const struct content *old, struct content **newc);
66static content_type amiga_dt_sound_content_type(void);
67
68static const content_handler amiga_dt_sound_content_handler = {
69 .create = amiga_dt_sound_create,
70 .data_complete = amiga_dt_sound_convert,
71 .destroy = amiga_dt_sound_destroy,
72 .redraw = amiga_dt_sound_redraw,
73 .open = amiga_dt_sound_open,
74 .clone = amiga_dt_sound_clone,
75 .type = amiga_dt_sound_content_type,
76 .no_share = false,
77};
78
79
80static void amiga_dt_sound_play(Object *dto)
81{
82 NSLOG(netsurf, INFO, "Playing...");
83 IDoMethod(dto, DTM_TRIGGER, NULL, STM_PLAY, NULL);
84}
85
86
87nserror amiga_dt_sound_init(void)
88{
89 struct DataType *dt, *prevdt = NULL;
90 lwc_string *type;
91 nserror error;
92 struct Node *node = NULL;
93
94 while((dt = ObtainDataType(DTST_RAM, NULL,
95 DTA_DataType, prevdt,
96 DTA_GroupID, GID_SOUND,
97 TAG_DONE)) != NULL)
98 {
99 ReleaseDataType(prevdt);
100 prevdt = dt;
101
102 do {
103 node = ami_mime_from_datatype(dt, &type, node);
104
105 if(node)
106 {
108 lwc_string_data(type),
109 &amiga_dt_sound_content_handler);
110
111 if (error != NSERROR_OK)
112 return error;
113 }
114
115 }while (node != NULL);
116
117 }
118
119 ReleaseDataType(prevdt);
120
121 return NSERROR_OK;
122}
123
124nserror amiga_dt_sound_create(const content_handler *handler,
125 lwc_string *imime_type, const struct http_parameter *params,
126 llcache_handle *llcache, const char *fallback_charset,
127 bool quirks, struct content **c)
128{
129 amiga_dt_sound_content *plugin;
130 nserror error;
131
132 NSLOG(netsurf, INFO, "amiga_dt_sound_create");
133
134 plugin = calloc(1, sizeof(amiga_dt_sound_content));
135 if (plugin == NULL)
136 return NSERROR_NOMEM;
137
138 error = content__init(&plugin->base, handler, imime_type, params,
139 llcache, fallback_charset, quirks);
140 if (error != NSERROR_OK) {
141 free(plugin);
142 return error;
143 }
144
145 *c = (struct content *) plugin;
146
147 return NSERROR_OK;
148}
149
150bool amiga_dt_sound_convert(struct content *c)
151{
152 NSLOG(netsurf, INFO, "amiga_dt_sound_convert");
153
154 amiga_dt_sound_content *plugin = (amiga_dt_sound_content *) c;
155 int width = 50, height = 50;
156 const uint8_t *data;
157 size_t size;
158
159 data = content__get_source_data(c, &size);
160
161 plugin->dto = NewDTObject(NULL,
162 DTA_SourceType, DTST_MEMORY,
163 DTA_SourceAddress, data,
164 DTA_SourceSize, size,
165 DTA_GroupID, GID_SOUND,
166 TAG_DONE);
167
168 if(plugin->dto == NULL) return false;
169
170 c->width = width;
171 c->height = height;
172
173 if(plugin->immediate == true) amiga_dt_sound_play(plugin->dto);
174
177
178 content_set_status(c, "");
179 return true;
180}
181
182void amiga_dt_sound_destroy(struct content *c)
183{
184 amiga_dt_sound_content *plugin = (amiga_dt_sound_content *) c;
185
186 NSLOG(netsurf, INFO, "amiga_dt_sound_destroy");
187
188 DisposeDTObject(plugin->dto);
189
190 return;
191}
192
193bool amiga_dt_sound_redraw(struct content *c,
194 struct content_redraw_data *data, const struct rect *clip,
195 const struct redraw_context *ctx)
196{
197 plot_style_t pstyle = {
199 .fill_colour = 0xffffff,
200 .stroke_colour = 0x000000,
201 .stroke_width = plot_style_int_to_fixed(1),
202 };
203 struct rect rect;
204
205 NSLOG(netsurf, INFO, "amiga_dt_sound_redraw");
206
207 rect.x0 = data->x;
208 rect.y0 = data->y;
209 rect.x1 = data->x + data->width;
210 rect.y1 = data->y + data->height;
211
212 /* this should be some sort of play/stop control */
213
214 ctx->plot->rectangle(ctx, &pstyle, &rect);
215
216 return (ctx->plot->text(ctx,
218 data->x,
219 data->y+20,
220 lwc_string_data(content__get_mime_type(c)),
221 lwc_string_length(content__get_mime_type(c))) == NSERROR_OK);
222
223}
224
225
226nserror amiga_dt_sound_open(struct content *c, struct browser_window *bw,
227 struct content *page, struct object_params *params)
228{
229 amiga_dt_sound_content *plugin = (amiga_dt_sound_content *) c;
230 struct object_param *param;
231
232 NSLOG(netsurf, INFO, "amiga_dt_sound_open");
233
234 plugin->immediate = false;
235
236 if(params && (param = params->params))
237 {
238 do
239 {
240 NSLOG(netsurf, INFO, "%s = %s", param->name,
241 param->value);
242 if((strcmp(param->name, "autoplay") == 0) &&
243 (strcmp(param->value, "true") == 0)) plugin->immediate = true;
244 if((strcmp(param->name, "autoStart") == 0) &&
245 (strcmp(param->value, "1") == 0)) plugin->immediate = true;
246 param = param->next;
247 } while(param != NULL);
248 }
249
250 if(plugin->dto && (plugin->immediate == true))
251 amiga_dt_sound_play(plugin->dto);
252
253 return NSERROR_OK;
254}
255
256
257nserror amiga_dt_sound_clone(const struct content *old, struct content **newc)
258{
259 amiga_dt_sound_content *plugin;
260 nserror error;
261
262 NSLOG(netsurf, INFO, "amiga_dt_sound_clone");
263
264 plugin = calloc(1, sizeof(amiga_dt_sound_content));
265 if (plugin == NULL)
266 return NSERROR_NOMEM;
267
268 error = content__clone(old, &plugin->base);
269 if (error != NSERROR_OK) {
270 content_destroy(&plugin->base);
271 return error;
272 }
273
274 /* We "clone" the old content by replaying conversion */
275 if (old->status == CONTENT_STATUS_READY ||
276 old->status == CONTENT_STATUS_DONE) {
277 if (amiga_dt_sound_convert(&plugin->base) == false) {
278 content_destroy(&plugin->base);
280 }
281 }
282
283 *newc = (struct content *) plugin;
284
285 return NSERROR_OK;
286}
287
288content_type amiga_dt_sound_content_type(void)
289{
290 return CONTENT_PLUGIN;
291}
292
293#endif
struct Node * ami_mime_from_datatype(struct DataType *dt, lwc_string **mimetype, struct Node *start_node)
Return a MIME Type matching a DataType.
Definition: filetype.c:455
Box interface.
void content_destroy(struct content *c)
Destroy and free a content.
Definition: content.c:354
lwc_string * content__get_mime_type(struct content *c)
Retrieve mime-type of content.
Definition: content.c:1080
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Definition: content.c:299
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
Definition: content.c:190
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
Definition: content.c:1216
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
Definition: content.c:1382
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:285
void content_set_status(struct content *c, const char *status_message)
Updates content with new status.
Definition: content.c:270
nserror content_factory_register_handler(const char *mime_type, const content_handler *handler)
Register a handler with the content factory.
Protected interface to Content handling.
@ CONTENT_STATUS_READY
Some parts of content still being loaded, but can be displayed.
Definition: content_type.h:92
@ CONTENT_STATUS_DONE
Content has completed all processing.
Definition: content_type.h:95
content_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_PLUGIN
Navigator API Plugins.
Definition: content_type.h:70
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_CLONE_FAILED
Failed to clone handle.
Definition: errors.h:37
@ NSERROR_OK
No error.
Definition: errors.h:30
const char * type
Definition: filetype.cpp:44
Public content interface.
Target independent plotting interface.
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
Low-level resource cache (interface)
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Localised message support (interface).
Minimal compatibility header for AmigaOS 3.
#define IDoMethod
Definition: os3support.h:169
plot_font_style_t const *const plot_style_font
Definition: plot_style.c:165
#define plot_style_int_to_fixed(v)
Definition: plot_style.h:51
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67
@ base
Definition: punycode.c:19
int width
Definition: gui.c:160
int height
Definition: gui.c:161
Interface to utility string handling.
Browser window data.
Content operation function table.
nserror(* create)(const struct content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
parameters to content redraw
Definition: content.h:40
int height
vertical dimension
Definition: content.h:48
int y
coordinate for top-left of redraw
Definition: content.h:42
int x
coordinate for top-left of redraw
Definition: content.h:41
int width
dimensions to render content at (for scaling contents with intrinsic dimensions)
Definition: content.h:47
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
int height
Height dimension, if applicable.
char * fallback_charset
Fallback charset, or NULL.
int width
Width dimension, if applicable.
const struct content_handler * handler
Handler for content.
content_status status
Current status.
unsigned int size
Estimated size of all data associated with this content.
Representation of an HTTP parameter.
Definition: parameter.c:31
Handle to low-level cache object.
Definition: llcache.c:76
Linked list of object element parameters.
Definition: box.h:152
char * value
Definition: box.h:154
struct object_param * next
Definition: box.h:157
char * name
Definition: box.h:153
Parameters for object element and similar elements.
Definition: box.h:164
struct object_param * params
Definition: box.h:170
Plot style for stroke/fill plotters.
Definition: plot_style.h:76
plot_operation_type_t fill_type
Fill plot type.
Definition: plot_style.h:80
nserror(* text)(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plotters.h:278
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
Definition: plotters.h:188
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
const struct plotter_table * plot
Current plot operation table.
Definition: plotters.h:73
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357