summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c77
1 files changed, 64 insertions, 13 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index ce4199a1d0..17695f4a6f 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -41,7 +41,8 @@ extern char iend[];
41 41
42struct plugin_api* rb; 42struct plugin_api* rb;
43 43
44#define BUFFER_SIZE 25*1024*1024 44/* The main buffer storing the compressed video data */
45#define BUFFER_SIZE (MEM-6)*1024*1024
45 46
46static mpeg2dec_t * mpeg2dec; 47static mpeg2dec_t * mpeg2dec;
47static vo_open_t * output_open = NULL; 48static vo_open_t * output_open = NULL;
@@ -49,8 +50,49 @@ static vo_instance_t * output;
49static int total_offset = 0; 50static int total_offset = 0;
50 51
51extern vo_open_t vo_rockbox_open; 52extern vo_open_t vo_rockbox_open;
53/* button definitions */
54#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
55#define MPEG_STOP BUTTON_OFF
56#define MPEG_PAUSE BUTTON_ON
52 57
53static void decode_mpeg2 (uint8_t * current, uint8_t * end) 58#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
59#define MPEG_STOP BUTTON_MENU
60#define MPEG_PAUSE BUTTON_PLAY
61
62#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
63#define MPEG_STOP BUTTON_POWER
64#define MPEG_PAUSE BUTTON_PLAY
65
66#else
67#error MPEGPLAYER: Unsupported keypad
68#endif
69static bool button_loop(void)
70{
71 int button = rb->button_get(false);
72 switch (button)
73 {
74 case MPEG_STOP:
75 return true;
76 case MPEG_PAUSE:
77 button = BUTTON_NONE;
78#ifdef HAVE_ADJUSTABLE_CPU_FREQ
79 rb->cpu_boost(false);
80#endif
81 do {
82 button = rb->button_get(true);
83 } while (button != MPEG_PAUSE);
84#ifdef HAVE_ADJUSTABLE_CPU_FREQ
85 rb->cpu_boost(true);
86#endif
87 break;
88 default:
89 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
90 return true;
91 }
92 return false;
93}
94
95static bool decode_mpeg2 (uint8_t * current, uint8_t * end)
54{ 96{
55 const mpeg2_info_t * info; 97 const mpeg2_info_t * info;
56 mpeg2_state_t state; 98 mpeg2_state_t state;
@@ -61,11 +103,13 @@ static void decode_mpeg2 (uint8_t * current, uint8_t * end)
61 103
62 info = mpeg2_info (mpeg2dec); 104 info = mpeg2_info (mpeg2dec);
63 while (1) { 105 while (1) {
106 if (button_loop())
107 return true;
64 state = mpeg2_parse (mpeg2dec); 108 state = mpeg2_parse (mpeg2dec);
65 109
66 switch (state) { 110 switch (state) {
67 case STATE_BUFFER: 111 case STATE_BUFFER:
68 return; 112 return false;
69 case STATE_SEQUENCE: 113 case STATE_SEQUENCE:
70 /* might set nb fbuf, convert format, stride */ 114 /* might set nb fbuf, convert format, stride */
71 /* might set fbufs */ 115 /* might set fbufs */
@@ -74,12 +118,12 @@ static void decode_mpeg2 (uint8_t * current, uint8_t * end)
74 info->sequence->chroma_width, 118 info->sequence->chroma_width,
75 info->sequence->chroma_height, &setup_result)) { 119 info->sequence->chroma_height, &setup_result)) {
76 //fprintf (stderr, "display setup failed\n"); 120 //fprintf (stderr, "display setup failed\n");
77 return; 121 return false;
78 } 122 }
79 if (setup_result.convert && 123 if (setup_result.convert &&
80 mpeg2_convert (mpeg2dec, setup_result.convert, NULL)) { 124 mpeg2_convert (mpeg2dec, setup_result.convert, NULL)) {
81 //fprintf (stderr, "color conversion setup failed\n"); 125 //fprintf (stderr, "color conversion setup failed\n");
82 return; 126 return false;
83 } 127 }
84 if (output->set_fbuf) { 128 if (output->set_fbuf) {
85 uint8_t * buf[3]; 129 uint8_t * buf[3];
@@ -140,21 +184,19 @@ static void decode_mpeg2 (uint8_t * current, uint8_t * end)
140 } 184 }
141} 185}
142 186
143static void es_loop (int in_file) 187static void es_loop (int in_file, uint8_t* buffer, size_t buffer_size)
144{ 188{
145 static uint8_t* buffer;
146 uint8_t * end; 189 uint8_t * end;
147 190
148 buffer=mpeg2_malloc(BUFFER_SIZE,0);
149
150 if (buffer==NULL) 191 if (buffer==NULL)
151 return; 192 return;
152 193
153 do { 194 do {
154 rb->splash(0,true,"Buffering..."); 195 rb->splash(0,true,"Buffering...");
155 end = buffer + rb->read (in_file, buffer, BUFFER_SIZE); 196 end = buffer + rb->read (in_file, buffer, buffer_size);
156 decode_mpeg2 (buffer, end); 197 if (decode_mpeg2 (buffer, end))
157 } while (end == buffer + BUFFER_SIZE); 198 break;
199 } while (end == buffer + buffer_size);
158} 200}
159 201
160enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 202enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
@@ -163,6 +205,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
163 void* audiobuf; 205 void* audiobuf;
164 int audiosize; 206 int audiosize;
165 int in_file; 207 int in_file;
208 uint8_t* buffer;
209 size_t buffer_size;
166 210
167 rb = api; 211 rb = api;
168 212
@@ -172,6 +216,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
172 /* Initialise our malloc buffer */ 216 /* Initialise our malloc buffer */
173 mpeg2_alloc_init(audiobuf,audiosize); 217 mpeg2_alloc_init(audiobuf,audiosize);
174 218
219 /* Grab most of the buffer for the compressed video - leave 2MB */
220 buffer_size = audiosize - 2*1024*1024;
221 buffer = mpeg2_malloc(buffer_size,0);
222
223 if (buffer == NULL)
224 return PLUGIN_ERROR;
225
175#ifdef USE_IRAM 226#ifdef USE_IRAM
176 rb->memcpy(iramstart, iramcopy, iramend-iramstart); 227 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
177 rb->memset(iedata, 0, iend - iedata); 228 rb->memset(iedata, 0, iend - iedata);
@@ -227,7 +278,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
227 rb->cpu_boost(true); 278 rb->cpu_boost(true);
228#endif 279#endif
229 280
230 es_loop (in_file); 281 es_loop (in_file, buffer, buffer_size);
231 282
232 mpeg2_close (mpeg2dec); 283 mpeg2_close (mpeg2dec);
233 284