From 8cb96bb66d3de04a3dae3e2c886c4a49736f1b65 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 21 Sep 2014 20:41:25 +0200 Subject: Centralise all media configuration values in mediaconfig.h --- src/audioinput.cc | 6 ++++-- src/mediaconfig.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/opusdecoder.cc | 4 +++- src/opusencoder.cc | 12 ++++-------- src/soundplayer.cc | 4 +++- src/soundplayer.h | 5 +++-- src/v4l.cc | 8 +++++--- src/videowidget.cc | 4 +++- 8 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/mediaconfig.h diff --git a/src/audioinput.cc b/src/audioinput.cc index a94d208..e0b4970 100644 --- a/src/audioinput.cc +++ b/src/audioinput.cc @@ -28,10 +28,12 @@ #include +#include "mediaconfig.h" + AudioInput::AudioInput(const char *device) { int err; - ai = ai_init(&err, device, "", 16000, 1); + ai = ai_init(&err, device, "", SAMPLERATE, 1); if(ai == NULL || err) { printf("ai_init: %d\n", err); return; @@ -39,7 +41,7 @@ AudioInput::AudioInput(const char *device) int srate = ai_get_samplerate(&err, ai); if(err) printf("ai_get_samplerate: %d\n", err); - if(srate != 16000) { + if(srate != SAMPLERATE) { printf("Samplerate: %d\n", srate); } } diff --git a/src/mediaconfig.h b/src/mediaconfig.h new file mode 100644 index 0000000..747cf80 --- /dev/null +++ b/src/mediaconfig.h @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mediaconfig.h + * + * Sun Sep 21 20:34:00 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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 2 of the License, or + * (at your option) any later version. + * + * SimpleRTP 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. + * + * You should have received a copy of the GNU General Public License + * along with SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __SIMPLERTP_MEDIACONFIG_H__ +#define __SIMPLERTP_MEDIACONFIG_H__ + + +#define V4LWIDTH 640 +#define V4LHEIGHT 480 + +#define SAMPLERATE 16000 + +// 500 to 512000 +#define OPUS_BITRATE 64000 + +// Frame size 10ms +#define OPUS_FRAME_SIZE 10 + +#endif/*__SIMPLERTP_MEDIACONFIG_H__*/ diff --git a/src/opusdecoder.cc b/src/opusdecoder.cc index 6366e78..016eb6a 100644 --- a/src/opusdecoder.cc +++ b/src/opusdecoder.cc @@ -26,10 +26,12 @@ */ #include "opusdecoder.h" +#include "mediaconfig.h" + OpusDecoder::OpusDecoder() { int err; - decoder = opus_decoder_create(16000, 1, &err); + decoder = opus_decoder_create(SAMPLERATE, 1, &err); if(err) printf("opus_decoder_create: %d\n", err); } diff --git a/src/opusencoder.cc b/src/opusencoder.cc index 27bdb90..a3fee36 100644 --- a/src/opusencoder.cc +++ b/src/opusencoder.cc @@ -29,17 +29,13 @@ #include #include -// 500 to 512000 -#define OPUS_BITRATE 64000 - -// Frame size 10ms -#define OPUS_FRAME_SIZE 10 +#include "mediaconfig.h" OpusEncoder::OpusEncoder() : cache(5760 * 10) { int err = 0; - encoder = opus_encoder_create(16000, 1, OPUS_APPLICATION_AUDIO, &err); + encoder = opus_encoder_create(SAMPLERATE, 1, OPUS_APPLICATION_AUDIO, &err); if(!encoder || err != OPUS_OK) { printf("opus_encoder_create: %d\n", err); } @@ -57,7 +53,7 @@ OpusEncoder::~OpusEncoder() unsigned int OpusEncoder::framesize() { - return 16000 / 1000 * OPUS_FRAME_SIZE; // 10ms audio data + return SAMPLERATE / 1000 * OPUS_FRAME_SIZE; // 10ms audio data } framelist_t OpusEncoder::encode(const char *pcm, size_t size) @@ -69,7 +65,7 @@ framelist_t OpusEncoder::encode(const char *pcm, size_t size) printf("encoder == NULL\n"); } - size_t bytes_per_packet = ((OPUS_BITRATE *framesize())/16000+4)/8; + size_t bytes_per_packet = ((OPUS_BITRATE *framesize())/SAMPLERATE+4)/8; cache.addSamples((short*)pcm, size / sizeof(short)); diff --git a/src/soundplayer.cc b/src/soundplayer.cc index 0f4fec2..024dea3 100644 --- a/src/soundplayer.cc +++ b/src/soundplayer.cc @@ -30,6 +30,8 @@ #include #include +#include "mediaconfig.h" + #define BUFSZ 512 SoundPlayer::SoundPlayer() @@ -53,7 +55,7 @@ void SoundPlayer::run() ao_sample_format sf; memset(&sf, 0, sizeof(sf)); sf.bits = 16; - sf.rate = 16000; + sf.rate = SAMPLERATE; sf.channels = 1; sf.byte_format = AO_FMT_NATIVE; diff --git a/src/soundplayer.h b/src/soundplayer.h index 35138bd..3679fd2 100644 --- a/src/soundplayer.h +++ b/src/soundplayer.h @@ -35,9 +35,10 @@ #include #include "frame.h" +#include "mediaconfig.h" -// Sixe of reingbuffer in samples (16KHz), delay will be half that value -#define RINGBUFFER 16000 +// Size of ringbuffer in samples, delay will be half that value +#define RINGBUFFER SAMPLERATE class QueueItem { public: diff --git a/src/v4l.cc b/src/v4l.cc index bd193f4..ed75f7c 100644 --- a/src/v4l.cc +++ b/src/v4l.cc @@ -50,6 +50,8 @@ extern "C" { #include } +#include "mediaconfig.h" + #define JPEG_HEADER_PAD 500 static bool isYUYV = false; @@ -173,7 +175,7 @@ static void process_image(const void *p, int size) int img_size = size; if(isYUYV) { - toJpeg(70, (unsigned char*)p, 640, 480, (char**)&img, (size_t*)&img_size); + toJpeg(70, (unsigned char*)p, V4LWIDTH, V4LHEIGHT, (char**)&img, (size_t*)&img_size); } if(v4l) v4l->processImage(img, img_size); @@ -590,8 +592,8 @@ static void init_device(void) fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (true || force_format) { - fmt.fmt.pix.width = 640; - fmt.fmt.pix.height = 480; + fmt.fmt.pix.width = V4LWIDTH; + fmt.fmt.pix.height = V4LHEIGHT; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG; // fmt.fmt.pix.field = V4L2_FIELD_NONE; diff --git a/src/videowidget.cc b/src/videowidget.cc index 9a0fda4..a8bd87c 100644 --- a/src/videowidget.cc +++ b/src/videowidget.cc @@ -28,12 +28,14 @@ #include +#include "mediaconfig.h" + VideoWidget::VideoWidget(int peer, InputStreamer *is) { this->is = is; this->peer = peer; setWindowTitle("SimpleRTP - " + is->getName()); - resize(640, 480); + resize(V4LWIDTH, V4LHEIGHT); show(); } -- cgit v1.2.3