summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/stream_thread.h
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-12-29 19:46:35 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-12-29 19:46:35 +0000
commita222f27c4a17ed8f9809cda7861fe5f23d4cc0c1 (patch)
treed393a23d83549f99772bb156e59ffb88725148b6 /apps/plugins/mpegplayer/stream_thread.h
parent1d0f6b90ff43776e55b4b9f062c9bea3f99aa768 (diff)
downloadrockbox-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/stream_thread.h')
-rw-r--r--apps/plugins/mpegplayer/stream_thread.h192
1 files changed, 192 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/stream_thread.h b/apps/plugins/mpegplayer/stream_thread.h
new file mode 100644
index 0000000000..1962a66878
--- /dev/null
+++ b/apps/plugins/mpegplayer/stream_thread.h
@@ -0,0 +1,192 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Declarations for stream-specific threading
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 STREAM_THREAD_H
22#define STREAM_THREAD_H
23
24#define PKT_HAS_TS 0x1
25
26/* Stream header which is the minimum to receive asynchronous buffering
27 * notifications.
28 * Layed-out to allow streaming access after random-access parsing */
29struct stream_hdr
30{
31 struct event_queue *q; /* Communication queue - separate to allow it
32 to be placed in another section */
33 off_t win_left; /* Left position within data stream */
34 union
35 {
36 off_t win_right; /* Right position within data stream */
37 off_t pos; /* Start/current position for random-access read */
38 };
39 off_t limit; /* Limit for random-access read */
40 struct list_item nf; /* List for data notification */
41};
42
43struct stream
44{
45 struct stream_hdr hdr; /* Base stream data */
46 struct thread_entry *thread; /* Stream's thread */
47 uint8_t* curr_packet; /* Current stream packet beginning */
48 uint8_t* curr_packet_end; /* Current stream packet end */
49 struct list_item l; /* List of streams - either reserve pool
50 or active pool */
51 int state; /* State machine parsing mode */
52 uint32_t start_pts; /* First timestamp for stream */
53 uint32_t end_pts; /* Last timestamp for stream */
54 uint32_t pts; /* Last presentation timestamp */
55 uint32_t pkt_flags; /* PKT_* flags */
56 unsigned id; /* Stream identifier */
57};
58
59/* Make sure there there is always enough data buffered ahead for
60 * the worst possible case - regardless of whether a valid stream
61 * would actually produce that */
62#define MIN_BUFAHEAD (21+65535+6+65535+6) /* 131103 */
63
64/* States that a stream's thread assumes internally */
65enum thread_states
66{
67 /* Stream thread... */
68 TSTATE_INIT = 0, /* is initialized and primed */
69 TSTATE_DATA, /* is awaiting data to be available */
70 TSTATE_BUFFERING, /* is buffering data */
71 TSTATE_EOS, /* has hit the end of data */
72 TSTATE_DECODE, /* is in a decoding state */
73 TSTATE_RENDER, /* is in a rendering state */
74 TSTATE_RENDER_WAIT, /* is waiting to render */
75 TSTATE_RENDER_WAIT_END, /* is waiting on remaining data */
76};
77
78/* Commands that streams respond to */
79enum stream_message
80{
81 STREAM_NULL = 0, /* A NULL message for whatever reason -
82 usually ignored */
83 STREAM_PLAY, /* Start playback at current position */
84 STREAM_PAUSE, /* Stop playing and await further commands */
85 STREAM_RESET, /* Reset the stream for a discontinuity */
86 STREAM_STOP, /* Stop stream - requires a reset later */
87 STREAM_SEEK, /* Seek the current stream to a new location */
88 STREAM_OPEN, /* Open a new file */
89 STREAM_CLOSE, /* Close the current file */
90 STREAM_QUIT, /* Exit the stream and thread */
91 STREAM_NEEDS_SYNC, /* Need to sync before stream decoding? */
92 STREAM_SYNC, /* Sync to the specified time from some key point */
93 STREAM_FIND_END_TIME, /* Get the exact end time of an elementary
94 * stream - ie. time just after last frame is finished */
95 /* Disk buffer */
96 STREAM_DISK_BUF_FIRST,
97 DISK_BUF_DATA_NOTIFY = STREAM_DISK_BUF_FIRST,
98 DISK_BUF_CLEAR_DATA_NOTIFY, /* Cancel pending data notification */
99 DISK_BUF_CACHE_RANGE, /* Cache a range of the file in the buffer */
100 /* Audio stream */
101 STREAM_AUDIO_FIRST,
102 /* Video stream */
103 STREAM_VIDEO_FIRST,
104 VIDEO_DISPLAY_SHOW = STREAM_VIDEO_FIRST, /* Show/hide video output */
105 VIDEO_DISPLAY_IS_VISIBLE, /* Is the video output visible? */
106 VIDEO_GET_SIZE, /* Get the video dimensions */
107 VIDEO_PRINT_FRAME, /* Print the frame at the current position */
108 VIDEO_PRINT_THUMBNAIL, /* Print a thumbnail of the current position */
109#ifdef GRAY_CACHE_MAINT
110 VIDEO_GRAY_CACHEOP,
111#endif
112 STREAM_MESSAGE_LAST,
113};
114
115/* Data parameter for STREAM_SEEK */
116struct stream_seek_data
117{
118 uint32_t time; /* Time to seek to/by */
119 int whence; /* Specification of relationship to current position/file */
120};
121
122/* Data parameter for STREAM_SYNC */
123struct str_sync_data
124{
125 uint32_t time; /* Time to sync to */
126 struct stream_scan sk; /* Specification of start/limits/direction */
127};
128
129/* Stream status codes - not eqivalent to thread states */
130enum stream_status
131{
132 /* Stream status is... */
133 STREAM_DATA_END = -4, /* Stream has ended */
134 STREAM_DATA_NOT_READY = -3, /* Data was not available yet */
135 STREAM_UNSUPPORTED = -2, /* Format is unsupported */
136 STREAM_ERROR = -1, /* some kind of error - quit it or reset it */
137 STREAM_OK = 0, /* General inequality for success >= is OK, < error */
138 STREAM_STOPPED = 0, /* stopped and awaiting commands - send STREAM_INIT */
139 STREAM_PLAYING, /* playing and rendering its data */
140 STREAM_PAUSED, /* paused and awaiting commands */
141 /* Other status codes (> STREAM_OK) */
142 STREAM_MATCH, /* A good match was found */
143 STREAM_PERFECT_MATCH, /* Exactly what was wanted was found or
144 no better match is possible */
145 STREAM_NOT_FOUND, /* Match not found */
146};
147
148#define STR_FROM_HEADER(sh) ((struct stream *)(sh))
149
150/* Clip time to range for a particular stream */
151static inline uint32_t clip_time(struct stream *str, uint32_t time)
152{
153 if (time < str->start_pts)
154 time = str->start_pts;
155 else if (time >= str->end_pts)
156 time = str->end_pts;
157
158 return time;
159}
160
161extern struct stream video_str IBSS_ATTR;
162extern struct stream audio_str IBSS_ATTR;
163
164bool video_thread_init(void);
165void video_thread_exit(void);
166bool audio_thread_init(void);
167void audio_thread_exit(void);
168
169/* Some queue function wrappers to keep things clean-ish */
170
171/* For stream use only */
172static inline bool str_have_msg(struct stream *str)
173 { return !rb->queue_empty(str->hdr.q); }
174
175static inline void str_get_msg(struct stream *str, struct queue_event *ev)
176 { rb->queue_wait(str->hdr.q, ev); }
177
178static inline void str_get_msg_w_tmo(struct stream *str, struct queue_event *ev,
179 int timeout)
180 { rb->queue_wait_w_tmo(str->hdr.q, ev, timeout); }
181
182static inline void str_reply_msg(struct stream *str, intptr_t reply)
183 { rb->queue_reply(str->hdr.q, reply); }
184
185/* Public use */
186static inline intptr_t str_send_msg(struct stream *str, long id, intptr_t data)
187 { return rb->queue_send(str->hdr.q, id, data); }
188
189static inline void str_post_msg(struct stream *str, long id, intptr_t data)
190 { rb->queue_post(str->hdr.q, id, data); }
191
192#endif /* STREAM_THREAD_H */