MCPcopy Create free account
hub / github.com/SIPp/sipp / rtpstream_start_task

Function rtpstream_start_task

src/rtpstream.cpp:1426–1521  ·  view source on GitHub ↗

code checked */

Source from the content-addressed store, hash-verified

1424
1425/* code checked */
1426static int rtpstream_start_task(rtpstream_callinfo_t* callinfo)
1427{
1428 int ready_index;
1429 int allocsize;
1430 threaddata_t **threadlist;
1431 threaddata_t *threaddata;
1432 pthread_t threadID;
1433
1434 /* safety check... */
1435 if (!callinfo->taskinfo) {
1436 return 0;
1437 }
1438
1439 /* we count on the fact that only one thread can add/remove playback tasks */
1440 /* thus we don't have mutexes to protect the thread list objects. */
1441 for (ready_index = 0; ready_index < num_ready_threads; ready_index++) {
1442 /* ready threads have a spare task slot or should have one very shortly */
1443 /* if we find a task with no spare slots, just skip to the next one. */
1444 if (ready_threads[ready_index]->num_tasks < ready_threads[ready_index]->max_tasks) {
1445 /* we found a thread with an open task slot. */
1446 break;
1447 }
1448 }
1449
1450 if (ready_index == num_ready_threads) {
1451 /* did not find a thread with spare task slots, thus we create one here */
1452 if (num_ready_threads >= ready_threads_max) {
1453 /* need to allocate more memory for thread list */
1454 ready_threads_max += RTPSTREAM_THREADBLOCKSIZE;
1455 threadlist = (threaddata_t **) realloc(ready_threads, sizeof(*ready_threads) * ready_threads_max);
1456 if (!threadlist) {
1457 /* could not allocate bigger block... worry [about it later] */
1458 ready_threads_max -= RTPSTREAM_THREADBLOCKSIZE;
1459 return 0;
1460 }
1461 ready_threads = threadlist;
1462 }
1463 /* create and initialise data structure for new thread */
1464 allocsize = sizeof(*threaddata) + sizeof(threaddata->tasklist) * (rtp_tasks_per_thread - 1);
1465 threaddata = (threaddata_t *) malloc(allocsize);
1466 if (!threaddata) {
1467 return 0;
1468 }
1469 memset(threaddata, 0, allocsize);
1470 threaddata->max_tasks = rtp_tasks_per_thread;
1471 threaddata->busy_list_index = -1;
1472 pthread_mutex_init(&(threaddata->tasklist_mutex), nullptr);
1473 /* create the thread itself */
1474 if (pthread_create(&threadID, nullptr, rtpstream_playback_thread, threaddata)) {
1475 /* error creating the thread */
1476 free(threaddata);
1477 return 0;
1478 }
1479
1480 threaddata->id = threadID;
1481
1482 printAudioHex("CREATED THREAD: ", "", 0, getThreadId(threadID), 0);
1483 printVideoHex("CREATED THREAD: ", "", 0, getThreadId(threadID), 0);

Callers 2

Calls 3

printAudioHexFunction · 0.85
getThreadIdFunction · 0.85
printVideoHexFunction · 0.85

Tested by

no test coverage detected