summaryrefslogtreecommitdiff
path: root/src/audio_encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio_encoder.cc')
-rw-r--r--src/audio_encoder.cc125
1 files changed, 108 insertions, 17 deletions
diff --git a/src/audio_encoder.cc b/src/audio_encoder.cc
index 8972e9a..97c6084 100644
--- a/src/audio_encoder.cc
+++ b/src/audio_encoder.cc
@@ -28,8 +28,10 @@
#include "audio_encoder.h"
#include "util.h"
-AudioEncoder::AudioEncoder(FramePriorityQueue *in, pthread_mutex_t *in_mutex, sem_t *in_sem,
- FramePriorityQueue *out, pthread_mutex_t *out_mutex, sem_t *out_sem,
+#include "liblame_wrapper.h"
+
+AudioEncoder::AudioEncoder(ThreadSafeQueuePriority *audio_input_queue,
+ ThreadSafeQueuePriority *audio_output_queue,
Info *i)
{
info = i;
@@ -37,18 +39,8 @@ AudioEncoder::AudioEncoder(FramePriorityQueue *in, pthread_mutex_t *in_mutex, se
running = true;
- // Queues
- inputqueue = in;
- outputqueue = out;
-
- // Queue mutexes
- input_mutex = in_mutex;
- output_mutex = out_mutex;
-
- input_sem = in_sem;
- output_sem = out_sem;
-
- frame_number = 0;
+ input_queue = audio_input_queue;
+ output_queue = audio_output_queue;
}
AudioEncoder::~AudioEncoder()
@@ -59,18 +51,109 @@ void AudioEncoder::thread_main()
{
info->info("AudioEncoder::run");
- unsigned int queuesize = 0;
-
// Run with slightly lower priority than MovEncoderWriter
// nice(2);
Frame *in_frame = NULL;
Frame *out_frame = NULL;
+
+ LibLAMEWrapper lame(info);
+
+ while(running) {
+ in_frame = input_queue->pop();
+
+ if(in_frame == NULL) info->error("AudioEncoder: in_frame == NULL!");
+
+ // Check for end of stream
+ if(in_frame->endOfFrameStream == true) {
+ info->info("endOfFrameStream in AudioEncoder");
+ running = false;
+ out_frame = lame.close();
+ } else {
+ // Encode audio
+ out_frame = lame.encode(in_frame);
+ }
+ out_frame->number = in_frame->number;
+ out_frame->endOfFrameStream = in_frame->endOfFrameStream;
+
+ //delete in_frame;
+ in_frame = NULL;
+
+ output_queue->push(out_frame);
+ }
+
+ info->info("AudioEncoder::stop");
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+
+void AudioEncoder::thread_main()
+{
+ info->info("AudioEncoder::run");
+
+#ifndef NEW_QUEUE
+ unsigned int queuesize = 0;
Frame *tmpframe;
+#endif
+
+ // Run with slightly lower priority than MovEncoderWriter
+ nice(2);
+
+ Frame *in_frame = NULL;
+ Frame *out_frame = NULL;
LibLAMEWrapper lame(info);
while(running) {
+ info->info("fisk");
+#ifdef NEW_QUEUE
+ in_frame = input_queue->pop();
+#else
sem_wait(input_sem);
// If no frame is in the buffer, get one from the queue
@@ -94,7 +177,8 @@ void AudioEncoder::thread_main()
sleep_0_2_frame();
}
-
+#endif
+
// Check for end of stream
if(in_frame->endOfFrameStream == true) {
info->info("endOfFrameStream in AudioEncoder");
@@ -110,6 +194,9 @@ void AudioEncoder::thread_main()
delete in_frame;
in_frame = NULL;
+#ifdef NEW_QUEUE
+ output_queue->push(out_frame);
+#else
// Lock output mutex
pthread_mutex_lock(output_mutex);
outputqueue->push(out_frame);
@@ -118,10 +205,14 @@ void AudioEncoder::thread_main()
// Kick multiplexer (audio)
sem_post(output_sem);
+#endif
}
+#ifndef NEW_QUEUE
// Kick multiplexer (audio)
sem_post(output_sem);
+#endif
info->info("AudioEncoder::stop");
}
+*/