$ git clone http://tcclient.ion.nu/tc_client.git
commit e778e72400868a7cdb81d39e33a4b9f6cda15379
Author: Alicia <...>
Date: Sat May 16 01:12:55 2015 +0200
tc_client-gtk and camviewer: fixed the code for fallback on libswresample.
diff --git a/ChangeLog b/ChangeLog
index 6336fa9..5343165 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ Fixed the issue where messages would show up on kanji on some platforms (a prope
When a message is sent with a privacy field, send it once with 'b' (broadcasting) and once with 'n' (not-broadcasting)
tc_client-gtk: added a margin to the autoscroll code, which should make scrolling work better when resizing the window or panes.
tc_client-gtk: copied and adjusted the code for keeping track of our own nickname from cursedchat.
+tc_client-gtk and camviewer: fixed the code for fallback on libswresample.
modbot: added a little note about the video being pre-approved when requesting an already approved video.
modbot: include the video title at the end of the /mbs command, which doesn't affect the flash client but lets e.g. tc_client users know which video is being played.
cursedchat: copied and adjusted the code for keeping track of our own text color from tc_client-gtk.
diff --git a/Makefile b/Makefile
index 8447c72..6ca5e3a 100644
--- a/Makefile
+++ b/Makefile
@@ -19,10 +19,10 @@ ifdef SWSCALE_LIBS
CFLAGS+=$(GTK_CFLAGS) $(AVCODEC_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS)
ifdef AO_LIBS
ifdef AVRESAMPLE_LIBS
- CFLAGS+=-DHAVE_SOUND=avresample $(AVRESAMPLE_CFLAGS) $(AO_CFLAGS)
+ CFLAGS+=-DHAVE_AVRESAMPLE=1 $(AVRESAMPLE_CFLAGS) $(AO_CFLAGS)
endif
ifdef SWRESAMPLE_LIBS
- CFLAGS+=-DHAVE_SOUND=swresample $(SWRESAMPLE_CFLAGS) $(AO_CFLAGS)
+ CFLAGS+=-DHAVE_SWRESAMPLE=1 $(SWRESAMPLE_CFLAGS) $(AO_CFLAGS)
endif
endif
ifdef LIBV4L2_LIBS
diff --git a/utilities/camviewer/camviewer.c b/utilities/camviewer/camviewer.c
index 174c60a..1d83ca9 100644
--- a/utilities/camviewer/camviewer.c
+++ b/utilities/camviewer/camviewer.c
@@ -26,14 +26,13 @@
#else
#include <libavcore/imgutils.h>
#endif
-#ifdef HAVE_SOUND
-// TODO: use libavresample instead if available
- #if HAVE_SOUND==avresample
- #include <libavutil/opt.h>
- #include <libavresample/avresample.h>
- #else
- #include <libswresample/swresample.h>
- #endif
+// Use libavresample instead if available
+#ifdef HAVE_AVRESAMPLE
+ #include <libavutil/opt.h>
+ #include <libavresample/avresample.h>
+ #include <ao/ao.h>
+#elif defined(HAVE_SWRESAMPLE)
+ #include <libswresample/swresample.h>
#include <ao/ao.h>
#endif
#include <gtk/gtk.h>
@@ -78,20 +77,19 @@ struct viddata
AVCodec* vdecoder;
AVCodec* vencoder;
AVCodec* adecoder;
-#ifdef HAVE_SOUND
+#ifdef HAVE_AVRESAMPLE
int audiopipe;
- #if HAVE_SOUND==avresample
- AVAudioResampleContext* resamplectx;
- #else
- SwrContext* swrctx;
- #endif
+ AVAudioResampleContext* resamplectx;
+#elif defined(HAVE_SWRESAMPLE)
+ int audiopipe;
+ SwrContext* swrctx;
#endif
};
int tc_client[2];
int tc_client_in[2];
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
// Experimental mixer, not sure if it really works
void camera_playsnd(struct viddata* data, struct camera* cam, short* samples, unsigned int samplecount)
{
@@ -132,7 +130,7 @@ void camera_remove(struct viddata* data, const char* nick)
gtk_widget_destroy(data->cams[i].box);
av_frame_free(&data->cams[i].frame);
avcodec_free_context(&data->cams[i].vctx);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
avcodec_free_context(&data->cams[i].actx);
#endif
free(data->cams[i].id);
@@ -203,7 +201,7 @@ gboolean handledata(GIOChannel* channel, GIOCondition condition, gpointer datap)
cam->id=strdup(id);
cam->vctx=avcodec_alloc_context3(data->vdecoder);
avcodec_open2(cam->vctx, data->vdecoder, 0);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
cam->actx=avcodec_alloc_context3(data->adecoder);
avcodec_open2(cam->actx, data->adecoder, 0);
cam->samples=0;
@@ -260,7 +258,7 @@ gboolean handledata(GIOChannel* channel, GIOCondition condition, gpointer datap)
{
pos+=read(tc_client[0], pkt.data+pos, size-pos);
}
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
// Find the camera representation for the given ID (for decoder context)
struct camera* cam=0;
for(i=0; i<data->camcount; ++i)
@@ -271,10 +269,10 @@ gboolean handledata(GIOChannel* channel, GIOCondition condition, gpointer datap)
int gotframe;
avcodec_decode_audio4(cam->actx, cam->frame, &gotframe, &pkt);
if(!gotframe){return 1;}
- #if HAVE_SOUND==avresample
+ #ifdef HAVE_AVRESAMPLE
int outlen=avresample_convert(data->resamplectx, cam->frame->data, cam->frame->linesize[0], cam->frame->nb_samples, cam->frame->data, cam->frame->linesize[0], cam->frame->nb_samples);
#else
- int outlen=swr_convert(data->resamplectx, cam->frame->data, cam->frame->nb_samples, (const uint8_t**)cam->frame->data, cam->frame->nb_samples);
+ int outlen=swr_convert(data->swrctx, cam->frame->data, cam->frame->nb_samples, (const uint8_t**)cam->frame->data, cam->frame->nb_samples);
#endif
camera_playsnd(data, cam, (short*)cam->frame->data[0], outlen);
#endif
@@ -332,7 +330,7 @@ gboolean handledata(GIOChannel* channel, GIOCondition condition, gpointer datap)
return 1;
}
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
void audiothread(int fd)
{
ao_initialize();
@@ -457,8 +455,8 @@ int main(int argc, char** argv)
data.vdecoder=avcodec_find_decoder(AV_CODEC_ID_FLV1);
data.adecoder=avcodec_find_decoder(AV_CODEC_ID_NELLYMOSER);
-#ifdef HAVE_SOUND
- #if HAVE_SOUND==avresample
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
+ #ifdef HAVE_AVRESAMPLE
data.resamplectx=avresample_alloc_context();
av_opt_set_int(data.resamplectx, "in_channel_layout", AV_CH_FRONT_CENTER, 0);
av_opt_set_int(data.resamplectx, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
@@ -469,7 +467,7 @@ int main(int argc, char** argv)
av_opt_set_int(data.resamplectx, "out_sample_rate", 22050, 0);
avresample_open(data.resamplectx);
#else
- data.resamplectx=swr_alloc_set_opts(0, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_S16, 22050, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_FLT, 11025, 0, 0);
+ data.swrctx=swr_alloc_set_opts(0, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_S16, 22050, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_FLT, 11025, 0, 0);
swr_init(data.swrctx);
#endif
int audiopipe[2];
@@ -524,13 +522,12 @@ int main(int argc, char** argv)
{
av_frame_free(&data.cams[i].frame);
avcodec_free_context(&data.cams[i].vctx);
-#ifdef HAVE_SOUND
+#ifdef HAVE_AVRESAMPLE
avcodec_free_context(&data.cams[i].actx);
- #if HAVE_SOUND==avresample
avresample_free(&data.resamplectx);
- #else
+#elif defined(HAVE_SWRESAMPLE)
+ avcodec_free_context(&data.cams[i].actx);
swr_free(&data.swrctx);
- #endif
#endif
free(data.cams[i].id);
free(data.cams[i].nick);
diff --git a/utilities/gtk/camviewer.c b/utilities/gtk/camviewer.c
index e2c708b..fe0e854 100644
--- a/utilities/gtk/camviewer.c
+++ b/utilities/gtk/camviewer.c
@@ -29,14 +29,13 @@
#else
#include <libavcore/imgutils.h>
#endif
-#ifdef HAVE_SOUND
- // Use libavresample if available, otherwise fall back on libswresample
- #if HAVE_SOUND==avresample
- #include <libavutil/opt.h>
- #include <libavresample/avresample.h>
- #else
- #include <libswresample/swresample.h>
- #endif
+// Use libavresample if available, otherwise fall back on libswresample
+#ifdef HAVE_AVRESAMPLE
+ #include <libavutil/opt.h>
+ #include <libavresample/avresample.h>
+ #include <ao/ao.h>
+#elif defined(HAVE_SWRESAMPLE)
+ #include <libswresample/swresample.h>
#include <ao/ao.h>
#endif
#include <gtk/gtk.h>
@@ -61,13 +60,12 @@ struct viddata
AVCodec* adecoder;
int scalewidth;
int scaleheight;
-#ifdef HAVE_SOUND
+#ifdef HAVE_AVRESAMPLE
int audiopipe;
- #if HAVE_SOUND==avresample
- AVAudioResampleContext* resamplectx;
- #else
- SwrContext* swrctx;
- #endif
+ AVAudioResampleContext* resamplectx;
+#elif defined(HAVE_SWRESAMPLE)
+ int audiopipe;
+ SwrContext* swrctx;
#endif
GtkTextBuffer* buffer; // TODO: struct buffer array, for PMs
GtkAdjustment* scroll;
@@ -349,7 +347,7 @@ gboolean handledata(GIOChannel* iochannel, GIOCondition condition, gpointer data
cam->id=strdup(id);
cam->vctx=avcodec_alloc_context3(data->vdecoder);
avcodec_open2(cam->vctx, data->vdecoder, 0);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
cam->actx=avcodec_alloc_context3(data->adecoder);
avcodec_open2(cam->actx, data->adecoder, 0);
cam->samples=0;
@@ -415,17 +413,17 @@ gboolean handledata(GIOChannel* iochannel, GIOCondition condition, gpointer data
{
pos+=read(fd, pkt.data+pos, size-pos);
}
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
// Find the camera representation for the given ID (for decoder context)
struct camera* cam=camera_find(&buf[7]);
if(!cam){printf("No cam found with ID '%s'\n", &buf[7]); return 1;}
int gotframe;
avcodec_decode_audio4(cam->actx, cam->frame, &gotframe, &pkt);
if(!gotframe){return 1;}
- #if HAVE_SOUND==avresample
+ #ifdef HAVE_AVRESAMPLE
int outlen=avresample_convert(data->resamplectx, cam->frame->data, cam->frame->linesize[0], cam->frame->nb_samples, cam->frame->data, cam->frame->linesize[0], cam->frame->nb_samples);
#else
- int outlen=swr_convert(data->resamplectx, cam->frame->data, cam->frame->nb_samples, (const uint8_t**)cam->frame->data, cam->frame->nb_samples);
+ int outlen=swr_convert(data->swrctx, cam->frame->data, cam->frame->nb_samples, (const uint8_t**)cam->frame->data, cam->frame->nb_samples);
#endif
camera_playsnd(data->audiopipe, cam, (short*)cam->frame->data[0], outlen);
#endif
@@ -478,7 +476,7 @@ gboolean handledata(GIOChannel* iochannel, GIOCondition condition, gpointer data
return 1;
}
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
void audiothread(int fd)
{
ao_initialize();
@@ -773,8 +771,8 @@ int main(int argc, char** argv)
data.vdecoder=avcodec_find_decoder(AV_CODEC_ID_FLV1);
data.adecoder=avcodec_find_decoder(AV_CODEC_ID_NELLYMOSER);
-#ifdef HAVE_SOUND
- #if HAVE_SOUND==avresample
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
+ #ifdef HAVE_AVRESAMPLE
data.resamplectx=avresample_alloc_context();
av_opt_set_int(data.resamplectx, "in_channel_layout", AV_CH_FRONT_CENTER, 0);
av_opt_set_int(data.resamplectx, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
@@ -785,7 +783,7 @@ int main(int argc, char** argv)
av_opt_set_int(data.resamplectx, "out_sample_rate", 22050, 0);
avresample_open(data.resamplectx);
#else
- data.resamplectx=swr_alloc_set_opts(0, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_S16, 22050, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_FLT, 11025, 0, 0);
+ data.swrctx=swr_alloc_set_opts(0, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_S16, 22050, AV_CH_FRONT_CENTER, AV_SAMPLE_FMT_FLT, 11025, 0, 0);
swr_init(data.swrctx);
#endif
int audiopipe[2];
@@ -892,12 +890,10 @@ int main(int argc, char** argv)
gtk_main();
camera_cleanup();
-#ifdef HAVE_SOUND
- #if HAVE_SOUND==avresample
+#ifdef HAVE_AVRESAMPLE
avresample_free(&data.resamplectx);
- #else
+#elif defined(HAVE_SWRESAMPLE)
swr_free(&data.swrctx);
- #endif
#endif
return 0;
}
diff --git a/utilities/gtk/media.c b/utilities/gtk/media.c
index e7fbb24..d8b103d 100644
--- a/utilities/gtk/media.c
+++ b/utilities/gtk/media.c
@@ -22,7 +22,7 @@
struct camera* cams=0;
unsigned int camcount=0;
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
// Experimental mixer, not sure if it really works
void camera_playsnd(int audiopipe, struct camera* cam, short* samples, unsigned int samplecount)
{
@@ -63,7 +63,7 @@ void camera_remove(const char* id)
gtk_widget_destroy(cams[i].box);
av_frame_free(&cams[i].frame);
avcodec_free_context(&cams[i].vctx);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
avcodec_free_context(&cams[i].actx);
#endif
free(cams[i].id);
@@ -85,7 +85,7 @@ void camera_removebynick(const char* nick)
gtk_widget_destroy(cams[i].box);
av_frame_free(&cams[i].frame);
avcodec_free_context(&cams[i].vctx);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
avcodec_free_context(&cams[i].actx);
#endif
free(cams[i].id);
@@ -131,7 +131,7 @@ void camera_cleanup(void)
{
av_frame_free(&cams[i].frame);
avcodec_free_context(&cams[i].vctx);
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
avcodec_free_context(&cams[i].actx);
#endif
free(cams[i].id);
diff --git a/utilities/gtk/media.h b/utilities/gtk/media.h
index 159e998..bd283e7 100644
--- a/utilities/gtk/media.h
+++ b/utilities/gtk/media.h
@@ -31,7 +31,7 @@ struct camera
extern struct camera* cams;
extern unsigned int camcount;
-#ifdef HAVE_SOUND
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
extern void camera_playsnd(int audiopipe, struct camera* cam, short* samples, unsigned int samplecount);
#endif
extern void camera_remove(const char* nick);