toxcore/toxav/codec.h

126 lines
3.5 KiB
C
Raw Normal View History

/** codec.h
2014-02-17 09:01:30 +08:00
*
* Copyright (C) 2013-2015 Tox project All Rights Reserved.
*
2014-02-16 05:36:15 +08:00
* This file is part of Tox.
*
2014-02-16 05:36:15 +08:00
* Tox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
2014-02-16 05:36:15 +08:00
* Tox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2014-02-16 05:36:15 +08:00
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CODEC_H
#define CODEC_H
2014-11-18 07:46:46 +08:00
#include "toxav.h"
#include "rtp.h"
#include <stdio.h>
#include <math.h>
2014-02-16 03:44:33 +08:00
#include <pthread.h>
2014-02-01 19:52:48 +08:00
2014-02-16 03:44:33 +08:00
#include <vpx/vpx_decoder.h>
#include <vpx/vpx_encoder.h>
#include <vpx/vp8dx.h>
#include <vpx/vp8cx.h>
2014-11-18 07:46:46 +08:00
#include <vpx/vpx_image.h>
2014-02-16 03:44:33 +08:00
#define VIDEO_CODEC_DECODER_INTERFACE (vpx_codec_vp8_dx())
#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx())
2014-02-01 19:52:48 +08:00
/* Audio encoding/decoding */
#include <opus.h>
2014-11-29 20:42:19 +08:00
#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; }
2015-03-29 08:10:34 +08:00
typedef struct CSession_s {
2014-06-21 07:58:55 +08:00
/* VIDEO
*
*
*/
/* video encoding */
2015-01-25 06:29:54 +08:00
vpx_codec_ctx_t v_encoder[1];
2014-02-16 03:44:33 +08:00
uint32_t frame_counter;
/* video decoding */
2015-01-25 06:29:54 +08:00
vpx_codec_ctx_t v_decoder[1];
void *vbuf_raw; /* Un-decoded data */
/* Data handling */
2014-11-18 07:46:46 +08:00
uint8_t *frame_buf; /* buffer for split video payloads */
uint32_t frame_size; /* largest address written to in frame_buf for current input frame */
2014-11-18 07:46:46 +08:00
uint8_t frameid_in, frameid_out; /* id of input and output video frame */
uint32_t last_timestamp; /* calculating cycles */
2014-11-18 07:46:46 +08:00
/* Limits */
uint32_t peer_video_frame_piece_size;
2015-02-02 06:43:54 +08:00
/* Splitting */
2014-11-18 07:46:46 +08:00
uint8_t *split_video_frame;
const uint8_t *processing_video_frame;
uint16_t processing_video_frame_size;
/* AUDIO
*
*
*/
2014-11-18 07:46:46 +08:00
/* audio encoding */
2014-02-01 19:52:48 +08:00
OpusEncoder *audio_encoder;
2015-03-29 08:10:34 +08:00
int32_t last_encoding_sampling_rate;
int32_t last_encoding_channel_count;
int32_t last_encoding_bitrate;
2015-01-25 06:29:54 +08:00
/* audio decoding */
2014-02-01 19:52:48 +08:00
OpusDecoder *audio_decoder;
2015-03-29 08:10:34 +08:00
int32_t last_packet_channel_count;
2015-02-02 06:43:54 +08:00
int32_t last_packet_sampling_rate;
int32_t last_packet_frame_duration;
struct JitterBuffer_s *j_buf;
/* OTHER
*
*
*/
2015-03-29 08:10:34 +08:00
ToxAV *av;
int32_t friend_id;
PAIR(toxav_receive_audio_frame_cb *, void *) acb; /* Audio frame receive callback */
PAIR(toxav_receive_video_frame_cb *, void *) vcb; /* Video frame receive callback */
2015-01-25 06:29:54 +08:00
pthread_mutex_t queue_mutex[1];
2015-03-29 08:10:34 +08:00
} CSession;
2014-02-01 19:52:48 +08:00
2014-11-18 07:46:46 +08:00
2015-03-29 08:10:34 +08:00
void cs_do(CSession *cs);
2015-02-02 06:43:54 +08:00
/* Make sure to be called BEFORE corresponding rtp_new */
2015-03-29 08:10:34 +08:00
CSession *cs_new(uint32_t peer_mvfpsz);
2015-02-02 06:43:54 +08:00
/* Make sure to be called AFTER corresponding rtp_kill */
2015-03-29 08:10:34 +08:00
void cs_kill(CSession *cs);
2015-02-02 06:43:54 +08:00
2015-03-29 08:10:34 +08:00
void cs_init_video_splitter_cycle(CSession *cs);
int cs_update_video_splitter_cycle(CSession* cs, const uint8_t* payload, uint16_t length);
const uint8_t *cs_iterate_split_video_frame(CSession *cs, uint16_t *size);
2015-02-02 06:43:54 +08:00
2015-03-29 08:10:34 +08:00
int cs_reconfigure_video_encoder(CSession* cs, int32_t bitrate, uint16_t width, uint16_t height);
int cs_reconfigure_audio_encoder(CSession* cs, int32_t bitrate, int32_t sampling_rate, uint8_t channels);
2015-02-02 06:43:54 +08:00
2014-06-21 07:58:55 +08:00
2014-11-18 07:46:46 +08:00
/* Internal. Called from rtp_handle_message */
void queue_message(RTPSession *session, RTPMessage *msg);
#endif /* CODEC_H */