blob: 71a3fd51c674450a20fc24566240bb85b92f677a [file] [log] [blame]
Michael Sevakisa222f272007-12-29 19:46:35 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * AV stream manager decalarations
11 *
12 * Copyright (c) 2007 Michael Sevakis
13 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000014 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
Michael Sevakisa222f272007-12-29 19:46:35 +000018 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#ifndef STREAM_MGR_H
24#define STREAM_MGR_H
25
26/* Basic media control interface - this handles state changes and stream
27 * coordination with assistance from the parser */
28struct stream_mgr
29{
30 struct thread_entry *thread; /* Playback control thread */
31 struct event_queue *q; /* event queue for control thread */
32 const char *filename; /* Current filename */
33 uint32_t resume_time; /* The stream tick where playback was
34 stopped (or started) */
35 bool seeked; /* A seek happened and things must be
36 resynced */
37 int status; /* Current playback status */
38 struct list_item strl; /* List of available streams */
39 struct list_item actl; /* List of active streams */
40 struct mutex str_mtx; /* Main stream manager mutex */
41 struct mutex actl_mtx; /* Lock for current-streams list */
Michael Sevakisa222f272007-12-29 19:46:35 +000042 union /* A place for reusable non-cacheable parameters */
43 {
44 struct vo_rect rc;
45 struct stream_seek_data skd;
46 } parms;
47};
48
Michael Sevakis05099142008-04-06 04:34:57 +000049extern struct stream_mgr stream_mgr SHAREDBSS_ATTR;
Michael Sevakisa222f272007-12-29 19:46:35 +000050
51struct stream_window
52{
53 off_t left, right;
54};
55
56/** Interface for use by streams and other internal objects **/
57bool stream_get_window(struct stream_window *sw);
58void stream_clear_notify(struct stream *str, int for_msg);
59int str_next_data_not_ready(struct stream *str);
60/* Called by a stream to say it got its buffering notification */
61void str_data_notify_received(struct stream *str);
62void stream_add_stream(struct stream *str);
63void stream_remove_streams(void);
64
65enum stream_events
66{
67 __STREAM_EV_FIRST = STREAM_MESSAGE_LAST-1,
68 STREAM_EV_COMPLETE,
69};
70
71void stream_generate_event(struct stream *str, long id, intptr_t data);
72
73/** Main control functions **/
74
75/* Initialize the playback engine */
76int stream_init(void);
77
78/* Close the playback engine */
79void stream_exit(void);
80
81/* Open a new file */
82int stream_open(const char *filename);
83
84/* Close the current file */
85int stream_close(void);
86
87/* Plays from the current seekpoint if stopped */
88int stream_play(void);
89
90/* Pauses playback if playing */
91int stream_pause(void);
92
93/* Resumes playback if paused */
94int stream_resume(void);
95
96/* Stops all streaming activity if playing or paused */
97int stream_stop(void);
98
99/* Point stream at a particular time.
100 * whence = one of SEEK_SET, SEEK_CUR, SEEK_END */
101int stream_seek(uint32_t time, int whence);
102
103/* Show/Hide the video image at the current seekpoint */
104bool stream_show_vo(bool show);
105
Michael Sevakisa5fc3f42008-01-03 17:14:28 +0000106/* Set the visible section of video */
107void stream_vo_set_clip(const struct vo_rect *rc);
108
Michael Sevakisa222f272007-12-29 19:46:35 +0000109#ifndef HAVE_LCD_COLOR
Michael Sevakisa222f272007-12-29 19:46:35 +0000110void stream_gray_show(bool show);
111#endif
112
113/* Display thumbnail of the current seekpoint */
114bool stream_display_thumb(const struct vo_rect *rc);
115
Michael Sevakisa5fc3f42008-01-03 17:14:28 +0000116/* Draw the frame at the current position */
117bool stream_draw_frame(bool no_prepare);
118
Michael Sevakisa222f272007-12-29 19:46:35 +0000119/* Return video dimensions */
120bool stream_vo_get_size(struct vo_ext *sz);
121
122/* Returns the resume time in timestamp ticks */
123uint32_t stream_get_resume_time(void);
124
Michael Sevakisa5fc3f42008-01-03 17:14:28 +0000125/* Returns stream_get_time if no seek is pending or else the
126 last time give to seek */
127uint32_t stream_get_seek_time(uint32_t *start);
128
Michael Sevakisa222f272007-12-29 19:46:35 +0000129/* Return the absolute stream time in clock ticks - adjusted by
130 * master clock stream via audio timestamps */
131static inline uint32_t stream_get_time(void)
132 { return pcm_output_get_clock(); }
133
134/* Return the absolute clock time in clock ticks - unadjusted */
135static inline uint32_t stream_get_ticks(uint32_t *start)
136 { return pcm_output_get_ticks(start); }
137
138/* Returns the current playback status */
139static inline int stream_status(void)
140 { return stream_mgr.status; }
141
Michael Sevakis3f4fd4d2008-01-27 21:45:15 +0000142/* Wait for a state transistion to complete */
143void stream_wait_status(void);
144
Michael Sevakisa222f272007-12-29 19:46:35 +0000145/* Returns the playback length of the stream */
146static inline uint32_t stream_get_duration(void)
147 { return str_parser.duration; }
148
149static inline bool stream_can_seek(void)
150 { return parser_can_seek(); }
151
152/* Keep the disk spinning (for seeking and browsing) */
153static inline void stream_keep_disk_active(void)
154{
155#ifndef HAVE_FLASH_STORAGE
156 rb->ata_spin();
157#endif
158 }
159
160#endif /* STREAM_MGR_H */