diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2007-12-29 19:46:35 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2007-12-29 19:46:35 +0000 |
commit | a222f27c4a17ed8f9809cda7861fe5f23d4cc0c1 (patch) | |
tree | d393a23d83549f99772bb156e59ffb88725148b6 /apps/plugins/mpegplayer/disk_buf.h | |
parent | 1d0f6b90ff43776e55b4b9f062c9bea3f99aa768 (diff) | |
download | rockbox-a222f27c4a17ed8f9809cda7861fe5f23d4cc0c1.tar.gz rockbox-a222f27c4a17ed8f9809cda7861fe5f23d4cc0c1.zip |
mpegplayer: Make playback engine fully seekable and frame-accurate and split into logical parts. Be sure to have all current features work. Actual UI for seeking will be added soon. Recommended GOP size is about 15-30 frames depending on target or seeking can be slow with really long GOPs (nature of MPEG video). More refined encoding recommendations for a particular player should be posted soon.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15977 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/disk_buf.h')
-rw-r--r-- | apps/plugins/mpegplayer/disk_buf.h | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/disk_buf.h b/apps/plugins/mpegplayer/disk_buf.h new file mode 100644 index 0000000000..90e72fac2f --- /dev/null +++ b/apps/plugins/mpegplayer/disk_buf.h | |||
@@ -0,0 +1,132 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * AV disk buffer declarations | ||
11 | * | ||
12 | * Copyright (c) 2007 Michael Sevakis | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef DISK_BUF_H | ||
22 | #define DISK_BUF_H | ||
23 | |||
24 | #define DISK_BUF_PAGE_SHIFT 15 /* 32KB cache lines */ | ||
25 | #define DISK_BUF_PAGE_SIZE (1 << DISK_BUF_PAGE_SHIFT) | ||
26 | #define DISK_BUF_PAGE_MASK (DISK_BUF_PAGE_SIZE-1) | ||
27 | |||
28 | enum | ||
29 | { | ||
30 | DISK_BUF_NOTIFY_ERROR = -1, | ||
31 | DISK_BUF_NOTIFY_NULL = 0, | ||
32 | DISK_BUF_NOTIFY_OK, | ||
33 | DISK_BUF_NOTIFY_TIMEDOUT, | ||
34 | DISK_BUF_NOTIFY_PROCESS_EVENT, | ||
35 | DISK_BUF_NOTIFY_REGISTERED, | ||
36 | }; | ||
37 | |||
38 | /** Macros to map file offsets to cached data **/ | ||
39 | |||
40 | /* Returns a cache tag given a file offset */ | ||
41 | #define MAP_OFFSET_TO_TAG(o) \ | ||
42 | ((o) >> DISK_BUF_PAGE_SHIFT) | ||
43 | |||
44 | /* Returns the cache page number given a file offset */ | ||
45 | #define MAP_OFFSET_TO_PAGE(o) \ | ||
46 | (MAP_OFFSET_TO_TAG(o) % disk_buf.pgcount) | ||
47 | |||
48 | /* Returns the buffer offset given a file offset */ | ||
49 | #define MAP_OFFSET_TO_BUFFER(o) \ | ||
50 | (MAP_OFFSET_TO_PAGE(o) * DISK_BUF_PAGE_SIZE) | ||
51 | |||
52 | struct dbuf_range | ||
53 | { | ||
54 | uint32_t tag_start; | ||
55 | uint32_t tag_end; | ||
56 | int pg_start; | ||
57 | }; | ||
58 | |||
59 | /* This object is an extension of the stream manager and handles some | ||
60 | * playback events as well as buffering */ | ||
61 | struct disk_buf | ||
62 | { | ||
63 | struct thread_entry *thread; | ||
64 | struct event_queue *q; | ||
65 | uint8_t *start; /* Start pointer */ | ||
66 | uint8_t *end; /* End of buffer pointer less MPEG_GUARDBUF_SIZE. The | ||
67 | guard space is used to wrap data at the buffer start to | ||
68 | pass continuous data packets */ | ||
69 | uint8_t *tail; /* Location of last data + 1 filled into the buffer */ | ||
70 | ssize_t size; /* The buffer length _not_ including the guard space (end-start) */ | ||
71 | int pgcount; /* Total number of available cached pages */ | ||
72 | uint32_t *cache; /* Pointer to cache structure - allocated on buffer */ | ||
73 | int in_file; /* File being read */ | ||
74 | ssize_t filesize; /* Size of file in_file in bytes */ | ||
75 | int file_pages; /* Number of pages in file (rounded up) */ | ||
76 | off_t offset; /* Current position (random access) */ | ||
77 | off_t win_left; /* Left edge of buffer window (streaming) */ | ||
78 | off_t win_right; /* Right edge of buffer window (streaming) */ | ||
79 | uint32_t time_last; /* Last time watermark was checked */ | ||
80 | off_t pos_last; /* Last position at watermark check time */ | ||
81 | ssize_t low_wm; /* The low watermark for automatic rebuffering */ | ||
82 | int status; /* Status as stream */ | ||
83 | int state; /* Current thread state */ | ||
84 | bool need_seek; /* Need to seek because a read was not contiguous */ | ||
85 | }; | ||
86 | |||
87 | extern struct disk_buf disk_buf NOCACHEBSS_ATTR; | ||
88 | |||
89 | static inline bool disk_buf_is_data_ready(struct stream_hdr *sh, | ||
90 | ssize_t margin) | ||
91 | { | ||
92 | /* Data window available? */ | ||
93 | off_t right = sh->win_right; | ||
94 | |||
95 | /* Margins past end-of-file can still return true */ | ||
96 | if (right > disk_buf.filesize - margin) | ||
97 | right = disk_buf.filesize - margin; | ||
98 | |||
99 | return sh->win_left >= disk_buf.win_left && | ||
100 | right + margin <= disk_buf.win_right; | ||
101 | } | ||
102 | |||
103 | |||
104 | bool disk_buf_init(void); | ||
105 | void disk_buf_exit(void); | ||
106 | |||
107 | int disk_buf_open(const char *filename); | ||
108 | void disk_buf_close(void); | ||
109 | ssize_t _disk_buf_getbuffer(size_t size, void **pp, void **pwrap, | ||
110 | size_t *sizewrap); | ||
111 | #define disk_buf_getbuffer(size, pp, pwrap, sizewrap) \ | ||
112 | _disk_buf_getbuffer((size), PUN_PTR(void **, (pp)), \ | ||
113 | PUN_PTR(void **, (pwrap)), (sizewrap)) | ||
114 | ssize_t disk_buf_read(void *buffer, size_t size); | ||
115 | ssize_t disk_buf_lseek(off_t offset, int whence); | ||
116 | |||
117 | static inline off_t disk_buf_ftell(void) | ||
118 | { return disk_buf.offset; } | ||
119 | |||
120 | static inline ssize_t disk_buf_filesize(void) | ||
121 | { return disk_buf.filesize; } | ||
122 | |||
123 | ssize_t disk_buf_prepare_streaming(off_t pos, size_t len); | ||
124 | ssize_t disk_buf_set_streaming_window(off_t left, off_t right); | ||
125 | void * disk_buf_offset2ptr(off_t offset); | ||
126 | int disk_buf_check_streaming_window(off_t left, off_t right); | ||
127 | |||
128 | intptr_t disk_buf_send_msg(long id, intptr_t data); | ||
129 | void disk_buf_post_msg(long id, intptr_t data); | ||
130 | void disk_buf_reply_msg(intptr_t retval); | ||
131 | |||
132 | #endif /* DISK_BUF_H */ | ||