A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 168 lines 5.4 kB view raw
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 * 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. 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 */ 28struct stream_mgr 29{ 30 unsigned int 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 void *strl[MPEGPLAYER_MAX_STREAMS+1]; /* List of available streams */ 39 void *actl[MPEGPLAYER_MAX_STREAMS+1]; /* List of active streams */ 40 struct mutex str_mtx; /* Main stream manager mutex */ 41 struct mutex actl_mtx; /* Lock for current-streams list */ 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 49extern struct stream_mgr stream_mgr SHAREDBSS_ATTR; 50 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 106/* Set the visible section of video */ 107void stream_vo_set_clip(const struct vo_rect *rc); 108 109/* Return current visible section of video */ 110bool stream_vo_get_clip(struct vo_rect *rc); 111 112#ifndef HAVE_LCD_COLOR 113void stream_gray_show(bool show); 114#endif 115 116/* Display thumbnail of the current seekpoint */ 117bool stream_display_thumb(const struct vo_rect *rc); 118 119/* Draw the frame at the current position */ 120bool stream_draw_frame(bool no_prepare); 121 122/* Return video dimensions */ 123bool stream_vo_get_size(struct vo_ext *sz); 124 125/* Returns the resume time in timestamp ticks */ 126uint32_t stream_get_resume_time(void); 127 128/* Returns stream_get_time if no seek is pending or else the 129 last time give to seek */ 130uint32_t stream_get_seek_time(uint32_t *start); 131 132/* Return the absolute stream time in clock ticks - adjusted by 133 * master clock stream via audio timestamps */ 134static inline uint32_t stream_get_time(void) 135 { return pcm_output_get_clock(); } 136 137/* Return the absolute clock time in clock ticks - unadjusted */ 138static inline uint32_t stream_get_ticks(uint32_t *start) 139 { return pcm_output_get_ticks(start); } 140 141/* Returns the current playback status */ 142static inline int stream_status(void) 143 { return stream_mgr.status; } 144 145/* Wait for a state transistion to complete */ 146void stream_wait_status(void); 147 148/* Returns the playback length of the stream */ 149static inline uint32_t stream_get_duration(void) 150 { return str_parser.duration; } 151 152static inline bool stream_can_seek(void) 153 { return parser_can_seek(); } 154 155static inline void stream_video_stats(struct video_output_stats *s) 156 { video_thread_get_stats(s); } 157 158bool stream_set_callback(long id, void * fn); 159 160/* Keep the disk spinning (for seeking and browsing) */ 161static inline void stream_keep_disk_active(void) 162{ 163#ifdef HAVE_DISK_STORAGE 164 rb->storage_spin(); 165#endif 166 } 167 168#endif /* STREAM_MGR_H */