th_pkt_t * pkt_copy_shallow(th_pkt_t *pkt) { th_pkt_t *n = malloc(sizeof(th_pkt_t)); *n = *pkt; n->pkt_refcount = 1; pktbuf_ref_inc(n->pkt_meta); pktbuf_ref_inc(n->pkt_payload); return n; }
static void htsp_send(htsp_connection_t *htsp, htsmsg_t *m, pktbuf_t *pb, htsp_msg_q_t *hmq, int payloadsize) { htsp_msg_t *hm = malloc(sizeof(htsp_msg_t)); hm->hm_msg = m; hm->hm_pb = pb; if(pb != NULL) pktbuf_ref_inc(pb); hm->hm_payloadsize = payloadsize; pthread_mutex_lock(&htsp->htsp_out_mutex); TAILQ_INSERT_TAIL(&hmq->hmq_q, hm, hm_link); if(hmq->hmq_length == 0) { /* Activate queue */ if(hmq->hmq_strict_prio) { TAILQ_INSERT_HEAD(&htsp->htsp_active_output_queues, hmq, hmq_link); } else { TAILQ_INSERT_TAIL(&htsp->htsp_active_output_queues, hmq, hmq_link); } } hmq->hmq_length++; hmq->hmq_payload += payloadsize; pthread_cond_signal(&htsp->htsp_out_cond); pthread_mutex_unlock(&htsp->htsp_out_mutex); }
streaming_message_t * streaming_msg_clone(streaming_message_t *src) { streaming_message_t *dst = malloc(sizeof(streaming_message_t)); streaming_start_t *ss; dst->sm_type = src->sm_type; #if ENABLE_TIMESHIFT dst->sm_time = src->sm_time; #endif switch(src->sm_type) { case SMT_PACKET: pkt_ref_inc(src->sm_data); dst->sm_data = src->sm_data; break; case SMT_START: ss = dst->sm_data = src->sm_data; atomic_add(&ss->ss_refcount, 1); break; case SMT_SKIP: dst->sm_data = malloc(sizeof(streaming_skip_t)); memcpy(dst->sm_data, src->sm_data, sizeof(streaming_skip_t)); break; case SMT_SIGNAL_STATUS: dst->sm_data = malloc(sizeof(signal_status_t)); memcpy(dst->sm_data, src->sm_data, sizeof(signal_status_t)); break; case SMT_TIMESHIFT_STATUS: dst->sm_data = malloc(sizeof(timeshift_status_t)); memcpy(dst->sm_data, src->sm_data, sizeof(timeshift_status_t)); break; case SMT_GRACE: case SMT_SPEED: case SMT_STOP: case SMT_SERVICE_STATUS: case SMT_NOSTART: dst->sm_code = src->sm_code; break; case SMT_EXIT: break; case SMT_MPEGTS: pktbuf_ref_inc(src->sm_data); dst->sm_data = src->sm_data; break; default: abort(); } return dst; }
th_pkt_t * pkt_copy_shallow(th_pkt_t *pkt) { th_pkt_t *n = malloc(sizeof(th_pkt_t)); if (n) { blacklisted_memcpy(n, pkt, sizeof(*pkt)); n->pkt_refcount = 1; pktbuf_ref_inc(n->pkt_meta); pktbuf_ref_inc(n->pkt_payload); memoryinfo_alloc(&pkt_memoryinfo, sizeof(*pkt)); } return n; }
streaming_start_t * streaming_start_copy(const streaming_start_t *src) { int i; size_t siz = sizeof(streaming_start_t) + sizeof(streaming_start_component_t) * src->ss_num_components; streaming_start_t *dst = malloc(siz); memcpy(dst, src, siz); service_source_info_copy(&dst->ss_si, &src->ss_si); for(i = 0; i < dst->ss_num_components; i++) { streaming_start_component_t *ssc = &dst->ss_components[i]; if(ssc->ssc_gh != NULL) pktbuf_ref_inc(ssc->ssc_gh); } dst->ss_refcount = 1; return dst; }
streaming_message_t * streaming_msg_clone(streaming_message_t *src) { streaming_message_t *dst = malloc(sizeof(streaming_message_t)); streaming_start_t *ss; memoryinfo_alloc(&streaming_msg_memoryinfo, sizeof(*dst)); dst->sm_type = src->sm_type; #if ENABLE_TIMESHIFT dst->sm_time = src->sm_time; #endif switch(src->sm_type) { case SMT_PACKET: pkt_ref_inc(src->sm_data); dst->sm_data = src->sm_data; break; case SMT_START: ss = dst->sm_data = src->sm_data; streaming_start_ref(ss); break; case SMT_SKIP: dst->sm_data = malloc(sizeof(streaming_skip_t)); memcpy(dst->sm_data, src->sm_data, sizeof(streaming_skip_t)); break; case SMT_SIGNAL_STATUS: dst->sm_data = malloc(sizeof(signal_status_t)); memcpy(dst->sm_data, src->sm_data, sizeof(signal_status_t)); break; case SMT_DESCRAMBLE_INFO: dst->sm_data = malloc(sizeof(descramble_info_t)); memcpy(dst->sm_data, src->sm_data, sizeof(descramble_info_t)); break; case SMT_TIMESHIFT_STATUS: dst->sm_data = malloc(sizeof(timeshift_status_t)); memcpy(dst->sm_data, src->sm_data, sizeof(timeshift_status_t)); break; case SMT_GRACE: case SMT_SPEED: case SMT_STOP: case SMT_SERVICE_STATUS: case SMT_NOSTART: case SMT_NOSTART_WARN: dst->sm_code = src->sm_code; break; case SMT_EXIT: break; case SMT_MPEGTS: pktbuf_ref_inc(src->sm_data); dst->sm_data = src->sm_data; break; default: abort(); } return dst; }