forked from DC-SWAT/DreamShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.c
More file actions
151 lines (122 loc) · 3.41 KB
/
module.c
File metadata and controls
151 lines (122 loc) · 3.41 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* DreamShell ##version##
module.c - ffmpeg module
Copyright (C)2011-2014 SWAT
*/
#include "ds.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
DEFAULT_MODULE_HEADER(ffmpeg);
static int file_open(URLContext *h, const char *filename, int flags) {
file_t fd;
int _flags = 0;
char fn[MAX_FN_LEN];
char proto[32];
sscanf(filename, "%[a-zA-Z0-9_]:%s", proto, fn);
switch(flags) {
case URL_RDONLY:
_flags = O_RDONLY;
break;
case URL_WRONLY:
_flags = O_WRONLY;
break;
case URL_RDWR:
_flags = O_RDWR;
break;
default:
ds_printf("DS_ERROR_FFMPEG: Uknown file open flag: %08x\n", flags);
return -1;
}
if ((fd = fs_open(fn, _flags)) < 0) {
return -1;
}
h->priv_data = (void*)fd;
return 0;
}
static int file_read(URLContext *h, unsigned char *buf, int size) {
return fs_read((file_t)h->priv_data, buf, size);
}
static int file_write(URLContext *h, unsigned char *buf, int size) {
return fs_write((file_t)h->priv_data, buf, size);
}
static int64_t file_seek(URLContext *h, int64_t pos, int whence) {
if(whence == AVSEEK_SIZE) {
return fs_total((file_t)h->priv_data);
}
return fs_seek((file_t)h->priv_data, pos, whence);
}
static int file_close(URLContext *h) {
fs_close((file_t)h->priv_data);
return 0;
}
/*
static int file_read_pause(URLContext *h, int pause) {
return 0;
}
static int64_t file_read_seek(URLContext *h, int stream_index, int64_t timestamp, int flags) {
return 0;
}
*/
static int file_get_file_handle(URLContext *h) {
return (file_t)h->priv_data;
}
static URLProtocol fs_protocol = {
"ds",
file_open,
file_read,
file_write,
file_seek,
file_close,
NULL,
NULL,
NULL,
file_get_file_handle
};
int ffplay(const char *filename, const char *force_format);
//int sdl_ffplay(const char *filename);
int builtin_ffplay_cmd(int argc, char *argv[]) {
if(argc == 1) {
ds_printf("Usage: %s option args...\n\n"
"Options: \n"
" -v, --version -Show ffmpeg version\n"
//" -s, --sdl -Use SDL_ffmpeg (slow)\n"
" -p, --play -Start playing\n\n"
"Arguments: \n"
" -i --format -Force format detection\n"
" -f, --file -File for playing\n\n"
"Examples: %s -p -f /cd/file.avi\n", argv[0], argv[0]);
return CMD_NO_ARG;
}
int play = 0, /*use_sdl = 0, */ver = 0;
char *file = NULL, *format = NULL;
struct cfg_option options[] = {
{"play", 'p', NULL, CFG_BOOL, (void *) &play, 0},
//{"sdl", 's', NULL, CFG_BOOL, (void *) &use_sdl, 0},
{"version", 'v', NULL, CFG_BOOL, (void *) &ver, 0},
{"file", 'f', NULL, CFG_STR, (void *) &file, 0},
{"format", 'i', NULL, CFG_STR, (void *) &format, 0},
CFG_END_OF_LIST
};
CMD_DEFAULT_ARGS_PARSER(options);
if(ver) {
ds_printf("DS: ffmpeg v%d.%d.%d build %02x\n", VER_MAJOR, VER_MINOR, VER_MICRO, VER_BUILD);
}
if(play) {
//if(use_sdl) {
// sdl_ffplay(file);
//} else {
ffplay(file, format);
//}
}
return CMD_OK;
}
int lib_open(klibrary_t *lib) {
av_register_all();
av_register_protocol(&fs_protocol);
AddCmd("ffplay", "Video/Audio player via ffmpeg", (CmdHandler *) builtin_ffplay_cmd);
return nmmgr_handler_add(&ds_ffmpeg_hnd.nmmgr);
}
int lib_close(klibrary_t *lib) {
RemoveCmd(GetCmdByName("ffplay"));
return nmmgr_handler_remove(&ds_ffmpeg_hnd.nmmgr);
}