summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/disk_buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpegplayer/disk_buf.c')
-rw-r--r--apps/plugins/mpegplayer/disk_buf.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/apps/plugins/mpegplayer/disk_buf.c b/apps/plugins/mpegplayer/disk_buf.c
index af349c302a..4d0f98e5a3 100644
--- a/apps/plugins/mpegplayer/disk_buf.c
+++ b/apps/plugins/mpegplayer/disk_buf.c
@@ -30,7 +30,7 @@ static struct queue_sender_list disk_buf_queue_send SHAREDBSS_ATTR;
30static uint32_t disk_buf_stack[DEFAULT_STACK_SIZE*2/sizeof(uint32_t)]; 30static uint32_t disk_buf_stack[DEFAULT_STACK_SIZE*2/sizeof(uint32_t)];
31 31
32struct disk_buf disk_buf SHAREDBSS_ATTR; 32struct disk_buf disk_buf SHAREDBSS_ATTR;
33static struct list_item nf_list; 33static void *nf_list[MPEGPLAYER_MAX_STREAMS+1];
34 34
35static inline void disk_buf_lock(void) 35static inline void disk_buf_lock(void)
36{ 36{
@@ -45,13 +45,12 @@ static inline void disk_buf_unlock(void)
45static inline void disk_buf_on_clear_data_notify(struct stream_hdr *sh) 45static inline void disk_buf_on_clear_data_notify(struct stream_hdr *sh)
46{ 46{
47 DEBUGF("DISK_BUF_CLEAR_DATA_NOTIFY: 0x%02X (cleared)\n", 47 DEBUGF("DISK_BUF_CLEAR_DATA_NOTIFY: 0x%02X (cleared)\n",
48 STR_FROM_HEADER(sh)->id); 48 STR_FROM_HDR(sh)->id);
49 list_remove_item(&sh->nf); 49 list_remove_item(nf_list, sh);
50} 50}
51 51
52
53inline bool disk_buf_is_data_ready(struct stream_hdr *sh, 52inline bool disk_buf_is_data_ready(struct stream_hdr *sh,
54 ssize_t margin) 53 ssize_t margin)
55{ 54{
56 /* Data window available? */ 55 /* Data window available? */
57 off_t right = sh->win_right; 56 off_t right = sh->win_right;
@@ -71,7 +70,7 @@ void dbuf_l2_init(struct dbuf_l2_cache *l2_p)
71 70
72static int disk_buf_on_data_notify(struct stream_hdr *sh) 71static int disk_buf_on_data_notify(struct stream_hdr *sh)
73{ 72{
74 DEBUGF("DISK_BUF_DATA_NOTIFY: 0x%02X ", STR_FROM_HEADER(sh)->id); 73 DEBUGF("DISK_BUF_DATA_NOTIFY: 0x%02X ", STR_FROM_HDR(sh)->id);
75 74
76 if (sh->win_left <= sh->win_right) 75 if (sh->win_left <= sh->win_right)
77 { 76 {
@@ -85,7 +84,7 @@ static int disk_buf_on_data_notify(struct stream_hdr *sh)
85 sh->win_left, sh->win_right, 84 sh->win_left, sh->win_right,
86 disk_buf.win_left, disk_buf.win_right); 85 disk_buf.win_left, disk_buf.win_right);
87 /* Be sure it's not listed though if multiple requests were made */ 86 /* Be sure it's not listed though if multiple requests were made */
88 list_remove_item(&sh->nf); 87 list_remove_item(nf_list, sh);
89 return DISK_BUF_NOTIFY_OK; 88 return DISK_BUF_NOTIFY_OK;
90 } 89 }
91 90
@@ -95,7 +94,7 @@ static int disk_buf_on_data_notify(struct stream_hdr *sh)
95 case TSTATE_BUFFERING: 94 case TSTATE_BUFFERING:
96 case TSTATE_INIT: 95 case TSTATE_INIT:
97 disk_buf.state = TSTATE_BUFFERING; 96 disk_buf.state = TSTATE_BUFFERING;
98 list_add_item(&nf_list, &sh->nf); 97 list_add_item(nf_list, sh);
99 DEBUGF("(registered)\n" 98 DEBUGF("(registered)\n"
100 " swl:%lu swr:%lu\n" 99 " swl:%lu swr:%lu\n"
101 " dwl:%lu dwr:%lu\n", 100 " dwl:%lu dwr:%lu\n",
@@ -109,20 +108,17 @@ static int disk_buf_on_data_notify(struct stream_hdr *sh)
109 return DISK_BUF_NOTIFY_ERROR; 108 return DISK_BUF_NOTIFY_ERROR;
110} 109}
111 110
112static bool check_data_notifies_callback(struct list_item *item, 111static bool check_data_notifies_callback(struct stream_hdr *sh, intptr_t data)
113 intptr_t data)
114{ 112{
115 struct stream_hdr *sh = TYPE_FROM_MEMBER(struct stream_hdr, item, nf);
116
117 if (disk_buf_is_data_ready(sh, 0)) 113 if (disk_buf_is_data_ready(sh, 0))
118 { 114 {
119 /* Remove from list then post notification - post because send 115 /* Remove from list then post notification - post because send
120 * could result in a wait for each thread to finish resulting 116 * could result in a wait for each thread to finish resulting
121 * in deadlock */ 117 * in deadlock */
122 list_remove_item(item); 118 list_remove_item(nf_list, sh);
123 str_post_msg(STR_FROM_HEADER(sh), DISK_BUF_DATA_NOTIFY, 0); 119 str_post_msg(STR_FROM_HDR(sh), DISK_BUF_DATA_NOTIFY, 0);
124 DEBUGF("DISK_BUF_DATA_NOTIFY: 0x%02X (notified)\n", 120 DEBUGF("DISK_BUF_DATA_NOTIFY: 0x%02X (notified)\n",
125 STR_FROM_HEADER(sh)->id); 121 STR_FROM_HDR(sh)->id);
126 } 122 }
127 123
128 return true; 124 return true;
@@ -130,15 +126,17 @@ static bool check_data_notifies_callback(struct list_item *item,
130} 126}
131 127
132/* Check registered streams and notify them if their data is available */ 128/* Check registered streams and notify them if their data is available */
133static void check_data_notifies(void) 129static inline void check_data_notifies(void)
134{ 130{
135 list_enum_items(&nf_list, check_data_notifies_callback, 0); 131 list_enum_items(nf_list,
132 (list_enum_callback_t)check_data_notifies_callback,
133 0);
136} 134}
137 135
138/* Clear all registered notifications - do not post them */ 136/* Clear all registered notifications - do not post them */
139static inline void clear_data_notifies(void) 137static inline void clear_data_notifies(void)
140{ 138{
141 list_clear_all(&nf_list); 139 list_clear_all(nf_list);
142} 140}
143 141
144/* Background buffering when streaming */ 142/* Background buffering when streaming */
@@ -492,7 +490,7 @@ static void disk_buf_thread(void)
492 disk_buf_buffer(); 490 disk_buf_buffer();
493 491
494 /* Check for any due notifications if any are pending */ 492 /* Check for any due notifications if any are pending */
495 if (nf_list.next != NULL) 493 if (*nf_list != NULL)
496 check_data_notifies(); 494 check_data_notifies();
497 495
498 /* Still more data left? */ 496 /* Still more data left? */
@@ -915,7 +913,6 @@ void disk_buf_reply_msg(intptr_t retval)
915bool disk_buf_init(void) 913bool disk_buf_init(void)
916{ 914{
917 disk_buf.thread = 0; 915 disk_buf.thread = 0;
918 list_initialize(&nf_list);
919 916
920 rb->mutex_init(&disk_buf_mtx); 917 rb->mutex_init(&disk_buf_mtx);
921 918