summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/mpeg_parser.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-05-16 14:41:00 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-05-16 14:41:00 +0000
commitb197c3b0d6bfcf3daae4a7b1cad415b1acea28f6 (patch)
tree1c7bce8c4bc39617ff819111d39a41370ca8f49b /apps/plugins/mpegplayer/mpeg_parser.c
parentcaa4f54e4235f99acd1c69673c85a4557b6183a9 (diff)
downloadrockbox-b197c3b0d6bfcf3daae4a7b1cad415b1acea28f6.tar.gz
rockbox-b197c3b0d6bfcf3daae4a7b1cad415b1acea28f6.zip
MPEGPlayer: Add a second layer of caching to help speed up byte-wise scanning and seeking a bit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26088 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/mpeg_parser.c')
-rw-r--r--apps/plugins/mpegplayer/mpeg_parser.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/apps/plugins/mpegplayer/mpeg_parser.c b/apps/plugins/mpegplayer/mpeg_parser.c
index 714f38ac09..f21292abd5 100644
--- a/apps/plugins/mpegplayer/mpeg_parser.c
+++ b/apps/plugins/mpegplayer/mpeg_parser.c
@@ -99,7 +99,7 @@ uint8_t * mpeg_parser_scan_start_code(struct stream_scan *sk, uint32_t code)
99 { 99 {
100 uint8_t *p; 100 uint8_t *p;
101 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET); 101 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
102 ssize_t len = disk_buf_getbuffer(4, &p, NULL, NULL); 102 ssize_t len = disk_buf_getbuffer_l2(&sk->l2, 4, (void **)&p);
103 103
104 if (pos < 0 || len < 4) 104 if (pos < 0 || len < 4)
105 break; 105 break;
@@ -131,7 +131,7 @@ unsigned mpeg_parser_scan_pes(struct stream_scan *sk)
131 { 131 {
132 uint8_t *p; 132 uint8_t *p;
133 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET); 133 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
134 ssize_t len = disk_buf_getbuffer(4, &p, NULL, NULL); 134 ssize_t len = disk_buf_getbuffer_l2(&sk->l2, 4, (void **)&p);
135 135
136 if (pos < 0 || len < 4) 136 if (pos < 0 || len < 4)
137 break; 137 break;
@@ -192,7 +192,7 @@ uint32_t mpeg_parser_scan_pts(struct stream_scan *sk, unsigned id)
192 { 192 {
193 uint8_t *p; 193 uint8_t *p;
194 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET); 194 off_t pos = disk_buf_lseek(sk->pos, SEEK_SET);
195 ssize_t len = disk_buf_getbuffer(35, &p, NULL, NULL); 195 ssize_t len = disk_buf_getbuffer_l2(&sk->l2, 30, (void **)&p);
196 196
197 if (pos < 0 || len < 4) 197 if (pos < 0 || len < 4)
198 break; 198 break;
@@ -201,7 +201,7 @@ uint32_t mpeg_parser_scan_pts(struct stream_scan *sk, unsigned id)
201 { 201 {
202 uint8_t *h = p; 202 uint8_t *h = p;
203 203
204 if (sk->margin < 6) 204 if (sk->margin < 7)
205 { 205 {
206 /* Insufficient data */ 206 /* Insufficient data */
207 } 207 }
@@ -215,29 +215,33 @@ uint32_t mpeg_parser_scan_pts(struct stream_scan *sk, unsigned id)
215 } 215 }
216 else /* mpeg1 */ 216 else /* mpeg1 */
217 { 217 {
218 ssize_t l = 7; 218 ssize_t l = 6;
219 ssize_t margin = sk->margin; 219 ssize_t margin = sk->margin;
220 220
221 /* Skip stuffing_byte */ 221 /* Skip stuffing_byte */
222 while (h[l - 1] == 0xff && ++l <= 23) 222 while (margin > 7 && h[l] == 0xff && ++l <= 22)
223 --margin; 223 --margin;
224 224
225 if ((h[l - 1] & 0xc0) == 0x40) 225 if (margin >= 7)
226 { 226 {
227 /* Skip STD_buffer_scale and STD_buffer_size */ 227 if ((h[l] & 0xc0) == 0x40)
228 margin -= 2; 228 {
229 l += 2; 229 /* Skip STD_buffer_scale and STD_buffer_size */
230 } 230 margin -= 2;
231 231 l += 2;
232 if (margin >= 4) 232 }
233 {
234 /* header points to the mpeg1 pes header */
235 h += l;
236 233
237 if ((h[-1] & 0xe0) == 0x20) 234 if (margin >= 5)
238 { 235 {
239 sk->data = (h + 4) - p; 236 /* Header points to the mpeg1 pes header */
240 return read_pts(h, -1); 237 h += l;
238
239 if ((h[0] & 0xe0) == 0x20)
240 {
241 /* PTS or PTS_DTS indicated */
242 sk->data = (h + 5) - p;
243 return read_pts(h, 0);
244 }
241 } 245 }
242 } 246 }
243 } 247 }
@@ -357,6 +361,8 @@ static off_t mpeg_parser_seek_PTS(uint32_t time, unsigned id)
357 enum state_enum state = STATE0; 361 enum state_enum state = STATE0;
358 struct stream_scan sk; 362 struct stream_scan sk;
359 363
364 stream_scan_init(&sk);
365
360 /* Initial estimate taken from average bitrate - later interpolations are 366 /* Initial estimate taken from average bitrate - later interpolations are
361 * taken similarly based on the remaining file interval */ 367 * taken similarly based on the remaining file interval */
362 pos_new = muldiv_uint32(time - time_left, pos_right - pos_left, 368 pos_new = muldiv_uint32(time - time_left, pos_right - pos_left,
@@ -564,6 +570,8 @@ static bool prepare_image(uint32_t time)
564 int tries; 570 int tries;
565 int result; 571 int result;
566 572
573 stream_scan_init(&sk);
574
567 if (!str_send_msg(&video_str, STREAM_NEEDS_SYNC, time)) 575 if (!str_send_msg(&video_str, STREAM_NEEDS_SYNC, time))
568 { 576 {
569 DEBUGF("Image was ready\n"); 577 DEBUGF("Image was ready\n");
@@ -734,7 +742,7 @@ static int parse_demux(struct stream *str, enum stream_parse_mode type)
734 str->hdr.pos = disk_buf_lseek(str->hdr.pos, SEEK_SET); 742 str->hdr.pos = disk_buf_lseek(str->hdr.pos, SEEK_SET);
735 743
736 if (str->hdr.pos < 0 || str->hdr.pos >= str->hdr.limit || 744 if (str->hdr.pos < 0 || str->hdr.pos >= str->hdr.limit ||
737 disk_buf_getbuffer(MIN_BUFAHEAD, &p, NULL, NULL) <= 0) 745 disk_buf_getbuffer(MIN_BUFAHEAD, (void **)&p, NULL, NULL) <= 0)
738 { 746 {
739 str_end_of_stream(str); 747 str_end_of_stream(str);
740 return STREAM_DATA_END; 748 return STREAM_DATA_END;
@@ -1009,7 +1017,7 @@ static int parse_elementary(struct stream *str, enum stream_parse_mode type)
1009 1017
1010 case STREAM_PM_RANDOM_ACCESS: 1018 case STREAM_PM_RANDOM_ACCESS:
1011 str->hdr.pos = disk_buf_lseek(str->hdr.pos, SEEK_SET); 1019 str->hdr.pos = disk_buf_lseek(str->hdr.pos, SEEK_SET);
1012 len = disk_buf_getbuffer(DISK_BUF_PAGE_SIZE, &p, NULL, NULL); 1020 len = disk_buf_getbuffer(DISK_BUF_PAGE_SIZE, (void **)&p, NULL, NULL);
1013 1021
1014 if (len <= 0 || str->hdr.pos < 0 || str->hdr.pos >= str->hdr.limit) 1022 if (len <= 0 || str->hdr.pos < 0 || str->hdr.pos >= str->hdr.limit)
1015 { 1023 {