summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/stream_mgr.h
blob: f577e5c2ce8091668b1f30cc9af764862cfdca0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * AV stream manager decalarations
 *
 * Copyright (c) 2007 Michael Sevakis
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef STREAM_MGR_H
#define STREAM_MGR_H

/* Basic media control interface - this handles state changes and stream
 * coordination with assistance from the parser */
struct stream_mgr
{
    struct thread_entry *thread; /* Playback control thread */
    struct event_queue *q;       /* event queue for control thread */
    const char *filename;        /* Current filename */
    uint32_t resume_time;        /* The stream tick where playback was
                                    stopped (or started) */
    bool seeked;                 /* A seek happened and things must be
                                    resynced */
    int    status;          /* Current playback status */
    struct list_item strl;  /* List of available streams */
    struct list_item actl;  /* List of active streams */
    struct mutex str_mtx;   /* Main stream manager mutex */
    struct mutex actl_mtx;  /* Lock for current-streams list */
    union /* A place for reusable non-cacheable parameters */
    {
        struct vo_rect rc;
        struct stream_seek_data skd;
    } parms;
};

extern struct stream_mgr stream_mgr SHAREDBSS_ATTR;

struct stream_window
{
    off_t left, right;
};

/** Interface for use by streams and other internal objects **/
bool stream_get_window(struct stream_window *sw);
void stream_clear_notify(struct stream *str, int for_msg);
int str_next_data_not_ready(struct stream *str);
/* Called by a stream to say it got its buffering notification */
void str_data_notify_received(struct stream *str);
void stream_add_stream(struct stream *str);
void stream_remove_streams(void);

enum stream_events
{
    __STREAM_EV_FIRST = STREAM_MESSAGE_LAST-1,
    STREAM_EV_COMPLETE,
};

void stream_generate_event(struct stream *str, long id, intptr_t data);

/** Main control functions **/

/* Initialize the playback engine */
int stream_init(void);

/* Close the playback engine */
void stream_exit(void);

/* Open a new file */
int stream_open(const char *filename);

/* Close the current file */
int stream_close(void);

/* Plays from the current seekpoint if stopped */
int stream_play(void);

/* Pauses playback if playing */
int stream_pause(void);

/* Resumes playback if paused */
int stream_resume(void);

/* Stops all streaming activity if playing or paused */
int stream_stop(void);

/* Point stream at a particular time.
 * whence = one of SEEK_SET, SEEK_CUR, SEEK_END */
int stream_seek(uint32_t time, int whence);

/* Show/Hide the video image at the current seekpoint */
bool stream_show_vo(bool show);

/* Set the visible section of video */
void stream_vo_set_clip(const struct vo_rect *rc);

#ifndef HAVE_LCD_COLOR
void stream_gray_show(bool show);
#endif

/* Display thumbnail of the current seekpoint */
bool stream_display_thumb(const struct vo_rect *rc);

/* Draw the frame at the current position */
bool stream_draw_frame(bool no_prepare);

/* Return video dimensions */
bool stream_vo_get_size(struct vo_ext *sz);

/* Returns the resume time in timestamp ticks */
uint32_t stream_get_resume_time(void);

/* Returns stream_get_time if no seek is pending or else the
   last time give to seek */
uint32_t stream_get_seek_time(uint32_t *start);

/* Return the absolute stream time in clock ticks - adjusted by
 * master clock stream via audio timestamps */
static inline uint32_t stream_get_time(void)
    { return pcm_output_get_clock(); }

/* Return the absolute clock time in clock ticks - unadjusted */
static inline uint32_t stream_get_ticks(uint32_t *start)
    { return pcm_output_get_ticks(start); }

/* Returns the current playback status */
static inline int stream_status(void)
    { return stream_mgr.status; }

/* Wait for a state transistion to complete */
void stream_wait_status(void);

/* Returns the playback length of the stream */
static inline uint32_t stream_get_duration(void)
    { return str_parser.duration; }

static inline bool stream_can_seek(void)
    { return parser_can_seek(); }

/* Keep the disk spinning (for seeking and browsing) */
static inline void stream_keep_disk_active(void)
{
#ifndef HAVE_FLASH_STORAGE
    rb->ata_spin();
#endif
    }

#endif /* STREAM_MGR_H */