1 /**
2 * @file media.c
3 *
4 * @brief Media data handling.
5 * @author David Suárez
6 * @author Chris Lightfoot
7 * @date Sun, 28 Oct 2018 16:14:56 +0100
8 *
9 * Copyright (c) 2002 Chris Lightfoot.
10 * Email: chris@ex-parrot.com; WWW: http://www.ex-parrot.com/~chris/
11 *
12 * Copyright (c) 2018 David Suárez.
13 * Email: david.sephirot@gmail.com
14 *
15 */
16
17 #include "compat/compat.h"
18
19 #include <string.h>
20 #include <sys/types.h>
21
22 #include "common/util.h"
23 #include "common/tmpdir.h"
24 #include "image.h"
25 #include "audio.h"
26 #include "http.h"
27 #include "playaudio.h"
28
29 #include "media.h"
30
31 static mediadrv_t media_drivers[NMEDIATYPES] = {
32 { "gif", MEDIATYPE_IMAGE, find_gif_image },
33 { "jpeg", MEDIATYPE_IMAGE, find_jpeg_image },
34 { "png", MEDIATYPE_IMAGE, find_png_image },
35 { "mpeg", MEDIATYPE_AUDIO, find_mpeg_stream },
36 { "HTTP", MEDIATYPE_TEXT, find_http_req }
37 };
38
39
get_drivers_for_mediatype(mediatype_t type)40 drivers_t* get_drivers_for_mediatype(mediatype_t type)
41 {
42 drivers_t* drivers = NULL;
43 int driver_count = 0;
44 int current_drv = 0;
45
46 for (int i = 0; i < NMEDIATYPES; ++i) {
47 if (media_drivers[i].type & type) {
48 driver_count++;
49 }
50 }
51
52 drivers = xmalloc(sizeof(drivers_t));
53
54 drivers->type = type;
55 drivers->count = driver_count;
56 drivers->list = xmalloc(sizeof(mediadrv_t*) * driver_count);
57
58 for (int i = 0; i < NMEDIATYPES; ++i) {
59 if (media_drivers[i].type & type) {
60 drivers->list[current_drv] = &media_drivers[i];
61 current_drv++;
62 }
63 }
64
65 return drivers;
66 }
67
close_media_drivers(drivers_t * drivers)68 void close_media_drivers(drivers_t* drivers)
69 {
70 if (drivers == NULL) {
71 return;
72 }
73
74 xfree(drivers->list);
75 xfree(drivers);
76 }
77