/** * @brief Encode and send video packet. * * @param av Handler. * @param input The packet. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ inline__ int toxav_send_video ( ToxAv *av, vpx_image_t *input) { if (vpx_codec_encode(&av->cs->v_encoder, input, av->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US) != VPX_CODEC_OK) { fprintf(stderr, "Could not encode video frame\n"); return ErrorInternal; } ++av->cs->frame_counter; vpx_codec_iter_t iter = NULL; const vpx_codec_cx_pkt_t *pkt; int sent = 0; while ( (pkt = vpx_codec_get_cx_data(&av->cs->v_encoder, &iter)) ) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (toxav_send_rtp_payload(av, TypeVideo, pkt->data.frame.buf, pkt->data.frame.sz) != -1) ++sent; } } if (sent > 0) return 0; return ErrorInternal; }
/** * @brief Send audio frame. * * @param av Handler. * @param data The audio data encoded with toxav_prepare_audio_frame(). * @param size Its size in number of bytes. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *data, unsigned int size) { if (size > MAX_CRYPTO_DATA_SIZE) return ErrorInternal; if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { LOGGER_WARNING("Action on inactive call: %d", call_index); return ErrorNoCall; } CallSpecific *call = &av->calls[call_index]; pthread_mutex_lock(&call->mutex); if (!call->call_active) { pthread_mutex_unlock(&call->mutex); LOGGER_WARNING("Action on inactive call: %d", call_index); return ErrorNoCall; } int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, data, size); pthread_mutex_unlock(&call->mutex); return rc; }
/** * @brief Send audio frame. * * @param av Handler. * @param frame The frame (raw 16 bit signed pcm with AUDIO_CHANNELS channels audio.) * @param frame_size Its size in number of frames/samples (one frame/sample is 16 bits or 2 bytes) * frame size should be AUDIO_FRAME_SIZE. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) { if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { LOGGER_WARNING("Action on inactive call: %d", call_index); return ErrorNoCall; } return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); }
/** * @brief Encode and send audio frame. * * @param av Handler. * @param frame The frame (raw 16 bit signed pcm with AUDIO_CHANNELS channels audio.) * @param frame_size Its size in number of frames/samples (one frame/sample is 16 bits or 2 bytes) * frame size should be AUDIO_FRAME_SIZE. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ inline__ int toxav_send_audio ( ToxAv *av, const int16_t *frame, int frame_size) { uint8_t temp_data[RTP_PAYLOAD_SIZE]; int32_t ret = opus_encode(av->cs->audio_encoder, frame, frame_size, temp_data, sizeof(temp_data)); if (ret <= 0) return ErrorInternal; return toxav_send_rtp_payload(av, TypeAudio, temp_data, ret); }
/** * @brief Encode and send video packet. * * @param av Handler. * @param input The packet. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, unsigned int frame_size) { if (cii(call_index, av->msi_session)) { LOGGER_WARNING("Invalid call index: %d", call_index); return ErrorNoCall; } CallSpecific *call = &av->calls[call_index]; pthread_mutex_lock(&call->mutex); if (!call->call_active) { pthread_mutex_unlock(&call->mutex); LOGGER_WARNING("Action on inactive call: %d", call_index); return ErrorNoCall; } int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); pthread_mutex_unlock(&call->mutex); return rc; }
/** * @brief Send audio frame. * * @param av Handler. * @param frame The frame (raw 16 bit signed pcm with AUDIO_CHANNELS channels audio.) * @param frame_size Its size in number of frames/samples (one frame/sample is 16 bits or 2 bytes) * frame size should be AUDIO_FRAME_SIZE. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) { return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); }
/** * @brief Send audio frame. * * @param av Handler. * @param frame The frame (raw 16 bit signed pcm with AUDIO_CHANNELS channels audio.) * @param frame_size Its size in number of frames/samples (one frame/sample is 16 bits or 2 bytes) * frame size should be AUDIO_FRAME_SIZE. * @return int * @retval 0 Success. * @retval ToxAvError On error. */ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) { if (cii(call_index, av->msi_session)) return ErrorNoCall; return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); }