Changeset 6112 for pjproject/trunk/pjmedia/src/pjmedia/wav_playlist.c
- Timestamp:
- Nov 29, 2019 4:21:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/wav_playlist.c
r5711 r6112 75 75 76 76 pj_status_t (*cb)(pjmedia_port*, void*); 77 pj_bool_t subscribed; 78 void (*cb2)(pjmedia_port*, void*); 77 79 }; 78 80 … … 102 104 103 105 return port; 106 } 107 108 109 static pj_status_t file_on_event(pjmedia_event *event, 110 void *user_data) 111 { 112 struct playlist_port *fport = (struct playlist_port*)user_data; 113 114 if (event->type == PJMEDIA_EVENT_CALLBACK) { 115 if (fport->cb2) 116 (*fport->cb2)(&fport->base, fport->base.port_data.pdata); 117 } 118 119 return PJ_SUCCESS; 104 120 } 105 121 … … 176 192 177 193 /* All files have been played. Call callback, if any. */ 178 if (fport->cb) 179 { 194 if (fport->cb2) { 195 pj_bool_t no_loop = (fport->options & PJMEDIA_FILE_NO_LOOP); 196 197 if (!fport->subscribed) { 198 status = pjmedia_event_subscribe(NULL, &file_on_event, 199 fport, fport); 200 fport->subscribed = (status == PJ_SUCCESS)? PJ_TRUE: 201 PJ_FALSE; 202 } 203 204 if (fport->subscribed && fport->eof != 2) { 205 pjmedia_event event; 206 207 if (no_loop) { 208 /* To prevent the callback from being called 209 * repeatedly. 210 */ 211 fport->eof = 2; 212 } else { 213 fport->eof = PJ_FALSE; 214 /* start with first file again. */ 215 fport->current_file = current_file = 0; 216 fport->fpos_list[0] = fport->start_data_list[0]; 217 pj_file_setpos(fport->fd_list[0], 218 fport->fpos_list[0], PJ_SEEK_SET); 219 fport->data_left_list[0] = fport->data_len_list[0]; 220 } 221 222 pjmedia_event_init(&event, PJMEDIA_EVENT_CALLBACK, 223 NULL, fport); 224 pjmedia_event_publish(NULL, fport, &event, 225 PJMEDIA_EVENT_PUBLISH_POST_EVENT); 226 } 227 228 /* Should not access player port after this since 229 * it might have been destroyed by the callback. 230 */ 231 return (no_loop? PJ_EEOF: PJ_SUCCESS); 232 233 } else if (fport->cb) { 180 234 PJ_LOG(5,(THIS_FILE, 181 235 "File port %.*s EOF, calling callback", … … 578 632 579 633 634 #if !DEPRECATED_FOR_TICKET_2251 580 635 /* 581 636 * Register a callback to be called when the file reading has reached the … … 595 650 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP); 596 651 652 PJ_LOG(1, (THIS_FILE, "pjmedia_wav_playlist_set_eof_cb() is deprecated. " 653 "Use pjmedia_wav_playlist_set_eof_cb2() instead.")); 654 597 655 fport = (struct playlist_port*) port; 598 656 599 657 fport->base.port_data.pdata = user_data; 600 658 fport->cb = cb; 659 660 return PJ_SUCCESS; 661 } 662 #endif 663 664 665 /* 666 * Register a callback to be called when the file reading has reached the 667 * end of the last file. 668 */ 669 PJ_DEF(pj_status_t) pjmedia_wav_playlist_set_eof_cb2(pjmedia_port *port, 670 void *user_data, 671 void (*cb)(pjmedia_port *port, 672 void *usr_data)) 673 { 674 struct playlist_port *fport; 675 676 /* Sanity check */ 677 PJ_ASSERT_RETURN(port, PJ_EINVAL); 678 679 /* Check that this is really a playlist port */ 680 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP); 681 682 fport = (struct playlist_port*) port; 683 684 fport->base.port_data.pdata = user_data; 685 fport->cb2 = cb; 601 686 602 687 return PJ_SUCCESS; … … 676 761 pj_assert(this_port->info.signature == SIGNATURE); 677 762 763 if (fport->subscribed) { 764 pjmedia_event_unsubscribe(NULL, &file_on_event, fport, fport); 765 fport->subscribed = PJ_FALSE; 766 } 767 678 768 for (index=0; index<fport->max_file; index++) 679 769 pj_file_close(fport->fd_list[index]);
Note: See TracChangeset
for help on using the changeset viewer.