summaryrefslogtreecommitdiffstats
path: root/src/VLCInput.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-03-11 21:15:38 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-03-11 21:15:38 +0100
commit58378f49c75b7c6e184c499082328761b468da68 (patch)
treedf16e70225672ea19fb1df01f2af40aaae67dfaa /src/VLCInput.h
parent599d0fc5892725e471772e567555bf075ad2ae86 (diff)
downloadfdk-aac-58378f49c75b7c6e184c499082328761b468da68.tar.gz
fdk-aac-58378f49c75b7c6e184c499082328761b468da68.tar.bz2
fdk-aac-58378f49c75b7c6e184c499082328761b468da68.zip
Add libvlc input
Be careful about sample rate conversion, VLC only wants to use the ugly resampler on some machines.
Diffstat (limited to 'src/VLCInput.h')
-rw-r--r--src/VLCInput.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/VLCInput.h b/src/VLCInput.h
new file mode 100644
index 0000000..13b0695
--- /dev/null
+++ b/src/VLCInput.h
@@ -0,0 +1,107 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 2015 Matthias P. Braendli
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef __VLC_INPUT_H_
+#define __VLC_INPUT_H_
+
+#include "config.h"
+
+#if HAVE_VLC
+
+#include <cstdio>
+#include <string>
+#include <vector>
+#include <deque>
+
+#include <vlc/vlc.h>
+#include <boost/thread/thread.hpp>
+
+#include "SampleQueue.h"
+
+// 16 bits per sample is fine for now
+#define BYTES_PER_SAMPLE 2
+
+class VLCInput
+{
+ public:
+ VLCInput(const std::string& uri,
+ int rate,
+ unsigned verbosity) :
+ m_uri(uri),
+ m_verbosity(verbosity),
+ m_channels(2),
+ m_rate(rate),
+ m_vlc(NULL) { }
+
+ ~VLCInput() {
+ if (m_mp) {
+ /* Stop playing */
+ libvlc_media_player_stop(m_mp);
+
+ /* Free the media_player */
+ libvlc_media_player_release(m_mp);
+ }
+
+ if (m_vlc) {
+ libvlc_release(m_vlc);
+ m_vlc = NULL;
+ }
+ }
+
+ /* Prepare the audio input */
+ int prepare();
+
+ ssize_t read(uint8_t* buf, size_t length);
+
+
+ // Callbacks for VLC
+ void preRender(
+ uint8_t** pp_pcm_buffer,
+ size_t size);
+
+ void postRender(
+ uint8_t* p_pcm_buffer,
+ size_t size);
+
+ int getRate() { return m_rate; }
+
+ protected:
+ ssize_t m_read(uint8_t* buf, size_t length);
+
+ std::vector<uint8_t> m_current_buf;
+
+ boost::mutex m_queue_mutex;
+ std::deque<uint8_t> m_queue;
+
+ std::string m_uri;
+ unsigned m_verbosity;
+ unsigned m_channels;
+ int m_rate;
+
+ // VLC pointers
+ libvlc_instance_t *m_vlc;
+ libvlc_media_player_t *m_mp;
+
+ private:
+ VLCInput(const VLCInput& other) {}
+};
+
+#endif // HAVE_VLC
+
+#endif
+