diff options
Diffstat (limited to 'toxav/toxmedia.h')
-rw-r--r-- | toxav/toxmedia.h | 99 |
1 files changed, 33 insertions, 66 deletions
diff --git a/toxav/toxmedia.h b/toxav/toxmedia.h index aad299bb..927c5ef8 100644 --- a/toxav/toxmedia.h +++ b/toxav/toxmedia.h | |||
@@ -27,25 +27,25 @@ | |||
27 | 27 | ||
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | #include <math.h> | 29 | #include <math.h> |
30 | #include "toxrtp.h" | ||
31 | #include "toxmsi.h" | ||
32 | #include "../toxcore/tox.h" | ||
33 | |||
34 | /* Video encoding/decoding */ | ||
30 | #include <libavcodec/avcodec.h> | 35 | #include <libavcodec/avcodec.h> |
31 | #include <libavformat/avformat.h> | 36 | #include <libavformat/avformat.h> |
32 | #include <libswscale/swscale.h> | 37 | #include <libswscale/swscale.h> |
33 | #include <libavdevice/avdevice.h> | 38 | #include <libavdevice/avdevice.h> |
34 | #include <libavutil/opt.h> | 39 | #include <libavutil/opt.h> |
35 | #include <pthread.h> | ||
36 | #include <AL/al.h> | ||
37 | #include <AL/alc.h> | ||
38 | #include "toxrtp.h" | ||
39 | #include "tox.h" | ||
40 | 40 | ||
41 | #include <SDL/SDL.h> | 41 | /* Audio encoding/decoding */ |
42 | #include <opus/opus.h> | 42 | #include <opus/opus.h> |
43 | 43 | ||
44 | /* ffmpeg VP8 codec ID */ | 44 | /* ffmpeg VP8 codec ID */ |
45 | #define VIDEO_CODEC AV_CODEC_ID_VP8 | 45 | #define VIDEO_CODEC AV_CODEC_ID_VP8 |
46 | 46 | ||
47 | /* ffmpeg Opus codec ID */ | 47 | /* ffmpeg Opus codec ID */ |
48 | #define AUDIO_CODEC AV_CODEC_ID_OPUS | 48 | #define AUDIO_CODEC AV_CODEC_ID_OPUS |
49 | 49 | ||
50 | /* default video bitrate in bytes/s */ | 50 | /* default video bitrate in bytes/s */ |
51 | #define VIDEO_BITRATE 10*1000 | 51 | #define VIDEO_BITRATE 10*1000 |
@@ -75,14 +75,6 @@ | |||
75 | #define DEFAULT_WEBCAM "0" | 75 | #define DEFAULT_WEBCAM "0" |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | extern SDL_Surface *screen; | ||
79 | |||
80 | typedef struct { | ||
81 | SDL_Overlay *bmp; | ||
82 | int width, height; | ||
83 | } VideoPicture; | ||
84 | |||
85 | |||
86 | typedef struct { | 78 | typedef struct { |
87 | uint8_t send_audio; | 79 | uint8_t send_audio; |
88 | uint8_t receive_audio; | 80 | uint8_t receive_audio; |
@@ -95,71 +87,46 @@ typedef struct { | |||
95 | uint8_t support_receive_video; | 87 | uint8_t support_receive_video; |
96 | 88 | ||
97 | /* video encoding */ | 89 | /* video encoding */ |
98 | AVInputFormat *video_input_format; | 90 | AVInputFormat *video_input_format; |
99 | AVFormatContext *video_format_ctx; | 91 | AVFormatContext *video_format_ctx; |
100 | uint8_t video_stream; | 92 | uint8_t video_stream; |
101 | AVCodecContext *webcam_decoder_ctx; | 93 | AVCodecContext *webcam_decoder_ctx; |
102 | AVCodec *webcam_decoder; | 94 | AVCodec *webcam_decoder; |
103 | AVCodecContext *video_encoder_ctx; | 95 | AVCodecContext *video_encoder_ctx; |
104 | AVCodec *video_encoder; | 96 | AVCodec *video_encoder; |
105 | 97 | ||
106 | /* video decoding */ | 98 | /* video decoding */ |
107 | AVCodecContext *video_decoder_ctx; | 99 | AVCodecContext *video_decoder_ctx; |
108 | AVCodec *video_decoder; | 100 | AVCodec *video_decoder; |
109 | 101 | ||
110 | /* audio encoding */ | 102 | /* audio encoding */ |
111 | ALCdevice *audio_capture_device; | 103 | OpusEncoder *audio_encoder; |
112 | OpusEncoder *audio_encoder; | 104 | int audio_bitrate; |
113 | int audio_bitrate; | ||
114 | 105 | ||
115 | /* audio decoding */ | 106 | /* audio decoding */ |
116 | OpusDecoder *audio_decoder; | 107 | OpusDecoder *audio_decoder; |
117 | 108 | ||
118 | uint8_t req_video_refresh; | 109 | uint8_t req_video_refresh; |
119 | |||
120 | /* context for converting image format to something SDL can use*/ | ||
121 | struct SwsContext *sws_SDL_r_ctx; | ||
122 | |||
123 | /* context for converting webcam image format to something the video encoder can use */ | ||
124 | struct SwsContext *sws_ctx; | ||
125 | |||
126 | /* rendered video picture, ready for display */ | ||
127 | VideoPicture video_picture; | ||
128 | |||
129 | RTPSession *_rtp_video; | ||
130 | RTPSession *_rtp_audio; | ||
131 | |||
132 | Tox* _messenger; | ||
133 | 110 | ||
134 | pthread_t encode_audio_thread; | ||
135 | pthread_t encode_video_thread; | ||
136 | |||
137 | pthread_t decode_audio_thread; | ||
138 | pthread_t decode_video_thread; | ||
139 | |||
140 | pthread_mutex_t rtp_msg_mutex_lock; | 111 | pthread_mutex_t rtp_msg_mutex_lock; |
141 | pthread_mutex_t avcodec_mutex_lock; | 112 | pthread_mutex_t avcodec_mutex_lock; |
113 | |||
114 | uint8_t quit; | ||
115 | |||
116 | uint32_t frame_rate; | ||
142 | 117 | ||
143 | uint8_t quit; | 118 | } codec_state; |
144 | SDL_Event SDL_event; | ||
145 | 119 | ||
146 | MSISession *_msi; | ||
147 | uint32_t _frame_rate; | ||
148 | 120 | ||
149 | } codec_state; | 121 | struct jitter_buffer *create_queue(int capacity); |
122 | int empty_queue(struct jitter_buffer *q); | ||
123 | |||
124 | int queue(struct jitter_buffer *q, RTPMessage *pk); | ||
125 | RTPMessage *dequeue(struct jitter_buffer *q, int *success); | ||
126 | |||
150 | 127 | ||
151 | int display_received_frame(codec_state *cs, AVFrame *r_video_frame); | ||
152 | int init_receive_audio(codec_state *cs); | ||
153 | int init_decoder(codec_state *cs); | ||
154 | int init_send_video(codec_state *cs); | ||
155 | int init_send_audio(codec_state *cs); | ||
156 | int init_encoder(codec_state *cs); | 128 | int init_encoder(codec_state *cs); |
157 | int video_encoder_refresh(codec_state *cs, int bps); | 129 | int init_decoder(codec_state *cs); |
158 | void *encode_video_thread(void *arg); | 130 | |
159 | void *encode_audio_thread(void *arg); | ||
160 | int video_decoder_refresh(codec_state *cs, int width, int height); | ||
161 | int handle_rtp_video_packet(codec_state *cs, RTPMessage *r_msg); | ||
162 | void *decode_video_thread(void *arg); | ||
163 | void *decode_audio_thread(void *arg); | ||
164 | 131 | ||
165 | #endif | 132 | #endif |