Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 14 | * 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 Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 18 | * |
| 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 */ |
| 28 | struct 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 Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 42 | 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 Sevakis | 0509914 | 2008-04-06 04:34:57 +0000 | [diff] [blame] | 49 | extern struct stream_mgr stream_mgr SHAREDBSS_ATTR; |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 50 | |
| 51 | struct stream_window |
| 52 | { |
| 53 | off_t left, right; |
| 54 | }; |
| 55 | |
| 56 | /** Interface for use by streams and other internal objects **/ |
| 57 | bool stream_get_window(struct stream_window *sw); |
| 58 | void stream_clear_notify(struct stream *str, int for_msg); |
| 59 | int str_next_data_not_ready(struct stream *str); |
| 60 | /* Called by a stream to say it got its buffering notification */ |
| 61 | void str_data_notify_received(struct stream *str); |
| 62 | void stream_add_stream(struct stream *str); |
| 63 | void stream_remove_streams(void); |
| 64 | |
| 65 | enum stream_events |
| 66 | { |
| 67 | __STREAM_EV_FIRST = STREAM_MESSAGE_LAST-1, |
| 68 | STREAM_EV_COMPLETE, |
| 69 | }; |
| 70 | |
| 71 | void stream_generate_event(struct stream *str, long id, intptr_t data); |
| 72 | |
| 73 | /** Main control functions **/ |
| 74 | |
| 75 | /* Initialize the playback engine */ |
| 76 | int stream_init(void); |
| 77 | |
| 78 | /* Close the playback engine */ |
| 79 | void stream_exit(void); |
| 80 | |
| 81 | /* Open a new file */ |
| 82 | int stream_open(const char *filename); |
| 83 | |
| 84 | /* Close the current file */ |
| 85 | int stream_close(void); |
| 86 | |
| 87 | /* Plays from the current seekpoint if stopped */ |
| 88 | int stream_play(void); |
| 89 | |
| 90 | /* Pauses playback if playing */ |
| 91 | int stream_pause(void); |
| 92 | |
| 93 | /* Resumes playback if paused */ |
| 94 | int stream_resume(void); |
| 95 | |
| 96 | /* Stops all streaming activity if playing or paused */ |
| 97 | int stream_stop(void); |
| 98 | |
| 99 | /* Point stream at a particular time. |
| 100 | * whence = one of SEEK_SET, SEEK_CUR, SEEK_END */ |
| 101 | int stream_seek(uint32_t time, int whence); |
| 102 | |
| 103 | /* Show/Hide the video image at the current seekpoint */ |
| 104 | bool stream_show_vo(bool show); |
| 105 | |
Michael Sevakis | a5fc3f4 | 2008-01-03 17:14:28 +0000 | [diff] [blame] | 106 | /* Set the visible section of video */ |
| 107 | void stream_vo_set_clip(const struct vo_rect *rc); |
| 108 | |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 109 | #ifndef HAVE_LCD_COLOR |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 110 | void stream_gray_show(bool show); |
| 111 | #endif |
| 112 | |
| 113 | /* Display thumbnail of the current seekpoint */ |
| 114 | bool stream_display_thumb(const struct vo_rect *rc); |
| 115 | |
Michael Sevakis | a5fc3f4 | 2008-01-03 17:14:28 +0000 | [diff] [blame] | 116 | /* Draw the frame at the current position */ |
| 117 | bool stream_draw_frame(bool no_prepare); |
| 118 | |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 119 | /* Return video dimensions */ |
| 120 | bool stream_vo_get_size(struct vo_ext *sz); |
| 121 | |
| 122 | /* Returns the resume time in timestamp ticks */ |
| 123 | uint32_t stream_get_resume_time(void); |
| 124 | |
Michael Sevakis | a5fc3f4 | 2008-01-03 17:14:28 +0000 | [diff] [blame] | 125 | /* Returns stream_get_time if no seek is pending or else the |
| 126 | last time give to seek */ |
| 127 | uint32_t stream_get_seek_time(uint32_t *start); |
| 128 | |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 129 | /* Return the absolute stream time in clock ticks - adjusted by |
| 130 | * master clock stream via audio timestamps */ |
| 131 | static inline uint32_t stream_get_time(void) |
| 132 | { return pcm_output_get_clock(); } |
| 133 | |
| 134 | /* Return the absolute clock time in clock ticks - unadjusted */ |
| 135 | static inline uint32_t stream_get_ticks(uint32_t *start) |
| 136 | { return pcm_output_get_ticks(start); } |
| 137 | |
| 138 | /* Returns the current playback status */ |
| 139 | static inline int stream_status(void) |
| 140 | { return stream_mgr.status; } |
| 141 | |
Michael Sevakis | 3f4fd4d | 2008-01-27 21:45:15 +0000 | [diff] [blame] | 142 | /* Wait for a state transistion to complete */ |
| 143 | void stream_wait_status(void); |
| 144 | |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 145 | /* Returns the playback length of the stream */ |
| 146 | static inline uint32_t stream_get_duration(void) |
| 147 | { return str_parser.duration; } |
| 148 | |
| 149 | static inline bool stream_can_seek(void) |
| 150 | { return parser_can_seek(); } |
| 151 | |
| 152 | /* Keep the disk spinning (for seeking and browsing) */ |
| 153 | static 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 */ |