Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/mpeg3io.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/mpeg3io.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3io.c b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c new file mode 100644 index 0000000..c5807a7 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c | |||
@@ -0,0 +1,127 @@ | |||
1 | #include "mpeg3private.h" | ||
2 | #include "mpeg3protos.h" | ||
3 | |||
4 | #ifndef _WIN32 | ||
5 | #include <mntent.h> | ||
6 | #else | ||
7 | |||
8 | #endif | ||
9 | #include <sys/stat.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | mpeg3_fs_t* mpeg3_new_fs(char *path) | ||
14 | { | ||
15 | mpeg3_fs_t *fs = (mpeg3_fs_t*)calloc(1, sizeof(mpeg3_fs_t)); | ||
16 | fs->css = mpeg3_new_css(); | ||
17 | strcpy(fs->path, path); | ||
18 | return fs; | ||
19 | } | ||
20 | |||
21 | int mpeg3_delete_fs(mpeg3_fs_t *fs) | ||
22 | { | ||
23 | mpeg3_delete_css(fs->css); | ||
24 | free(fs); | ||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | int mpeg3_copy_fs(mpeg3_fs_t *dst, mpeg3_fs_t *src) | ||
29 | { | ||
30 | strcpy(dst->path, src->path); | ||
31 | dst->current_byte = 0; | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | long mpeg3io_get_total_bytes(mpeg3_fs_t *fs) | ||
36 | { | ||
37 | /* | ||
38 | * struct stat st; | ||
39 | * if(stat(fs->path, &st) < 0) return 0; | ||
40 | * return (long)st.st_size; | ||
41 | */ | ||
42 | |||
43 | fseek(fs->fd, 0, SEEK_END); | ||
44 | fs->total_bytes = ftell(fs->fd); | ||
45 | fseek(fs->fd, 0, SEEK_SET); | ||
46 | return fs->total_bytes; | ||
47 | } | ||
48 | |||
49 | int mpeg3io_open_file(mpeg3_fs_t *fs) | ||
50 | { | ||
51 | /* Need to perform authentication before reading a single byte. */ | ||
52 | mpeg3_get_keys(fs->css, fs->path); | ||
53 | |||
54 | if(!(fs->fd = fopen(fs->path, "rb"))) | ||
55 | { | ||
56 | perror("mpeg3io_open_file"); | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | fs->total_bytes = mpeg3io_get_total_bytes(fs); | ||
61 | |||
62 | if(!fs->total_bytes) | ||
63 | { | ||
64 | fclose(fs->fd); | ||
65 | return 1; | ||
66 | } | ||
67 | fs->current_byte = 0; | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | int mpeg3io_close_file(mpeg3_fs_t *fs) | ||
72 | { | ||
73 | if(fs->fd) fclose(fs->fd); | ||
74 | fs->fd = 0; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | int mpeg3io_read_data(unsigned char *buffer, long bytes, mpeg3_fs_t *fs) | ||
79 | { | ||
80 | int result = 0; | ||
81 | //printf("read %d bytes\n",bytes); | ||
82 | result = !fread(buffer, 1, bytes, fs->fd); | ||
83 | fs->current_byte += bytes; | ||
84 | return (result && bytes); | ||
85 | } | ||
86 | |||
87 | int mpeg3io_device(char *path, char *device) | ||
88 | { | ||
89 | struct stat file_st, device_st; | ||
90 | struct mntent *mnt; | ||
91 | FILE *fp; | ||
92 | |||
93 | if(stat(path, &file_st) < 0) | ||
94 | { | ||
95 | perror("mpeg3io_device"); | ||
96 | return 1; | ||
97 | } | ||
98 | |||
99 | #ifndef _WIN32 | ||
100 | fp = setmntent(MOUNTED, "r"); | ||
101 | while(fp && (mnt = getmntent(fp))) | ||
102 | { | ||
103 | if(stat(mnt->mnt_fsname, &device_st) < 0) continue; | ||
104 | if(device_st.st_rdev == file_st.st_dev) | ||
105 | { | ||
106 | strncpy(device, mnt->mnt_fsname, MPEG3_STRLEN); | ||
107 | break; | ||
108 | } | ||
109 | } | ||
110 | endmntent(fp); | ||
111 | #endif | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | int mpeg3io_seek(mpeg3_fs_t *fs, long byte) | ||
117 | { | ||
118 | fs->current_byte = byte; | ||
119 | return fseek(fs->fd, byte, SEEK_SET); | ||
120 | } | ||
121 | |||
122 | int mpeg3io_seek_relative(mpeg3_fs_t *fs, long bytes) | ||
123 | { | ||
124 | fs->current_byte += bytes; | ||
125 | return fseek(fs->fd, fs->current_byte, SEEK_SET); | ||
126 | } | ||
127 | |||